Skip to content

feat: Replace Python IO with Rust FFI#83

Open
samuelburnham wants to merge 2 commits intoNethermindEth:mainfrom
argumentcomputer:rust-ffi
Open

feat: Replace Python IO with Rust FFI#83
samuelburnham wants to merge 2 commits intoNethermindEth:mainfrom
argumentcomputer:rust-ffi

Conversation

@samuelburnham
Copy link
Copy Markdown

@samuelburnham samuelburnham commented Mar 24, 2026

This PR replaces Python IO calls with faster/safer Rust FFI using https://docs.rs/revm-precompile/32.1.0/revm_precompile/ for the Rust backend and https://github.com/argumentcomputer/lean-ffi for a safe API over rust-bindgen bindings to the lean.h C library.

If this approach is of interest, we can replace the rest of the Python calls with FFI to https://github.com/bluealloy/revm.

I wasn't sure if Python or C was being used for blake2, Sha256, and Keccak, so I replaced both blake2 Python and C with Rust as a proof of concept for now. There is less benefit to replacing C with Rust, but the latter still produces simpler/less error-prone code. The Rust API has typed wrappers to distinguish owned from borrowed Lean references, and Clone/Drop implementations handle ref counting automatically instead of requiring manual lean_inc/lean_dec calls.

I also added a small test filtering helper to run e.g. just ripemd tests with

  lake exe conform \
    static_CallRipemd160_1_d0g0v0_Cancun \
    static_CallRipemd160_2_d0g0v0_Cancun \
    static_CallRipemd160_3_d0g0v0_Cancun \
    CALLCODERipemd160_0_d0g0v0_Cancun

where the test names were grepped from the Ethereum tests JSONs such as static_CallRipemd160_1.json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant