diff --git a/Cargo.lock b/Cargo.lock index 944143f2f9b..d6d7e420a1c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -106,9 +106,9 @@ checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" [[package]] name = "alloy-chains" -version = "0.2.30" +version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90f374d3c6d729268bbe2d0e0ff992bb97898b2df756691a62ee1d5f0506bc39" +checksum = "1b9ebac8ff9c2f07667e1803dc777304337e160ce5153335beb45e8ec0751808" dependencies = [ "alloy-primitives", "alloy-rlp", @@ -290,8 +290,7 @@ dependencies = [ [[package]] name = "alloy-evm" version = "0.27.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2ccfe6d724ceabd5518350cfb34f17dd3a6c3cc33579eee94d98101d3a511ff" +source = "git+https://github.com/0xforerunner/evm?rev=0833666#08336663fe05521c820d8e9fdb9b8e040587893e" dependencies = [ "alloy-consensus", "alloy-eips", @@ -3053,18 +3052,18 @@ dependencies = [ [[package]] name = "derive_more" -version = "2.1.1" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d751e9e49156b02b44f9c1815bcb94b984cdcc4396ecc32521c739452808b134" +checksum = "10b768e943bed7bf2cab53df09f4bc34bfd217cdb57d971e769874c9a6710618" dependencies = [ "derive_more-impl", ] [[package]] name = "derive_more-impl" -version = "2.1.1" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "799a97264921d8623a957f6c3b9011f3b5492f557bbb7a5a19b7fa6d06ba8dcb" +checksum = "6d286bfdaf75e988b4a78e013ecd79c581e06399ab53fbacd2d916c2f904f30b" dependencies = [ "convert_case", "proc-macro2", @@ -4760,13 +4759,14 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.20" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" +checksum = "727805d60e7938b76b826a6ef209eb70eaa1812794f9424d4a4e2d740662df5f" dependencies = [ "base64 0.22.1", "bytes", "futures-channel", + "futures-core", "futures-util", "http", "http-body", @@ -12924,9 +12924,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "uuid" -version = "1.20.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee48d38b119b0cd71fe4141b30f5ba9c7c5d9f4e7a3a8b4a674e4b6ef789976f" +checksum = "e2e054861b4bd027cd373e18e8d8d8e6548085000e41290d95ce0c373a654b4a" dependencies = [ "getrandom 0.3.4", "js-sys", @@ -13887,18 +13887,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.8.39" +version = "0.8.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db6d35d663eadb6c932438e763b262fe1a70987f9ae936e60158176d710cae4a" +checksum = "fd74ec98b9250adb3ca554bdde269adf631549f51d8a8f8f0a10b50f1cb298c3" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.39" +version = "0.8.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4122cd3169e94605190e77839c9a40d40ed048d305bfdc146e7df40ab0f3e517" +checksum = "d8a8d209fdf45cf5138cbb5a506f6b52522a25afccc534d1475dad8e31105c6a" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 1f3eef32663..47ae87ef38c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -446,14 +446,18 @@ revm-inspectors = "0.34.2" # eth alloy-dyn-abi = "1.5.5" -alloy-primitives = { version = "1.5.5", default-features = false, features = ["map-foldhash"] } +alloy-primitives = { version = "1.5.5", default-features = false, features = [ + "map-foldhash", +] } alloy-sol-types = { version = "1.5.5", default-features = false } alloy-chains = { version = "0.2.5", default-features = false } alloy-eip2124 = { version = "0.2.0", default-features = false } alloy-eip7928 = { version = "0.3.0", default-features = false } alloy-evm = { version = "0.27.2", default-features = false } -alloy-rlp = { version = "0.3.10", default-features = false, features = ["core-net"] } +alloy-rlp = { version = "0.3.10", default-features = false, features = [ + "core-net", +] } alloy-trie = { version = "0.9.4", default-features = false } alloy-hardforks = "0.4.5" @@ -465,10 +469,15 @@ alloy-genesis = { version = "1.6.3", default-features = false } alloy-json-rpc = { version = "1.6.3", default-features = false } alloy-network = { version = "1.6.3", default-features = false } alloy-network-primitives = { version = "1.6.3", default-features = false } -alloy-provider = { version = "1.6.3", features = ["reqwest", "debug-api"], default-features = false } +alloy-provider = { version = "1.6.3", features = [ + "reqwest", + "debug-api", +], default-features = false } alloy-pubsub = { version = "1.6.3", default-features = false } alloy-rpc-client = { version = "1.6.3", default-features = false } -alloy-rpc-types = { version = "1.6.3", features = ["eth"], default-features = false } +alloy-rpc-types = { version = "1.6.3", features = [ + "eth", +], default-features = false } alloy-rpc-types-admin = { version = "1.6.3", default-features = false } alloy-rpc-types-anvil = { version = "1.6.3", default-features = false } alloy-rpc-types-beacon = { version = "1.6.3", default-features = false } @@ -482,7 +491,9 @@ alloy-serde = { version = "1.6.3", default-features = false } alloy-signer = { version = "1.6.3", default-features = false } alloy-signer-local = { version = "1.6.3", default-features = false } alloy-transport = { version = "1.6.3" } -alloy-transport-http = { version = "1.6.3", features = ["reqwest-rustls-tls"], default-features = false } +alloy-transport-http = { version = "1.6.3", features = [ + "reqwest-rustls-tls", +], default-features = false } alloy-transport-ipc = { version = "1.6.3", default-features = false } alloy-transport-ws = { version = "1.6.3", default-features = false } @@ -501,7 +512,10 @@ either = { version = "1.15.0", default-features = false } arrayvec = { version = "0.7.6", default-features = false } aquamarine = "0.6" auto_impl = "1" -backon = { version = "1.2", default-features = false, features = ["std-blocking-sleep", "tokio-sleep"] } +backon = { version = "1.2", default-features = false, features = [ + "std-blocking-sleep", + "tokio-sleep", +] } bincode = "1.3" bitflags = "2.4" boyer-moore-magiclen = "0.2.16" @@ -523,9 +537,13 @@ itertools = { version = "0.14", default-features = false } linked_hash_set = "0.1" lz4 = "1.28.1" modular-bitfield = "0.13.1" -notify = { version = "8.0.0", default-features = false, features = ["macos_fsevent"] } +notify = { version = "8.0.0", default-features = false, features = [ + "macos_fsevent", +] } nybbles = { version = "0.4.8", default-features = false } -once_cell = { version = "1.19", default-features = false, features = ["critical-section"] } +once_cell = { version = "1.19", default-features = false, features = [ + "critical-section", +] } parking_lot = "0.12" paste = "1.0" rand = "0.9" @@ -544,7 +562,9 @@ strum_macros = "0.27" syn = "2.0" thiserror = { version = "2.0.0", default-features = false } tar = "0.4.44" -tracing = { version = "0.1.0", default-features = false, features = ["attributes"] } +tracing = { version = "0.1.0", default-features = false, features = [ + "attributes", +] } tracing-appender = "0.2" url = { version = "2.3", default-features = false } zstd = "0.13" @@ -582,7 +602,11 @@ futures-util = { version = "0.3", default-features = false } hyper = "1.3" hyper-util = "0.1.5" pin-project = "1.0.12" -reqwest = { version = "0.12", default-features = false, features = ["rustls-tls", "rustls-tls-native-roots", "stream"] } +reqwest = { version = "0.12", default-features = false, features = [ + "rustls-tls", + "rustls-tls-native-roots", + "stream", +] } tracing-futures = "0.2" tower = "0.5" tower-http = "0.6" @@ -607,7 +631,10 @@ proptest-arbitrary-interop = "0.1.0" # crypto enr = { version = "0.13", default-features = false } k256 = { version = "0.13", default-features = false, features = ["ecdsa"] } -secp256k1 = { version = "0.30", default-features = false, features = ["global-context", "recovery"] } +secp256k1 = { version = "0.30", default-features = false, features = [ + "global-context", + "recovery", +] } # rand 8 for secp256k1 rand_08 = { package = "rand", version = "0.8" } @@ -708,6 +735,7 @@ vergen-git2 = "9.1.0" ipnet = "2.11" [patch.crates-io] +alloy-evm = { git = "https://github.com/0xforerunner/evm", rev = "0833666" } # alloy-consensus = { git = "https://github.com/alloy-rs/alloy", rev = "3049f232fbb44d1909883e154eb38ec5962f53a3" } # alloy-contract = { git = "https://github.com/alloy-rs/alloy", rev = "3049f232fbb44d1909883e154eb38ec5962f53a3" } # alloy-eips = { git = "https://github.com/alloy-rs/alloy", rev = "3049f232fbb44d1909883e154eb38ec5962f53a3" } diff --git a/crates/ethereum/evm/src/test_utils.rs b/crates/ethereum/evm/src/test_utils.rs index ed472c28a4d..6286b046b0d 100644 --- a/crates/ethereum/evm/src/test_utils.rs +++ b/crates/ethereum/evm/src/test_utils.rs @@ -2,7 +2,7 @@ use crate::EthEvmConfig; use alloc::{boxed::Box, sync::Arc, vec, vec::Vec}; use alloy_consensus::{Header, TxType}; use alloy_eips::eip7685::Requests; -use alloy_evm::precompiles::PrecompilesMap; +use alloy_evm::{block::StateDB, precompiles::PrecompilesMap}; use alloy_primitives::Bytes; use alloy_rpc_types_engine::ExecutionData; use parking_lot::Mutex; @@ -19,7 +19,6 @@ use reth_execution_types::{BlockExecutionResult, ExecutionOutcome}; use reth_primitives_traits::{BlockTy, SealedBlock, SealedHeader}; use revm::{ context::result::{ExecutionResult, HaltReason, Output, ResultAndState, SuccessReason}, - database::State, Inspector, }; @@ -58,12 +57,12 @@ impl BlockExecutorFactory for MockEvmConfig { fn create_executor<'a, DB, I>( &'a self, - evm: EthEvm<&'a mut State, I, PrecompilesMap>, + evm: EthEvm, _ctx: Self::ExecutionCtx<'a>, ) -> impl BlockExecutorFor<'a, Self, DB, I> where - DB: Database + 'a, - I: Inspector<::Context<&'a mut State>> + 'a, + DB: StateDB + Database + 'a, + I: Inspector<::Context> + 'a, { MockExecutor { result: self.exec_results.lock().pop().unwrap(), @@ -76,18 +75,18 @@ impl BlockExecutorFactory for MockEvmConfig { /// Mock executor that returns a fixed execution result. #[derive(derive_more::Debug)] -pub struct MockExecutor<'a, DB: Database, I> { +pub struct MockExecutor { result: ExecutionOutcome, - evm: EthEvm<&'a mut State, I, PrecompilesMap>, + evm: EthEvm, #[debug(skip)] hook: Option>, receipts: Vec, } -impl<'a, DB: Database, I: Inspector>>> BlockExecutor - for MockExecutor<'a, DB, I> +impl>> BlockExecutor + for MockExecutor { - type Evm = EthEvm<&'a mut State, I, PrecompilesMap>; + type Evm = EthEvm; type Transaction = TransactionSigned; type Receipt = Receipt; type Result = EthTxResult; @@ -139,7 +138,7 @@ impl<'a, DB: Database, I: Inspector>>> BlockExec blob_gas_used: 0, }; - evm.db_mut().bundle_state = bundle; + *evm.db_mut().bundle_state_mut() = bundle; Ok((evm, result)) } diff --git a/crates/evm/evm/src/execute.rs b/crates/evm/evm/src/execute.rs index 00010db95c2..a989b6c0f7a 100644 --- a/crates/evm/evm/src/execute.rs +++ b/crates/evm/evm/src/execute.rs @@ -1,12 +1,14 @@ //! Traits for execution. +use alloc::borrow::Cow; + use crate::{ConfigureEvm, Database, OnStateHook, TxEnvFor}; use alloc::{boxed::Box, sync::Arc, vec::Vec}; use alloy_consensus::{BlockHeader, Header}; use alloy_eips::eip2718::WithEncoded; pub use alloy_evm::block::{BlockExecutor, BlockExecutorFactory}; use alloy_evm::{ - block::{CommitChanges, ExecutableTxParts}, + block::{CommitChanges, ExecutableTxParts, StateDB}, Evm, EvmEnv, EvmFactory, RecoveredTx, ToTxEnv, }; use alloy_primitives::{Address, B256}; @@ -202,7 +204,7 @@ pub struct BlockAssemblerInput<'a, 'b, F: BlockExecutorFactory, H = Header> { /// Output of block execution. pub output: &'b BlockExecutionResult, /// [`BundleState`] after the block execution. - pub bundle_state: &'a BundleState, + pub bundle_state: Cow<'a, BundleState>, /// Provider with access to state. #[debug(skip)] pub state_provider: &'b dyn StateProvider, @@ -222,7 +224,7 @@ impl<'a, 'b, F: BlockExecutorFactory, H> BlockAssemblerInput<'a, 'b, F, H> { parent: &'a SealedHeader, transactions: Vec, output: &'b BlockExecutionResult, - bundle_state: &'a BundleState, + bundle_state: impl Into>, state_provider: &'b dyn StateProvider, state_root: B256, ) -> Self { @@ -232,7 +234,7 @@ impl<'a, 'b, F: BlockExecutorFactory, H> BlockAssemblerInput<'a, 'b, F, H> { parent, transactions, output, - bundle_state, + bundle_state: bundle_state.into(), state_provider, state_root, } @@ -431,8 +433,7 @@ where } } -impl<'a, F, DB, Executor, Builder, N> BlockBuilder - for BasicBlockBuilder<'a, F, Executor, Builder, N> +impl<'a, F, Executor, Builder, N> BlockBuilder for BasicBlockBuilder<'a, F, Executor, Builder, N> where F: BlockExecutorFactory, Executor: BlockExecutor< @@ -440,12 +441,11 @@ where Spec = ::Spec, HaltReason = ::HaltReason, BlockEnv = ::BlockEnv, - DB = &'a mut State, + DB: StateDB + 'a, >, Transaction = N::SignedTx, Receipt = N::Receipt, >, - DB: Database + 'a, Builder: BlockAssembler, N: NodePrimitives, { @@ -479,13 +479,13 @@ where state: impl StateProvider, ) -> Result, BlockExecutionError> { let (evm, result) = self.executor.finish()?; - let (db, evm_env) = evm.finish(); + let (mut db, evm_env) = evm.finish(); // merge all transitions into bundle state db.merge_transitions(BundleRetention::Reverts); // calculate the state root - let hashed_state = state.hashed_post_state(&db.bundle_state); + let hashed_state = state.hashed_post_state(db.bundle_state()); let (state_root, trie_updates) = state .state_root_with_updates(hashed_state.clone()) .map_err(BlockExecutionError::other)?; @@ -499,7 +499,7 @@ where parent: self.parent, transactions, output: &result, - bundle_state: &db.bundle_state, + bundle_state: Cow::Owned(db.take_bundle()), state_provider: &state, state_root, })?; diff --git a/crates/evm/evm/src/lib.rs b/crates/evm/evm/src/lib.rs index bf5ca7ae1de..2dec8b2611c 100644 --- a/crates/evm/evm/src/lib.rs +++ b/crates/evm/evm/src/lib.rs @@ -25,7 +25,7 @@ use alloy_eips::{ eip4895::Withdrawals, }; use alloy_evm::{ - block::{BlockExecutorFactory, BlockExecutorFor}, + block::{BlockExecutorFactory, BlockExecutorFor, StateDB}, precompiles::PrecompilesMap, }; use alloy_primitives::{Address, Bytes, B256}; @@ -35,7 +35,7 @@ use reth_execution_errors::BlockExecutionError; use reth_primitives_traits::{ BlockTy, HeaderTy, NodePrimitives, ReceiptTy, SealedBlock, SealedHeader, TxTy, }; -use revm::{context::TxEnv, database::State, primitives::hardfork::SpecId}; +use revm::{context::TxEnv, primitives::hardfork::SpecId, DatabaseCommit}; pub mod either; /// EVM environment configuration. @@ -313,20 +313,20 @@ pub trait ConfigureEvm: Clone + Debug + Send + Sync + Unpin { /// Creates a strategy with given EVM and execution context. fn create_executor<'a, DB, I>( &'a self, - evm: EvmFor, I>, + evm: EvmFor, ctx: ::ExecutionCtx<'a>, ) -> impl BlockExecutorFor<'a, Self::BlockExecutorFactory, DB, I> where - DB: Database, - I: InspectorFor> + 'a, + DB: StateDB + DatabaseCommit + Database + 'a, + I: InspectorFor + 'a, { self.block_executor_factory().create_executor(evm, ctx) } /// Creates a strategy for execution of a given block. - fn executor_for_block<'a, DB: Database>( + fn executor_for_block<'a, DB: StateDB + DatabaseCommit + Database + 'a>( &'a self, - db: &'a mut State, + db: DB, block: &'a SealedBlock<::Block>, ) -> Result, Self::Error> { let evm = self.evm_for_block(db, block.header())?; @@ -351,7 +351,7 @@ pub trait ConfigureEvm: Clone + Debug + Send + Sync + Unpin { /// ``` fn create_block_builder<'a, DB, I>( &'a self, - evm: EvmFor, I>, + evm: EvmFor, parent: &'a SealedHeader>, ctx: ::ExecutionCtx<'a>, ) -> impl BlockBuilder< @@ -359,8 +359,8 @@ pub trait ConfigureEvm: Clone + Debug + Send + Sync + Unpin { Executor: BlockExecutorFor<'a, Self::BlockExecutorFactory, DB, I>, > where - DB: Database, - I: InspectorFor> + 'a, + DB: StateDB + DatabaseCommit + Database + 'a, + I: InspectorFor + 'a, { BasicBlockBuilder { executor: self.create_executor(evm, ctx.clone()), @@ -400,9 +400,9 @@ pub trait ConfigureEvm: Clone + Debug + Send + Sync + Unpin { /// // Complete block building /// let outcome = builder.finish(state_provider)?; /// ``` - fn builder_for_next_block<'a, DB: Database + 'a>( + fn builder_for_next_block<'a, DB: StateDB + DatabaseCommit + Database + 'a>( &'a self, - db: &'a mut State, + db: DB, parent: &'a SealedHeader<::BlockHeader>, attributes: Self::NextBlockEnvCtx, ) -> Result< diff --git a/examples/custom-beacon-withdrawals/src/main.rs b/examples/custom-beacon-withdrawals/src/main.rs index d6b67572167..248eb07fe55 100644 --- a/examples/custom-beacon-withdrawals/src/main.rs +++ b/examples/custom-beacon-withdrawals/src/main.rs @@ -5,7 +5,7 @@ use alloy_eips::eip4895::Withdrawal; use alloy_evm::{ - block::{BlockExecutorFactory, BlockExecutorFor, ExecutableTx}, + block::{BlockExecutorFactory, BlockExecutorFor, ExecutableTx, StateDB}, eth::{EthBlockExecutionCtx, EthBlockExecutor, EthTxResult}, precompiles::PrecompilesMap, revm::context::Block as _, @@ -23,7 +23,6 @@ use reth_ethereum::{ }, revm::{ context::TxEnv, - db::State, primitives::{address, hardfork::SpecId, Address}, DatabaseCommit, }, @@ -101,12 +100,12 @@ impl BlockExecutorFactory for CustomEvmConfig { fn create_executor<'a, DB, I>( &'a self, - evm: EthEvm<&'a mut State, I, PrecompilesMap>, + evm: EthEvm, ctx: EthBlockExecutionCtx<'a>, ) -> impl BlockExecutorFor<'a, Self, DB, I> where - DB: Database + 'a, - I: InspectorFor> + 'a, + DB: StateDB + DatabaseCommit + Database + 'a, + I: InspectorFor + 'a, { CustomBlockExecutor { inner: EthBlockExecutor::new( @@ -187,10 +186,9 @@ pub struct CustomBlockExecutor<'a, Evm> { inner: EthBlockExecutor<'a, Evm, &'a Arc, &'a RethReceiptBuilder>, } -impl<'db, DB, E> BlockExecutor for CustomBlockExecutor<'_, E> +impl BlockExecutor for CustomBlockExecutor<'_, E> where - DB: Database + 'db, - E: Evm, Tx = TxEnv>, + E: Evm, { type Transaction = TransactionSigned; type Receipt = Receipt;