arnaucube
arnaucube/shockwave-plusPublic Self-hosted repository
shockwave-plus/shockwave_plus/src/polynomial/blinder_poly.rs
shockwave_plus/src/polynomial/blinder_poly.rsRaw
 1use crate::FieldExt;
 2
 3pub struct BlinderPoly<F: FieldExt> {
 4    inner_poly_coeffs: Vec<Vec<F>>,
 5}
 6
 7impl<F: FieldExt> BlinderPoly<F> {
 8    pub fn sample_random(num_vars: usize, degree: usize) -> Self {
 9        let mut rng = rand::thread_rng();
10        let inner_poly_coeffs = (0..num_vars)
11            .map(|_| (0..(degree + 1)).map(|_| F::random(&mut rng)).collect())
12            .collect();
13
14        Self { inner_poly_coeffs }
15    }
16
17    pub fn eval(&self, x: &[F]) -> F {
18        let mut res = F::ZERO;
19
20        for (coeffs, x_i) in self.inner_poly_coeffs.iter().zip(x.iter()) {
21            let mut tmp = F::ZERO;
22            let mut x_i_pow = F::ONE;
23
24            for coeff in coeffs.iter() {
25                tmp += *coeff * x_i_pow;
26                x_i_pow *= x_i;
27            }
28
29            res += tmp;
30        }
31
32        res
33    }
34}