Skip to content

Commit db31aa1

Browse files
roninjin10claude
andcommitted
✨ feat: implement complete Ethereum precompiles package with REVM integration
Implement all 12 Ethereum precompiled contracts (0x01-0x11) using a hybrid approach: **🦀 REVM-Wrapped Implementations (10 precompiles):** - ECRECOVER (0x01) - secp256k1 signature recovery - RIPEMD160 (0x03) - RIPEMD-160 hashing - MODEXP (0x05) - big integer modular exponentiation - BN128 operations (0x06-0x08) - elliptic curve math for ZK proofs - BLAKE2F (0x09) - BLAKE2b compression function - KZG_POINT_EVALUATION (0x0A) - EIP-4844 proto-danksharding support - BLS12_381 operations (0x0B-0x11) - advanced elliptic curve operations **⚡ Pure Zig Implementations (2 precompiles):** - SHA256 (0x02) - using std.crypto.hash.sha2.Sha256 - IDENTITY (0x04) - simple data passthrough operation **🔧 Technical Features:** - Complete C FFI wrapper around revm-precompile v22.0.0 - Comprehensive error handling with detailed error codes - Memory-safe malloc/free patterns for C interop - Full gas cost calculations per Ethereum specifications - Secure, audited foundation using battle-tested REVM implementations **📦 Core Files:** - src/precompiles/src/lib.rs - Main REVM wrapper with C FFI interface - src/precompiles/sha256.zig, identity.zig - Pure Zig implementations - src/precompiles/package.zig - Zig module integration - src/precompiles/rust_build.zig - Build system integration - Cargo.toml, build.rs, cbindgen.toml - Rust build configuration **🎯 EIP Coverage:** - Full EIP-4844 (proto-danksharding) support via KZG precompile - All mainnet-active precompiles from Frontier through Cancun - Future-ready with EIP-2537 BLS12-381 operations This provides a secure, audited foundation for all Ethereum precompiled contracts needed by the TEVM project, balancing performance and maintainability. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 5848323 commit db31aa1

File tree

12 files changed

+5105
-0
lines changed

12 files changed

+5105
-0
lines changed

build.zig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ pub fn build(b: *std.Build) void {
106106
});
107107
compiler_mod.addImport("zabi", zabi_dep.module("zabi"));
108108

109+
const precompiles_mod = b.createModule(.{
110+
.root_source_file = b.path("src/precompiles/package.zig"),
111+
.target = target,
112+
.optimize = optimize,
113+
});
114+
precompiles_mod.stack_check = false;
115+
precompiles_mod.single_threaded = true;
116+
109117
// Create a separate compiler module for WASM without problematic dependencies
110118
const compiler_wasm_mod = b.createModule(.{
111119
.root_source_file = b.path("src/compilers/compiler_wasm.zig"),
@@ -171,6 +179,7 @@ pub fn build(b: *std.Build) void {
171179
target_architecture_mod.addImport("Block", block_mod);
172180
target_architecture_mod.addImport("Bytecode", bytecode_mod);
173181
target_architecture_mod.addImport("Compiler", compiler_mod);
182+
target_architecture_mod.addImport("Precompiles", precompiles_mod);
174183
target_architecture_mod.addImport("evm", evm_mod);
175184
target_architecture_mod.addImport("Rlp", rlp_mod);
176185
target_architecture_mod.addImport("Token", token_mod);
@@ -298,6 +307,7 @@ pub fn build(b: *std.Build) void {
298307
lib_unit_tests.root_module.addImport("Block", block_mod);
299308
lib_unit_tests.root_module.addImport("Bytecode", bytecode_mod);
300309
lib_unit_tests.root_module.addImport("Compiler", compiler_mod);
310+
lib_unit_tests.root_module.addImport("Precompiles", precompiles_mod);
301311
lib_unit_tests.root_module.addImport("evm", evm_mod);
302312
lib_unit_tests.root_module.addImport("Rlp", rlp_mod);
303313
lib_unit_tests.root_module.addImport("Token", token_mod);

0 commit comments

Comments
 (0)