Skip to content

fix(levm): fix precompiles problem with eip7702 - #2900

Merged
jrchatruc merged 7 commits into
mainfrom
levm/fix_precompile_problem
May 27, 2025
Merged

jrchatruc merged 7 commits into
mainfrom
levm/fix_precompile_problem

Conversation

@JereSalo

@JereSalo JereSalo commented May 22, 2025 •

Copy link
Copy Markdown
Contributor

Motivation

  • Fix holesky Prague syncing with LEVM

Description

  • I previously misunderstood the behavior between EIP 7702 and precompiles and because of that some edge cases were breaking our VM. The current solution I believe is implemented correctly and is also simpler than what I thought.

Before we were luckily (unluckily I'd say) passing all EFTests despite this misimplementation.

Closes #issue_number

@JereSalo JereSalo added the levm Lambda EVM implementation label May 22, 2025
@JereSalo JereSalo self-assigned this May 22, 2025
@github-actions

github-actions Bot commented May 22, 2025 •

Copy link
Copy Markdown

Lines of code report

Total lines added: 0
Total lines removed: 30
Total lines changed: 30

Detailed view
+-----------------------------------------------------+-------+------+
| File                                                | Lines | Diff |
+-----------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/opcode_handlers/system.rs | 760   | -11  |
+-----------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/utils.rs                  | 502   | -8   |
+-----------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/vm.rs                     | 168   | -11  |
+-----------------------------------------------------+-------+------+

@github-actions

github-actions Bot commented May 22, 2025 •

Copy link
Copy Markdown

Benchmark Results Comparison

PR Results

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Factorial 240.8 ± 1.0 239.8 242.6 1.00
levm_Factorial 813.4 ± 5.4 807.9 826.8 3.38 ± 0.03

Benchmark Results: Factorial - Recursive

Command Mean [s] Min [s] Max [s] Relative
revm_FactorialRecursive 1.562 ± 0.102 1.417 1.663 1.00
levm_FactorialRecursive 13.050 ± 0.126 12.929 13.238 8.36 ± 0.55

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Fibonacci 223.1 ± 4.3 218.6 230.7 1.00
levm_Fibonacci 820.1 ± 7.1 811.9 832.4 3.68 ± 0.08

Benchmark Results: ManyHashes

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ManyHashes 8.8 ± 0.1 8.5 9.0 1.00
levm_ManyHashes 17.0 ± 0.2 16.9 17.6 1.93 ± 0.04

Benchmark Results: BubbleSort

Command Mean [s] Min [s] Max [s] Relative
revm_BubbleSort 3.240 ± 0.011 3.224 3.259 1.00
levm_BubbleSort 5.519 ± 0.031 5.483 5.591 1.70 ± 0.01

Benchmark Results: ERC20 - Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Transfer 251.2 ± 2.5 248.9 256.2 1.00
levm_ERC20Transfer 500.5 ± 1.6 498.2 503.5 1.99 ± 0.02

Benchmark Results: ERC20 - Mint

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Mint 142.5 ± 0.9 140.5 143.8 1.00
levm_ERC20Mint 320.5 ± 1.2 319.0 323.1 2.25 ± 0.02

Benchmark Results: ERC20 - Approval

Command Mean [s] Min [s] Max [s] Relative
revm_ERC20Approval 1.038 ± 0.012 1.029 1.068 1.00
levm_ERC20Approval 1.894 ± 0.027 1.876 1.967 1.83 ± 0.03

Main Results

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Factorial 240.3 ± 1.6 238.8 243.7 1.00
levm_Factorial 832.2 ± 51.0 807.4 974.5 3.46 ± 0.21

Benchmark Results: Factorial - Recursive

Command Mean [s] Min [s] Max [s] Relative
revm_FactorialRecursive 1.545 ± 0.100 1.419 1.679 1.00
levm_FactorialRecursive 12.981 ± 0.112 12.891 13.194 8.40 ± 0.55

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Fibonacci 216.7 ± 1.4 214.9 218.6 1.00
levm_Fibonacci 825.4 ± 11.5 812.4 852.4 3.81 ± 0.06

Benchmark Results: ManyHashes

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ManyHashes 8.8 ± 0.0 8.7 8.9 1.00
levm_ManyHashes 17.6 ± 0.2 17.4 17.9 2.00 ± 0.02

Benchmark Results: BubbleSort

Command Mean [s] Min [s] Max [s] Relative
revm_BubbleSort 3.242 ± 0.017 3.217 3.273 1.00
levm_BubbleSort 5.654 ± 0.202 5.547 6.215 1.74 ± 0.06

Benchmark Results: ERC20 - Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Transfer 254.4 ± 1.2 253.1 257.5 1.00
levm_ERC20Transfer 503.8 ± 2.5 501.3 507.7 1.98 ± 0.01

Benchmark Results: ERC20 - Mint

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Mint 144.7 ± 0.9 143.4 147.0 1.00
levm_ERC20Mint 320.0 ± 1.8 318.1 323.3 2.21 ± 0.02

Benchmark Results: ERC20 - Approval

Command Mean [s] Min [s] Max [s] Relative
revm_ERC20Approval 1.052 ± 0.010 1.041 1.072 1.00
levm_ERC20Approval 1.928 ± 0.040 1.906 2.038 1.83 ± 0.04

@github-actions

github-actions Bot commented May 23, 2025 •

Copy link
Copy Markdown

EF Tests Comparison

Same results between main branch and the current PR.

@JereSalo
JereSalo marked this pull request as ready for review May 23, 2025 22:58
@JereSalo
JereSalo requested a review from a team as a code owner May 23, 2025 22:58
@JereSalo JereSalo mentioned this pull request May 26, 2025
@mpaulucci mpaulucci moved this to In Progress in ethrex_l1 May 26, 2025
self.increase_account_balance(to, value)?;
}

