This commit is contained in:
2026-03-24 13:40:41 +00:00
parent d123919b73
commit b48386b154
3 changed files with 83 additions and 29 deletions
@@ -32,6 +32,10 @@ pub enum VerifierError {
UnknownClosureCallee { pc: usize },
/// User-provided arg_count for CALL_CLOSURE does not match callee signature
BadClosureArgCount { pc: usize, expected: u16, got: u16 },
/// YIELD executed in an invalid context (minimal safety rule violation)
InvalidYieldContext { pc: usize, height: u16 },
/// SPAWN arg_count does not match callee param_slots
BadSpawnArgCount { pc: usize, expected: u16, got: u16 },
}
pub struct Verifier;
@@ -168,6 +172,23 @@ impl Verifier {
// Temporarily set pushes=0; we'll compute real pushes after type checks.
(arg_count + 1, 0)
}
OpCode::Spawn => {
// imm: fn_id (u32), arg_count (u32)
let (fn_id, arg_count_u32) = instr.imm_u32x2().unwrap();
let callee = all_functions.get(fn_id as usize).ok_or_else(|| {
VerifierError::InvalidFuncId { pc: func_start + pc, id: fn_id }
})?;
let arg_count = arg_count_u32 as u16;
// Enforce exact arity match for safety and determinism
if callee.param_slots != arg_count {
return Err(VerifierError::BadSpawnArgCount {
pc: func_start + pc,
expected: callee.param_slots,
got: arg_count,
});
}
(arg_count, 0)
}
OpCode::Ret => (func.return_slots, 0),
OpCode::Syscall => {
let id = instr.imm_u32().unwrap();
@@ -186,6 +207,13 @@ impl Verifier {
});
}
// Coroutine safety: forbid YIELD when operand stack is not empty (minimal rule)
if let OpCode::Yield = instr.opcode {
if in_height != 0 {
return Err(VerifierError::InvalidYieldContext { pc: func_start + pc, height: in_height });
}
}
// Compute out types vector with closure-aware rules
use SlotTy::*;
let mut out_types = in_types.clone();