2021-09-30 14:35:33 -07:00
|
|
|
use group::{
|
|
|
|
ff::{BatchInvert, Field},
|
|
|
|
Curve,
|
|
|
|
};
|
2021-12-25 05:36:41 -08:00
|
|
|
use rand::RngCore;
|
2021-07-02 15:20:36 -07:00
|
|
|
use std::iter::{self, ExactSizeIterator};
|
2020-11-24 16:49:52 -08:00
|
|
|
|
2021-04-12 23:47:25 -07:00
|
|
|
use super::super::{circuit::Any, ChallengeBeta, ChallengeGamma, ChallengeX};
|
2020-12-23 12:03:31 -08:00
|
|
|
use super::{Argument, ProvingKey};
|
2020-11-24 16:49:52 -08:00
|
|
|
use crate::{
|
2021-09-30 14:35:33 -07:00
|
|
|
arithmetic::{eval_polynomial, parallelize, CurveAffine, FieldExt},
|
2021-04-12 23:47:25 -07:00
|
|
|
plonk::{self, Error},
|
2020-11-24 16:49:52 -08:00
|
|
|
poly::{
|
|
|
|
commitment::{Blind, Params},
|
|
|
|
multiopen::ProverQuery,
|
|
|
|
Coeff, ExtendedLagrangeCoeff, LagrangeCoeff, Polynomial, Rotation,
|
|
|
|
},
|
2021-04-30 18:28:50 -07:00
|
|
|
transcript::{EncodedChallenge, TranscriptWrite},
|
2020-11-24 16:49:52 -08:00
|
|
|
};
|
|
|
|
|
2021-07-02 15:20:36 -07:00
|
|
|
pub struct CommittedSet<C: CurveAffine> {
|
2020-12-22 15:51:32 -08:00
|
|
|
permutation_product_poly: Polynomial<C::Scalar, Coeff>,
|
|
|
|
permutation_product_coset: Polynomial<C::Scalar, ExtendedLagrangeCoeff>,
|
|
|
|
permutation_product_blind: Blind<C::Scalar>,
|
2020-11-24 16:49:52 -08:00
|
|
|
}
|
|
|
|
|
2021-07-02 15:20:36 -07:00
|
|
|
pub(crate) struct Committed<C: CurveAffine> {
|
|
|
|
sets: Vec<CommittedSet<C>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct ConstructedSet<C: CurveAffine> {
|
2020-12-22 15:51:32 -08:00
|
|
|
permutation_product_poly: Polynomial<C::Scalar, Coeff>,
|
|
|
|
permutation_product_blind: Blind<C::Scalar>,
|
2020-11-24 16:49:52 -08:00
|
|
|
}
|
|
|
|
|
2021-07-02 15:20:36 -07:00
|
|
|
pub(crate) struct Constructed<C: CurveAffine> {
|
|
|
|
sets: Vec<ConstructedSet<C>>,
|
|
|
|
}
|
|
|
|
|
2020-11-24 16:49:52 -08:00
|
|
|
pub(crate) struct Evaluated<C: CurveAffine> {
|
|
|
|
constructed: Constructed<C>,
|
|
|
|
}
|
|
|
|
|
2020-12-01 06:16:31 -08:00
|
|
|
impl Argument {
|
2021-04-12 23:47:25 -07:00
|
|
|
pub(in crate::plonk) fn commit<
|
|
|
|
C: CurveAffine,
|
2021-05-07 07:21:54 -07:00
|
|
|
E: EncodedChallenge<C>,
|
2021-12-25 05:36:41 -08:00
|
|
|
R: RngCore,
|
2021-05-07 07:21:54 -07:00
|
|
|
T: TranscriptWrite<C, E>,
|
2021-04-12 23:47:25 -07:00
|
|
|
>(
|
2020-12-22 15:51:32 -08:00
|
|
|
&self,
|
2020-11-24 16:49:52 -08:00
|
|
|
params: &Params<C>,
|
2020-12-22 15:51:32 -08:00
|
|
|
pk: &plonk::ProvingKey<C>,
|
|
|
|
pkey: &ProvingKey<C>,
|
2020-11-24 16:49:52 -08:00
|
|
|
advice: &[Polynomial<C::Scalar, LagrangeCoeff>],
|
2021-02-17 05:13:25 -08:00
|
|
|
fixed: &[Polynomial<C::Scalar, LagrangeCoeff>],
|
|
|
|
instance: &[Polynomial<C::Scalar, LagrangeCoeff>],
|
2020-12-23 12:03:31 -08:00
|
|
|
beta: ChallengeBeta<C>,
|
|
|
|
gamma: ChallengeGamma<C>,
|
2021-12-25 05:36:41 -08:00
|
|
|
mut rng: R,
|
2020-12-23 12:03:31 -08:00
|
|
|
transcript: &mut T,
|
2020-11-24 16:49:52 -08:00
|
|
|
) -> Result<Committed<C>, Error> {
|
|
|
|
let domain = &pk.vk.domain;
|
|
|
|
|
2021-07-02 15:20:36 -07:00
|
|
|
// How many columns can be included in a single permutation polynomial?
|
2021-07-09 08:18:45 -07:00
|
|
|
// We need to multiply by z(X) and (1 - (l_last(X) + l_blind(X))). This
|
2021-07-02 15:20:36 -07:00
|
|
|
// will never underflow because of the requirement of at least a degree
|
|
|
|
// 3 circuit for the permutation argument.
|
2021-07-10 07:12:08 -07:00
|
|
|
assert!(pk.vk.cs.degree() >= 3);
|
2021-07-02 15:20:36 -07:00
|
|
|
let chunk_len = pk.vk.cs.degree() - 2;
|
|
|
|
let blinding_factors = pk.vk.cs.blinding_factors();
|
2020-12-22 15:51:32 -08:00
|
|
|
|
2021-07-02 15:20:36 -07:00
|
|
|
// Each column gets its own delta power.
|
2020-12-22 15:51:32 -08:00
|
|
|
let mut deltaomega = C::Scalar::one();
|
|
|
|
|
2021-07-02 15:20:36 -07:00
|
|
|
// Track the "last" value from the previous column set
|
|
|
|
let mut last_z = C::Scalar::one();
|
|
|
|
|
|
|
|
let mut sets = vec![];
|
|
|
|
|
2021-07-13 09:11:38 -07:00
|
|
|
for (columns, permutations) in self
|
2021-07-02 15:20:36 -07:00
|
|
|
.columns
|
|
|
|
.chunks(chunk_len)
|
2021-07-13 09:11:38 -07:00
|
|
|
.zip(pkey.permutations.chunks(chunk_len))
|
|
|
|
{
|
2021-07-02 15:20:36 -07:00
|
|
|
// Goal is to compute the products of fractions
|
|
|
|
//
|
|
|
|
// (p_j(\omega^i) + \delta^j \omega^i \beta + \gamma) /
|
|
|
|
// (p_j(\omega^i) + \beta s_j(\omega^i) + \gamma)
|
|
|
|
//
|
|
|
|
// where p_j(X) is the jth column in this permutation,
|
|
|
|
// and i is the ith row of the column.
|
|
|
|
|
|
|
|
let mut modified_values = vec![C::Scalar::one(); params.n as usize];
|
|
|
|
|
|
|
|
// Iterate over each column of the permutation
|
|
|
|
for (&column, permuted_column_values) in columns.iter().zip(permutations.iter()) {
|
|
|
|
let values = match column.column_type() {
|
|
|
|
Any::Advice => advice,
|
|
|
|
Any::Fixed => fixed,
|
|
|
|
Any::Instance => instance,
|
|
|
|
};
|
|
|
|
parallelize(&mut modified_values, |modified_values, start| {
|
|
|
|
for ((modified_values, value), permuted_value) in modified_values
|
|
|
|
.iter_mut()
|
|
|
|
.zip(values[column.index()][start..].iter())
|
|
|
|
.zip(permuted_column_values[start..].iter())
|
|
|
|
{
|
|
|
|
*modified_values *= &(*beta * permuted_value + &*gamma + value);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Invert to obtain the denominator for the permutation product polynomial
|
|
|
|
modified_values.batch_invert();
|
|
|
|
|
|
|
|
// Iterate over each column again, this time finishing the computation
|
|
|
|
// of the entire fraction by computing the numerators
|
|
|
|
for &column in columns.iter() {
|
|
|
|
let omega = domain.get_omega();
|
|
|
|
let values = match column.column_type() {
|
|
|
|
Any::Advice => advice,
|
|
|
|
Any::Fixed => fixed,
|
|
|
|
Any::Instance => instance,
|
|
|
|
};
|
|
|
|
parallelize(&mut modified_values, |modified_values, start| {
|
|
|
|
let mut deltaomega = deltaomega * &omega.pow_vartime(&[start as u64, 0, 0, 0]);
|
|
|
|
for (modified_values, value) in modified_values
|
|
|
|
.iter_mut()
|
|
|
|
.zip(values[column.index()][start..].iter())
|
|
|
|
{
|
|
|
|
// Multiply by p_j(\omega^i) + \delta^j \omega^i \beta
|
|
|
|
*modified_values *= &(deltaomega * &*beta + &*gamma + value);
|
|
|
|
deltaomega *= ω
|
|
|
|
}
|
|
|
|
});
|
|
|
|
deltaomega *= &C::Scalar::DELTA;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The modified_values vector is a vector of products of fractions
|
|
|
|
// of the form
|
|
|
|
//
|
|
|
|
// (p_j(\omega^i) + \delta^j \omega^i \beta + \gamma) /
|
|
|
|
// (p_j(\omega^i) + \beta s_j(\omega^i) + \gamma)
|
|
|
|
//
|
|
|
|
// where i is the index into modified_values, for the jth column in
|
|
|
|
// the permutation
|
|
|
|
|
|
|
|
// Compute the evaluations of the permutation product polynomial
|
|
|
|
// over our domain, starting with z[0] = 1
|
|
|
|
let mut z = vec![last_z];
|
|
|
|
for row in 1..(params.n as usize) {
|
|
|
|
let mut tmp = z[row - 1];
|
|
|
|
|
|
|
|
tmp *= &modified_values[row - 1];
|
|
|
|
z.push(tmp);
|
|
|
|
}
|
|
|
|
let mut z = domain.lagrange_from_vec(z);
|
|
|
|
// Set blinding factors
|
|
|
|
for z in &mut z[params.n as usize - blinding_factors..] {
|
2021-12-25 05:36:41 -08:00
|
|
|
*z = C::Scalar::random(&mut rng);
|
2021-07-02 15:20:36 -07:00
|
|
|
}
|
|
|
|
// Set new last_z
|
|
|
|
last_z = z[params.n as usize - (blinding_factors + 1)];
|
|
|
|
|
2021-12-25 05:36:41 -08:00
|
|
|
let blind = Blind(C::Scalar::random(&mut rng));
|
2021-07-02 15:20:36 -07:00
|
|
|
|
|
|
|
let permutation_product_commitment_projective = params.commit_lagrange(&z, blind);
|
|
|
|
let permutation_product_blind = blind;
|
|
|
|
let z = domain.lagrange_to_coeff(z);
|
|
|
|
let permutation_product_poly = z.clone();
|
|
|
|
|
2021-07-12 11:57:09 -07:00
|
|
|
let permutation_product_coset = domain.coeff_to_extended(z.clone());
|
2020-12-22 15:51:32 -08:00
|
|
|
|
2021-07-02 15:20:36 -07:00
|
|
|
let permutation_product_commitment =
|
|
|
|
permutation_product_commitment_projective.to_affine();
|
2020-12-22 15:51:32 -08:00
|
|
|
|
2021-07-02 15:20:36 -07:00
|
|
|
// Hash the permutation product commitment
|
2021-05-26 14:28:11 -07:00
|
|
|
transcript.write_point(permutation_product_commitment)?;
|
2020-12-22 15:51:32 -08:00
|
|
|
|
2021-07-02 15:20:36 -07:00
|
|
|
sets.push(CommittedSet {
|
|
|
|
permutation_product_poly,
|
|
|
|
permutation_product_coset,
|
|
|
|
permutation_product_blind,
|
|
|
|
});
|
|
|
|
}
|
2020-11-24 16:49:52 -08:00
|
|
|
|
2021-07-02 15:20:36 -07:00
|
|
|
Ok(Committed { sets })
|
2020-11-24 16:49:52 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<C: CurveAffine> Committed<C> {
|
2020-12-01 13:14:14 -08:00
|
|
|
pub(in crate::plonk) fn construct<'a>(
|
2020-11-24 16:49:52 -08:00
|
|
|
self,
|
2020-12-22 15:51:32 -08:00
|
|
|
pk: &'a plonk::ProvingKey<C>,
|
|
|
|
p: &'a Argument,
|
|
|
|
pkey: &'a ProvingKey<C>,
|
2020-11-24 16:49:52 -08:00
|
|
|
advice_cosets: &'a [Polynomial<C::Scalar, ExtendedLagrangeCoeff>],
|
2021-02-17 05:13:25 -08:00
|
|
|
fixed_cosets: &'a [Polynomial<C::Scalar, ExtendedLagrangeCoeff>],
|
|
|
|
instance_cosets: &'a [Polynomial<C::Scalar, ExtendedLagrangeCoeff>],
|
2020-12-23 12:03:31 -08:00
|
|
|
beta: ChallengeBeta<C>,
|
|
|
|
gamma: ChallengeGamma<C>,
|
2021-01-14 05:29:19 -08:00
|
|
|
) -> (
|
|
|
|
Constructed<C>,
|
|
|
|
impl Iterator<Item = Polynomial<C::Scalar, ExtendedLagrangeCoeff>> + 'a,
|
|
|
|
) {
|
2020-11-24 16:49:52 -08:00
|
|
|
let domain = &pk.vk.domain;
|
2021-07-02 15:20:36 -07:00
|
|
|
let chunk_len = pk.vk.cs.degree() - 2;
|
2021-07-12 11:53:12 -07:00
|
|
|
let blinding_factors = pk.vk.cs.blinding_factors();
|
|
|
|
let last_rotation = Rotation(-((blinding_factors + 1) as i32));
|
2021-07-02 15:20:36 -07:00
|
|
|
|
|
|
|
let constructed = Constructed {
|
|
|
|
sets: self
|
|
|
|
.sets
|
|
|
|
.iter()
|
|
|
|
.map(|set| ConstructedSet {
|
|
|
|
permutation_product_poly: set.permutation_product_poly.clone(),
|
|
|
|
permutation_product_blind: set.permutation_product_blind,
|
|
|
|
})
|
|
|
|
.collect(),
|
|
|
|
};
|
|
|
|
|
2020-11-24 16:49:52 -08:00
|
|
|
let expressions = iter::empty()
|
2021-07-02 15:20:36 -07:00
|
|
|
// Enforce only for the first set.
|
|
|
|
// l_0(X) * (1 - z_0(X)) = 0
|
|
|
|
.chain(self.sets.first().map(|first_set| {
|
|
|
|
Polynomial::one_minus(first_set.permutation_product_coset.clone()) * &pk.l0
|
|
|
|
}))
|
|
|
|
// Enforce only for the last set.
|
|
|
|
// l_last(X) * (z_l(X)^2 - z_l(X)) = 0
|
|
|
|
.chain(self.sets.last().map(|last_set| {
|
|
|
|
((last_set.permutation_product_coset.clone() * &last_set.permutation_product_coset)
|
|
|
|
- &last_set.permutation_product_coset)
|
|
|
|
* &pk.l_last
|
|
|
|
}))
|
|
|
|
// Except for the first set, enforce.
|
|
|
|
// l_0(X) * (z_i(X) - z_{i-1}(\omega^(last) X)) = 0
|
|
|
|
.chain(
|
|
|
|
self.sets
|
2020-11-30 18:09:03 -08:00
|
|
|
.iter()
|
2021-07-02 15:20:36 -07:00
|
|
|
.skip(1)
|
|
|
|
.zip(self.sets.iter())
|
|
|
|
.map(|(set, last_set)| {
|
2021-07-12 11:53:12 -07:00
|
|
|
domain.sub_extended(
|
|
|
|
set.permutation_product_coset.clone(),
|
|
|
|
&last_set.permutation_product_coset,
|
|
|
|
last_rotation,
|
|
|
|
) * &pk.l0
|
2020-12-23 08:45:16 -08:00
|
|
|
})
|
2021-07-10 07:12:08 -07:00
|
|
|
.collect::<Vec<_>>(),
|
2021-07-02 15:20:36 -07:00
|
|
|
)
|
|
|
|
// And for all the sets we enforce:
|
2021-07-13 15:30:52 -07:00
|
|
|
// (1 - (l_last(X) + l_blind(X))) * (
|
2021-07-10 07:12:08 -07:00
|
|
|
// z_i(\omega X) \prod_j (p(X) + \beta s_j(X) + \gamma)
|
|
|
|
// - z_i(X) \prod_j (p(X) + \delta^j \beta X + \gamma)
|
2021-07-02 15:20:36 -07:00
|
|
|
// )
|
|
|
|
.chain(
|
|
|
|
self.sets
|
|
|
|
.into_iter()
|
|
|
|
.zip(p.columns.chunks(chunk_len))
|
|
|
|
.zip(pkey.cosets.chunks(chunk_len))
|
|
|
|
.enumerate()
|
|
|
|
.map(move |(chunk_index, ((set, columns), cosets))| {
|
2021-07-12 11:53:12 -07:00
|
|
|
let mut left = domain
|
|
|
|
.rotate_extended(&set.permutation_product_coset, Rotation::next());
|
2021-07-02 15:20:36 -07:00
|
|
|
for (values, permutation) in columns
|
|
|
|
.iter()
|
|
|
|
.map(|&column| match column.column_type() {
|
2021-07-12 11:53:12 -07:00
|
|
|
Any::Advice => &advice_cosets[column.index()],
|
|
|
|
Any::Fixed => &fixed_cosets[column.index()],
|
|
|
|
Any::Instance => &instance_cosets[column.index()],
|
2021-07-02 15:20:36 -07:00
|
|
|
})
|
|
|
|
.zip(cosets.iter())
|
2020-11-30 18:09:03 -08:00
|
|
|
{
|
2021-07-02 15:20:36 -07:00
|
|
|
parallelize(&mut left, |left, start| {
|
|
|
|
for ((left, value), permutation) in left
|
|
|
|
.iter_mut()
|
|
|
|
.zip(values[start..].iter())
|
|
|
|
.zip(permutation[start..].iter())
|
|
|
|
{
|
|
|
|
*left *= &(*value + &(*beta * permutation) + &*gamma);
|
|
|
|
}
|
|
|
|
});
|
2020-11-30 18:09:03 -08:00
|
|
|
}
|
2020-11-24 16:49:52 -08:00
|
|
|
|
2021-07-02 15:33:22 -07:00
|
|
|
let mut right = set.permutation_product_coset;
|
2021-07-02 15:20:36 -07:00
|
|
|
let mut current_delta = *beta
|
|
|
|
* &C::Scalar::ZETA
|
|
|
|
* &(C::Scalar::DELTA.pow_vartime(&[(chunk_index * chunk_len) as u64]));
|
|
|
|
let step = domain.get_extended_omega();
|
|
|
|
for values in columns.iter().map(|&column| match column.column_type() {
|
2021-07-12 11:53:12 -07:00
|
|
|
Any::Advice => &advice_cosets[column.index()],
|
|
|
|
Any::Fixed => &fixed_cosets[column.index()],
|
|
|
|
Any::Instance => &instance_cosets[column.index()],
|
2021-07-02 15:20:36 -07:00
|
|
|
}) {
|
|
|
|
parallelize(&mut right, move |right, start| {
|
|
|
|
let mut beta_term =
|
|
|
|
current_delta * &step.pow_vartime(&[start as u64, 0, 0, 0]);
|
|
|
|
for (right, value) in right.iter_mut().zip(values[start..].iter()) {
|
|
|
|
*right *= &(*value + &beta_term + &*gamma);
|
|
|
|
beta_term *= &step;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
current_delta *= &C::Scalar::DELTA;
|
2020-11-30 18:09:03 -08:00
|
|
|
}
|
2020-11-24 16:49:52 -08:00
|
|
|
|
2021-07-09 08:18:45 -07:00
|
|
|
(left - &right) * &Polynomial::one_minus(pk.l_last.clone() + &pk.l_blind)
|
2021-07-02 15:20:36 -07:00
|
|
|
}),
|
|
|
|
);
|
2020-11-24 16:49:52 -08:00
|
|
|
|
2021-07-02 15:20:36 -07:00
|
|
|
(constructed, expressions)
|
2020-11-24 16:49:52 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-30 18:09:03 -08:00
|
|
|
impl<C: CurveAffine> super::ProvingKey<C> {
|
2021-07-15 13:30:52 -07:00
|
|
|
pub(in crate::plonk) fn open(
|
|
|
|
&self,
|
|
|
|
x: ChallengeX<C>,
|
|
|
|
) -> impl Iterator<Item = ProverQuery<'_, C>> + Clone {
|
2021-01-13 16:22:32 -08:00
|
|
|
self.polys.iter().map(move |poly| ProverQuery {
|
|
|
|
point: *x,
|
|
|
|
poly,
|
|
|
|
blind: Blind::default(),
|
|
|
|
})
|
2020-11-30 18:09:03 -08:00
|
|
|
}
|
2021-07-15 13:30:52 -07:00
|
|
|
|
|
|
|
pub(in crate::plonk) fn evaluate<E: EncodedChallenge<C>, T: TranscriptWrite<C, E>>(
|
|
|
|
&self,
|
|
|
|
x: ChallengeX<C>,
|
|
|
|
transcript: &mut T,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
// Hash permutation evals
|
|
|
|
for eval in self.polys.iter().map(|poly| eval_polynomial(poly, *x)) {
|
2021-05-26 14:28:11 -07:00
|
|
|
transcript.write_scalar(eval)?;
|
2021-07-15 13:30:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2020-11-30 18:09:03 -08:00
|
|
|
}
|
|
|
|
|
2020-11-24 16:49:52 -08:00
|
|
|
impl<C: CurveAffine> Constructed<C> {
|
2021-05-07 07:21:54 -07:00
|
|
|
pub(in crate::plonk) fn evaluate<E: EncodedChallenge<C>, T: TranscriptWrite<C, E>>(
|
2020-11-24 16:49:52 -08:00
|
|
|
self,
|
2020-12-22 15:51:32 -08:00
|
|
|
pk: &plonk::ProvingKey<C>,
|
2020-12-23 12:03:31 -08:00
|
|
|
x: ChallengeX<C>,
|
|
|
|
transcript: &mut T,
|
|
|
|
) -> Result<Evaluated<C>, Error> {
|
2020-11-24 16:49:52 -08:00
|
|
|
let domain = &pk.vk.domain;
|
2021-07-02 15:20:36 -07:00
|
|
|
let blinding_factors = pk.vk.cs.blinding_factors();
|
2020-11-24 16:49:52 -08:00
|
|
|
|
2021-07-02 15:20:36 -07:00
|
|
|
{
|
|
|
|
let mut sets = self.sets.iter();
|
|
|
|
|
|
|
|
while let Some(set) = sets.next() {
|
|
|
|
let permutation_product_eval = eval_polynomial(&set.permutation_product_poly, *x);
|
|
|
|
|
|
|
|
let permutation_product_next_eval = eval_polynomial(
|
|
|
|
&set.permutation_product_poly,
|
|
|
|
domain.rotate_omega(*x, Rotation::next()),
|
|
|
|
);
|
|
|
|
|
|
|
|
// Hash permutation product evals
|
|
|
|
for eval in iter::empty()
|
|
|
|
.chain(Some(&permutation_product_eval))
|
|
|
|
.chain(Some(&permutation_product_next_eval))
|
|
|
|
{
|
2021-05-26 14:28:11 -07:00
|
|
|
transcript.write_scalar(*eval)?;
|
2021-07-02 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
2021-07-14 09:08:49 -07:00
|
|
|
// If we have any remaining sets to process, evaluate this set at omega^u
|
|
|
|
// so we can constrain the last value of its running product to equal the
|
|
|
|
// first value of the next set's running product, chaining them together.
|
2021-07-02 15:20:36 -07:00
|
|
|
if sets.len() > 0 {
|
|
|
|
let permutation_product_last_eval = eval_polynomial(
|
|
|
|
&set.permutation_product_poly,
|
|
|
|
domain.rotate_omega(*x, Rotation(-((blinding_factors + 1) as i32))),
|
|
|
|
);
|
|
|
|
|
2021-05-26 14:28:11 -07:00
|
|
|
transcript.write_scalar(permutation_product_last_eval)?;
|
2021-07-02 15:20:36 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-13 16:22:32 -08:00
|
|
|
Ok(Evaluated { constructed: self })
|
2020-11-24 16:49:52 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<C: CurveAffine> Evaluated<C> {
|
2020-12-01 13:14:14 -08:00
|
|
|
pub(in crate::plonk) fn open<'a>(
|
2020-11-24 16:49:52 -08:00
|
|
|
&'a self,
|
2020-12-22 15:51:32 -08:00
|
|
|
pk: &'a plonk::ProvingKey<C>,
|
2020-12-23 12:03:31 -08:00
|
|
|
x: ChallengeX<C>,
|
2020-11-24 16:49:52 -08:00
|
|
|
) -> impl Iterator<Item = ProverQuery<'a, C>> + Clone {
|
2021-07-02 15:20:36 -07:00
|
|
|
let blinding_factors = pk.vk.cs.blinding_factors();
|
2021-03-04 09:34:56 -08:00
|
|
|
let x_next = pk.vk.domain.rotate_omega(*x, Rotation::next());
|
2021-07-02 15:20:36 -07:00
|
|
|
let x_last = pk
|
|
|
|
.vk
|
|
|
|
.domain
|
|
|
|
.rotate_omega(*x, Rotation(-((blinding_factors + 1) as i32)));
|
2020-11-24 16:49:52 -08:00
|
|
|
|
|
|
|
iter::empty()
|
2021-07-02 15:20:36 -07:00
|
|
|
.chain(self.constructed.sets.iter().flat_map(move |set| {
|
|
|
|
iter::empty()
|
2021-07-14 08:48:56 -07:00
|
|
|
// Open permutation product commitments at x and \omega x
|
2021-07-02 15:20:36 -07:00
|
|
|
.chain(Some(ProverQuery {
|
|
|
|
point: *x,
|
|
|
|
poly: &set.permutation_product_poly,
|
|
|
|
blind: set.permutation_product_blind,
|
|
|
|
}))
|
|
|
|
.chain(Some(ProverQuery {
|
|
|
|
point: x_next,
|
|
|
|
poly: &set.permutation_product_poly,
|
|
|
|
blind: set.permutation_product_blind,
|
|
|
|
}))
|
2020-12-22 15:51:32 -08:00
|
|
|
}))
|
2021-07-14 09:17:44 -07:00
|
|
|
// Open it at \omega^{last} x for all but the last set. This rotation is only
|
|
|
|
// sensical for the first row, but we only use this rotation in a constraint
|
|
|
|
// that is gated on l_0.
|
2021-07-02 15:20:36 -07:00
|
|
|
.chain(
|
|
|
|
self.constructed
|
|
|
|
.sets
|
|
|
|
.iter()
|
|
|
|
.rev()
|
|
|
|
.skip(1)
|
|
|
|
.flat_map(move |set| {
|
|
|
|
Some(ProverQuery {
|
|
|
|
point: x_last,
|
|
|
|
poly: &set.permutation_product_poly,
|
|
|
|
blind: set.permutation_product_blind,
|
|
|
|
})
|
|
|
|
}),
|
|
|
|
)
|
2020-11-24 16:49:52 -08:00
|
|
|
}
|
|
|
|
}
|