Charles Chen 1 year ago
parent
commit
648ea51ff4
18 changed files with 140 additions and 140 deletions
  1. +13
    -13
      arithmetic/src/multilinear_polynomial.rs
  2. +14
    -14
      arithmetic/src/virtual_polynomial.rs
  3. +2
    -2
      hyperplonk/src/selectors.rs
  4. +15
    -12
      hyperplonk/src/snark.rs
  5. +3
    -3
      hyperplonk/src/structs.rs
  6. +8
    -8
      hyperplonk/src/utils.rs
  7. +2
    -2
      hyperplonk/src/witness.rs
  8. +4
    -4
      subroutines/benches/iop_bench.rs
  9. +2
    -2
      subroutines/benches/pcs_bench.rs
  10. +2
    -8
      subroutines/src/pcs/mod.rs
  11. +8
    -8
      subroutines/src/pcs/multilinear_kzg/batching.rs
  12. +5
    -5
      subroutines/src/pcs/multilinear_kzg/mod.rs
  13. +17
    -17
      subroutines/src/poly_iop/perm_check/mod.rs
  14. +8
    -8
      subroutines/src/poly_iop/perm_check/util.rs
  15. +13
    -13
      subroutines/src/poly_iop/prod_check/mod.rs
  16. +14
    -14
      subroutines/src/poly_iop/prod_check/util.rs
  17. +4
    -4
      subroutines/src/poly_iop/sum_check/mod.rs
  18. +6
    -3
      subroutines/src/poly_iop/sum_check/prover.rs

+ 13
- 13
arithmetic/src/multilinear_polynomial.rs

