Skip to content

refactor(levm,l2): hooks #2508

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 44 commits into from
Apr 30, 2025
Merged

refactor(levm,l2): hooks #2508

merged 44 commits into from
Apr 30, 2025

Conversation

ilitteri
Copy link
Contributor

@ilitteri ilitteri commented Apr 21, 2025

Motivation

  • Remove duplicated code between DefaultHook and L2Hook implementations.
  • Use the L2Hook for every tx (regular ETH txs and L2's privilege txs) when running the L2.

Description

This PR:

  • Generates abstractions to be used in DefaultHook and L2Hook to remove repeated code.
  • Adds the is_privilege field to LEVM's Environment only compiled under the l2 feature flag.
  • L2Hook now supports executing every tx (before only privileged).

@ilitteri ilitteri added tech debt Refactors, cleanups, etc L2 Rollup client labels Apr 21, 2025
@ilitteri ilitteri self-assigned this Apr 21, 2025
Copy link

github-actions bot commented Apr 21, 2025

Lines of code report

Total lines added: 99
Total lines removed: 61
Total lines changed: 160

Detailed view
+-------------------------------------------------+-------+------+
| File                                            | Lines | Diff |
+-------------------------------------------------+-------+------+
| ethrex/cmd/ef_tests/state/runner/levm_runner.rs | 383   | +1   |
+-------------------------------------------------+-------+------+
| ethrex/crates/vm/backends/levm/mod.rs           | 640   | +2   |
+-------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/environment.rs        | 29    | +1   |
+-------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/errors.rs             | 230   | +2   |
+-------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/hooks/default_hook.rs | 339   | +75  |
+-------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/hooks/l2_hook.rs      | 133   | -61  |
+-------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/hooks/mod.rs          | 7     | +4   |
+-------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/vm.rs                 | 386   | +14  |
+-------------------------------------------------+-------+------+

Copy link

github-actions bot commented Apr 21, 2025

Benchmark Results Comparison

PR Results

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Factorial 239.3 ± 1.2 238.0 242.4 1.00
levm_Factorial 879.1 ± 4.0 873.0 886.7 3.67 ± 0.02

Benchmark Results: Factorial - Recursive

Command Mean [s] Min [s] Max [s] Relative
revm_FactorialRecursive 1.437 ± 0.073 1.352 1.540 1.00
levm_FactorialRecursive 13.302 ± 0.134 13.066 13.451 9.26 ± 0.48

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Fibonacci 209.3 ± 0.6 207.9 210.2 1.00
levm_Fibonacci 879.0 ± 8.3 870.2 897.0 4.20 ± 0.04

Benchmark Results: ManyHashes

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ManyHashes 8.8 ± 0.1 8.7 9.0 1.00
levm_ManyHashes 17.6 ± 0.3 17.3 18.3 2.01 ± 0.04

Benchmark Results: BubbleSort

Command Mean [s] Min [s] Max [s] Relative
revm_BubbleSort 3.243 ± 0.033 3.210 3.306 1.00
levm_BubbleSort 5.734 ± 0.028 5.702 5.780 1.77 ± 0.02

Benchmark Results: ERC20 - Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Transfer 252.0 ± 3.9 247.7 257.9 1.00
levm_ERC20Transfer 507.9 ± 7.1 499.9 522.9 2.02 ± 0.04

Benchmark Results: ERC20 - Mint

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Mint 142.6 ± 0.6 141.7 143.6 1.00
levm_ERC20Mint 322.2 ± 4.5 316.1 329.8 2.26 ± 0.03

Benchmark Results: ERC20 - Approval

Command Mean [s] Min [s] Max [s] Relative
revm_ERC20Approval 1.040 ± 0.007 1.031 1.051 1.00
levm_ERC20Approval 1.922 ± 0.040 1.894 2.032 1.85 ± 0.04

Main Results

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Factorial 237.9 ± 1.9 233.0 240.4 1.00
levm_Factorial 885.5 ± 16.1 874.0 916.8 3.72 ± 0.07

Benchmark Results: Factorial - Recursive

Command Mean [s] Min [s] Max [s] Relative
revm_FactorialRecursive 1.577 ± 0.086 1.412 1.675 1.00
levm_FactorialRecursive 13.203 ± 0.201 12.986 13.430 8.37 ± 0.47

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Fibonacci 207.5 ± 2.1 205.9 213.3 1.00
levm_Fibonacci 874.9 ± 3.3 871.7 881.5 4.22 ± 0.05

Benchmark Results: ManyHashes

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ManyHashes 8.7 ± 0.1 8.6 8.8 1.00
levm_ManyHashes 17.6 ± 0.3 17.4 18.4 2.01 ± 0.04

Benchmark Results: BubbleSort

Command Mean [s] Min [s] Max [s] Relative
revm_BubbleSort 3.259 ± 0.013 3.245 3.283 1.00
levm_BubbleSort 5.795 ± 0.065 5.724 5.889 1.78 ± 0.02

Benchmark Results: ERC20 - Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Transfer 252.4 ± 0.5 251.2 252.9 1.00
levm_ERC20Transfer 511.4 ± 8.9 501.8 533.5 2.03 ± 0.04

Benchmark Results: ERC20 - Mint

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Mint 145.2 ± 3.5 143.3 155.0 1.00
levm_ERC20Mint 318.8 ± 2.0 316.1 322.0 2.20 ± 0.05

Benchmark Results: ERC20 - Approval

Command Mean [s] Min [s] Max [s] Relative
revm_ERC20Approval 1.039 ± 0.002 1.037 1.042 1.00
levm_ERC20Approval 1.925 ± 0.015 1.901 1.943 1.85 ± 0.01

@ilitteri ilitteri marked this pull request as ready for review April 22, 2025 19:15
@ilitteri ilitteri requested a review from a team as a code owner April 22, 2025 19:15
@ilitteri ilitteri changed the title refactor(l2): generalize L2 hook refactor(levm,l2): hooks Apr 22, 2025
@ilitteri ilitteri requested a review from tomip01 April 24, 2025 16:37
@@ -188,6 +188,8 @@ pub fn prepare_vm_for_tx<'a>(
tx_nonce: test_tx.nonce,
block_gas_limit: test.env.current_gas_limit,
transient_storage: HashMap::new(),
#[cfg(feature = "l2")]
is_privilege: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be is_privileged?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in e60b7ee.

Ok(())
}

pub fn validate_type_3_tx(vm: &mut VM<'_>) -> Result<(), VMError> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Something like validate_4844_tx might be easier to read

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 8941381.

Ok(())
}

pub fn validate_type_4_tx(vm: &mut VM<'_>) -> Result<(), VMError> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 8941381.

@ilitteri ilitteri added this pull request to the merge queue Apr 30, 2025
Merged via the queue into main with commit bb8cece Apr 30, 2025
35 checks passed
@ilitteri ilitteri deleted the generalize_l2_hook branch April 30, 2025 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L2 Rollup client tech debt Refactors, cleanups, etc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants