1- use super :: * ;
2-
3- type EthEvmHandler < ' db , I > =
4- MainnetHandler < EthRevmEvm < ' db , I > , EVMError < DatabaseError > , EthFrame < EthInterpreter > > ;
1+ use alloy_evm:: {
2+ EthEvm , EthEvmFactory , Evm , EvmEnv , EvmFactory , eth:: EthEvmContext , precompiles:: PrecompilesMap ,
3+ } ;
4+ use foundry_fork_db:: DatabaseError ;
5+ use revm:: {
6+ context:: {
7+ BlockEnv , ContextTr , Evm as RevmEvm , LocalContextTr , TxEnv ,
8+ result:: { EVMError , ResultAndState } ,
9+ } ,
10+ handler:: {
11+ EthFrame , EvmTr , FrameResult , Handler , MainnetHandler , instructions:: EthInstructions ,
12+ } ,
13+ inspector:: InspectorHandler ,
14+ interpreter:: {
15+ FrameInput , SharedMemory , interpreter:: EthInterpreter , interpreter_action:: FrameInit ,
16+ } ,
17+ primitives:: hardfork:: SpecId ,
18+ } ;
19+
20+ use crate :: {
21+ FoundryContextExt , FoundryInspectorExt ,
22+ backend:: { DatabaseExt , JournaledState } ,
23+ evm:: { FoundryEvmFactory , NestedEvm } ,
24+ } ;
25+
26+ type EthEvmHandler < ' db , I > = MainnetHandler < EthRevmEvm < ' db , I > , EVMError < DatabaseError > , EthFrame > ;
527
628pub type EthRevmEvm < ' db , I > = RevmEvm <
729 EthEvmContext < & ' db mut dyn DatabaseExt < EthEvmFactory > > ,
830 I ,
931 EthInstructions < EthInterpreter , EthEvmContext < & ' db mut dyn DatabaseExt < EthEvmFactory > > > ,
1032 PrecompilesMap ,
11- EthFrame < EthInterpreter > ,
33+ EthFrame ,
1234> ;
1335
14- pub struct EthFoundryEvm <
15- ' db ,
16- I : FoundryInspectorExt < EthEvmContext < & ' db mut dyn DatabaseExt < EthEvmFactory > > > ,
17- > {
18- pub inner : EthRevmEvm < ' db , I > ,
19- }
20-
21- impl < ' db , I : FoundryInspectorExt < EthEvmContext < & ' db mut dyn DatabaseExt < EthEvmFactory > > > > Evm
22- for EthFoundryEvm < ' db , I >
23- {
24- type Precompiles = PrecompilesMap ;
25- type Inspector = I ;
26- type DB = & ' db mut dyn DatabaseExt < EthEvmFactory > ;
27- type Error = EVMError < DatabaseError > ;
28- type HaltReason = HaltReason ;
29- type Spec = SpecId ;
30- type Tx = TxEnv ;
31- type BlockEnv = BlockEnv ;
32-
33- fn block ( & self ) -> & BlockEnv {
34- & self . inner . block
35- }
36-
37- fn chain_id ( & self ) -> u64 {
38- self . inner . ctx . cfg . chain_id
39- }
40-
41- fn components ( & self ) -> ( & Self :: DB , & Self :: Inspector , & Self :: Precompiles ) {
42- ( & self . inner . ctx . journaled_state . database , & self . inner . inspector , & self . inner . precompiles )
43- }
44-
45- fn components_mut ( & mut self ) -> ( & mut Self :: DB , & mut Self :: Inspector , & mut Self :: Precompiles ) {
46- (
47- & mut self . inner . ctx . journaled_state . database ,
48- & mut self . inner . inspector ,
49- & mut self . inner . precompiles ,
50- )
51- }
52-
53- fn set_inspector_enabled ( & mut self , _enabled : bool ) {
54- unimplemented ! ( "FoundryEvm is always inspecting" )
55- }
56-
57- fn transact_raw (
58- & mut self ,
59- tx : Self :: Tx ,
60- ) -> Result < ResultAndState < Self :: HaltReason > , Self :: Error > {
61- self . inner . set_tx ( tx) ;
62-
63- let result = EthEvmHandler :: < I > :: default ( ) . inspect_run ( & mut self . inner ) ?;
64-
65- Ok ( ResultAndState :: new ( result, self . inner . ctx . journaled_state . inner . state . clone ( ) ) )
66- }
67-
68- fn transact_system_call (
69- & mut self ,
70- _caller : Address ,
71- _contract : Address ,
72- _data : Bytes ,
73- ) -> Result < ExecResultAndState < ExecutionResult > , Self :: Error > {
74- unimplemented ! ( )
75- }
76-
77- fn finish ( self ) -> ( Self :: DB , EvmEnv < Self :: Spec > )
78- where
79- Self : Sized ,
80- {
81- let Context { block : block_env, cfg : cfg_env, journaled_state, .. } = self . inner . ctx ;
82-
83- ( journaled_state. database , EvmEnv { block_env, cfg_env } )
84- }
85- }
86-
87- impl < ' db , I : FoundryInspectorExt < EthEvmContext < & ' db mut dyn DatabaseExt < EthEvmFactory > > > > Deref
88- for EthFoundryEvm < ' db , I >
89- {
90- type Target = EthEvmContext < & ' db mut dyn DatabaseExt < EthEvmFactory > > ;
91-
92- fn deref ( & self ) -> & Self :: Target {
93- & self . inner . ctx
94- }
95- }
96-
97- impl < ' db , I : FoundryInspectorExt < EthEvmContext < & ' db mut dyn DatabaseExt < EthEvmFactory > > > > DerefMut
98- for EthFoundryEvm < ' db , I >
99- {
100- fn deref_mut ( & mut self ) -> & mut Self :: Target {
101- & mut self . inner . ctx
102- }
103- }
104-
10536impl FoundryEvmFactory for EthEvmFactory {
10637 type FoundryContext < ' db > = EthEvmContext < & ' db mut dyn DatabaseExt < Self > > ;
10738
108- type FoundryEvm < ' db , I : FoundryInspectorExt < Self :: FoundryContext < ' db > > > = EthFoundryEvm < ' db , I > ;
39+ type FoundryEvm < ' db , I : FoundryInspectorExt < Self :: FoundryContext < ' db > > > =
40+ EthEvm < & ' db mut dyn DatabaseExt < Self > , I , Self :: Precompiles > ;
10941
11042 fn create_foundry_evm_with_inspector < ' db , I : FoundryInspectorExt < Self :: FoundryContext < ' db > > > (
11143 & self ,
11244 db : & ' db mut dyn DatabaseExt < Self > ,
11345 evm_env : EvmEnv ,
11446 inspector : I ,
11547 ) -> Self :: FoundryEvm < ' db , I > {
116- let eth_evm = Self :: default ( ) . create_evm_with_inspector ( db, evm_env, inspector) ;
117- let mut inner = eth_evm. into_inner ( ) ;
118- inner. ctx . cfg . tx_chain_id_check = true ;
119-
120- let mut evm = EthFoundryEvm { inner } ;
121- evm. inspector ( ) . get_networks ( ) . inject_precompiles ( evm. precompiles_mut ( ) ) ;
122- evm
48+ let mut eth_evm = Self :: default ( ) . create_evm_with_inspector ( db, evm_env, inspector) ;
49+ eth_evm. cfg . tx_chain_id_check = true ;
50+ eth_evm. inspector ( ) . get_networks ( ) . inject_precompiles ( eth_evm. precompiles_mut ( ) ) ;
51+ eth_evm
12352 }
12453
12554 fn create_foundry_nested_evm < ' db > (
@@ -128,7 +57,7 @@ impl FoundryEvmFactory for EthEvmFactory {
12857 evm_env : EvmEnv ,
12958 inspector : & ' db mut dyn FoundryInspectorExt < Self :: FoundryContext < ' db > > ,
13059 ) -> Box < dyn NestedEvm < Spec = SpecId , Block = BlockEnv , Tx = TxEnv > + ' db > {
131- Box :: new ( self . create_foundry_evm_with_inspector ( db, evm_env, inspector) . inner )
60+ Box :: new ( self . create_foundry_evm_with_inspector ( db, evm_env, inspector) . into_inner ( ) )
13261 }
13362}
13463
@@ -148,7 +77,7 @@ impl<'db, I: FoundryInspectorExt<EthEvmContext<&'db mut dyn DatabaseExt<EthEvmFa
14877
14978 // Create first frame
15079 let memory =
151- SharedMemory :: new_with_buffer ( self . ctx ( ) . local ( ) . shared_memory_buffer ( ) . clone ( ) ) ;
80+ SharedMemory :: new_with_buffer ( self . ctx_ref ( ) . local ( ) . shared_memory_buffer ( ) . clone ( ) ) ;
15281 let first_frame_input = FrameInit { depth : 0 , memory, frame_input : frame } ;
15382
15483 // Run execution loop
@@ -160,10 +89,7 @@ impl<'db, I: FoundryInspectorExt<EthEvmContext<&'db mut dyn DatabaseExt<EthEvmFa
16089 Ok ( frame_result)
16190 }
16291
163- fn transact_raw (
164- & mut self ,
165- tx : Self :: Tx ,
166- ) -> Result < ResultAndState < HaltReason > , EVMError < DatabaseError > > {
92+ fn transact_raw ( & mut self , tx : Self :: Tx ) -> Result < ResultAndState , EVMError < DatabaseError > > {
16793 self . set_tx ( tx) ;
16894
16995 let result = EthEvmHandler :: < I > :: default ( ) . inspect_run ( self ) ?;
0 commit comments