✨ feat: Add fork-state host with RPC integration and 3-tier caching#22
Open
roninjin10 wants to merge 231 commits intomainfrom
Open
✨ feat: Add fork-state host with RPC integration and 3-tier caching#22roninjin10 wants to merge 231 commits intomainfrom
roninjin10 wants to merge 231 commits intomainfrom
Conversation
feat: Improve CREATE/CREATE2 with collision detection and logging system
chore: fix typo in build comment
Add complete MODEXP (modular exponentiation) precompile implementation: - Parse base_length, exp_length, mod_length from input - Calculate gas cost using complexity and iteration formulas - Implement modular exponentiation with u256 support - Handle edge cases (modulus=0, empty inputs) - Support for values up to 32 bytes 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Copy entire crypto/ directory with modexp, blake2, bn254, secp256k1, etc. - Copy precompiles/ directory with all EVM precompile implementations - Copy lib/ directory with Rust FFI bindings (ark, c-kzg-4844, etc.) - Add build_options module for vector_length configuration - Wire crypto and precompiles modules into build system This brings full precompile support from the main guillotine implementation including MODEXP, BLAKE2F, BN254 curves, and KZG point evaluation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
…es module - Remove ~250 lines of inline precompile code from evm.zig - Use precompiles.execute_precompile() for all precompile calls - Add precompiles module import to evm.zig - Add build_options module to build.zig for vector_length config - Wire precompiles module into main guillotine_mini module This brings full precompile support including MODEXP, BLAKE2F, BN254, ECRECOVER, SHA256, RIPEMD160, Identity, and all other EVM precompiles. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Change precompiles import to use relative path in evm.zig - Update precompiles.zig and kzg_setup.zig to use relative crypto imports - Add trusted_setup.txt file for KZG support - Add inline build_options struct in precompiles.zig Still need to resolve c_kzg module dependencies in crypto/root.zig. The crypto module has many external dependencies that need to be properly configured in the build system. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Add Rust workspace configuration and integrate BLST, C-KZG, and BN254 library support into the Zig build system. Enables cryptographic precompiles for EIP-196/197 (BN254) and EIP-4844 (KZG) support. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Provide fallback stub implementations for BLS12-381 and KZG operations when native crypto libraries are not available. Enables compilation and testing of non-cryptographic hardforks without full dependencies. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Replace relative imports with module imports to support the new build system configuration. Enables proper module resolution for crypto and build_options dependencies in precompiles. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Update Berlin attempt report with build configuration challenges and current blockers. Clarifies that Berlin tests don't require BLS12-381 or BN254 precompiles and recommends focusing on EIP-2929/2930 implementation. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Lock Rust dependency versions to ensure consistent builds across different environments and prevent unexpected dependency updates. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Added comprehensive documentation of the Berlin test suite fixes, including root cause analysis and solution details for the 28 failing intrinsic gas validation tests. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add CREATE/CREATE2 collision detection per EIP-684 - Implement proper EIP-6780 SELFDESTRUCT behavior - Fix Berlin hardfork gas calculations for SELFDESTRUCT - Add setCode method to host interface - Remove debug prints from CREATE2 implementation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Fix Cancun hardfork EIP-6780 SELFDESTRUCT and CREATE collision handling
…ation - Fix return_data semantics: empty on success, output on failure - Add precompile pre-warming for Berlin+ forks - Improve CREATE collision detection and nonce handling - Add output capture for failed contract creation - Fix gas refund calculations in inner_create 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add OSAKA hardfork enum variant - Implement EIP-7883 ModExp gas calculation changes - Update complexity formula for inputs <= 32 bytes - Adjust minimum gas to 500 and divisor to 1 - Add hardfork string parsing for Osaka 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add detailed analysis of CREATE2 test failures - Document gas discrepancy investigation (~147k-516k gas) - Explain blockchain_tests vs state_tests differences - Summarize fixes: collision detection, nonce handling, return_data - Note remaining issues with Berlin+ fork state tests 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
🐛 fix: Improve CREATE/CREATE2 handling and add Osaka hardfork support
Switch blst library to portable C implementation to fix point_evaluation precompile failures. The assembly build was causing issues with the KZG cryptographic operations required for EIP-4788. Key changes: - Remove assembly build dependency from blst - Use __BLST_NO_ASM__ flag to force C implementation - Define llimb_t=__uint128_t to work around blst 64-bit platform bug - Add vect.c to c-kzg-4844 build for completeness This resolves test failures in the Cancun hardfork beacon block root validation tests. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Documents successful resolution of blst compilation issues on ARM64 platforms enabling all 260 Cancun EIP-4788 beacon root tests to pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
fix: Pass Cancun EIP-4788 beacon root tests
Fixed two critical issues preventing Homestead tests from passing: 1. DELEGATECALL hardfork guard - Added check to prevent DELEGATECALL (0xf4) execution before Homestead, as it was introduced by EIP-7 2. Gas forwarding rules - Implemented correct gas forwarding behavior: - Before EIP-150 (Frontier, Homestead): Forward 100% of remaining gas - After EIP-150 (Tangerine Whistle+): Forward 63/64 of remaining gas Applied to CREATE, CALL, CALLCODE, DELEGATECALL, CREATE2, STATICCALL 3. Build configuration - Fixed blst library build to use portable mode without assembly, resolving architecture-specific compilation issues All 24 Homestead tests now pass (10 blockchain, 4 engine, 10 state). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
feat: Homestead hardfork implementation and EVM fixes
Reordered test suite execution to prioritize Paris/Merge hardfork tests, which are now passing. This ensures the test runner executes test suites in a more logical order with recently fixed tests appearing first. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Fix stack pop order: dest, src, len (was incorrectly src, dest, len) - Improve memory expansion to cover both source and destination ranges - Add missing GasFastestStep base gas cost per EIP-5656 - Optimize zero-length copy gas calculation to skip memory expansion 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Update test components to support state/blockchain test separation: - Enhance test runner to handle different test types - Update test host implementation for improved spec compliance - Ensure compatibility with new test generation pipeline - Maintain test execution performance and accuracy 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit fixes all 310 Cancun EIP-4844 blob precompile point evaluation basic tests by addressing two critical issues: **Issue 1: Missing precompile handling in transaction entry point** When transactions targeted precompile addresses directly (not via CALL opcodes), the call() function retrieved empty bytecode and returned immediately without executing the precompile. This caused 12 test failures in the tx_entry_point test suite with 500,000 gas undercharge. Fix: Added precompile detection and execution logic to call() in src/evm.zig (lines 382-474), mirroring the existing logic in inner_call(). Now properly: - Detects precompile addresses when bytecode is empty - Executes precompiles via precompiles.execute_precompile() - Handles gas accounting and transaction-scoped state cleanup - Supports both transaction-level and opcode-level precompile calls **Issue 2: Incorrect gas forwarding on insufficient gas in CALL opcodes** The CALL/CALLCODE/DELEGATECALL/STATICCALL opcodes incorrectly forwarded min(gas_param, max_allowed_gas) even when the caller had insufficient gas to cover the base operation cost. Per Python execution-specs (gas.py:232-237), when gas_left < cost, the full stack gas parameter should still be charged. Fix: Modified gas forwarding logic in src/frame.zig for all CALL-family opcodes to forward the full stack gas parameter when insufficient gas is available, matching Python reference behavior. **Additional fixes:** - EXTCODESIZE: Now returns actual code length instead of hardcoded 0 - EXTCODEHASH: Now returns correct keccak256(code) or 0 for empty accounts Result: All 310 tests now pass (previously 298 passing, 12 failing) EIP-4844: https://eips.ethereum.org/EIPS/eip-4844 Test suite: execution-spec-tests/tests/cancun/eip4844_blobs/point_evaluation_precompile 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Added cancun-blob-precompile-basic-attempt2 report documenting the fix - Added QUICK_TEST_REFERENCE for common test commands and patterns - Added TEST_TYPE_SEPARATION documenting build system test organization 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Add configurable filtering to exclude consensus-layer blockchain_test_engine format tests by default, keeping them available via INCLUDE_ENGINE_TESTS=1. Engine API tests validate block-level concerns (consensus layer) rather than core EVM execution, making them out-of-scope for an EVM library like guillotine-mini (similar to REVM's scope). This improves test signal by focusing on ~11,500 relevant EVM tests vs ~900 consensus-layer tests. Changes: - Add Config struct with environment variable detection - Detect engine tests by engineNewPayloads field or path patterns - Return SkipZigTest error when engine tests disabled (default) - Add hardfork guards to preWarmTransaction for clarity - Improve EIP comments for address pre-warming logic Usage: - Default: zig build test (skips engine tests) - Optional: INCLUDE_ENGINE_TESTS=1 zig build test (includes all) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Document the new engine test filtering system with detailed explanations of scope, usage, and rationale. Engine API tests validate consensus-layer functionality rather than EVM execution, so they're disabled by default but available via INCLUDE_ENGINE_TESTS=1 for comprehensive testing. Additions: - ENGINE_TESTS.md: Complete guide explaining Engine API vs EVM scope, test counts (~11,500 EVM vs ~900 engine), usage examples, and future considerations for full node functionality - CLAUDE.md: Updated test types table and added "Test Scope and Filtering" section explaining default behavior and opt-in comprehensive testing This clarifies guillotine-mini's position as an EVM library (like REVM) rather than a full node (like Reth), improving test clarity and focus on core EVM execution validation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Clean up build system by removing blake2 module references and deleting unused implementation file. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add embedded trusted setup data in src/kzg/trusted_setup.zig - Update c_kzg bindings to use embedded setup instead of file loading - Improve KZG setup initialization with embedded data - Remove file-based trusted setup dependency for better portability 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Fix EVM implementation cleanup and balance restoration logic - Add new EVM test suite in src/evm_test.zig - Fix test runner variable name (evm_module -> evm_mod) - Update root module to include new test file 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Replace Address.Address with primitives.Address throughout codebase - Improve error propagation in nested call operations - Enhance memory allocation error handling in EVM snapshots - Update instruction handlers for type consistency 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Improve comment formatting and alignment - Standardize whitespace and indentation - Enhance code readability with consistent formatting - Apply consistent style across crypto, EVM, frame, and primitive modules 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Replace unsafe `catch {}` patterns with proper error handling and propagation.
- Remove silent error suppression in EVM transient storage restoration
- Propagate tracing errors properly in Frame execution
- Add meaningful error messages for trace generation failures
- Ensure all utility function errors are handled and propagated
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Move std import to top of file to follow consistent import ordering conventions. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Enhance KZG trusted setup error handling with specific error type checking and remove unused test host functionality. - Only ignore TrustedSetupNotLoaded errors during cleanup - Add panic for unexpected KZG cleanup errors - Remove unused innerCall vtable function from test host - Improve test robustness and error diagnostics 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…d modules - Add new Storage module to consolidate storage operations and caching - Introduce AccessListManager for EIP-2929/EIP-2930 warm/cold tracking - Refactor EVM to use unified storage and access list abstractions - Update instruction handlers to work with new storage architecture - Adapt C API and tests to new storage interfaces 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add explicit rule against creating .backup, .bak, .old files - Emphasize using git branches/stashes for version control instead - Prevents accumulation of temporary backup files in the repository 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Remove ENGINE_TESTS.md (no longer needed) - Remove QUICK_TEST_REFERENCE.md (outdated reference) - Remove TEST_TYPE_SEPARATION.md (consolidated into CLAUDE.md) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…cated modules - Create AsyncExecutor struct to encapsulate async execution patterns - Extract Storage abstraction layer to handle all EVM state management - Refactor EVM to use Storage module and delegate async execution to AsyncExecutor - Add support for yield/resume semantics for async data requests 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Update consumeGas to check config.enable_gas_checks - Update memoryExpansionCost to return 0 when gas checks disabled - Enable noop behavior for gas operations when configured 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Enhance frame execution and opcode implementations - Fix precompile gas calculations and spec compliance - Update gas constants for hardfork-specific behavior - Improve C API integration and memory management 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Enhance spec test runner with better gas calculation for access lists - Update test host interface to support new storage abstraction - Improve test infrastructure compatibility with async execution patterns 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit fixes two critical bugs that were preventing EIP-4844 blob transaction tests from passing, bringing the implementation into full compliance with the Ethereum execution specification for this test suite. Bug 1: Incorrect upfront balance validation for EIP-1559/EIP-4844 - Root cause: Used effective gas price instead of maximum gas price for upfront balance checks, violating EIP-1559 and EIP-4844 specifications - Fix: Track max_fee_per_gas and max_fee_per_blob_gas separately from effective prices for validation, ensuring transactions are rejected if sender cannot afford worst-case gas costs - Impact: Prevents transactions that would fail mid-execution due to insufficient funds Bug 2: Value transfer failing for zero execution gas transactions - Root cause: When intrinsic gas consumed all available gas (execution_gas=0), EVM validation rejected calls before value transfer could occur - Fix: Handle value transfer in test runner before EVM call when execution_gas=0, matching Ethereum specification behavior - Impact: Value transfers now succeed even when no gas remains for execution Additional improvements: - Fix CALL-family opcode gas accounting to match Python reference spec - Add thread-safe KZG proof verification wrapper for concurrent tests - Fix PUSH0 gas cost (2 gas vs 3 gas for PUSH1-PUSH32) - Correct pre-Tangerine Whistle CALL base gas cost (40 vs 700) Test Results: - Before: 480 failures (1440 total tests) - After: 0 failures (1440 total tests) ✅ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
…tiple opcodes Root cause: PUSH0 (EIP-3855) was incorrectly accepted in all hardforks, causing execution path divergence and balance mismatches in pre-Shanghai forks. Additionally, several opcodes had implementation issues. Key changes: - Add hardfork guard for PUSH0 (0x5f) - reject in forks before Shanghai - Fix EXTCODECOPY to actually copy external code instead of writing zeros - Fix RETURNDATACOPY to update memory_size after expansion - Fix CALL/STATICCALL gas accounting to refund unused gas (not subtract used) - Fix SELFDESTRUCT balance transfer order and EIP-2929 access list handling This brings the implementation into full compliance with the Homestead hardfork specification across all subsequent forks. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Fix SELFDESTRUCT beneficiary cold access cost calculation. The bug was using preWarmAddresses() which had side effects on gas calculation timing. Changed to directly use warm_addresses.getOrPut() to match Python reference implementation behavior where the beneficiary is marked warm before charging the cold access cost. EIP-6780 restricts SELFDESTRUCT behavior post-Cancun, and correct gas accounting for beneficiary access is critical for collision scenarios. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Implements lazy-fetch blockchain state from remote RPC endpoints with a 3-tier caching strategy (local → fork cache → RPC). Supports both WASM and native builds with user-injectable RPC request function. Architecture: - **json_rpc.zig**: JSON-RPC builders/parsers for eth_getStorageAt, eth_getBalance, eth_getCode, eth_getTransactionCount - **fork_host.zig**: ForkHost implementation with local cache (mods), fork cache (pristine), and RPC fallback - **root_c.zig**: WASM integration via extern js_rpc_request callback and evm_set_fork_config() C API export - **test_host.zig**: Moved from test/specs/ to src/host/ for consistency References TEVM monorepo architecture (packages/state/src) while adapting to Zig idioms and vtable-based host interface. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Architecture
Core Components
src/host/json_rpc.zig - JSON-RPC request builders and response parsers
buildGetStorageAtParams()/parseStorageResponse()buildGetBalanceParams()/parseBalanceResponse()buildGetCodeParams()/parseCodeResponse()buildGetTransactionCountParams()/parseNonceResponse()src/host/fork_host.zig - Fork-enabled host with 3-tier caching
local_*maps: Modified state during EVM executionfork_cache_*maps: Pristine remote data (immutable)src/host/test_host.zig - In-memory test host (moved from test/specs/)
src/root_c.zig - WASM integration
extern "env" fn js_rpc_request()- JavaScript callbackexport fn evm_set_fork_config()- Configure fork block and RPCwasmRpcRequest()- Wrapper for calling JavaScriptWASM Integration Pattern
Usage (WASM)
Test Plan
Files Changed
src/host/json_rpc.zig- 412 lines (new)src/host/fork_host.zig- 525 lines (new)src/host/test_host.zig- 191 lines (moved from test/specs/)src/root_c.zig- +139 lines (WASM integration)src/root.zig- +2 lines (test imports)CLAUDE.md- +26 lines (test filtering docs)🤖 Generated with Claude Code