Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check the proof size is a multiple of 60 #99

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions rvsol/src/RISCV.sol
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,13 @@ contract RISCV is IBigStepper {
}
if iszero(eq(_proof.offset, proofContentOffset())) { revert(0, 0) }

if mod(calldataload(sub(proofContentOffset(), 32)), 60) {
// 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
revert(0, 0)
}

//
// State loading
//
Expand Down
14 changes: 13 additions & 1 deletion rvsol/test/RISCV.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2371,11 +2371,23 @@ contract RISCV_Test is CommonTest {
riscv.step(encodedState, proof, 0);
}

function test_invalid_proof_size() public {
uint32 insn = encodeRType(0xff, 0, 0, 0, 0, 0);
(State memory state, bytes memory proof) = constructRISCVState(0, insn);
bytes memory encodedState = encodeState(state);
proof = hex"00"; // Invalid memory proof size

vm.expectRevert();
riscv.step(encodedState, proof, 0);
}

function test_invalid_proof() public {
uint32 insn = encodeRType(0xff, 0, 0, 0, 0, 0);
(State memory state, bytes memory proof) = constructRISCVState(0, insn);
bytes memory encodedState = encodeState(state);
proof = hex"00"; // Invalid memory proof
// Invalid memory proof
proof =
hex"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";

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