Skip to content

Commit

Permalink
sort sigs before iterating
Browse files Browse the repository at this point in the history
  • Loading branch information
YairVaknin-starkware committed Nov 11, 2024
1 parent 0a36033 commit adfe27b
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions vm/src/vm/runners/builtin_runner/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,17 @@ impl SignatureBuiltinRunner {

pub fn air_private_input(&self, memory: &Memory) -> Vec<PrivateInput> {
let mut private_inputs = vec![];
for (addr, signature) in self.signatures.borrow().iter() {

// Collect and sort the signatures by their index before the loop
let binding = self.signatures.borrow();
let mut sorted_signatures: Vec<_> = binding.iter().collect();
sorted_signatures.sort_by_key(|(addr, _)| {
addr.offset
.checked_div(CELLS_PER_SIGNATURE as usize)
.unwrap_or_default()
});

for (addr, signature) in sorted_signatures {
if let (Ok(pubkey), Some(msg)) = (
memory.get_integer(*addr),
(*addr + 1_usize)
Expand Down Expand Up @@ -238,14 +248,6 @@ impl SignatureBuiltinRunner {
}))
}
}
private_inputs.sort_by_key(|input| match input {
PrivateInput::Signature(sig) => sig.index,
_ => unreachable!(
"Unexpected variant in private_inputs: {:?}.
This private input of the signature builtin is always a Signature variant.",
input
),
});
private_inputs
}
}
Expand Down

0 comments on commit adfe27b

Please sign in to comment.