1#[cfg(feature = "std")]
2mod customprinter;
3#[cfg(all(feature = "std", feature = "serde-json"))]
4mod eip3155;
5mod gas;
6mod handler_register;
7mod noop;
89pub use handler_register::{inspector_handle_register, GetInspector};
1011use crate::{
12 interpreter::{
13 CallInputs, CallOutcome, CreateInputs, CreateOutcome, EOFCreateInputs, Interpreter,
14 },
15 primitives::{db::Database, Address, Log, U256},
16 EvmContext,
17};
18use auto_impl::auto_impl;
1920/// [Inspector] implementations.
21pub mod inspectors {
22#[cfg(feature = "std")]
23pub use super::customprinter::CustomPrintTracer;
24#[cfg(all(feature = "std", feature = "serde-json"))]
25pub use super::eip3155::TracerEip3155;
26pub use super::gas::GasInspector;
27pub use super::noop::NoOpInspector;
28}
2930/// EVM [Interpreter] callbacks.
31#[auto_impl(&mut, Box)]
32pub trait Inspector<DB: Database> {
33/// Called before the interpreter is initialized.
34 ///
35 /// If `interp.instruction_result` is set to anything other than [crate::interpreter::InstructionResult::Continue] then the execution of the interpreter
36 /// is skipped.
37#[inline]
38fn initialize_interp(&mut self, interp: &mut Interpreter, context: &mut EvmContext<DB>) {
39let _ = interp;
40let _ = context;
41 }
4243/// Called on each step of the interpreter.
44 ///
45 /// Information about the current execution, including the memory, stack and more is available
46 /// on `interp` (see [Interpreter]).
47 ///
48 /// # Example
49 ///
50 /// To get the current opcode, use `interp.current_opcode()`.
51#[inline]
52fn step(&mut self, interp: &mut Interpreter, context: &mut EvmContext<DB>) {
53let _ = interp;
54let _ = context;
55 }
5657/// Called after `step` when the instruction has been executed.
58 ///
59 /// Setting `interp.instruction_result` to anything other than [crate::interpreter::InstructionResult::Continue] alters the execution
60 /// of the interpreter.
61#[inline]
62fn step_end(&mut self, interp: &mut Interpreter, context: &mut EvmContext<DB>) {
63let _ = interp;
64let _ = context;
65 }
6667/// Called when a log is emitted.
68#[inline]
69fn log(&mut self, interp: &mut Interpreter, context: &mut EvmContext<DB>, log: &Log) {
70let _ = interp;
71let _ = context;
72let _ = log;
73 }
7475/// Called whenever a call to a contract is about to start.
76 ///
77 /// InstructionResulting anything other than [crate::interpreter::InstructionResult::Continue] overrides the result of the call.
78#[inline]
79fn call(
80&mut self,
81 context: &mut EvmContext<DB>,
82 inputs: &mut CallInputs,
83 ) -> Option<CallOutcome> {
84let _ = context;
85let _ = inputs;
86None
87}
8889/// Called when a call to a contract has concluded.
90 ///
91 /// The returned [CallOutcome] is used as the result of the call.
92 ///
93 /// This allows the inspector to modify the given `result` before returning it.
94#[inline]
95fn call_end(
96&mut self,
97 context: &mut EvmContext<DB>,
98 inputs: &CallInputs,
99 outcome: CallOutcome,
100 ) -> CallOutcome {
101let _ = context;
102let _ = inputs;
103 outcome
104 }
105106/// Called when a contract is about to be created.
107 ///
108 /// If this returns `Some` then the [CreateOutcome] is used to override the result of the creation.
109 ///
110 /// If this returns `None` then the creation proceeds as normal.
111#[inline]
112fn create(
113&mut self,
114 context: &mut EvmContext<DB>,
115 inputs: &mut CreateInputs,
116 ) -> Option<CreateOutcome> {
117let _ = context;
118let _ = inputs;
119None
120}
121122/// Called when a contract has been created.
123 ///
124 /// InstructionResulting anything other than the values passed to this function (`(ret, remaining_gas,
125 /// address, out)`) will alter the result of the create.
126#[inline]
127fn create_end(
128&mut self,
129 context: &mut EvmContext<DB>,
130 inputs: &CreateInputs,
131 outcome: CreateOutcome,
132 ) -> CreateOutcome {
133let _ = context;
134let _ = inputs;
135 outcome
136 }
137138/// Called when EOF creating is called.
139 ///
140 /// This can happen from create TX or from EOFCREATE opcode.
141fn eofcreate(
142&mut self,
143 context: &mut EvmContext<DB>,
144 inputs: &mut EOFCreateInputs,
145 ) -> Option<CreateOutcome> {
146let _ = context;
147let _ = inputs;
148None
149}
150151/// Called when eof creating has ended.
152fn eofcreate_end(
153&mut self,
154 context: &mut EvmContext<DB>,
155 inputs: &EOFCreateInputs,
156 outcome: CreateOutcome,
157 ) -> CreateOutcome {
158let _ = context;
159let _ = inputs;
160 outcome
161 }
162163/// Called when a contract has been self-destructed with funds transferred to target.
164#[inline]
165fn selfdestruct(&mut self, contract: Address, target: Address, value: U256) {
166let _ = contract;
167let _ = target;
168let _ = value;
169 }
170}