Skip to content

Commit a04ea5e

Browse files
committed
hint test with frame change
1 parent 66204c2 commit a04ea5e

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

integration/src/instruction_builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,11 @@ pub fn pre_read_u32<F: PrimeField32>() -> Instruction<F> {
333333
}
334334

335335
#[allow(dead_code)]
336-
pub fn read_u32<F: PrimeField32>(rd: usize, num_words: usize) -> Instruction<F> {
336+
pub fn read_u32<F: PrimeField32>(rd: usize) -> Instruction<F> {
337337
Instruction::from_isize(
338338
HintStoreOpcode::HINT_STOREW.global_opcode(),
339339
(riscv::RV32_REGISTER_NUM_LIMBS * rd) as isize,
340-
(riscv::RV32_REGISTER_NUM_LIMBS * num_words) as isize,
340+
0,
341341
0,
342342
1,
343343
0,

integration/src/main.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ mod tests {
757757
fn test_input_hint() -> Result<(), Box<dyn std::error::Error>> {
758758
let instructions = vec![
759759
wom::pre_read_u32::<F>(),
760-
wom::read_u32::<F>(10, 0),
760+
wom::read_u32::<F>(10),
761761
reveal(10, 0),
762762
halt(),
763763
];
@@ -766,4 +766,41 @@ mod tests {
766766

767767
run_vm_test("Input hint", instructions, 42, Some(stdin))
768768
}
769+
770+
#[test]
771+
fn test_input_hint_with_frame_jump_and_xor() -> Result<(), Box<dyn std::error::Error>> {
772+
let instructions = vec![
773+
// Read first value into r8
774+
wom::pre_read_u32::<F>(),
775+
wom::read_u32::<F>(8),
776+
wom::allocate_frame_imm::<F>(9, 64), // Allocate frame, pointer in 99
777+
wom::copy_into_frame::<F>(2, 8, 9), // Copy r8 to frame[2]
778+
// Jump to new frame
779+
wom::jaaf::<F>(24, 9), // Jump to PC=24, activate frame at r9
780+
// This should be skipped
781+
halt(),
782+
// Read second value into r3
783+
wom::pre_read_u32::<F>(),
784+
wom::read_u32::<F>(3),
785+
// Xor the two read values
786+
wom::xor::<F>(4, 2, 3),
787+
// TODO: register 5 below is the absolute value for local register 4 used above,
788+
// due to the `loadstore` chip not being fp relative yet.
789+
// The allocated frame is 4 (first allocation). Registers are 4-aligned,
790+
// so in order to access local reg 4 we need (fp / 4 + local reg) = 4/4+1.
791+
reveal(5, 0),
792+
halt(),
793+
];
794+
795+
let mut stdin = StdIn::default();
796+
stdin.write(&170u32); // First value: 170 in decimal
797+
stdin.write(&204u32); // Second value: 204 in decimal
798+
799+
run_vm_test(
800+
"Input hint with frame jump and XOR",
801+
instructions,
802+
102,
803+
Some(stdin),
804+
)
805+
}
769806
}

0 commit comments

Comments
 (0)