1use alloy_primitives::U256;
2use revm::{
3 interpreter::{InstructionResult, Interpreter},
4 Database, EvmContext, Inspector,
5};
67/// An inspector for Chisel
8#[derive(Clone, Debug, Default)]
9pub struct ChiselState {
10/// The PC of the final instruction
11pub final_pc: usize,
12/// The final state of the REPL contract call
13pub state: Option<(Vec<U256>, Vec<u8>, InstructionResult)>,
14}
1516impl ChiselState {
17/// Create a new Chisel state inspector.
18#[inline]
19pub fn new(final_pc: usize) -> Self {
20Self { final_pc, state: None }
21 }
22}
2324impl<DB: Database> Inspector<DB> for ChiselState {
25#[cold]
26fn step_end(&mut self, interp: &mut Interpreter, _context: &mut EvmContext<DB>) {
27// If we are at the final pc of the REPL contract execution, set the state.
28 // Subtraction can't overflow because `pc` is always at least 1 in `step_end`.
29if self.final_pc == interp.program_counter() - 1 {
30self.state = Some((
31interp.stack.data().clone(),
32interp.shared_memory.context_memory().to_vec(),
33interp.instruction_result,
34 ))
35 }
36 }
37}