Skip to content
Draft
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
2239cce
start adding support for more tests
JereSalo Oct 7, 2025
f0a35b0
add more fork variants and dont return error if expected exception do…
JereSalo Oct 7, 2025
dccc615
add support for post state hash
JereSalo Oct 7, 2025
1ec79df
comment tests we dont want to run
JereSalo Oct 7, 2025
2455583
improve some comments
JereSalo Oct 7, 2025
e770f54
rename network to fork
JereSalo Oct 7, 2025
86c50b5
remove unnecessary checks
JereSalo Oct 7, 2025
dbe4eb8
typo
JereSalo Oct 7, 2025
163d91c
remove unnecessary code
JereSalo Oct 7, 2025
5683de0
update gitignore
JereSalo Oct 7, 2025
05a0280
restore mistake i made
JereSalo Oct 7, 2025
934c8b8
vectors targets
JereSalo Oct 7, 2025
b31f222
refactor all.rs to make it prettier
JereSalo Oct 7, 2025
21f46c4
add some reasons for skipped tests
JereSalo Oct 7, 2025
219a252
add reasons of skipped tests
JereSalo Oct 7, 2025
cd220b9
change comment in createBlobhashTx test
JereSalo Oct 7, 2025
2dbeb13
add comment
JereSalo Oct 7, 2025
965f493
Update tooling/ef_tests/blockchain/tests/all.rs
JereSalo Oct 8, 2025
a1b90fb
Update tooling/ef_tests/blockchain/fork.rs
JereSalo Oct 8, 2025
7d454f9
update comment
JereSalo Oct 8, 2025
0821ac7
merge changes from other branch
JereSalo Oct 8, 2025
b9f4354
fix skipped tests in stateless execution
JereSalo Oct 8, 2025
b3445ff
first iteration of having storage root in evm
JereSalo Oct 8, 2025
8c65367
remove skipped tests and impl default for levmaccount
JereSalo Oct 8, 2025
0edc0f2
stop skipping some tests and add comments
JereSalo Oct 8, 2025
eaaa143
improve comments
JereSalo Oct 8, 2025
b9c5dbe
clippy lint
JereSalo Oct 8, 2025
628ec36
add comment
JereSalo Oct 8, 2025
0cae51d
add comment
JereSalo Oct 8, 2025
16d89fb
add comment
JereSalo Oct 8, 2025
ddc3c46
Delete tooling/ef_tests/state/Cargo.lock
JereSalo Oct 8, 2025
7822ca4
add extra skips to sp1
JereSalo Oct 8, 2025
6da2845
add comment
JereSalo Oct 8, 2025
5fa99a1
Merge branch 'skipped_tests_reason' into levm/get_storage_root
JereSalo Oct 8, 2025
c9891d1
uncomment commented test
JereSalo Oct 9, 2025
822d5ec
merge main
JereSalo Oct 9, 2025
8d2e3ec
merge other branch
JereSalo Oct 9, 2025
3f09178
improve comments
JereSalo Oct 9, 2025
8dab81c
add comment and rename to has_storage
JereSalo Oct 9, 2025
a63a566
update comments
JereSalo Oct 9, 2025
1f67670
Merge branch 'main' into skipped_tests_reason
JereSalo Oct 9, 2025
0b73e7a
merge main
JereSalo Oct 9, 2025
6fe1bfc
Merge branch 'main' into skipped_tests_reason
JereSalo Oct 9, 2025
bd4c43b
Update tooling/ef_tests/blockchain/tests/all.rs
JereSalo Oct 10, 2025
8db673b
Delete tooling/ef_tests/state/Cargo.lock
JereSalo Oct 13, 2025
a307fb3
remove comments
JereSalo Oct 13, 2025
617fb61
merge other branch
JereSalo Oct 13, 2025
715b088
start simplifying trait
JereSalo Oct 13, 2025
d87a7c5
clippy lints
JereSalo Oct 13, 2025
af3e402
remove arc again
JereSalo Oct 13, 2025
58013de
remove comment
JereSalo Oct 13, 2025
f09efe3
run cargo fmt
JereSalo Oct 13, 2025
d44fb4e
improve comments
JereSalo Oct 13, 2025
9cd86b8
remove dyn clone crate
JereSalo Oct 13, 2025
01163d9
remove arc import
JereSalo Oct 13, 2025
0934abd
make some fixes
JereSalo Oct 13, 2025
08a320a
add git ignore
JereSalo Oct 13, 2025
4c7754a
change some things for revm runner
JereSalo Oct 13, 2025
b6ee5b5
change some things for revm runner
JereSalo Oct 13, 2025
9dc3a0e
change some things for revm runner 2
JereSalo Oct 13, 2025
f079e01
update lockfiles
JereSalo Oct 13, 2025
4014df9
move StoreVmDatabase to vm crate
JereSalo Oct 14, 2025
6b464d4
delete report
JereSalo Oct 14, 2025
bc37f5e
cargo fmt
JereSalo Oct 14, 2025
ed668ac
update lockfiles
JereSalo Oct 14, 2025
d7cc491
simple fixes
JereSalo Oct 15, 2025
f11a200
merge main
JereSalo Oct 15, 2025
ee3eab1
Merge branch 'main' into simplify_vm_database_trait
JereSalo Oct 15, 2025
3c1af30
import types on top witness.rs
JereSalo Oct 16, 2025
4ecefe9
Merge branch 'main' into simplify_vm_database_trait
JereSalo Oct 16, 2025
32dc09f
Merge branch 'main' into simplify_vm_database_trait
JereSalo Oct 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/blockchain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ethrex-rlp.workspace = true
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.

