diff --git a/Cargo.lock b/Cargo.lock index ae154ee4..ce0e42e5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2587,6 +2587,7 @@ dependencies = [ "alloy-rpc-types-engine", "alloy-transport", "alloy-transport-http", + "alloy-trie", "criterion", "kona-host", "kona-mpt", diff --git a/crates/executor/Cargo.toml b/crates/executor/Cargo.toml index fcfd4067..fd4e5103 100644 --- a/crates/executor/Cargo.toml +++ b/crates/executor/Cargo.toml @@ -23,6 +23,7 @@ alloy-consensus = { workspace = true, features = ["k256"] } alloy-primitives = { workspace = true, features = ["rlp"] } alloy-eips.workspace = true alloy-rlp.workspace = true +alloy-trie.workspace = true # Op Alloy op-alloy-consensus.workspace = true diff --git a/crates/executor/src/db/account.rs b/crates/executor/src/db/account.rs deleted file mode 100644 index 400e09d0..00000000 --- a/crates/executor/src/db/account.rs +++ /dev/null @@ -1,82 +0,0 @@ -//! This module contains the [TrieAccount] struct. - -use alloy_primitives::{B256, U256}; -use alloy_rlp::{RlpDecodable, RlpEncodable}; -use revm::primitives::{Account, AccountInfo}; - -/// An Ethereum account as represented in the trie. -#[derive(Clone, Copy, Debug, PartialEq, Eq, Default, RlpEncodable, RlpDecodable)] -pub struct TrieAccount { - /// Account nonce. - pub nonce: u64, - /// Account balance. - pub balance: U256, - /// Account's storage root. - pub storage_root: B256, - /// Hash of the account's bytecode. - pub code_hash: B256, -} - -impl From<(Account, B256)> for TrieAccount { - fn from((account, storage_root): (Account, B256)) -> Self { - Self { - nonce: account.info.nonce, - balance: account.info.balance, - storage_root, - code_hash: account.info.code_hash, - } - } -} - -impl From<(AccountInfo, B256)> for TrieAccount { - fn from((account, storage_root): (AccountInfo, B256)) -> Self { - Self { - nonce: account.nonce, - balance: account.balance, - storage_root, - code_hash: account.code_hash, - } - } -} - -#[cfg(test)] -mod tests { - use super::*; - use alloy_primitives::uint; - - #[test] - fn test_trie_account_from_account() { - let account = Account { - info: AccountInfo { - nonce: 1, - balance: uint!(2_U256), - code_hash: B256::default(), - code: Default::default(), - }, - status: Default::default(), - storage: Default::default(), - }; - let storage_root = B256::default(); - let trie_account = TrieAccount::from((account, storage_root)); - assert_eq!(trie_account.nonce, 1); - assert_eq!(trie_account.balance, uint!(2_U256)); - assert_eq!(trie_account.storage_root, B256::default()); - assert_eq!(trie_account.code_hash, B256::default()); - } - - #[test] - fn test_trie_account_from_account_info() { - let account_info = AccountInfo { - nonce: 1, - balance: uint!(2_U256), - code_hash: B256::default(), - code: Default::default(), - }; - let storage_root = B256::default(); - let trie_account = TrieAccount::from((account_info, storage_root)); - assert_eq!(trie_account.nonce, 1); - assert_eq!(trie_account.balance, uint!(2_U256)); - assert_eq!(trie_account.storage_root, B256::default()); - assert_eq!(trie_account.code_hash, B256::default()); - } -} diff --git a/crates/executor/src/db/mod.rs b/crates/executor/src/db/mod.rs index 355b2178..c283ad83 100644 --- a/crates/executor/src/db/mod.rs +++ b/crates/executor/src/db/mod.rs @@ -6,6 +6,7 @@ use alloc::{string::ToString, vec::Vec}; use alloy_consensus::{Header, Sealed, EMPTY_ROOT_HASH}; use alloy_primitives::{keccak256, Address, B256, U256}; use alloy_rlp::{Decodable, Encodable}; +use alloy_trie::TrieAccount; use kona_mpt::{Nibbles, TrieHinter, TrieNode, TrieNodeError}; use revm::{ db::{states::StorageSlot, BundleState}, @@ -13,9 +14,6 @@ use revm::{ Database, }; -mod account; -pub use account::TrieAccount; - mod traits; pub use traits::{NoopTrieDBProvider, TrieDBProvider}; diff --git a/crates/executor/src/lib.rs b/crates/executor/src/lib.rs index f6ca7e81..49aefc37 100644 --- a/crates/executor/src/lib.rs +++ b/crates/executor/src/lib.rs @@ -22,7 +22,7 @@ pub use executor::{ }; mod db; -pub use db::{NoopTrieDBProvider, TrieAccount, TrieDB, TrieDBProvider}; +pub use db::{NoopTrieDBProvider, TrieDB, TrieDBProvider}; mod constants; mod syscalls;