Skip to content

Conversation

fmoletta
Copy link
Contributor

@fmoletta fmoletta commented Aug 19, 2025

Motivation
A gas mismatch was found on a sepolia transaction. This was due to the transaction failing at an ecpairing precompile on the network but not on levm. The difference was that geth checks that the coordinates received are within the bounds of the field, while we perform modulus on the input coordinates (see BN254FieldElement::from_bytes_be). This PR fixes this by checking that the input coordinates are within the field bounds before constructing the FieldElements.
It also adds some tests taken from geth to ensure that the implementation remains correct + a test for the out of bounds case

Description

  • Check that input coordinates are within field bounds in ecpairing precompile
  • Add tests for ecpairing precompile

Closes #issue_number

@github-actions github-actions bot added the levm Lambda EVM implementation label Aug 19, 2025
Copy link

github-actions bot commented Aug 19, 2025

Lines of code report

Total lines added: 137
Total lines removed: 0
Total lines changed: 137

Detailed view
+------------------------------------------+-------+------+
| File                                     | Lines | Diff |
+------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/errors.rs      | 214   | +2   |
+------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/precompiles.rs | 1201  | +135 |
+------------------------------------------+-------+------+

Copy link

github-actions bot commented Aug 19, 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 3.187 ± 0.011 3.173 3.208 1.01 ± 0.01
main_levm_BubbleSort 3.493 ± 0.031 3.470 3.576 1.10 ± 0.01
pr_revm_BubbleSort 3.162 ± 0.012 3.151 3.186 1.00
pr_levm_BubbleSort 3.603 ± 0.022 3.576 3.639 1.14 ± 0.01

Benchmark Results: ERC20Approval

Command Mean [s] Min [s] Max [s] Relative
main_revm_ERC20Approval 1.031 ± 0.010 1.021 1.052 1.00
main_levm_ERC20Approval 1.197 ± 0.009 1.187 1.217 1.16 ± 0.01
pr_revm_ERC20Approval 1.033 ± 0.006 1.027 1.047 1.00 ± 0.01
pr_levm_ERC20Approval 1.228 ± 0.009 1.214 1.241 1.19 ± 0.01

Benchmark Results: ERC20Mint

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Mint 135.3 ± 0.3 134.9 136.0 1.00
main_levm_ERC20Mint 168.7 ± 1.5 166.7 170.9 1.25 ± 0.01
pr_revm_ERC20Mint 136.0 ± 0.6 135.3 137.5 1.01 ± 0.01
pr_levm_ERC20Mint 174.5 ± 1.9 171.8 177.1 1.29 ± 0.01

Benchmark Results: ERC20Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Transfer 243.4 ± 2.6 241.5 248.9 1.00 ± 0.02
main_levm_ERC20Transfer 296.4 ± 2.5 292.7 301.4 1.22 ± 0.02
pr_revm_ERC20Transfer 242.8 ± 2.6 241.0 249.9 1.00
pr_levm_ERC20Transfer 301.7 ± 3.0 296.8 306.0 1.24 ± 0.02

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Factorial 235.1 ± 0.6 234.3 236.5 1.00 ± 0.01
main_levm_Factorial 308.4 ± 0.8 307.7 310.5 1.32 ± 0.01
pr_revm_Factorial 234.0 ± 1.1 232.7 236.1 1.00
pr_levm_Factorial 312.1 ± 11.6 306.2 344.9 1.33 ± 0.05

Benchmark Results: FactorialRecursive

Command Mean [s] Min [s] Max [s] Relative
main_revm_FactorialRecursive 1.567 ± 0.020 1.538 1.596 1.00
main_levm_FactorialRecursive 6.976 ± 0.018 6.955 7.001 4.45 ± 0.06
pr_revm_FactorialRecursive 1.578 ± 0.027 1.520 1.615 1.01 ± 0.02
pr_levm_FactorialRecursive 6.991 ± 0.058 6.884 7.083 4.46 ± 0.07

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Fibonacci 210.1 ± 1.1 209.0 213.0 1.00 ± 0.01
main_levm_Fibonacci 306.7 ± 1.9 304.3 311.4 1.46 ± 0.01
pr_revm_Fibonacci 210.0 ± 1.1 209.0 212.7 1.00
pr_levm_Fibonacci 300.2 ± 2.6 297.3 304.8 1.43 ± 0.01

Benchmark Results: FibonacciRecursive

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_FibonacciRecursive 829.8 ± 8.4 819.3 843.4 1.00 ± 0.02
main_levm_FibonacciRecursive 1094.4 ± 8.0 1083.6 1105.8 1.32 ± 0.02
pr_revm_FibonacciRecursive 828.7 ± 12.1 804.2 848.2 1.00
pr_levm_FibonacciRecursive 1055.1 ± 8.7 1044.6 1070.8 1.27 ± 0.02

Benchmark Results: ManyHashes

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ManyHashes 8.6 ± 0.1 8.5 8.7 1.00
main_levm_ManyHashes 10.5 ± 0.1 10.4 10.7 1.22 ± 0.02
pr_revm_ManyHashes 8.6 ± 0.1 8.5 8.7 1.00 ± 0.01
pr_levm_ManyHashes 10.5 ± 0.1 10.3 10.8 1.23 ± 0.02

Benchmark Results: MstoreBench

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_MstoreBench 268.6 ± 2.0 266.3 271.7 1.00 ± 0.01
main_levm_MstoreBench 758.5 ± 5.4 752.1 768.1 2.83 ± 0.03
pr_revm_MstoreBench 268.5 ± 2.0 266.0 273.1 1.00
pr_levm_MstoreBench 756.5 ± 2.8 753.2 760.7 2.82 ± 0.02

Benchmark Results: Push

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Push 298.9 ± 2.1 293.4 301.4 1.00
main_levm_Push 882.2 ± 4.2 878.0 892.7 2.95 ± 0.02
pr_revm_Push 299.6 ± 0.9 298.3 300.8 1.00 ± 0.01
pr_levm_Push 879.9 ± 2.4 877.7 884.5 2.94 ± 0.02

Benchmark Results: SstoreBench_no_opt

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_SstoreBench_no_opt 157.9 ± 1.4 156.6 161.1 1.95 ± 0.05
main_levm_SstoreBench_no_opt 80.8 ± 1.9 79.3 85.4 1.00
pr_revm_SstoreBench_no_opt 157.4 ± 1.1 156.1 159.1 1.95 ± 0.05
pr_levm_SstoreBench_no_opt 82.0 ± 4.7 79.3 94.3 1.02 ± 0.06

@fmoletta fmoletta marked this pull request as ready for review August 19, 2025 20:13
@fmoletta fmoletta requested a review from a team as a code owner August 19, 2025 20:13
Copy link
Contributor

@SDartayet SDartayet left a comment

Choose a reason for hiding this comment

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

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
levm Lambda EVM implementation
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants