This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Echidna is a Haskell-based smart contract fuzzer designed for property-based testing of Ethereum smart contracts. It uses sophisticated grammar-based fuzzing campaigns to find bugs and verify invariants in Solidity code.
# Enter the Nix development shell first
nix develop
# Build the project using Cabal
cabal build
# Build with profiling enabled (for performance debugging)
cabal --enable-profiling build# Run the full test suite
cabal run tests
# Run tests in a specific directory context
cabal test# Run Echidna on a contract
cabal run echidna -- contract.sol
# Run with config file
cabal run echidna -- contract.sol --config config.yaml
# Run with profiling for performance analysis
cabal --enable-profiling run echidna -- contract.sol +RTS -p -s- Uses Nix for dependency management and development environment
- Primary build system is Cabal (not Stack, despite stack.yaml presence)
- Important: Always work inside
nix developshell for consistent environment
- lib/Echidna.hs: Main entry point for contract preparation and setup
- lib/Echidna/Campaign.hs: Fuzzing campaign logic and execution
- lib/Echidna/Types/: Core type definitions (Config, Test, Tx, World, etc.)
- lib/Echidna/Solidity.hs: Solidity compilation and contract handling
- lib/Echidna/ABI.hs: ABI encoding/decoding for transaction generation
- Contract Preparation (
prepareContract): Compiles contracts, extracts tests, creates VM - Test Generation: Uses Slither for static analysis to guide fuzzing
- Campaign Execution: Generates random transaction sequences to test invariants
- Coverage Analysis: Tracks code coverage to guide fuzzing toward unexplored paths
- Uses Tasty for test organization
- Tests are located in
src/test/Tests/ - Integration tests in
tests/solidity/cover various Solidity patterns - Test runner automatically changes to
./tests/soliditydirectory
- YAML-based configuration files (see
tests/solidity/basic/default.yaml) - Main config types in
lib/Echidna/Types/Config.hs - Supports campaign, UI, transaction, and Solidity-specific settings
Imports should be organized into three groups, separated by blank lines, with imports alphabetically ordered within each group:
- System and 3rd-party imports: Standard library and external dependencies (alphabetically ordered)
- EVM imports: Modules from
hevm(e.g.,EVM.*,EVM.Types.*) (alphabetically ordered) - Echidna imports: Internal modules from this project (e.g.,
Echidna.*) (alphabetically ordered)
Example:
import Control.Monad (when)
import Data.Text (Text)
import EVM (VM)
import EVM.Types (Addr)
import Echidna.ABI (genAbiCall)
import Echidna.Types.Campaign (Campaign)- The project uses GHC2021 language standard with several extensions enabled
- Profiling builds available for performance analysis of fuzzing campaigns
- Static analysis integration with Slither for enhanced test generation
- Supports multiple output formats (text, JSON, interactive UI)