diff --git a/crates/handler/src/instructions.rs b/crates/handler/src/instructions.rs index 89bcf663c0..4f853ce8cb 100644 --- a/crates/handler/src/instructions.rs +++ b/crates/handler/src/instructions.rs @@ -45,6 +45,7 @@ where HOST: Host, { /// Returns `EthInstructions` with mainnet spec. + #[deprecated(since = "0.2.0", note = "use new_mainnet_with_spec instead")] pub fn new_mainnet() -> Self { let spec = SpecId::default(); Self::new(instruction_table_gas_changes_spec(spec), spec) @@ -83,13 +84,3 @@ where &self.instruction_table } } - -impl Default for EthInstructions -where - WIRE: InterpreterTypes, - HOST: Host, -{ - fn default() -> Self { - Self::new_mainnet() - } -} diff --git a/crates/handler/src/precompile_provider.rs b/crates/handler/src/precompile_provider.rs index dab165140f..e953484334 100644 --- a/crates/handler/src/precompile_provider.rs +++ b/crates/handler/src/precompile_provider.rs @@ -72,16 +72,6 @@ impl Clone for EthPrecompiles { } } -impl Default for EthPrecompiles { - fn default() -> Self { - let spec = SpecId::default(); - Self { - precompiles: Precompiles::new(PrecompileSpecId::from_spec_id(spec)), - spec, - } - } -} - impl PrecompileProvider for EthPrecompiles { type Output = InterpreterResult; diff --git a/examples/cheatcode_inspector/src/main.rs b/examples/cheatcode_inspector/src/main.rs index 577f29f647..dbce2d0989 100644 --- a/examples/cheatcode_inspector/src/main.rs +++ b/examples/cheatcode_inspector/src/main.rs @@ -18,14 +18,11 @@ use revm::{ Block, JournalTr, Transaction, }, database::InMemoryDB, - handler::{ - instructions::{EthInstructions, InstructionProvider}, - EthPrecompiles, PrecompileProvider, - }, + handler::{instructions::EthInstructions, EthPrecompiles}, inspector::{inspectors::TracerEip3155, JournalExt}, interpreter::{ - interpreter::EthInterpreter, CallInputs, CallOutcome, InterpreterResult, SStoreResult, - SelfDestructResult, StateLoad, + interpreter::EthInterpreter, CallInputs, CallOutcome, SStoreResult, SelfDestructResult, + StateLoad, }, primitives::{ hardfork::SpecId, Address, AddressMap, AddressSet, HashSet, Log, StorageKey, StorageValue, @@ -349,14 +346,7 @@ impl JournalExt for Backend { trait DatabaseExt: JournalTr { /// Mimics `DatabaseExt::transact` /// See `commit_transaction` for the generics - fn method_that_takes_inspector_as_argument< - InspectorT, - BlockT, - TxT, - CfgT, - InstructionProviderT, - PrecompileT, - >( + fn method_that_takes_inspector_as_argument( &mut self, env: Env, inspector: InspectorT, @@ -365,44 +355,21 @@ trait DatabaseExt: JournalTr { InspectorT: Inspector, EthInterpreter>, BlockT: Block, TxT: Transaction + Clone, - CfgT: Cfg, - InstructionProviderT: InstructionProvider< - Context = Context, - InterpreterTypes = EthInterpreter, - > + Default, - PrecompileT: PrecompileProvider< - Context, - Output = InterpreterResult, - > + Default; + CfgT: Cfg; /// Mimics `DatabaseExt::roll_fork_to_transaction` - fn method_that_constructs_inspector( + fn method_that_constructs_inspector( &mut self, env: Env, ) -> anyhow::Result<()> where BlockT: Block, TxT: Transaction + Clone, - CfgT: Cfg, - InstructionProviderT: InstructionProvider< - Context = Context, - InterpreterTypes = EthInterpreter, - > + Default, - PrecompileT: PrecompileProvider< - Context, - Output = InterpreterResult, - > + Default; + CfgT: Cfg; } impl DatabaseExt for Backend { - fn method_that_takes_inspector_as_argument< - InspectorT, - BlockT, - TxT, - CfgT, - InstructionProviderT, - PrecompileT, - >( + fn method_that_takes_inspector_as_argument( &mut self, env: Env, inspector: InspectorT, @@ -412,23 +379,13 @@ impl DatabaseExt for Backend { BlockT: Block, TxT: Transaction + Clone, CfgT: Cfg, - InstructionProviderT: InstructionProvider< - Context = Context, - InterpreterTypes = EthInterpreter, - > + Default, - PrecompileT: PrecompileProvider< - Context, - Output = InterpreterResult, - > + Default, { - commit_transaction::( - self, env, inspector, - )?; + commit_transaction(self, env, inspector)?; self.method_with_inspector_counter += 1; Ok(()) } - fn method_that_constructs_inspector( + fn method_that_constructs_inspector( &mut self, env: Env, ) -> anyhow::Result<()> @@ -436,25 +393,9 @@ impl DatabaseExt for Backend { BlockT: Block, TxT: Transaction + Clone, CfgT: Cfg, - InstructionProviderT: InstructionProvider< - Context = Context, - InterpreterTypes = EthInterpreter, - > + Default, - PrecompileT: PrecompileProvider< - Context, - Output = InterpreterResult, - > + Default, { let inspector = TracerEip3155::new(Box::new(std::io::sink())); - commit_transaction::< - // Generic interpreter types are not supported yet in the `Evm` implementation - TracerEip3155, - BlockT, - TxT, - CfgT, - InstructionProviderT, - PrecompileT, - >(self, env, inspector)?; + commit_transaction(self, env, inspector)?; self.method_without_inspector_counter += 1; Ok(()) @@ -464,25 +405,16 @@ impl DatabaseExt for Backend { /// An REVM inspector that intercepts calls to the cheatcode address and executes them with the help of the /// `DatabaseExt` trait. #[derive(Clone, Default)] -struct Cheatcodes { +struct Cheatcodes { call_count: usize, - phantom: core::marker::PhantomData<(BlockT, TxT, CfgT, InstructionProviderT, PrecompileT)>, + phantom: core::marker::PhantomData<(BlockT, TxT, CfgT)>, } -impl - Cheatcodes +impl Cheatcodes where BlockT: Block + Clone, TxT: Transaction + Clone, CfgT: Cfg + Clone, - InstructionProviderT: InstructionProvider< - Context = Context, - InterpreterTypes = EthInterpreter, - > + Default, - PrecompileT: PrecompileProvider< - Context, - Output = InterpreterResult, - > + Default, { fn apply_cheatcode( &mut self, @@ -496,7 +428,7 @@ where // `transact` cheatcode would do this context .journal_mut() - .method_that_takes_inspector_as_argument::<_, _, _, _, InstructionProviderT, PrecompileT>( + .method_that_takes_inspector_as_argument( Env { block: block.clone(), tx: tx.clone(), @@ -508,28 +440,17 @@ where // `rollFork(bytes32 transaction)` cheatcode would do this context .journal_mut() - .method_that_constructs_inspector::<_, _, _, InstructionProviderT, PrecompileT>( - Env { block, tx, cfg }, - )?; + .method_that_constructs_inspector(Env { block, tx, cfg })?; Ok(()) } } -impl - Inspector> - for Cheatcodes +impl Inspector> + for Cheatcodes where BlockT: Block + Clone, TxT: Transaction + Clone, CfgT: Cfg + Clone, - InstructionProviderT: InstructionProvider< - Context = Context, - InterpreterTypes = EthInterpreter, - > + Default, - PrecompileT: PrecompileProvider< - Context, - Output = InterpreterResult, - > + Default, { /// Note that precompiles are no longer accessible via `EvmContext::precompiles`. fn call( @@ -572,7 +493,7 @@ impl Env { /// Executes a transaction and runs the inspector using the `Backend` as the state. /// Mimics `commit_transaction` -fn commit_transaction( +fn commit_transaction( backend: &mut Backend, env: Env, inspector: InspectorT, @@ -582,14 +503,6 @@ where BlockT: Block, TxT: Transaction + Clone, CfgT: Cfg, - InstructionProviderT: InstructionProvider< - Context = Context, - InterpreterTypes = EthInterpreter, - > + Default, - PrecompileT: PrecompileProvider< - Context, - Output = InterpreterResult, - > + Default, { // Create new journaled state and backend with the same DB and journaled state as the original for the transaction. // This new backend and state will be discarded after the transaction is done and the changes are applied to the @@ -611,8 +524,8 @@ where let mut evm = Evm::new_with_inspector( context, inspector, - InstructionProviderT::default(), - PrecompileT::default(), + EthInstructions::new_mainnet_with_spec(SpecId::default()), + EthPrecompiles::new(SpecId::default()), ); let state = evm.inspect_tx(tx)?.state; @@ -642,13 +555,7 @@ fn update_state(state: &mut EvmState, db: &mut DB) -> Result<(), D fn main() -> anyhow::Result<()> { let backend = Backend::new(SpecId::default(), InMemoryDB::default()); - let mut inspector = Cheatcodes::< - BlockEnv, - TxEnv, - CfgEnv, - EthInstructions>, - EthPrecompiles, - >::default(); + let mut inspector = Cheatcodes::::default(); let env = Env::mainnet(); let tx = env.tx.clone(); @@ -665,8 +572,8 @@ fn main() -> anyhow::Result<()> { let mut evm = Evm::new_with_inspector( context, &mut inspector, - EthInstructions::default(), - EthPrecompiles::default(), + EthInstructions::new_mainnet_with_spec(SpecId::default()), + EthPrecompiles::new(SpecId::default()), ); evm.inspect_tx(tx)?; diff --git a/examples/custom_opcodes/src/main.rs b/examples/custom_opcodes/src/main.rs index c81d99f238..5964048511 100644 --- a/examples/custom_opcodes/src/main.rs +++ b/examples/custom_opcodes/src/main.rs @@ -12,6 +12,7 @@ use revm::{ interpreter_types::{Immediates, Jumps}, Instruction, InstructionContext, }, + primitives::hardfork::SpecId, primitives::TxKind, state::Bytecode, Context, InspectEvm, MainContext, @@ -37,7 +38,7 @@ pub fn main() { ))); // Create a new instruction set with our mainnet opcodes. - let mut instructions = EthInstructions::new_mainnet(); + let mut instructions = EthInstructions::new_mainnet_with_spec(SpecId::default()); // insert our custom opcode instructions.insert_instruction( MY_STATIC_JUMP, @@ -51,7 +52,7 @@ pub fn main() { ); // Create a new EVM instance. - let mut evm = Evm::new(ctx, instructions, EthPrecompiles::default()) + let mut evm = Evm::new(ctx, instructions, EthPrecompiles::new(SpecId::default())) .with_inspector(TracerEip3155::new_stdout().without_summary()); // inspect the transaction. diff --git a/examples/custom_precompile_journal/src/custom_evm.rs b/examples/custom_precompile_journal/src/custom_evm.rs index 3974d6e490..3b00331e6b 100644 --- a/examples/custom_precompile_journal/src/custom_evm.rs +++ b/examples/custom_precompile_journal/src/custom_evm.rs @@ -51,7 +51,7 @@ where Self(Evm { ctx, inspector, - instruction: EthInstructions::new_mainnet(), + instruction: EthInstructions::new_mainnet_with_spec(SpecId::CANCUN), precompiles: CustomPrecompileProvider::new_with_spec(SpecId::CANCUN), frame_stack: FrameStack::new(), }) diff --git a/examples/custom_precompile_journal/src/precompile_provider.rs b/examples/custom_precompile_journal/src/precompile_provider.rs index 1ffef4454b..d2815c91f2 100644 --- a/examples/custom_precompile_journal/src/precompile_provider.rs +++ b/examples/custom_precompile_journal/src/precompile_provider.rs @@ -26,7 +26,7 @@ pub struct CustomPrecompileProvider { impl CustomPrecompileProvider { pub fn new_with_spec(spec: SpecId) -> Self { Self { - inner: EthPrecompiles::default(), + inner: EthPrecompiles::new(spec), spec, } } @@ -44,7 +44,7 @@ where } self.spec = spec; // Create a new inner provider with the new spec - self.inner = EthPrecompiles::default(); + self.inner = EthPrecompiles::new(spec); true } diff --git a/examples/my_evm/src/evm.rs b/examples/my_evm/src/evm.rs index 133afd497d..fbdeacb8be 100644 --- a/examples/my_evm/src/evm.rs +++ b/examples/my_evm/src/evm.rs @@ -6,6 +6,7 @@ use revm::{ }, inspector::{InspectorEvmTr, JournalExt}, interpreter::interpreter::EthInterpreter, + primitives::hardfork::SpecId, Database, Inspector, }; @@ -47,8 +48,8 @@ impl MyEvm { Self(Evm { ctx, inspector, - instruction: EthInstructions::new_mainnet(), - precompiles: EthPrecompiles::default(), + instruction: EthInstructions::new_mainnet_with_spec(SpecId::default()), + precompiles: EthPrecompiles::new(SpecId::default()), frame_stack: FrameStack::new(), }) }