Skip to content

perf(levm): improve ecpairing (bn128) #4130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 22, 2025
Merged

perf(levm): improve ecpairing (bn128) #4130

merged 5 commits into from
Aug 22, 2025

Conversation

edg-l
Copy link
Contributor

@edg-l edg-l commented Aug 22, 2025

Motivation

a 73% improvement over ethrex main

The main change is properly batching BN254AtePairing::compute_batch calls

image

Copy link

github-actions bot commented Aug 22, 2025

Lines of code report

Total lines added: 0
Total lines removed: 7
Total lines changed: 7

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

@edg-l edg-l marked this pull request as ready for review August 22, 2025 12:46
@edg-l edg-l requested a review from a team as a code owner August 22, 2025 12:46
Copy link

github-actions bot commented Aug 22, 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.220 ± 0.010 3.210 3.239 1.01 ± 0.01
main_levm_BubbleSort 3.487 ± 0.026 3.466 3.558 1.09 ± 0.01
pr_revm_BubbleSort 3.194 ± 0.022 3.169 3.237 1.00
pr_levm_BubbleSort 3.530 ± 0.014 3.505 3.555 1.11 ± 0.01

Benchmark Results: ERC20Approval

Command Mean [s] Min [s] Max [s] Relative
main_revm_ERC20Approval 1.042 ± 0.045 1.018 1.166 1.00
main_levm_ERC20Approval 1.198 ± 0.015 1.186 1.240 1.15 ± 0.05
pr_revm_ERC20Approval 1.054 ± 0.005 1.049 1.065 1.01 ± 0.04
pr_levm_ERC20Approval 1.220 ± 0.011 1.213 1.249 1.17 ± 0.05

Benchmark Results: ERC20Mint

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Mint 137.9 ± 3.7 135.4 147.5 1.00
main_levm_ERC20Mint 164.5 ± 2.7 162.1 171.4 1.19 ± 0.04
pr_revm_ERC20Mint 139.8 ± 5.5 136.0 155.1 1.01 ± 0.05
pr_levm_ERC20Mint 167.0 ± 1.9 165.1 170.8 1.21 ± 0.04

Benchmark Results: ERC20Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Transfer 242.7 ± 1.3 240.9 244.8 1.00
main_levm_ERC20Transfer 291.3 ± 2.1 288.4 295.7 1.20 ± 0.01
pr_revm_ERC20Transfer 247.6 ± 3.4 242.8 253.9 1.02 ± 0.01
pr_levm_ERC20Transfer 297.1 ± 2.0 293.5 299.6 1.22 ± 0.01

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Factorial 237.8 ± 0.8 236.6 239.1 1.01 ± 0.01
main_levm_Factorial 310.0 ± 1.9 308.0 313.4 1.31 ± 0.01
pr_revm_Factorial 235.9 ± 1.3 235.0 239.4 1.00
pr_levm_Factorial 309.4 ± 1.3 307.9 312.3 1.31 ± 0.01

Benchmark Results: FactorialRecursive

Command Mean [s] Min [s] Max [s] Relative
main_revm_FactorialRecursive 1.602 ± 0.020 1.573 1.640 1.01 ± 0.03
main_levm_FactorialRecursive 6.956 ± 0.015 6.926 6.975 4.39 ± 0.12
pr_revm_FactorialRecursive 1.585 ± 0.043 1.494 1.644 1.00
pr_levm_FactorialRecursive 6.937 ± 0.042 6.898 7.035 4.38 ± 0.12

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Fibonacci 211.2 ± 0.4 210.6 212.3 1.01 ± 0.01
main_levm_Fibonacci 308.2 ± 17.1 299.3 356.1 1.47 ± 0.08
pr_revm_Fibonacci 209.9 ± 1.1 208.5 212.2 1.00
pr_levm_Fibonacci 304.9 ± 5.6 299.0 319.3 1.45 ± 0.03

Benchmark Results: FibonacciRecursive

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_FibonacciRecursive 867.2 ± 15.0 846.9 896.2 1.04 ± 0.02
main_levm_FibonacciRecursive 1060.4 ± 6.3 1053.0 1070.4 1.27 ± 0.02
pr_revm_FibonacciRecursive 836.7 ± 11.5 815.2 850.5 1.00
pr_levm_FibonacciRecursive 1063.4 ± 18.1 1048.7 1103.3 1.27 ± 0.03

Benchmark Results: ManyHashes

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ManyHashes 8.6 ± 0.1 8.5 8.7 1.00 ± 0.01
main_levm_ManyHashes 10.1 ± 0.1 10.1 10.2 1.18 ± 0.01
pr_revm_ManyHashes 8.6 ± 0.1 8.5 8.7 1.00
pr_levm_ManyHashes 10.2 ± 0.0 10.1 10.2 1.19 ± 0.01

Benchmark Results: MstoreBench

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_MstoreBench 272.8 ± 1.1 271.5 275.4 1.00
main_levm_MstoreBench 756.8 ± 2.5 754.5 762.3 2.77 ± 0.01
pr_revm_MstoreBench 274.3 ± 1.9 272.4 279.0 1.01 ± 0.01
pr_levm_MstoreBench 763.0 ± 1.4 760.0 765.6 2.80 ± 0.01

Benchmark Results: Push

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Push 292.6 ± 1.1 290.7 294.3 1.00 ± 0.00
main_levm_Push 876.0 ± 6.2 867.3 889.3 3.00 ± 0.02
pr_revm_Push 291.6 ± 0.9 290.7 293.6 1.00
pr_levm_Push 875.5 ± 2.5 871.8 878.3 3.00 ± 0.01

Benchmark Results: SstoreBench_no_opt

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_SstoreBench_no_opt 159.1 ± 0.8 157.9 160.1 1.95 ± 0.06
main_levm_SstoreBench_no_opt 81.7 ± 3.9 78.7 92.1 1.00 ± 0.06
pr_revm_SstoreBench_no_opt 158.6 ± 0.8 157.9 160.1 1.94 ± 0.06
pr_levm_SstoreBench_no_opt 81.6 ± 2.4 79.5 87.6 1.00

Copy link

github-actions bot commented Aug 22, 2025

Benchmark Block Execution Results Comparison Against Main

Command Mean [s] Min [s] Max [s] Relative
base 162.241 ± 0.489 161.427 162.883 1.00
head 163.238 ± 0.594 162.389 164.332 1.01 ± 0.00

Comment on lines +777 to +779
let batch: Vec<_> = valid_pairs.iter().map(|(p1, p2)| (p1, p2)).collect();
let pairing_result = BN254AtePairing::compute_batch(&batch)
.map_err(|_| PrecompileError::BN254AtePairingError)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Sent an issue to Lambdaworks #1019. This allocation here seems avoidable.

@ilitteri ilitteri added this pull request to the merge queue Aug 22, 2025
Merged via the queue into main with commit c673d17 Aug 22, 2025
53 checks passed
@ilitteri ilitteri deleted the improve_ecpairing branch August 22, 2025 20:29
@github-project-automation github-project-automation bot moved this from Todo to Done in ethrex_performance Aug 22, 2025
pedrobergamini pushed a commit to pedrobergamini/ethrex that referenced this pull request Aug 24, 2025
**Motivation**

a 73% improvement over ethrex main

The main change is properly batching BN254AtePairing::compute_batch
calls

<img width="1337" height="1108" alt="image"
src="https://github.com/user-attachments/assets/626ff6ac-978a-4b69-b674-8e5692736912"
/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants