revm_interpreter/
instruction_context.rs

1use crate::{interpreter_types::Jumps, Interpreter, InterpreterTypes};
2
3use super::Instruction;
4
5pub struct InstructionContext<'a, H: ?Sized, ITy: InterpreterTypes> {
6    pub host: &'a mut H,
7    pub interpreter: &'a mut Interpreter<ITy>,
8}
9
10impl<H: ?Sized, ITy: InterpreterTypes> InstructionContext<'_, H, ITy> {
11    /// Executes the instruction at the current instruction pointer.
12    ///
13    /// Internally it will increment instruction pointer by one.
14    #[inline]
15    pub(crate) fn step(self, instruction_table: &[Instruction<ITy, H>; 256]) {
16        // Get current opcode.
17        let opcode = self.interpreter.bytecode.opcode();
18
19        // SAFETY: In analysis we are doing padding of bytecode so that we are sure that last
20        // byte instruction is STOP so we are safe to just increment program_counter bcs on last instruction
21        // it will do noop and just stop execution of this contract
22        self.interpreter.bytecode.relative_jump(1);
23
24        // Execute instruction.
25        instruction_table[opcode as usize](self)
26    }
27}