diff --git a/Cargo.toml b/Cargo.toml index 9beb110..bc9b744 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "trevm" -version = "0.23.8" +version = "0.27.0" rust-version = "1.83.0" edition = "2021" authors = ["init4"] @@ -34,7 +34,7 @@ name = "fork_ref_transact" required-features = ["alloy-db"] [dependencies] -alloy = { version = "1.0.5", default-features = false, features = [ +alloy = { version = "1.0.13", default-features = false, features = [ "consensus", "rpc-types-mev", "eips", @@ -44,7 +44,7 @@ alloy = { version = "1.0.5", default-features = false, features = [ "sol-types", ] } -revm = { version = "23.1.0", default-features = false } +revm = { version = "27.0.1", default-features = false } dashmap = { version = "6.1.0", optional = true } tracing = { version = "0.1.41", optional = true } @@ -53,10 +53,10 @@ thiserror = "2.0.11" tokio = { version = "1.44", optional = true } [dev-dependencies] -revm = { version = "23.1.0", features = ["serde-json", "std", "alloydb"] } +revm = { version = "27.0.1", features = ["serde-json", "std", "alloydb"] } trevm = { path = ".", features = ["test-utils"] } -alloy = { version = "1.0.5", features = ["providers", "transports"] } +alloy = { version = "1.0.13", features = ["providers", "transports"] } # misc eyre = "0.6" @@ -87,7 +87,6 @@ estimate_gas = ["optional_eip3607", "optional_no_base_fee", "dep:tracing"] test-utils = ["revm/std", "revm/serde-json", "revm/alloydb"] secp256k1 = ["revm/secp256k1"] -secp256r1 = ["revm/secp256r1"] c-kzg = ["revm/c-kzg"] blst = ["revm/blst"] diff --git a/src/driver/alloy.rs b/src/driver/alloy.rs index 9e6db7a..212c377 100644 --- a/src/driver/alloy.rs +++ b/src/driver/alloy.rs @@ -57,11 +57,11 @@ impl core::fmt::Display for BundleError { Self::BundleEmpty => write!(f, "bundle has no transactions"), Self::Eip4844BlobGasExceeded => write!(f, "max blob gas limit exceeded"), Self::UnsupportedTransactionType => write!(f, "unsupported transaction type"), - Self::TransactionDecodingError(err) => write!(f, "transaction decoding error: {}", err), + Self::TransactionDecodingError(err) => write!(f, "transaction decoding error: {err}"), Self::TransactionSenderRecoveryError(err) => { - write!(f, "transaction sender recovery error: {}", err) + write!(f, "transaction sender recovery error: {err}") } - Self::EVMError { inner } => write!(f, "internal EVM error: {}", inner), + Self::EVMError { inner } => write!(f, "internal EVM error: {inner}"), } } } @@ -107,11 +107,11 @@ impl core::fmt::Debug for BundleError { Self::BlockNumberMismatch => write!(f, "BlockNumberMismatch"), Self::BundleEmpty => write!(f, "BundleEmpty"), Self::BundleReverted => write!(f, "BundleReverted"), - Self::TransactionDecodingError(e) => write!(f, "TransactionDecodingError({:?})", e), + Self::TransactionDecodingError(e) => write!(f, "TransactionDecodingError({e:?})"), Self::UnsupportedTransactionType => write!(f, "UnsupportedTransactionType"), Self::Eip4844BlobGasExceeded => write!(f, "Eip4844BlobGasExceeded"), Self::TransactionSenderRecoveryError(e) => { - write!(f, "TransactionSenderRecoveryError({:?})", e) + write!(f, "TransactionSenderRecoveryError({e:?})") } Self::EVMError { .. } => write!(f, "EVMError"), } @@ -278,7 +278,7 @@ where ) -> DriveBundleResult { // Check if the block we're in is valid for this bundle. Both must match trevm_ensure!( - trevm.inner().block.number == self.bundle.block_number, + trevm.inner().block.number == U256::from(self.bundle.block_number), trevm, BundleError::BlockNumberMismatch ); @@ -296,7 +296,7 @@ where // Set the state block number this simulation was based on self.response.state_block_number = - self.bundle.state_block_number.as_number().unwrap_or(trevm.inner().block.number); + self.bundle.state_block_number.as_number().unwrap_or(trevm.block_number().to()); let bundle_filler = BundleBlockFiller::from(&self.bundle); @@ -416,7 +416,7 @@ where { // Check if the block we're in is valid for this bundle. Both must match trevm_ensure!( - trevm.inner().block.number == self.bundle.block_number, + trevm.block_number() == U256::from(self.bundle.block_number), trevm, BundleError::BlockNumberMismatch ); @@ -424,7 +424,7 @@ where // Check for start timestamp range validity if let Some(min_timestamp) = self.bundle.min_timestamp { trevm_ensure!( - trevm.inner().block.timestamp >= min_timestamp, + trevm.block_timestamp() >= U256::from(min_timestamp), trevm, BundleError::TimestampOutOfRange ); @@ -433,7 +433,7 @@ where // Check for end timestamp range validity if let Some(max_timestamp) = self.bundle.max_timestamp { trevm_ensure!( - trevm.inner().block.timestamp <= max_timestamp, + trevm.block_timestamp() <= U256::from(max_timestamp), trevm, BundleError::TimestampOutOfRange ); @@ -503,9 +503,9 @@ struct BundleBlockFiller { impl Block for BundleBlockFiller { fn fill_block_env(&self, block_env: &mut revm::context::block::BlockEnv) { if let Some(timestamp) = self.timestamp { - block_env.timestamp = timestamp; + block_env.timestamp = U256::from(timestamp); } else { - block_env.timestamp += 12; + block_env.timestamp += U256::from(12); } if let Some(gas_limit) = self.gas_limit { block_env.gas_limit = gas_limit; @@ -517,7 +517,7 @@ impl Block for BundleBlockFiller { block_env.basefee = base_fee.try_into().unwrap_or(u64::MAX); } if let Some(block_number) = self.block_number.as_number() { - block_env.number = block_number; + block_env.number = U256::from(block_number); } } } @@ -559,7 +559,7 @@ where ) -> DriveBundleResult { // Check if the block we're in is valid for this bundle. Both must match trevm_ensure!( - trevm.inner().block.number == self.block_number, + trevm.block_number() == U256::from(self.block_number), trevm, BundleError::BlockNumberMismatch ); @@ -650,7 +650,7 @@ where ) -> DriveBundleResult { // Check if the block we're in is valid for this bundle. Both must match trevm_ensure!( - trevm.inner().block.number == self.block_number, + trevm.block_number() == U256::from(self.block_number), trevm, BundleError::BlockNumberMismatch ); @@ -659,7 +659,7 @@ where if let Some(min_timestamp) = self.min_timestamp { trevm_ensure!( - trevm.inner().block.timestamp >= min_timestamp, + trevm.block_timestamp() >= U256::from(min_timestamp), trevm, BundleError::TimestampOutOfRange ); @@ -668,7 +668,7 @@ where // Check for end timestamp range validity if let Some(max_timestamp) = self.max_timestamp { trevm_ensure!( - trevm.inner().block.timestamp <= max_timestamp, + trevm.block_timestamp() <= U256::from(max_timestamp), trevm, BundleError::TimestampOutOfRange ); diff --git a/src/evm.rs b/src/evm.rs index 4f4f314..e05b950 100644 --- a/src/evm.rs +++ b/src/evm.rs @@ -275,7 +275,7 @@ where &mut self, address: Address, ) -> Result, ::Error> { - self.inner.db().basic(address) + self.inner.db_mut().basic(address) } /// Get the current nonce for a specific address @@ -300,7 +300,7 @@ where address: Address, slot: U256, ) -> Result::Error> { - self.inner.db().storage(address, slot) + self.inner.db_mut().storage(address, slot) } /// Get the code at the given account, if any. @@ -312,7 +312,7 @@ where ) -> Result, ::Error> { let acct_info = self.try_read_account(address)?; match acct_info { - Some(acct) => Ok(Some(self.inner.db().code_by_hash(acct.code_hash)?)), + Some(acct) => Ok(Some(self.inner.db_mut().code_by_hash(acct.code_hash)?)), None => Ok(None), } } @@ -409,7 +409,7 @@ where /// /// Note: due to revm's DB model, this requires a mutable pointer. pub fn read_account(&mut self, address: Address) -> Option { - self.inner.db().basic(address).expect("infallible") + self.inner.db_mut().basic(address).expect("infallible") } /// Get the current nonce for a specific address @@ -430,7 +430,7 @@ where /// /// Note: due to revm's DB model, this requires a mutable pointer. pub fn read_storage(&mut self, address: Address, slot: U256) -> U256 { - self.inner.db().storage(address, slot).expect("infallible") + self.inner.db_mut().storage(address, slot).expect("infallible") } /// Get the code at the given account, if any. @@ -438,7 +438,7 @@ where /// Note: due to revm's DB model, this requires a mutable pointer. pub fn read_code(&mut self, address: Address) -> Option { let acct_info = self.read_account(address)?; - Some(self.inner.db().code_by_hash(acct_info.code_hash).expect("infallible")) + Some(self.inner.db_mut().code_by_hash(acct_info.code_hash).expect("infallible")) } } @@ -493,7 +493,7 @@ where where Db: DatabaseCommit, { - self.inner.db().commit(state); + self.inner.db_mut().commit(state); } /// Modify an account with a closure and commit the modified account. This @@ -735,7 +735,7 @@ where /// Set the [EIP-161] state clear flag, activated in the Spurious Dragon /// hardfork. pub fn set_state_clear_flag(&mut self, flag: bool) { - self.inner.db().set_state_clear_flag(flag) + self.inner.db_mut().set_state_clear_flag(flag) } } @@ -753,7 +753,7 @@ where &mut self, flag: bool, ) -> Result<(), ::Error> { - self.inner.db().try_set_state_clear_flag(flag) + self.inner.db_mut().try_set_state_clear_flag(flag) } } @@ -1129,12 +1129,12 @@ where } /// Get the current block number. - pub fn block_number(&self) -> u64 { + pub fn block_number(&self) -> U256 { self.block().number() } /// Get the current block timestamp. - pub fn block_timestamp(&self) -> u64 { + pub fn block_timestamp(&self) -> U256 { self.block().timestamp() } @@ -1204,8 +1204,8 @@ where /// [`State::take_bundle`]: revm::database::State::take_bundle pub fn finish(self) -> BundleState { let Self { inner: mut evm, .. } = self; - evm.db().merge_transitions(BundleRetention::Reverts); - let bundle = evm.db().take_bundle(); + evm.db_mut().merge_transitions(BundleRetention::Reverts); + let bundle = evm.db_mut().take_bundle(); bundle } @@ -1231,7 +1231,7 @@ where pub fn try_finish( mut self, ) -> Result::Error>> { - let db = self.inner.db(); + let db = self.inner.db_mut(); trevm_try!(db.try_merge_transitions(BundleRetention::Reverts), self); @@ -1544,7 +1544,7 @@ where overrides.fill_block(&mut self.inner); if let Some(hashes) = overrides.block_hash.as_ref() { - self.inner.db().set_block_hashes(hashes) + self.inner.db_mut().set_block_hashes(hashes) } self @@ -1590,7 +1590,7 @@ where overrides.fill_block(&mut self.inner); if let Some(hashes) = overrides.block_hash.as_ref() { - trevm_try!(self.inner.db().try_set_block_hashes(hashes), self); + trevm_try!(self.inner.db_mut().try_set_block_hashes(hashes), self); } Ok(self) @@ -1636,10 +1636,10 @@ where } /// Execute the loaded transaction. This is a wrapper around - /// [`InspectEvm::inspect_replay`] and produces either [`EvmTransacted`] or + /// [`InspectEvm::inspect_tx`] and produces either [`EvmTransacted`] or /// [`EvmErrored`]. pub fn run(mut self) -> Result, EvmErrored> { - let result = self.inner.inspect_replay(); + let result = self.inner.inspect_tx(self.tx().clone()); let Self { inner, .. } = self; @@ -2110,7 +2110,7 @@ where { let Self { mut inner, state: TransactedState { result } } = self; - inner.db().commit(result.state); + inner.db_mut().commit(result.state); (result.result, Trevm { inner, state: NeedsTx::new() }) } @@ -2133,7 +2133,7 @@ where { let Self { mut inner, state: TransactedState { result } } = self; - trevm_try!(inner.db().try_commit(result.state), Trevm { inner, state: NeedsTx::new() }); + trevm_try!(inner.db_mut().try_commit(result.state), Trevm { inner, state: NeedsTx::new() }); Ok((result.result, Trevm { inner, state: NeedsTx::new() })) } diff --git a/src/ext.rs b/src/ext.rs index 8e3e304..7ec57a4 100644 --- a/src/ext.rs +++ b/src/ext.rs @@ -83,7 +83,7 @@ pub trait EvmExtUnchecked { let mut acct = self.account(address)?; let old = self.storage(address, index)?; - let change = EvmStorageSlot::new_changed(old, value); + let change = EvmStorageSlot::new_changed(old, value, 0); acct.storage.insert(index, change); acct.mark_touch(); @@ -171,11 +171,11 @@ pub trait EvmExtUnchecked { } } -impl EvmExtUnchecked for Evm +impl EvmExtUnchecked for Evm where Ctx: ContextTr, { fn db_mut_ext(&mut self) -> &mut Ctx::Db { - self.ctx.db() + self.ctx.db_mut() } } diff --git a/src/fill/alloy.rs b/src/fill/alloy.rs index 07c15ce..a367cda 100644 --- a/src/fill/alloy.rs +++ b/src/fill/alloy.rs @@ -2,10 +2,7 @@ use alloy::{ consensus::{Signed, TxType}, primitives::U256, }; -use revm::{ - context::{BlockEnv, TxEnv}, - context_interface::block::BlobExcessGasAndPrice, -}; +use revm::context::{BlockEnv, TxEnv}; use crate::{Block, Tx}; @@ -288,18 +285,23 @@ impl Block for alloy::consensus::Header { prevrandao, blob_excess_gas_and_price: _, } = block_env; - *number = self.number; + *number = U256::from(self.number); *beneficiary = self.beneficiary; - *timestamp = self.timestamp; + *timestamp = U256::from(self.timestamp); *gas_limit = self.gas_limit; *basefee = self.base_fee_per_gas.unwrap_or_default(); *difficulty = self.difficulty; *prevrandao = Some(self.mix_hash); + let update_fraction = if self.prague_active() { + revm::primitives::eip4844::BLOB_BASE_FEE_UPDATE_FRACTION_PRAGUE + } else { + revm::primitives::eip4844::BLOB_BASE_FEE_UPDATE_FRACTION_CANCUN + }; + if let Some(excess_blob_gas) = self.excess_blob_gas { - block_env - .set_blob_excess_gas_and_price(excess_blob_gas, self.withdrawals_root.is_some()); + block_env.set_blob_excess_gas_and_price(excess_blob_gas, update_fraction); } } @@ -310,26 +312,7 @@ impl Block for alloy::consensus::Header { impl Block for alloy::rpc::types::eth::Header { fn fill_block_env(&self, block_env: &mut BlockEnv) { - let BlockEnv { - number, - beneficiary, - timestamp, - gas_limit, - basefee, - difficulty, - prevrandao, - blob_excess_gas_and_price, - } = block_env; - *number = self.number; - *beneficiary = self.beneficiary; - *timestamp = self.timestamp; - *gas_limit = self.gas_limit; - *basefee = self.base_fee_per_gas.unwrap_or_default(); - *difficulty = self.difficulty; - *prevrandao = Some(self.mix_hash); - *blob_excess_gas_and_price = self - .blob_gas_used - .map(|bgu| BlobExcessGasAndPrice::new(bgu, self.withdrawals_root.is_some())); + self.inner.fill_block_env(block_env); } } @@ -408,7 +391,7 @@ impl Block for alloy::rpc::types::BlockOverrides { *difficulty = U256::from(*d); } if let Some(t) = &self.time { - *timestamp = *t; + *timestamp = U256::from(*t); } if let Some(g) = &self.gas_limit { *gas_limit = *g; diff --git a/src/fill/fillers.rs b/src/fill/fillers.rs index f917a85..9b0a486 100644 --- a/src/fill/fillers.rs +++ b/src/fill/fillers.rs @@ -69,9 +69,9 @@ impl Cfg for GasEstimationFiller { DisableNonceCheck.fill_cfg_env(cfg_env); } - fn fill_cfg( + fn fill_cfg( &self, - evm: &mut revm::context::Evm, Insp, Inst, Prec>, + evm: &mut revm::context::Evm, Insp, Inst, Prec, Frame>, ) { evm.ctx.modify_cfg(|cfg_env| self.fill_cfg_env(cfg_env)); @@ -103,9 +103,9 @@ impl Cfg for CallFiller { DisableNonceCheck.fill_cfg_env(cfg_env); } - fn fill_cfg( + fn fill_cfg( &self, - evm: &mut revm::context::Evm, Insp, Inst, Prec>, + evm: &mut revm::context::Evm, Insp, Inst, Prec, Frame>, ) { evm.ctx.modify_cfg(|cfg_env| self.fill_cfg_env(cfg_env)); diff --git a/src/fill/traits.rs b/src/fill/traits.rs index ddab8ca..c01e0cc 100644 --- a/src/fill/traits.rs +++ b/src/fill/traits.rs @@ -19,8 +19,10 @@ pub trait Tx: Send + Sync { fn fill_tx_env(&self, tx_env: &mut TxEnv); /// Fill the transaction environment on the EVM. - fn fill_tx(&self, evm: &mut Evm, Insp, Inst, Prec>) - where + fn fill_tx( + &self, + evm: &mut Evm, Insp, Inst, Prec, Frame>, + ) where Self: Sized, { evm.ctx.modify_tx(|tx_env| self.fill_tx_env(tx_env)); @@ -67,8 +69,10 @@ pub trait Block: Send + Sync { fn fill_block_env(&self, block_env: &mut BlockEnv); /// Fill the block environment on the EVM. - fn fill_block(&self, evm: &mut Evm, Insp, Inst, Prec>) - where + fn fill_block( + &self, + evm: &mut Evm, Insp, Inst, Prec, Frame>, + ) where Self: Sized, { evm.ctx.modify_block(|block_env| self.fill_block_env(block_env)); @@ -130,8 +134,10 @@ pub trait Cfg: Send + Sync { fn fill_cfg_env(&self, cfg_env: &mut CfgEnv); /// Fill the configuration environment on the EVM. - fn fill_cfg(&self, evm: &mut Evm, Insp, Inst, Prec>) - where + fn fill_cfg( + &self, + evm: &mut Evm, Insp, Inst, Prec, Frame>, + ) where Self: Sized, { evm.ctx.modify_cfg(|cfg_env| self.fill_cfg_env(cfg_env)); @@ -197,16 +203,20 @@ mod test { prevrandao, blob_excess_gas_and_price, } = block_env; - *number = 1; + *number = U256::ONE; *beneficiary = Default::default(); - *timestamp = 1720450148; // Time when I was writing the test code + *timestamp = U256::from(1720450148u64); // Time when I was writing the test code *gas_limit = 30_000_000; *basefee = 5 * GWEI_TO_WEI; let diff = B256::repeat_byte(0xab); *prevrandao = Some(diff); *difficulty = U256::from_be_bytes(diff.into()); - *blob_excess_gas_and_price = Some(BlobExcessGasAndPrice::new(1_000_000, false)); + + *blob_excess_gas_and_price = Some(BlobExcessGasAndPrice::new( + 1_000_000, + revm::primitives::eip4844::BLOB_BASE_FEE_UPDATE_FRACTION_PRAGUE, + )); } fn tx_count_hint(&self) -> Option { diff --git a/src/helpers.rs b/src/helpers.rs index 7ae4db6..40c4c27 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -1,9 +1,9 @@ use revm::{ context::{BlockEnv, CfgEnv, TxEnv}, context_interface::context::ContextError, - handler::{instructions::EthInstructions, EthPrecompiles}, + handler::{instructions::EthInstructions, EthFrame, EthPrecompiles}, inspector::NoOpInspector, - interpreter::{interpreter::EthInterpreter, Interpreter, InterpreterTypes}, + interpreter::{interpreter::EthInterpreter, InstructionContext, InterpreterTypes}, Context, Database, Journal, }; @@ -12,7 +12,7 @@ pub type Ctx, C = ()> = Context, Prec = EthPrecompiles> = - revm::context::Evm, Insp, Inst, Prec>; + revm::context::Evm, Insp, Inst, Prec, EthFrame>; /// Handler table for EVM opcodes. pub type Instructions = EthInstructions>; @@ -22,9 +22,6 @@ pub type Instruction = revm::interpreter::Instruction( - _interpreter: &mut Interpreter, - ctx: &mut Ctx, -) { - ctx.error = Err(ContextError::Custom("forbidden opcode".to_string())); +pub fn forbidden(ctx: InstructionContext<'_, Ctx, Int>) { + ctx.host.error = Err(ContextError::Custom("forbidden opcode".to_string())); } diff --git a/src/inspectors/layer.rs b/src/inspectors/layer.rs index b4b4fc2..9c8705c 100644 --- a/src/inspectors/layer.rs +++ b/src/inspectors/layer.rs @@ -1,7 +1,6 @@ use revm::{ interpreter::{ - CallInputs, CallOutcome, CreateInputs, CreateOutcome, EOFCreateInputs, Interpreter, - InterpreterTypes, + CallInputs, CallOutcome, CreateInputs, CreateOutcome, Interpreter, InterpreterTypes, }, primitives::{Address, Log, U256}, Inspector, @@ -117,27 +116,6 @@ where self.inner.create_end(context, inputs, outcome); } - fn eofcreate( - &mut self, - context: &mut Ctx, - inputs: &mut EOFCreateInputs, - ) -> Option { - if let Some(outcome) = self.outer.eofcreate(context, inputs) { - return Some(outcome); - } - self.inner.eofcreate(context, inputs) - } - - fn eofcreate_end( - &mut self, - context: &mut Ctx, - inputs: &EOFCreateInputs, - outcome: &mut CreateOutcome, - ) { - self.outer.eofcreate_end(context, inputs, outcome); - self.inner.eofcreate_end(context, inputs, outcome); - } - fn selfdestruct(&mut self, contract: Address, target: Address, value: U256) { self.outer.selfdestruct(contract, target, value); self.inner.selfdestruct(contract, target, value); diff --git a/src/inspectors/set.rs b/src/inspectors/set.rs index 48121b6..2b06b88 100644 --- a/src/inspectors/set.rs +++ b/src/inspectors/set.rs @@ -2,8 +2,7 @@ use std::collections::VecDeque; use revm::{ interpreter::{ - CallInputs, CallOutcome, CreateInputs, CreateOutcome, EOFCreateInputs, Interpreter, - InterpreterTypes, + CallInputs, CallOutcome, CreateInputs, CreateOutcome, Interpreter, InterpreterTypes, }, primitives::{Address, Log, U256}, Inspector, @@ -125,29 +124,6 @@ where self.inspectors.iter_mut().for_each(|i| i.create_end(context, inputs, outcome)) } - fn eofcreate( - &mut self, - context: &mut Ctx, - inputs: &mut EOFCreateInputs, - ) -> Option { - for inspector in self.inspectors.iter_mut() { - let outcome = inspector.eofcreate(context, inputs); - if outcome.is_some() { - return outcome; - } - } - None - } - - fn eofcreate_end( - &mut self, - context: &mut Ctx, - inputs: &EOFCreateInputs, - outcome: &mut CreateOutcome, - ) { - self.inspectors.iter_mut().for_each(|i| i.eofcreate_end(context, inputs, outcome)) - } - fn selfdestruct(&mut self, contract: Address, target: Address, value: U256) { self.inspectors.iter_mut().for_each(|i| i.selfdestruct(contract, target, value)) } diff --git a/src/inspectors/spanning.rs b/src/inspectors/spanning.rs index 18fe1d8..c6048fc 100644 --- a/src/inspectors/spanning.rs +++ b/src/inspectors/spanning.rs @@ -2,8 +2,8 @@ use alloy::{consensus::constants::SELECTOR_LEN, hex}; use revm::{ context::{ContextTr, LocalContextTr}, interpreter::{ - CallInput, CallInputs, CallOutcome, CreateInputs, CreateOutcome, EOFCreateInputs, - Interpreter, InterpreterTypes, + CallInput, CallInputs, CallOutcome, CreateInputs, CreateOutcome, Interpreter, + InterpreterTypes, }, Inspector, }; @@ -157,23 +157,6 @@ impl SpanningInspector { fn enter_create(&mut self, context: &Ctx, inputs: &CreateInputs) { self.active.push(self.span_create(context, inputs).entered()) } - - /// Create a span for an EOF `CREATE`-family opcode. - fn span_eof_create(&self, _context: &Ctx, inputs: &EOFCreateInputs) -> Span { - runtime_level_span!( - self.level, - "eof_create", - caller = %inputs.caller, - value = %inputs.value, - gas_limit = inputs.gas_limit, - kind = ?inputs.kind, - ) - } - - /// Create, enter, and store a span for an EOF `CREATE`-family opcode. - fn enter_eof_create(&mut self, context: &Ctx, inputs: &EOFCreateInputs) { - self.active.push(self.span_eof_create(context, inputs).entered()) - } } impl Inspector for SpanningInspector @@ -207,24 +190,6 @@ where ) { self.exit_span(); } - - fn eofcreate( - &mut self, - context: &mut Ctx, - inputs: &mut EOFCreateInputs, - ) -> Option { - self.enter_eof_create(context, inputs); - None - } - - fn eofcreate_end( - &mut self, - _context: &mut Ctx, - _inputs: &EOFCreateInputs, - _outcome: &mut CreateOutcome, - ) { - self.exit_span(); - } } /// Resolve a selector from the [CallInputs]. diff --git a/src/inspectors/timeout.rs b/src/inspectors/timeout.rs index 82a584c..fddbe62 100644 --- a/src/inspectors/timeout.rs +++ b/src/inspectors/timeout.rs @@ -2,8 +2,7 @@ use crate::helpers::Ctx; use revm::{ context_interface::context::ContextError, interpreter::{ - CallInputs, CallOutcome, CreateInputs, CreateOutcome, EOFCreateInputs, Interpreter, - InterpreterTypes, + CallInputs, CallOutcome, CreateInputs, CreateOutcome, Interpreter, InterpreterTypes, }, Database, Inspector, }; @@ -108,23 +107,4 @@ impl Inspector, Int> for TimeLimit ) { check_timeout!(self, ctx); } - - fn eofcreate( - &mut self, - ctx: &mut Ctx, - _inputs: &mut EOFCreateInputs, - ) -> Option { - check_timeout!(self, ctx); - - None - } - - fn eofcreate_end( - &mut self, - ctx: &mut Ctx, - _inputs: &EOFCreateInputs, - _outcome: &mut CreateOutcome, - ) { - check_timeout!(self, ctx); - } } diff --git a/src/journal/coder.rs b/src/journal/coder.rs index e73edd3..14a1968 100644 --- a/src/journal/coder.rs +++ b/src/journal/coder.rs @@ -4,11 +4,7 @@ use alloy::{ rlp::{Buf, BufMut}, }; use revm::{ - bytecode::{ - eip7702::{Eip7702Bytecode, Eip7702DecodeError}, - eof::EofDecodeError, - Eof, - }, + bytecode::eip7702::{Eip7702Bytecode, Eip7702DecodeError}, database::{states::StorageSlot, BundleState}, state::{AccountInfo, Bytecode}, }; @@ -16,7 +12,6 @@ use std::{ borrow::{Cow, ToOwned}, collections::BTreeMap, fmt::Debug, - sync::Arc, vec::Vec, }; @@ -35,7 +30,6 @@ const TAG_STORAGE_UNCHANGED: u8 = 3; // Bytecode encoding const TAG_BYTECODE_RAW: u8 = 0; -const TAG_BYTECODE_EOF: u8 = 1; const TAG_BYTECODE_7702: u8 = 2; // Option encoding @@ -73,9 +67,6 @@ pub enum JournalDecodeError { /// Storage slot is unchanged, journal should not contain unchanged slots. UnchangedStorage, - /// Error decoding an EOF bytecode. - EofDecode(EofDecodeError), - /// Error decoding an EIP-7702 bytecode. Eip7702Decode(Eip7702DecodeError), } @@ -95,9 +86,6 @@ impl core::fmt::Display for JournalDecodeError { "storage slot is unchanged. Unchanged items should never be in the journal" ) } - Self::EofDecode(e) => { - write!(f, "error decoding EOF bytecode: {e}") - } Self::Eip7702Decode(e) => { write!(f, "error decoding EIP-7702 bytecode: {e}") } @@ -108,7 +96,6 @@ impl core::fmt::Display for JournalDecodeError { impl core::error::Error for JournalDecodeError { fn cause(&self) -> Option<&dyn core::error::Error> { match self { - Self::EofDecode(e) => Some(e), Self::Eip7702Decode(e) => Some(e), _ => None, } @@ -120,19 +107,12 @@ impl core::error::Error for JournalDecodeError { fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { - Self::EofDecode(e) => Some(e), Self::Eip7702Decode(e) => Some(e), _ => None, } } } -impl From for JournalDecodeError { - fn from(err: EofDecodeError) -> Self { - Self::EofDecode(err) - } -} - impl From for JournalDecodeError { fn from(err: Eip7702DecodeError) -> Self { Self::Eip7702Decode(err) @@ -365,7 +345,6 @@ impl JournalEncode for Bytecode { fn encode(&self, buf: &mut dyn BufMut) { match self { Self::LegacyAnalyzed(_) => buf.put_u8(TAG_BYTECODE_RAW), - Self::Eof(_) => buf.put_u8(TAG_BYTECODE_EOF), Self::Eip7702(_) => buf.put_u8(TAG_BYTECODE_7702), } @@ -585,7 +564,6 @@ impl JournalDecode for Bytecode { match tag { TAG_BYTECODE_RAW => Ok(Self::new_raw(raw)), - TAG_BYTECODE_EOF => Ok(Self::Eof(Arc::new(Eof::decode(raw)?))), TAG_BYTECODE_7702 => Ok(Self::Eip7702(Eip7702Bytecode::new_raw(raw)?)), _ => Err(JournalDecodeError::InvalidTag { ty_name: "Bytecode", tag, max_expected: 2 }), } @@ -704,23 +682,13 @@ mod test { roundtrip(&changed_acc); let bytecode = Bytecode::new_raw(Bytes::from(vec![1, 2, 3])); - let eof_bytes = Bytecode::Eof(Arc::new(Eof::default())); roundtrip(&bytecode); - roundtrip(&eof_bytes); let bsi = BundleStateIndex { - state: vec![ - (Address::repeat_byte(0xa), created_acc), - (Address::repeat_byte(0xb), changed_acc), - ] - .into_iter() - .collect(), - new_contracts: vec![ - (B256::repeat_byte(0xa), Cow::Owned(bytecode)), - (B256::repeat_byte(0xb), Cow::Owned(eof_bytes)), - ] - .into_iter() - .collect(), + state: vec![(Address::repeat_byte(0xa), created_acc)].into_iter().collect(), + new_contracts: vec![(B256::repeat_byte(0xa), Cow::Owned(bytecode))] + .into_iter() + .collect(), }; roundtrip(&bsi); } diff --git a/src/system/eip2935.rs b/src/system/eip2935.rs index 2d1fb39..987dd70 100644 --- a/src/system/eip2935.rs +++ b/src/system/eip2935.rs @@ -31,7 +31,7 @@ where /// /// [EIP-2935]: https://eips.ethereum.org/EIPS/eip-2935 pub fn apply_eip2935(&mut self) -> Result<(), EVMError> { - if self.spec_id() < SpecId::PRAGUE || self.block().number == 0 { + if self.spec_id() < SpecId::PRAGUE || self.block_number().is_zero() { return Ok(()); } @@ -42,13 +42,16 @@ where )?; let block_num = self.block().number; - let prev_block = block_num.saturating_sub(1); + let prev_block = block_num.saturating_sub(U256::ONE); // Update the EVM state with the new value. - let slot = eip2935_slot(prev_block); + let slot = eip2935_slot(prev_block.to()); - let parent_block_hash = - self.inner_mut_unchecked().db().block_hash(prev_block).map_err(EVMError::Database)?; + let parent_block_hash = self + .inner_mut_unchecked() + .db_mut() + .block_hash(prev_block.to()) + .map_err(EVMError::Database)?; self.try_set_storage_unchecked(HISTORY_STORAGE_ADDRESS, slot, parent_block_hash.into()) .map_err(EVMError::Database)?; @@ -75,12 +78,12 @@ mod test { let mut trevm = crate::test_utils::test_trevm().fill_cfg(&NoopCfg).fill_block(&NoopBlock); trevm.inner_mut_unchecked().modify_block(|block| { - block.number = block_num; + block.number = U256::from(block_num); }); // we set the previous block hash in the cachedb, as it will be loaded // during eip application - trevm.inner_mut_unchecked().db().cache.block_hashes.insert(prev_block_num, prev_hash); + trevm.inner_mut_unchecked().db_mut().cache.block_hashes.insert(prev_block_num, prev_hash); trevm.apply_eip2935().unwrap(); diff --git a/src/system/eip4788.rs b/src/system/eip4788.rs index 839e18d..693e4cc 100644 --- a/src/system/eip4788.rs +++ b/src/system/eip4788.rs @@ -89,7 +89,7 @@ mod test { let mut trevm = crate::test_utils::test_trevm().fill_cfg(&NoopCfg).fill_block(&NoopBlock); trevm.inner_mut_unchecked().modify_block(|block| { - block.timestamp = timestamp; + block.timestamp = U256::from(timestamp); }); let parent_beacon_root = B256::repeat_byte(0xaa); diff --git a/src/system/mod.rs b/src/system/mod.rs index e996655..1c92006 100644 --- a/src/system/mod.rs +++ b/src/system/mod.rs @@ -142,12 +142,12 @@ where let old_base_fee = core::mem::take(&mut block.basefee); let previous_nonce_check = std::mem::replace(&mut evm.ctx.cfg.disable_nonce_check, true); - let mut result = evm.inspect_replay()?; + let mut result = evm.inspect_tx(evm.tx().clone())?; // Cleanup the syscall. cleanup_syscall(evm, &mut result, syscall, old_gas_limit, old_base_fee, previous_nonce_check); - evm.ctx.db().commit(result.state); + evm.ctx.db_mut().commit(result.state); // apply result, remove receipt from block outputs. Ok(result.result) diff --git a/src/test_utils.rs b/src/test_utils.rs index 0e6ce71..c706e45 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -5,8 +5,7 @@ use revm::{ database::{CacheDB, EmptyDB, InMemoryDB, State}, inspector::{inspectors::TracerEip3155, NoOpInspector}, interpreter::{ - CallInputs, CallOutcome, CreateInputs, CreateOutcome, EOFCreateInputs, Interpreter, - InterpreterTypes, + CallInputs, CallOutcome, CreateInputs, CreateOutcome, Interpreter, InterpreterTypes, }, primitives::{hardfork::SpecId, Log}, state::AccountInfo, @@ -209,26 +208,6 @@ where self.create_end = true; } - fn eofcreate( - &mut self, - _context: &mut Ctx, - _inputs: &mut EOFCreateInputs, - ) -> Option { - tracing::info!("eofcreate"); - self.eofcreate = true; - None - } - - fn eofcreate_end( - &mut self, - _context: &mut Ctx, - _inputs: &EOFCreateInputs, - _outcome: &mut CreateOutcome, - ) { - tracing::info!("eofcreate_end"); - self.eofcreate_end = true; - } - fn selfdestruct(&mut self, contract: Address, target: Address, value: U256) { tracing::info!(?contract, ?target, ?value, "selfdestruct"); self.selfdestruct = true;