Skip to content

Commit

Permalink
Merge pull request privacy-scaling-explorations#32 from appliedzkp/kz…
Browse files Browse the repository at this point in the history
…g-rebase

Add name for lookup
  • Loading branch information
kilic authored Feb 16, 2022
2 parents e5ce9a3 + 6f8a605 commit 514152c
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion halo2_proofs/examples/circuit-layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ impl<F: FieldExt> Circuit<F> for MyCircuit<F> {
* ... ... ... 0
* ]
*/
meta.lookup(|meta| {
meta.lookup("lookup", |meta| {
let a_ = meta.query_any(a, Rotation::cur());
vec![(a_, sl)]
});
Expand Down
15 changes: 13 additions & 2 deletions halo2_proofs/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ pub enum VerifyFailure {
},
/// A lookup input did not exist in its corresponding table.
Lookup {
/// The name of the lookup that is not satisfied.
name: &'static str,
/// The index of the lookup that is not satisfied. These indices are assigned in
/// the order in which `ConstraintSystem::lookup` is called during
/// `Circuit::configure`.
Expand Down Expand Up @@ -215,9 +217,16 @@ impl fmt::Display for VerifyFailure {
)
}
Self::Lookup {
name,
lookup_index,
location,
} => write!(f, "Lookup {} is not satisfied {}", lookup_index, location),
} => {
write!(
f,
"Lookup {}(index: {}) is not satisfied {}",
name, lookup_index, location
)
}
Self::Permutation { column, row } => {
write!(
f,
Expand Down Expand Up @@ -938,6 +947,7 @@ impl<F: FieldExt> MockProver<F> {
None
} else {
Some(VerifyFailure::Lookup {
name: lookup.name,
lookup_index,
location: FailureLocation::find_expressions(
&self.cs,
Expand Down Expand Up @@ -1122,7 +1132,7 @@ mod tests {
let q = meta.complex_selector();
let table = meta.lookup_table_column();

meta.lookup(|cells| {
meta.lookup("lookup", |cells| {
let a = cells.query_advice(a, Rotation::cur());
let q = cells.query_selector(q);

Expand Down Expand Up @@ -1199,6 +1209,7 @@ mod tests {
assert_eq!(
prover.verify(),
Err(vec![VerifyFailure::Lookup {
name: "lookup",
lookup_index: 0,
location: FailureLocation::InRegion {
region: (2, "Faulty synthesis").into(),
Expand Down
6 changes: 4 additions & 2 deletions halo2_proofs/src/plonk/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,7 @@ impl<F: Field> ConstraintSystem<F> {
/// they need to match.
pub fn lookup(
&mut self,
name: &'static str,
table_map: impl FnOnce(&mut VirtualCells<'_, F>) -> Vec<(Expression<F>, TableColumn)>,
) -> usize {
let mut cells = VirtualCells::new(self);
Expand All @@ -935,7 +936,7 @@ impl<F: Field> ConstraintSystem<F> {

let index = self.lookups.len();

self.lookups.push(lookup::Argument::new(table_map));
self.lookups.push(lookup::Argument::new(name, table_map));

index
}
Expand All @@ -948,14 +949,15 @@ impl<F: Field> ConstraintSystem<F> {
/// This API allows any column type to be used as table columns.
pub fn lookup_any(
&mut self,
name: &'static str,
table_map: impl FnOnce(&mut VirtualCells<'_, F>) -> Vec<(Expression<F>, Expression<F>)>,
) -> usize {
let mut cells = VirtualCells::new(self);
let table_map = table_map(&mut cells);

let index = self.lookups.len();

self.lookups.push(lookup::Argument::new(table_map));
self.lookups.push(lookup::Argument::new(name, table_map));

index
}
Expand Down
4 changes: 3 additions & 1 deletion halo2_proofs/src/plonk/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub(crate) mod verifier;

#[derive(Clone, Debug)]
pub(crate) struct Argument<F: Field> {
pub name: &'static str,
pub input_expressions: Vec<Expression<F>>,
pub table_expressions: Vec<Expression<F>>,
}
Expand All @@ -14,9 +15,10 @@ impl<F: Field> Argument<F> {
/// Constructs a new lookup argument.
///
/// `table_map` is a sequence of `(input, table)` tuples.
pub fn new(table_map: Vec<(Expression<F>, Expression<F>)>) -> Self {
pub fn new(name: &'static str, table_map: Vec<(Expression<F>, Expression<F>)>) -> Self {
let (input_expressions, table_expressions) = table_map.into_iter().unzip();
Argument {
name,
input_expressions,
table_expressions,
}
Expand Down
4 changes: 2 additions & 2 deletions halo2_proofs/tests/lookup_any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn lookup_any() {
};

// Lookup on even numbers
meta.lookup_any(|meta| {
meta.lookup_any("even number", |meta| {
let input = meta.query_advice(config.input, Rotation::cur());

let q_even = meta.query_selector(config.q_even);
Expand All @@ -47,7 +47,7 @@ fn lookup_any() {
});

// Lookup on odd numbers
meta.lookup_any(|meta| {
meta.lookup_any("odd number", |meta| {
let input = meta.query_advice(config.input, Rotation::cur());

let q_odd = meta.query_selector(config.q_odd);
Expand Down
2 changes: 1 addition & 1 deletion halo2_proofs/tests/plonk_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ fn plonk_api() {
* ]
*/

meta.lookup(|meta| {
meta.lookup("lookup", |meta| {
let a_ = meta.query_any(a, Rotation::cur());
vec![(a_, sl)]
});
Expand Down

0 comments on commit 514152c

Please sign in to comment.