Remove redundant permutation_queries vector.

This commit is contained in:
Sean Bowe 2020-09-06 14:18:05 -06:00
parent eff149e734
commit 190242a4e9
No known key found for this signature in database
GPG key ID: 95684257D8F8B031
3 changed files with 22 additions and 25 deletions

View file

@ -163,13 +163,13 @@ pub struct MetaCircuit<F> {
pub(crate) rotations: BTreeMap<Rotation, PointIndex>,
// Vector of permutation arguments, where each corresponds to a set of wires
// that are involved in a permutation argument. As an example, we could have
// a permutation argument between wires (A, B, C) which allows copy
// constraints to be enforced between advice wire values in A, B and C, and
// another permutation between wires (B, C, D) which allows the same with D
// instead of A.
pub(crate) permutations: Vec<Vec<AdviceWire>>,
pub(crate) permutation_queries: Vec<Vec<usize>>,
// that are involved in a permutation argument, as well as the corresponding
// query index for each wire. As an example, we could have a permutation
// argument between wires (A, B, C) which allows copy constraints to be
// enforced between advice wire values in A, B and C, and another
// permutation between wires (B, C, D) which allows the same with D instead
// of A.
pub(crate) permutations: Vec<Vec<(AdviceWire, usize)>>,
}
impl<F: Field> Default for MetaCircuit<F> {
@ -185,7 +185,6 @@ impl<F: Field> Default for MetaCircuit<F> {
advice_queries: Vec::new(),
rotations,
permutations: Vec::new(),
permutation_queries: Vec::new(),
}
}
}
@ -199,13 +198,11 @@ impl<F: Field> MetaCircuit<F> {
let len = self.rotations.len();
self.rotations.entry(at).or_insert(PointIndex(len));
}
self.permutations.push(wires.to_vec());
let mut queries = vec![];
for wire in wires {
queries.push(self.query_advice_index(*wire, 0));
}
self.permutation_queries.push(queries);
let wires = wires
.iter()
.map(|&wire| (wire, self.query_advice_index(wire, 0)))
.collect();
self.permutations.push(wires);
index
}

View file

@ -142,7 +142,7 @@ impl<C: CurveAffine> Proof<C> {
let mut modified_advice = Vec::with_capacity(wires.len());
// Iterate over each wire of the permutation
for (wire, permuted_wire_values) in wires.iter().zip(permuted_values.iter()) {
for (&(wire, _), permuted_wire_values) in wires.iter().zip(permuted_values.iter()) {
// Grab the advice wire's values from the witness
let mut tmp_advice_values = witness.advice[wire.0].clone();
@ -179,7 +179,7 @@ impl<C: CurveAffine> Proof<C> {
// Iterate over each wire again, this time finishing the computation
// of the entire fraction by computing the numerators
let mut deltaomega = C::Scalar::one();
for (wire, modified_advice) in wires.iter().zip(modified_advice.iter_mut()) {
for (&(wire, _), modified_advice) in wires.iter().zip(modified_advice.iter_mut()) {
// For each row i, we compute
// p_j(\omega^i) + \delta^j \omega^i \beta + \gamma
// for the jth wire of the permutation
@ -319,7 +319,7 @@ impl<C: CurveAffine> Proof<C> {
}
// z(X) \prod (p(X) + \beta s_i(X) + \gamma) - z(omega^{-1} X) \prod (p(X) + \delta^i \beta X + \gamma)
for (permutation_index, wires) in srs.meta.permutation_queries.iter().enumerate() {
for (permutation_index, wires) in srs.meta.permutations.iter().enumerate() {
parallelize(&mut h_poly, |a, _| {
for a in a.iter_mut() {
*a *= &x_2;
@ -329,7 +329,7 @@ impl<C: CurveAffine> Proof<C> {
let mut left = permutation_product_cosets[permutation_index].clone();
for (advice, permutation) in wires
.iter()
.map(|&wire| &advice_cosets[wire])
.map(|&(_, index)| &advice_cosets[index])
.zip(srs.permutation_cosets[permutation_index].iter())
{
parallelize(&mut left, |left, start| {
@ -346,7 +346,7 @@ impl<C: CurveAffine> Proof<C> {
let mut right = permutation_product_cosets_inv[permutation_index].clone();
let mut current_delta = x_0 * &C::Scalar::ZETA;
let step = domain.get_extended_omega();
for advice in wires.iter().map(|&wire| &advice_cosets[wire]) {
for advice in wires.iter().map(|&(_, index)| &advice_cosets[index]) {
parallelize(&mut right, move |right, start| {
let mut beta_term = current_delta * &step.pow_vartime(&[start as u64, 0, 0, 0]);
for (right, advice) in right.iter_mut().zip(advice[start..].iter()) {

View file

@ -98,13 +98,13 @@ impl<C: CurveAffine> Proof<C> {
}
// z(X) \prod (p(X) + \beta s_i(X) + \gamma) - z(omega^{-1} X) \prod (p(X) + \delta^i \beta X + \gamma)
for (permutation_index, queries) in srs.meta.permutation_queries.iter().enumerate() {
for (permutation_index, wires) in srs.meta.permutations.iter().enumerate() {
h_eval *= &x_2;
let mut left = self.permutation_product_evals[permutation_index];
for (advice_eval, permutation_eval) in queries
for (advice_eval, permutation_eval) in wires
.iter()
.map(|&query_index| self.advice_evals[query_index])
.map(|&(_, query_index)| self.advice_evals[query_index])
.zip(self.permutation_evals[permutation_index].iter())
{
left *= &(advice_eval + &(x_0 * permutation_eval) + &x_1);
@ -112,9 +112,9 @@ impl<C: CurveAffine> Proof<C> {
let mut right = self.permutation_product_inv_evals[permutation_index];
let mut current_delta = x_0 * &x_3;
for advice_eval in queries
for advice_eval in wires
.iter()
.map(|&query_index| self.advice_evals[query_index])
.map(|&(_, query_index)| self.advice_evals[query_index])
{
right *= &(advice_eval + &current_delta + &x_1);
current_delta *= &C::Scalar::DELTA;