Skip to content

refactor(levm): use ethrex account types in LEVM #2629

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 12 commits into from
Apr 29, 2025
Merged

Conversation

JereSalo
Copy link
Contributor

@JereSalo JereSalo commented Apr 28, 2025

Motivation

  • Stop using the Account and AccountInfo types defined in LEVM and start using the ones defined in the L1 client.
    • Biggest changes are that AccountInfo no longer has code, so we can't use it with that purpose and also we don't have our struct StorageSlot anymore, so we have to keep track of original values somewhere else.

Description

  • Now we use the structs of the L1 client but they are different from the ones that we used so I had to make changes:
    • get_account_info is now get_account because we also need the code of the account and AccountInfo has the code_hash only. This makes changes on every structure that implements LevmDatabase trait.
    • Now that we don't have StorageSlot that had the current_value and original_value of a storage slot (original_value being the value pre-tx) I had to make some changes to logic and store those original values into an auxiliary HashMap on VM.
  • Added new function get_original_storage() for getting the original storage value.
  • Make some tiny changes in SSTORE, mostly organize it better.

Storage changes deep description:

  • Now every time we want to get the original_value we will look up in the original values stored in the VM struct. These intends to store the storage values previous to starting the execution of a particular transaction. For efficiency and performance, we only update this new field when actually getting the original value.
    • Let me clarify: At the beginning of the transaction the CacheDB could have a lot of accounts with their storage but the VM.storage_original_valueswill start empty on every transaction. When SSTORE opcode is executed and we actually care for the original value of a storage slot we will look at storage_original_values and it won’t find it (the first time), so then it will see what the value in the CacheDB is, and if it’s not there it will finally check on the actual Database. After retrieving the value, it will be added to storage_original_values , but ONLY the FIRST time. That means that if the value keeps on changing the original_value won’t change because once it’s added it’s not modified.

Closes #issue_number

@JereSalo JereSalo added the levm Lambda EVM implementation label Apr 28, 2025
@JereSalo JereSalo self-assigned this Apr 28, 2025
Copy link

github-actions bot commented Apr 28, 2025

Lines of code report

Total lines added: 45
Total lines removed: 60
Total lines changed: 105

Detailed view
+------------------------------------------------------------------------+-------+------+
| File                                                                   | Lines | Diff |
+------------------------------------------------------------------------+-------+------+
| ethrex/cmd/ef_tests/state/runner/mod.rs                                | 226   | -4   |
+------------------------------------------------------------------------+-------+------+
| ethrex/cmd/ef_tests/state/runner/revm_runner.rs                        | 505   | -9   |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/common/types/account.rs                                  | 198   | +32  |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/l2/prover/bench/src/rpc/db.rs                            | 488   | +1   |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/vm/backends/levm/db.rs                                   | 187   | -6   |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/vm/backends/levm/mod.rs                                  | 638   | -10  |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/call_frame.rs                                | 128   | +2   |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/db/cache.rs                                  | 28    | -1   |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/db/gen_db.rs                                 | 188   | -21  |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/db/mod.rs                                    | 18    | +2   |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/gas_cost.rs                                  | 1131  | +1   |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/hooks/default_hook.rs                        | 264   | +2   |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/hooks/l2_hook.rs                             | 194   | +2   |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/lib.rs                                       | 16    | -2   |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/opcode_handlers/environment.rs               | 315   | -3   |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/opcode_handlers/stack_memory_storage_flow.rs | 287   | -1   |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/opcode_handlers/system.rs                    | 842   | +2   |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/utils.rs                                     | 426   | +1   |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/vm.rs                                        | 372   | -3   |
+------------------------------------------------------------------------+-------+------+

Copy link

github-actions bot commented Apr 28, 2025

Benchmark Results Comparison

PR Results

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Factorial 241.2 ± 3.6 238.9 251.2 1.00
levm_Factorial 874.5 ± 5.8 869.4 887.8 3.63 ± 0.06

Benchmark Results: Factorial - Recursive

Command Mean [s] Min [s] Max [s] Relative
revm_FactorialRecursive 1.539 ± 0.107 1.403 1.676 1.00
levm_FactorialRecursive 13.140 ± 0.164 12.979 13.382 8.54 ± 0.60

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Fibonacci 210.4 ± 1.2 209.3 212.3 1.00
levm_Fibonacci 876.3 ± 9.2 865.8 892.3 4.17 ± 0.05

Benchmark Results: ManyHashes

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ManyHashes 8.8 ± 0.1 8.8 8.9 1.00
levm_ManyHashes 17.6 ± 0.2 17.3 18.1 1.99 ± 0.03

Benchmark Results: BubbleSort

Command Mean [s] Min [s] Max [s] Relative
revm_BubbleSort 3.264 ± 0.020 3.245 3.316 1.00
levm_BubbleSort 5.778 ± 0.029 5.754 5.845 1.77 ± 0.01

