Skip to content

Commit

Permalink
More renames (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuvalsw authored Dec 30, 2024
1 parent ab17ac2 commit 7f2593f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion stwo_cairo_prover/crates/adapted_prover/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn run(args: impl Iterator<Item = String>) -> Result<CairoProof<Blake2sMerkleHas
let casm_states_by_opcode_count = &vm_output.state_transitions.casm_states_by_opcode.counts();
log::info!("Casm states by opcode count: {casm_states_by_opcode_count:?}");

// TODO(Ohad): Propogate hash from CLI args.
// TODO(Ohad): Propagate hash from CLI args.
let proof =
prove_cairo::<Blake2sMerkleChannel>(vm_output, args.debug_lookup, args.display_components)?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ pub struct ClaimGenerator {
pub multiplicities: MultiplicityColumn,
}
impl ClaimGenerator {
pub fn new(mem: &Memory) -> Self {
let ids = (0..mem.address_to_id.len())
.map(|addr| mem.get_raw_id(addr as u32))
pub fn new(memory: &Memory) -> Self {
let ids = (0..memory.address_to_id.len())
.map(|addr| memory.get_raw_id(addr as u32))
.collect_vec();
let multiplicities = MultiplicityColumn::new(ids.len());

Expand Down
22 changes: 11 additions & 11 deletions stwo_cairo_prover/crates/prover/src/input/state_transitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl StateTransitions {
/// Iterates over the casm states and splits them into the appropriate opcode components.
pub fn from_iter(
iter: impl Iterator<Item = TraceEntry>,
mem: &mut MemoryBuilder,
memory: &mut MemoryBuilder,
dev_mode: bool,
) -> Self {
let mut res = Self::default();
Expand All @@ -189,24 +189,24 @@ impl StateTransitions {
return res;
};
res.initial_state = first.into();
res.push_instr(mem, first.into(), dev_mode);
res.push_instr(memory, first.into(), dev_mode);

while let Some(entry) = iter.next() {
// TODO(Ohad): Check if the adapter outputs the final state.
let Some(_) = iter.peek() else {
res.final_state = entry.into();
break;
};
res.push_instr(mem, entry.into(), dev_mode);
res.push_instr(memory, entry.into(), dev_mode);
}
res
}

// TODO(Ohad): remove dev_mode after adding the rest of the instructions.
/// Pushes the state transition at pc into the appropriate opcode component.
fn push_instr(&mut self, mem: &mut MemoryBuilder, state: CasmState, dev_mode: bool) {
fn push_instr(&mut self, memory: &mut MemoryBuilder, state: CasmState, dev_mode: bool) {
let CasmState { ap, fp, pc } = state;
let instruction = mem.get_inst(pc.0);
let instruction = memory.get_inst(pc.0);
let instruction = Instruction::decode(instruction);

match instruction {
Expand Down Expand Up @@ -409,7 +409,7 @@ impl StateTransitions {
opcode_assert_eq: false,
} => {
let dst_addr = if dst_base_fp { fp } else { ap };
let dst = mem.get(dst_addr.0.checked_add_signed(offset0 as i32).unwrap());
let dst = memory.get(dst_addr.0.checked_add_signed(offset0 as i32).unwrap());
let taken = dst != MemoryValue::Small(0);
if taken {
if dst_base_fp {
Expand Down Expand Up @@ -509,8 +509,8 @@ impl StateTransitions {
if op_1_base_fp { fp } else { ap },
);
let (op0, op_1) = (
mem.get(op0_addr.0.checked_add_signed(offset1 as i32).unwrap()),
mem.get(op_1_addr.0.checked_add_signed(offset2 as i32).unwrap()),
memory.get(op0_addr.0.checked_add_signed(offset1 as i32).unwrap()),
memory.get(op_1_addr.0.checked_add_signed(offset2 as i32).unwrap()),
);
if op_1_imm {
// [ap/fp + offset0] = [ap/fp + offset1] * Imm.
Expand Down Expand Up @@ -576,9 +576,9 @@ impl StateTransitions {
if op_1_base_fp { fp } else { ap },
);
let (dst, op0, op_1) = (
mem.get(dst_addr.0.checked_add_signed(offset0 as i32).unwrap()),
mem.get(op0_addr.0.checked_add_signed(offset1 as i32).unwrap()),
mem.get(op_1_addr.0.checked_add_signed(offset2 as i32).unwrap()),
memory.get(dst_addr.0.checked_add_signed(offset0 as i32).unwrap()),
memory.get(op0_addr.0.checked_add_signed(offset1 as i32).unwrap()),
memory.get(op_1_addr.0.checked_add_signed(offset2 as i32).unwrap()),
);
if op_1_imm {
// [ap/fp + offset0] = [ap/fp + offset1] + Imm.
Expand Down
10 changes: 5 additions & 5 deletions stwo_cairo_prover/crates/prover/src/input/vm_import/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ pub fn import_from_vm_output(

let mut trace_file = std::io::BufReader::new(std::fs::File::open(trace_path)?);
let mut memory_file = std::io::BufReader::new(std::fs::File::open(memory_path)?);
let mut memory = MemoryBuilder::from_iter(memory_config, MemEntryIter(&mut memory_file));
let mut memory = MemoryBuilder::from_iter(memory_config, MemoryEntryIter(&mut memory_file));
let state_transitions =
StateTransitions::from_iter(TraceIter(&mut trace_file), &mut memory, dev_mode);

let public_mem_addresses = public_input
let public_memory_addresses = public_input
.public_memory
.iter()
.map(|entry| entry.address as u32)
Expand All @@ -71,7 +71,7 @@ pub fn import_from_vm_output(
Ok(CairoInput {
state_transitions,
memory: memory.build(),
public_memory_addresses: public_mem_addresses,
public_memory_addresses,
range_check_builtin: MemorySegmentAddresses {
begin_addr: public_input.memory_segments["range_check"].begin_addr as usize,
stop_ptr: public_input.memory_segments["range_check"].stop_ptr as usize,
Expand Down Expand Up @@ -121,8 +121,8 @@ pub struct MemoryEntry {
pub value: [u32; 8],
}

pub struct MemEntryIter<'a, R: Read>(pub &'a mut R);
impl<R: Read> Iterator for MemEntryIter<'_, R> {
pub struct MemoryEntryIter<'a, R: Read>(pub &'a mut R);
impl<R: Read> Iterator for MemoryEntryIter<'_, R> {
type Item = MemoryEntry;

fn next(&mut self) -> Option<Self::Item> {
Expand Down

0 comments on commit 7f2593f

Please sign in to comment.