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

feat(levm): implement create_access_list #2244

Merged
merged 9 commits into from
Mar 27, 2025

Conversation

LeanSerra
Copy link
Contributor

@LeanSerra LeanSerra commented Mar 17, 2025

Motivation

Implement create_access_list for levm

Description

  • Implement a function that executes a transaction and creates from the resulting accrued_substate an access list.
  • Add a function to utils that generates the access list

Observation

Changes touched_storage_slots from HashSet to BTreeSet to align with the expected output order of the addresses in the Hive tests.

Hive Tests

These hive tests should be fixed with this PR

make run-hive EVM_BACKEND="levm" SIMULATION="ethereum/rpc-compat" TEST_PATTERN="rpc-compat/eth_createAccessList/"                          

Closes #2183

@LeanSerra LeanSerra added rpc-api Public rpc-json api for users levm Lambda EVM implementation labels Mar 17, 2025
Copy link

github-actions bot commented Mar 17, 2025

Lines of code report

Total lines added: 43
Total lines removed: 8
Total lines changed: 51

Detailed view
+---------------------------------------+-------+------+
| File                                  | Lines | Diff |
+---------------------------------------+-------+------+
| ethrex/crates/vm/backends/levm/mod.rs | 569   | +43  |
+---------------------------------------+-------+------+
| ethrex/crates/vm/backends/mod.rs      | 339   | -8   |
+---------------------------------------+-------+------+

Copy link

github-actions bot commented Mar 17, 2025

EF Tests Comparison

Same results between main branch and the current PR.

Copy link

github-actions bot commented Mar 17, 2025

Benchmark Results Comparison

PR Results

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Factorial 234.0 ± 1.7 232.3 237.4 1.00
levm_Factorial 924.9 ± 16.5 911.4 970.3 3.95 ± 0.08

Benchmark Results: Factorial - Recursive

Command Mean [s] Min [s] Max [s] Relative
revm_FactorialRecursive 1.359 ± 0.030 1.324 1.404 1.00
levm_FactorialRecursive 15.782 ± 0.035 15.742 15.849 11.61 ± 0.26

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Fibonacci 207.1 ± 3.6 203.8 215.7 1.00
levm_Fibonacci 926.5 ± 18.1 907.7 972.7 4.47 ± 0.12

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 18.7 ± 0.4 18.3 19.7 2.15 ± 0.04

Benchmark Results: BubbleSort

Command Mean [s] Min [s] Max [s] Relative
revm_BubbleSort 3.240 ± 0.025 3.212 3.291 1.00
levm_BubbleSort 6.221 ± 0.024 6.188 6.256 1.92 ± 0.02

Benchmark Results: ERC20 - Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Transfer 254.1 ± 2.1 251.9 257.9 1.00
levm_ERC20Transfer 540.1 ± 14.9 528.9 580.9 2.13 ± 0.06

Benchmark Results: ERC20 - Mint

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Mint 143.9 ± 0.5 143.1 144.8 1.00
levm_ERC20Mint 350.0 ± 2.6 347.2 354.0 2.43 ± 0.02

Benchmark Results: ERC20 - Approval

Command Mean [s] Min [s] Max [s] Relative
revm_ERC20Approval 1.069 ± 0.031 1.054 1.157 1.00
levm_ERC20Approval 2.041 ± 0.040 1.998 2.126 1.91 ± 0.07

Main Results

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Factorial 241.2 ± 1.2 237.9 242.2 1.00
levm_Factorial 924.2 ± 7.9 913.8 935.9 3.83 ± 0.04

Benchmark Results: Factorial - Recursive

Command Mean [s] Min [s] Max [s] Relative
revm_FactorialRecursive 1.468 ± 0.098 1.339 1.600 1.00
levm_FactorialRecursive 15.839 ± 0.133 15.728 16.088 10.79 ± 0.73

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Fibonacci 211.6 ± 0.5 210.9 212.7 1.00
levm_Fibonacci 915.9 ± 3.5 910.1 920.8 4.33 ± 0.02

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 18.4 ± 0.1 18.2 18.5 2.11 ± 0.02

