← 开源

Smart contract fuzzer for Foundry projects — Echidna-inspired, written in Rust

Rust
增长势头
+024 小时新增 Star0.0%
21
Star
4
Fork
2
贡献者
创建于 2026-04-15 · 更新于 2026-12-04 · 今日第 28445 名
主要开发者
0kn0tGalloDaSballo
README

Recon Fuzzer

A high-performance smart contract fuzzer for Foundry projects, written in Rust. Echidna-inspired, with coverage-guided mutation, automatic shrinking, and parallel workers.

Features

  • Fast & parallel — multi-threaded fuzzing with configurable worker count
  • Multiple test modes — property, assertion, optimization, exploration
  • Coverage-guided — tracks per-instruction or per-branch coverage
  • ABI-aware mutation — smart corpus-based mutation driven by contract ABI
  • Automatic shrinking — minimizes failing sequences for reproducible reports
  • Forking — run against live chain state via RPC
  • Echidna-compatible corpus — share echidna.yaml and corpora between Recon and Echidna

Installation

Via reconup (recommended)

reconup is the official installer and updater. Install it once with:

curl -L https://raw.githubusercontent.com/Recon-Fuzz/reconup/refs/heads/main/install | bash

Then restart your shell (or source ~/.zshrc / source ~/.bashrc) and install recon:

reconup

Updating — run reconup again. It only downloads if a newer release is available.

Supported platforms — Linux x86_64, macOS ARM64 (Apple Silicon), macOS x86_64 (Intel), Windows x86_64. On Windows, run reconup from Git Bash or WSL.

Install location — ~/.recon/bin/recon.

Uninstall — rm -rf ~/.recon, then remove the PATH export from your shell profile.

Pre-built binaries (manual)

If you'd rather skip reconup, download directly from the Releases page:

# Linux x86_64
wget https://github.com/Recon-Fuzz/recon-fuzzer/releases/latest/download/recon-linux-x86_64.tar.gz
tar -xzf recon-linux-x86_64.tar.gz && sudo mv recon /usr/local/bin/

# macOS Apple Silicon
wget https://github.com/Recon-Fuzz/recon-fuzzer/releases/latest/download/recon-macos-aarch64.tar.gz
tar -xzf recon-macos-aarch64.tar.gz && sudo mv recon /usr/local/bin/

Build from source

Requires Rust 1.70+.

git clone https://github.com/Recon-Fuzz/recon-fuzzer.git
cd recon-fuzzer
cargo build --release
# binary at target/release/recon

Quick start

recon fuzz /path/to/foundry/project
recon fuzz . --contract MyContract --workers 8 --test-limit 100000

Commands

The CLI has one subcommand: fuzz. Everything else happens through flags.

recon fuzz [OPTIONS] <PROJECT>

<PROJECT>

Path to a Foundry project (directory containing foundry.toml). Recon compiles it with forge build and picks a target contract.

Common options

Flag Description
-c, --contract <NAME> Contract to fuzz (defaults to first)
--config <FILE> YAML config file (CLI flags override)
-w, --workers <N> Number of parallel worker threads
--test-limit <N> Total test iterations across all workers (default: 50000)
--seq-len <N> Calls per sequence (default: 100)
--seed <N> Deterministic RNG seed
--timeout <SEC> Wall-clock timeout
--stop-on-fail Exit as soon as any test fails
-q, --quiet Reduce log verbosity

Test modes

--test-mode property       # functions prefixed with echidna_ returning bool
--test-mode assertion      # detect assert() failures
--test-mode optimization   # maximize int return value of echidna_opt_* functions
--test-mode exploration    # coverage-only, no assertions

Examples below.

Addresses and senders

--contract-addr <0x...>    # deployment address (default 0x00a329c0648769a73afac7f9381e08fb43dbea72)
--deployer <0x...>         # deployer address (default 0x30000)
--sender <0x...>           # sender to cycle through (repeatable)
--all-contracts            # generate calls to every deployed contract, not just the target
--mutable-only             # skip pure/view functions

Forking

--rpc-url <URL>
--rpc-block <N>

Coverage & performance

Flag Description
--coverage-mode full|branch full tracks every opcode, branch only JUMPI/JUMPDEST (faster)
--fast Alias for --coverage-mode branch
--lcov Emit LCOV coverage report during the run

Corpus management

Flag Description
--corpus-dir <DIR> Corpus directory (shared format with Echidna)
--recon-corpus-dir <DIR> Recon-native corpus directory (see below)
--shrink Skip fuzzing; only shrink existing reproducers in the corpus
--replay <FILE> Replay one reproducer file and print traces
--convert Convert Recon corpus to Echidna format and exit

Other

Flag Description
--format text|json|none Output format for the final report
--shortcuts Run shortcut_* functions at startup to bootstrap the corpus
--shrink-limit <N> Shrink attempts per failing test (default: 5000)
--filter-functions <SIG> Exclude functions from fuzzing (repeatable, Echidna filterFunctions)
--filter-whitelist Treat --filter-functions as a whitelist instead of blacklist
--hot-reload Watch .sol files and restart campaign on recompilation

Storage Hooks (Rvm.sol)

Recon extends Foundry's vm.load/vm.store with cheatcodes that read and write storage by variable name — no public getters needed. This enables property tests on private state, packed struct members, and mapping values.

Setup

Import Rvm.sol from the project root:

import "recon-fuzzer/Rvm.sol";

This gives you rvm — a global constant bound to the HEVM cheatcode address.

Reading storage

// Read by variable name (auto-resolved from storageLayout)
uint256 val = uint256(rvm.loadVar(address(vault), "totalDeposits"));

// Packed struct member
uint128 fee = uint128(uint256(rvm.loadVar(address(vault), "config.feeNumerator")));

// Mapping with keys
uint256 bal = uint256(rvm.loadVar(address(vault), "balances", abi.encode(user)));

// Nested mapping
uint256 allow = uint256(rvm.loadVar(address(vault), "allowances", abi.encode(owner, spender)));

// Raw packed extraction (no layout needed)
bool paused = uint256(rvm.loadVar(address(vault), bytes32(uint256(0)), 0, 1)) != 0;

Writing storage

// Write by variable name
rvm.storeVar(address(vault), "totalDeposits", bytes32(uint256(1000)));

// Write packed struct member
rvm.storeVar(address(vault), "config.paused", bytes32(uint256(1)));

// Write mapping value
rvm.storeVar(address(vault), "balances", abi.encode(user), bytes32(uint256(1 ether)));

Layout registration

For contracts deployed by your test harness (via new), storage layouts are auto-registered — no setup needed.

For external contracts (proxies, fork mode, on-chain addresses):

// Assign a known contract's layout to an address
rvm.assignStorageLayout(address(proxy), "VaultImplementation");

// Register layout manually (compact format)
rvm.registerStorageLayout(address(proxy),
    "uint256 totalDeposits, address owner, mapping(address => uint256) balances"
);

// Register layout manually (solc JSON format)
rvm.registerStorageLayout(address(proxy), '{"storage":[...],"types":{...}}');

ERC-7201 namespaced storage

// Register by namespace string (computes ERC-7201 base slot automatically)
rvm.registerNamespace(address(token), "openzeppelin.storage.ERC20",
    "mapping(address => uint256) balances, mapping(address => mapping(address => uint256)) allowances, uint256 totalSupply"
);

// Then read normally — namespace is the path prefix
uint256 supply = uint256(rvm.loadVar(address(token), "openzeppelin.storage.ERC20.totalSupply"));

// Manual base slot (for non-ERC-7201 patterns)
rvm.registerNamespace(address(token), 0x1234...00,
    "uint256 value, address owner"
);

Compact layout format

The compact format mirrors Solidity struct syntax:

"uint256 a, bool b, address c"                                    — flat fields
"(uint128 lo, uint64 hi) config"                                  — inline struct
"(uint16 b, (uint32 x, bool y) inner) mid"                       — nested struct
"mapping(address => uint256) balances"                            — mapping
"mapping(address => mapping(uint256 => bool)) approvals"          — nested mapping
"uint256[] items"                                                  — dynamic array
"(uint32 x, bool y)[3] fixedArr"                                  — fixed array of structs

All Solidity value types are supported: uint8–uint256, int8–int256, bool, address, bytes1–bytes32, bytes, string.

Hot Reload

Pass --hot-reload to automatically restart the campaign when Solidity files change:

recon fuzz . --hot-reload
recon fuzz . --hot-reload --web

When a .sol file is modified, Recon recompiles in the background (workers keep running), then restarts the campaign with fresh bytecode. The existing corpus is preserved and replayed against the new code. Coverage maps, tests, and EVM state are fully reset.

Can also be enabled via config:

hotReload: true

Web UI (experimental)

Recon ships an optional browser UI for watching a campaign live. Pass --web to a recon fuzz run:

recon fuzz . --web

Experimental. This is still rough — not all features are wired up and the frontend is under active development. Treat it as an early preview, not a finished product. The CLI remains the supported way to run campaigns.

Configuration file

Recon understands the Echidna-style echidna.yaml. CLI flags override file values.

testMode: property
prefix: echidna_
corpusDir: corpus
testLimit: 50000
shrinkLimit: 5000
seqLen: 100
workers: 4
timeout: 86400
stopOnFail: false
contractAddr: "0x00a329c0648769a73afac7f9381e08fb43dbea72"
deployer: "0x30000"
sender:
  - "0x10000"
  - "0x20000"
  - "0x30000"
rpcUrl: "https://eth-mainnet.alchemyapi.io/v2/..."
rpcBlock: 18000000
allContracts: false
mutableOnly: false
lcovEnable: false
coverageMode: full
shortcutsEnable: false
filterFunctions:
  - "Token.transfer(address,uint256)"
  - "Token.approve(address,uint256)"
filterBlacklist: true   # true = exclude listed (default), false = fuzz ONLY listed
recon fuzz . --config echidna.yaml

Test mode examples

Property

contract Vault {
    uint256 public balance;

    function echidna_balance_never_negative() public view returns (bool) {
        return balance >= 0;
    }
}
recon fuzz . --test-mode property --contract Vault

Assertion

function transfer(uint256 amount) public {
    assert(amount <= balance);
    balance -= amount;
}
recon fuzz . --test-mode assertion --contract Vault

Optimization

function echidna_opt_balance() public view returns (int256) {
    return int256(balance);
}
recon fuzz . --test-mode optimization --contract Vault

Exploration

Pure coverage exploration, no property checks:

recon fuzz . --test-mode exploration

Sharing corpus with Echidna

Recon can interoperate with an Echidna corpus so you can alternate between the two tools without regenerating inputs.

Recon ↔ Echidna layout

Echidna reads/writes plaintext reproducers under corpusDir. Recon's native format is richer (priorities, delay pairs, selector map). To keep both happy:

project/
├── echidna.yaml                 # shared config (corpusDir: corpus/)
├── corpus/                      # Echidna-format corpus (shared)
└── corpus-recon/                # Recon-native corpus

Two corpora at once (recommended)

Point Recon at its own dir via --recon-corpus-dir. It fuzzes using the native format and auto-exports every new corpus entry to --corpus-dir (or corpusDir: in the config) in Echidna format:

recon fuzz . \
  --config echidna.yaml \
  --recon-corpus-dir corpus-recon

Run Echidna afterwards and it picks up the exported entries from corpus/.

One-shot conversion

To convert an existing Recon corpus to Echidna format without fuzzing, add --convert:

recon fuzz . \
  --config echidna.yaml \
  --recon-corpus-dir corpus-recon \
  --convert

Recon exits after exporting. The Echidna-format files land in corpus/ (or whatever corpusDir resolves to).

Using an Echidna corpus from Recon

Point --corpus-dir (or corpusDir:) at the existing Echidna corpus without --recon-corpus-dir. Recon reads the Echidna-format reproducers directly.

recon fuzz . --corpus-dir ./echidna/corpus

Replaying and shrinking

# Replay a saved reproducer and dump the trace
recon fuzz . --replay corpus/reproducers/failure_001.txt

# Re-shrink every reproducer in the corpus without running the fuzzer
recon fuzz . --corpus-dir corpus --shrink

Troubleshooting

"Contract not found" — make sure forge build succeeds first.

"Failed to compile project" — Recon expects a standard Foundry layout with foundry.toml.

Slow iterations — try --fast (branch-only coverage), lower --seq-len, or raise --workers.

Browser fuzzer (WebAssembly)

browser-fuzzer/ is an experimental WebAssembly build of the fuzzer that runs entirely in the browser — no server, no backend. It shares the core engine with the CLI. Requires Rust nightly to build (uses #![feature(thread_local)] for multi-worker shared memory).

cd browser-fuzzer
cargo +nightly build --target wasm32-unknown-unknown --release

Contributing

Contributions welcome. See CONTRIBUTING.md.

License

GPL-2.0. See LICENSE.

Acknowledgments

Huge thanks to the Crytic team for Echidna. Recon is heavily inspired by Echidna's design — the testing modes, corpus format, and many implementation details trace directly back to their work. This project would not exist without it.

Also built on top of:

  • revm — EVM execution
  • alloy — Ethereum primitives
  • Foundry — project compilation

Disclaimer

Large portions of this codebase were written with the assistance of AI coding tools ("vibe coding"). The maintainers have reviewed and exercised the code but cannot guarantee correctness, completeness, or security of every path. Use at your own risk. No warranty is provided — see the LICENSE for details. Do not rely on Recon as the sole line of defense when auditing production contracts; always combine it with independent review, established tools, and human judgment.

Support

排名相邻

AI Rank iPhone 版

随时追踪 AI 模型榜单

在 App Store 下载