Skip to content

Commit

Permalink
lint powers_of
Browse files Browse the repository at this point in the history
  • Loading branch information
thor314 committed Jul 11, 2023
1 parent 4b8ee54 commit 9636bbb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
28 changes: 17 additions & 11 deletions halo2_proofs/src/protostar/error_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,15 +436,21 @@ pub fn evaluated_challenge_powers<F: Field>(
}

/// Computes [1, v, v^2, ..., v^max_degee]
fn powers_of<F: Field>(v: &F, max_degee: usize) -> Vec<F> {
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<F: Field>(v: &F, max_degree: usize) -> Vec<F> {
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<Fp> = [1,2,4,8,16,32].into_iter().map(Fp::from).collect();
assert_eq!(expect, powers_of(&v, 5));
}
}
2 changes: 2 additions & 0 deletions halo2_proofs/src/protostar/shuffle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<F: Field, R: RngCore, const W: usize, const H: usize>(rng: &mut R) -> [[F; H]; W] {
[(); W].map(|_| [(); H].map(|_| F::random(&mut *rng)))
}

/// randomly permute the columns 2d array `original`
fn shuffled<F: Field, R: RngCore, const W: usize, const H: usize>(
original: [[F; H]; W],
rng: &mut R,
Expand Down

0 comments on commit 9636bbb

Please sign in to comment.