Benchmark Results: ERC20 - Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Transfer 255.2 ± 1.8 253.8 259.2 1.00
levm_ERC20Transfer 506.3 ± 2.8 500.8 510.1 1.98 ± 0.02

Benchmark Results: ERC20 - Mint

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Mint 145.3 ± 1.1 144.2 147.5 1.00
levm_ERC20Mint 321.0 ± 2.6 317.8 326.2 2.21 ± 0.02

Benchmark Results: ERC20 - Approval

Command Mean [s] Min [s] Max [s] Relative
revm_ERC20Approval 1.050 ± 0.005 1.044 1.058 1.00
levm_ERC20Approval 2.026 ± 0.342 1.902 3.000 1.93 ± 0.33

Main Results

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Factorial 236.5 ± 3.7 227.1 240.9 1.00
levm_Factorial 893.1 ± 11.4 883.8 915.0 3.78 ± 0.08

Benchmark Results: Factorial - Recursive

Command Mean [s] Min [s] Max [s] Relative
revm_FactorialRecursive 1.456 ± 0.088 1.348 1.567 1.00
levm_FactorialRecursive 13.965 ± 0.177 13.817 14.187 9.59 ± 0.59

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Fibonacci 210.6 ± 1.8 206.0 212.9 1.00
levm_Fibonacci 888.5 ± 4.3 883.5 897.8 4.22 ± 0.04

Benchmark Results: ManyHashes

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ManyHashes 8.7 ± 0.0 8.6 8.8 1.00
levm_ManyHashes 17.6 ± 0.2 17.4 18.1 2.03 ± 0.03

Benchmark Results: BubbleSort

Command Mean [s] Min [s] Max [s] Relative
revm_BubbleSort 3.262 ± 0.028 3.234 3.327 1.00
levm_BubbleSort 11.251 ± 0.299 11.043 12.073 3.45 ± 0.10

Benchmark Results: ERC20 - Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Transfer 251.7 ± 4.1 248.9 261.1 1.00
levm_ERC20Transfer 568.9 ± 8.0 561.8 589.1 2.26 ± 0.05

Benchmark Results: ERC20 - Mint

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Mint 141.4 ± 0.6 140.8 142.5 1.00
levm_ERC20Mint 385.3 ± 4.4 378.0 396.0 2.73 ± 0.03

Benchmark Results: ERC20 - Approval

Command Mean [s] Min [s] Max [s] Relative
revm_ERC20Approval 1.034 ± 0.008 1.029 1.056 1.00
levm_ERC20Approval 2.079 ± 0.020 2.054 2.126 2.01 ± 0.02

Copy link

github-actions bot commented Apr 28, 2025

EF Tests Comparison

Test Name MAIN PR DIFF
Summary: 32881/38385 (85.66%) 32725/38385 (85.25%) ⬇️️ -156
Prague: 5202/5202 (100.00%) 5202/5202 (100.00%) ➖️
Cancun: 7608/7608 (100.00%) 7608/7608 (100.00%) ➖️
Shanghai: 3214/3214 (100.00%) 3214/3214 (100.00%) ➖️
Paris: 2886/2886 (100.00%) 2886/2886 (100.00%) ➖️
London: 2898/2915 (99.42%) 2870/2915 (98.46%) ⬇️️ -28
Berlin: 215/2755 (7.80%) 215/2755 (7.80%) ➖️
Istanbul: 238/2709 (8.79%) 238/2709 (8.79%) ➖️
Petersburg: 2512/2564 (97.97%) 2490/2564 (97.11%) ⬇️️ -22
Constantinople: 2334/2428 (96.13%) 2312/2428 (95.22%) ⬇️️ -22
Byzantium: 2444/2492 (98.07%) 2429/2492 (97.47%) ⬇️️ -15
SpuriousDragon: 580/598 (96.99%) 567/598 (94.82%) ⬇️️ -13
Tangerine: 592/669 (88.49%) 570/669 (85.20%) ⬇️️ -22
Homestead: 1373/1465 (93.72%) 1354/1465 (92.42%) ⬇️️ -19
Frontier: 785/880 (89.20%) 770/880 (87.50%) ⬇️️ -15

@JereSalo JereSalo marked this pull request as ready for review April 28, 2025 20:56
@JereSalo JereSalo requested a review from a team as a code owner April 28, 2025 20:56
Copy link
Contributor

@tomip01 tomip01 left a comment

Choose a reason for hiding this comment

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

Very good! Just one suggestion

@JereSalo JereSalo added this pull request to the merge queue Apr 29, 2025
Merged via the queue into main with commit 33e34ef Apr 29, 2025
38 checks passed
@JereSalo JereSalo deleted the levm/acc_types_refactor branch April 29, 2025 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
levm Lambda EVM implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants