Skip to content

Commit b804923

Browse files
fix: execution from non-zero instret (#2155)
`InterpretedInstance::execute_from_state` for pure execution was using `num_insns` instead of `instret_end` in the `ExecutionCtx` constructor. This was not caught because we currently only ever execute from `instret=0`.
1 parent 13362dc commit b804923

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

crates/vm/src/arch/execution.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ pub enum ExecutionError {
6666
FailedWithExitCode(u32),
6767
#[error("trace buffer out of bounds: requested {requested} but capacity is {capacity}")]
6868
TraceBufferOutOfBounds { requested: usize, capacity: usize },
69+
#[error("instruction counter overflow: {instret} + {num_insns} > u64::MAX")]
70+
InstretOverflow { instret: u64, num_insns: u64 },
6971
#[error("inventory error: {0}")]
7072
Inventory(#[from] ExecutorInventoryError),
7173
#[error("static program error: {0}")]

crates/vm/src/arch/interpreter.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,21 @@ where
353353
from_state: VmState<F, GuestMemory>,
354354
num_insns: Option<u64>,
355355
) -> Result<VmState<F, GuestMemory>, ExecutionError> {
356-
let ctx = ExecutionCtx::new(num_insns);
356+
let instret = from_state.instret();
357+
let instret_end = if let Some(n) = num_insns {
358+
let end = instret
359+
.checked_add(n)
360+
.ok_or(ExecutionError::InstretOverflow {
361+
instret,
362+
num_insns: n,
363+
})?;
364+
Some(end)
365+
} else {
366+
None
367+
};
368+
let ctx = ExecutionCtx::new(instret_end);
357369
let mut exec_state = VmExecState::new(from_state, ctx);
358370

359-
let instret = exec_state.instret();
360371
let pc = exec_state.pc();
361372
let instret_end = exec_state.ctx.instret_end;
362373
run!(

0 commit comments

Comments
 (0)