Skip to content
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

refactor(l2): use levm for sp1 prover using a trait #2250

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

tomip01
Copy link
Contributor

@tomip01 tomip01 commented Mar 18, 2025

Motivation

This PR exists to use LEVM as the EVM for executing SP1 prover

Description

  • Implement the trait LevmDatabase for the ExecutionDb.
  • Add the function get_chain_config() for the LevmDatabase trait.
  • Move the ExecutionDb to a common place and remove from some of REVM dependencies. But, there are some left to be removed in the next PR.
  • Add a feature flag levm-l2 for choosing whether to execute the Prover and the ExecutionDb with LEVM or not.

Status

Links to #2225

Copy link

github-actions bot commented Mar 18, 2025

Lines of code report

Total lines added: 143
Total lines removed: 73
Total lines changed: 216

Detailed view
+--------------------------------------------------------+-------+------+
| File                                                   | Lines | Diff |
+--------------------------------------------------------+-------+------+
| ethrex/cmd/ef_tests/state/runner/levm_runner.rs        | 364   | +6   |
+--------------------------------------------------------+-------+------+
| ethrex/cmd/ef_tests/state/runner/revm_runner.rs        | 537   | +9   |
+--------------------------------------------------------+-------+------+
| ethrex/crates/l2/prover/zkvm/interface/sp1/src/main.rs | 55    | +6   |
+--------------------------------------------------------+-------+------+
| ethrex/crates/l2/sequencer/prover_server.rs            | 456   | -3   |
+--------------------------------------------------------+-------+------+
| ethrex/crates/l2/utils/prover/save_state.rs            | 418   | +19  |
+--------------------------------------------------------+-------+------+
| ethrex/crates/vm/backends/levm/db.rs                   | 71    | +31  |
+--------------------------------------------------------+-------+------+
| ethrex/crates/vm/backends/levm/mod.rs                  | 500   | -20  |
+--------------------------------------------------------+-------+------+
| ethrex/crates/vm/backends/mod.rs                       | 326   | +19  |
+--------------------------------------------------------+-------+------+
| ethrex/crates/vm/backends/revm/db.rs                   | 324   | +4   |
+--------------------------------------------------------+-------+------+
| ethrex/crates/vm/backends/revm/execution_db.rs         | 125   | -50  |
+--------------------------------------------------------+-------+------+
| ethrex/crates/vm/db.rs                                 | 52    | +45  |
+--------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/db/mod.rs                    | 66    | +4   |
+--------------------------------------------------------+-------+------+

Copy link

github-actions bot commented Mar 18, 2025

Benchmark Results Comparison

PR Results

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Factorial 233.6 ± 4.7 228.6 242.5 1.00
levm_Factorial 913.9 ± 10.8 901.9 929.4 3.91 ± 0.09

Benchmark Results: Factorial - Recursive

Command Mean [s] Min [s] Max [s] Relative
revm_FactorialRecursive 1.340 ± 0.067 1.265 1.455 1.00
levm_FactorialRecursive 15.715 ± 0.091 15.556 15.824 11.73 ± 0.59

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Fibonacci 203.8 ± 0.6 202.4 204.6 1.00
levm_Fibonacci 911.4 ± 20.2 893.2 962.4 4.47 ± 0.10

Benchmark Results: ManyHashes

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ManyHashes 8.6 ± 0.1 8.5 8.7 1.00
levm_ManyHashes 18.5 ± 0.7 18.0 20.3 2.15 ± 0.08

Benchmark Results: BubbleSort

Command Mean [s] Min [s] Max [s] Relative
revm_BubbleSort 3.228 ± 0.047 3.196 3.354 1.00
levm_BubbleSort 6.110 ± 0.079 6.046 6.315 1.89 ± 0.04

Benchmark Results: ERC20 - Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Transfer 246.0 ± 1.7 243.8 248.9 1.00
levm_ERC20Transfer 541.2 ± 2.4 536.1 544.8 2.20 ± 0.02

Benchmark Results: ERC20 - Mint

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Mint 140.2 ± 1.2 138.7 141.9 1.00
levm_ERC20Mint 353.9 ± 5.2 350.4 367.6 2.52 ± 0.04

Benchmark Results: ERC20 - Approval

Command Mean [s] Min [s] Max [s] Relative
revm_ERC20Approval 1.035 ± 0.003 1.031 1.040 1.00
levm_ERC20Approval 2.018 ± 0.016 1.999 2.043 1.95 ± 0.02

Main Results

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Factorial 231.1 ± 1.6 229.4 234.3 1.00
levm_Factorial 920.4 ± 25.1 905.0 987.9 3.98 ± 0.11

Benchmark Results: Factorial - Recursive

Command Mean [s] Min [s] Max [s] Relative
revm_FactorialRecursive 1.376 ± 0.068 1.301 1.468 1.00
levm_FactorialRecursive 15.677 ± 0.099 15.534 15.852 11.40 ± 0.57

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Fibonacci 203.7 ± 1.3 200.1 204.8 1.00
levm_Fibonacci 911.4 ± 14.0 893.9 934.5 4.47 ± 0.07

Benchmark Results: ManyHashes

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ManyHashes 8.6 ± 0.0 8.6 8.7 1.00
levm_ManyHashes 18.7 ± 0.1 18.5 18.9 2.17 ± 0.02

Benchmark Results: BubbleSort

Command Mean [s] Min [s] Max [s] Relative
revm_BubbleSort 3.226 ± 0.017 3.203 3.265 1.00
levm_BubbleSort 6.124 ± 0.048 6.072 6.196 1.90 ± 0.02

Benchmark Results: ERC20 - Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Transfer 245.6 ± 2.1 243.3 249.4 1.00
levm_ERC20Transfer 539.8 ± 2.5 535.9 544.4 2.20 ± 0.02

Benchmark Results: ERC20 - Mint

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Mint 141.7 ± 6.8 138.8 160.6 1.00
levm_ERC20Mint 354.8 ± 1.5 352.4 356.8 2.50 ± 0.12

Benchmark Results: ERC20 - Approval

Command Mean [s] Min [s] Max [s] Relative
revm_ERC20Approval 1.030 ± 0.006 1.024 1.042 1.00
levm_ERC20Approval 2.025 ± 0.017 2.007 2.065 1.96 ± 0.02

@tomip01 tomip01 changed the title Prover/use levm trait refactor(l2): use levm for sp1 prover Mar 18, 2025
@tomip01 tomip01 self-assigned this Mar 18, 2025
@tomip01 tomip01 added tech debt Refactors, cleanups, etc L2 Rollup client labels Mar 18, 2025
@tomip01 tomip01 marked this pull request as ready for review March 18, 2025 16:17
@tomip01 tomip01 requested a review from a team as a code owner March 18, 2025 16:17
@tomip01 tomip01 changed the title refactor(l2): use levm for sp1 prover refactor(l2): use levm for sp1 prover using a trait Mar 18, 2025
Copy link
Contributor

@fborello-lambda fborello-lambda left a comment

Choose a reason for hiding this comment

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

Seems more straight-forward than the enum, i think i prefer this approach. However, i'm not sure if an Arc is the best way to handle the StoreWrapper: Arc::new(store_wrapper.clone()), seems to be, but i would wait for someone with more experience.

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
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants