This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This repository by Trail of Bits provides 168 pre-made Solidity property tests for fuzz testing smart contracts with Echidna or Medusa. It covers:
- ERC20 tokens (25 properties)
- ERC721 tokens (19 properties)
- ERC4626 vaults (37 properties)
- ABDKMath64x64 fixed-point library (106 properties)
Root level (Foundry):
forge build # Compile contractsRoot level (Hardhat):
npm install # Install dependencies
npm run compile # Compile contractsLinting and formatting:
npm run format # Format code with Prettier
npm run lint # Check formatting and markdown linksTests are organized in tests/<standard>/<framework>/ directories (e.g., tests/ERC20/foundry/).
Echidna (from root directory):
# Internal testing
# ERC20
echidna tests/ERC20/foundry/test/CryticTest.sol --contract CryticERC20InternalHarness --config tests/ERC20/foundry/echidna-config.yaml
# ERC721
echidna tests/ERC721/foundry/test/CryticTest.sol --contract CryticERC721InternalHarness --config tests/ERC721/foundry/echidna-config.yaml
# ERC4626
echidna tests/ERC4626/foundry/test/CryticTest.sol --contract CryticERC4626InternalHarness --config tests/ERC4626/foundry/echidna.yaml
# External testing
# Use similar command structure, pointing to external harness contract and configMedusa (from root directory):
# Build first
forge build --build-info
# Run fuzzer
medusa fuzz --target-contracts CryticERC20InternalHarness --config tests/ERC20/foundry/medusa-config.jsoncontracts/- Property contracts by standardERC20/,ERC721/,ERC4626/- Each split intointernal/andexternal/testingMath/ABDKMath64x64/- Fixed-point math propertiesutil/- Helper functions (PropertiesHelper.sol, Hevm.sol, PropertiesConstants.sol)
tests/- Example test harnesses for Foundry and HardhatPROPERTIES.md- Complete property reference table
Internal testing: Test contract inherits from both the token and property contracts. Properties access internal state directly.
External testing: Separate harness contract interacts with token through its external interface. Requires allContracts: true in Echidna config.
- Harness contracts inherit from
CryticERC*Propertiesand initialize test state (mint to USER1, USER2, USER3) - PropertiesConstants provides standard addresses:
USER1=0x10000,USER2=0x20000,USER3=0x30000,INITIAL_BALANCE=1000e18 - PropertiesHelper provides
assertEq,assertWithMsg,clampBetween, andLogXxxevents for debugging - Echidna/Medusa configs use assertion mode (
testMode: assertion) with deployer0x10000
- Add property to appropriate file in
contracts/<standard>/internal/properties/andexternal/properties/ - For external properties, update the interface in
contracts/<standard>/util/ - Add test in
contracts/<standard>/*/test/to verify property catches violations - Update
PROPERTIES.mdtable - Update
contracts/<standard>/README.mdif present
- Features:
dev-<description>(e.g.,dev-add-properties-for-erc20-transfers) - Bug fixes:
fix-<description>(e.g.,fix-typo-in-readme)