Skip to content

Document cargo-afl fuzzing support - #2815

Open
leighmcculloch wants to merge 16 commits into
mainfrom
docs-cargo-afl-fuzzing
Open

Document cargo-afl fuzzing support#2815
leighmcculloch wants to merge 16 commits into
mainfrom
docs-cargo-afl-fuzzing

Conversation

@leighmcculloch

@leighmcculloch leighmcculloch commented Sep 3, 2026

Copy link
Copy Markdown
Member

What

Add a step-by-step guide for fuzzing Soroban contracts with cargo-afl (AFL++) to the fuzzing guide, replacing the placeholder note that just pointed readers to the generic Rust Fuzz book.

Why

We should demonstrate it as the fuzzing tools can be a bit overwhelming.

@github-actions github-actions Bot added the preview Preview builds for PRs by SDF employees. label Sep 3, 2026
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot removed the preview Preview builds for PRs by SDF employees. label Sep 3, 2026
@github-actions github-actions Bot added the preview Preview builds for PRs by SDF employees. label Sep 3, 2026
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot added preview Preview builds for PRs by SDF employees. and removed preview Preview builds for PRs by SDF employees. labels Sep 3, 2026
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

@leighmcculloch
leighmcculloch marked this pull request as ready for review September 3, 2026 13:18
@leighmcculloch
leighmcculloch requested review from ElliotFriend and a balanced review from Copilot September 3, 2026 13:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a step-by-step guide for fuzzing Soroban contracts with cargo-afl.

Changes:

  • Documents installation, configuration, execution, and crash replay.
  • Adds an AFL++ fuzz-target example and references.
Suppressed comments (5)

docs/build/guides/testing/fuzzing.mdx:148

  • This dependency name does not match the package used by the linked increment example (soroban-increment-contract). Cargo therefore looks for a package named my-contract at .. and fails before compiling the target.
   my-contract = { path = ".." }

docs/build/guides/testing/fuzzing.mdx:169

  • An arbitrary u64 makes most executions effectively unbounded: the provided eight-byte seed decodes to a value in the quadrillions, so the very first execution spends its time in the loop and is classified as a timeout instead of exercising useful inputs. Bound the generated operation count to keep every fuzz iteration fast.
       pub by: u64,

docs/build/guides/testing/fuzzing.mdx:184

  • last is never updated, so Some(current) > None is true on every successful call and the stated monotonicity property is not actually tested. Save each successful value after asserting it.
                   Ok(Ok(current)) => assert!(Some(current) > last),

docs/build/guides/testing/fuzzing.mdx:218

  • After AFL++ records more than one crash, this wildcard expands to multiple paths and the shell rejects the input redirection as ambiguous. Select and quote one concrete crash path before replaying it.
RUST_BACKTRACE=1 ./target/debug/fuzz_target_1 < out/default/crashes/id:000000*

docs/build/guides/testing/fuzzing.mdx:211

  • This rationale is incorrect for cargo-afl: its build wrapper explicitly passes both -C overflow_checks and -C debug-assertions for instrumented Cargo builds, including release builds. Avoid telling readers that release mode necessarily loses these checks.
   Fuzz debug builds, at least at first: they keep integer overflow checks and `debug_assert!`s enabled, and those catch bugs a release build won't.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

cargo afl system-config
```

3. Create a fuzz target crate, for example with `cargo new --bin fuzz` inside your contract's directory. Unlike a `cargo-fuzz` target, an AFL++ target depends on the `arbitrary` crate directly, because the `fuzz!` macro expands to code that refers to it by an absolute path, which only resolves if `arbitrary` is a direct dependency. Add the following to the new crate's `Cargo.toml`:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

preview Preview builds for PRs by SDF employees.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants