Allocate permutation_modified_advice once in Proof::create

This commit is contained in:
Jack Grigg 2020-10-21 16:02:25 +01:00
parent cc5f45231d
commit feba8e2fdf
1 changed files with 26 additions and 17 deletions

View File

@ -182,8 +182,12 @@ impl<C: CurveAffine> Proof<C> {
let mut permutation_product_blinds = vec![]; let mut permutation_product_blinds = vec![];
// Iterate over each permutation // Iterate over each permutation
let mut permutation_modified_advice = vec![]; let mut permutation_modified_advice = pk
for (columns, permuted_values) in pk.vk.cs.permutations.iter().zip(pk.permutations.iter()) { .vk
.cs
.permutations
.iter()
.zip(pk.permutations.iter())
// Goal is to compute the products of fractions // Goal is to compute the products of fractions
// //
// (p_j(\omega^i) + \delta^j \omega^i \beta + \gamma) / // (p_j(\omega^i) + \delta^j \omega^i \beta + \gamma) /
@ -191,23 +195,28 @@ impl<C: CurveAffine> Proof<C> {
// //
// where p_j(X) is the jth advice column in this permutation, // where p_j(X) is the jth advice column in this permutation,
// and i is the ith row of the column. // and i is the ith row of the column.
let mut modified_advice = vec![C::Scalar::one(); params.n as usize]; .map(|(columns, permuted_values)| {
let mut modified_advice = vec![C::Scalar::one(); params.n as usize];
// Iterate over each column of the permutation // Iterate over each column of the permutation
for (&column, permuted_column_values) in columns.iter().zip(permuted_values.iter()) { for (&column, permuted_column_values) in columns.iter().zip(permuted_values.iter())
parallelize(&mut modified_advice, |modified_advice, start| { {
for ((modified_advice, advice_value), permuted_advice_value) in modified_advice parallelize(&mut modified_advice, |modified_advice, start| {
.iter_mut() for ((modified_advice, advice_value), permuted_advice_value) in
.zip(witness.advice[column.index()][start..].iter()) modified_advice
.zip(permuted_column_values[start..].iter()) .iter_mut()
{ .zip(witness.advice[column.index()][start..].iter())
*modified_advice *= &(x_0 * permuted_advice_value + &x_1 + advice_value); .zip(permuted_column_values[start..].iter())
} {
}); *modified_advice *=
} &(x_0 * permuted_advice_value + &x_1 + advice_value);
}
});
}
permutation_modified_advice.push(modified_advice); modified_advice
} })
.collect::<Vec<_>>();
// Batch invert to obtain the denominators for the permutation product // Batch invert to obtain the denominators for the permutation product
// polynomials // polynomials