@@ -9,18 +9,15 @@ use foundry_evm::{
99 executor:: inspector:: { LogCollector , Tracer } ,
1010 revm,
1111 revm:: {
12- inspectors:: GasInspector ,
1312 interpreter:: { CallInputs , CreateInputs , Gas , InstructionResult , Interpreter } ,
1413 primitives:: { B160 , B256 } ,
1514 EVMData ,
1615 } ,
1716} ;
18- use std:: { cell:: RefCell , rc:: Rc } ;
1917
2018/// The [`revm::Inspector`] used when transacting in the evm
2119#[ derive( Debug , Clone , Default ) ]
2220pub struct Inspector {
23- pub gas : Option < Rc < RefCell < GasInspector > > > ,
2421 pub tracer : Option < Tracer > ,
2522 /// collects all `console.sol` logs
2623 pub log_collector : LogCollector ,
@@ -42,109 +39,83 @@ impl Inspector {
4239 self
4340 }
4441
45- /// Enables steps recording for `Tracer` and attaches `GasInspector` to it
46- /// If `Tracer` wasn't configured before, configures it automatically
42+ /// Enables steps recording for `Tracer`.
4743 pub fn with_steps_tracing ( mut self ) -> Self {
48- if self . tracer . is_none ( ) {
49- self = self . with_tracing ( )
50- }
51- let gas_inspector = Rc :: new ( RefCell :: new ( GasInspector :: default ( ) ) ) ;
52- self . gas = Some ( gas_inspector. clone ( ) ) ;
53- self . tracer = self . tracer . map ( |tracer| tracer. with_steps_recording ( gas_inspector) ) ;
54-
44+ let tracer = self . tracer . get_or_insert_with ( Default :: default) ;
45+ tracer. record_steps ( ) ;
5546 self
5647 }
5748}
5849
5950impl < DB : Database > revm:: Inspector < DB > for Inspector {
51+ #[ inline]
6052 fn initialize_interp (
6153 & mut self ,
6254 interp : & mut Interpreter ,
6355 data : & mut EVMData < ' _ , DB > ,
6456 is_static : bool ,
6557 ) -> InstructionResult {
66- call_inspectors ! (
67- inspector,
68- [ & mut self . gas. as_deref( ) . map( |gas| gas. borrow_mut( ) ) , & mut self . tracer] ,
69- { inspector. initialize_interp( interp, data, is_static) }
70- ) ;
58+ call_inspectors ! ( [ & mut self . tracer] , |inspector| {
59+ inspector. initialize_interp( interp, data, is_static) ;
60+ } ) ;
7161 InstructionResult :: Continue
7262 }
7363
64+ #[ inline]
7465 fn step (
7566 & mut self ,
7667 interp : & mut Interpreter ,
7768 data : & mut EVMData < ' _ , DB > ,
7869 is_static : bool ,
7970 ) -> InstructionResult {
80- call_inspectors ! (
81- inspector,
82- [ & mut self . gas. as_deref( ) . map( |gas| gas. borrow_mut( ) ) , & mut self . tracer] ,
83- {
84- inspector. step( interp, data, is_static) ;
85- }
86- ) ;
71+ call_inspectors ! ( [ & mut self . tracer] , |inspector| {
72+ inspector. step( interp, data, is_static) ;
73+ } ) ;
8774 InstructionResult :: Continue
8875 }
8976
77+ #[ inline]
9078 fn log (
9179 & mut self ,
9280 evm_data : & mut EVMData < ' _ , DB > ,
9381 address : & B160 ,
9482 topics : & [ B256 ] ,
9583 data : & Bytes ,
9684 ) {
97- call_inspectors ! (
98- inspector,
99- [
100- & mut self . gas. as_deref( ) . map( |gas| gas. borrow_mut( ) ) ,
101- & mut self . tracer,
102- Some ( & mut self . log_collector)
103- ] ,
104- {
105- inspector. log( evm_data, address, topics, data) ;
106- }
107- ) ;
85+ call_inspectors ! ( [ & mut self . tracer, Some ( & mut self . log_collector) ] , |inspector| {
86+ inspector. log( evm_data, address, topics, data) ;
87+ } ) ;
10888 }
10989
90+ #[ inline]
11091 fn step_end (
11192 & mut self ,
11293 interp : & mut Interpreter ,
11394 data : & mut EVMData < ' _ , DB > ,
11495 is_static : bool ,
11596 eval : InstructionResult ,
11697 ) -> InstructionResult {
117- call_inspectors ! (
118- inspector,
119- [ & mut self . gas. as_deref( ) . map( |gas| gas. borrow_mut( ) ) , & mut self . tracer] ,
120- {
121- inspector. step_end( interp, data, is_static, eval) ;
122- }
123- ) ;
98+ call_inspectors ! ( [ & mut self . tracer] , |inspector| {
99+ inspector. step_end( interp, data, is_static, eval) ;
100+ } ) ;
124101 eval
125102 }
126103
104+ #[ inline]
127105 fn call (
128106 & mut self ,
129107 data : & mut EVMData < ' _ , DB > ,
130108 call : & mut CallInputs ,
131109 is_static : bool ,
132110 ) -> ( InstructionResult , Gas , Bytes ) {
133- call_inspectors ! (
134- inspector,
135- [
136- & mut self . gas. as_deref( ) . map( |gas| gas. borrow_mut( ) ) ,
137- & mut self . tracer,
138- Some ( & mut self . log_collector)
139- ] ,
140- {
141- inspector. call( data, call, is_static) ;
142- }
143- ) ;
111+ call_inspectors ! ( [ & mut self . tracer, Some ( & mut self . log_collector) ] , |inspector| {
112+ inspector. call( data, call, is_static) ;
113+ } ) ;
144114
145115 ( InstructionResult :: Continue , Gas :: new ( call. gas_limit ) , Bytes :: new ( ) )
146116 }
147117
118+ #[ inline]
148119 fn call_end (
149120 & mut self ,
150121 data : & mut EVMData < ' _ , DB > ,
@@ -154,32 +125,26 @@ impl<DB: Database> revm::Inspector<DB> for Inspector {
154125 out : Bytes ,
155126 is_static : bool ,
156127 ) -> ( InstructionResult , Gas , Bytes ) {
157- call_inspectors ! (
158- inspector,
159- [ & mut self . gas. as_deref( ) . map( |gas| gas. borrow_mut( ) ) , & mut self . tracer] ,
160- {
161- inspector. call_end( data, inputs, remaining_gas, ret, out. clone( ) , is_static) ;
162- }
163- ) ;
128+ call_inspectors ! ( [ & mut self . tracer] , |inspector| {
129+ inspector. call_end( data, inputs, remaining_gas, ret, out. clone( ) , is_static) ;
130+ } ) ;
164131 ( ret, remaining_gas, out)
165132 }
166133
134+ #[ inline]
167135 fn create (
168136 & mut self ,
169137 data : & mut EVMData < ' _ , DB > ,
170138 call : & mut CreateInputs ,
171139 ) -> ( InstructionResult , Option < B160 > , Gas , Bytes ) {
172- call_inspectors ! (
173- inspector,
174- [ & mut self . gas. as_deref( ) . map( |gas| gas. borrow_mut( ) ) , & mut self . tracer] ,
175- {
176- inspector. create( data, call) ;
177- }
178- ) ;
140+ call_inspectors ! ( [ & mut self . tracer] , |inspector| {
141+ inspector. create( data, call) ;
142+ } ) ;
179143
180144 ( InstructionResult :: Continue , None , Gas :: new ( call. gas_limit ) , Bytes :: new ( ) )
181145 }
182146
147+ #[ inline]
183148 fn create_end (
184149 & mut self ,
185150 data : & mut EVMData < ' _ , DB > ,
@@ -189,18 +154,15 @@ impl<DB: Database> revm::Inspector<DB> for Inspector {
189154 gas : Gas ,
190155 retdata : Bytes ,
191156 ) -> ( InstructionResult , Option < B160 > , Gas , Bytes ) {
192- call_inspectors ! (
193- inspector,
194- [ & mut self . gas. as_deref( ) . map( |gas| gas. borrow_mut( ) ) , & mut self . tracer] ,
195- {
196- inspector. create_end( data, inputs, status, address, gas, retdata. clone( ) ) ;
197- }
198- ) ;
157+ call_inspectors ! ( [ & mut self . tracer] , |inspector| {
158+ inspector. create_end( data, inputs, status, address, gas, retdata. clone( ) ) ;
159+ } ) ;
199160 ( status, address, gas, retdata)
200161 }
201162}
202163
203164/// Prints all the logs
165+ #[ inline]
204166pub fn print_logs ( logs : & [ Log ] ) {
205167 for log in decode_console_logs ( logs) {
206168 node_info ! ( "{}" , log) ;
0 commit comments