@ -4,19 +4,19 @@ use ark_poly::MultilinearExtension;
use ark_std::{end_timer, rand::RngCore, start_timer};
#[cfg(feature = "parallel")]
use rayon::prelude::{IndexedParallelIterator, IntoParallelRefMutIterator, ParallelIterator};
use std::rc::Rc;
use std::sync::Arc;
pub use ark_poly::DenseMultilinearExtension;
/// Sample a random list of multilinear polynomials.
/// Returns
/// - the list of polynomials,
/// - its sum of polynomial evaluations over the boolean hypercube.
/// - its sum of polynomial evaluations over the boolean hypeArcube.
pub fn random_mle_list<F: PrimeField, R: RngCore>(
nv: usize,
degree: usize,
rng: &mut R,
) -> (Vec<Rc<DenseMultilinearExtension<F>>>, F) {
) -> (Vec<Arc<DenseMultilinearExtension<F>>>, F) {
let start = start_timer!(|| "sample random mle list");
let mut multiplicands = Vec::with_capacity(degree);
for _ in 0..degree {
@ -37,7 +37,7 @@ pub fn random_mle_list(
let list = multiplicands
.into_iter()
.map(|x| Rc::new(DenseMultilinearExtension::from_evaluations_vec(nv, x)))
.map(|x| Arc::new(DenseMultilinearExtension::from_evaluations_vec(nv, x)))
.collect();
end_timer!(start);
@ -49,7 +49,7 @@ pub fn random_zero_mle_list(
nv: usize,
degree: usize,
rng: &mut R,
) -> Vec<Rc<DenseMultilinearExtension<F>>> {
) -> Vec<Arc<DenseMultilinearExtension<F>>> {
let start = start_timer!(|| "sample random zero mle list");
let mut multiplicands = Vec::with_capacity(degree);
@ -65,7 +65,7 @@ pub fn random_zero_mle_list(
let list = multiplicands
.into_iter()
.map(|x| Rc::new(DenseMultilinearExtension::from_evaluations_vec(nv, x)))
.map(|x| Arc::new(DenseMultilinearExtension::from_evaluations_vec(nv, x)))
.collect();
end_timer!(start);
@ -81,12 +81,12 @@ pub fn identity_permutation(num_vars: usize, num_chunks: usize) -
pub fn identity_permutation_mles<F: PrimeField>(
num_vars: usize,
num_chunks: usize,
) -> Vec<Rc<DenseMultilinearExtension<F>>> {
) -> Vec<Arc<DenseMultilinearExtension<F>>> {
let mut res = vec![];
for i in 0..num_chunks {
let shift = (i * (1 << num_vars)) as u64;
let s_id_vec = (shift..shift + (1u64 << num_vars)).map(F::from).collect();
res.push(Rc::new(DenseMultilinearExtension::from_evaluations_vec(
res.push(Arc::new(DenseMultilinearExtension::from_evaluations_vec(
num_vars, s_id_vec,
)));
}
@ -113,12 +113,12 @@ pub fn random_permutation_mles(
num_vars: usize,
num_chunks: usize,
rng: &mut R,
) -> Vec<Rc<DenseMultilinearExtension<F>>> {
) -> Vec<Arc<DenseMultilinearExtension<F>>> {
let s_perm_vec = random_permutation(num_vars, num_chunks, rng);
let mut res = vec![];
let n = 1 << num_vars;
for i in 0..num_chunks {
res.push(Rc::new(DenseMultilinearExtension::from_evaluations_vec(
res.push(Arc::new(DenseMultilinearExtension::from_evaluations_vec(
num_vars,
s_perm_vec[i * n..i * n + n].to_vec(),
)));
@ -203,8 +203,8 @@ fn fix_variables_no_par(
/// merge a set of polynomials. Returns an error if the
/// polynomials do not share a same number of nvs.
pub fn merge_polynomials<F: PrimeField>(
polynomials: &[Rc<DenseMultilinearExtension<F>>],
) -> Result<Rc<DenseMultilinearExtension<F>>, ArithErrors> {
polynomials: &[Arc<DenseMultilinearExtension<F>>],
) -> Result<Arc<DenseMultilinearExtension<F>>, ArithErrors> {
let nv = polynomials[0].num_vars();
for poly in polynomials.iter() {
if nv != poly.num_vars() {
@ -220,7 +220,7 @@ pub fn merge_polynomials(
scalars.extend_from_slice(poly.to_evaluations().as_slice());
}
scalars.extend_from_slice(vec![F::zero(); (1 << merged_nv) - scalars.len()].as_ref());
Ok(Rc::new(DenseMultilinearExtension::from_evaluations_vec(
Ok(Arc::new(DenseMultilinearExtension::from_evaluations_vec(
merged_nv, scalars,
)))
}

+ 14
- 14
arithmetic/src/virtual_polynomial.rs

@ -11,7 +11,7 @@ use ark_std::{
start_timer,
};
use rayon::prelude::*;
use std::{cmp::max, collections::HashMap, marker::PhantomData, ops::Add, rc::Rc};
use std::{cmp::max, collections::HashMap, marker::PhantomData, ops::Add, sync::Arc};
#[rustfmt::skip]
/// A virtual polynomial is a sum of products of multilinear polynomials;
@ -48,7 +48,7 @@ pub struct VirtualPolynomial {
pub products: Vec<(F, Vec<usize>)>,
/// Stores multilinear extensions in which product multiplicand can refer
/// to.
pub flattened_ml_extensions: Vec<Rc<DenseMultilinearExtension<F>>>,
pub flattened_ml_extensions: Vec<Arc<DenseMultilinearExtension<F>>>,
/// Pointers to the above poly extensions
raw_pointers_lookup_table: HashMap<*const DenseMultilinearExtension<F>, usize>,
}
@ -71,7 +71,7 @@ impl Add for &VirtualPolynomial {
let start = start_timer!(|| "virtual poly add");
let mut res = self.clone();
for products in other.products.iter() {
let cur: Vec<Rc<DenseMultilinearExtension<F>>> = products
let cur: Vec<Arc<DenseMultilinearExtension<F>>> = products
.1
.iter()
.map(|&x| other.flattened_ml_extensions[x].clone())
@ -102,8 +102,8 @@ impl VirtualPolynomial {
}
/// Creates an new virtual polynomial from a MLE and its coefficient.
pub fn new_from_mle(mle: &Rc<DenseMultilinearExtension<F>>, coefficient: F) -> Self {
let mle_ptr: *const DenseMultilinearExtension<F> = Rc::as_ptr(mle);
pub fn new_from_mle(mle: &Arc<DenseMultilinearExtension<F>>, coefficient: F) -> Self {
let mle_ptr: *const DenseMultilinearExtension<F> = Arc::as_ptr(mle);
let mut hm = HashMap::new();
hm.insert(mle_ptr, 0);
@ -129,10 +129,10 @@ impl VirtualPolynomial {
/// `coefficient`.
pub fn add_mle_list(
&mut self,
mle_list: impl IntoIterator<Item = Rc<DenseMultilinearExtension<F>>>,
mle_list: impl IntoIterator<Item = Arc<DenseMultilinearExtension<F>>>,
coefficient: F,
) -> Result<(), ArithErrors> {
let mle_list: Vec<Rc<DenseMultilinearExtension<F>>> = mle_list.into_iter().collect();
let mle_list: Vec<Arc<DenseMultilinearExtension<F>>> = mle_list.into_iter().collect();
let mut indexed_product = Vec::with_capacity(mle_list.len());
if mle_list.is_empty() {
@ -151,7 +151,7 @@ impl VirtualPolynomial {
)));
}
let mle_ptr: *const DenseMultilinearExtension<F> = Rc::as_ptr(&mle);
let mle_ptr: *const DenseMultilinearExtension<F> = Arc::as_ptr(&mle);
if let Some(index) = self.raw_pointers_lookup_table.get(&mle_ptr) {
indexed_product.push(*index)
} else {
@ -171,7 +171,7 @@ impl VirtualPolynomial {
/// Returns an error if the MLE has a different `num_vars` from self.
pub fn mul_by_mle(
&mut self,
mle: Rc<DenseMultilinearExtension<F>>,
mle: Arc<DenseMultilinearExtension<F>>,
coefficient: F,
) -> Result<(), ArithErrors> {
let start = start_timer!(|| "mul by mle");
@ -183,7 +183,7 @@ impl VirtualPolynomial {
)));
}
let mle_ptr: *const DenseMultilinearExtension<F> = Rc::as_ptr(&mle);
let mle_ptr: *const DenseMultilinearExtension<F> = Arc::as_ptr(&mle);
// check if this mle already exists in the virtual polynomial
let mle_index = match self.raw_pointers_lookup_table.get(&mle_ptr) {
@ -350,11 +350,11 @@ pub fn eq_eval(x: &[F], y: &[F]) -> Result {
/// eq(x,y) = \prod_i=1^num_var (x_i * r_i + (1-x_i)*(1-r_i))
pub fn build_eq_x_r<F: PrimeField>(
r: &[F],
) -> Result<Rc<DenseMultilinearExtension<F>>, ArithErrors> {
) -> Result<Arc<DenseMultilinearExtension<F>>, ArithErrors> {
let evals = build_eq_x_r_vec(r)?;
let mle = DenseMultilinearExtension::from_evaluations_vec(r.len(), evals);
Ok(Rc::new(mle))
Ok(Arc::new(mle))
}
/// This function build the eq(x, r) polynomial for any given r, and output the
/// evaluation of eq(x, r) in its vector form.
@ -511,7 +511,7 @@ mod test {
// eq(x,y) = \prod_i=1^num_var (x_i * y_i + (1-x_i)*(1-y_i))
// over r, which is
// eq(x,y) = \prod_i=1^num_var (x_i * r_i + (1-x_i)*(1-r_i))
fn build_eq_x_r_for_test<F: PrimeField>(r: &[F]) -> Rc<DenseMultilinearExtension<F>> {
fn build_eq_x_r_for_test<F: PrimeField>(r: &[F]) -> Arc<DenseMultilinearExtension<F>> {
let start = start_timer!(|| "zero check naive build eq_x_r");
// we build eq(x,r) from its evaluations
@ -545,7 +545,7 @@ mod test {
let mle = DenseMultilinearExtension::from_evaluations_vec(num_var, eval);
let res = Rc::new(mle);
let res = Arc::new(mle);
end_timer!(start);
res
}

+ 2
- 2
hyperplonk/src/selectors.rs

@ -2,7 +2,7 @@ use crate::{build_mle, errors::HyperPlonkErrors};
use ark_ff::PrimeField;
use ark_poly::DenseMultilinearExtension;
use ark_std::log2;
use std::rc::Rc;
use std::sync::Arc;
/// A row of selector of width `#selectors`
#[derive(Debug, Clone, PartialEq, Eq)]
@ -67,7 +67,7 @@ impl SelectorRow {
/// output mle(a1,b1,c1, ...), mle(a2,b2,c2, ...), ...
pub fn build_mles(
matrix: &[Self],
) -> Result<Vec<Rc<DenseMultilinearExtension<F>>>, HyperPlonkErrors> {
) -> Result<Vec<Arc<DenseMultilinearExtension<F>>>, HyperPlonkErrors> {
build_mle!(matrix)
}
}

+ 15
- 12
hyperplonk/src/snark.rs

@ -9,7 +9,10 @@ use arithmetic::{evaluate_opt, gen_eval_point, VPAuxInfo};
use ark_ec::PairingEngine;
use ark_poly::DenseMultilinearExtension;
use ark_std::{end_timer, log2, start_timer, One, Zero};
use std::{marker::PhantomData, rc::Rc};
use rayon::iter::IntoParallelRefIterator;
#[cfg(feature = "parallel")]
use rayon::iter::ParallelIterator;
use std::{marker::PhantomData, sync::Arc};
use subroutines::{
pcs::prelude::{Commitment, PolynomialCommitmentScheme},
poly_iop::{
@ -28,7 +31,7 @@ where
// we cannot bound PCS::Polynomial with a property trait bound.
PCS: PolynomialCommitmentScheme<
E,
Polynomial = Rc<DenseMultilinearExtension<E::Fr>>,
Polynomial = Arc<DenseMultilinearExtension<E::Fr>>,
Point = Vec<E::Fr>,
Evaluation = E::Fr,
Commitment = Commitment<E>,
@ -56,7 +59,7 @@ where
let mut perm_comms = vec![];
let chunk_size = 1 << num_vars;
for i in 0..index.num_witness_columns() {
let perm_oracle = Rc::new(DenseMultilinearExtension::from_evaluations_slice(
let perm_oracle = Arc::new(DenseMultilinearExtension::from_evaluations_slice(
num_vars,
&index.permutation[i * chunk_size..(i + 1) * chunk_size],
));
@ -66,10 +69,10 @@ where
}
// build selector oracles and commit to it
let selector_oracles: Vec<Rc<DenseMultilinearExtension<E::Fr>>> = index
let selector_oracles: Vec<Arc<DenseMultilinearExtension<E::Fr>>> = index
.selectors
.iter()
.map(|s| Rc::new(DenseMultilinearExtension::from(s)))
.map(|s| Arc::new(DenseMultilinearExtension::from(s)))
.collect();
let selector_commitments = selector_oracles
@ -168,13 +171,13 @@ where
// =======================================================================
let step = start_timer!(|| "commit witnesses");
let witness_polys: Vec<Rc<DenseMultilinearExtension<E::Fr>>> = witnesses
let witness_polys: Vec<Arc<DenseMultilinearExtension<E::Fr>>> = witnesses
.iter()
.map(|w| Rc::new(DenseMultilinearExtension::from(w)))
.map(|w| Arc::new(DenseMultilinearExtension::from(w)))
.collect();
let witness_commits = witness_polys
.iter()
.par_iter()
.map(|x| PCS::commit(&pk.pcs_param, x).unwrap())
.collect::<Vec<_>>();
for w_com in witness_commits.iter() {
@ -663,15 +666,15 @@ mod tests {
let w1 = WitnessColumn(vec![
E::Fr::zero(),
E::Fr::one(),
E::Fr::from(2u64),
E::Fr::from(3u64),
E::Fr::from(2u128),
E::Fr::from(3u128),
]);
// w2 := [0^5, 1^5, 2^5, 3^5]
let w2 = WitnessColumn(vec![
E::Fr::zero(),
E::Fr::one(),
E::Fr::from(32u64),
E::Fr::from(243u64),
E::Fr::from(32u128),
E::Fr::from(243u128),
]);
// public input = w1
let pi = w1.clone();

+ 3
- 3
hyperplonk/src/structs.rs

@ -5,7 +5,7 @@ use ark_ec::PairingEngine;
use ark_ff::PrimeField;
use ark_poly::DenseMultilinearExtension;
use ark_std::log2;
use std::rc::Rc;
use std::sync::Arc;
use subroutines::{
pcs::PolynomialCommitmentScheme,
poly_iop::prelude::{PermutationCheck, ZeroCheck},
@ -126,9 +126,9 @@ pub struct HyperPlonkProvingKey
/// Hyperplonk instance parameters
pub params: HyperPlonkParams,
/// The preprocessed permutation polynomials
pub permutation_oracles: Vec<Rc<DenseMultilinearExtension<E::Fr>>>,
pub permutation_oracles: Vec<Arc<DenseMultilinearExtension<E::Fr>>>,
/// The preprocessed selector polynomials
pub selector_oracles: Vec<Rc<DenseMultilinearExtension<E::Fr>>>,
pub selector_oracles: Vec<Arc<DenseMultilinearExtension<E::Fr>>>,
/// Commitments to the preprocessed selector polynomials
pub selector_commitments: Vec<PCS::Commitment>,
/// Commitments to the preprocessed permutation polynomials

+ 8
- 8
hyperplonk/src/utils.rs

@ -6,7 +6,7 @@ use arithmetic::{evaluate_opt, VirtualPolynomial};
use ark_ec::PairingEngine;
use ark_ff::PrimeField;
use ark_poly::DenseMultilinearExtension;
use std::{borrow::Borrow, rc::Rc};
use std::{borrow::Borrow, sync::Arc};
use subroutines::pcs::{prelude::Commitment, PolynomialCommitmentScheme};
use transcript::IOPTranscript;
@ -32,7 +32,7 @@ where
E: PairingEngine,
PCS: PolynomialCommitmentScheme<
E,
Polynomial = Rc<DenseMultilinearExtension<E::Fr>>,
Polynomial = Arc<DenseMultilinearExtension<E::Fr>>,
Point = Vec<E::Fr>,
Evaluation = E::Fr,
Commitment = Commitment<E>,
@ -104,7 +104,7 @@ macro_rules! build_mle {
for row in $rows.iter() {
cur_coeffs.push(row.0[i])
}
res.push(Rc::new(DenseMultilinearExtension::from_evaluations_vec(
res.push(Arc::new(DenseMultilinearExtension::from_evaluations_vec(
num_vars, cur_coeffs,
)))
}
@ -178,8 +178,8 @@ pub(crate) fn prover_sanity_check(
pub(crate) fn build_f<F: PrimeField>(
gates: &CustomizedGates,
num_vars: usize,
selector_mles: &[Rc<DenseMultilinearExtension<F>>],
witness_mles: &[Rc<DenseMultilinearExtension<F>>],
selector_mles: &[Arc<DenseMultilinearExtension<F>>],
witness_mles: &[Arc<DenseMultilinearExtension<F>>],
) -> Result<VirtualPolynomial<F>, HyperPlonkErrors> {
// TODO: check that selector and witness lengths match what is in
// the gate definition
@ -306,7 +306,7 @@ mod test {
// 1, 0 |-> 0
// 1, 1 |-> 5
let ql_eval = vec![F::zero(), F::from(2u64), F::zero(), F::from(5u64)];
let ql = Rc::new(DenseMultilinearExtension::from_evaluations_vec(2, ql_eval));
let ql = Arc::new(DenseMultilinearExtension::from_evaluations_vec(2, ql_eval));
// W1 = x1x2 + x1 whose evaluations are
// 0, 0 |-> 0
@ -314,7 +314,7 @@ mod test {
// 1, 0 |-> 1
// 1, 1 |-> 2
let w_eval = vec![F::zero(), F::zero(), F::from(1u64), F::from(2u64)];
let w1 = Rc::new(DenseMultilinearExtension::from_evaluations_vec(2, w_eval));
let w1 = Arc::new(DenseMultilinearExtension::from_evaluations_vec(2, w_eval));
// W2 = x1 + x2 whose evaluations are
// 0, 0 |-> 0
@ -322,7 +322,7 @@ mod test {
// 1, 0 |-> 1
// 1, 1 |-> 2
let w_eval = vec![F::zero(), F::one(), F::from(1u64), F::from(2u64)];
let w2 = Rc::new(DenseMultilinearExtension::from_evaluations_vec(2, w_eval));
let w2 = Arc::new(DenseMultilinearExtension::from_evaluations_vec(2, w_eval));
// Example:
// q_L(X) * W_1(X)^5 - W_2(X)

+ 2
- 2
hyperplonk/src/witness.rs

@ -2,7 +2,7 @@ use crate::{build_mle, errors::HyperPlonkErrors};
use ark_ff::PrimeField;
use ark_poly::DenseMultilinearExtension;
use ark_std::log2;
use std::rc::Rc;
use std::sync::Arc;
/// A row of witnesses of width `#wires`
#[derive(Debug, Clone)]
@ -71,7 +71,7 @@ impl WitnessRow {
/// output mle(a1,b1,c1, ...), mle(a2,b2,c2, ...), ...
pub fn build_mles(
matrix: &[Self],
) -> Result<Vec<Rc<DenseMultilinearExtension<F>>>, HyperPlonkErrors> {
) -> Result<Vec<Arc<DenseMultilinearExtension<F>>>, HyperPlonkErrors> {
build_mle!(matrix)
}
}

+ 4
- 4
subroutines/benches/iop_bench.rs

@ -2,7 +2,7 @@ use arithmetic::{identity_permutation_mles, VPAuxInfo, VirtualPolynomial};
use ark_bls12_381::{Bls12_381, Fr};
use ark_poly::{DenseMultilinearExtension, MultilinearExtension};
use ark_std::test_rng;
use std::{marker::PhantomData, rc::Rc, time::Instant};
use std::{marker::PhantomData, sync::Arc, time::Instant};
use subroutines::{
pcs::{prelude::MultilinearKzgPCS, PolynomialCommitmentScheme},
poly_iop::prelude::{
@ -144,7 +144,7 @@ fn bench_permutation_check() -> Result<(), PolyIOPErrors> {
10
};
let ws = vec![Rc::new(DenseMultilinearExtension::rand(nv, &mut rng))];
let ws = vec![Arc::new(DenseMultilinearExtension::rand(nv, &mut rng))];
// identity map
let perms = identity_permutation_mles(nv, 1);
@ -218,8 +218,8 @@ fn bench_prod_check() -> Result<(), PolyIOPErrors> {
let f: DenseMultilinearExtension<Fr> = DenseMultilinearExtension::rand(nv, &mut rng);
let mut g = f.clone();
g.evaluations.reverse();
let fs = vec![Rc::new(f)];
let gs = vec![Rc::new(g)];
let fs = vec![Arc::new(f)];
let gs = vec![Arc::new(g)];
let proof = {
let start = Instant::now();

+ 2
- 2
subroutines/benches/pcs_bench.rs

@ -1,7 +1,7 @@
use ark_bls12_381::{Bls12_381, Fr};
use ark_ff::UniformRand;
use ark_poly::{DenseMultilinearExtension, MultilinearExtension};
use ark_std::{rc::Rc, test_rng};
use ark_std::{sync::Arc, test_rng};
use std::time::Instant;
use subroutines::pcs::{
prelude::{MultilinearKzgPCS, PCSError, PolynomialCommitmentScheme},
@ -27,7 +27,7 @@ fn bench_pcs() -> Result<(), PCSError> {
2
};
let poly = Rc::new(DenseMultilinearExtension::rand(nv, &mut rng));
let poly = Arc::new(DenseMultilinearExtension::rand(nv, &mut rng));
let (ck, vk) = uni_params.trim(nv)?;
let point: Vec<_> = (0..nv).map(|_| Fr::rand(&mut rng)).collect();

+ 2
- 8
subroutines/src/pcs/mod.rs

@ -17,19 +17,13 @@ use transcript::IOPTranscript;
/// Note that for our usage of PCS, we do not require the hiding property.
pub trait PolynomialCommitmentScheme<E: PairingEngine> {
/// Prover parameters
type ProverParam: Clone;
type ProverParam: Clone + Sync;
/// Verifier parameters
type VerifierParam: Clone + CanonicalSerialize + CanonicalDeserialize;
/// Structured reference string
type SRS: Clone + Debug;
/// Polynomial and its associated types
type Polynomial: Clone
+ Debug
+ Hash
+ PartialEq
+ Eq
+ CanonicalSerialize
+ CanonicalDeserialize;
type Polynomial: Clone + Debug + Hash + PartialEq + Eq;
/// Polynomial input domain
type Point: Clone + Ord + Debug + Sync + Hash + PartialEq + Eq;
/// Polynomial Evaluation

+ 8
- 8
subroutines/src/pcs/multilinear_kzg/batching.rs

@ -17,7 +17,7 @@ use arithmetic::{build_eq_x_r_vec, DenseMultilinearExtension, VPAuxInfo, Virtual
use ark_ec::{msm::VariableBaseMSM, PairingEngine, ProjectiveCurve};
use ark_ff::PrimeField;
use ark_std::{end_timer, log2, start_timer, One, Zero};
use std::{marker::PhantomData, rc::Rc};
use std::{marker::PhantomData, sync::Arc};
use transcript::IOPTranscript;
#[derive(Clone, Debug, Default, PartialEq, Eq)]
@ -53,7 +53,7 @@ where
E: PairingEngine,
PCS: PolynomialCommitmentScheme<
E,
Polynomial = Rc<DenseMultilinearExtension<E::Fr>>,
Polynomial = Arc<DenseMultilinearExtension<E::Fr>>,
Point = Vec<E::Fr>,
Evaluation = E::Fr,
>,
@ -79,7 +79,7 @@ where
for (j, &f_i_eval) in f_i.iter().enumerate() {
tilde_g_eval[j] = f_i_eval * eq_t_i_list[index];
}
tilde_gs.push(Rc::new(DenseMultilinearExtension::from_evaluations_vec(
tilde_gs.push(Arc::new(DenseMultilinearExtension::from_evaluations_vec(
num_var,
tilde_g_eval,
)));
@ -90,7 +90,7 @@ where
let mut tilde_eqs = vec![];
for point in points.iter() {
let eq_b_zi = build_eq_x_r_vec(point)?;
tilde_eqs.push(Rc::new(DenseMultilinearExtension::from_evaluations_vec(
tilde_eqs.push(Arc::new(DenseMultilinearExtension::from_evaluations_vec(
num_var, eq_b_zi,
)));
}
@ -131,7 +131,7 @@ where
g_prime_evals[j] += tilde_g_eval * eq_i_a2;
}
}
let g_prime = Rc::new(DenseMultilinearExtension::from_evaluations_vec(
let g_prime = Arc::new(DenseMultilinearExtension::from_evaluations_vec(
num_var,
g_prime_evals,
));
@ -169,7 +169,7 @@ where
E: PairingEngine,
PCS: PolynomialCommitmentScheme<
E,
Polynomial = Rc<DenseMultilinearExtension<E::Fr>>,
Polynomial = Arc<DenseMultilinearExtension<E::Fr>>,
Point = Vec<E::Fr>,
Evaluation = E::Fr,
Commitment = Commitment<E>,
@ -265,7 +265,7 @@ mod tests {
fn test_multi_open_helper<R: RngCore + CryptoRng>(
ml_params: &MultilinearUniversalParams<E>,
polys: &[Rc<DenseMultilinearExtension<Fr>>],
polys: &[Arc<DenseMultilinearExtension<Fr>>],
rng: &mut R,
) -> Result<(), PCSError> {
let merged_nv = get_batched_nv(polys[0].num_vars(), polys.len());
@ -323,7 +323,7 @@ mod tests {
for num_poly in 5..6 {
for nv in 15..16 {
let polys1: Vec<_> = (0..num_poly)
.map(|_| Rc::new(DenseMultilinearExtension::rand(nv, &mut rng)))
.map(|_| Arc::new(DenseMultilinearExtension::rand(nv, &mut rng)))
.collect();
test_multi_open_helper(&ml_params, &polys1, &mut rng)?;
}

+ 5
- 5
subroutines/src/pcs/multilinear_kzg/mod.rs

@ -27,9 +27,9 @@ use ark_std::{
end_timer, format,
marker::PhantomData,
rand::{CryptoRng, RngCore},
rc::Rc,
start_timer,
string::ToString,
sync::Arc,
vec,
vec::Vec,
One, Zero,
@ -59,7 +59,7 @@ impl PolynomialCommitmentScheme for MultilinearKzgPCS {
type VerifierParam = MultilinearVerifierParam<E>;
type SRS = MultilinearUniversalParams<E>;
// Polynomial and its associated types
type Polynomial = Rc<DenseMultilinearExtension<E::Fr>>;
type Polynomial = Arc<DenseMultilinearExtension<E::Fr>>;
type Point = Vec<E::Fr>;
type Evaluation = E::Fr;
// Commitments and proofs
@ -356,7 +356,7 @@ mod tests {
fn test_single_helper<R: RngCore + CryptoRng>(
params: &MultilinearUniversalParams<E>,
poly: &Rc<DenseMultilinearExtension<Fr>>,
poly: &Arc<DenseMultilinearExtension<Fr>>,
rng: &mut R,
) -> Result<(), PCSError> {
let nv = poly.num_vars();
@ -385,11 +385,11 @@ mod tests {
let params = MultilinearKzgPCS::<E>::gen_srs_for_testing(&mut rng, 10)?;
// normal polynomials
let poly1 = Rc::new(DenseMultilinearExtension::rand(8, &mut rng));
let poly1 = Arc::new(DenseMultilinearExtension::rand(8, &mut rng));
test_single_helper(&params, &poly1, &mut rng)?;
// single-variate polynomials
let poly2 = Rc::new(DenseMultilinearExtension::rand(1, &mut rng));
let poly2 = Arc::new(DenseMultilinearExtension::rand(1, &mut rng));
test_single_helper(&params, &poly2, &mut rng)?;
Ok(())

+ 17
- 17
subroutines/src/poly_iop/perm_check/mod.rs

@ -8,7 +8,7 @@ use crate::{
use ark_ec::PairingEngine;
use ark_poly::DenseMultilinearExtension;
use ark_std::{end_timer, start_timer};
use std::rc::Rc;
use std::sync::Arc;
use transcript::IOPTranscript;
/// A permutation subclaim consists of
@ -95,7 +95,7 @@ where
impl<E, PCS> PermutationCheck<E, PCS> for PolyIOP<E::Fr>
where
E: PairingEngine,
PCS: PolynomialCommitmentScheme<E, Polynomial = Rc<DenseMultilinearExtension<E::Fr>>>,
PCS: PolynomialCommitmentScheme<E, Polynomial = Arc<DenseMultilinearExtension<E::Fr>>>,
{
type PermutationCheckSubClaim = PermutationCheckSubClaim<E, PCS, Self>;
type PermutationProof = Self::ProductCheckProof;
@ -192,19 +192,19 @@ mod test {
use ark_ec::PairingEngine;
use ark_poly::{DenseMultilinearExtension, MultilinearExtension};
use ark_std::test_rng;
use std::{marker::PhantomData, rc::Rc};
use std::{marker::PhantomData, sync::Arc};
type KZG = MultilinearKzgPCS<Bls12_381>;
fn test_permutation_check_helper<E, PCS>(
pcs_param: &PCS::ProverParam,
fxs: &[Rc<DenseMultilinearExtension<E::Fr>>],
gxs: &[Rc<DenseMultilinearExtension<E::Fr>>],
perms: &[Rc<DenseMultilinearExtension<E::Fr>>],
fxs: &[Arc<DenseMultilinearExtension<E::Fr>>],
gxs: &[Arc<DenseMultilinearExtension<E::Fr>>],
perms: &[Arc<DenseMultilinearExtension<E::Fr>>],
) -> Result<(), PolyIOPErrors>
where
E: PairingEngine,
PCS: PolynomialCommitmentScheme<E, Polynomial = Rc<DenseMultilinearExtension<E::Fr>>>,
PCS: PolynomialCommitmentScheme<E, Polynomial = Arc<DenseMultilinearExtension<E::Fr>>>,
{
let nv = fxs[0].num_vars;
// what's AuxInfo used for?
@ -257,8 +257,8 @@ mod test {
// good path: (w1, w2) is a permutation of (w1, w2) itself under the identify
// map
let ws = vec![
Rc::new(DenseMultilinearExtension::rand(nv, &mut rng)),
Rc::new(DenseMultilinearExtension::rand(nv, &mut rng)),
Arc::new(DenseMultilinearExtension::rand(nv, &mut rng)),
Arc::new(DenseMultilinearExtension::rand(nv, &mut rng)),
];
// perms is the identity map
test_permutation_check_helper::<Bls12_381, KZG>(&pcs_param, &ws, &ws, &id_perms)?;
@ -267,8 +267,8 @@ mod test {
{
// good path: f = (w1, w2) is a permutation of g = (w2, w1) itself under a map
let mut fs = vec![
Rc::new(DenseMultilinearExtension::rand(nv, &mut rng)),
Rc::new(DenseMultilinearExtension::rand(nv, &mut rng)),
Arc::new(DenseMultilinearExtension::rand(nv, &mut rng)),
Arc::new(DenseMultilinearExtension::rand(nv, &mut rng)),
];
let gs = fs.clone();
fs.reverse();
@ -281,8 +281,8 @@ mod test {
{
// bad path 1: w is a not permutation of w itself under a random map
let ws = vec![
Rc::new(DenseMultilinearExtension::rand(nv, &mut rng)),
Rc::new(DenseMultilinearExtension::rand(nv, &mut rng)),
Arc::new(DenseMultilinearExtension::rand(nv, &mut rng)),
Arc::new(DenseMultilinearExtension::rand(nv, &mut rng)),
];
// perms is a random map
let perms = random_permutation_mles(nv, 2, &mut rng);
@ -296,12 +296,12 @@ mod test {
{
// bad path 2: f is a not permutation of g under a identity map
let fs = vec![
Rc::new(DenseMultilinearExtension::rand(nv, &mut rng)),
Rc::new(DenseMultilinearExtension::rand(nv, &mut rng)),
Arc::new(DenseMultilinearExtension::rand(nv, &mut rng)),
Arc::new(DenseMultilinearExtension::rand(nv, &mut rng)),
];
let gs = vec![
Rc::new(DenseMultilinearExtension::rand(nv, &mut rng)),
Rc::new(DenseMultilinearExtension::rand(nv, &mut rng)),
Arc::new(DenseMultilinearExtension::rand(nv, &mut rng)),
Arc::new(DenseMultilinearExtension::rand(nv, &mut rng)),
];
// s_perm is the identity map

+ 8
- 8
subroutines/src/poly_iop/perm_check/util.rs

@ -5,7 +5,7 @@ use arithmetic::identity_permutation_mles;
use ark_ff::PrimeField;
use ark_poly::DenseMultilinearExtension;
use ark_std::{end_timer, start_timer};
use std::rc::Rc;
use std::sync::Arc;
/// Returns the evaluations of two list of MLEs:
/// - numerators = (a1, ..., ak)
@ -24,13 +24,13 @@ use std::rc::Rc;
pub(super) fn computer_nums_and_denoms<F: PrimeField>(
beta: &F,
gamma: &F,
fxs: &[Rc<DenseMultilinearExtension<F>>],
gxs: &[Rc<DenseMultilinearExtension<F>>],
perms: &[Rc<DenseMultilinearExtension<F>>],
fxs: &[Arc<DenseMultilinearExtension<F>>],
gxs: &[Arc<DenseMultilinearExtension<F>>],
perms: &[Arc<DenseMultilinearExtension<F>>],
) -> Result<
(
Vec<Rc<DenseMultilinearExtension<F>>>,
Vec<Rc<DenseMultilinearExtension<F>>>,
Vec<Arc<DenseMultilinearExtension<F>>>,
Vec<Arc<DenseMultilinearExtension<F>>>,
),
PolyIOPErrors,
> {
@ -54,11 +54,11 @@ pub(super) fn computer_nums_and_denoms(
numerator_evals.push(numerator);
denominator_evals.push(denominator);
}
numerators.push(Rc::new(DenseMultilinearExtension::from_evaluations_vec(
numerators.push(Arc::new(DenseMultilinearExtension::from_evaluations_vec(
num_vars,
numerator_evals,
)));
denominators.push(Rc::new(DenseMultilinearExtension::from_evaluations_vec(
denominators.push(Arc::new(DenseMultilinearExtension::from_evaluations_vec(
num_vars,
denominator_evals,
)));

+ 13
- 13
subroutines/src/poly_iop/prod_check/mod.rs

@ -14,7 +14,7 @@ use ark_ec::PairingEngine;
use ark_ff::{One, PrimeField, Zero};
use ark_poly::DenseMultilinearExtension;
use ark_std::{end_timer, start_timer};
use std::rc::Rc;
use std::sync::Arc;
use transcript::IOPTranscript;
mod util;
@ -142,7 +142,7 @@ pub struct ProductCheckProof<
impl<E, PCS> ProductCheck<E, PCS> for PolyIOP<E::Fr>
where
E: PairingEngine,
PCS: PolynomialCommitmentScheme<E, Polynomial = Rc<DenseMultilinearExtension<E::Fr>>>,
PCS: PolynomialCommitmentScheme<E, Polynomial = Arc<DenseMultilinearExtension<E::Fr>>>,
{
type ProductCheckSubClaim = ProductCheckSubClaim<E::Fr, Self>;
type ProductCheckProof = ProductCheckProof<E, PCS, Self>;
@ -257,12 +257,12 @@ mod test {
use ark_ec::PairingEngine;
use ark_poly::{DenseMultilinearExtension, MultilinearExtension};
use ark_std::test_rng;
use std::{marker::PhantomData, rc::Rc};
use std::{marker::PhantomData, sync::Arc};
fn check_frac_poly<E>(
frac_poly: &Rc<DenseMultilinearExtension<E::Fr>>,
fs: &[Rc<DenseMultilinearExtension<E::Fr>>],
gs: &[Rc<DenseMultilinearExtension<E::Fr>>],
frac_poly: &Arc<DenseMultilinearExtension<E::Fr>>,
fs: &[Arc<DenseMultilinearExtension<E::Fr>>],
gs: &[Arc<DenseMultilinearExtension<E::Fr>>],
) where
E: PairingEngine,
{
@ -285,14 +285,14 @@ mod test {
// fs and gs are guaranteed to have the same product
// fs and hs doesn't have the same product
fn test_product_check_helper<E, PCS>(
fs: &[Rc<DenseMultilinearExtension<E::Fr>>],
gs: &[Rc<DenseMultilinearExtension<E::Fr>>],
hs: &[Rc<DenseMultilinearExtension<E::Fr>>],
fs: &[Arc<DenseMultilinearExtension<E::Fr>>],
gs: &[Arc<DenseMultilinearExtension<E::Fr>>],
hs: &[Arc<DenseMultilinearExtension<E::Fr>>],
pcs_param: &PCS::ProverParam,
) -> Result<(), PolyIOPErrors>
where
E: PairingEngine,
PCS: PolynomialCommitmentScheme<E, Polynomial = Rc<DenseMultilinearExtension<E::Fr>>>,
PCS: PolynomialCommitmentScheme<E, Polynomial = Arc<DenseMultilinearExtension<E::Fr>>>,
{
let mut transcript = <PolyIOP<E::Fr> as ProductCheck<E, PCS>>::init_transcript();
transcript.append_message(b"testing", b"initializing transcript for testing")?;
@ -352,11 +352,11 @@ mod test {
let f2: DenseMultilinearExtension<Fr> = DenseMultilinearExtension::rand(nv, &mut rng);
let mut g2 = f2.clone();
g2.evaluations.reverse();
let fs = vec![Rc::new(f1), Rc::new(f2)];
let gs = vec![Rc::new(g2), Rc::new(g1)];
let fs = vec![Arc::new(f1), Arc::new(f2)];
let gs = vec![Arc::new(g2), Arc::new(g1)];
let mut hs = vec![];
for _ in 0..fs.len() {
hs.push(Rc::new(DenseMultilinearExtension::rand(
hs.push(Arc::new(DenseMultilinearExtension::rand(
fs[0].num_vars,
&mut rng,
)));

+ 14
- 14
subroutines/src/poly_iop/prod_check/util.rs

@ -5,7 +5,7 @@ use arithmetic::{get_index, VirtualPolynomial};
use ark_ff::PrimeField;
use ark_poly::DenseMultilinearExtension;
use ark_std::{end_timer, start_timer};
use std::rc::Rc;
use std::sync::Arc;
use transcript::IOPTranscript;
/// Compute multilinear fractional polynomial s.t. frac(x) = f1(x) * ... * fk(x)
@ -14,9 +14,9 @@ use transcript::IOPTranscript;
/// The caller needs to sanity-check that the number of polynomials and
/// variables match in fxs and gxs; and gi(x) has no zero entries.
pub(super) fn compute_frac_poly<F: PrimeField>(
fxs: &[Rc<DenseMultilinearExtension<F>>],
gxs: &[Rc<DenseMultilinearExtension<F>>],
) -> Result<Rc<DenseMultilinearExtension<F>>, PolyIOPErrors> {
fxs: &[Arc<DenseMultilinearExtension<F>>],
gxs: &[Arc<DenseMultilinearExtension<F>>],
) -> Result<Arc<DenseMultilinearExtension<F>>, PolyIOPErrors> {
let start = start_timer!(|| "compute frac(x)");
let mut f_evals = vec![F::one(); 1 << fxs[0].num_vars];
@ -41,7 +41,7 @@ pub(super) fn compute_frac_poly(
}
end_timer!(start);
Ok(Rc::new(DenseMultilinearExtension::from_evaluations_vec(
Ok(Arc::new(DenseMultilinearExtension::from_evaluations_vec(
fxs[0].num_vars,
f_evals,
)))
@ -55,8 +55,8 @@ pub(super) fn compute_frac_poly(
/// The caller needs to check num_vars matches in f and g
/// Cost: linear in N.
pub(super) fn compute_product_poly<F: PrimeField>(
frac_poly: &Rc<DenseMultilinearExtension<F>>,
) -> Result<Rc<DenseMultilinearExtension<F>>, PolyIOPErrors> {
frac_poly: &Arc<DenseMultilinearExtension<F>>,
) -> Result<Arc<DenseMultilinearExtension<F>>, PolyIOPErrors> {
let start = start_timer!(|| "compute evaluations of prod polynomial");
let num_vars = frac_poly.num_vars;
let frac_evals = &frac_poly.evaluations;
@ -96,7 +96,7 @@ pub(super) fn compute_product_poly(
prod_x_evals.push(F::zero());
end_timer!(start);
Ok(Rc::new(DenseMultilinearExtension::from_evaluations_vec(
Ok(Arc::new(DenseMultilinearExtension::from_evaluations_vec(
num_vars,
prod_x_evals,
)))
@ -111,10 +111,10 @@ pub(super) fn compute_product_poly(
///
/// Cost: O(N)
pub(super) fn prove_zero_check<F: PrimeField>(
fxs: &[Rc<DenseMultilinearExtension<F>>],
gxs: &[Rc<DenseMultilinearExtension<F>>],
frac_poly: &Rc<DenseMultilinearExtension<F>>,
prod_x: &Rc<DenseMultilinearExtension<F>>,
fxs: &[Arc<DenseMultilinearExtension<F>>],
gxs: &[Arc<DenseMultilinearExtension<F>>],
frac_poly: &Arc<DenseMultilinearExtension<F>>,
prod_x: &Arc<DenseMultilinearExtension<F>>,
alpha: &F,
transcript: &mut IOPTranscript<F>,
) -> Result<(IOPProof<F>, VirtualPolynomial<F>), PolyIOPErrors> {
@ -135,10 +135,10 @@ pub(super) fn prove_zero_check(
p2_evals[x] = prod_x.evaluations[x1];
}
}
let p1 = Rc::new(DenseMultilinearExtension::from_evaluations_vec(
let p1 = Arc::new(DenseMultilinearExtension::from_evaluations_vec(
num_vars, p1_evals,
));
let p2 = Rc::new(DenseMultilinearExtension::from_evaluations_vec(
let p2 = Arc::new(DenseMultilinearExtension::from_evaluations_vec(
num_vars, p2_evals,
));

+ 4
- 4
subroutines/src/poly_iop/sum_check/mod.rs

@ -9,7 +9,7 @@ use arithmetic::{VPAuxInfo, VirtualPolynomial};
use ark_ff::PrimeField;
use ark_poly::DenseMultilinearExtension;
use ark_std::{end_timer, start_timer};
use std::{fmt::Debug, rc::Rc};
use std::{fmt::Debug, sync::Arc};
use transcript::IOPTranscript;
mod prover;
@ -127,7 +127,7 @@ impl SumCheck for PolyIOP {
type SumCheckProof = IOPProof<F>;
type VirtualPolynomial = VirtualPolynomial<F>;
type VPAuxInfo = VPAuxInfo<F>;
type MultilinearExtension = Rc<DenseMultilinearExtension<F>>;
type MultilinearExtension = Arc<DenseMultilinearExtension<F>>;
type SumCheckSubClaim = SumCheckSubClaim<F>;
type Transcript = IOPTranscript<F>;
@ -210,7 +210,7 @@ mod test {
use ark_ff::UniformRand;
use ark_poly::{DenseMultilinearExtension, MultilinearExtension};
use ark_std::test_rng;
use std::rc::Rc;
use std::sync::Arc;
fn test_sumcheck(
nv: usize,
@ -326,7 +326,7 @@ mod test {
fn test_shared_reference() -> Result<(), PolyIOPErrors> {
let mut rng = test_rng();
let ml_extensions: Vec<_> = (0..5)
.map(|_| Rc::new(DenseMultilinearExtension::<Fr>::rand(8, &mut rng)))
.map(|_| Arc::new(DenseMultilinearExtension::<Fr>::rand(8, &mut rng)))
.collect();
let mut poly = VirtualPolynomial::new(8);
poly.add_mle_list(

+ 6
- 3
subroutines/src/poly_iop/sum_check/prover.rs

@ -10,7 +10,7 @@ use ark_ff::PrimeField;
use ark_poly::DenseMultilinearExtension;
use ark_std::{end_timer, start_timer, vec::Vec};
use rayon::prelude::IntoParallelIterator;
use std::rc::Rc;
use std::sync::Arc;
#[cfg(feature = "parallel")]
use rayon::iter::{IntoParallelRefMutIterator, ParallelIterator};
@ -138,7 +138,7 @@ impl SumCheckProver for IOPProverState {
}
} else {
for (t, e) in products_sum.iter_mut().enumerate() {
let t = F::from(t as u64);
let t = F::from(t as u128);
let products = (0..1 << (self.poly.aux_info.num_variables - self.round))
.into_par_iter()
.map(|b| {
@ -149,6 +149,9 @@ impl SumCheckProver for IOPProverState {
let mut product = *coefficient;
for &f in products.iter().take(num_mles) {
let table = &flattened_ml_extensions[f]; // f's range is checked in init
// TODO: Could be done faster by cashing the results from the
// previous t and adding the diff
// Also possible to use Karatsuba multiplication
product *=
table[b << 1] + (table[(b << 1) + 1] - table[b << 1]) * t;
}
@ -188,7 +191,7 @@ impl SumCheckProver for IOPProverState {
// update prover's state to the partial evaluated polynomial
self.poly.flattened_ml_extensions = flattened_ml_extensions
.iter()
.map(|x| Rc::new(x.clone()))
.map(|x| Arc::new(x.clone()))
.collect();
// end_timer!(compute_sum);

Loading…
Cancel
Save