Skip to content

feat(testing): added contract fuzzing and property-based testing - #717

Open
Codex723 wants to merge 1 commit into
Nanle-code:masterfrom
Codex723:feat/contract-fuzzing-property-testing
Open

feat(testing): added contract fuzzing and property-based testing#717
Codex723 wants to merge 1 commit into
Nanle-code:masterfrom
Codex723:feat/contract-fuzzing-property-testing

Conversation

@Codex723

Copy link
Copy Markdown

D-11: Add Contract Fuzzing and Property-Based Testing

Summary

Integrates fuzzing tools and property-based testing frameworks to automatically discover edge cases and vulnerabilities in Soroban contracts. This PR adds 4 contract-specific fuzzing harnesses, 18 property-based tests across 6 test groups, seed corpora, CI pipeline integration, mutation testing coverage, and comprehensive documentation.

Changes

New Files

File Description
fuzz/fuzz_targets/fuzz_wasm_validation.rs WASM binary validation fuzzing harness — tests magic header, minimum size, and panic-freedom
fuzz/fuzz_targets/fuzz_contract_invocation.rs Mock contract client invocation fuzzing harness — tests call counting, return/error determinism, and reset
fuzz/fuzz_targets/fuzz_contract_spec_parse.rs Contract test spec JSON parsing fuzzing harness — tests malformed JSON, truncated docs, and hostile Unicode
fuzz/fuzz_targets/fuzz_test_generator.rs Test case generation from source fuzzing harness — tests malformed Rust, empty files, and arbitrary fragments
tests/contract_property_tests.rs 18 property-based tests across 6 groups: WASM validation, WASM hash computation, mock contract invocation, mock storage, mock addresses, and mock environment
fuzz/corpus/fuzz_wasm_validation/valid_wasm.bin Seed corpus for WASM validation fuzzing
fuzz/corpus/fuzz_contract_spec_parse/valid_spec.json Seed corpus for contract spec parsing (valid spec)
fuzz/corpus/fuzz_contract_spec_parse/empty_spec.json Seed corpus for contract spec parsing (empty spec)
fuzz/corpus/fuzz_contract_spec_parse/malformed_spec.json Seed corpus for contract spec parsing (malformed JSON)
fuzz/corpus/fuzz_test_generator/valid_source.rs Seed corpus for test generation (valid Rust source)
fuzz/corpus/fuzz_test_generator/empty_source.rs Seed corpus for test generation (empty source)

Modified Files

File Changes
fuzz/Cargo.toml Added 4 new contract fuzz target entries + tempfile dependency
.github/workflows/fuzzing.yml Added contract fuzz targets to fuzz-smoke matrix, added contract property tests to CI, fixed YAML indentation
FUZZING_GUIDE.md Added contract fuzzing section with harness descriptions, invariants, run commands, and security focus areas
.cargo-mutants.toml Added contract testing source files to mutation testing scope

Acceptance Criteria

  • Property-based tests for contracts — 18 property tests across 6 groups in tests/contract_property_tests.rs
  • Fuzzing harnesses work — 4 contract-specific harnesses in fuzz/fuzz_targets/
  • Mutation testing integration.cargo-mutants.toml updated to include contract source files
  • Coverage reporting — CI pipeline includes cargo-llvm-cov coverage generation with Codecov upload
  • CI pipeline integration.github/workflows/fuzzing.yml updated with contract fuzz targets and property tests
  • Documentation and examplesFUZZING_GUIDE.md updated with contract fuzzing section, examples, and security focus areas

How to Test

# Run contract property tests
cargo test --test contract_property_tests

# Run with more iterations
PROPTEST_CASES=5000 cargo test --test contract_property_tests

# Run contract fuzz targets (requires nightly + cargo-fuzz)
cargo fuzz run fuzz_wasm_validation --fuzz-dir fuzz -- -max_total_time=60
cargo fuzz run fuzz_contract_invocation --fuzz-dir fuzz -- -max_total_time=60
cargo fuzz run fuzz_contract_spec_parse --fuzz-dir fuzz -- -max_total_time=60
cargo fuzz run fuzz_test_generator --fuzz-dir fuzz -- -max_total_time=60

Related Issue

Closes #308

…tructure

- Add 4 contract fuzzing harnesses: fuzz_wasm_validation, fuzz_contract_invocation, fuzz_contract_spec_parse, fuzz_test_generator
- Add contract property-based tests (tests/contract_property_tests.rs) with 6 test groups covering WASM validation, hash computation, mock invocation, storage, addresses, and environment
- Update fuzz/Cargo.toml with new contract fuzz targets
- Update fuzzing CI workflow to include contract fuzz targets in fuzz-smoke matrix and contract property tests
- Update FUZZING_GUIDE.md with contract fuzzing section, examples, and documentation
- Add contract fuzzing seed corpus files for WASM validation, spec parsing, and test generation
- Update .cargo-mutants.toml to include contract testing source files
@drips-wave

drips-wave Bot commented Jul 30, 2026

Copy link
Copy Markdown

@Codex723 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

D-11: Add Contract Fuzzing and Property-Based Testing

2 participants