secp256k1.workspace = true

thiserror.workspace = true
Expand Down
11 changes: 6 additions & 5 deletions crates/blockchain/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use ethrex_storage::{
AccountUpdatesList, Store, UpdateBatch, error::StoreError, hash_address, hash_key,
};
use ethrex_vm::backends::levm::db::DatabaseLogger;
use ethrex_vm::{BlockExecutionResult, DynVmDatabase, Evm, EvmError};
use ethrex_vm::{BlockExecutionResult, Evm, EvmError};
use mempool::Mempool;
use payload::PayloadOrTask;
use std::collections::{BTreeMap, HashMap};
Expand Down Expand Up @@ -216,8 +216,7 @@ impl Blockchain {

for block in blocks {
let parent_hash = block.header.parent_hash;
let vm_db: DynVmDatabase =
Box::new(StoreVmDatabase::new(self.storage.clone(), parent_hash));
let vm_db = StoreVmDatabase::new(self.storage.clone(), parent_hash);
let logger = Arc::new(DatabaseLogger::new(Arc::new(Mutex::new(Box::new(vm_db)))));
let mut vm = match self.options.r#type {
BlockchainType::L1 => Evm::new_from_db_for_l1(logger.clone()),
Expand Down Expand Up @@ -916,9 +915,11 @@ impl Blockchain {
}

pub fn new_evm(&self, vm_db: StoreVmDatabase) -> Result<Evm, EvmError> {
use std::sync::Arc;
let store = Arc::new(vm_db);
let evm = match self.options.r#type {
BlockchainType::L1 => Evm::new_for_l1(vm_db),
BlockchainType::L2 => Evm::new_for_l2(vm_db)?,
BlockchainType::L1 => Evm::new_from_db_for_l1(store),
BlockchainType::L2 => Evm::new_from_db_for_l2(store),
};
Ok(evm)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/blockchain/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ impl PayloadBuildContext {

let vm_db = StoreVmDatabase::new(storage.clone(), payload.header.parent_hash);
let vm = match blockchain_type {
BlockchainType::L1 => Evm::new_for_l1(vm_db),
BlockchainType::L2 => Evm::new_for_l2(vm_db)?,
BlockchainType::L1 => Evm::new_from_db_for_l1(Arc::new(vm_db)),
BlockchainType::L2 => Evm::new_from_db_for_l2(Arc::new(vm_db)),
};

Ok(PayloadBuildContext {
Expand Down
42 changes: 23 additions & 19 deletions crates/blockchain/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ use bytes::Bytes;
use ethrex_common::{
Address, H256, U256,
constants::EMPTY_KECCACK_HASH,
types::{AccountInfo, BlockHash, BlockNumber, ChainConfig},
types::{AccountState, BlockHash, BlockNumber, ChainConfig},
};
use ethrex_levm::db::Database as LevmDatabase;
use ethrex_levm::errors::DatabaseError;
use ethrex_storage::Store;
use ethrex_vm::{EvmError, VmDatabase};
use std::{cmp::Ordering, collections::HashMap};
use tracing::instrument;

Expand Down Expand Up @@ -41,23 +42,25 @@ impl StoreVmDatabase {
}
}

impl VmDatabase for StoreVmDatabase {
impl LevmDatabase for StoreVmDatabase {
#[instrument(level = "trace", name = "Account read", skip_all)]
fn get_account_info(&self, address: Address) -> Result<Option<AccountInfo>, EvmError> {
fn get_account_state(&self, address: Address) -> Result<AccountState, DatabaseError> {
self.store
.get_account_info_by_hash(self.block_hash, address)
.map_err(|e| EvmError::DB(e.to_string()))
.get_account_state_by_hash(self.block_hash, address)
.map(|opt| opt.unwrap_or_default())
.map_err(|e| DatabaseError::Custom(e.to_string()))
}

#[instrument(level = "trace", name = "Storage read", skip_all)]
fn get_storage_slot(&self, address: Address, key: H256) -> Result<Option<U256>, EvmError> {
fn get_storage_value(&self, address: Address, key: H256) -> Result<U256, DatabaseError> {
self.store
.get_storage_at_hash(self.block_hash, address, key)
.map_err(|e| EvmError::DB(e.to_string()))
.map(|opt| opt.unwrap_or_default())
.map_err(|e| DatabaseError::Custom(e.to_string()))
}

#[instrument(level = "trace", name = "Block hash read", skip_all)]
fn get_block_hash(&self, block_number: u64) -> Result<H256, EvmError> {
fn get_block_hash(&self, block_number: u64) -> Result<H256, DatabaseError> {
// Check if we have it cached
if let Some(block_hash) = self.block_hash_cache.get(&block_number) {
return Ok(*block_hash);
Expand All @@ -66,24 +69,25 @@ impl VmDatabase for StoreVmDatabase {
if self
.store
.is_canonical_sync(self.block_hash)
.map_err(|err| EvmError::DB(err.to_string()))?
.map_err(|err| DatabaseError::Custom(err.to_string()))?
{
if let Some(hash) = self
.store
.get_canonical_block_hash_sync(block_number)
.map_err(|err| EvmError::DB(err.to_string()))?
.map_err(|err| DatabaseError::Custom(err.to_string()))?
{
return Ok(hash);
}
// If our block is not canonical then we must look for the target in our block's ancestors
} else {
for ancestor_res in self.store.ancestors(self.block_hash) {
let (hash, ancestor) = ancestor_res.map_err(|e| EvmError::DB(e.to_string()))?;
let (hash, ancestor) =
ancestor_res.map_err(|e| DatabaseError::Custom(e.to_string()))?;
match ancestor.number.cmp(&block_number) {
Ordering::Greater => continue,
Ordering::Equal => return Ok(hash),
Ordering::Less => {
return Err(EvmError::DB(format!(
return Err(DatabaseError::Custom(format!(
"Block number requested {block_number} is higher than the current block number {}",
ancestor.number
)));
Expand All @@ -92,28 +96,28 @@ impl VmDatabase for StoreVmDatabase {
}
}
// Block not found
Err(EvmError::DB(format!(
Err(DatabaseError::Custom(format!(
"Block hash not found for block number {block_number}"
)))
}

fn get_chain_config(&self) -> Result<ChainConfig, EvmError> {
fn get_chain_config(&self) -> Result<ChainConfig, DatabaseError> {
self.store
.get_chain_config()
.map_err(|e| EvmError::DB(e.to_string()))
.map_err(|e| DatabaseError::Custom(e.to_string()))
}

#[instrument(level = "trace", name = "Account code read", skip_all)]
fn get_account_code(&self, code_hash: H256) -> Result<Bytes, EvmError> {
fn get_account_code(&self, code_hash: H256) -> Result<Bytes, DatabaseError> {
if code_hash == *EMPTY_KECCACK_HASH {
return Ok(Bytes::new());
}
match self.store.get_account_code(code_hash) {
Ok(Some(code)) => Ok(code),
Ok(None) => Err(EvmError::DB(format!(
Ok(None) => Err(DatabaseError::Custom(format!(
"Code not found for hash: {code_hash:?}",
))),
Err(e) => Err(EvmError::DB(e.to_string())),
Err(e) => Err(DatabaseError::Custom(e.to_string())),
}
}
}
5 changes: 5 additions & 0 deletions crates/common/trie/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,11 @@ impl Trie {
all_nodes: &BTreeMap<H256, Vec<u8>>,
root_hash: H256,
) -> Result<NodeRef, TrieError> {
// If the root hash is of the empty trie then we can get away by setting the NodeRef to default
if root_hash == *EMPTY_TRIE_HASH {
return Ok(NodeRef::default());
}

let root_rlp = all_nodes
.get(&root_hash)
.ok_or(TrieError::InconsistentTree)?;
Expand Down
12 changes: 4 additions & 8 deletions crates/common/types/block_execution_witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::types::Block;
use crate::{
H160,
constants::EMPTY_KECCACK_HASH,
types::{AccountInfo, AccountState, AccountUpdate, BlockHeader, ChainConfig},
types::{AccountState, AccountUpdate, BlockHeader, ChainConfig},
utils::{decode_hex, keccak},
};
use bytes::Bytes;
Expand Down Expand Up @@ -357,10 +357,10 @@ impl GuestProgramState {

/// Retrieves the account info based on what is stored in the state trie.
/// Returns an error if the state trie is not rebuilt or if decoding the account state fails.
pub fn get_account_info(
pub fn get_account_state(
&mut self,
address: Address,
) -> Result<Option<AccountInfo>, GuestProgramStateError> {
) -> Result<Option<AccountState>, GuestProgramStateError> {
let state_trie = self
.state_trie
.as_ref()
Expand All @@ -380,11 +380,7 @@ impl GuestProgramState {
GuestProgramStateError::Database("Failed to get decode account from trie".to_string())
})?;

Ok(Some(AccountInfo {
balance: state.balance,
code_hash: state.code_hash,
nonce: state.nonce,
}))
Ok(Some(state))
}

/// Fetches the block hash for a specific block number.
Expand Down
1 change: 1 addition & 0 deletions crates/l2/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ethrex-rlp.workspace = true
ethrex-storage.workspace = true
ethrex-trie.workspace = true
ethrex-vm.workspace = true
ethrex-levm.workspace = true
bytes.workspace = true
thiserror.workspace = true
serde.workspace = true
Expand Down
16 changes: 8 additions & 8 deletions crates/l2/common/src/state_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ use ethrex_common::types::{
AccountInfo, AccountState, AccountUpdate, BlockHeader, PrivilegedL2Transaction, TxKind,
code_hash,
};
use ethrex_levm::db::Database as LevmDatabase;
use ethrex_rlp::decode::RLPDecode;
use ethrex_storage::{error::StoreError, hash_address};
use ethrex_trie::{Trie, TrieError};
use ethrex_vm::{EvmError, VmDatabase};
use ethrex_vm::EvmError;
use serde::{Deserialize, Serialize};

use crate::{l1_messages::L1Message, privileged_transactions::PrivilegedTransactionLog};
Expand Down Expand Up @@ -536,16 +537,15 @@ impl Decoder {
/// Calculates nonce_diff between current and previous block.
pub fn get_nonce_diff(
account_update: &AccountUpdate,
db: &impl VmDatabase,
db: &impl LevmDatabase,
) -> Result<u16, StateDiffError> {
// Get previous account_info either from store or cache
let account_info = db.get_account_info(account_update.address)?;
let account_state = db
.get_account_state(account_update.address)
.map_err(EvmError::from)?;

// Get previous nonce
let prev_nonce = match account_info {
Some(info) => info.nonce,
None => 0,
};
let prev_nonce = account_state.nonce;

// Get current nonce
let new_nonce = if let Some(info) = account_update.info.clone() {
Expand All @@ -567,7 +567,7 @@ pub fn get_nonce_diff(
/// Prepare the state diff for the block.
pub fn prepare_state_diff(
last_header: BlockHeader,
db: &impl VmDatabase,
db: &impl LevmDatabase,
l1messages: &[L1Message],
privileged_transactions: &[PrivilegedL2Transaction],
account_updates: Vec<AccountUpdate>,
Expand Down
7 changes: 4 additions & 3 deletions crates/l2/prover/src/guest_program/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ use ethrex_common::{
};
#[cfg(feature = "l2")]
use ethrex_l2_common::l1_messages::L1Message;
use ethrex_vm::{Evm, EvmError, GuestProgramStateWrapper, VmDatabase};
use ethrex_vm::{Evm, EvmError, GuestProgramStateWrapper};
use std::collections::{BTreeMap, HashMap};
use std::sync::Arc;

#[cfg(feature = "l2")]
use ethrex_common::types::{
Expand Down Expand Up @@ -320,9 +321,9 @@ fn execute_stateless(

// Execute block
#[cfg(feature = "l2")]
let mut vm = Evm::new_for_l2(wrapped_db.clone())?;
let mut vm = Evm::new_from_db_for_l2(Arc::new(wrapped_db.clone()));
#[cfg(not(feature = "l2"))]
let mut vm = Evm::new_for_l1(wrapped_db.clone());
let mut vm = Evm::new_from_db_for_l1(Arc::new(wrapped_db.clone()));
let result = vm
.execute_block(block)
.map_err(StatelessExecutionError::EvmError)?;
Expand Down
Loading
Loading