1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
use crateEvmError;
use crate;
use ExecutionResult;
use ;
/// Defines how an inspector converts its state to a specific output type
///
/// This trait allows inspectors to provide their collected data in a
/// standardized format, making it easier to process and analyze results.
///
/// # Type Parameters
/// * `Output` - The type that this inspector produces as its final result
///
/// # Example
/// ```
/// use revm_trace::traits::TraceOutput;
///
/// struct MyInspector {
/// gas_used: u64,
/// }
///
/// impl TraceOutput for MyInspector {
/// type Output = u64;
///
/// fn get_output(&self) -> Self::Output {
/// self.gas_used
/// }
/// }
/// ```
/// Defines how an inspector can reset its internal state
///
/// This trait is crucial for inspectors that maintain state between transactions
/// and need to clear that state before processing a new transaction.
///
/// # Example
/// ```
/// use revm_trace::traits::Reset;
///
/// struct MyInspector {
/// call_count: u32,
/// gas_used: u64,
/// }
///
/// impl Reset for MyInspector {
/// fn reset(&mut self) {
/// self.call_count = 0;
/// self.gas_used = 0;
/// }
/// }
/// ```
/// Combined trait for EVM inspectors with tracing capabilities
///
/// `TraceInspector` is a marker trait that combines three essential traits
/// for comprehensive EVM transaction tracing:
///
/// - **`Inspector<CTX>`**: Core REVM inspector interface for receiving EVM execution callbacks
/// - **`Reset`**: Ability to reset internal state between transactions
/// - **`TraceOutput`**: Ability to extract structured output after execution
///
/// Any type implementing all three traits automatically implements `TraceInspector`.
///
/// # Usage
///
/// This trait is primarily used as a constraint in generic functions and structs
/// that need full tracing capabilities:
///
/// ```rust
/// use revm_trace::traits::TraceInspector;
/// use revm::database::Database;
///
/// fn process_with_trace<DB, I>(inspector: &mut I)
/// where
/// DB: Database,
/// I: TraceInspector<DB>
/// {
/// // Can use inspector for EVM execution
/// // Can reset state between transactions
/// // Can extract output after execution
/// }
/// ```
///
/// # Examples
///
/// Implementing `TraceInspector` for a custom inspector:
///
/// ```rust
/// use revm_trace::traits::{Reset, TraceOutput, TraceInspector};
/// use revm::{Inspector, database::Database};
///
/// struct MyInspector {
/// call_count: u32,
/// }
///
/// impl<DB: Database> Inspector<DB> for MyInspector {
/// // Inspector implementation...
/// }
///
/// impl Reset for MyInspector {
/// fn reset(&mut self) {
/// self.call_count = 0;
/// }
/// }
///
/// impl TraceOutput for MyInspector {
/// type Output = u32;
///
/// fn get_output(&self) -> Self::Output {
/// self.call_count
/// }
/// }
///
/// // MyInspector now automatically implements TraceInspector
/// ```
/// Automatic implementation of `TraceInspector` for qualifying types
///
/// This blanket implementation automatically provides `TraceInspector` for any type
/// that implements all the required traits. This design follows Rust's principle
/// of "coherence" and eliminates the need for manual implementation boilerplate.
///
/// # Required Traits
///
/// Any type implementing all of the following traits will automatically
/// implement `TraceInspector`:
///
/// - **`Inspector<CTX>`**: Core REVM inspector interface for EVM execution callbacks
/// - **`Reset`**: Ability to reset internal state between transactions
/// - **`TraceOutput`**: Ability to extract structured output after execution
///
/// Note: The `Clone` requirement was removed in v3.1 for better performance.
///
/// # Design Rationale
///
/// This approach provides several benefits:
///
/// 1. **Zero Boilerplate**: No need to explicitly implement `TraceInspector`
/// 2. **Automatic Coherence**: Any type meeting the requirements gets the trait automatically
/// 3. **Compile-Time Safety**: The type system ensures all required capabilities are present
/// 4. **Future Compatibility**: New requirements can be added to the supertrait bounds
///
/// # Example
///
/// ```rust
/// use revm_trace::traits::{Reset, TraceOutput, TraceInspector};
/// use revm::Inspector;
///
/// #[derive(Default)]
/// struct MyInspector {
/// calls: Vec<String>,
/// }
///
/// impl<CTX> Inspector<CTX> for MyInspector {
/// // Inspector implementation...
/// }
///
/// impl Reset for MyInspector {
/// fn reset(&mut self) {
/// self.calls.clear();
/// }
/// }
///
/// impl TraceOutput for MyInspector {
/// type Output = Vec<String>;
///
/// fn get_output(&self) -> Self::Output {
/// self.calls.clone()
/// }
/// }
///
/// // MyInspector now automatically implements TraceInspector<CTX>
/// // No explicit implementation needed!
/// ```
///
/// # Trait Bounds
///
/// Previously required `Clone` bound for batch transaction processing,
/// but this has been optimized away in v3.1 for better performance.
pub type TraceResult<T> = ;
/// Defines standard transaction processing capabilities
///
/// This trait establishes a standardized flow for transaction processing:
/// 1. Transaction preparation and validation
/// 2. Execution in EVM
/// 3. Result collection and state management
///
/// Implementors must follow this standard flow to ensure consistent behavior
/// across different execution contexts.
/// Defines the ability to reset database state
///
/// This trait is implemented by EVM instances that support resetting
/// their underlying database to a clean state, typically used for:
///
/// - Batch processing where each transaction should start from the same state
/// - Testing scenarios requiring clean state isolation
/// - Simulation environments needing state rollback capabilities
// ========================= NoOpInspector Implementations =========================
/// Implementation of Reset trait for NoOpInspector
///
/// Since NoOpInspector doesn't maintain any internal state that needs to be reset,
/// this is a no-operation implementation. This allows NoOpInspector to satisfy
/// the Reset trait requirement for TraceInspector.
/// Implementation of TraceOutput trait for NoOpInspector
///
/// NoOpInspector produces no meaningful output, so this implementation returns
/// the unit type `()`. This allows NoOpInspector to satisfy the TraceOutput
/// trait requirement for TraceInspector.
// Note: NoOpInspector automatically implements TraceInspector<CTX> through the blanket implementation:
// impl<CTX, T> TraceInspector<CTX> for T
// where T: Inspector<CTX> + Reset + TraceOutput
//
// Since NoOpInspector already implements Inspector<CTX> (from revm),
// and we've implemented Reset and TraceOutput above, it automatically gets TraceInspector.