|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Revive Differential Tests is a differential testing framework for Ethereum-compatible smart contract stacks. It compiles and executes declarative smart-contract tests against multiple platforms (Geth, Revive Dev Node, Zombienet, Polkadot Omni Node) and compares their behavior (status, return data, events, state diffs). |
| 8 | + |
| 9 | +The test corpus lives in a separate repository: [resolc-compiler-tests](https://github.com/paritytech/resolc-compiler-tests) and is included as a git submodule. |
| 10 | + |
| 11 | +## Build and Test Commands |
| 12 | + |
| 13 | +```bash |
| 14 | +# Build release binary |
| 15 | +cargo build --release |
| 16 | + |
| 17 | +# Install retester and report-processor binaries |
| 18 | +cargo install --path crates/core |
| 19 | +cargo install --path crates/report-processor |
| 20 | + |
| 21 | +# Run unit tests |
| 22 | +cargo make test |
| 23 | + |
| 24 | +# Linting and formatting |
| 25 | +cargo make fmt-check # Check formatting |
| 26 | +cargo make clippy # Run clippy with --deny warnings |
| 27 | +cargo make machete # Check for unused dependencies |
| 28 | +``` |
| 29 | + |
| 30 | +## Running Differential Tests |
| 31 | + |
| 32 | +### Full Test Suite (PolkaVM with Resolc) |
| 33 | + |
| 34 | +This is how the polkadot-sdk CI runs tests: |
| 35 | + |
| 36 | +```bash |
| 37 | +retester test \ |
| 38 | + --test ./resolc-compiler-tests/fixtures/solidity/simple \ |
| 39 | + --test ./resolc-compiler-tests/fixtures/solidity/complex \ |
| 40 | + --test ./resolc-compiler-tests/fixtures/solidity/translated_semantic_tests \ |
| 41 | + -p revive-dev-node-polkavm-resolc \ |
| 42 | + --report.file-name report.json \ |
| 43 | + --concurrency.number-of-nodes 10 \ |
| 44 | + --concurrency.number-of-threads 10 \ |
| 45 | + --concurrency.number-of-concurrent-tasks 100 \ |
| 46 | + --working-directory ./workdir \ |
| 47 | + --revive-dev-node.consensus manual-seal-200 \ |
| 48 | + --resolc.heap-size 528000 \ |
| 49 | + --resolc.stack-size 128000 |
| 50 | +``` |
| 51 | + |
| 52 | +### Important Resolc Parameters |
| 53 | + |
| 54 | +| Parameter | Default | Description | |
| 55 | +|-----------|---------|-------------| |
| 56 | +| `--resolc.heap-size` | 131072 | Emulated EVM heap memory buffer size in bytes. Increase for tests accessing large memory offsets. | |
| 57 | +| `--resolc.stack-size` | 131072 | Contract stack size in bytes. | |
| 58 | +| `--resolc.path` | (from PATH) | Path to resolc binary. | |
| 59 | + |
| 60 | +**Critical:** These are **compile-time** settings embedded in the PVM bytecode. Changing them requires clearing the compilation cache (see Troubleshooting). |
| 61 | + |
| 62 | +### Test Specifiers |
| 63 | + |
| 64 | +```bash |
| 65 | +# Run all tests in a directory |
| 66 | +-t ./resolc-compiler-tests/fixtures/solidity/simple |
| 67 | + |
| 68 | +# Run specific test file |
| 69 | +-t path/to/test.sol |
| 70 | + |
| 71 | +# Run specific case within a metadata file (case_idx is 0-indexed) |
| 72 | +-t path/to/metadata.json::0 |
| 73 | + |
| 74 | +# Run specific case with specific mode |
| 75 | +-t path/to/metadata.json::0::Y\ M0 |
| 76 | +``` |
| 77 | + |
| 78 | +### Report Processing |
| 79 | + |
| 80 | +```bash |
| 81 | +# Generate expectations file from test report |
| 82 | +report-processor generate-expectations-file \ |
| 83 | + --report-path ./workdir/report.json \ |
| 84 | + --output-path expectations.json \ |
| 85 | + --remove-prefix ./resolc-compiler-tests \ |
| 86 | + --include-status failed |
| 87 | +``` |
| 88 | + |
| 89 | +## Supported Platforms |
| 90 | + |
| 91 | +| Platform CLI Name | Description | |
| 92 | +|-------------------|-------------| |
| 93 | +| `geth-evm-solc` | Go-Ethereum reference EVM + Solc | |
| 94 | +| `lighthouse-geth-evm-solc` | Geth with Lighthouse consensus + Solc | |
| 95 | +| `revive-dev-node-polkavm-resolc` | Substrate PolkaVM + Resolc | |
| 96 | +| `revive-dev-node-revm-solc` | Substrate REVM + Solc | |
| 97 | +| `zombienet-polkavm-resolc` | Zombienet Substrate + Resolc | |
| 98 | +| `zombienet-revm-solc` | Zombienet REVM + Solc | |
| 99 | +| `polkadot-omni-node-polkavm-resolc` | Polkadot Omni Node + Resolc | |
| 100 | +| `polkadot-omni-node-revm-solc` | Polkadot Omni Node + Solc | |
| 101 | + |
| 102 | +## Architecture |
| 103 | + |
| 104 | +The project is a Rust workspace (edition 2024, MSRV 1.87.0) with crates in `/crates/`: |
| 105 | + |
| 106 | +- **core** (`retester` binary) - Main test runner and orchestrator |
| 107 | +- **config** - CLI argument parsing via Clap; defines `Context` enum (Test, Benchmark, ExportJsonSchema, ExportGenesis) |
| 108 | +- **format** - Declarative test definition format based on MatterLabs; includes `gas_overrides` support for platform-specific gas limits |
| 109 | +- **common** - Shared types including `PlatformIdentifier`, `ParsedTestSpecifier`, `Mode`, `ParsedMode` |
| 110 | +- **compiler** - Compilation abstraction for Solc and Resolc compilers |
| 111 | + - `revive_resolc.rs`: Uses `SolcStandardJsonInputSettingsSelection::new_required_for_tests()` to request `evm.bytecode` output (required for resolc 0.6.0+) |
| 112 | +- **node** - Platform/node implementations in `src/node_implementations/` |
| 113 | +- **node-interaction** - Transaction submission, gas estimation via alloy, receipt waiting |
| 114 | + - `fallback_gas_filler.rs`: Handles gas estimation for reverting transactions using debug traces |
| 115 | +- **report** - Test result aggregation and reporting (JSON format) |
| 116 | +- **report-processor** - Secondary binary for post-execution report analysis |
| 117 | +- **solc-binaries** - Solc compiler binary caching and downloads |
| 118 | + |
| 119 | +## Test Format |
| 120 | + |
| 121 | +Tests use the MatterLabs format with metadata either as JSON files or inline Solidity comments: |
| 122 | + |
| 123 | +``` |
| 124 | +Corpus (directory) |
| 125 | +└── Metadata (JSON file or Solidity with inline comments) |
| 126 | + └── Case (individual test) |
| 127 | + ├── targets (optional): filter to specific platforms |
| 128 | + ├── modes (optional): restrict to specific compiler modes (e.g., ["E-"] for EVM assembly only) |
| 129 | + ├── gas_overrides (optional): platform-specific hardcoded gas limits |
| 130 | + └── Steps |
| 131 | + ├── Transaction steps with assertions |
| 132 | + └── State assertions (balances, storage) |
| 133 | +``` |
| 134 | + |
| 135 | +### Gas Overrides |
| 136 | + |
| 137 | +For tests that fail gas estimation (e.g., due to `consume_all_gas` behavior in resolc), use `gas_overrides`: |
| 138 | + |
| 139 | +```json |
| 140 | +{ |
| 141 | + "method": "test", |
| 142 | + "calldata": ["0x100000000"], |
| 143 | + "gas_overrides": { |
| 144 | + "revive-dev-node-polkavm-resolc": { |
| 145 | + "gas_limit": 10000000 |
| 146 | + } |
| 147 | + } |
| 148 | +} |
| 149 | +``` |
| 150 | + |
| 151 | +## External Dependencies |
| 152 | + |
| 153 | +**Always required:** |
| 154 | +- Solc (Solidity compiler) - auto-downloaded but resolc needs it in PATH |
| 155 | + |
| 156 | +**Platform-specific:** |
| 157 | +| Platform | Required Tools | |
| 158 | +|----------|----------------| |
| 159 | +| `geth-evm-solc` | Geth | |
| 160 | +| `lighthouse-geth-evm-solc` | Geth, Kurtosis, Docker | |
| 161 | +| `revive-dev-node-*` | revive-dev-node, eth-rpc | |
| 162 | +| `zombienet-*` | Zombienet SDK binaries | |
| 163 | +| `polkadot-omni-node-*` | polkadot-omni-node, eth-rpc | |
| 164 | + |
| 165 | +**For PolkaVM platforms:** Resolc compiler |
| 166 | + |
| 167 | +## Troubleshooting |
| 168 | + |
| 169 | +### Clearing the Compilation Cache |
| 170 | + |
| 171 | +Compilation artifacts are cached in the working directory. If you change compiler settings (like `--resolc.heap-size`), you must clear the cache: |
| 172 | + |
| 173 | +```bash |
| 174 | +rm -rf ./workdir |
| 175 | +``` |
| 176 | + |
| 177 | +### Common Issues |
| 178 | + |
| 179 | +1. **"Failed to find information for contract"** - The resolc output selection doesn't include bytecode. Ensure `crates/compiler/src/revive_resolc.rs` uses `new_required_for_tests()` instead of `new_required()`. |
| 180 | + |
| 181 | +2. **"OutOfGas" errors on tests with large memory offsets** - Increase `--resolc.heap-size` (e.g., to 528000) and clear the compilation cache. |
| 182 | + |
| 183 | +3. **"ContractTrapped" on memory access** - The contract is accessing memory beyond the configured heap size. Increase `--resolc.heap-size`. |
| 184 | + |
| 185 | +4. **Tests failing after changing resolc parameters** - Clear the compilation cache (`rm -rf ./workdir`) to force recompilation. |
| 186 | + |
| 187 | +5. **Gas estimation failures for reverting transactions** - The test may need `gas_overrides` in the test metadata to specify a hardcoded gas limit. |
| 188 | + |
| 189 | +## Updating the Test Submodule |
| 190 | + |
| 191 | +```bash |
| 192 | +git submodule update --init --remote resolc-compiler-tests |
| 193 | +``` |
0 commit comments