Benchmark Results: BubbleSort

Command Mean [s] Min [s] Max [s] Relative
revm_BubbleSort 3.235 ± 0.019 3.211 3.267 1.00
levm_BubbleSort 6.115 ± 0.014 6.098 6.139 1.89 ± 0.01

Benchmark Results: ERC20 - Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Transfer 253.2 ± 4.2 250.6 264.8 1.00
levm_ERC20Transfer 540.6 ± 6.4 534.7 557.1 2.14 ± 0.04

Benchmark Results: ERC20 - Mint

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Mint 142.5 ± 0.7 141.2 143.5 1.00
levm_ERC20Mint 356.5 ± 1.8 353.0 360.0 2.50 ± 0.02

Benchmark Results: ERC20 - Approval

Command Mean [s] Min [s] Max [s] Relative
revm_ERC20Approval 1.057 ± 0.007 1.049 1.072 1.00
levm_ERC20Approval 2.024 ± 0.019 1.994 2.065 1.92 ± 0.02

@avilagaston9 avilagaston9 force-pushed the levm/implement_create_access_list branch from d00597d to ec6a407 Compare March 17, 2025 17:32
@avilagaston9 avilagaston9 self-assigned this Mar 17, 2025
@avilagaston9 avilagaston9 marked this pull request as ready for review March 17, 2025 18:43
@avilagaston9 avilagaston9 requested a review from a team as a code owner March 17, 2025 18:43
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.

Amazing!

Base automatically changed from levm/feat/implement_simulate_tx to main March 18, 2025 14:28
@avilagaston9 avilagaston9 force-pushed the levm/implement_create_access_list branch from 8fb6b8a to 7a25f44 Compare March 18, 2025 17:39
.map_err(|_| VMError::FatalError)?,
header,
);
let mut env = Environment {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I imagine this is done more than once, maybe it should have an utility function or something?

Copy link
Contributor

Choose a reason for hiding this comment

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

Refactored in 000f5f7!

header: &BlockHeader,
store: &StoreWrapper,
chain_config: &ChainConfig,
block_cache: &mut CacheDB,
Copy link
Contributor

Choose a reason for hiding this comment

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

Does block_cache need to be mutable here? We are not updating the state, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Addressed in 2848656!

Copy link
Contributor

@JereSalo JereSalo left a comment

Choose a reason for hiding this comment

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

I think it looks good! Just left some suggestions but nothing important

let access_list: AccessList = substate
.touched_storage_slots
.iter()
.map(|(k, v)| (*k, v.iter().cloned().collect::<Vec<H256>>()))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
.map(|(k, v)| (*k, v.iter().cloned().collect::<Vec<H256>>()))
.map(|(address, slots)| (*address, slots.iter().cloned().collect::<Vec<H256>>()))

Just for clarity

Copy link
Contributor

Choose a reason for hiding this comment

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

Addressed in 000f5f7!

@@ -738,3 +738,13 @@ pub fn eip7702_get_code(

Ok((true, access_cost, auth_address, authorized_bytecode))
}

pub fn build_access_list(substate: &mut Substate) -> AccessList {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pub fn build_access_list(substate: &mut Substate) -> AccessList {
pub fn build_access_list(substate: &Substate) -> AccessList {

It doesn't need to be mutable, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Addressed in 000f5f7!

tx,
header,
store_wrapper,
&store_wrapper.store.get_chain_config()?,
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can get the chain config inside the function itself so that the interface is simpler. I see that we are also calling get_chain_config() inside of create_access_list despite having it as a parameter. So maybe we could do a let chain_config = ... at the beginning of the function and use that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Addressed in 000f5f7!

@avilagaston9 avilagaston9 added this pull request to the merge queue Mar 27, 2025
Merged via the queue into main with commit f13c24d Mar 27, 2025
46 checks passed
@avilagaston9 avilagaston9 deleted the levm/implement_create_access_list branch March 27, 2025 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
levm Lambda EVM implementation rpc-api Public rpc-json api for users
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement create_access_list
5 participants