Skip to content

Commit

Permalink
check done: basic preflight
Browse files Browse the repository at this point in the history
  • Loading branch information
supragya committed Jul 7, 2024
1 parent f5753cf commit 0b99bc6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ mod tests {
#[test]
/// Tests whether two numbers in memory can be added together
/// in the ZKVM
fn test_preflight_1() {
fn test_preflight_add_memory() {
let instructions = vec![
Instruction::Lb(Register::R0, MemoryLocation(0x40)),
Instruction::Lb(Register::R1, MemoryLocation(0x41)),
Expand Down Expand Up @@ -63,6 +63,14 @@ mod tests {
assert!(simulation.is_ok());
let simulation = simulation.unwrap();

println!("{:#?}", simulation);
assert_eq!(
simulation.trace_rows[simulation
.trace_rows
.len()
- 1]
.get_memory_at(&expected.0)
.unwrap(),
expected.1
);
}
}
17 changes: 15 additions & 2 deletions src/preflight_simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ impl SimulationRow {
.context("instruction not found")?;

let is_halted = instruction == Instruction::Halt;
let mut registers = self
.registers;
let mut registers = self.registers;

let mut memory_snapshot = self
.memory_snapshot
Expand Down Expand Up @@ -148,6 +147,20 @@ impl SimulationRow {
memory_snapshot,
})
}

pub fn get_memory_at(
&self,
address: &u8,
) -> Option<u8> {
self.memory_snapshot
.get(address)
.copied()
}

pub fn get_registers(&self) -> [u8; REGISTER_COUNT] {
self.registers
.clone()
}
}

/// Unconstrainted Preflight Simulation of the program built
Expand Down

0 comments on commit 0b99bc6

Please sign in to comment.