diff --git a/src/plonk.rs b/src/plonk.rs index c6a8be1..a3feeed 100644 --- a/src/plonk.rs +++ b/src/plonk.rs @@ -121,7 +121,7 @@ fn test_proving() { use crate::poly::commitment::{Blind, Params}; use crate::transcript::DummyHash; use crate::tweedle::{EqAffine, Fp, Fq}; - use circuit::{Advice, Any, Column, Fixed}; + use circuit::{Advice, Column, Fixed}; use std::marker::PhantomData; const K: u32 = 5; @@ -354,11 +354,8 @@ fn test_proving() { * * ] */ - meta.lookup(&[Column::::from(a)], &[Column::::from(sl)]); - meta.lookup( - &[Column::::from(a), Column::::from(b)], - &[Column::::from(sl), Column::::from(sl2)], - ); + meta.lookup(&[a.into()], &[sl.into()]); + meta.lookup(&[a.into(), b.into()], &[sl.into(), sl2.into()]); meta.create_gate(|meta| { let d = meta.query_advice(d, 1); diff --git a/src/plonk/circuit.rs b/src/plonk/circuit.rs index 822ea14..b217137 100644 --- a/src/plonk/circuit.rs +++ b/src/plonk/circuit.rs @@ -359,12 +359,13 @@ impl ConstraintSystem { } /// Add a lookup argument for some input columns and table columns. + /// The function will panic if the number of input columns and table + /// columns are not the same. pub fn lookup( &mut self, input_columns: &[Column], table_columns: &[Column], ) -> usize { - // The function will panic if the number of input columns and table columns are not the same. assert_eq!(input_columns.len(), table_columns.len()); let index = self.lookups.len(); diff --git a/src/plonk/lookup.rs b/src/plonk/lookup.rs index e24e2b3..640faef 100644 --- a/src/plonk/lookup.rs +++ b/src/plonk/lookup.rs @@ -1,7 +1,7 @@ use super::circuit::{Any, Column}; use crate::arithmetic::CurveAffine; -pub(crate) mod prover; +mod prover; mod verifier; #[derive(Clone, Debug)] diff --git a/src/plonk/lookup/prover.rs b/src/plonk/lookup/prover.rs index 31b6c1d..80f743a 100644 --- a/src/plonk/lookup/prover.rs +++ b/src/plonk/lookup/prover.rs @@ -233,44 +233,28 @@ impl<'a, C: CurveAffine> Permuted<'a, C> { lookup_product.iter_mut().batch_invert(); // Finish the computation of the entire fraction by computing the numerators - // (\theta^{m-1} a_1(\omega^i) + \theta^{m-2} a_2(\omega^i) + ... + \theta a_{m-1}(\omega^i) + a_m(\omega^i) + \beta)(\theta^{m-1} s_1(\omega^i) + \theta^{m-2} s_2(\omega^i) + ... + \theta s_{m-1}(\omega^i) + s_m(\omega^i) + \gamma) - // Compress unpermuted input columns - let mut input_term = vec![C::Scalar::zero(); params.n as usize]; - for unpermuted_input_column in self.unpermuted_input_columns.iter() { - parallelize(&mut input_term, |input_term, start| { - for (input_term, input_value) in input_term - .iter_mut() - .zip(unpermuted_input_column[start..].iter()) - { - *input_term *= θ - *input_term += input_value; - } - }); - } - - // Compress unpermuted table columns - let mut table_term = vec![C::Scalar::zero(); params.n as usize]; - for unpermuted_table_columns in self.unpermuted_table_columns.iter() { - parallelize(&mut table_term, |table_term, start| { - for (table_term, fixed_value) in table_term - .iter_mut() - .zip(unpermuted_table_columns[start..].iter()) - { - *table_term *= θ - *table_term += fixed_value; - } - }); - } - - // Add \beta and \gamma offsets + // (\theta^{m-1} a_1(\omega^i) + \theta^{m-2} a_2(\omega^i) + ... + \theta a_{m-1}(\omega^i) + a_m(\omega^i) + \beta) + // * (\theta^{m-1} s_1(\omega^i) + \theta^{m-2} s_2(\omega^i) + ... + \theta s_{m-1}(\omega^i) + s_m(\omega^i) + \gamma) parallelize(&mut lookup_product, |product, start| { - for ((product, input_term), table_term) in product - .iter_mut() - .zip(input_term[start..].iter()) - .zip(table_term[start..].iter()) - { - *product *= &(*input_term + &beta); - *product *= &(*table_term + &gamma); + for (i, product) in product.iter_mut().enumerate() { + let i = i + start; + + // Compress unpermuted input columns + let mut input_term = C::Scalar::zero(); + for unpermuted_input_column in self.unpermuted_input_columns.iter() { + input_term *= θ + input_term += &unpermuted_input_column[i]; + } + + // Compress unpermuted table columns + let mut table_term = C::Scalar::zero(); + for unpermuted_table_column in self.unpermuted_table_columns.iter() { + table_term *= θ + table_term += &unpermuted_table_column[i]; + } + + *product *= &(input_term + &beta); + *product *= &(table_term + &gamma); } }); @@ -402,42 +386,27 @@ impl<'a, C: CurveAffine> Committed<'a, C> { // z'(\omega^{-1} X) (\theta^m a_1(X) + \theta^{m-1} a_2(X) + ... + a_m(X) + \beta) (\theta^m s_1(X) + \theta^{m-1} s_2(X) + ... + s_m(X) + \gamma) let mut right = self.product_inv_coset; - let mut input_terms = pk.vk.domain.empty_extended(); - - // Compress the unpermuted input columns - for input in permuted.unpermuted_input_cosets.iter() { - // \theta^m a_1(X) + \theta^{m-1} a_2(X) + ... + a_m(X) - parallelize(&mut input_terms, |input_term, start| { - for (input_term, input) in input_term.iter_mut().zip(input[start..].iter()) - { - *input_term *= &(*theta); - *input_term += input; - } - }); - } - - let mut table_terms = pk.vk.domain.empty_extended(); - // Compress the unpermuted table columns - for table in permuted.unpermuted_table_cosets.iter() { - // \theta^m s_1(X) + \theta^{m-1} s_2(X) + ... + s_m(X) - parallelize(&mut table_terms, |table_term, start| { - for (table_term, table) in table_term.iter_mut().zip(table[start..].iter()) - { - *table_term *= &(*theta); - *table_term += table; - } - }); - } - - // Add \beta and \gamma offsets parallelize(&mut right, |right, start| { - for ((right, input_term), table_term) in right - .iter_mut() - .zip(input_terms[start..].iter()) - .zip(table_terms[start..].iter()) - { - *right *= &(*input_term + &(*beta)); - *right *= &(*table_term + &(*gamma)); + for (i, right) in right.iter_mut().enumerate() { + let i = i + start; + + // Compress the unpermuted input columns + let mut input_term = C::Scalar::zero(); + for input in permuted.unpermuted_input_cosets.iter() { + input_term *= θ + input_term += &input[i]; + } + + // Compress the unpermuted table columns + let mut table_term = C::Scalar::zero(); + for table in permuted.unpermuted_table_cosets.iter() { + table_term *= θ + table_term += &table[i]; + } + + // Add \beta and \gamma offsets + *right *= &(input_term + &beta); + *right *= &(table_term + &gamma); } });