Skip to content

Conversation

@ilitteri
Copy link
Contributor

@ilitteri ilitteri commented Oct 17, 2025

Caution

We are currently testing this PR with snapsync, do not merge yet.

@ilitteri ilitteri self-assigned this Oct 17, 2025
@ilitteri ilitteri requested a review from a team as a code owner October 17, 2025 16:06
@Copilot Copilot AI review requested due to automatic review settings October 17, 2025 16:06
@github-actions github-actions bot added the L1 Ethereum client label Oct 17, 2025
@github-actions
Copy link

Lines of code report

Total lines added: 41
Total lines removed: 0
Total lines changed: 41

Detailed view
+------------------------------------------+-------+------+
| File                                     | Lines | Diff |
+------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/precompiles.rs | 1585  | +41  |
+------------------------------------------+-------+------+

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Reintroduces the ECRECOVER precompile for L1 using the secp256k1 crate when not building with the sp1 feature, while retaining the k256-based implementation for sp1 builds. It also wires a new sp1 feature through the vm and guest crates and cleans up imports and feature flags accordingly.

  • Add a cfg(not(feature = "sp1")) ECRECOVER implementation using secp256k1.
  • Keep the k256-based ECRECOVER under cfg(feature = "sp1") and route features through vm and guest.
  • Adjust Cargo features and remove the previous secp256k1 patch override.

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
crates/vm/levm/src/precompiles.rs Adds a new secp256k1-based ecrecover under cfg(not(feature = "sp1")), keeps k256-based path for sp1, and localizes the ECRECOVER_COST import.
crates/vm/levm/Cargo.toml Introduces the sp1 feature and formatting tweaks; keeps secp256k1 and p256 deps.
crates/vm/Cargo.toml Adds the sp1 feature and propagates it to ethrex-levm.
crates/l2/prover/src/guest_program/src/sp1/Cargo.toml Enables the sp1 feature on ethrex-vm for the guest build.
Cargo.toml Removes the secp256k1 crate patch override.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

};

// We need to take the 64 bytes from the public key (discarding the first pos of the slice)
let public_key_hash = Keccak256::digest(&public_key.serialize_uncompressed()[1..]);
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keccak256::digest is a trait method from sha3::Digest and requires the Digest trait to be in scope; otherwise this won't compile. Add use sha3::Digest; alongside the Keccak256 import in this cfg block.

Copilot uses AI. Check for mistakes.

Comment on lines +414 to +418
let Ok(recoverable_signature) =
secp256k1::ecdsa::RecoverableSignature::from_compact(raw_sig, recovery_id)
else {
return Ok(Bytes::new());
};
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ECRECOVER precompile must enforce EIP-2 (Homestead) to reject high-s signatures; otherwise malleable signatures will be accepted. After constructing the recoverable signature, convert to a standard signature and reject if normalization would change s: let mut standard_sig = recoverable_signature.to_standard(); if standard_sig.normalize_s() { return Ok(Bytes::new()); }.

Copilot uses AI. Check for mistakes.

Copy link
Collaborator

@rodrigo-o rodrigo-o left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We saw some issues with ecrecover in another PR:

025-10-17T06:06:12.673560Z  INFO ethrex_p2p::sync: Executing 26 blocks for full sync. First block hash: 0xa375e446c5632ace5643b25e3929f074b88de3368dccac3bfcce56a80dd56b2c Last block hash: 0x894deba66c55ac3da824a5eefbb51236791961e0b56457fed672944fd797e986
2025-10-17T06:06:12.725721Z  WARN ethrex_p2p::sync: Failed to add block during FullSync err=EVM error: Tried to slice non-existing data block=0xa375…6b2c
2025-10-17T06:06:12.725750Z ERROR ethrex_p2p::sync: Sync cycle failed due to EVM error: Tried to slice non-existing data, time elapsed: 0 secs
2025-10-17T06:06:14.642229Z ERROR ethrex_rpc::eth::gas_tip_estimator: Block body for block number 9428946 is missing but is below the latest known block!

Probably best to test this a lot and even wait for other PRs first

@github-project-automation github-project-automation bot moved this to In Progress in ethrex_l1 Oct 17, 2025
@ilitteri
Copy link
Contributor Author

ilitteri commented Oct 17, 2025

We saw some issues with ecrecover in another PR:

025-10-17T06:06:12.673560Z  INFO ethrex_p2p::sync: Executing 26 blocks for full sync. First block hash: 0xa375e446c5632ace5643b25e3929f074b88de3368dccac3bfcce56a80dd56b2c Last block hash: 0x894deba66c55ac3da824a5eefbb51236791961e0b56457fed672944fd797e986
2025-10-17T06:06:12.725721Z  WARN ethrex_p2p::sync: Failed to add block during FullSync err=EVM error: Tried to slice non-existing data block=0xa375…6b2c
2025-10-17T06:06:12.725750Z ERROR ethrex_p2p::sync: Sync cycle failed due to EVM error: Tried to slice non-existing data, time elapsed: 0 secs
2025-10-17T06:06:14.642229Z ERROR ethrex_rpc::eth::gas_tip_estimator: Block body for block number 9428946 is missing but is below the latest known block!

Probably best to test this a lot and even wait for other PRs first

I clarified this internally; this is not the same ecrecover implementation using secp256k1 from #4544. I agree, though, that this PR needs to be tested out.

@github-actions
Copy link

github-actions bot commented Oct 17, 2025

Benchmark Results Comparison

No significant difference was registered for any benchmark run.

Detailed Results

