From 98f9bab876856bcff9ded92a06ac7e38cc50320d Mon Sep 17 00:00:00 2001 From: Thor Kamphefner Date: Mon, 10 Jul 2023 17:26:39 -0700 Subject: [PATCH] lint powers_of --- halo2_proofs/src/protostar/error_check.rs | 28 ++++++++++++++--------- halo2_proofs/src/protostar/shuffle.rs | 2 ++ 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/halo2_proofs/src/protostar/error_check.rs b/halo2_proofs/src/protostar/error_check.rs index 3c05dfa0..a69a9d60 100644 --- a/halo2_proofs/src/protostar/error_check.rs +++ b/halo2_proofs/src/protostar/error_check.rs @@ -436,15 +436,21 @@ pub fn evaluated_challenge_powers( } /// Computes [1, v, v^2, ..., v^max_degee] -fn powers_of(v: &F, max_degee: usize) -> Vec { - let mut powers = Vec::with_capacity(max_degee + 1); - let mut acc = F::ONE; - powers.push(acc); - - // we need max_degee + 1 since we include v^0 = 1 - for _i in 1..max_degee + 1 { - acc *= v; - powers.push(acc); - } - powers +fn powers_of(v: &F, max_degree: usize) -> Vec { + std::iter::successors(Some(F::ONE), |&n| Some(n * v)) + // we need max_degee + 1 since we include v^0 = 1 + .take(max_degree + 1) + .collect() } + +#[cfg(test)] +mod test{ + use super::*; + use crate::{halo2curves::pasta::Fp, plonk::sealed::SealedPhase}; + #[test] + fn test_powers_of(){ + let v = Fp::from(2u64); + let expect: Vec = [1,2,4,8,16,32].into_iter().map(Fp::from).collect(); + assert_eq!(expect, powers_of(&v, 5)); + } +} \ No newline at end of file diff --git a/halo2_proofs/src/protostar/shuffle.rs b/halo2_proofs/src/protostar/shuffle.rs index 133cb3dd..f53e38f7 100644 --- a/halo2_proofs/src/protostar/shuffle.rs +++ b/halo2_proofs/src/protostar/shuffle.rs @@ -21,10 +21,12 @@ use ff::{BatchInvert, FromUniformBytes}; use rand_core::{OsRng, RngCore}; use std::iter::{self, zip}; +/// generate a random 2d array of field elements of size W x H fn rand_2d_array(rng: &mut R) -> [[F; H]; W] { [(); W].map(|_| [(); H].map(|_| F::random(&mut *rng))) } +/// randomly permute the columns 2d array `original` fn shuffled( original: [[F; H]; W], rng: &mut R,