Skip to content

Commit

Permalink
adds tests for loadfp instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
tess-eract committed May 7, 2024
1 parent d2480cb commit 54f3f5a
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion basic/tests/test_prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use valida_alu_u32::lt::{Lt32Instruction, Lte32Instruction, Sle32Instruction, Sl
use valida_basic::BasicMachine;
use valida_cpu::{
BeqInstruction, BneInstruction, Imm32Instruction, JalInstruction, JalvInstruction,
MachineWithCpuChip, StopInstruction,
LoadFpInstruction, MachineWithCpuChip, StopInstruction,
};
use valida_machine::{
FixedAdviceProvider, Instruction, InstructionWord, Machine, MachineProof, Operands, ProgramROM,
Expand Down Expand Up @@ -378,6 +378,29 @@ fn signed_inequality_program<Val: PrimeField32 + TwoAdicField>() -> Vec<Instruct
program
}

fn loadfp_program<Val: PrimeField32 + TwoAdicField>() -> Vec<InstructionWord<i32>> {
let mut program = vec![];
// loadfp 4(fp), 0, 0, 0, 0
// loadfp 8(fp), 3, 0, 0, 0
// stop
program.extend([
InstructionWord {
opcode: <LoadFpInstruction as Instruction<BasicMachine<Val>, Val>>::OPCODE,
operands: Operands([4, 0, 0, 0, 0]),
},
InstructionWord {
opcode: <LoadFpInstruction as Instruction<BasicMachine<Val>, Val>>::OPCODE,
operands: Operands([8, 3, 0, 0, 0]),
},
InstructionWord {
opcode: <StopInstruction as Instruction<BasicMachine<Val>, Val>>::OPCODE,
operands: Operands::default(),
},
]);

program
}

fn prove_program(program: Vec<InstructionWord<i32>>) -> BasicMachine<BabyBear> {
let mut machine = BasicMachine::<Val>::default();
let rom = ProgramROM::new(program);
Expand Down Expand Up @@ -584,3 +607,19 @@ fn prove_signed_inequality() {
Word([0, 0, 0, 0]) // 0xFFFFFFFF < 1 (false)
);
}

#[test]
fn prove_loadfp() {
let program = loadfp_program::<BabyBear>();

let machine = prove_program(program);

assert_eq!(
*machine.mem().cells.get(&(0x1000 + 4)).unwrap(),
Word([0, 0, 16, 0]) // fp = 0x1000 = (0, 0, 16, 0)
);
assert_eq!(
*machine.mem().cells.get(&(0x1000 + 8)).unwrap(),
Word([0, 0, 16, 3]) // fp(3) = 0x1003 = (0, 0, 16, 0)
);
}

0 comments on commit 54f3f5a

Please sign in to comment.