mirror of
https://github.com/saymrwulf/pasta_curves-source.git
synced 2026-09-04 20:03:39 +00:00
Correct privacy of lookup structs + minor cleanups
Co-authored-by: str4d <jack@electriccoin.co>
This commit is contained in:
parent
2284bbd0d8
commit
ecc805fa35
3 changed files with 46 additions and 66 deletions
|
|
@ -1,5 +1,5 @@
|
|||
use super::super::{
|
||||
circuit::{Advice, Any, Aux, Column, Fixed},
|
||||
circuit::{Any, Column},
|
||||
ChallengeBeta, ChallengeGamma, ChallengeTheta, ChallengeX, Error, ProvingKey,
|
||||
};
|
||||
use super::{Argument, Proof};
|
||||
|
|
@ -13,10 +13,10 @@ use crate::{
|
|||
transcript::{Hasher, Transcript},
|
||||
};
|
||||
use ff::Field;
|
||||
use std::{collections::BTreeMap, convert::TryFrom, iter};
|
||||
use std::{collections::BTreeMap, iter};
|
||||
|
||||
#[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_cosets: Vec<&'a Polynomial<C::Scalar, ExtendedLagrangeCoeff>>,
|
||||
permuted_input_column: Polynomial<C::Scalar, LagrangeCoeff>,
|
||||
|
|
@ -35,7 +35,7 @@ pub(crate) struct Permuted<'a, C: CurveAffine> {
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct Committed<'a, C: CurveAffine> {
|
||||
pub(in crate::plonk) struct Committed<'a, C: CurveAffine> {
|
||||
permuted: Permuted<'a, C>,
|
||||
product_poly: Polynomial<C::Scalar, Coeff>,
|
||||
product_coset: Polynomial<C::Scalar, ExtendedLagrangeCoeff>,
|
||||
|
|
@ -44,7 +44,7 @@ pub(crate) struct Committed<'a, C: CurveAffine> {
|
|||
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_blind: Blind<C::Scalar>,
|
||||
permuted_input_commitment: C,
|
||||
|
|
@ -56,13 +56,13 @@ pub(crate) struct Constructed<C: CurveAffine> {
|
|||
product_commitment: C,
|
||||
}
|
||||
|
||||
pub(crate) struct Evaluated<C: CurveAffine> {
|
||||
pub(in crate::plonk) struct Evaluated<C: CurveAffine> {
|
||||
constructed: Constructed<C>,
|
||||
pub product_eval: C::Scalar,
|
||||
pub product_inv_eval: C::Scalar,
|
||||
pub permuted_input_eval: C::Scalar,
|
||||
pub permuted_input_inv_eval: C::Scalar,
|
||||
pub permuted_table_eval: C::Scalar,
|
||||
product_eval: C::Scalar,
|
||||
product_inv_eval: C::Scalar,
|
||||
permuted_input_eval: C::Scalar,
|
||||
permuted_input_inv_eval: C::Scalar,
|
||||
permuted_table_eval: C::Scalar,
|
||||
}
|
||||
|
||||
impl Argument {
|
||||
|
|
@ -99,28 +99,16 @@ impl Argument {
|
|||
// Values of input columns involved in the lookup
|
||||
let (unpermuted_columns, unpermuted_cosets): (Vec<_>, Vec<_>) = columns
|
||||
.iter()
|
||||
.map(|&column| match column.column_type() {
|
||||
Any::Advice => (
|
||||
&advice_values[column.index()],
|
||||
&advice_cosets[pk.vk.cs.get_advice_query_index(
|
||||
Column::<Advice>::try_from(column).unwrap(),
|
||||
0,
|
||||
)],
|
||||
),
|
||||
Any::Fixed => (
|
||||
&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)],
|
||||
),
|
||||
.map(|&column| {
|
||||
let (values, cosets) = match column.column_type() {
|
||||
Any::Advice => (advice_values, advice_cosets),
|
||||
Any::Fixed => (fixed_values, fixed_cosets),
|
||||
Any::Aux => (aux_values, aux_cosets),
|
||||
};
|
||||
(
|
||||
&values[column.index()],
|
||||
&cosets[pk.vk.cs.get_any_query_index(column, 0)],
|
||||
)
|
||||
})
|
||||
.unzip();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use std::iter;
|
||||
|
||||
use super::super::circuit::Any;
|
||||
use super::super::circuit::{Any, Column};
|
||||
use super::{Argument, Proof};
|
||||
use crate::{
|
||||
arithmetic::CurveAffine,
|
||||
|
|
@ -11,7 +11,7 @@ use crate::{
|
|||
use ff::Field;
|
||||
|
||||
impl<C: CurveAffine> Proof<C> {
|
||||
pub(crate) fn absorb_permuted_commitments<
|
||||
pub(in crate::plonk) fn absorb_permuted_commitments<
|
||||
HBase: Hasher<C::Base>,
|
||||
HScalar: Hasher<C::Scalar>,
|
||||
>(
|
||||
|
|
@ -26,7 +26,10 @@ impl<C: CurveAffine> Proof<C> {
|
|||
.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,
|
||||
transcript: &mut Transcript<C, HBase, HScalar>,
|
||||
) -> Result<(), Error> {
|
||||
|
|
@ -54,34 +57,23 @@ impl<C: CurveAffine> Proof<C> {
|
|||
* &(self.permuted_input_eval + &beta)
|
||||
* &(self.permuted_table_eval + &gamma);
|
||||
|
||||
let mut right = self.product_inv_eval;
|
||||
let mut input_term = C::Scalar::zero();
|
||||
for &input in argument.input_columns.iter() {
|
||||
let index = vk.cs.get_any_query_index(input, 0);
|
||||
let eval = match input.column_type() {
|
||||
Any::Advice => advice_evals[index],
|
||||
Any::Fixed => fixed_evals[index],
|
||||
Any::Aux => aux_evals[index],
|
||||
};
|
||||
input_term *= θ
|
||||
input_term += &eval;
|
||||
}
|
||||
input_term += β
|
||||
let compress_columns = |columns: &[Column<Any>]| {
|
||||
columns
|
||||
.iter()
|
||||
.map(|column| {
|
||||
let index = vk.cs.get_any_query_index(*column, 0);
|
||||
match column.column_type() {
|
||||
Any::Advice => advice_evals[index],
|
||||
Any::Fixed => fixed_evals[index],
|
||||
Any::Aux => aux_evals[index],
|
||||
}
|
||||
})
|
||||
.fold(C::Scalar::zero(), |acc, eval| acc * &theta + &eval)
|
||||
};
|
||||
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 *= θ
|
||||
table_term += &eval;
|
||||
}
|
||||
table_term += γ
|
||||
|
||||
right *= &(input_term * &table_term);
|
||||
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()
|
||||
.chain(Some(&self.product_eval))
|
||||
.chain(Some(&self.product_inv_eval))
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ impl<C: CurveAffine> Proof<C> {
|
|||
.collect();
|
||||
|
||||
// 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
|
||||
let lookups = pk
|
||||
|
|
@ -402,7 +402,7 @@ impl<C: CurveAffine> Proof<C> {
|
|||
advice_commitments,
|
||||
h_commitments,
|
||||
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,
|
||||
fixed_evals,
|
||||
aux_evals,
|
||||
|
|
|
|||
Loading…
Reference in a new issue