Skip to content

Commit

Permalink
add a test to show that the proof's memory_layout is not used
Browse files Browse the repository at this point in the history
  • Loading branch information
sagar-a16z committed Oct 31, 2024
1 parent d11e866 commit ac2a9af
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions jolt-core/src/jolt/vm/rv32i_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,4 +550,44 @@ mod tests {
verification_result.err()
);
}

#[test]
#[should_panic]
fn truncated_malicious_trace() {
let artifact_guard = FIB_FILE_LOCK.lock().unwrap();
let mut program = host::Program::new("fibonacci-guest");
program.set_input(&1u8); // change input to 1 so that termination bit equal true
let (bytecode, memory_init) = program.decode();
let (mut io_device, mut trace) = program.trace();
let memory_layout = io_device.memory_layout.clone();
trace.truncate(100);
// change the output to the same as input to show that we can also forge the output value
io_device.outputs[0] = 1;
drop(artifact_guard);

// change memory address of output & termination bit to the same address as input
// changes here should not be able to spoof the verifier result
io_device.memory_layout.output_start = io_device.memory_layout.input_start;
io_device.memory_layout.output_end = io_device.memory_layout.input_end;
io_device.memory_layout.termination = io_device.memory_layout.input_start;

Check warning on line 572 in jolt-core/src/jolt/vm/rv32i_vm.rs

View workflow job for this annotation

GitHub Actions / fmt

Diff in /home/runner/work/jolt/jolt/jolt-core/src/jolt/vm/rv32i_vm.rs

// Since the preprocessing is done with the original memory layout, the verifier should fail
let preprocessing =
RV32IJoltVM::preprocess(bytecode.clone(), memory_layout, memory_init, 1 << 20, 1 << 20, 1 << 20);
let (proof, commitments, debug_info) = <RV32IJoltVM as Jolt<
Fr,
HyperKZG<Bn254, KeccakTranscript>,
C,
M,
KeccakTranscript,
>>::prove(
io_device, trace, preprocessing.clone()
);
let verification_result =
RV32IJoltVM::verify(preprocessing, proof, commitments, debug_info);
assert!(
verification_result.is_err(),
"Verification passed unexpectedly",
);
}
}

0 comments on commit ac2a9af

Please sign in to comment.