if bytecode.is_empty() && is_delegation {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was removed because it was just an early return. But the result it the same if the callframe is created and the bytecode is empty. I just thought that it was best to remove it for clarity and say that we execute empty code.


if self.is_precompile()? {
// Execute precompile immediately and handle result.
if self.is_precompile(&code_address) && !is_delegation_7702 {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This check was added because precompile shouldn't be executed if it's target of delegation.
See here

Comment thread crates/vm/levm/src/vm.rs
Comment on lines -172 to -190
let precompile_result = match self.is_delegation_target(precompile_address) {
// Avoid executing precompile if it is target of a delegation in EIP-7702 transaction.
true => {
let gas_limit = self.current_call_frame()?.gas_limit;
if gas_limit == 0 {
// `pointer_to_precompile.json` tests that it should fail in a call with zero gas limit.
Err(VMError::PrecompileError(PrecompileError::NotEnoughGas))
} else {
Ok(Bytes::new())
}
}
// Otherwise, execute precompile
false => {
let callframe = self.current_call_frame_mut()?;
execute_precompile(
precompile_address,
&callframe.calldata,
&mut callframe.gas_used,
callframe.gas_limit,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We don't need these checks anymore because it's enough with the checks that are being performed in XCALL opcodes. Before we were making checks in external transactions too, which wasn't necessary at all.

@github-project-automation github-project-automation Bot moved this from In Progress to In Review in ethrex_l1 May 27, 2025
@jrchatruc
jrchatruc added this pull request to the merge queue May 27, 2025
Merged via the queue into main with commit 2b4abbe May 27, 2025
@jrchatruc
jrchatruc deleted the levm/fix_precompile_problem branch May 27, 2025 13:48
@github-project-automation github-project-automation Bot moved this from In Review to Done in ethrex_l1 May 27, 2025
pedrobergamini pushed a commit to pedrobergamini/ethrex that referenced this pull request Aug 24, 2025
**Motivation**

- Fix holesky Prague syncing with LEVM

**Description**

- I previously misunderstood the behavior between [EIP
7702](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7702.md) and
precompiles and because of that some edge cases were breaking our VM.
The current solution I believe is implemented correctly and is also
simpler than what I thought.

Before we were luckily (unluckily I'd say) passing all EFTests despite
this misimplementation.


<!-- Link to issues: Resolves lambdaclass#111, Resolves lambdaclass#222 -->

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

Labels

levm Lambda EVM implementation

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants