From e2a01d23db5e284f8912ced4735ee7a4133aac92 Mon Sep 17 00:00:00 2001 From: Zhang Zhuo Date: Tue, 15 Feb 2022 11:57:57 +0800 Subject: [PATCH 1/4] dev: add name for lookup --- halo2_proofs/src/dev.rs | 11 ++++++++++- halo2_proofs/src/plonk/circuit.rs | 6 ++++-- halo2_proofs/src/plonk/lookup.rs | 4 +++- halo2_proofs/tests/lookup_any.rs | 8 ++++++-- halo2_proofs/tests/plonk_api.rs | 2 +- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/halo2_proofs/src/dev.rs b/halo2_proofs/src/dev.rs index 8331521db8..6f111e2ef5 100644 --- a/halo2_proofs/src/dev.rs +++ b/halo2_proofs/src/dev.rs @@ -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`. @@ -215,9 +217,15 @@ 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, @@ -938,6 +946,7 @@ impl MockProver { None } else { Some(VerifyFailure::Lookup { + name: lookup.name, lookup_index, location: FailureLocation::find_expressions( &self.cs, diff --git a/halo2_proofs/src/plonk/circuit.rs b/halo2_proofs/src/plonk/circuit.rs index 9f934dca55..3c41cf27b6 100644 --- a/halo2_proofs/src/plonk/circuit.rs +++ b/halo2_proofs/src/plonk/circuit.rs @@ -917,6 +917,7 @@ impl ConstraintSystem { /// they need to match. pub fn lookup( &mut self, + name: &'static str, table_map: impl FnOnce(&mut VirtualCells<'_, F>) -> Vec<(Expression, TableColumn)>, ) -> usize { let mut cells = VirtualCells::new(self); @@ -935,7 +936,7 @@ impl ConstraintSystem { let index = self.lookups.len(); - self.lookups.push(lookup::Argument::new(table_map)); + self.lookups.push(lookup::Argument::new(name, table_map)); index } @@ -948,6 +949,7 @@ impl ConstraintSystem { /// 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, Expression)>, ) -> usize { let mut cells = VirtualCells::new(self); @@ -955,7 +957,7 @@ impl ConstraintSystem { let index = self.lookups.len(); - self.lookups.push(lookup::Argument::new(table_map)); + self.lookups.push(lookup::Argument::new(name, table_map)); index } diff --git a/halo2_proofs/src/plonk/lookup.rs b/halo2_proofs/src/plonk/lookup.rs index ea312eed31..b7f97042c2 100644 --- a/halo2_proofs/src/plonk/lookup.rs +++ b/halo2_proofs/src/plonk/lookup.rs @@ -6,6 +6,7 @@ pub(crate) mod verifier; #[derive(Clone, Debug)] pub(crate) struct Argument { + pub name: &'static str, pub input_expressions: Vec>, pub table_expressions: Vec>, } @@ -14,9 +15,10 @@ impl Argument { /// Constructs a new lookup argument. /// /// `table_map` is a sequence of `(input, table)` tuples. - pub fn new(table_map: Vec<(Expression, Expression)>) -> Self { + pub fn new(name: &'static str, table_map: Vec<(Expression, Expression)>) -> Self { let (input_expressions, table_expressions) = table_map.into_iter().unzip(); Argument { + name, input_expressions, table_expressions, } diff --git a/halo2_proofs/tests/lookup_any.rs b/halo2_proofs/tests/lookup_any.rs index 7d7658cdba..e661aaa96e 100644 --- a/halo2_proofs/tests/lookup_any.rs +++ b/halo2_proofs/tests/lookup_any.rs @@ -1,3 +1,4 @@ + use std::marker::PhantomData; use halo2_proofs::{ @@ -37,7 +38,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); @@ -47,7 +48,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); @@ -207,4 +208,7 @@ fn lookup_any() { // the odd number lookup will fail. let prover = MockProver::run(k, &circuit, vec![even_lookup]).unwrap(); assert!(prover.verify().is_err()) + name: "odd number", + name: "odd number", + name: "odd number", } diff --git a/halo2_proofs/tests/plonk_api.rs b/halo2_proofs/tests/plonk_api.rs index be47a2b691..9f78b31387 100644 --- a/halo2_proofs/tests/plonk_api.rs +++ b/halo2_proofs/tests/plonk_api.rs @@ -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)] }); From 2a49e2a2bbbe4ab82b21ae1262efb1da01990cf4 Mon Sep 17 00:00:00 2001 From: Zhang Zhuo Date: Sun, 23 Jan 2022 16:36:30 +0800 Subject: [PATCH 2/4] dev: add name for lookup --- halo2_proofs/src/dev.rs | 4 +++- halo2_proofs/tests/lookup_any.rs | 3 --- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/halo2_proofs/src/dev.rs b/halo2_proofs/src/dev.rs index 6f111e2ef5..02c842affa 100644 --- a/halo2_proofs/src/dev.rs +++ b/halo2_proofs/src/dev.rs @@ -226,6 +226,7 @@ impl fmt::Display for VerifyFailure { "Lookup {}(index: {}) is not satisfied {}", name, lookup_index, location ) + } Self::Permutation { column, row } => { write!( f, @@ -1131,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); @@ -1208,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(), diff --git a/halo2_proofs/tests/lookup_any.rs b/halo2_proofs/tests/lookup_any.rs index e661aaa96e..f1fafcf620 100644 --- a/halo2_proofs/tests/lookup_any.rs +++ b/halo2_proofs/tests/lookup_any.rs @@ -208,7 +208,4 @@ fn lookup_any() { // the odd number lookup will fail. let prover = MockProver::run(k, &circuit, vec![even_lookup]).unwrap(); assert!(prover.verify().is_err()) - name: "odd number", - name: "odd number", - name: "odd number", } From 67437b222d65d04c3fa6bf06ca58f4685623cb05 Mon Sep 17 00:00:00 2001 From: Zhang Zhuo Date: Tue, 25 Jan 2022 17:52:04 +0800 Subject: [PATCH 3/4] fix examples --- halo2_proofs/examples/circuit-layout.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/halo2_proofs/examples/circuit-layout.rs b/halo2_proofs/examples/circuit-layout.rs index feaaaf4a2d..921d96298f 100644 --- a/halo2_proofs/examples/circuit-layout.rs +++ b/halo2_proofs/examples/circuit-layout.rs @@ -215,7 +215,7 @@ impl Circuit for MyCircuit { * ... ... ... 0 * ] */ - meta.lookup(|meta| { + meta.lookup("lookup", |meta| { let a_ = meta.query_any(a, Rotation::cur()); vec![(a_, sl)] }); From ca8cad0e62f4ef595e6e30bbd75da830037bf297 Mon Sep 17 00:00:00 2001 From: Zhang Zhuo Date: Tue, 15 Feb 2022 20:14:01 +0800 Subject: [PATCH 4/4] format --- halo2_proofs/tests/lookup_any.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/halo2_proofs/tests/lookup_any.rs b/halo2_proofs/tests/lookup_any.rs index f1fafcf620..676c8a0862 100644 --- a/halo2_proofs/tests/lookup_any.rs +++ b/halo2_proofs/tests/lookup_any.rs @@ -1,4 +1,3 @@ - use std::marker::PhantomData; use halo2_proofs::{