Skip to main content

foundry_evm/inspectors/
chisel_state.rs

1use alloy_primitives::U256;
2use revm::{
3    Inspector,
4    interpreter::{Interpreter, interpreter_types::Jumps},
5};
6
7/// An inspector for Chisel
8#[derive(Clone, Debug, Default)]
9pub struct ChiselState {
10    /// The PC of the final instruction
11    pub final_pc: usize,
12    /// The final state of the REPL contract call
13    pub state: Option<(Vec<U256>, Vec<u8>)>,
14}
15
16impl ChiselState {
17    /// Create a new Chisel state inspector.
18    #[inline]
19    pub const fn new(final_pc: usize) -> Self {
20        Self { final_pc, state: None }
21    }
22}
23
24impl<CTX> Inspector<CTX> for ChiselState {
25    #[cold]
26    fn step_end(&mut self, interpreter: &mut Interpreter, _context: &mut CTX) {
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`.
29        if self.final_pc == interpreter.bytecode.pc() - 1 {
30            self.state = Some((
31                interpreter.stack.data().clone(),
32                interpreter.memory.context_memory().to_vec(),
33            ))
34        }
35    }
36}