From bee67686d07682185ee78bdd492f7f8391a817bb Mon Sep 17 00:00:00 2001 From: Charles Chen Date: Wed, 9 Nov 2022 16:30:01 -0500 Subject: [PATCH] remove redundant apis --- arithmetic/src/lib.rs | 5 ++-- arithmetic/src/multilinear_polynomial.rs | 29 ---------------------- hyperplonk/src/mock.rs | 4 +-- hyperplonk/src/snark.rs | 14 ++++++----- subroutines/benches/iop_bench.rs | 31 ++++++++++++------------ 5 files changed, 28 insertions(+), 55 deletions(-) diff --git a/arithmetic/src/lib.rs b/arithmetic/src/lib.rs index b05ee8b..a05acaa 100644 --- a/arithmetic/src/lib.rs +++ b/arithmetic/src/lib.rs @@ -7,9 +7,8 @@ mod virtual_polynomial; pub use errors::ArithErrors; pub use multilinear_polynomial::{ evaluate_no_par, evaluate_opt, fix_last_variables, fix_last_variables_no_par, fix_variables, - identity_permutation_mle, identity_permutation_mles, merge_polynomials, random_mle_list, - random_permutation_mle, random_permutation_mles, random_zero_mle_list, - DenseMultilinearExtension, + identity_permutation_mles, merge_polynomials, random_mle_list, random_permutation_mles, + random_zero_mle_list, DenseMultilinearExtension, }; pub use univariate_polynomial::{build_l, get_uni_domain}; pub use util::{bit_decompose, gen_eval_point, get_batched_nv, get_index}; diff --git a/arithmetic/src/multilinear_polynomial.rs b/arithmetic/src/multilinear_polynomial.rs index 37197ed..cda1247 100644 --- a/arithmetic/src/multilinear_polynomial.rs +++ b/arithmetic/src/multilinear_polynomial.rs @@ -72,35 +72,6 @@ pub fn random_zero_mle_list( list } -/// An MLE that represent an identity permutation: `f(index) \mapto index` -/// TODO(binyi): remove -pub fn identity_permutation_mle( - num_vars: usize, -) -> Rc> { - let s_id_vec = (0..1u64 << num_vars).map(F::from).collect(); - Rc::new(DenseMultilinearExtension::from_evaluations_vec( - num_vars, s_id_vec, - )) -} - -/// An MLE that represent a random permutation -/// TODO(binyi): remove -pub fn random_permutation_mle( - num_vars: usize, - rng: &mut R, -) -> Rc> { - let len = 1u64 << num_vars; - let mut s_id_vec: Vec = (0..len).map(F::from).collect(); - let mut s_perm_vec = vec![]; - for _ in 0..len { - let index = rng.next_u64() as usize % s_id_vec.len(); - s_perm_vec.push(s_id_vec.remove(index)); - } - Rc::new(DenseMultilinearExtension::from_evaluations_vec( - num_vars, s_perm_vec, - )) -} - /// A list of MLEs that represents an identity permutation pub fn identity_permutation_mles( num_vars: usize, diff --git a/hyperplonk/src/mock.rs b/hyperplonk/src/mock.rs index 0833ff2..c605224 100644 --- a/hyperplonk/src/mock.rs +++ b/hyperplonk/src/mock.rs @@ -1,4 +1,4 @@ -use arithmetic::identity_permutation_mle; +use arithmetic::identity_permutation_mles; use ark_ff::PrimeField; use ark_poly::MultilinearExtension; use ark_std::{log2, test_rng}; @@ -93,7 +93,7 @@ impl MockCircuit { gate_func: gate.clone(), }; - let permutation = identity_permutation_mle(merged_nv as usize).to_evaluations(); + let permutation = identity_permutation_mles(merged_nv as usize, 1)[0].to_evaluations(); let index = HyperPlonkIndex { params, permutation, diff --git a/hyperplonk/src/snark.rs b/hyperplonk/src/snark.rs index a7d85b3..a2581aa 100644 --- a/hyperplonk/src/snark.rs +++ b/hyperplonk/src/snark.rs @@ -5,7 +5,7 @@ use crate::{ witness::WitnessColumn, HyperPlonkSNARK, }; -use arithmetic::{evaluate_opt, identity_permutation_mle, merge_polynomials, VPAuxInfo}; +use arithmetic::{evaluate_opt, identity_permutation_mles, merge_polynomials, VPAuxInfo}; use ark_ec::PairingEngine; use ark_poly::DenseMultilinearExtension; use ark_std::{end_timer, log2, start_timer, One, Zero}; @@ -526,8 +526,8 @@ where // we evaluate MLE directly instead of using s_id/s_perm PCS verify // Verification takes n pairings while evaluate takes 2^n field ops. - let s_id = identity_permutation_mle::(perm_check_point.len()); - let s_id_eval = evaluate_opt(&s_id, perm_check_point); + let s_ids = identity_permutation_mles::(perm_check_point.len(), 1); + let s_id_eval = evaluate_opt(&s_ids[0], perm_check_point); let s_perm_eval = evaluate_opt(&vk.permutation_oracle, perm_check_point); let q_x_rec = prod_evals[1] - prod_evals[2] * prod_evals[3] @@ -629,7 +629,7 @@ mod tests { custom_gate::CustomizedGates, selectors::SelectorColumn, structs::HyperPlonkParams, witness::WitnessColumn, }; - use arithmetic::random_permutation_mle; + use arithmetic::random_permutation_mles; use ark_bls12_381::Bls12_381; use ark_std::test_rng; use subroutines::pcs::prelude::MultilinearKzgPCS; @@ -672,7 +672,9 @@ mod tests { num_pub_input, gate_func, }; - let permutation = identity_permutation_mle(merged_nv).evaluations.clone(); + let permutation = identity_permutation_mles(merged_nv, 1)[0] + .evaluations + .clone(); let q1 = SelectorColumn(vec![E::Fr::one(), E::Fr::one(), E::Fr::one(), E::Fr::one()]); let index = HyperPlonkIndex { params, @@ -714,7 +716,7 @@ mod tests { )?; // bad path 1: wrong permutation - let rand_perm: Vec = random_permutation_mle(merged_nv, &mut rng) + let rand_perm: Vec = random_permutation_mles(merged_nv, 1, &mut rng)[0] .evaluations .clone(); let mut bad_index = index.clone(); diff --git a/subroutines/benches/iop_bench.rs b/subroutines/benches/iop_bench.rs index 7547aac..cfd9cbc 100644 --- a/subroutines/benches/iop_bench.rs +++ b/subroutines/benches/iop_bench.rs @@ -1,4 +1,4 @@ -use arithmetic::{identity_permutation_mle, VPAuxInfo, VirtualPolynomial}; +use arithmetic::{identity_permutation_mles, VPAuxInfo, VirtualPolynomial}; use ark_bls12_381::{Bls12_381, Fr}; use ark_poly::{DenseMultilinearExtension, MultilinearExtension}; use ark_std::test_rng; @@ -144,10 +144,10 @@ fn bench_permutation_check() -> Result<(), PolyIOPErrors> { 10 }; - let w = Rc::new(DenseMultilinearExtension::rand(nv, &mut rng)); + let ws = vec![Rc::new(DenseMultilinearExtension::rand(nv, &mut rng))]; - // s_perm is the identity map - let s_perm = identity_permutation_mle(nv); + // identity map + let perms = identity_permutation_mles(nv, 1); let proof = { let start = Instant::now(); @@ -157,9 +157,9 @@ fn bench_permutation_check() -> Result<(), PolyIOPErrors> { let (proof, _q_x) = as PermutationCheck>::prove( &pcs_param, - &w, - &w, - &s_perm, + &ws, + &ws, + &perms, &mut transcript, )?; @@ -218,20 +218,21 @@ fn bench_prod_check() -> Result<(), PolyIOPErrors> { let f: DenseMultilinearExtension = DenseMultilinearExtension::rand(nv, &mut rng); let mut g = f.clone(); g.evaluations.reverse(); - let f = Rc::new(f); - let g = Rc::new(g); + let fs = vec![Rc::new(f)]; + let gs = vec![Rc::new(g)]; let proof = { let start = Instant::now(); let mut transcript = as ProductCheck>::init_transcript(); transcript.append_message(b"testing", b"initializing transcript for testing")?; - let (proof, _prod_x) = as ProductCheck>::prove( - &pcs_param, - &f, - &g, - &mut transcript, - )?; + let (proof, _prod_x, _frac_poly) = + as ProductCheck>::prove( + &pcs_param, + &fs, + &gs, + &mut transcript, + )?; println!( "product check proving time for {} variables: {} ns",