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(l1,levm): remove coupling LEVM and REVM #2083

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

Conversation

JereSalo
Copy link
Contributor

@JereSalo JereSalo commented Feb 25, 2025

Motivation

  • Try to stop using EvmState whenever possible. (except for when we use REVM, of course)

Description

  • We want to use EvmState only in cases in which we use REVM, not for LEVM methods!
  • LEVM uses its own get_state_transitions, there is no need for using EvmState in it but remember that we can't use ExecutionDB with LEVM!
  • Now we have an EVM struct that has an EvmImplementation enum and a Store.
  • We don't pass ass parameter in EVM methods anything that can be accessed with Store.

Note: There are still functions that are both for LEVM and REVM and therefore they tend to have the parameters each EVM needs. In the case of REVM we need state: EvmState, and in the case of LEVM we need block_cache: CacheDB. We probably want to avoid passing these things as parameters.

We also want to decouple our VMs from Store but maybe that's a change for a following PR.

Note 2: We decided to keep EVM stateless because stateful had complexity attached to it. See #2096

@JereSalo JereSalo added levm Lambda EVM implementation L1 Ethereum client labels Feb 25, 2025
@JereSalo JereSalo self-assigned this Feb 25, 2025
Copy link

github-actions bot commented Feb 25, 2025

| File                                                                     | Lines | Diff |
+--------------------------------------------------------------------------+-------+------+
| /home/runner/work/ethrex/ethrex/cmd/ef_tests/state/runner/levm_runner.rs | 359   | -7   |
+--------------------------------------------------------------------------+-------+------+
| /home/runner/work/ethrex/ethrex/cmd/ef_tests/state/runner/revm_runner.rs | 529   | -3   |
+--------------------------------------------------------------------------+-------+------+
| /home/runner/work/ethrex/ethrex/cmd/ef_tests/state/utils.rs              | 74    | +10  |
+--------------------------------------------------------------------------+-------+------+
| /home/runner/work/ethrex/ethrex/cmd/ethrex/ethrex.rs                     | 433   | +3   |
+--------------------------------------------------------------------------+-------+------+
| /home/runner/work/ethrex/ethrex/crates/blockchain/blockchain.rs          | 282   | +2   |
+--------------------------------------------------------------------------+-------+------+
| /home/runner/work/ethrex/ethrex/crates/blockchain/payload.rs             | 566   | -3   |
+--------------------------------------------------------------------------+-------+------+
| /home/runner/work/ethrex/ethrex/crates/l2/proposer/l1_committer.rs       | 378   | -3   |
+--------------------------------------------------------------------------+-------+------+
| /home/runner/work/ethrex/ethrex/crates/vm/backends/levm.rs               | 437   | -12  |
+--------------------------------------------------------------------------+-------+------+
| /home/runner/work/ethrex/ethrex/crates/vm/backends/mod.rs                | 203   | -81  |
+--------------------------------------------------------------------------+-------+------+
| /home/runner/work/ethrex/ethrex/crates/vm/backends/revm_b.rs             | 650   | +96  |
+--------------------------------------------------------------------------+-------+------+

Total lines added: +111
Total lines removed: 109
Total lines changed: 220


// Validate the block pre-execution
validate_block(block, &parent_header, &chain_config)?;
let BlockExecutionResult {
receipts,
requests,
account_updates,
} = self.vm.execute_block(block, &mut state)?;
} = self.vm.execute_block(block, self.storage.clone())?;
Copy link
Collaborator

@mpaulucci mpaulucci Feb 25, 2025

Choose a reason for hiding this comment

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

I was hoping that we could decouple the vm from storage. I think the vm should not be aware of the storage crate.

Instead, it would be ideal if vm could define an interface for the state access it needs and blockchain could implement that interface by calling methods from storage.

So that our dependency tree can look more like this: https://www.mermaidchart.com/raw/4e4ac69d-5149-40e8-92f2-2466890c2893?theme=light&version=v0.1&format=svg

Thoughts?

Copy link
Contributor Author

@JereSalo JereSalo Feb 25, 2025

Choose a reason for hiding this comment

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

I think I can do something about it but maybe in a subsequent PR (or at least after making sure nothing breaks in the decoupling). I like the idea though!

@JereSalo JereSalo changed the title refactor(l1,levm): remove decoupling LEVM and REVM refactor(l1,levm): remove coupling LEVM and REVM Feb 25, 2025
@JereSalo JereSalo marked this pull request as ready for review February 27, 2025 20:58
@JereSalo JereSalo requested a review from a team as a code owner February 27, 2025 20:58
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
None yet
Development

Successfully merging this pull request may close these issues.

2 participants