Some minor tweaks (#21) Minor tweaks
Daniel Lubarov daniel@lubarov.com
Mon, 03 Aug 2020 11:55:21 -0700
5 files changed,
16 insertions(+),
16 deletions(-)
M
src/commitments.rs
→
src/commitments.rs
@@ -1,7 +1,8 @@
use super::group::{GroupElement, VartimeMultiscalarMul, GROUP_BASEPOINT_COMPRESSED}; use super::scalar::Scalar; -use digest::{ExtendableOutput, Input, XofReader}; +use digest::{ExtendableOutput, Input}; use sha3::Shake256; +use std::io::Read; #[derive(Debug)] pub struct MultiCommitGens {@@ -20,7 +21,7 @@ let mut reader = shake.xof_result();
let mut gens: Vec<GroupElement> = Vec::new(); let mut uniform_bytes = [0u8; 64]; for _ in 0..n + 1 { - reader.read(&mut uniform_bytes); + reader.read_exact(&mut uniform_bytes).unwrap(); gens.push(GroupElement::from_uniform_bytes(&uniform_bytes)); }@@ -39,8 +40,8 @@ G: self.G.clone(),
} } - pub fn split_at_mut(&mut self, mid: usize) -> (MultiCommitGens, MultiCommitGens) { - let (G1, G2) = self.G.split_at_mut(mid); + pub fn split_at(&self, mid: usize) -> (MultiCommitGens, MultiCommitGens) { + let (G1, G2) = self.G.split_at(mid); ( MultiCommitGens {@@ -63,14 +64,14 @@ }
impl Commitments for Scalar { fn commit(&self, blind: &Scalar, gens_n: &MultiCommitGens) -> GroupElement { - assert!(gens_n.n == 1); + assert_eq!(gens_n.n, 1); GroupElement::vartime_multiscalar_mul(&[*self, *blind], &[gens_n.G[0], gens_n.h]) } } impl Commitments for Vec<Scalar> { fn commit(&self, blind: &Scalar, gens_n: &MultiCommitGens) -> GroupElement { - assert!(gens_n.n == self.len()); + assert_eq!(gens_n.n, self.len()); GroupElement::vartime_multiscalar_mul(self, &gens_n.G) + blind * gens_n.h } }
M
src/dense_mlpoly.rs
→
src/dense_mlpoly.rs
@@ -16,7 +16,7 @@ use rayon::prelude::*;
#[derive(Debug)] pub struct DensePolynomial { - num_vars: usize, //the number of variables in the multilinear polynomial + num_vars: usize, // the number of variables in the multilinear polynomial len: usize, Z: Vec<Scalar>, // evaluations of the polynomial in all the 2^num_vars Boolean inputs }@@ -148,8 +148,7 @@ let L_size = blinds.len();
let R_size = self.Z.len() / L_size; assert_eq!(L_size * R_size, self.Z.len()); let C = (0..L_size) - .collect::<Vec<usize>>() - .par_iter() + .into_par_iter() .map(|&i| { self.Z[R_size * i..R_size * (i + 1)] .commit(&blinds[i], gens)@@ -207,7 +206,7 @@ let L_size = left_num_vars.pow2();
let R_size = right_num_vars.pow2(); (0..R_size) .map(|i| (0..L_size).map(|j| L[j] * self.Z[j * R_size + i]).sum()) - .collect::<Vec<Scalar>>() + .collect() } pub fn bound_poly_var_top(&mut self, r: &Scalar) {
M
src/nizk/bullet.rs
→
src/nizk/bullet.rs
@@ -168,8 +168,8 @@ let allinv = Scalar::batch_invert(&mut challenges_inv);
// 3. Compute u_i^2 and (1/u_i)^2 for i in 0..lg_n { - challenges[i] = challenges[i] * challenges[i]; - challenges_inv[i] = challenges_inv[i] * challenges_inv[i]; + challenges[i] = challenges[i].square(); + challenges_inv[i] = challenges_inv[i].square(); } let challenges_sq = challenges; let challenges_inv_sq = challenges_inv;
M
src/nizk/mod.rs
→
src/nizk/mod.rs
@@ -415,7 +415,7 @@ }
impl DotProductProofGens { pub fn new(n: usize, label: &[u8]) -> Self { - let (gens_n, gens_1) = MultiCommitGens::new(n + 1, label).split_at_mut(n); + let (gens_n, gens_1) = MultiCommitGens::new(n + 1, label).split_at(n); DotProductProofGens { n, gens_n, gens_1 } } }
M
src/unipoly.rs
→
src/unipoly.rs
@@ -103,9 +103,9 @@ linear_term -= self.coeffs_except_linear_term[i];
} let mut coeffs: Vec<Scalar> = Vec::new(); - coeffs.extend(vec![&self.coeffs_except_linear_term[0]]); - coeffs.extend(vec![&linear_term]); - coeffs.extend(self.coeffs_except_linear_term[1..].to_vec()); + coeffs.push(self.coeffs_except_linear_term[0]); + coeffs.push(linear_term); + coeffs.extend(&self.coeffs_except_linear_term[1..]); assert_eq!(self.coeffs_except_linear_term.len() + 1, coeffs.len()); UniPoly { coeffs } }