# Smart Contract Fuzzing > Property-based, stateful fuzzing of on-chain programs: the fuzzer generates sequences of transactions against a contract and checks after each one that user-written invariants still hold, so the oracle is a broken accounting rule rather than a crash. ## How it works - **The oracle is a property.** Smart contracts rarely "crash"; the bugs that cost money are accounting and access-control errors that leave every transaction valid. Echidna is defined by the fuzzer that "generates call sequences to falsify user-defined properties and Solidity assertions" ([[raw/ack3.ai/evaluating-agent-written-fuzz-tests-14828|Evaluating agent-written fuzz tests]]). An invariant is "a property that must remain true before and after every relevant state transition" ([[raw/ack3.ai/introducing-wake-5-agent-written-solidity-fuzzing-in-python-14922|Introducing Wake 5]]). - **Stateful sequences, not single inputs.** A harness is made of *flows* (state-changing calls with fuzzed arguments) and *invariants* checked after each flow, plus, in Wake's style, a Python model of the contract's expected state ([[raw/ack3.ai/evaluating-agent-written-fuzz-tests-14828|Evaluating agent-written fuzz tests]], [[raw/ack3.ai/introducing-wake-5-agent-written-solidity-fuzzing-in-python-14922|Introducing Wake 5]]). Bugs live in particular orderings: the Drips bug D1 needs a claim on a stream *after* its start time has passed, so a harness that only ever claims in the future-only case can never reach it. - **Coverage and corpus.** Medusa is coverage-guided, emits an HTML coverage report, and keeps a corpus; Trail of Bits benchmarked it against Echidna on coverage and corpus size and found them similar ([[raw/blog.trailofbits.com/unleashing-medusa-smart-contract-fuzzing-3904|Medusa]]). Echidna 2.4.0 improved corpus reuse (including `seqLen: 1`) and made test limits count executed transactions ([[raw/github.com/echidna-2-4-0-mcp-support-for-interactive-fuzzing-and-improved-symboli-14562|Echidna 2.4.0]]). - **Input generation is the binding constraint, not speed.** On the Daedaluzz maze benchmark (153 reachable assertions behind constant guards), Wake 5 runs 29,931 tx/s, Foundry 30,186, Echidna 2,600. Yet after eight hours they plateau at medians of 75, 71 and 70 assertions (union 93). Wake's integer generator puts 51% of its mass below 2³², and once shallow assertions are exhausted the generator prior, not throughput, bounds every tool ([[raw/arxiv.org/wake-5-a-python-framework-for-solidity-testing-fuzzing-and-static-anal-14066|Wake 5 paper]]). - **Fuzzing plus symbolic execution.** Echidna's `--test-mode verification` runs hevm symbolic execution. Functions prefixed `check` or `prove` are treated as verification entry points. The 2.4.0 backend handles arithmetic-heavy properties, mappings, packed storage and hashes far better. One multiplication-monotonicity property verified in about 1.6 s where native arithmetic timed out at 30 s ([[raw/github.com/echidna-2-4-0-mcp-support-for-interactive-fuzzing-and-improved-symboli-14562|Echidna 2.4.0]]). ## Tools | Tool | Engine / language | Notes | |---|---|---| | Echidna | hevm symbolic backend | Property and assertion fuzzer; 2.4.0 adds an MCP server, better Foundry compatibility (invariant naming, expected-revert tests), library auto-linking | | Medusa | Go, built on Geth | Coverage-guided, parallel, Slither-informed value generation, on-chain fuzzing seeded from live chain state, rich traces; Trail of Bits' main focus now, Echidna gets minor fixes | | Foundry | revm | Invariant tests; same throughput class as Wake 5 | | Wake 5 | Python, revm in-process | `pip3 install eth-wake`; harnesses are Python, generated types per contract, `chain.connect(fork=...)` forking, multi-chain in one process, history bounded to 256 blocks for multi-hour runs, `wake mcp` for agents | | Recon | — | One of the four baseline fuzzers in scfuzzbench | | Fuzzy | Solana | Agent-built Solana program fuzzer with attack classes and IDL-derived property fuzzing | Sources: [[raw/blog.trailofbits.com/unleashing-medusa-smart-contract-fuzzing-3904|Medusa]], [[raw/github.com/echidna-2-4-0-mcp-support-for-interactive-fuzzing-and-improved-symboli-14562|Echidna 2.4.0]], [[raw/ack3.ai/introducing-wake-5-agent-written-solidity-fuzzing-in-python-14922|Introducing Wake 5]], [[raw/ack3.ai/evaluating-agent-written-fuzz-tests-14828|Evaluating agent-written fuzz tests]], [[raw/blog.verafy.ai/fuzzy-an-agent-built-solana-program-fuzzer-14268|Fuzzy]]. Getting started with Medusa: install it (Homebrew on macOS), initialise the project to generate a `medusa.json` config, then start fuzzing ([[raw/blog.trailofbits.com/unleashing-medusa-smart-contract-fuzzing-3904|Medusa]]). ## Writing properties and invariants - **Conservation and accounting.** For value-moving Uniswap v4 hooks, Trail of Bits says to test at least three invariants: no user receives output the accounting did not charge for; a same-transaction round trip cannot create value from accounting alone; internal accounting matches actual asset balances ([[raw/blog.trailofbits.com/building-secure-uniswap-v4-hooks-10943|Building secure Uniswap v4 hooks]]). - **Adversarial token and pool behaviour.** Those invariants must also hold for fee-on-transfer, rebasing, callback-enabled (reentrant) and pausable/blacklistable tokens. Use Echidna and Medusa to fuzz nested callbacks, fee extremes, malicious pools and non-standard tokens, not just happy paths ([[raw/blog.trailofbits.com/building-secure-uniswap-v4-hooks-10943|Uniswap v4 hooks]]). - **Concrete examples from a real suite.** The OUSD stablecoin's Echidna properties show what good invariants look like ([[raw/ack3.ai/evaluating-agent-written-fuzz-tests-14828|Evaluating agent-written fuzz tests]]): - total supply never below the sum of balances; - non-rebasing supply never above total supply; - rebasing credits per token never increase; - mint raises a balance by exactly the amount, and burn lowers it by exactly the amount; - burning a full balance leaves zero and does not revert; - a transfer within balance does not revert, and moves exactly the amount. - **Scenarios matter as much as checks.** Make sure the flows reach the states where funds can go wrong (e.g. claims after a stream has started); a passing test that never builds that state proves nothing ([[raw/ack3.ai/evaluating-agent-written-fuzz-tests-14828|Evaluating agent-written fuzz tests]]). - **Where it fits.** The Ethereum Foundation guidance quoted in a Web3 tooling guide: Slither detectors on every commit, then add Echidna property-based fuzzing for complex state-machine properties as the codebase grows, then symbolic execution and formal verification for critical rules ([[raw/augmentcode.com/ai-smart-contract-vulnerability-detection-web3-guide-8674|AI Smart Contract Vulnerability Detection]]). ## AI and agentic approaches - **Agents write the harness.** Wake 5's pitch: a coding agent writes the flows, state model and invariants from one prompt, and the auditor reviews them as Python ([[raw/ack3.ai/introducing-wake-5-agent-written-solidity-fuzzing-in-python-14922|Introducing Wake 5]]). On Daedaluzz, an agent harness that handed guards to a constraint solver and planned routes through the maze reached all 153 assertions in each of five campaigns, in 33–79 minutes ([[raw/arxiv.org/wake-5-a-python-framework-for-solidity-testing-fuzzing-and-static-anal-14066|Wake 5 paper]]). The authors argue the fuzzer's role is shifting "from search to execution". - **Multi-role workflow (ai-fuzz).** Developer writes and debugs the test; Reviewer reads diffs and line coverage and files tasks for missing flows, weak invariants and uncovered code; Researcher answers what the code *should* do from docs only, never the implementation; Triage gives each issue a verdict and takes over failures that 20 debugging sessions could not resolve ([[raw/ack3.ai/evaluating-agent-written-fuzz-tests-14828|Evaluating agent-written fuzz tests]]). - **Interactive fuzzing over MCP.** `echidna MyContract.sol --server 8080 --format text` exposes an MCP endpoint at `/mcp` so an assistant can inspect coverage and failing tests, prioritise sequences, replay calls and reload the corpus. The feature is experimental ([[raw/github.com/echidna-2-4-0-mcp-support-for-interactive-fuzzing-and-improved-symboli-14562|Echidna 2.4.0]]). `wake mcp` gives agents static facts: definitions, references, inheritance, storage layout, selectors, external calls ([[raw/ack3.ai/introducing-wake-5-agent-written-solidity-fuzzing-in-python-14922|Introducing Wake 5]]). - **Static analysis helps precision, not recall.** In the Wake 5 ablation, MCP static-analysis tools raised precision for all three models, improved recall for none, and added up to 12.7% LLM cost ([[raw/arxiv.org/wake-5-a-python-framework-for-solidity-testing-fuzzing-and-static-anal-14066|Wake 5 paper]]). - **Solana: attack, prove, grade.** Fuzzy ingests the deployed bytecode and IDL, learns honest paths, replays recent mainnet calls on cloned accounts, then attacks: dropped signers, account substitution, reinitialisation, overflow, unchecked CPI targets, non-canonical PDA bumps, close-then-reuse, price-account manipulation. A finding counts only if the attack transaction moves funds to the attacker or makes them an authority ([[raw/blog.verafy.ai/fuzzy-an-agent-built-solana-program-fuzzer-14268|Fuzzy]]). - **LLM-only detection is not enough.** LLM auditing can raise recall, but false-positive rates on real DeFi protocols often exceed 97%. The recommended stack layers static analysis, fuzzing, symbolic execution, formal verification and human review ([[raw/augmentcode.com/ai-smart-contract-vulnerability-detection-web3-guide-8674|AI Smart Contract Vulnerability Detection]]). ## Notable cases - **OUSD (scfuzzbench).** Six agent-written runs together reproduced 6 of 12 known bugs (K1, K2, K4, K7, K11, K12). That is the same set every hand-written harness for Echidna, Medusa, Recon and Foundry reproduces, and none of the six no tool finds. The best single run found four in 6.3 h. Hand-written harnesses hit most of these in seconds (Recon <1 s on K1, Medusa 3 s); Foundry took up to 25 min, and up to 3.7 h on K12 ([[raw/ack3.ai/evaluating-agent-written-fuzz-tests-14828|Evaluating agent-written fuzz tests]]). - **Drips D1.** A claim did not cap a stream's start at its configuration-update time, so already-streamed funds could be lost. Baselines found it in 1.7 s (Recon), 15 s (Echidna), 21 s (Medusa) and 1.7 h (Foundry). Two current-workflow agent runs (83.6 h and 94.8 h) missed it because they never claimed after a stream started; the 13 runs cost $2,451.62 in total ([[raw/ack3.ai/evaluating-agent-written-fuzz-tests-14828|Evaluating agent-written fuzz tests]]). - **Bunni ($8.4M, Sept 2025).** A rounding bug in BunniHook's idle-balance accounting: a flash loan moved the tick, then 44 tiny withdrawals each shrank the active balance more than the shares burned. Every transaction satisfied the PoolManager's settlement invariant, because the bug was in the hook's own accounting. That is the case for writing protocol-specific invariants ([[raw/blog.trailofbits.com/building-secure-uniswap-v4-hooks-10943|Uniswap v4 hooks]]). - **Fuzzy on 100 Solana programs.** No proven exploits; for the 31 programs with checkable IDL-derived invariants, every invariant held. Most scores were low because only 36 publish an IDL. Fuzzy also caught its own false positives: a replay that kept the victim as signer, and CPI proxies and swap routers that looked like theft ([[raw/blog.verafy.ai/fuzzy-an-agent-built-solana-program-fuzzer-14268|Fuzzy]]). ## Pitfalls - A finished, passing harness can still miss the one scenario a bug needs, and nothing in an agent's own loop notices. Reviewers should check reachability of fund-moving states, not just green runs ([[raw/ack3.ai/evaluating-agent-written-fuzz-tests-14828|Evaluating agent-written fuzz tests]]). - Comparing fuzzers by throughput alone is misleading; generator priors decide deep reach ([[raw/arxiv.org/wake-5-a-python-framework-for-solidity-testing-fuzzing-and-static-anal-14066|Wake 5 paper]]). - Echidna 2.4.0 breaking changes: `--server` now serves MCP instead of SSE, JSON transaction arguments are structured, and a fixed seed cannot be combined with a timeout (use `testLimit`) ([[raw/github.com/echidna-2-4-0-mcp-support-for-interactive-fuzzing-and-improved-symboli-14562|Echidna 2.4.0]]). ## Related - [[Fuzzing]] - [[LLM-Assisted Fuzzing]] - [[Coverage-Guided Fuzzing]] - [[Fuzzing Harness Design]] - [[Differential Fuzzing]] - [[AI and LLM Security]] ## Sources - [[raw/blog.trailofbits.com/unleashing-medusa-smart-contract-fuzzing-3904|Unleashing Medusa: Smart Contract Fuzzing]] - [[raw/github.com/echidna-2-4-0-mcp-support-for-interactive-fuzzing-and-improved-symboli-14562|Echidna 2.4.0: MCP support for interactive fuzzing and improved symbolic execution]] - [[raw/ack3.ai/introducing-wake-5-agent-written-solidity-fuzzing-in-python-14922|Introducing Wake 5: agent-written Solidity fuzzing in Python]] - [[raw/arxiv.org/wake-5-a-python-framework-for-solidity-testing-fuzzing-and-static-anal-14066|Wake 5: a Python framework for Solidity testing, fuzzing and static analysis]] - [[raw/ack3.ai/evaluating-agent-written-fuzz-tests-14828|Evaluating agent-written fuzz tests]] - [[raw/blog.verafy.ai/fuzzy-an-agent-built-solana-program-fuzzer-14268|Fuzzy: an agent-built Solana program fuzzer]] - [[raw/blog.trailofbits.com/building-secure-uniswap-v4-hooks-10943|Building secure Uniswap v4 hooks]] - [[raw/augmentcode.com/ai-smart-contract-vulnerability-detection-web3-guide-8674|AI Smart Contract Vulnerability Detection: Web3 Guide]]