Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/osp/OneStepProverHostIo.sol
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,25 @@ contract OneStepProverHostIo is IOneStepProver {
uint256 preimageType = mach.valueStack.pop().assumeI32();
uint256 ptr = mach.valueStack.pop().assumeI32();

// Validate preimageType fits in u8 (matches Rust u8::try_from)
if (preimageType > 255) {
mach.status = MachineStatus.ERRORED;
return;
}

// Invalid enum values (4-255) return 0 with no memory access
// This matches Rust where PreimageType::try_from fails
if (preimageType >= 4) {
mach.valueStack.push(ValueLib.newI32(0));
return;
}

// Validate ptr (matches Rust load_32_byte_aligned check)
if (!mod.moduleMemory.isValidLeaf(ptr)) {
mach.status = MachineStatus.ERRORED;
return;
}

// Prove the hash in memory
uint256 leafIdx = ptr / LEAF_SIZE;
uint256 proofOffset = 0;
Expand All @@ -302,7 +321,7 @@ contract OneStepProverHostIo is IOneStepProver {
mach.valueStack.push(ValueLib.newI32(0));
}
} else {
// Non-CustomDA always valid
// preimageType 0, 1, 2 -> always valid
mach.valueStack.push(ValueLib.newI32(1));
}

Expand Down
Loading