From 15a9826e3ce7469dc408bc6c71952196d8f0f112 Mon Sep 17 00:00:00 2001 From: Daniel Lubarov Date: Mon, 3 Aug 2020 11:55:21 -0700 Subject: [PATCH] Some minor tweaks (#21) Minor tweaks --- src/commitments.rs | 13 +++++++------ src/dense_mlpoly.rs | 7 +++---- src/nizk/bullet.rs | 4 ++-- src/nizk/mod.rs | 2 +- src/unipoly.rs | 6 +++--- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/commitments.rs b/src/commitments.rs index 3108000..8cc9112 100644 --- a/src/commitments.rs +++ b/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 @@ impl MultiCommitGens { let mut gens: Vec = 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 @@ impl MultiCommitGens { } } - 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 @@ pub trait Commitments { 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 { 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 } } diff --git a/src/dense_mlpoly.rs b/src/dense_mlpoly.rs index f12f6c6..3c836c1 100644 --- a/src/dense_mlpoly.rs +++ b/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, // evaluations of the polynomial in all the 2^num_vars Boolean inputs } @@ -148,8 +148,7 @@ impl DensePolynomial { let R_size = self.Z.len() / L_size; assert_eq!(L_size * R_size, self.Z.len()); let C = (0..L_size) - .collect::>() - .par_iter() + .into_par_iter() .map(|&i| { self.Z[R_size * i..R_size * (i + 1)] .commit(&blinds[i], gens) @@ -207,7 +206,7 @@ impl DensePolynomial { 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::>() + .collect() } pub fn bound_poly_var_top(&mut self, r: &Scalar) { diff --git a/src/nizk/bullet.rs b/src/nizk/bullet.rs index 902e322..0224932 100644 --- a/src/nizk/bullet.rs +++ b/src/nizk/bullet.rs @@ -168,8 +168,8 @@ impl BulletReductionProof { // 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; diff --git a/src/nizk/mod.rs b/src/nizk/mod.rs index bf0137d..0cfb592 100644 --- a/src/nizk/mod.rs +++ b/src/nizk/mod.rs @@ -415,7 +415,7 @@ pub struct DotProductProofGens { 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 } } } diff --git a/src/unipoly.rs b/src/unipoly.rs index a6db038..895b24d 100644 --- a/src/unipoly.rs +++ b/src/unipoly.rs @@ -103,9 +103,9 @@ impl CompressedUniPoly { } let mut coeffs: Vec = 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 } }