Skip to content

refactor: create crypto submodules for each precompile#3529

Open
jdh847 wants to merge 4 commits intobluealloy:mainfrom
jdh847:refactor/crypto-submodules
Open

refactor: create crypto submodules for each precompile#3529
jdh847 wants to merge 4 commits intobluealloy:mainfrom
jdh847:refactor/crypto-submodules

Conversation

@jdh847
Copy link
Copy Markdown

@jdh847 jdh847 commented Mar 29, 2026

Summary

Closes #2782

Creates a dedicated crypto.rs submodule for each precompile that has mixed runner + cryptographic code, isolating pure cryptographic implementations from EVM-specific precompile logic (gas accounting, input parsing, output formatting).

Changes per precompile:

  • secp256k1: Moved ecrecover_bytes and cfg_if! backend selection (k256 vs bitcoin_secp256k1) into secp256k1/crypto.rs
  • secp256r1: Moved verify_signature and feature-gated implementations (p256 vs aws-lc-rs) into secp256r1/crypto.rs
  • blake2: Moved the entire algo module (SIGMA, IV, G function, compress, round) and AVX2 optimized variant into blake2/crypto.rs
  • modexp: Moved modexp function (GMP + aurora-engine-modexp fallback) into modexp/crypto.rs

Not changed (already separated):

  • bn254: Already has arkworks.rs/substrate.rs as crypto_backend
  • bls12_381: Already has arkworks.rs/blst.rs as crypto_backend
  • kzg_point_evaluation: Already has arkworks.rs/blst.rs as crypto_backend
  • hash: Crypto lives entirely in the Crypto trait default implementations (thin wrappers around sha2/ripemd crates)

Design decisions:

  • No API changes — all existing paths (e.g., crate::secp256k1::ecrecover_bytes) still work via re-exports
  • One commit per precompile for easy review
  • Crypto trait in interface.rs unchanged — default implementations still delegate to the same functions
  • Backward-compatible re-export pub use crypto::algo in blake2 preserves the blake2::algo::compress path

Test plan

  • cargo check -p revm-precompile — compiles clean
  • cargo clippy -p revm-precompile --all-targets --all-features — no warnings
  • cargo test -p revm-precompile — 52 tests pass, 0 failures

jdh847 added 4 commits March 29, 2026 11:17
Move `ecrecover_bytes` and the backend selection (`cfg_if!` for
k256 vs bitcoin_secp256k1) into a dedicated `crypto.rs` submodule,
separating pure cryptographic logic from the precompile runner.

Closes part of bluealloy#2782
Move `verify_signature` and its feature-gated implementations
(p256 vs aws-lc-rs) into a dedicated `crypto.rs` submodule,
separating pure cryptographic logic from the precompile runner.

Closes part of bluealloy#2782
Move the BLAKE2b compression algorithm (`algo` module with SIGMA,
IV, G function, compress, round) and the AVX2 optimized variant
into a dedicated `crypto.rs` submodule, separating pure
cryptographic logic from the precompile runner.

Closes part of bluealloy#2782
Move the `modexp` function (both GMP and aurora-engine-modexp
fallback implementations) into a dedicated `crypto.rs` submodule,
separating pure cryptographic logic from the precompile runner
and gas calculation code.

Closes bluealloy#2782
@jdh847 jdh847 force-pushed the refactor/crypto-submodules branch from e283fa6 to dfb5425 Compare March 29, 2026 10:26
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.

Create a crypto submodule for each precompile

1 participant