Skip to content

Commit

Permalink
Reduce the number of rounds in ROM checking to 2.
Browse files Browse the repository at this point in the history
It was spuriously three because of imprecise dependency tracking
  • Loading branch information
alex-ozdemir committed Jul 8, 2024
1 parent 1224730 commit dfb0342
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
1 change: 1 addition & 0 deletions examples/circ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ fn main() {
println!("R1CS stats: {:#?}", r1cs.stats());
}
let (prover_data, verifier_data) = r1cs.finalize(cs);
println!("Final R1cs rounds: {}", prover_data.precompute.stage_sizes().count() - 1);
match action {
ProofAction::Count => (),
#[cfg(feature = "bellman")]
Expand Down
2 changes: 1 addition & 1 deletion src/ir/opt/mem/ram/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ pub fn haboeck_range_check(
let ns = ns.subspace("range");
let f_sort = Sort::Field(f.clone());
let haystack: Vec<Term> = f_sort.elems_iter().take(n).collect();
assertions.push(rom::lookup(c, ns, haystack, values));
assertions.push(rom::lookup(c, ns, haystack, values, None));
}

/// Ensure that each element of `values` is in `[0, n)`.
Expand Down
41 changes: 27 additions & 14 deletions src/ir/opt/mem/ram/checker/rom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@ use log::debug;
///
/// Takes haystack, needles, and returns a term which should be asserted to ensure that each needle
/// is in haystack.
pub fn lookup(c: &mut Computation, ns: Namespace, haystack: Vec<Term>, needles: Vec<Term>) -> Term {
///
/// If `original_data` is set, then the keys will be independent of it; otherwise, of
/// needles/haystack.
pub fn lookup(
c: &mut Computation,
ns: Namespace,
haystack: Vec<Term>,
needles: Vec<Term>,
original_data: Option<Vec<Term>>,
) -> Term {
debug!(
"Haboeck lookup haystack {}, needles {}",
haystack.len(),
Expand Down Expand Up @@ -45,12 +54,14 @@ pub fn lookup(c: &mut Computation, ns: Namespace, haystack: Vec<Term>, needles:
.collect();
let key = term(
Op::new_chall(ns.fqn("key"), f.clone()),
haystack
.iter()
.chain(&needles)
.chain(&counts)
.cloned()
.collect(),
original_data.unwrap_or_else(|| {
haystack
.iter()
.chain(&needles)
.chain(&counts)
.cloned()
.collect()
}),
);
// x_i + k
let needle_shifts: Vec<Term> = needles
Expand Down Expand Up @@ -137,13 +148,15 @@ pub fn check_covering_rom(c: &mut Computation, ns: Namespace, ram: Ram) -> Term
}
}
assert!(!writes.is_empty());
let uhf = UniversalHasher::new(
ns.fqn("uhf_key"),
f,
reads.iter().chain(&writes).flatten().cloned().collect(),
writes[0].len(),
);
let inputs: Vec<_> = reads.iter().chain(&writes).flatten().cloned().collect();
let uhf = UniversalHasher::new(ns.fqn("uhf_key"), f, inputs.clone(), writes[0].len());
let write_hashes = writes.into_iter().map(|a| uhf.hash(a)).collect();
let read_hashes = reads.into_iter().map(|a| uhf.hash(a)).collect();
lookup(c, ns.subspace("scalar"), write_hashes, read_hashes)
lookup(
c,
ns.subspace("scalar"),
write_hashes,
read_hashes,
Some(inputs),
)
}
1 change: 1 addition & 0 deletions src/ir/opt/mem/ram/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub fn apply(c: &mut Computation) {
ns.subspace(format!("setmem{}", i)),
haystack,
keys,
None,
));
}
to_assert.push(c.outputs[0].clone());
Expand Down

0 comments on commit dfb0342

Please sign in to comment.