Skip to content

Conversation

@fedacking
Copy link
Contributor

Motivation

There were multiple functions implementing the eip4844 helper function fake_exponential. These functions should be unified to a single U256 implementation that properly takes into account the possible overflow.

Description

  • Removed fake_exponential function in LEVM crate
  • Removed fake_exponential_checked function in block.rs
  • Changed fake_exponential function signature to be U256
  • Changed base_fee_per_blob_gas to be U256 where is it used
  • Added a test for the 400M limit where the function still operates

**Motivation**

Currently, we have 3 differential fake_exponential functions that are a helper for the 4844 eip https://eips.ethereum.org/EIPS/eip-4844#helpers. These functions may silently overflow, causing bugs if the excess_blog_gas grows.

**Changes**

- Unified into a single fake_exponential function (the levm implementation)
- The node panics if the output exceeds the u64 limit for the base_fee_per_blob_gas
@github-actions
Copy link

github-actions bot commented Oct 29, 2025

Lines of code report

Total lines added: 41
Total lines removed: 31
Total lines changed: 72

Detailed view
+------------------------------------------------+-------+------+
| File                                           | Lines | Diff |
+------------------------------------------------+-------+------+
| ethrex/crates/common/serde_utils.rs            | 633   | +22  |
+------------------------------------------------+-------+------+
| ethrex/crates/common/types/block.rs            | 878   | +8   |
+------------------------------------------------+-------+------+
| ethrex/crates/networking/rpc/eth/fee_market.rs | 231   | +2   |
+------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/errors.rs            | 234   | +5   |
+------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/gas_cost.rs          | 830   | -31  |
+------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/utils.rs             | 503   | +4   |
+------------------------------------------------+-------+------+

@github-actions
Copy link

github-actions bot commented Oct 29, 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.711 ± 0.007 4.699 4.724 1.00
main_levm_BubbleSort 4.750 ± 0.080 4.691 4.966 1.01 ± 0.02
pr_revm_BubbleSort 4.714 ± 0.013 4.692 4.738 1.00 ± 0.00
pr_levm_BubbleSort 4.739 ± 0.024 4.711 4.773 1.01 ± 0.01

Benchmark Results: ERC20Approval

Command Mean [s] Min [s] Max [s] Relative
main_revm_ERC20Approval 1.538 ± 0.007 1.531 1.554 1.00 ± 0.01
main_levm_ERC20Approval 1.698 ± 0.012 1.687 1.728 1.11 ± 0.01
pr_revm_ERC20Approval 1.533 ± 0.011 1.525 1.554 1.00
pr_levm_ERC20Approval 1.677 ± 0.017 1.660 1.722 1.09 ± 0.01

Benchmark Results: ERC20Mint

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Mint 187.2 ± 4.9 184.8 201.0 1.02 ± 0.03
main_levm_ERC20Mint 205.8 ± 1.2 204.3 208.6 1.12 ± 0.01
pr_revm_ERC20Mint 183.9 ± 0.8 182.7 185.3 1.00
pr_levm_ERC20Mint 207.0 ± 0.8 205.9 208.3 1.13 ± 0.01

Benchmark Results: ERC20Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Transfer 352.0 ± 2.2 350.1 357.6 1.01 ± 0.01
main_levm_ERC20Transfer 397.4 ± 2.7 394.4 402.2 1.13 ± 0.01
pr_revm_ERC20Transfer 350.2 ± 3.4 347.2 356.4 1.00
pr_levm_ERC20Transfer 396.2 ± 2.2 393.6 401.0 1.13 ± 0.01

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Factorial 240.0 ± 13.6 234.7 278.7 1.02 ± 0.06
main_levm_Factorial 277.7 ± 5.2 274.4 291.2 1.18 ± 0.02
pr_revm_Factorial 235.9 ± 1.8 234.4 240.6 1.00
pr_levm_Factorial 278.0 ± 1.5 276.9 281.8 1.18 ± 0.01

Benchmark Results: FactorialRecursive

Command Mean [s] Min [s] Max [s] Relative
main_revm_FactorialRecursive 1.664 ± 0.027 1.616 1.705 1.00
main_levm_FactorialRecursive 8.785 ± 0.104 8.604 8.918 5.28 ± 0.11
pr_revm_FactorialRecursive 1.672 ± 0.028 1.639 1.727 1.00 ± 0.02
pr_levm_FactorialRecursive 8.658 ± 0.103 8.491 8.779 5.20 ± 0.10

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Fibonacci 208.7 ± 1.1 207.3 211.0 1.00 ± 0.01
main_levm_Fibonacci 257.9 ± 5.4 252.2 264.8 1.24 ± 0.03
pr_revm_Fibonacci 208.7 ± 0.7 207.7 209.8 1.00
pr_levm_Fibonacci 259.9 ± 3.9 253.6 264.8 1.25 ± 0.02

Benchmark Results: FibonacciRecursive

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_FibonacciRecursive 861.8 ± 6.1 851.1 873.6 1.10 ± 0.02
main_levm_FibonacciRecursive 783.5 ± 7.4 776.5 799.4 1.00 ± 0.02
pr_revm_FibonacciRecursive 855.3 ± 5.7 843.5 861.8 1.09 ± 0.02
pr_levm_FibonacciRecursive 781.1 ± 10.6 771.6 800.5 1.00

Benchmark Results: ManyHashes

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ManyHashes 12.4 ± 0.1 12.3 12.5 1.00 ± 0.01
main_levm_ManyHashes 13.6 ± 0.1 13.5 13.9 1.10 ± 0.01
pr_revm_ManyHashes 12.4 ± 0.1 12.3 12.5 1.00
pr_levm_ManyHashes 13.6 ± 0.2 13.5 14.0 1.10 ± 0.02

Benchmark Results: MstoreBench

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_MstoreBench 262.2 ± 3.4 259.0 269.6 1.04 ± 0.01
main_levm_MstoreBench 251.6 ± 1.4 250.3 254.9 1.00
pr_revm_MstoreBench 261.8 ± 3.6 259.6 271.7 1.04 ± 0.02
pr_levm_MstoreBench 252.7 ± 1.8 250.2 257.2 1.00 ± 0.01

Benchmark Results: Push

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Push 297.3 ± 2.4 294.1 302.1 1.01 ± 0.01
main_levm_Push 300.8 ± 3.9 295.9 306.4 1.02 ± 0.01
pr_revm_Push 295.5 ± 0.8 294.4 297.0 1.00
pr_levm_Push 302.4 ± 4.5 296.0 310.1 1.02 ± 0.02

Benchmark Results: SstoreBench_no_opt

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_SstoreBench_no_opt 218.5 ± 0.7 217.7 219.6 2.46 ± 0.06
main_levm_SstoreBench_no_opt 88.8 ± 2.1 85.3 91.7 1.00
pr_revm_SstoreBench_no_opt 220.0 ± 2.8 217.9 227.5 2.48 ± 0.07
pr_levm_SstoreBench_no_opt 90.0 ± 2.9 85.9 96.9 1.01 ± 0.04

@fedacking fedacking marked this pull request as ready for review October 31, 2025 13:38
@fedacking fedacking requested a review from a team as a code owner October 31, 2025 13:38
Copy link
Contributor

@ElFantasma ElFantasma 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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants