Skip to content

Commit

Permalink
Change proof size check to 60*32
Browse files Browse the repository at this point in the history
  • Loading branch information
mininny committed Jan 15, 2025
1 parent b4d5cf6 commit e86edbf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions rvsol/src/RISCV.sol
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,10 @@ contract RISCV is IBigStepper {
}
if iszero(eq(_proof.offset, proofContentOffset())) { revert(0, 0) }

if mod(calldataload(sub(proofContentOffset(), 32)), 60) {
if mod(calldataload(sub(proofContentOffset(), 32)), mul(60, 32)) {
// proof offset must be stateContentOffset+paddedStateSize+32
// proof size: 64-5+1=60 * 32 byte leaf,
// so the proofSize must be a multiple of 60
// so the proofSize must be a multiple of 60*32
revert(0, 0)
}

Expand Down
8 changes: 5 additions & 3 deletions rvsol/test/RISCV.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2385,9 +2385,11 @@ contract RISCV_Test is CommonTest {
uint32 insn = encodeRType(0xff, 0, 0, 0, 0, 0);
(State memory state, bytes memory proof) = constructRISCVState(0, insn);
bytes memory encodedState = encodeState(state);
// Invalid memory proof
proof =
hex"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";

// Overwrite the first 60 bytes of the proof with zero to create invalid memory proof
for (uint256 i = 0; i < 60 && i < proof.length; i++) {
proof[i] = 0x00;
}

vm.expectRevert(hex"00000000000000000000000000000000000000000000000000000000badf00d1");
riscv.step(encodedState, proof, 0);
Expand Down

0 comments on commit e86edbf

Please sign in to comment.