Skip to content

Conversation

JereSalo
Copy link
Contributor

@JereSalo JereSalo commented Oct 13, 2025

Motivation

  • Trait may have been unnecessarily complex when we could've used LevmDatabase trait directly instead without problems.

Description

  • Remove VmDatabase and related structures and implement LevmDatabase in all the Storage structs we use.

Copy link

github-actions bot commented Oct 13, 2025

Benchmark Results Comparison

Benchmark Results: MstoreBench

Command Mean [s] Min [s] Max [s] Relative
main_revm_MstoreBench 272.6 ± 3.2 270.5 279.4 1.00
main_levm_MstoreBench 756.8 ± 1.2 755.2 758.6 2.78 ± 0.03
pr_revm_MstoreBench 328.5 ± 174.9 270.7 826.2 1.20 ± 0.64
Detailed Results

Benchmark Results: BubbleSort

Command Mean [s] Min [s] Max [s] Relative
main_revm_BubbleSort 4.791 ± 0.017 4.770 4.825 1.04 ± 0.01
main_levm_BubbleSort 4.609 ± 0.027 4.580 4.653 1.00
pr_revm_BubbleSort 4.795 ± 0.031 4.768 4.856 1.04 ± 0.01
pr_levm_BubbleSort 4.633 ± 0.020 4.604 4.681 1.01 ± 0.01

Benchmark Results: ERC20Approval

Command Mean [s] Min [s] Max [s] Relative
main_revm_ERC20Approval 1.561 ± 0.006 1.551 1.570 1.01 ± 0.01
main_levm_ERC20Approval 1.644 ± 0.011 1.633 1.671 1.07 ± 0.01
pr_revm_ERC20Approval 1.542 ± 0.006 1.526 1.549 1.00
pr_levm_ERC20Approval 1.652 ± 0.006 1.643 1.663 1.07 ± 0.01

Benchmark Results: ERC20Mint

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Mint 187.9 ± 0.5 187.3 188.7 1.00 ± 0.00
main_levm_ERC20Mint 199.6 ± 1.3 198.4 202.8 1.07 ± 0.01
pr_revm_ERC20Mint 187.2 ± 0.4 186.7 188.1 1.00
pr_levm_ERC20Mint 200.0 ± 1.1 198.7 202.2 1.07 ± 0.01

Benchmark Results: ERC20Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Transfer 357.4 ± 2.0 355.9 362.7 1.00 ± 0.01
main_levm_ERC20Transfer 385.1 ± 2.0 382.8 389.2 1.08 ± 0.01
pr_revm_ERC20Transfer 356.3 ± 1.2 355.0 358.8 1.00
pr_levm_ERC20Transfer 385.6 ± 3.6 381.9 392.5 1.08 ± 0.01

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Factorial 243.8 ± 1.1 241.7 245.9 1.00
main_levm_Factorial 276.7 ± 1.1 275.2 278.2 1.13 ± 0.01
pr_revm_Factorial 244.8 ± 1.3 243.5 247.5 1.00 ± 0.01
pr_levm_Factorial 278.5 ± 1.4 277.0 281.9 1.14 ± 0.01

Benchmark Results: FactorialRecursive

Command Mean [s] Min [s] Max [s] Relative
main_revm_FactorialRecursive 1.701 ± 0.036 1.627 1.745 1.00 ± 0.04
main_levm_FactorialRecursive 10.012 ± 0.638 9.043 10.813 5.89 ± 0.44
pr_revm_FactorialRecursive 1.700 ± 0.064 1.533 1.750 1.00
pr_levm_FactorialRecursive 9.599 ± 0.769 9.031 10.796 5.65 ± 0.50

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Fibonacci 219.9 ± 1.6 215.5 221.7 1.00
main_levm_Fibonacci 250.7 ± 1.0 249.6 252.2 1.14 ± 0.01
pr_revm_Fibonacci 220.1 ± 2.8 215.6 226.2 1.00 ± 0.01
pr_levm_Fibonacci 252.3 ± 3.6 250.3 262.4 1.15 ± 0.02

Benchmark Results: FibonacciRecursive

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_FibonacciRecursive 896.8 ± 5.5 888.1 906.1 1.04 ± 0.01
main_levm_FibonacciRecursive 1038.4 ± 5.8 1030.2 1048.0 1.20 ± 0.01
pr_revm_FibonacciRecursive 866.0 ± 7.6 854.3 880.7 1.00
pr_levm_FibonacciRecursive 1041.4 ± 17.7 1030.7 1090.3 1.20 ± 0.02

Benchmark Results: ManyHashes

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ManyHashes 12.4 ± 0.1 12.3 12.5 1.00
main_levm_ManyHashes 13.6 ± 0.1 13.5 13.7 1.10 ± 0.01
pr_revm_ManyHashes 12.6 ± 0.1 12.5 12.7 1.01 ± 0.01
pr_levm_ManyHashes 13.7 ± 0.2 13.5 14.1 1.10 ± 0.02

Benchmark Results: MstoreBench

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_MstoreBench 272.6 ± 3.2 270.5 279.4 1.00
main_levm_MstoreBench 756.8 ± 1.2 755.2 758.6 2.78 ± 0.03
pr_revm_MstoreBench 328.5 ± 174.9 270.7 826.2 1.20 ± 0.64
pr_levm_MstoreBench 757.2 ± 2.1 754.4 760.6 2.78 ± 0.03

Benchmark Results: Push

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Push 308.9 ± 2.2 305.7 312.3 1.00 ± 0.01
main_levm_Push 842.4 ± 7.7 837.6 864.1 2.73 ± 0.03
pr_revm_Push 308.3 ± 1.7 306.5 311.9 1.00
pr_levm_Push 841.7 ± 4.0 839.4 852.8 2.73 ± 0.02

Benchmark Results: SstoreBench_no_opt

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_SstoreBench_no_opt 221.7 ± 2.0 218.7 223.9 2.42 ± 0.03
main_levm_SstoreBench_no_opt 93.0 ± 4.6 89.6 105.9 1.02 ± 0.05
pr_revm_SstoreBench_no_opt 222.2 ± 3.9 219.9 232.8 2.43 ± 0.05
pr_levm_SstoreBench_no_opt 91.4 ± 1.0 89.1 92.4 1.00

@JereSalo JereSalo moved this to In Progress in ethrex_l1 Oct 13, 2025
ethrex-common.workspace = true
ethrex-storage.workspace = true
ethrex-vm.workspace = true
ethrex-levm.workspace = true
Copy link
Collaborator

Choose a reason for hiding this comment

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

if we have to add this here, then the vm crate doesn't really have a reason to exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing that out. I moved the StoreVmDatabase to the vm crate so that it lives there with the other databases that implement the LevmDatabase trait. I think it's tidier this way but I don't know if you think it's a good idea to have it there or not.

@JereSalo JereSalo changed the title refactor(l1,levm): simplify vm database trait refactor(l1,levm): simplify vm database trait. Oct 14, 2025
Base automatically changed from levm/get_storage_root to main October 15, 2025 18:44
@JereSalo JereSalo marked this pull request as ready for review October 15, 2025 21:05
@JereSalo JereSalo requested a review from a team as a code owner October 15, 2025 21:05
@Copilot Copilot AI review requested due to automatic review settings October 15, 2025 21:05
@ethrex-project-sync ethrex-project-sync bot moved this from In Progress to In Review in ethrex_l1 Oct 15, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the VM database trait architecture by removing the VmDatabase trait abstraction and directly implementing the LevmDatabase trait on storage structures. This simplifies the codebase by eliminating an unnecessary abstraction layer.

Key changes:

  • Removed VmDatabase trait and DynVmDatabase type alias
  • Implemented LevmDatabase trait directly on StoreVmDatabase, GuestProgramStateWrapper, and DatabaseLogger
  • Updated method signatures to return non-optional values with defaults instead of Option<T>
  • Changed database wrapper types from Box<dyn VmDatabase> to Arc<dyn LevmDatabase>

Reviewed Changes

Copilot reviewed 18 out of 21 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
crates/vm/lib.rs Removed db module and VmDatabase exports, moved GuestProgramStateWrapper export
crates/vm/backends/mod.rs Removed new_for_l1 and new_for_l2 constructor methods
crates/vm/backends/levm/db/mod.rs Created new module file to export database implementations
crates/vm/backends/levm/db/store.rs Implemented LevmDatabase trait, changed return types to non-optional with defaults
crates/vm/backends/levm/db/witness.rs Implemented LevmDatabase trait, updated error types to DatabaseError
crates/vm/backends/levm/db/logger.rs Removed DynVmDatabase LevmDatabase implementation
crates/vm/Cargo.toml Removed dyn-clone dependency, added ethrex-storage dependency
crates/blockchain/blockchain.rs Updated to use Arc<dyn LevmDatabase> and new constructor methods
crates/blockchain/payload.rs Updated constructor calls to use new_from_db_for_l1/l2
crates/blockchain/tracing.rs Updated import path for StoreVmDatabase
crates/l2/common/src/state_diff.rs Updated to use LevmDatabase trait instead of VmDatabase
crates/l2/prover/src/guest_program/src/execution.rs Updated constructor calls and removed VmDatabase import
tooling/ef_tests/state/utils.rs Changed from Box to Arc for database wrapper
tooling/ef_tests/state/runner/revm_db.rs Implemented direct LevmDatabase usage with AccountState
tooling/ef_tests/state_v2/src/modules/utils.rs Changed from Box to Arc for database wrapper
crates/vm/levm/runner/src/main.rs Changed from Box to Arc for database wrapper
crates/vm/levm/bench/revm_comparison/src/levm_bench.rs Changed from Box to Arc for database wrapper
crates/l2/common/Cargo.toml Added ethrex-levm dependency

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One of the core changes, the databases that implement Levm trait are now in the db folder

Copy link
Contributor Author

@JereSalo JereSalo Oct 16, 2025

Choose a reason for hiding this comment

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

Changes in this file are correct but unimportant because we don't care about the revm runner of eftests anymore. I suggest ignoring them

@JereSalo JereSalo requested a review from mpaulucci October 16, 2025 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L1 Ethereum client levm Lambda EVM implementation

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

2 participants