Make `usable_rows` temporary to avoid duplicative code.

This commit is contained in:
Sean Bowe 2021-07-09 12:45:51 -06:00
parent 326cae153e
commit 9e6277ef6b
No known key found for this signature in database
GPG Key ID: 95684257D8F8B031
1 changed files with 6 additions and 5 deletions

View File

@ -613,8 +613,10 @@ fn permute_expression_pair<C: CurveAffine>(
table_expression: &Polynomial<C::Scalar, LagrangeCoeff>, table_expression: &Polynomial<C::Scalar, LagrangeCoeff>,
) -> Result<ExpressionPair<C::Scalar>, Error> { ) -> Result<ExpressionPair<C::Scalar>, Error> {
let blinding_factors = pk.vk.cs.blinding_factors(); let blinding_factors = pk.vk.cs.blinding_factors();
let usable_rows = params.n as usize - (blinding_factors + 1);
let mut permuted_input_expression: Vec<C::Scalar> = input_expression.to_vec(); let mut permuted_input_expression: Vec<C::Scalar> = input_expression.to_vec();
permuted_input_expression.truncate(params.n as usize - (blinding_factors + 1)); permuted_input_expression.truncate(usable_rows);
// Sort input lookup expression values // Sort input lookup expression values
permuted_input_expression.sort(); permuted_input_expression.sort();
@ -622,13 +624,12 @@ fn permute_expression_pair<C: CurveAffine>(
// A BTreeMap of each unique element in the table expression and its count // A BTreeMap of each unique element in the table expression and its count
let mut leftover_table_map: BTreeMap<C::Scalar, u32> = table_expression let mut leftover_table_map: BTreeMap<C::Scalar, u32> = table_expression
.iter() .iter()
.take(params.n as usize - (blinding_factors + 1)) .take(usable_rows)
.fold(BTreeMap::new(), |mut acc, coeff| { .fold(BTreeMap::new(), |mut acc, coeff| {
*acc.entry(*coeff).or_insert(0) += 1; *acc.entry(*coeff).or_insert(0) += 1;
acc acc
}); });
let mut permuted_table_coeffs = let mut permuted_table_coeffs = vec![C::Scalar::zero(); usable_rows];
vec![C::Scalar::zero(); params.n as usize - (blinding_factors + 1)];
let mut repeated_input_rows = permuted_input_expression let mut repeated_input_rows = permuted_input_expression
.iter() .iter()
@ -673,7 +674,7 @@ fn permute_expression_pair<C: CurveAffine>(
for (a, b) in permuted_input_expression for (a, b) in permuted_input_expression
.iter() .iter()
.zip(permuted_table_coeffs.iter()) .zip(permuted_table_coeffs.iter())
.take(params.n as usize - (blinding_factors + 1)) .take(usable_rows)
{ {
if *a != *b { if *a != *b {
assert_eq!(*a, last); assert_eq!(*a, last);