Correct privacy of lookup structs + minor cleanups

Co-authored-by: str4d <jack@electriccoin.co>
This commit is contained in:
ying tong 2020-12-04 09:18:28 +08:00 committed by therealyingtong
parent 2284bbd0d8
commit ecc805fa35
3 changed files with 46 additions and 66 deletions

View file

@ -1,5 +1,5 @@
use super::super::{ use super::super::{
circuit::{Advice, Any, Aux, Column, Fixed}, circuit::{Any, Column},
ChallengeBeta, ChallengeGamma, ChallengeTheta, ChallengeX, Error, ProvingKey, ChallengeBeta, ChallengeGamma, ChallengeTheta, ChallengeX, Error, ProvingKey,
}; };
use super::{Argument, Proof}; use super::{Argument, Proof};
@ -13,10 +13,10 @@ use crate::{
transcript::{Hasher, Transcript}, transcript::{Hasher, Transcript},
}; };
use ff::Field; use ff::Field;
use std::{collections::BTreeMap, convert::TryFrom, iter}; use std::{collections::BTreeMap, iter};
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct Permuted<'a, C: CurveAffine> { pub(in crate::plonk) struct Permuted<'a, C: CurveAffine> {
unpermuted_input_columns: Vec<&'a Polynomial<C::Scalar, LagrangeCoeff>>, unpermuted_input_columns: Vec<&'a Polynomial<C::Scalar, LagrangeCoeff>>,
unpermuted_input_cosets: Vec<&'a Polynomial<C::Scalar, ExtendedLagrangeCoeff>>, unpermuted_input_cosets: Vec<&'a Polynomial<C::Scalar, ExtendedLagrangeCoeff>>,
permuted_input_column: Polynomial<C::Scalar, LagrangeCoeff>, permuted_input_column: Polynomial<C::Scalar, LagrangeCoeff>,
@ -35,7 +35,7 @@ pub(crate) struct Permuted<'a, C: CurveAffine> {
} }
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct Committed<'a, C: CurveAffine> { pub(in crate::plonk) struct Committed<'a, C: CurveAffine> {
permuted: Permuted<'a, C>, permuted: Permuted<'a, C>,
product_poly: Polynomial<C::Scalar, Coeff>, product_poly: Polynomial<C::Scalar, Coeff>,
product_coset: Polynomial<C::Scalar, ExtendedLagrangeCoeff>, product_coset: Polynomial<C::Scalar, ExtendedLagrangeCoeff>,
@ -44,7 +44,7 @@ pub(crate) struct Committed<'a, C: CurveAffine> {
product_commitment: C, product_commitment: C,
} }
pub(crate) struct Constructed<C: CurveAffine> { pub(in crate::plonk) struct Constructed<C: CurveAffine> {
permuted_input_poly: Polynomial<C::Scalar, Coeff>, permuted_input_poly: Polynomial<C::Scalar, Coeff>,
permuted_input_blind: Blind<C::Scalar>, permuted_input_blind: Blind<C::Scalar>,
permuted_input_commitment: C, permuted_input_commitment: C,
@ -56,13 +56,13 @@ pub(crate) struct Constructed<C: CurveAffine> {
product_commitment: C, product_commitment: C,
} }
pub(crate) struct Evaluated<C: CurveAffine> { pub(in crate::plonk) struct Evaluated<C: CurveAffine> {
constructed: Constructed<C>, constructed: Constructed<C>,
pub product_eval: C::Scalar, product_eval: C::Scalar,
pub product_inv_eval: C::Scalar, product_inv_eval: C::Scalar,
pub permuted_input_eval: C::Scalar, permuted_input_eval: C::Scalar,
pub permuted_input_inv_eval: C::Scalar, permuted_input_inv_eval: C::Scalar,
pub permuted_table_eval: C::Scalar, permuted_table_eval: C::Scalar,
} }
impl Argument { impl Argument {
@ -99,28 +99,16 @@ impl Argument {
// Values of input columns involved in the lookup // Values of input columns involved in the lookup
let (unpermuted_columns, unpermuted_cosets): (Vec<_>, Vec<_>) = columns let (unpermuted_columns, unpermuted_cosets): (Vec<_>, Vec<_>) = columns
.iter() .iter()
.map(|&column| match column.column_type() { .map(|&column| {
Any::Advice => ( let (values, cosets) = match column.column_type() {
&advice_values[column.index()], Any::Advice => (advice_values, advice_cosets),
&advice_cosets[pk.vk.cs.get_advice_query_index( Any::Fixed => (fixed_values, fixed_cosets),
Column::<Advice>::try_from(column).unwrap(), Any::Aux => (aux_values, aux_cosets),
0, };
)], (
), &values[column.index()],
Any::Fixed => ( &cosets[pk.vk.cs.get_any_query_index(column, 0)],
&fixed_values[column.index()], )
&fixed_cosets[pk
.vk
.cs
.get_fixed_query_index(Column::<Fixed>::try_from(column).unwrap(), 0)],
),
Any::Aux => (
&aux_values[column.index()],
&aux_cosets[pk
.vk
.cs
.get_aux_query_index(Column::<Aux>::try_from(column).unwrap(), 0)],
),
}) })
.unzip(); .unzip();

View file

@ -1,6 +1,6 @@
use std::iter; use std::iter;
use super::super::circuit::Any; use super::super::circuit::{Any, Column};
use super::{Argument, Proof}; use super::{Argument, Proof};
use crate::{ use crate::{
arithmetic::CurveAffine, arithmetic::CurveAffine,
@ -11,7 +11,7 @@ use crate::{
use ff::Field; use ff::Field;
impl<C: CurveAffine> Proof<C> { impl<C: CurveAffine> Proof<C> {
pub(crate) fn absorb_permuted_commitments< pub(in crate::plonk) fn absorb_permuted_commitments<
HBase: Hasher<C::Base>, HBase: Hasher<C::Base>,
HScalar: Hasher<C::Scalar>, HScalar: Hasher<C::Scalar>,
>( >(
@ -26,7 +26,10 @@ impl<C: CurveAffine> Proof<C> {
.map_err(|_| Error::TranscriptError) .map_err(|_| Error::TranscriptError)
} }
pub(crate) fn absorb_product_commitment<HBase: Hasher<C::Base>, HScalar: Hasher<C::Scalar>>( pub(in crate::plonk) fn absorb_product_commitment<
HBase: Hasher<C::Base>,
HScalar: Hasher<C::Scalar>,
>(
&self, &self,
transcript: &mut Transcript<C, HBase, HScalar>, transcript: &mut Transcript<C, HBase, HScalar>,
) -> Result<(), Error> { ) -> Result<(), Error> {
@ -54,34 +57,23 @@ impl<C: CurveAffine> Proof<C> {
* &(self.permuted_input_eval + &beta) * &(self.permuted_input_eval + &beta)
* &(self.permuted_table_eval + &gamma); * &(self.permuted_table_eval + &gamma);
let mut right = self.product_inv_eval; let compress_columns = |columns: &[Column<Any>]| {
let mut input_term = C::Scalar::zero(); columns
for &input in argument.input_columns.iter() { .iter()
let index = vk.cs.get_any_query_index(input, 0); .map(|column| {
let eval = match input.column_type() { let index = vk.cs.get_any_query_index(*column, 0);
Any::Advice => advice_evals[index], match column.column_type() {
Any::Fixed => fixed_evals[index], Any::Advice => advice_evals[index],
Any::Aux => aux_evals[index], Any::Fixed => fixed_evals[index],
}; Any::Aux => aux_evals[index],
input_term *= &theta; }
input_term += &eval; })
} .fold(C::Scalar::zero(), |acc, eval| acc * &theta + &eval)
input_term += &beta; };
let right = self.product_inv_eval
* &(compress_columns(&argument.input_columns) + &beta)
* &(compress_columns(&argument.table_columns) + &gamma);
let mut table_term = C::Scalar::zero();
for &table in argument.table_columns.iter() {
let index = vk.cs.get_any_query_index(table, 0);
let eval = match table.column_type() {
Any::Advice => advice_evals[index],
Any::Fixed => fixed_evals[index],
Any::Aux => aux_evals[index],
};
table_term *= &theta;
table_term += &eval;
}
table_term += &gamma;
right *= &(input_term * &table_term);
left - &right left - &right
}; };
@ -106,7 +98,7 @@ impl<C: CurveAffine> Proof<C> {
)) ))
} }
pub(crate) fn evals(&self) -> impl Iterator<Item = &C::Scalar> { pub(in crate::plonk) fn evals(&self) -> impl Iterator<Item = &C::Scalar> {
iter::empty() iter::empty()
.chain(Some(&self.product_eval)) .chain(Some(&self.product_eval))
.chain(Some(&self.product_inv_eval)) .chain(Some(&self.product_inv_eval))

View file

@ -170,7 +170,7 @@ impl<C: CurveAffine> Proof<C> {
.collect(); .collect();
// Sample theta challenge for keeping lookup columns linearly independent // Sample theta challenge for keeping lookup columns linearly independent
let theta = ChallengeTheta::<C::Scalar>::get(&mut transcript); let theta = ChallengeTheta::get(&mut transcript);
// Construct and commit to permuted values for each lookup // Construct and commit to permuted values for each lookup
let lookups = pk let lookups = pk
@ -402,7 +402,7 @@ impl<C: CurveAffine> Proof<C> {
advice_commitments, advice_commitments,
h_commitments, h_commitments,
permutations: permutations.map(|p| p.build()), permutations: permutations.map(|p| p.build()),
lookups: lookups.into_iter().map(|p| p.build()).collect::<Vec<_>>(), lookups: lookups.into_iter().map(|p| p.build()).collect(),
advice_evals, advice_evals,
fixed_evals, fixed_evals,
aux_evals, aux_evals,