Browse Source

Some minor tweaks (#21)

Minor tweaks
master
Daniel Lubarov 3 years ago
committed by GitHub
parent
commit
15a9826e3c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 16 deletions
  1. +7
    -6
      src/commitments.rs
  2. +3
    -4
      src/dense_mlpoly.rs
  3. +2
    -2
      src/nizk/bullet.rs
  4. +1
    -1
      src/nizk/mod.rs
  5. +3
    -3
      src/unipoly.rs

+ 7
- 6
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<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 @@ 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<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
}
}

+ 3
- 4
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 @@ 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::<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 @@ 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::<Vec<Scalar>>()
.collect()
}
pub fn bound_poly_var_top(&mut self, r: &Scalar) {

+ 2
- 2
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;

+ 1
- 1
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 }
}
}

+ 3
- 3
src/unipoly.rs

@ -103,9 +103,9 @@ impl CompressedUniPoly {
}
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 }
}

Loading…
Cancel
Save