mirror of
https://github.com/arnaucube/testudo.git
synced 2026-01-12 16:51:28 +01:00
@@ -1,7 +1,8 @@
|
|||||||
use super::group::{GroupElement, VartimeMultiscalarMul, GROUP_BASEPOINT_COMPRESSED};
|
use super::group::{GroupElement, VartimeMultiscalarMul, GROUP_BASEPOINT_COMPRESSED};
|
||||||
use super::scalar::Scalar;
|
use super::scalar::Scalar;
|
||||||
use digest::{ExtendableOutput, Input, XofReader};
|
use digest::{ExtendableOutput, Input};
|
||||||
use sha3::Shake256;
|
use sha3::Shake256;
|
||||||
|
use std::io::Read;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct MultiCommitGens {
|
pub struct MultiCommitGens {
|
||||||
@@ -20,7 +21,7 @@ impl MultiCommitGens {
|
|||||||
let mut gens: Vec<GroupElement> = Vec::new();
|
let mut gens: Vec<GroupElement> = Vec::new();
|
||||||
let mut uniform_bytes = [0u8; 64];
|
let mut uniform_bytes = [0u8; 64];
|
||||||
for _ in 0..n + 1 {
|
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));
|
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) {
|
pub fn split_at(&self, mid: usize) -> (MultiCommitGens, MultiCommitGens) {
|
||||||
let (G1, G2) = self.G.split_at_mut(mid);
|
let (G1, G2) = self.G.split_at(mid);
|
||||||
|
|
||||||
(
|
(
|
||||||
MultiCommitGens {
|
MultiCommitGens {
|
||||||
@@ -63,14 +64,14 @@ pub trait Commitments {
|
|||||||
|
|
||||||
impl Commitments for Scalar {
|
impl Commitments for Scalar {
|
||||||
fn commit(&self, blind: &Scalar, gens_n: &MultiCommitGens) -> GroupElement {
|
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])
|
GroupElement::vartime_multiscalar_mul(&[*self, *blind], &[gens_n.G[0], gens_n.h])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Commitments for Vec<Scalar> {
|
impl Commitments for Vec<Scalar> {
|
||||||
fn commit(&self, blind: &Scalar, gens_n: &MultiCommitGens) -> GroupElement {
|
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
|
GroupElement::vartime_multiscalar_mul(self, &gens_n.G) + blind * gens_n.h
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ use rayon::prelude::*;
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct DensePolynomial {
|
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,
|
len: usize,
|
||||||
Z: Vec<Scalar>, // evaluations of the polynomial in all the 2^num_vars Boolean inputs
|
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;
|
let R_size = self.Z.len() / L_size;
|
||||||
assert_eq!(L_size * R_size, self.Z.len());
|
assert_eq!(L_size * R_size, self.Z.len());
|
||||||
let C = (0..L_size)
|
let C = (0..L_size)
|
||||||
.collect::<Vec<usize>>()
|
.into_par_iter()
|
||||||
.par_iter()
|
|
||||||
.map(|&i| {
|
.map(|&i| {
|
||||||
self.Z[R_size * i..R_size * (i + 1)]
|
self.Z[R_size * i..R_size * (i + 1)]
|
||||||
.commit(&blinds[i], gens)
|
.commit(&blinds[i], gens)
|
||||||
@@ -207,7 +206,7 @@ impl DensePolynomial {
|
|||||||
let R_size = right_num_vars.pow2();
|
let R_size = right_num_vars.pow2();
|
||||||
(0..R_size)
|
(0..R_size)
|
||||||
.map(|i| (0..L_size).map(|j| L[j] * self.Z[j * R_size + i]).sum())
|
.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) {
|
pub fn bound_poly_var_top(&mut self, r: &Scalar) {
|
||||||
|
|||||||
@@ -168,8 +168,8 @@ impl BulletReductionProof {
|
|||||||
|
|
||||||
// 3. Compute u_i^2 and (1/u_i)^2
|
// 3. Compute u_i^2 and (1/u_i)^2
|
||||||
for i in 0..lg_n {
|
for i in 0..lg_n {
|
||||||
challenges[i] = challenges[i] * challenges[i];
|
challenges[i] = challenges[i].square();
|
||||||
challenges_inv[i] = challenges_inv[i] * challenges_inv[i];
|
challenges_inv[i] = challenges_inv[i].square();
|
||||||
}
|
}
|
||||||
let challenges_sq = challenges;
|
let challenges_sq = challenges;
|
||||||
let challenges_inv_sq = challenges_inv;
|
let challenges_inv_sq = challenges_inv;
|
||||||
|
|||||||
@@ -415,7 +415,7 @@ pub struct DotProductProofGens {
|
|||||||
|
|
||||||
impl DotProductProofGens {
|
impl DotProductProofGens {
|
||||||
pub fn new(n: usize, label: &[u8]) -> Self {
|
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 }
|
DotProductProofGens { n, gens_n, gens_1 }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,9 +103,9 @@ impl CompressedUniPoly {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut coeffs: Vec<Scalar> = Vec::new();
|
let mut coeffs: Vec<Scalar> = Vec::new();
|
||||||
coeffs.extend(vec![&self.coeffs_except_linear_term[0]]);
|
coeffs.push(self.coeffs_except_linear_term[0]);
|
||||||
coeffs.extend(vec![&linear_term]);
|
coeffs.push(linear_term);
|
||||||
coeffs.extend(self.coeffs_except_linear_term[1..].to_vec());
|
coeffs.extend(&self.coeffs_except_linear_term[1..]);
|
||||||
assert_eq!(self.coeffs_except_linear_term.len() + 1, coeffs.len());
|
assert_eq!(self.coeffs_except_linear_term.len() + 1, coeffs.len());
|
||||||
UniPoly { coeffs }
|
UniPoly { coeffs }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user