Skip to content

Conversation

edg-l
Copy link
Contributor

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

Use malachite library to improve the performance of the modexp precompile. There are speedups up to 7-8x observed in the new benchmarks.

Copy link

github-actions bot commented Aug 14, 2025

Lines of code report

Total lines added: 12
Total lines removed: 0
Total lines changed: 12

Detailed view
+------------------------------------------+-------+------+
| File                                     | Lines | Diff |
+------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/gas_cost.rs    | 820   | +1   |
+------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/precompiles.rs | 1032  | +11  |
+------------------------------------------+-------+------+

Copy link

github-actions bot commented Aug 14, 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.134 ± 0.019 3.109 3.174 1.00
main_levm_BubbleSort 3.493 ± 0.018 3.476 3.539 1.11 ± 0.01
pr_revm_BubbleSort 3.139 ± 0.008 3.127 3.151 1.00 ± 0.01
pr_levm_BubbleSort 3.491 ± 0.029 3.466 3.552 1.11 ± 0.01

Benchmark Results: ERC20Approval

Command Mean [s] Min [s] Max [s] Relative
main_revm_ERC20Approval 1.021 ± 0.007 1.012 1.033 1.00
main_levm_ERC20Approval 1.206 ± 0.011 1.196 1.236 1.18 ± 0.01
pr_revm_ERC20Approval 1.043 ± 0.016 1.029 1.077 1.02 ± 0.02
pr_levm_ERC20Approval 1.208 ± 0.009 1.195 1.223 1.18 ± 0.01

Benchmark Results: ERC20Mint

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Mint 133.8 ± 0.5 133.0 134.5 1.00
main_levm_ERC20Mint 165.9 ± 1.5 163.6 168.0 1.24 ± 0.01
pr_revm_ERC20Mint 136.5 ± 0.9 135.5 138.1 1.02 ± 0.01
pr_levm_ERC20Mint 167.3 ± 2.3 165.6 172.1 1.25 ± 0.02

Benchmark Results: ERC20Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Transfer 237.6 ± 0.9 236.4 239.3 1.00
main_levm_ERC20Transfer 297.2 ± 2.3 293.8 299.7 1.25 ± 0.01
pr_revm_ERC20Transfer 244.7 ± 6.8 241.6 263.9 1.03 ± 0.03
pr_levm_ERC20Transfer 299.8 ± 2.1 296.6 302.6 1.26 ± 0.01

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Factorial 229.6 ± 2.7 227.8 236.2 1.01 ± 0.01
main_levm_Factorial 309.2 ± 1.3 307.3 311.9 1.36 ± 0.01
pr_revm_Factorial 228.0 ± 1.2 226.9 231.0 1.00
pr_levm_Factorial 309.3 ± 1.1 307.9 312.0 1.36 ± 0.01

Benchmark Results: FactorialRecursive

Command Mean [s] Min [s] Max [s] Relative
main_revm_FactorialRecursive 1.552 ± 0.025 1.520 1.583 1.00
main_levm_FactorialRecursive 7.031 ± 0.047 6.982 7.153 4.53 ± 0.08
pr_revm_FactorialRecursive 1.555 ± 0.024 1.507 1.582 1.00 ± 0.02
pr_levm_FactorialRecursive 7.056 ± 0.025 7.015 7.084 4.55 ± 0.07

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Fibonacci 199.6 ± 1.7 195.6 201.1 1.01 ± 0.02
main_levm_Fibonacci 300.7 ± 2.4 297.7 304.8 1.52 ± 0.03
pr_revm_Fibonacci 198.2 ± 2.9 191.7 204.0 1.00
pr_levm_Fibonacci 307.2 ± 12.8 298.1 341.4 1.55 ± 0.07

Benchmark Results: FibonacciRecursive

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_FibonacciRecursive 827.7 ± 12.0 795.5 838.0 1.02 ± 0.02
main_levm_FibonacciRecursive 1110.9 ± 7.2 1100.2 1121.6 1.37 ± 0.03
pr_revm_FibonacciRecursive 810.9 ± 15.5 783.6 826.7 1.00
pr_levm_FibonacciRecursive 1116.5 ± 4.5 1111.1 1124.6 1.38 ± 0.03

Benchmark Results: ManyHashes

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ManyHashes 8.7 ± 0.6 8.4 10.5 1.01 ± 0.07
main_levm_ManyHashes 10.2 ± 0.1 10.1 10.4 1.18 ± 0.02
pr_revm_ManyHashes 8.6 ± 0.1 8.5 8.8 1.00
pr_levm_ManyHashes 10.2 ± 0.1 10.1 10.5 1.18 ± 0.02

Benchmark Results: MstoreBench

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_MstoreBench 264.4 ± 0.7 263.4 265.5 1.00
main_levm_MstoreBench 794.6 ± 4.6 790.4 806.6 3.00 ± 0.02
pr_revm_MstoreBench 265.4 ± 1.6 263.8 268.4 1.00 ± 0.01
pr_levm_MstoreBench 791.5 ± 2.1 789.1 795.8 2.99 ± 0.01

Benchmark Results: Push

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Push 286.5 ± 0.8 285.5 288.2 1.00 ± 0.00
main_levm_Push 923.2 ± 3.7 920.0 932.5 3.23 ± 0.01
pr_revm_Push 285.7 ± 0.6 284.9 286.7 1.00
pr_levm_Push 923.1 ± 4.9 917.8 931.7 3.23 ± 0.02

Benchmark Results: SstoreBench_no_opt

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_SstoreBench_no_opt 157.1 ± 1.0 155.9 158.4 1.94 ± 0.03
main_levm_SstoreBench_no_opt 81.4 ± 2.7 79.6 88.8 1.01 ± 0.04
pr_revm_SstoreBench_no_opt 157.0 ± 1.2 155.4 158.4 1.94 ± 0.03
pr_levm_SstoreBench_no_opt 80.8 ± 0.9 79.5 82.3 1.00

@edg-l edg-l marked this pull request as ready for review August 14, 2025 15:01
@edg-l edg-l requested a review from a team as a code owner August 14, 2025 15:01
@edg-l edg-l moved this from Todo to In review in ethrex_performance Aug 14, 2025
Copy link
Collaborator

@Arkenan Arkenan left a comment

Choose a reason for hiding this comment

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

LGTM great PR

Copy link
Contributor

@JereSalo JereSalo left a comment

Choose a reason for hiding this comment

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

The "EVM" aspect of it is perfectly fine. Maybe someone with more math knowledge would be able to give a deeper review in terms of the precompile itself.

Copy link

github-actions bot commented Aug 14, 2025

Benchmark Block Execution Results Comparison Against Main

Command Mean [s] Min [s] Max [s] Relative
base 162.004 ± 0.550 161.178 162.567 1.00 ± 0.00
head 161.724 ± 0.517 160.726 162.262 1.00

@Arkenan Arkenan enabled auto-merge August 14, 2025 16:48
@Arkenan Arkenan added this pull request to the merge queue Aug 14, 2025
Merged via the queue into main with commit 37f2517 Aug 14, 2025
52 checks passed
@Arkenan Arkenan deleted the modexp_malachite branch August 14, 2025 18:00
@github-project-automation github-project-automation bot moved this from In review to Done in ethrex_performance Aug 14, 2025
@Oppen Oppen mentioned this pull request Aug 14, 2025
pedrobergamini pushed a commit to pedrobergamini/ethrex that referenced this pull request Aug 24, 2025
Use malachite library to improve the performance of the modexp
precompile. There are speedups up to 7-8x observed in the new
benchmarks.

---------

Co-authored-by: Tomás Arjovsky <[email protected]>
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