@@ -36,8 +36,11 @@ use foundry_evm_core::{
3636 abi:: Vm :: stopExpectSafeMemoryCall,
3737 backend:: { DatabaseError , DatabaseExt , RevertDiagnostic } ,
3838 constants:: { CHEATCODE_ADDRESS , HARDHAT_CONSOLE_ADDRESS , MAGIC_ASSUME } ,
39- evm:: { new_evm_with_context, FoundryEvmContext } ,
40- InspectorExt ,
39+ evm:: {
40+ new_evm_with_context, new_evm_with_inspector, FoundryEvm , FoundryEvmContext ,
41+ FoundryPrecompiles ,
42+ } ,
43+ AsEnvMut , ContextExt , Env , InspectorExt ,
4144} ;
4245use foundry_evm_traces:: { TracingInspector , TracingInspectorConfig } ;
4346use foundry_wallets:: multi_wallet:: MultiWallet ;
@@ -47,18 +50,19 @@ use rand::Rng;
4750use revm:: {
4851 self ,
4952 bytecode:: { opcode as op, EOF_MAGIC_BYTES } ,
50- context:: { BlockEnv , JournalTr } ,
53+ context:: { BlockEnv , CfgEnv , Evm , JournalInner , JournalTr , TxEnv } ,
5154 context_interface:: { result:: EVMError , transaction:: SignedAuthorization , CreateScheme } ,
52- handler:: { FrameOrResult , FrameResult } ,
55+ handler:: { instructions :: EthInstructions , FrameOrResult , FrameResult } ,
5356 interpreter:: {
57+ interpreter:: EthInterpreter ,
5458 interpreter_types:: { Jumps , LoopControl , MemoryTr } ,
5559 CallInputs , CallOutcome , CallScheme , CreateInputs , CreateOutcome , EOFCreateInputs ,
5660 EOFCreateKind , Gas , Host , InstructionResult , Interpreter , InterpreterAction ,
5761 InterpreterResult ,
5862 } ,
5963 primitives:: hardfork:: SpecId ,
6064 state:: EvmStorageSlot ,
61- Inspector ,
65+ Context , Inspector ,
6266} ;
6367use serde_json:: Value ;
6468use std:: {
@@ -93,39 +97,39 @@ pub trait CheatcodesExecutor {
9397 ccx : & mut CheatsCtxt ,
9498 ) -> Result < CreateOutcome , EVMError < DatabaseError > > {
9599 with_evm ( self , ccx, |evm| {
96- evm. context . evm . inner . journaled_state . depth += 1 ;
100+ evm. journaled_state . depth += 1 ;
97101
98102 // Handle EOF bytecode
99- let first_frame_or_result = if evm. handler . cfg . spec_id . is_enabled_in ( SpecId :: OSAKA ) &&
103+ let first_frame_or_result = if evm. cfg . spec . is_enabled_in ( SpecId :: OSAKA ) &&
100104 inputs. scheme == CreateScheme :: Create &&
101105 inputs. init_code . starts_with ( & EOF_MAGIC_BYTES )
102106 {
103107 evm. handler . execution ( ) . eofcreate (
104108 & mut evm. context ,
105- Box :: new ( EOFCreateInputs :: new (
109+ & mut EOFCreateInputs :: new (
106110 inputs. caller ,
107111 inputs. value ,
108112 inputs. gas_limit ,
109113 EOFCreateKind :: Tx { initdata : inputs. init_code } ,
110- ) ) ,
114+ ) ,
111115 ) ?
112116 } else {
113- evm. handler . execution ( ) . create ( & mut evm. context , Box :: new ( inputs) ) ?
117+ evm. handler . execution ( ) . create ( & mut evm. context , inputs) ?
114118 } ;
115119
116120 let mut result = match first_frame_or_result {
117- revm :: FrameOrResult :: Frame ( first_frame) => evm. run_the_loop ( first_frame) ?,
118- revm :: FrameOrResult :: Result ( result) => result,
121+ FrameOrResult :: Item ( first_frame) => evm. run_the_loop ( first_frame) ?,
122+ FrameOrResult :: Result ( result) => result,
119123 } ;
120124
121125 evm. handler . execution ( ) . last_frame_return ( & mut evm. context , & mut result) ?;
122126
123127 let outcome = match result {
124- revm :: FrameResult :: Call ( _) => unreachable ! ( ) ,
125- revm :: FrameResult :: Create ( create) | revm :: FrameResult :: EOFCreate ( create) => create,
128+ FrameResult :: Call ( _) => unreachable ! ( ) ,
129+ FrameResult :: Create ( create) | FrameResult :: EOFCreate ( create) => create,
126130 } ;
127131
128- evm. context . evm . inner . journaled_state . depth -= 1 ;
132+ evm. journaled_state . depth -= 1 ;
129133
130134 Ok ( outcome)
131135 } )
@@ -150,32 +154,53 @@ fn with_evm<E, F, O>(
150154where
151155 E : CheatcodesExecutor + ?Sized ,
152156 F : for <' a , ' b > FnOnce (
153- & mut revm:: Evm < ' _ , & ' b mut dyn InspectorExt , & ' a mut dyn DatabaseExt > ,
157+ & ' a mut Evm <
158+ Context < BlockEnv , TxEnv , CfgEnv , & ' b mut dyn DatabaseExt > ,
159+ & ' a mut dyn InspectorExt ,
160+ EthInstructions <
161+ EthInterpreter ,
162+ Context < BlockEnv , TxEnv , CfgEnv , & ' b mut dyn DatabaseExt > ,
163+ > ,
164+ FoundryPrecompiles ,
165+ > ,
154166 ) -> Result < O , EVMError < DatabaseError > > ,
155167{
156168 let mut inspector = executor. get_inspector ( ccx. state ) ;
157- let error = std:: mem:: replace ( & mut ccx. ecx . error , Ok ( ( ) ) ) ;
158- let l1_block_info = std:: mem:: take ( & mut ccx. ecx . l1_block_info ) ;
159-
160- let inner = revm:: InnerEvmContext {
161- env : ccx. ecx . env . clone ( ) ,
162- journaled_state : std:: mem:: replace (
163- & mut ccx. ecx . journaled_state ,
164- revm:: JournaledState :: new ( Default :: default ( ) , Default :: default ( ) ) ,
165- ) ,
166- db : & mut ccx. ecx . db as & mut dyn DatabaseExt ,
167- error,
168- l1_block_info,
169- } ;
170-
171- let mut evm = new_evm_with_existing_context ( inner, & mut * inspector) ;
169+ std:: mem:: replace ( & mut ccx. ecx . error , Ok ( ( ) ) ) ;
170+ // let l1_block_info = std::mem::take(&mut ccx.ecx.l1_block_info);
171+
172+ // let inner = revm::InnerEvmContext {
173+ // env: ccx.ecx.env.clone(),
174+ // journaled_state: std::mem::replace(
175+ // &mut ccx.ecx.journaled_state,
176+ // revm::JournaledState::new(Default::default(), Default::default()),
177+ // ),
178+ // db: &mut ccx.ecx.db as &mut dyn DatabaseExt,
179+ // error,
180+ // l1_block_info,
181+ // };
182+
183+ let ( db, journal, env) = ccx. ecx . as_db_env_and_journal ( ) ;
184+ std:: mem:: replace ( journal, JournalInner :: new ( ) ) ;
185+
186+ let mut evm: Evm <
187+ Context < BlockEnv , TxEnv , CfgEnv , & mut dyn DatabaseExt > ,
188+ & mut dyn InspectorExt ,
189+ EthInstructions < EthInterpreter , Context < BlockEnv , TxEnv , CfgEnv , & mut dyn DatabaseExt > > ,
190+ FoundryPrecompiles ,
191+ > = new_evm_with_inspector (
192+ db,
193+ & Env :: from ( env. cfg . clone ( ) , env. block . clone ( ) , env. tx . clone ( ) ) . as_env_mut ( ) ,
194+ & mut * inspector,
195+ ) ;
172196
173197 let res = f ( & mut evm) ?;
174198
175- ccx. ecx . journaled_state = evm. context . evm . inner . journaled_state ;
176- ccx. ecx . env = evm. context . evm . inner . env ;
177- ccx. ecx . l1_block_info = evm. context . evm . inner . l1_block_info ;
178- ccx. ecx . error = evm. context . evm . inner . error ;
199+ ccx. ecx . journaled_state . inner = evm. journaled_state . inner ;
200+ ccx. ecx . block = evm. block ;
201+ ccx. ecx . cfg = evm. cfg ;
202+ ccx. ecx . tx = evm. tx ;
203+ ccx. ecx . error = evm. error ;
179204
180205 Ok ( res)
181206}
0 commit comments