mirror of https://github.com/zcash/halo2.git
Further cleanups
Co-authored-by: ebfull <ewillbefull@gmail.com>
This commit is contained in:
parent
ecc805fa35
commit
30c13d5a6a
|
@ -121,7 +121,7 @@ fn test_proving() {
|
||||||
use crate::poly::commitment::{Blind, Params};
|
use crate::poly::commitment::{Blind, Params};
|
||||||
use crate::transcript::DummyHash;
|
use crate::transcript::DummyHash;
|
||||||
use crate::tweedle::{EqAffine, Fp, Fq};
|
use crate::tweedle::{EqAffine, Fp, Fq};
|
||||||
use circuit::{Advice, Any, Column, Fixed};
|
use circuit::{Advice, Column, Fixed};
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
const K: u32 = 5;
|
const K: u32 = 5;
|
||||||
|
|
||||||
|
@ -354,11 +354,8 @@ fn test_proving() {
|
||||||
*
|
*
|
||||||
* ]
|
* ]
|
||||||
*/
|
*/
|
||||||
meta.lookup(&[Column::<Any>::from(a)], &[Column::<Any>::from(sl)]);
|
meta.lookup(&[a.into()], &[sl.into()]);
|
||||||
meta.lookup(
|
meta.lookup(&[a.into(), b.into()], &[sl.into(), sl2.into()]);
|
||||||
&[Column::<Any>::from(a), Column::<Any>::from(b)],
|
|
||||||
&[Column::<Any>::from(sl), Column::<Any>::from(sl2)],
|
|
||||||
);
|
|
||||||
|
|
||||||
meta.create_gate(|meta| {
|
meta.create_gate(|meta| {
|
||||||
let d = meta.query_advice(d, 1);
|
let d = meta.query_advice(d, 1);
|
||||||
|
|
|
@ -359,12 +359,13 @@ impl<F: Field> ConstraintSystem<F> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a lookup argument for some input columns and table columns.
|
/// 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(
|
pub fn lookup(
|
||||||
&mut self,
|
&mut self,
|
||||||
input_columns: &[Column<Any>],
|
input_columns: &[Column<Any>],
|
||||||
table_columns: &[Column<Any>],
|
table_columns: &[Column<Any>],
|
||||||
) -> usize {
|
) -> 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());
|
assert_eq!(input_columns.len(), table_columns.len());
|
||||||
|
|
||||||
let index = self.lookups.len();
|
let index = self.lookups.len();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use super::circuit::{Any, Column};
|
use super::circuit::{Any, Column};
|
||||||
use crate::arithmetic::CurveAffine;
|
use crate::arithmetic::CurveAffine;
|
||||||
|
|
||||||
pub(crate) mod prover;
|
mod prover;
|
||||||
mod verifier;
|
mod verifier;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
|
|
@ -233,44 +233,28 @@ impl<'a, C: CurveAffine> Permuted<'a, C> {
|
||||||
lookup_product.iter_mut().batch_invert();
|
lookup_product.iter_mut().batch_invert();
|
||||||
|
|
||||||
// Finish the computation of the entire fraction by computing the numerators
|
// 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)
|
// (\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)
|
||||||
// Compress unpermuted input columns
|
// * (\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)
|
||||||
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
|
|
||||||
parallelize(&mut lookup_product, |product, start| {
|
parallelize(&mut lookup_product, |product, start| {
|
||||||
for ((product, input_term), table_term) in product
|
for (i, product) in product.iter_mut().enumerate() {
|
||||||
.iter_mut()
|
let i = i + start;
|
||||||
.zip(input_term[start..].iter())
|
|
||||||
.zip(table_term[start..].iter())
|
// Compress unpermuted input columns
|
||||||
{
|
let mut input_term = C::Scalar::zero();
|
||||||
*product *= &(*input_term + &beta);
|
for unpermuted_input_column in self.unpermuted_input_columns.iter() {
|
||||||
*product *= &(*table_term + &gamma);
|
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)
|
// 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 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| {
|
parallelize(&mut right, |right, start| {
|
||||||
for ((right, input_term), table_term) in right
|
for (i, right) in right.iter_mut().enumerate() {
|
||||||
.iter_mut()
|
let i = i + start;
|
||||||
.zip(input_terms[start..].iter())
|
|
||||||
.zip(table_terms[start..].iter())
|
// Compress the unpermuted input columns
|
||||||
{
|
let mut input_term = C::Scalar::zero();
|
||||||
*right *= &(*input_term + &(*beta));
|
for input in permuted.unpermuted_input_cosets.iter() {
|
||||||
*right *= &(*table_term + &(*gamma));
|
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);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue