Merge pull request #29 from lispc/debug/better_lookup_err3

dev: add name for lookup
This commit is contained in:
Chih Cheng Liang 2022-02-16 23:14:40 +08:00 committed by GitHub
commit 6f8a605821
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 9 deletions

View File

@ -215,7 +215,7 @@ impl<F: FieldExt> Circuit<F> for MyCircuit<F> {
* ... ... ... 0 * ... ... ... 0
* ] * ]
*/ */
meta.lookup(|meta| { meta.lookup("lookup", |meta| {
let a_ = meta.query_any(a, Rotation::cur()); let a_ = meta.query_any(a, Rotation::cur());
vec![(a_, sl)] vec![(a_, sl)]
}); });

View File

@ -154,6 +154,8 @@ pub enum VerifyFailure {
}, },
/// A lookup input did not exist in its corresponding table. /// A lookup input did not exist in its corresponding table.
Lookup { 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 index of the lookup that is not satisfied. These indices are assigned in
/// the order in which `ConstraintSystem::lookup` is called during /// the order in which `ConstraintSystem::lookup` is called during
/// `Circuit::configure`. /// `Circuit::configure`.
@ -215,9 +217,16 @@ impl fmt::Display for VerifyFailure {
) )
} }
Self::Lookup { Self::Lookup {
name,
lookup_index, lookup_index,
location, 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 } => { Self::Permutation { column, row } => {
write!( write!(
f, f,
@ -938,6 +947,7 @@ impl<F: FieldExt> MockProver<F> {
None None
} else { } else {
Some(VerifyFailure::Lookup { Some(VerifyFailure::Lookup {
name: lookup.name,
lookup_index, lookup_index,
location: FailureLocation::find_expressions( location: FailureLocation::find_expressions(
&self.cs, &self.cs,
@ -1122,7 +1132,7 @@ mod tests {
let q = meta.complex_selector(); let q = meta.complex_selector();
let table = meta.lookup_table_column(); let table = meta.lookup_table_column();
meta.lookup(|cells| { meta.lookup("lookup", |cells| {
let a = cells.query_advice(a, Rotation::cur()); let a = cells.query_advice(a, Rotation::cur());
let q = cells.query_selector(q); let q = cells.query_selector(q);
@ -1199,6 +1209,7 @@ mod tests {
assert_eq!( assert_eq!(
prover.verify(), prover.verify(),
Err(vec![VerifyFailure::Lookup { Err(vec![VerifyFailure::Lookup {
name: "lookup",
lookup_index: 0, lookup_index: 0,
location: FailureLocation::InRegion { location: FailureLocation::InRegion {
region: (2, "Faulty synthesis").into(), region: (2, "Faulty synthesis").into(),

View File

@ -917,6 +917,7 @@ impl<F: Field> ConstraintSystem<F> {
/// they need to match. /// they need to match.
pub fn lookup( pub fn lookup(
&mut self, &mut self,
name: &'static str,
table_map: impl FnOnce(&mut VirtualCells<'_, F>) -> Vec<(Expression<F>, TableColumn)>, table_map: impl FnOnce(&mut VirtualCells<'_, F>) -> Vec<(Expression<F>, TableColumn)>,
) -> usize { ) -> usize {
let mut cells = VirtualCells::new(self); let mut cells = VirtualCells::new(self);
@ -935,7 +936,7 @@ impl<F: Field> ConstraintSystem<F> {
let index = self.lookups.len(); let index = self.lookups.len();
self.lookups.push(lookup::Argument::new(table_map)); self.lookups.push(lookup::Argument::new(name, table_map));
index index
} }
@ -948,6 +949,7 @@ impl<F: Field> ConstraintSystem<F> {
/// This API allows any column type to be used as table columns. /// This API allows any column type to be used as table columns.
pub fn lookup_any( pub fn lookup_any(
&mut self, &mut self,
name: &'static str,
table_map: impl FnOnce(&mut VirtualCells<'_, F>) -> Vec<(Expression<F>, Expression<F>)>, table_map: impl FnOnce(&mut VirtualCells<'_, F>) -> Vec<(Expression<F>, Expression<F>)>,
) -> usize { ) -> usize {
let mut cells = VirtualCells::new(self); let mut cells = VirtualCells::new(self);
@ -955,7 +957,7 @@ impl<F: Field> ConstraintSystem<F> {
let index = self.lookups.len(); let index = self.lookups.len();
self.lookups.push(lookup::Argument::new(table_map)); self.lookups.push(lookup::Argument::new(name, table_map));
index index
} }

View File

@ -6,6 +6,7 @@ pub(crate) mod verifier;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub(crate) struct Argument<F: Field> { pub(crate) struct Argument<F: Field> {
pub name: &'static str,
pub input_expressions: Vec<Expression<F>>, pub input_expressions: Vec<Expression<F>>,
pub table_expressions: Vec<Expression<F>>, pub table_expressions: Vec<Expression<F>>,
} }
@ -14,9 +15,10 @@ impl<F: Field> Argument<F> {
/// Constructs a new lookup argument. /// Constructs a new lookup argument.
/// ///
/// `table_map` is a sequence of `(input, table)` tuples. /// `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(); let (input_expressions, table_expressions) = table_map.into_iter().unzip();
Argument { Argument {
name,
input_expressions, input_expressions,
table_expressions, table_expressions,
} }

View File

@ -37,7 +37,7 @@ fn lookup_any() {
}; };
// Lookup on even numbers // Lookup on even numbers
meta.lookup_any(|meta| { meta.lookup_any("even number", |meta| {
let input = meta.query_advice(config.input, Rotation::cur()); let input = meta.query_advice(config.input, Rotation::cur());
let q_even = meta.query_selector(config.q_even); let q_even = meta.query_selector(config.q_even);
@ -47,7 +47,7 @@ fn lookup_any() {
}); });
// Lookup on odd numbers // Lookup on odd numbers
meta.lookup_any(|meta| { meta.lookup_any("odd number", |meta| {
let input = meta.query_advice(config.input, Rotation::cur()); let input = meta.query_advice(config.input, Rotation::cur());
let q_odd = meta.query_selector(config.q_odd); let q_odd = meta.query_selector(config.q_odd);

View File

@ -299,7 +299,7 @@ fn plonk_api() {
* ] * ]
*/ */
meta.lookup(|meta| { meta.lookup("lookup", |meta| {
let a_ = meta.query_any(a, Rotation::cur()); let a_ = meta.query_any(a, Rotation::cur());
vec![(a_, sl)] vec![(a_, sl)]
}); });