Benchmark Results: BubbleSort

Command Mean [s] Min [s] Max [s] Relative
main_revm_BubbleSort 4.742 ± 0.017 4.718 4.772 1.02 ± 0.01
main_levm_BubbleSort 4.677 ± 0.016 4.655 4.702 1.00 ± 0.01
pr_revm_BubbleSort 4.738 ± 0.018 4.714 4.766 1.02 ± 0.01
pr_levm_BubbleSort 4.662 ± 0.024 4.647 4.726 1.00

Benchmark Results: ERC20Approval

Command Mean [s] Min [s] Max [s] Relative
main_revm_ERC20Approval 1.536 ± 0.005 1.530 1.548 1.00
main_levm_ERC20Approval 1.651 ± 0.009 1.641 1.668 1.07 ± 0.01
pr_revm_ERC20Approval 1.542 ± 0.009 1.533 1.557 1.00 ± 0.01
pr_levm_ERC20Approval 1.640 ± 0.007 1.630 1.651 1.07 ± 0.01

Benchmark Results: ERC20Mint

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Mint 185.4 ± 0.6 184.1 186.1 1.00 ± 0.01
main_levm_ERC20Mint 200.1 ± 0.8 198.7 201.3 1.08 ± 0.01
pr_revm_ERC20Mint 184.5 ± 0.9 183.6 186.3 1.00
pr_levm_ERC20Mint 199.0 ± 1.0 198.3 201.5 1.08 ± 0.01

Benchmark Results: ERC20Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Transfer 350.7 ± 2.1 348.9 355.0 1.00 ± 0.01
main_levm_ERC20Transfer 387.4 ± 2.9 382.7 392.3 1.11 ± 0.01
pr_revm_ERC20Transfer 349.9 ± 0.8 349.2 351.8 1.00
pr_levm_ERC20Transfer 386.3 ± 1.4 383.7 388.2 1.10 ± 0.00

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Factorial 233.1 ± 1.5 231.9 237.0 1.00
main_levm_Factorial 285.1 ± 0.6 283.8 285.8 1.22 ± 0.01
pr_revm_Factorial 233.5 ± 1.1 232.1 235.6 1.00 ± 0.01
pr_levm_Factorial 284.3 ± 0.6 283.4 285.1 1.22 ± 0.01

Benchmark Results: FactorialRecursive

Command Mean [s] Min [s] Max [s] Relative
main_revm_FactorialRecursive 1.599 ± 0.102 1.373 1.676 1.00
main_levm_FactorialRecursive 8.811 ± 0.064 8.686 8.926 5.51 ± 0.35
pr_revm_FactorialRecursive 1.657 ± 0.030 1.616 1.707 1.04 ± 0.07
pr_levm_FactorialRecursive 8.717 ± 0.096 8.584 8.909 5.45 ± 0.35

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Fibonacci 210.5 ± 2.1 207.3 214.6 1.00
main_levm_Fibonacci 267.2 ± 3.1 263.8 275.3 1.27 ± 0.02
pr_revm_Fibonacci 211.8 ± 1.4 210.6 215.4 1.01 ± 0.01
pr_levm_Fibonacci 267.8 ± 0.9 266.4 269.4 1.27 ± 0.01

Benchmark Results: FibonacciRecursive

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_FibonacciRecursive 856.1 ± 11.0 836.5 872.5 1.00
main_levm_FibonacciRecursive 1114.8 ± 8.3 1106.9 1128.0 1.30 ± 0.02
pr_revm_FibonacciRecursive 865.8 ± 7.9 851.4 878.9 1.01 ± 0.02
pr_levm_FibonacciRecursive 1106.9 ± 5.6 1100.3 1119.1 1.29 ± 0.02

Benchmark Results: ManyHashes

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ManyHashes 12.3 ± 0.0 12.2 12.4 1.00
main_levm_ManyHashes 13.7 ± 0.1 13.6 14.0 1.12 ± 0.01
pr_revm_ManyHashes 12.4 ± 0.1 12.3 12.5 1.01 ± 0.01
pr_levm_ManyHashes 13.7 ± 0.1 13.6 13.7 1.11 ± 0.01

Benchmark Results: MstoreBench

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_MstoreBench 265.0 ± 1.6 263.3 267.8 1.00
main_levm_MstoreBench 796.2 ± 4.6 792.6 805.2 3.00 ± 0.03
pr_revm_MstoreBench 265.2 ± 5.1 262.3 279.6 1.00 ± 0.02
pr_levm_MstoreBench 806.3 ± 30.8 794.1 893.7 3.04 ± 0.12

Benchmark Results: Push

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Push 294.6 ± 1.0 293.4 296.7 1.00 ± 0.00
main_levm_Push 898.7 ± 12.0 891.8 931.1 3.06 ± 0.04
pr_revm_Push 294.0 ± 1.0 291.9 295.2 1.00
pr_levm_Push 903.7 ± 34.1 886.5 1000.1 3.07 ± 0.12

Benchmark Results: SstoreBench_no_opt

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_SstoreBench_no_opt 219.7 ± 4.1 217.4 230.9 2.36 ± 0.06
main_levm_SstoreBench_no_opt 93.3 ± 1.7 91.2 95.4 1.00 ± 0.02
pr_revm_SstoreBench_no_opt 220.4 ± 8.3 216.5 243.9 2.36 ± 0.10
pr_levm_SstoreBench_no_opt 93.2 ± 1.6 91.1 95.0 1.00

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

Labels

L1 Ethereum client

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

3 participants