Guides writing and running Echidna property-based fuzzing for Solidity smart contracts: property design, assertion mode, corpus management, and Foundry integration.
Ships in echidna. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Echidna is a property-based fuzzer for Ethereum smart contracts built by Trail of Bits. It generates random sequences of transactions to find violations of user-defined properties. Unlike static analysis (Slither) or symbolic execution (Mythril), Echidna executes real EVM bytecode with coverage-guided mutation — it learns which inputs reach new code paths and explores deeper.
LLMs treat Echidna like "just run the fuzzer." The hard part is designing properties, not invoking the tool.
echidna . on a contract with weak properties proves nothing. A property that always returns true passes 100% of the time and catches 0% of bugs. Invest time in thinking about what invariants your protocol must maintain.assert() failures and Solidity panics (division by zero, overflow in unchecked blocks, array out of bounds). It does NOT check echidna_* functions. These are two different testing strategies.echidna_ prefix is mandatory in property mode — Properties must be public/external functions starting with echidna_ that take no arguments and return bool. Naming a function check_invariant() does nothing — Echidna ignores it.vm.prank, vm.deal, vm.warp do not work in Echidna. For time-dependent properties, use hevm-compatible cheatcodes or restructure your test harness with helper functions.Download the latest release from GitHub:
# macOS (Apple Silicon)
curl -L https://github.com/crytic/echidna/releases/latest/download/echidna-arm64-macos.tar.gz | tar xz
sudo mv echidna /usr/local/bin/
# macOS (Intel)
curl -L https://github.com/crytic/echidna/releases/latest/download/echidna-x86_64-macos.tar.gz | tar xz
sudo mv echidna /usr/local/bin/
# Linux (x86_64)
curl -L https://github.com/crytic/echidna/releases/latest/download/echidna-x86_64-linux.tar.gz | tar xz
sudo mv echidna /usr/local/bin/
Verify installation:
echidna --version
docker pull ghcr.io/crytic/echidna/echidna:latest
# Run on current directory
docker run --rm -v $(pwd):/src ghcr.io/crytic/echidna/echidna echidna /src/test/EchidnaTest.sol --contract EchidnaTest
Requires GHC 9.x and Stack:
git clone https://github.com/crytic/echidna.git
cd echidna
stack install
Echidna needs solc on PATH. Install the version matching your contracts:
pip3 install solc-select
solc-select install 0.8.28
solc-select use 0.8.28
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
contract Counter {
uint256 public count;
error Overflow();
function increment() external {
if (count >= 100) revert Overflow();
count += 1;
}
function decrement() external {
if (count == 0) return;
count -= 1;
}
}
Test harness:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import "./Counter.sol";
contract CounterTest is Counter {
// Property: count never exceeds 100
function echidna_count_bounded() public view returns (bool) {
return count <= 100;
}
// Property: count is always valid (non-negative is guaranteed by uint256)
function echidna_count_valid() public view returns (bool) {
return count <= 100;
}
}
Run:
echidna test/CounterTest.sol --contract CounterTest
Output when all properties hold:
echidna_count_bounded: passing
echidna_count_valid: passing
Unique instructions: 42
Corpus size: 3
Properties are functions prefixed with echidna_ that return bool. Echidna calls random contract functions between property checks. A property failure means the function returned false.
contract TokenPropertyTest is MyToken {
// MUST: public/external, no args, returns bool, starts with echidna_
function echidna_total_supply_bounded() public view returns (bool) {
return totalSupply() <= MAX_SUPPLY;
}
function echidna_zero_address_has_no_balance() public view returns (bool) {
return balanceOf(address(0)) == 0;
}
}
echidna test/TokenPropertyTest.sol --contract TokenPropertyTest
Instead of echidna_* functions, assertion mode looks for assert() failures and Solidity panic codes. Useful for inline checks within functions.
contract VaultAssertionTest is Vault {
function deposit_and_check(uint256 amount) public {
if (amount == 0 || amount > 1e30) return;
uint256 totalBefore = totalAssets();
deposit(amount);
uint256 totalAfter = totalAssets();
// Assertion mode catches this failure
assert(totalAfter >= totalBefore);
}
}
echidna test/VaultAssertionTest.sol --contract VaultAssertionTest --test-mode assertion
Config equivalent:
testMode: "assertion"
Finds inputs that maximize or minimize a numeric value. Functions must start with echidna_optimize_ and return int256.
contract GasOptimizeTest is MyContract {
// Echidna tries to MAXIMIZE the return value
function echidna_optimize_gas_usage() public returns (int256) {
uint256 gasBefore = gasleft();
complexOperation();
uint256 gasUsed = gasBefore - gasleft();
return int256(gasUsed);
}
// Find the maximum extractable value
function echidna_optimize_max_withdrawal() public returns (int256) {
uint256 balance = address(this).balance;
exploit();
uint256 stolen = balance - address(this).balance;
return int256(stolen);
}
}
echidna test/GasOptimizeTest.sol --contract GasOptimizeTest --test-mode optimization
Compatible with ds-test/forge-std style test functions. Functions starting with test that revert are treated as failures.
echidna test/FoundryStyleTest.sol --contract FoundryStyleTest --test-mode dapptest
Assets in = assets out. Nothing created from nothing.
contract ERC20InvariantTest is MyToken {
// Total supply equals sum of all known balances
function echidna_supply_conservation() public view returns (bool) {
return totalSupply() <= MAX_SUPPLY;
}
// Transfers do not create or destroy tokens
function echidna_no_token_creation() public view returns (bool) {
return totalSupply() == _initialSupply;
}
}
Only authorized actors can perform privileged operations.
contract AccessControlTest is Ownable, MyProtocol {
address constant ECHIDNA_CALLER = address(0x10000);
// Non-owner should never be able to change critical params
function echidna_only_owner_sets_fee() public view returns (bool) {
if (msg.sender != owner()) {
return fee() == _initialFee;
}
return true;
}
}
Valid state transitions only.
contract AuctionTest is Auction {
// Once ended, auction cannot restart
function echidna_no_restart_after_end() public view returns (bool) {
if (hasEnded) {
return !isActive;
}
return true;
}
// Bid must be higher than current highest
function echidna_bids_monotonic() public view returns (bool) {
return highestBid >= _previousHighestBid;
}
}
Protocol always has enough to cover its obligations.
contract VaultInvariantTest is Vault {
// Vault holds at least as much as it owes
function echidna_solvent() public view returns (bool) {
return token.balanceOf(address(this)) >= totalDebt();
}
// No share holder can extract more than total assets
function echidna_no_excess_withdrawal() public view returns (bool) {
if (totalSupply() == 0) return true;
uint256 maxWithdraw = previewRedeem(totalSupply());
return maxWithdraw <= token.balanceOf(address(this));
}
}
Constrain fuzz inputs to meaningful ranges within the test harness:
contract BoundedTest is MyProtocol {
// Helper: Echidna calls this with random amounts
function deposit_bounded(uint256 amount) public {
// Skip meaningless inputs instead of reverting
if (amount == 0 || amount > 1e24) return;
token.mint(msg.sender, amount);
token.approve(address(this), amount);
deposit(amount);
}
function echidna_total_deposits_tracked() public view returns (bool) {
return totalDeposits == token.balanceOf(address(this));
}
}
Track cumulative state that the contract itself doesn't store:
contract GhostTracker is MyToken {
uint256 internal _ghostTotalMinted;
uint256 internal _ghostTotalBurned;
function mint(address to, uint256 amount) public override {
super.mint(to, amount);
_ghostTotalMinted += amount;
}
function burn(uint256 amount) public override {
super.burn(amount);
_ghostTotalBurned += amount;
}
function echidna_mint_burn_conservation() public view returns (bool) {
return totalSupply() == _ghostTotalMinted - _ghostTotalBurned;
}
}
Echidna maintains a corpus of transaction sequences that achieve new code coverage. Each entry is a minimized sequence of calls that reached a previously unseen execution path.
# Save corpus to disk
corpusDir: "corpus"
# First run — builds corpus from scratch
echidna test/MyTest.sol --contract MyTest --corpus-dir corpus
# Subsequent runs — starts from existing corpus, finds new coverage faster
echidna test/MyTest.sol --contract MyTest --corpus-dir corpus
corpus/
├── coverage/ # Transaction sequences that hit new code paths
│ ├── 0001.txt # Minimized call sequence
│ ├── 0002.txt
│ └── ...
└── reproducers/ # Transaction sequences that violate properties
├── 0001.txt
└── ...
Provide initial transaction sequences to guide the fuzzer:
# Use a dictionary of interesting values
dictionary: "dict.txt"
Dictionary file format:
# dict.txt — one value per line, hex encoded
0x0000000000000000000000000000000000000000000000000000000000000000
0x0000000000000000000000000000000000000000000000000000000000000001
0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
0x00000000000000000000000000000000000000000000000000000000deadbeef
# Replay all saved reproducers to verify they still fail
echidna test/MyTest.sol --contract MyTest --corpus-dir corpus
# Number of transactions to generate per test
testLimit: 50000
# Maximum transaction sequence length before checking properties
seqLen: 100
# Shrink failing sequences to minimal reproduction
shrinkLimit: 5000
# Testing mode: "property" | "assertion" | "optimization" | "dapptest"
testMode: "property"
# Addresses
deployer: "0x30000"
sender: ["0x10000", "0x20000", "0x30000"]
contractAddr: "0x00a329c0648769A73afAc7F9381E08FB43dBEA72"
# Corpus persistence
corpusDir: "corpus"
# Compilation
cryticArgs: ["--solc-remaps", "@openzeppelin/=lib/openzeppelin-contracts/"]
# Coverage
coverage: true
# Workers (parallel fuzzing)
workers: 4
# Timeout per test in seconds (0 = no timeout)
testTimeout: 300
# Balance of test contract in wei
balanceContract: 0xffffffffffffffffffffffff
# Balance of sender addresses
balanceAddr: 0xffffffffffffffffffffffff
testLimit — Default is 50,000. For CI, use 10,000-50,000. For deep campaigns, use 500,000-5,000,000. Higher is not always better if properties are weak.
seqLen — Maximum number of transactions in a single test sequence. Default is 100. Increase for protocols where bugs require long setup sequences (lending protocols, governance). Decrease for simple contracts to speed up exploration.
shrinkLimit — How many attempts Echidna makes to minimize a failing sequence. Default is 5,000. Higher values give cleaner reproducers but take longer.
workers — Parallel fuzzing workers. Set to your CPU core count. Each worker explores independently and shares coverage.
sender — Addresses that Echidna uses as msg.sender. By default, three addresses. Add more for multi-user interaction testing. The deployer is NOT automatically a sender.
Create a test harness that deploys and wires up all contracts:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import "../src/Token.sol";
import "../src/Vault.sol";
import "../src/PriceOracle.sol";
contract SystemTest {
Token public token;
Vault public vault;
PriceOracle public oracle;
constructor() {
token = new Token("Test", "TST", 18);
oracle = new PriceOracle();
vault = new Vault(address(token), address(oracle));
// Seed initial state
token.mint(address(this), 1_000_000e18);
token.approve(address(vault), type(uint256).max);
// Fund sender addresses so they can interact
token.mint(address(0x10000), 100_000e18);
token.mint(address(0x20000), 100_000e18);
}
// Expose vault functions for Echidna to call
function deposit(uint256 amount) public {
if (amount == 0 || amount > token.balanceOf(msg.sender)) return;
vault.deposit(amount);
}
function withdraw(uint256 shares) public {
if (shares == 0 || shares > vault.balanceOf(msg.sender)) return;
vault.withdraw(shares);
}
function updatePrice(uint256 price) public {
if (price == 0 || price > 1e36) return;
oracle.setPrice(price);
}
// System-wide invariant
function echidna_vault_solvent() public view returns (bool) {
return token.balanceOf(address(vault)) >= vault.totalDebt();
}
function echidna_total_supply_matches() public view returns (bool) {
return vault.totalSupply() <= vault.totalAssets();
}
}
Config for multi-contract:
testLimit: 100000
seqLen: 200
sender: ["0x10000", "0x20000"]
deployer: "0x30000"
# allContracts: true makes Echidna call functions on ALL deployed contracts
allContracts: true
corpusDir: "corpus"
workers: 4
echidna test/SystemTest.sol --contract SystemTest --config echidna.yaml
Echidna works with Foundry project layouts. Set compilation args to use forge's remappings:
# echidna.yaml for a Foundry project
cryticArgs: ["--compile-force-framework", "foundry"]
corpusDir: "corpus"
testLimit: 50000
Alternatively, pass remappings explicitly:
cryticArgs: [
"--solc-remaps",
"@openzeppelin/=lib/openzeppelin-contracts/src/;forge-std/=lib/forge-std/src/"
]
project/
├── foundry.toml
├── echidna.yaml
├── src/
│ └── Token.sol
├── test/
│ ├── Token.t.sol # Foundry unit/fuzz tests
│ └── echidna/
│ └── TokenEchidna.sol # Echidna property tests
├── corpus/ # Echidna corpus (gitignore in CI, commit for shared campaigns)
└── lib/
└── forge-std/
# .github/workflows/security.yml
name: Security
on: [push, pull_request]
jobs:
foundry-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: foundry-rs/foundry-toolchain@v1
- run: forge test --fuzz-runs 10000
echidna:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Echidna
run: |
curl -L https://github.com/crytic/echidna/releases/latest/download/echidna-x86_64-linux.tar.gz | tar xz
sudo mv echidna /usr/local/bin/
- name: Install solc
run: |
pip3 install solc-select
solc-select install 0.8.28
solc-select use 0.8.28
- name: Run Echidna
run: echidna test/echidna/TokenEchidna.sol --contract TokenEchidna --config echidna.yaml
When Echidna finds a property violation, the raw failing sequence might be 50+ transactions. Shrinking iteratively removes and simplifies transactions to find the minimum reproducing case.
shrinkLimit)echidna_no_free_tokens: failed!
Call sequence:
mint(115792089237316195423570985008687907853269984665640564039457584007913129639935)
transfer(0x10000, 1)
Shrunk 47/50 times
This tells you: the original failing sequence was ~50 calls, but the minimal reproduction is just mint followed by transfer with specific arguments.
# More shrink attempts = cleaner reproducers, slower
shrinkLimit: 10000
# Fewer attempts = faster results, noisier reproducers
shrinkLimit: 1000
| Tool | Type | Strengths | Limitations |
|---|---|---|---|
| Slither | Static analysis | Fast (<30s), CI-friendly, low false positives | Cannot find state-dependent bugs |
| Mythril | Symbolic execution | Finds deep logic bugs, path exploration | Slow on large contracts, state explosion |
| Echidna | Property-based fuzzing | Stateful, coverage-guided, corpus reuse | Only as good as your properties |
| Foundry Fuzz | Fuzz testing | Fast, Solidity-native, cheatcodes | Single-function (not stateful sequences) |
| Halmos | Symbolic testing | Formal verification in Solidity | Early stage, limited EVM support |
| Certora | Formal verification | Mathematical proofs of correctness | Expensive, custom specification language |
| Semgrep | Pattern matching | Custom rules, fast CI scans | Surface-level, no execution semantics |
testFuzz_*)testLimit (500,000+) and long seqLen (200+)// BAD: this always returns true because Echidna calls it from a non-owner address
function echidna_only_owner_mints() public view returns (bool) {
return totalSupply() <= MAX_SUPPLY;
}
This property checks the effect (supply bounded) rather than the cause (unauthorized minting). If an attacker finds a way to mint without being owner but stays under MAX_SUPPLY, this property misses it.
// BETTER: track actual minting behavior
function echidna_unauthorized_cannot_mint() public view returns (bool) {
if (msg.sender != owner()) {
return totalSupply() == _supplyAtLastOwnerAction;
}
return true;
}
Echidna deploys the contract once and then sends many transaction sequences. If your constructor sets up state that makes properties trivially true, you are testing nothing:
// BAD: empty vault always passes solvency check
constructor() {
// no initial deposits
}
function echidna_solvent() public view returns (bool) {
return totalAssets() >= totalDebt(); // always 0 >= 0
}
Seed meaningful state in the constructor or use helper functions that Echidna can call to build up state.
Last verified: February 2026
docs/troubleshooting.md (opens in a new tab)examples/access-control-fuzzing/README.md (opens in a new tab)examples/config-tuning/README.md (opens in a new tab)examples/invariant-testing/README.md (opens in a new tab)examples/token-fuzzing/README.md (opens in a new tab)resources/config-reference.md (opens in a new tab)resources/error-codes.md (opens in a new tab)resources/property-patterns.md (opens in a new tab)templates/echidna-config.yaml (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
echidna, fuzzing, property-testing, solidity-security, trail-of-bits
Other plugins' skills for the same job
/echidna:echidnafrom echidna
npx claudepluginhub naruto11eth/cryptoskills --plugin echidna2 plugins ship this exact skill · first indexed Jul 19, 2026