diff --git a/bins/revm-test/src/bin/burntpix/main.rs b/bins/revm-test/src/bin/burntpix/main.rs index ef0b78ea2a..6808b05625 100644 --- a/bins/revm-test/src/bin/burntpix/main.rs +++ b/bins/revm-test/src/bin/burntpix/main.rs @@ -4,8 +4,7 @@ use regex::bytes::Regex; use revm::{ db::{CacheDB, EmptyDB}, primitives::{ - address, hex, keccak256, AccountInfo, Address, Bytecode, Bytes, ExecutionResult, Output, - TxKind, B256, U256, + address, hex, keccak256, AccountInfo, Address, Bytecode, Bytes, ChainAddress, ExecutionResult, Output, TransactTo, TxKind, B256, U256 }, Evm, }; @@ -37,8 +36,8 @@ fn main() { let mut evm = Evm::builder() .modify_tx_env(|tx| { - tx.caller = address!("1000000000000000000000000000000000000000"); - tx.transact_to = TxKind::Call(BURNTPIX_MAIN_ADDRESS); + tx.caller = ChainAddress(1, address!("1000000000000000000000000000000000000000")); + tx.transact_to = TransactTo::Call(BURNTPIX_MAIN_ADDRESS); tx.data = run_call_data.clone().into(); }) .with_db(db) diff --git a/crates/interpreter/src/instructions/bitwise.rs b/crates/interpreter/src/instructions/bitwise.rs index 8a87ee5ae0..e9af5b580c 100644 --- a/crates/interpreter/src/instructions/bitwise.rs +++ b/crates/interpreter/src/instructions/bitwise.rs @@ -130,7 +130,7 @@ mod tests { #[test] fn test_shift_left() { let mut host = DummyHost::new(Env::default()); - let mut interpreter = Interpreter::new(Contract::default(), u64::MAX, false); + let mut interpreter = Interpreter::new(Contract::default(), u64::MAX, false, 1, false); struct TestCase { value: U256, @@ -211,7 +211,7 @@ mod tests { #[test] fn test_logical_shift_right() { let mut host = DummyHost::new(Env::default()); - let mut interpreter = Interpreter::new(Contract::default(), u64::MAX, false); + let mut interpreter = Interpreter::new(Contract::default(), u64::MAX, false, 1, false); struct TestCase { value: U256, @@ -292,7 +292,7 @@ mod tests { #[test] fn test_arithmetic_shift_right() { let mut host = DummyHost::new(Env::default()); - let mut interpreter = Interpreter::new(Contract::default(), u64::MAX, false); + let mut interpreter = Interpreter::new(Contract::default(), u64::MAX, false, 1, false); struct TestCase { value: U256, @@ -404,7 +404,7 @@ mod tests { } let mut host = DummyHost::new(Env::default()); - let mut interpreter = Interpreter::new(Contract::default(), u64::MAX, false); + let mut interpreter = Interpreter::new(Contract::default(), u64::MAX, false, 1, false); let input_value = U256::from(0x1234567890abcdef1234567890abcdef_u128); let test_cases = (0..32) diff --git a/crates/interpreter/src/interpreter.rs b/crates/interpreter/src/interpreter.rs index a4696ffc87..9aeb9ee9d8 100644 --- a/crates/interpreter/src/interpreter.rs +++ b/crates/interpreter/src/interpreter.rs @@ -116,18 +116,22 @@ impl Interpreter { /// Test related helper #[cfg(test)] pub fn new_bytecode(bytecode: Bytecode) -> Self { + use revm_primitives::ChainAddress; + Self::new( Contract::new( Bytes::new(), bytecode, None, - crate::primitives::Address::default(), + ChainAddress::default(), None, - crate::primitives::Address::default(), + ChainAddress::default(), U256::ZERO, ), 0, false, + 1, + false ) } @@ -482,7 +486,7 @@ mod tests { #[test] fn object_safety() { - let mut interp = Interpreter::new(Contract::default(), u64::MAX, false); + let mut interp = Interpreter::new(Contract::default(), u64::MAX, false, 1, false); let mut host = crate::DummyHost::default(); let table: &InstructionTable = diff --git a/crates/interpreter/src/interpreter/serde.rs b/crates/interpreter/src/interpreter/serde.rs index 736baf8f4c..76846a6ba4 100644 --- a/crates/interpreter/src/interpreter/serde.rs +++ b/crates/interpreter/src/interpreter/serde.rs @@ -121,7 +121,7 @@ mod tests { #[test] fn test_serde() { - let interp = Interpreter::new(Contract::default(), u64::MAX, false); + let interp = Interpreter::new(Contract::default(), u64::MAX, false, 1, false); let serialized = bincode::serialize(&interp).unwrap(); let de: Interpreter = bincode::deserialize(&serialized).unwrap(); assert_eq!(interp.program_counter(), de.program_counter()); diff --git a/crates/primitives/src/db.rs b/crates/primitives/src/db.rs index 8f102431f5..7eee14b283 100644 --- a/crates/primitives/src/db.rs +++ b/crates/primitives/src/db.rs @@ -1,4 +1,5 @@ use crate::{Account, AccountInfo, ChainAddress, Bytecode, HashMap, B256, U256}; +use alloy_primitives::Address; use auto_impl::auto_impl; pub mod components; @@ -6,12 +7,48 @@ pub use components::{ BlockHash, BlockHashRef, DatabaseComponentError, DatabaseComponents, State, StateRef, }; -/// EVM database interface. #[auto_impl(&mut, Box)] pub trait Database { /// The database error type. type Error; + /// Get basic account information. + fn basic(&mut self, address: Address) -> Result, Self::Error>; + + /// Get account code by its hash. + fn code_by_hash(&mut self, code_hash: B256) -> Result; + + /// Get storage value of address at index. + fn storage(&mut self, address: Address, index: U256) -> Result; + + /// Get block hash by block number. + fn block_hash(&mut self, number: u64) -> Result; +} + +#[auto_impl(&, &mut, Box, Rc, Arc)] +pub trait DatabaseRef { + /// The database error type. + type Error; + + /// Get basic account information. + fn basic_ref(&self, address: Address) -> Result, Self::Error>; + + /// Get account code by its hash. + fn code_by_hash_ref(&self, code_hash: B256) -> Result; + + /// Get storage value of address at index. + fn storage_ref(&self, address: Address, index: U256) -> Result; + + /// Get block hash by block number. + fn block_hash_ref(&self, number: u64) -> Result; +} + +/// EVM database interface. +#[auto_impl(&mut, Box)] +pub trait SyncDatabase { + /// The database error type. + type Error; + /// Get basic account information. fn basic(&mut self, address: ChainAddress) -> Result, Self::Error>; @@ -39,7 +76,7 @@ pub trait DatabaseCommit { /// Use [`WrapDatabaseRef`] to provide [`Database`] implementation for a type /// that only implements this trait. #[auto_impl(&, &mut, Box, Rc, Arc)] -pub trait DatabaseRef { +pub trait SyncDatabaseRef { /// The database error type. type Error; @@ -58,16 +95,16 @@ pub trait DatabaseRef { /// Wraps a [`DatabaseRef`] to provide a [`Database`] implementation. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct WrapDatabaseRef(pub T); +pub struct WrapDatabaseRef(pub T); -impl From for WrapDatabaseRef { +impl From for WrapDatabaseRef { #[inline] fn from(f: F) -> Self { WrapDatabaseRef(f) } } -impl Database for WrapDatabaseRef { +impl SyncDatabase for WrapDatabaseRef { type Error = T::Error; #[inline] @@ -91,7 +128,7 @@ impl Database for WrapDatabaseRef { } } -impl DatabaseCommit for WrapDatabaseRef { +impl DatabaseCommit for WrapDatabaseRef { #[inline] fn commit(&mut self, changes: HashMap) { self.0.commit(changes) diff --git a/crates/primitives/src/db/components.rs b/crates/primitives/src/db/components.rs index 6afefc5e36..e4d0c55d49 100644 --- a/crates/primitives/src/db/components.rs +++ b/crates/primitives/src/db/components.rs @@ -6,7 +6,7 @@ pub use block_hash::{BlockHash, BlockHashRef}; pub use state::{State, StateRef}; use crate::{ - db::{Database, DatabaseRef}, + db::{SyncDatabase as Database, SyncDatabaseRef as DatabaseRef}, Account, AccountInfo, Address, ChainAddress, Bytecode, HashMap, B256, U256, }; diff --git a/crates/primitives/src/env.rs b/crates/primitives/src/env.rs index 36e1346d10..598891bcf7 100644 --- a/crates/primitives/src/env.rs +++ b/crates/primitives/src/env.rs @@ -720,7 +720,6 @@ use alloy_rlp::{Buf, BufMut, Decodable, Encodable, EMPTY_STRING_CODE}; /// The `to` field of a transaction. Either a target address, or empty for a /// contract creation. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "arbitrary", derive(derive_arbitrary::Arbitrary, proptest_derive::Arbitrary))] pub enum TransactTo { /// A transaction that creates a contract. #[default] diff --git a/crates/revm/src/builder.rs b/crates/revm/src/builder.rs index 706ce3c198..4b3ca63c37 100644 --- a/crates/revm/src/builder.rs +++ b/crates/revm/src/builder.rs @@ -1,5 +1,5 @@ use crate::{ - db::{Database, DatabaseRef, EmptyDB, WrapDatabaseRef}, + db::{SyncDatabase as Database, SyncDatabaseRef as DatabaseRef, EmptyDB, WrapDatabaseRef}, handler::register, primitives::{ BlockEnv, CfgEnv, CfgEnvWithHandlerCfg, Env, EnvWithHandlerCfg, HandlerCfg, SpecId, TxEnv, diff --git a/crates/revm/src/context.rs b/crates/revm/src/context.rs index e29b3b4d68..cb0999e5cb 100644 --- a/crates/revm/src/context.rs +++ b/crates/revm/src/context.rs @@ -11,7 +11,7 @@ pub use inner_evm_context::InnerEvmContext; use revm_interpreter::{as_u64_saturated, Eip7702CodeLoad, StateLoad}; use crate::{ - db::{Database, EmptyDB}, + db::{SyncDatabase as Database, EmptyDB}, interpreter::{AccountLoad, Host, SStoreResult, SelfDestructResult}, primitives::{Address, Bytes, ChainAddress, Env, HandlerCfg, Log, B256, BLOCK_HASH_HISTORY, U256}, }; diff --git a/crates/revm/src/context/context_precompiles.rs b/crates/revm/src/context/context_precompiles.rs index f674093535..d97dae5c51 100644 --- a/crates/revm/src/context/context_precompiles.rs +++ b/crates/revm/src/context/context_precompiles.rs @@ -1,7 +1,7 @@ use super::InnerEvmContext; use crate::{ precompile::{Precompile, PrecompileResult}, - primitives::{db::Database, Address, Bytes, HashMap, HashSet}, + primitives::{db::SyncDatabase as Database, Address, Bytes, HashMap, HashSet}, }; use dyn_clone::DynClone; use revm_precompile::{PrecompileSpecId, PrecompileWithAddress, Precompiles}; diff --git a/crates/revm/src/context/evm_context.rs b/crates/revm/src/context/evm_context.rs index 213ce75fab..3295cac354 100644 --- a/crates/revm/src/context/evm_context.rs +++ b/crates/revm/src/context/evm_context.rs @@ -3,7 +3,7 @@ use revm_precompile::PrecompileErrors; use super::inner_evm_context::InnerEvmContext; use crate::{ - db::Database, + db::SyncDatabase as Database, interpreter::{ analysis::validate_eof, return_ok, CallInputs, Contract, CreateInputs, EOFCreateInputs, EOFCreateKind, Gas, InstructionResult, Interpreter, InterpreterResult, diff --git a/crates/revm/src/context/inner_evm_context.rs b/crates/revm/src/context/inner_evm_context.rs index 991716c491..e43beadea8 100644 --- a/crates/revm/src/context/inner_evm_context.rs +++ b/crates/revm/src/context/inner_evm_context.rs @@ -1,5 +1,5 @@ use crate::{ - db::Database, + db::SyncDatabase as Database, interpreter::{ analysis::to_analysed, gas, return_ok, AccountLoad, Eip7702CodeLoad, InstructionResult, InterpreterResult, SStoreResult, SelfDestructResult, StateLoad, diff --git a/crates/revm/src/db/emptydb.rs b/crates/revm/src/db/emptydb.rs index e6572ce387..34dd957e03 100644 --- a/crates/revm/src/db/emptydb.rs +++ b/crates/revm/src/db/emptydb.rs @@ -1,6 +1,6 @@ use core::{convert::Infallible, fmt, marker::PhantomData}; use revm_interpreter::primitives::{ - db::{Database, DatabaseRef}, + db::{SyncDatabase as Database, SyncDatabaseRef as DatabaseRef}, keccak256, AccountInfo, ChainAddress, Bytecode, B256, U256, }; use std::string::ToString; diff --git a/crates/revm/src/db/ethersdb.rs b/crates/revm/src/db/ethersdb.rs index 050f8fcbc5..5810374900 100644 --- a/crates/revm/src/db/ethersdb.rs +++ b/crates/revm/src/db/ethersdb.rs @@ -5,7 +5,7 @@ use ethers_providers::Middleware; use tokio::runtime::{Handle, Runtime}; use crate::primitives::{AccountInfo, Address, Bytecode, ChainAddress, B256, U256}; -use crate::{Database, DatabaseRef}; +use crate::{SyncDatabase as Database, SyncDatabaseRef as DatabaseRef}; use super::utils::HandleOrRuntime; diff --git a/crates/revm/src/db/in_memory_db.rs b/crates/revm/src/db/in_memory_db.rs index fc98a356f2..6e78aa4248 100644 --- a/crates/revm/src/db/in_memory_db.rs +++ b/crates/revm/src/db/in_memory_db.rs @@ -1,9 +1,9 @@ -use super::{DatabaseCommit, DatabaseRef, EmptyDB}; +use super::{DatabaseCommit, SyncDatabaseRef as DatabaseRef, EmptyDB}; use crate::primitives::{ hash_map::Entry, Account, AccountInfo, Address, ChainAddress, Bytecode, HashMap, Log, B256, KECCAK_EMPTY, U256, }; -use crate::Database; +use crate::SyncDatabase as Database; use core::convert::Infallible; use std::vec::Vec; @@ -24,6 +24,7 @@ pub struct CacheDB { /// `code` is always `None`, and bytecode can be found in `contracts`. pub accounts: HashMap, /// Tracks all contracts by their code hash. + // FIX(Cecilia): should be (u64, B256) pub contracts: HashMap, /// All logs that were committed via [DatabaseCommit::commit]. pub logs: Vec, @@ -411,7 +412,7 @@ impl Database for BenchmarkDB { #[cfg(test)] mod tests { use super::{CacheDB, EmptyDB}; - use crate::primitives::{db::Database, AccountInfo, Address, ChainAddress, U256}; + use crate::primitives::{db::SyncDatabase as Database, AccountInfo, Address, ChainAddress, U256}; #[test] fn test_insert_account_storage() { @@ -474,7 +475,7 @@ mod tests { let nonce = 420; let mut init_state = CacheDB::new(EmptyDB::default()); init_state.insert_account_info( - account, + ChainAddress(0, account), AccountInfo { nonce, ..Default::default() @@ -484,9 +485,9 @@ mod tests { let serialized = serde_json::to_string(&init_state).unwrap(); let deserialized: CacheDB = serde_json::from_str(&serialized).unwrap(); - assert!(deserialized.accounts.contains_key(&account)); + assert!(deserialized.accounts.contains_key(&ChainAddress(0, account))); assert_eq!( - deserialized.accounts.get(&account).unwrap().info.nonce, + deserialized.accounts.get(&ChainAddress(0, account)).unwrap().info.nonce, nonce ); } diff --git a/crates/revm/src/db/states/bundle_state.rs b/crates/revm/src/db/states/bundle_state.rs index d8b14771db..e43ef18b76 100644 --- a/crates/revm/src/db/states/bundle_state.rs +++ b/crates/revm/src/db/states/bundle_state.rs @@ -28,7 +28,7 @@ pub struct BundleBuilder { revert_account: HashMap<(u64, ChainAddress), Option>>, revert_storage: HashMap<(u64, ChainAddress), Vec<(U256, U256)>>, - contracts: HashMap, + contracts: HashMap<(u64, B256), Bytecode>, } /// Option for [`BundleState`] when converting it to the plain state. @@ -159,8 +159,8 @@ impl BundleBuilder { } /// Collect contracts info - pub fn contract(mut self, address: B256, bytecode: Bytecode) -> Self { - self.set_contract(address, bytecode); + pub fn contract(mut self, chain_id: u64, address: B256, bytecode: Bytecode) -> Self { + self.set_contract(chain_id, address, bytecode); self } @@ -234,8 +234,8 @@ impl BundleBuilder { } /// Set contracts info. - pub fn set_contract(&mut self, address: B256, bytecode: Bytecode) -> &mut Self { - self.contracts.insert(address, bytecode); + pub fn set_contract(&mut self, chain_id: u64, address: B256, bytecode: Bytecode) -> &mut Self { + self.contracts.insert((chain_id, address), bytecode); self } @@ -365,7 +365,7 @@ impl BundleBuilder { } /// Mutable getter for `contracts` field - pub fn get_contracts_mut(&mut self) -> &mut HashMap { + pub fn get_contracts_mut(&mut self) -> &mut HashMap<(u64, B256), Bytecode> { &mut self.contracts } } @@ -399,7 +399,7 @@ pub struct BundleState { /// Account state. pub state: HashMap, /// All created contracts in this block. - pub contracts: HashMap, + pub contracts: HashMap<(u64, B256), Bytecode>, /// Changes to revert. /// /// Note: Inside vector is *not* sorted by address. @@ -436,7 +436,7 @@ impl BundleState { ), >, >, - contracts: impl IntoIterator, + contracts: impl IntoIterator, ) -> Self { // Create state from iterator. let mut state_size = 0; @@ -495,6 +495,58 @@ impl BundleState { } } + pub fn filter_for_chain(&self, chain_id: u64) -> Self { + let mut state_size = self.state_size; + let state = self + .state + .iter() + .filter_map(|(address, account)| { + if address.0 == chain_id { + Some((*address, account.clone())) + } else { + state_size -= account.size_hint(); + None + } + }) + .collect(); + let contracts = self + .contracts + .iter() + .filter_map(|((id, hash), bytecode)| { + if *id == chain_id { + Some(((*id, *hash), bytecode.clone())) + } else { + None + } + }) + .collect(); + let mut reverts_size = self.reverts_size; + let reverts = self + .reverts + .iter() + .map(|block_reverts| { + block_reverts + .iter() + .filter_map(|(address, revert)| { + if address.0 == chain_id { + Some((*address, revert.clone())) + } else { + reverts_size -= revert.size_hint(); + None + } + }) + .collect::>() + }) + .collect::>(); + Self { + state, + contracts, + reverts: Reverts::new(reverts), + state_size, + reverts_size, + } + } + /// Returns the approximate size of changes in the bundle state. /// The estimation is not precise, because the information about the number of /// destroyed entries that need to be removed is not accessible to the bundle state. @@ -523,8 +575,8 @@ impl BundleState { } /// Get bytecode from state - pub fn bytecode(&self, hash: &B256) -> Option { - self.contracts.get(hash).cloned() + pub fn bytecode(&self, chain_id: u64, hash: &B256) -> Option { + self.contracts.get(&(chain_id, *hash)).cloned() } /// Consume [`TransitionState`] by applying the changes and creating the @@ -549,7 +601,7 @@ impl BundleState { for (address, transition) in transitions.transitions.into_iter() { // add new contract if it was created/changed. if let Some((hash, new_bytecode)) = transition.has_new_contract() { - self.contracts.insert(hash, new_bytecode.clone()); + self.contracts.insert((address.0, hash), new_bytecode.clone()); } // update state and create revert. let revert = match self.state.entry(address) { @@ -635,7 +687,7 @@ impl BundleState { .contracts .into_iter() // remove empty bytecodes - .filter(|(b, _)| *b != KECCAK_EMPTY) + .filter(|((_, b), _)| *b != KECCAK_EMPTY) .collect::>(); StateChangeset { accounts, @@ -1302,7 +1354,7 @@ mod tests { assert!(builder.get_contracts_mut().is_empty()); builder .get_contracts_mut() - .insert(B256::default(), Bytecode::default()); - assert!(builder.get_contracts_mut().contains_key(&B256::default())); + .insert((0, B256::default()), Bytecode::default()); + assert!(builder.get_contracts_mut().contains_key(&(0, B256::default()))); } } diff --git a/crates/revm/src/db/states/changes.rs b/crates/revm/src/db/states/changes.rs index f7c451dde2..a87125aa0e 100644 --- a/crates/revm/src/db/states/changes.rs +++ b/crates/revm/src/db/states/changes.rs @@ -15,7 +15,29 @@ pub struct StateChangeset { /// Vector of **not** sorted storage. pub storage: Vec, /// Vector of contracts by bytecode hash. **not** sorted. - pub contracts: Vec<(B256, Bytecode)>, + pub contracts: Vec<((u64, B256), Bytecode)>, +} + +impl StateChangeset { + pub fn filter_for_chain(&mut self, chain_id: u64) { + // multiple Txs has multiple reverts per ChainAddress, + // filter out account chainges and storage changes for given chain_id + self.accounts = self + .accounts + .drain(..) + .filter(|(chain, _)| chain.0 == chain_id) + .collect(); + self.storage = self + .storage + .drain(..) + .filter(|change| change.address.0 == chain_id) + .collect(); + self.contracts = self + .contracts + .drain(..) + .filter(|((chain, _), _)| *chain == chain_id) + .collect(); + } } /// Plain storage changeset. Used to apply storage changes of plain state to @@ -65,6 +87,29 @@ impl PlainStateReverts { storage: Vec::with_capacity(capacity), } } + + pub fn filter_for_chain(&mut self, chain_id: u64) { + // multiple Txs has multiple reverts per ChainAddress, + // filter out account chainges and storage changes for given chain_id + self.accounts = self + .accounts + .drain(..) + .map(|inner| { + inner.into_iter() + .filter(|(chain, _)| chain.0 == chain_id) + .collect() + }) + .collect(); + self.storage = self + .storage + .drain(..) + .map(|inner| { + inner.into_iter() + .filter(|revert| revert.address.0 == chain_id) + .collect() + }) + .collect(); + } } /// Storage reverts diff --git a/crates/revm/src/db/states/state.rs b/crates/revm/src/db/states/state.rs index 3f22293f39..0dad12be7c 100644 --- a/crates/revm/src/db/states/state.rs +++ b/crates/revm/src/db/states/state.rs @@ -4,7 +4,7 @@ use super::{ }; use crate::db::EmptyDB; use revm_interpreter::primitives::{ - db::{Database, DatabaseCommit}, + db::{SyncDatabase as Database, DatabaseCommit}, hash_map, Account, AccountInfo, Bytecode, HashMap, B256, BLOCK_HASH_HISTORY, U256, }; use std::{ @@ -228,7 +228,7 @@ impl Database for State { hash_map::Entry::Occupied(entry) => Ok(entry.get().clone()), hash_map::Entry::Vacant(entry) => { if self.use_preloaded_bundle { - if let Some(code) = self.bundle_state.contracts.get(&code_hash) { + if let Some(code) = self.bundle_state.contracts.get(&(chain_id, code_hash)) { entry.insert(code.clone()); return Ok(code.clone()); } diff --git a/crates/revm/src/db/states/state_builder.rs b/crates/revm/src/db/states/state_builder.rs index f029ae13d4..9f92192a98 100644 --- a/crates/revm/src/db/states/state_builder.rs +++ b/crates/revm/src/db/states/state_builder.rs @@ -1,7 +1,7 @@ use super::{cache::CacheState, state::DBBox, BundleState, State, TransitionState}; use crate::db::EmptyDB; use revm_interpreter::primitives::{ - db::{Database, DatabaseRef, WrapDatabaseRef}, + db::{SyncDatabase as Database, SyncDatabaseRef as DatabaseRef, WrapDatabaseRef}, B256, }; use std::collections::BTreeMap; diff --git a/crates/revm/src/evm.rs b/crates/revm/src/evm.rs index 3c46bcb794..0a6f60533f 100644 --- a/crates/revm/src/evm.rs +++ b/crates/revm/src/evm.rs @@ -1,6 +1,6 @@ use crate::{ builder::{EvmBuilder, HandlerStage, SetGenericStage}, - db::{Database, DatabaseCommit, EmptyDB}, + db::{SyncDatabase as Database, DatabaseCommit, EmptyDB}, handler::Handler, interpreter::{ CallInputs, CreateInputs, EOFCreateInputs, Host, InterpreterAction, SharedMemory, diff --git a/crates/revm/src/handler.rs b/crates/revm/src/handler.rs index ed31917bbe..4d7453bfff 100644 --- a/crates/revm/src/handler.rs +++ b/crates/revm/src/handler.rs @@ -9,7 +9,7 @@ pub use handle_types::*; // Includes. use crate::{ interpreter::{opcode::InstructionTables, Host, InterpreterAction, SharedMemory}, - primitives::{db::Database, spec_to_generic, EVMError, HandlerCfg, Spec, SpecId}, + primitives::{db::SyncDatabase as Database, spec_to_generic, EVMError, HandlerCfg, Spec, SpecId}, Context, Frame, }; use core::mem; diff --git a/crates/revm/src/handler/handle_types/execution.rs b/crates/revm/src/handler/handle_types/execution.rs index 27d31eb118..f15ad7e33e 100644 --- a/crates/revm/src/handler/handle_types/execution.rs +++ b/crates/revm/src/handler/handle_types/execution.rs @@ -2,7 +2,7 @@ use crate::{ frame::EOFCreateFrame, handler::mainnet, interpreter::{CallInputs, CreateInputs, SharedMemory}, - primitives::{db::Database, EVMError, Spec}, + primitives::{db::SyncDatabase as Database, EVMError, Spec}, CallFrame, Context, CreateFrame, Frame, FrameOrResult, FrameResult, }; use revm_interpreter::{ diff --git a/crates/revm/src/handler/handle_types/generic.rs b/crates/revm/src/handler/handle_types/generic.rs index 434e490676..41dd4c4f83 100644 --- a/crates/revm/src/handler/handle_types/generic.rs +++ b/crates/revm/src/handler/handle_types/generic.rs @@ -1,5 +1,5 @@ use crate::{ - primitives::{db::Database, EVMResultGeneric}, + primitives::{db::SyncDatabase as Database, EVMResultGeneric}, Context, }; use std::sync::Arc; diff --git a/crates/revm/src/handler/handle_types/post_execution.rs b/crates/revm/src/handler/handle_types/post_execution.rs index b6899bbfba..eda2bbc164 100644 --- a/crates/revm/src/handler/handle_types/post_execution.rs +++ b/crates/revm/src/handler/handle_types/post_execution.rs @@ -2,7 +2,7 @@ use crate::{ handler::mainnet, interpreter::Gas, - primitives::{db::Database, EVMError, EVMResultGeneric, ResultAndState, Spec}, + primitives::{db::SyncDatabase as Database, EVMError, EVMResultGeneric, ResultAndState, Spec}, Context, FrameResult, }; use std::sync::Arc; diff --git a/crates/revm/src/handler/handle_types/pre_execution.rs b/crates/revm/src/handler/handle_types/pre_execution.rs index e64c6081e1..9926baa3ee 100644 --- a/crates/revm/src/handler/handle_types/pre_execution.rs +++ b/crates/revm/src/handler/handle_types/pre_execution.rs @@ -2,7 +2,7 @@ use super::{GenericContextHandle, GenericContextHandleRet, GenericContextHandleChain}; use crate::{ handler::mainnet, - primitives::{db::Database, EVMError, Spec}, + primitives::{db::SyncDatabase as Database, EVMError, Spec}, Context, ContextPrecompiles, }; use std::sync::Arc; diff --git a/crates/revm/src/handler/handle_types/validation.rs b/crates/revm/src/handler/handle_types/validation.rs index 8aa55c28c2..644c21f391 100644 --- a/crates/revm/src/handler/handle_types/validation.rs +++ b/crates/revm/src/handler/handle_types/validation.rs @@ -1,6 +1,6 @@ use crate::{ handler::mainnet, - primitives::{db::Database, EVMError, Env, Spec}, + primitives::{db::SyncDatabase as Database, EVMError, Env, Spec}, Context, }; use std::sync::Arc; diff --git a/crates/revm/src/handler/mainnet/execution.rs b/crates/revm/src/handler/mainnet/execution.rs index a189e96c41..b7680eeef8 100644 --- a/crates/revm/src/handler/mainnet/execution.rs +++ b/crates/revm/src/handler/mainnet/execution.rs @@ -1,5 +1,5 @@ use crate::{ - db::Database, + db::SyncDatabase as Database, frame::EOFCreateFrame, interpreter::{ return_ok, return_revert, CallInputs, CreateInputs, CreateOutcome, Gas, InstructionResult, diff --git a/crates/revm/src/handler/mainnet/post_execution.rs b/crates/revm/src/handler/mainnet/post_execution.rs index 3e2f520e3e..78331befa9 100644 --- a/crates/revm/src/handler/mainnet/post_execution.rs +++ b/crates/revm/src/handler/mainnet/post_execution.rs @@ -1,7 +1,7 @@ use crate::{ interpreter::{Gas, SuccessOrHalt}, primitives::{ - db::Database, EVMError, ExecutionResult, ResultAndState, Spec, SpecId, SpecId::LONDON, U256, + db::SyncDatabase as Database, EVMError, ExecutionResult, ResultAndState, Spec, SpecId, SpecId::LONDON, U256, }, Context, FrameResult, }; diff --git a/crates/revm/src/handler/mainnet/pre_execution.rs b/crates/revm/src/handler/mainnet/pre_execution.rs index dd345b3447..a7c8c1820c 100644 --- a/crates/revm/src/handler/mainnet/pre_execution.rs +++ b/crates/revm/src/handler/mainnet/pre_execution.rs @@ -5,7 +5,7 @@ use crate::{ precompile::PrecompileSpecId, primitives::{ - db::Database, + db::SyncDatabase as Database, eip7702, Account, Bytecode, ChainAddress, EVMError, Env, Spec, SpecId::{CANCUN, PRAGUE, SHANGHAI}, TransactTo, TxKind, BLOCKHASH_STORAGE_ADDRESS, U256, diff --git a/crates/revm/src/handler/mainnet/validation.rs b/crates/revm/src/handler/mainnet/validation.rs index 18d6241224..7db0538398 100644 --- a/crates/revm/src/handler/mainnet/validation.rs +++ b/crates/revm/src/handler/mainnet/validation.rs @@ -1,7 +1,7 @@ use revm_interpreter::gas; use crate::{ - primitives::{db::Database, EVMError, Env, InvalidTransaction, Spec}, + primitives::{db::SyncDatabase as Database, EVMError, Env, InvalidTransaction, Spec}, Context, }; diff --git a/crates/revm/src/handler/register.rs b/crates/revm/src/handler/register.rs index e05225c17c..d63fae9dfa 100644 --- a/crates/revm/src/handler/register.rs +++ b/crates/revm/src/handler/register.rs @@ -1,4 +1,4 @@ -use crate::{db::Database, handler::Handler, Context}; +use crate::{db::SyncDatabase as Database, handler::Handler, Context}; use std::boxed::Box; /// EVM Handler diff --git a/crates/revm/src/inspector.rs b/crates/revm/src/inspector.rs index 025a0138ce..91ce230fcb 100644 --- a/crates/revm/src/inspector.rs +++ b/crates/revm/src/inspector.rs @@ -12,7 +12,7 @@ use crate::{ interpreter::{ CallInputs, CallOutcome, CreateInputs, CreateOutcome, EOFCreateInputs, Interpreter, }, - primitives::{db::Database, Address, ChainAddress, Log, U256}, + primitives::{db::SyncDatabase as Database, Address, ChainAddress, Log, U256}, EvmContext, }; use auto_impl::auto_impl; diff --git a/crates/revm/src/inspector/customprinter.rs b/crates/revm/src/inspector/customprinter.rs index 5cadea7c4c..0c379bd731 100644 --- a/crates/revm/src/inspector/customprinter.rs +++ b/crates/revm/src/inspector/customprinter.rs @@ -9,7 +9,7 @@ use crate::{ inspectors::GasInspector, interpreter::{CallInputs, CreateInputs, Interpreter}, primitives::{Address, ChainAddress, U256}, - Database, EvmContext, Inspector, + SyncDatabase as Database, EvmContext, Inspector, }; /// Custom print [Inspector], it has step level information of execution. diff --git a/crates/revm/src/inspector/eip3155.rs b/crates/revm/src/inspector/eip3155.rs index aec20ffd8f..de1a49a99e 100644 --- a/crates/revm/src/inspector/eip3155.rs +++ b/crates/revm/src/inspector/eip3155.rs @@ -3,7 +3,7 @@ use crate::{ interpreter::{ CallInputs, CallOutcome, CreateInputs, CreateOutcome, Interpreter, InterpreterResult, }, - primitives::{db::Database, hex, HashMap, B256, U256}, + primitives::{db::SyncDatabase as Database, hex, HashMap, B256, U256}, EvmContext, Inspector, }; use revm_interpreter::OpCode; diff --git a/crates/revm/src/inspector/gas.rs b/crates/revm/src/inspector/gas.rs index 20d1a060b7..3dab85f961 100644 --- a/crates/revm/src/inspector/gas.rs +++ b/crates/revm/src/inspector/gas.rs @@ -4,7 +4,7 @@ use revm_interpreter::CallOutcome; use crate::{ interpreter::{CallInputs, CreateInputs, CreateOutcome}, - primitives::db::Database, + primitives::db::SyncDatabase as Database, EvmContext, Inspector, }; @@ -90,7 +90,7 @@ mod tests { inspectors::GasInspector, interpreter::{CallInputs, CreateInputs, Interpreter}, primitives::{Log, ChainAddress, TransactTo}, - Database, EvmContext, Inspector, + SyncDatabase as Database, EvmContext, Inspector, }; #[derive(Default, Debug)] diff --git a/crates/revm/src/inspector/handler_register.rs b/crates/revm/src/inspector/handler_register.rs index 7248b3fa67..1e9feda0a7 100644 --- a/crates/revm/src/inspector/handler_register.rs +++ b/crates/revm/src/inspector/handler_register.rs @@ -1,5 +1,5 @@ use crate::{ - db::Database, + db::SyncDatabase as Database, handler::register::EvmHandler, interpreter::{opcode, InstructionResult, Interpreter}, primitives::EVMError, diff --git a/crates/revm/src/inspector/noop.rs b/crates/revm/src/inspector/noop.rs index 9e9556e286..528bde61d6 100644 --- a/crates/revm/src/inspector/noop.rs +++ b/crates/revm/src/inspector/noop.rs @@ -1,4 +1,4 @@ -use crate::{Database, Inspector}; +use crate::{SyncDatabase as Database, Inspector}; /// Dummy [Inspector], helpful as standalone replacement. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct NoOpInspector; diff --git a/crates/revm/src/journaled_state.rs b/crates/revm/src/journaled_state.rs index 75c5dbbce5..1506d4d472 100644 --- a/crates/revm/src/journaled_state.rs +++ b/crates/revm/src/journaled_state.rs @@ -3,7 +3,7 @@ use revm_interpreter::Eip7702CodeLoad; use crate::{ interpreter::{AccountLoad, InstructionResult, SStoreResult, SelfDestructResult, StateLoad}, primitives::{ - db::Database, hash_map::Entry, Account, Address, Bytecode, EVMError, EvmState, + db::SyncDatabase as Database, hash_map::Entry, Account, Address, Bytecode, EVMError, EvmState, EvmStorageSlot, HashMap, HashSet, Log, SpecId, SpecId::*, TransientStorage, B256, KECCAK_EMPTY, PRECOMPILE3, U256, }, diff --git a/crates/revm/src/lib.rs b/crates/revm/src/lib.rs index 5097388526..98874411fa 100644 --- a/crates/revm/src/lib.rs +++ b/crates/revm/src/lib.rs @@ -34,7 +34,7 @@ pub use context::{ pub use db::{ CacheState, DBBox, State, StateBuilder, StateDBBox, TransitionAccount, TransitionState, }; -pub use db::{Database, DatabaseCommit, DatabaseRef, InMemoryDB}; +pub use db::{SyncDatabase, DatabaseRef, Database, DatabaseCommit, SyncDatabaseRef, InMemoryDB}; pub use evm::{Evm, CALL_STACK_LIMIT}; pub use frame::{CallFrame, CreateFrame, Frame, FrameData, FrameOrResult, FrameResult}; pub use handler::Handler;