@@ -13,20 +13,30 @@ use revm::{
1313} ;
1414
1515pub enum EventMetadata {
16- Create ( Bytes ) ,
16+ Create ( CreateEventMetadata ) ,
1717 Call ( CallEventMetadata ) ,
1818}
1919
20+ pub struct CreateEventMetadata {
21+ pub init_code : Bytes ,
22+ pub bytecode_address : Address ,
23+ }
24+
2025pub struct CallEventMetadata {
2126 pub metadata : Vec < u8 > ,
22- pub bytecode_address : Option < Address > ,
27+ pub bytecode_address : Address ,
2328}
2429
2530pub enum ErrorMetadata {
26- Create ( Bytes ) ,
31+ Create ( CreateErrorMetadata ) ,
2732 Call ( CallErrorMetadata ) ,
2833}
2934
35+ pub struct CreateErrorMetadata {
36+ pub init_code : Bytes ,
37+ pub bytecode_address : Address ,
38+ }
39+
3040pub struct CallErrorMetadata {
3141 pub metadata : Vec < u8 > ,
3242 pub bytecode_address : Address ,
@@ -38,10 +48,9 @@ pub struct FqnInspector {
3848
3949 /// Stack of bytecode addresses.
4050 ///
41- /// Bytecode address is only used to resolve external events in the case of forking
42- /// Since CREATE / EOFCREATE can only be performed with local (not forked) contracts,
43- /// we can use None in create subcalls
44- bytecode_addresses : Vec < Option < Address > > ,
51+ /// Bytecode address is used to resolve external events in the case of forking
52+ /// and when pytypes overrides are used.
53+ bytecode_addresses : Vec < Address > ,
4554
4655 /// Stack of init code.
4756 ///
@@ -106,10 +115,15 @@ impl FqnInspector {
106115
107116impl < CTX : ContextTr < Journal : JournalExt > > Inspector < CTX > for FqnInspector {
108117 fn log ( & mut self , interp : & mut Interpreter , _context : & mut CTX , log : Log ) {
118+ let bytecode_address = self . bytecode_addresses . last ( ) . unwrap ( ) . clone ( ) ;
119+
109120 if let Some ( init_code) = self . init_code_stack . last ( ) . unwrap ( ) {
110121 self . events_metadata . insert (
111122 log. clone ( ) ,
112- EventMetadata :: Create ( init_code. clone ( ) ) ,
123+ EventMetadata :: Create ( CreateEventMetadata {
124+ init_code : init_code. clone ( ) ,
125+ bytecode_address,
126+ } ) ,
113127 ) ;
114128 } else {
115129 let bytecode = interp. bytecode . original_byte_slice ( ) ;
@@ -119,15 +133,16 @@ impl<CTX: ContextTr<Journal: JournalExt>> Inspector<CTX> for FqnInspector {
119133 log. clone ( ) ,
120134 EventMetadata :: Call ( CallEventMetadata {
121135 metadata : metadata. to_vec ( ) ,
122- bytecode_address : self . bytecode_addresses . last ( ) . unwrap ( ) . clone ( ) ,
136+ bytecode_address,
123137 } ) ,
124138 ) ;
125139 }
126140 }
127141 }
128142
129- fn create ( & mut self , _context : & mut CTX , inputs : & mut CreateInputs ) -> Option < CreateOutcome > {
130- self . bytecode_addresses . push ( None ) ;
143+ fn create ( & mut self , context : & mut CTX , inputs : & mut CreateInputs ) -> Option < CreateOutcome > {
144+ let nonce = context. journal ( ) . load_account ( inputs. caller ) . ok ( ) ?. info . nonce ;
145+ self . bytecode_addresses . push ( inputs. created_address ( nonce) ) ;
131146 self . init_code_stack . push ( Some ( inputs. init_code . clone ( ) ) ) ;
132147 None
133148 }
@@ -138,15 +153,18 @@ impl<CTX: ContextTr<Journal: JournalExt>> Inspector<CTX> for FqnInspector {
138153 inputs : & CreateInputs ,
139154 outcome : & mut CreateOutcome ,
140155 ) {
141- self . bytecode_addresses . pop ( ) ;
156+ let bytecode_address = self . bytecode_addresses . pop ( ) . unwrap ( ) ;
142157 self . init_code_stack . pop ( ) ;
143158
144159 if outcome. result . result == InstructionResult :: Revert && outcome. result . output . len ( ) >= 4 {
145160 let selector: [ u8 ; 4 ] = ( & outcome. result . output [ ..4 ] ) . try_into ( ) . unwrap ( ) ;
146161
147162 self . errors_metadata
148163 . entry ( selector)
149- . or_insert ( ErrorMetadata :: Create ( inputs. init_code . clone ( ) ) ) ;
164+ . or_insert ( ErrorMetadata :: Create ( CreateErrorMetadata {
165+ init_code : inputs. init_code . clone ( ) ,
166+ bytecode_address,
167+ } ) ) ;
150168 }
151169 }
152170
@@ -155,7 +173,6 @@ impl<CTX: ContextTr<Journal: JournalExt>> Inspector<CTX> for FqnInspector {
155173 _context : & mut CTX ,
156174 _inputs : & mut EOFCreateInputs ,
157175 ) -> Option < CreateOutcome > {
158- self . bytecode_addresses . push ( None ) ;
159176 todo ! ( ) ;
160177 }
161178
@@ -165,12 +182,11 @@ impl<CTX: ContextTr<Journal: JournalExt>> Inspector<CTX> for FqnInspector {
165182 _inputs : & EOFCreateInputs ,
166183 _outcome : & mut CreateOutcome ,
167184 ) {
168- self . bytecode_addresses . pop ( ) ;
169- self . init_code_stack . pop ( ) ;
185+ todo ! ( ) ;
170186 }
171187
172188 fn call ( & mut self , _context : & mut CTX , inputs : & mut CallInputs ) -> Option < CallOutcome > {
173- self . bytecode_addresses . push ( Some ( inputs. bytecode_address ) ) ;
189+ self . bytecode_addresses . push ( inputs. bytecode_address ) ;
174190 self . init_code_stack . push ( None ) ;
175191
176192 None
0 commit comments