From bca3070a37f10924af15281cdf285911d78b2e91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Sun, 11 Feb 2024 10:47:31 -0500 Subject: [PATCH 1/5] test: POlyEvalWitness batch --- Cargo.toml | 7 ++++--- src/r1cs/mod.rs | 1 - src/spartan/mod.rs | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 108d6e253..56a023123 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,10 +40,10 @@ abomonation_derive = { version = "0.1.0", package = "abomonation_derive_ng" } tracing = "0.1.37" cfg-if = "1.0.0" once_cell = "1.18.0" -itertools = "0.12.0" +itertools = "0.12.0" # zip_eq rand = "0.8.5" -ref-cast = "1.0.20" -derive_more = "0.99.17" +ref-cast = "1.0.20" # allocation-less conversion in multilinear polys +derive_more = "0.99.17" # lightens impl macros for pasta static_assertions = "1.1.0" [target.'cfg(any(target_arch = "x86_64", target_arch = "aarch64"))'.dependencies] @@ -57,6 +57,7 @@ getrandom = { version = "0.2.0", default-features = false, features = ["js"] } [target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] proptest = "1.2.0" +proptest-derive = "0.4.0" pprof = { version = "0.13" } criterion = { version = "0.5", features = ["html_reports"] } diff --git a/src/r1cs/mod.rs b/src/r1cs/mod.rs index b4085e76f..caf336ecb 100644 --- a/src/r1cs/mod.rs +++ b/src/r1cs/mod.rs @@ -1,6 +1,5 @@ //! This module defines R1CS related types and a folding scheme for Relaxed R1CS mod sparse; -#[cfg(test)] pub(crate) mod util; use crate::{ diff --git a/src/spartan/mod.rs b/src/spartan/mod.rs index 3df202b1c..1ff49b71a 100644 --- a/src/spartan/mod.rs +++ b/src/spartan/mod.rs @@ -24,6 +24,7 @@ use crate::{ use ff::Field; use itertools::Itertools as _; use polys::multilinear::SparsePolynomial; + use rayon::{iter::IntoParallelRefIterator, prelude::*}; // Creates a vector of the first `n` powers of `s`. @@ -225,3 +226,51 @@ fn compute_eval_table_sparse( (A_evals, B_evals, C_evals) } + +#[cfg(all(test, not(target_arch = "wasm32")))] +mod tests { + use proptest::prelude::*; + use crate::r1cs::util::FWrap; + use proptest::collection::vec; + use pasta_curves::Fq as Scalar; + use crate::provider::PallasEngine; + use super::*; + + + + proptest!{ + #[test] + fn test_pe_witness_batch_diff_size_batch( + s in any::>(), + vecs in (50usize..100).prop_flat_map(|size| vec( + vec(any::>().prop_map(|f| f.0), size..=size), // even-sized vec + 1..5)) + ) + { + // when the vectors are the same size, batch_diff_size and batch agree + let res = PolyEvalWitness::::batch(&vecs.iter().by_ref().collect::>(), &s.0); + let witnesses = vecs.into_iter().map(|v| PolyEvalWitness{ p: v}).collect::>>(); + let res2 = PolyEvalWitness::::batch_diff_size(witnesses, s.0); + + prop_assert_eq!(res.p, res2.p); + } + + #[test] + fn test_pe_witness_batch_diff_size_pad_batch( + s in any::>(), + vecs in (50usize..100).prop_flat_map(|size| vec( + vec(any::>().prop_map(|f| f.0), size-10..=size), // even-sized vec + 1..10)) + ) + { + let size = vecs.iter().map(|v| v.len()).max().unwrap_or(0); + // when the vectors are not the same size, batch agrees with the padded version of the input + let padded_vecs = vecs.iter().cloned().map(|mut v| {v.resize(size, Scalar::ZERO); v}).collect::>(); + let res = PolyEvalWitness::::batch(&padded_vecs.iter().by_ref().collect::>(), &s.0); + let witnesses = vecs.into_iter().map(|v| PolyEvalWitness{ p: v}).collect::>>(); + let res2 = PolyEvalWitness::::batch_diff_size(witnesses, s.0); + + prop_assert_eq!(res.p, res2.p); + } + } +} From ee01322c0026a686929b01315f91db9e4b760bc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Sun, 11 Feb 2024 11:53:10 -0500 Subject: [PATCH 2/5] test: PolyEvalInstance batch --- Cargo.toml | 5 +++-- src/r1cs/util.rs | 23 +++++++++++++++++++++++ src/spartan/mod.rs | 46 ++++++++++++++++++++++++++++++++++++---------- 3 files changed, 62 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 56a023123..c2520c2c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,9 +55,10 @@ grumpkin-msm = { git = "https://github.com/lurk-lab/grumpkin-msm", branch = "dev # see https://github.com/rust-random/rand/pull/948 getrandom = { version = "0.2.0", default-features = false, features = ["js"] } -[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] proptest = "1.2.0" -proptest-derive = "0.4.0" + +[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] pprof = { version = "0.13" } criterion = { version = "0.5", features = ["html_reports"] } diff --git a/src/r1cs/util.rs b/src/r1cs/util.rs index fe97462fc..f082a1c1e 100644 --- a/src/r1cs/util.rs +++ b/src/r1cs/util.rs @@ -24,3 +24,26 @@ impl Arbitrary for FWrap { strategy.boxed() } } + +/// Wrapper struct around a Group element that implements additional traits +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct GWrap(pub G); + +impl Copy for GWrap {} + +#[cfg(not(target_arch = "wasm32"))] +/// Trait implementation for generating `GWrap` instances with proptest +impl Arbitrary for GWrap { + type Parameters = (); + type Strategy = BoxedStrategy; + + fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { + use rand::rngs::StdRng; + use rand_core::SeedableRng; + + let strategy = any::<[u8; 32]>() + .prop_map(|seed| Self(G::random(StdRng::from_seed(seed)))) + .no_shrink(); + strategy.boxed() + } +} diff --git a/src/spartan/mod.rs b/src/spartan/mod.rs index 1ff49b71a..07d90820f 100644 --- a/src/spartan/mod.rs +++ b/src/spartan/mod.rs @@ -151,15 +151,14 @@ impl PolyEvalInstance { // vᵢ = L₀(x_lo)⋅Pᵢ(x_hi) lagrange_eval * eval - }) - .collect::>(); + }); // C = ∑ᵢ γⁱ⋅Cᵢ let comm_joint = zip_with!(iter, (c_vec, powers), |c, g_i| *c * *g_i) .fold(Commitment::::default(), |acc, item| acc + item); // v = ∑ᵢ γⁱ⋅vᵢ - let eval_joint = zip_with!((evals_scaled.into_iter(), powers.iter()), |e, g_i| e * g_i).sum(); + let eval_joint = zip_with!((evals_scaled, powers.iter()), |e, g_i| e * g_i).sum(); Self { c: comm_joint, @@ -229,14 +228,13 @@ fn compute_eval_table_sparse( #[cfg(all(test, not(target_arch = "wasm32")))] mod tests { - use proptest::prelude::*; - use crate::r1cs::util::FWrap; - use proptest::collection::vec; - use pasta_curves::Fq as Scalar; - use crate::provider::PallasEngine; use super::*; - - + use crate::provider::PallasEngine; + use crate::r1cs::util::{FWrap, GWrap}; + use pasta_curves::pallas::Point as PallasPoint; + use pasta_curves::Fq as Scalar; + use proptest::collection::vec; + use proptest::prelude::*; proptest!{ #[test] @@ -272,5 +270,33 @@ mod tests { prop_assert_eq!(res.p, res2.p); } + + #[test] + fn test_pe_instance_batch_diff_size_batch( + s in any::>(), + vecs_tuple in (50usize..100).prop_flat_map(|size| + (vec(any::>().prop_map(|f| f.0), size..=size), + vec(any::>().prop_map(|f| f.0), size..=size), + vec(any::>().prop_map(|f| f.0), size..=size) + ), // even-sized vecs + ) + ) + { + let (c_vec, e_vec, x_vec) = vecs_tuple; + let c_vecs = c_vec.into_iter().map(|c| Commitment::{ comm: c }).collect::>(); + // when poly evals are all for the max # of variables, batch_diff_size and batch agree + let res = PolyEvalInstance::::batch( + &c_vecs, + &x_vec, + &e_vec, + &s.0); + + let sizes = vec![x_vec.len(); x_vec.len()]; + let res2 = PolyEvalInstance::::batch_diff_size(&c_vecs, &e_vec, &sizes, x_vec.clone(), s.0); + + prop_assert_eq!(res.c, res2.c); + prop_assert_eq!(res.x, res2.x); + prop_assert_eq!(res.e, res2.e); + } } } From aedae9c86813599b505cf8799b82bd653bc53060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Sun, 11 Feb 2024 11:55:53 -0500 Subject: [PATCH 3/5] chore: C-CALLER-CONTROL --- src/spartan/batched_ppsnark.rs | 4 ++-- src/spartan/mod.rs | 6 +++--- src/spartan/ppsnark.rs | 10 ++++++---- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/spartan/batched_ppsnark.rs b/src/spartan/batched_ppsnark.rs index 0fe410e61..897a72fb2 100644 --- a/src/spartan/batched_ppsnark.rs +++ b/src/spartan/batched_ppsnark.rs @@ -375,7 +375,7 @@ impl> BatchedRelaxedR1CSSNARKTrait |comm_Az_Bz_Cz, evals_Az_Bz_Cz_at_tau| { let u = PolyEvalInstance::::batch( comm_Az_Bz_Cz.as_slice(), - &[], // ignored by the function + vec![], // ignored by the function evals_Az_Bz_Cz_at_tau.as_slice(), &c, ); @@ -819,7 +819,7 @@ impl> BatchedRelaxedR1CSSNARKTrait |comm_Az_Bz_Cz, evals_Az_Bz_Cz_at_tau| { let u = PolyEvalInstance::::batch( comm_Az_Bz_Cz.as_slice(), - &tau_coords, + tau_coords.clone(), evals_Az_Bz_Cz_at_tau.as_slice(), &c, ); diff --git a/src/spartan/mod.rs b/src/spartan/mod.rs index 07d90820f..62a6d0e79 100644 --- a/src/spartan/mod.rs +++ b/src/spartan/mod.rs @@ -167,7 +167,7 @@ impl PolyEvalInstance { } } - fn batch(c_vec: &[Commitment], x: &[E::Scalar], e_vec: &[E::Scalar], s: &E::Scalar) -> Self { + fn batch(c_vec: &[Commitment], x: Vec, e_vec: &[E::Scalar], s: &E::Scalar) -> Self { let num_instances = c_vec.len(); assert_eq!(e_vec.len(), num_instances); @@ -180,7 +180,7 @@ impl PolyEvalInstance { Self { c, - x: x.to_vec(), + x, e, } } @@ -287,7 +287,7 @@ mod tests { // when poly evals are all for the max # of variables, batch_diff_size and batch agree let res = PolyEvalInstance::::batch( &c_vecs, - &x_vec, + x_vec.clone(), &e_vec, &s.0); diff --git a/src/spartan/ppsnark.rs b/src/spartan/ppsnark.rs index 56edc70e6..dc75dbbac 100644 --- a/src/spartan/ppsnark.rs +++ b/src/spartan/ppsnark.rs @@ -580,7 +580,8 @@ impl> RelaxedR1CSSNARKTrait for Relax let poly_vec = vec![&Az, &Bz, &Cz]; let c = transcript.squeeze(b"c")?; let w: PolyEvalWitness = PolyEvalWitness::batch(&poly_vec, &c); - let u: PolyEvalInstance = PolyEvalInstance::batch(&comm_vec, &tau_coords, &eval_vec, &c); + let u: PolyEvalInstance = + PolyEvalInstance::batch(&comm_vec, tau_coords.clone(), &eval_vec, &c); // we now need to prove three claims // (1) 0 = \sum_x poly_tau(x) * (poly_Az(x) * poly_Bz(x) - poly_uCz_E(x)), and eval_Az_at_tau + r * eval_Bz_at_tau + r^2 * eval_Cz_at_tau = (Az+r*Bz+r^2*Cz)(tau) @@ -769,7 +770,7 @@ impl> RelaxedR1CSSNARKTrait for Relax transcript.absorb(b"e", &eval_vec.as_slice()); // comm_vec is already in the transcript let c = transcript.squeeze(b"c")?; let w: PolyEvalWitness = PolyEvalWitness::batch(&poly_vec, &c); - let u: PolyEvalInstance = PolyEvalInstance::batch(&comm_vec, &rand_sc, &eval_vec, &c); + let u: PolyEvalInstance = PolyEvalInstance::batch(&comm_vec, rand_sc.clone(), &eval_vec, &c); let eval_arg = EE::prove(ck, &pk.pk_ee, &mut transcript, &u.c, &w.p, &rand_sc, &u.e)?; @@ -855,7 +856,8 @@ impl> RelaxedR1CSSNARKTrait for Relax transcript.absorb(b"e", &vec![comm_L_row, comm_L_col].as_slice()); let comm_vec = vec![comm_Az, comm_Bz, comm_Cz]; let c = transcript.squeeze(b"c")?; - let u: PolyEvalInstance = PolyEvalInstance::batch(&comm_vec, &tau_coords, &eval_vec, &c); + let u: PolyEvalInstance = + PolyEvalInstance::batch(&comm_vec, tau_coords.clone(), &eval_vec, &c); let claim = u.e; let gamma = transcript.squeeze(b"g")?; @@ -1032,7 +1034,7 @@ impl> RelaxedR1CSSNARKTrait for Relax ]; transcript.absorb(b"e", &eval_vec.as_slice()); // comm_vec is already in the transcript let c = transcript.squeeze(b"c")?; - let u: PolyEvalInstance = PolyEvalInstance::batch(&comm_vec, &rand_sc, &eval_vec, &c); + let u: PolyEvalInstance = PolyEvalInstance::batch(&comm_vec, rand_sc.clone(), &eval_vec, &c); // verify EE::verify( From 37faf82a4161d1770799b5ec8f58c35c84b4039e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Sun, 11 Feb 2024 12:31:05 -0500 Subject: [PATCH 4/5] refactor: shrink batching code --- src/spartan/batched_ppsnark.rs | 3 +- src/spartan/mod.rs | 167 +++++++++++++++++++-------------- src/spartan/snark.rs | 2 +- 3 files changed, 99 insertions(+), 73 deletions(-) diff --git a/src/spartan/batched_ppsnark.rs b/src/spartan/batched_ppsnark.rs index 897a72fb2..717e91f55 100644 --- a/src/spartan/batched_ppsnark.rs +++ b/src/spartan/batched_ppsnark.rs @@ -701,7 +701,8 @@ impl> BatchedRelaxedR1CSSNARKTrait let num_vars_u = w_vec.iter().map(|w| w.p.len().log_2()).collect::>(); let u_batch = PolyEvalInstance::::batch_diff_size(&comms_vec, &evals_vec, &num_vars_u, rand_sc, c); - let w_batch = PolyEvalWitness::::batch_diff_size(w_vec, c); + let w_batch = + PolyEvalWitness::::batch_diff_size(&w_vec.iter().by_ref().collect::>(), c); let eval_arg = EE::prove( ck, diff --git a/src/spartan/mod.rs b/src/spartan/mod.rs index 62a6d0e79..f83f6698b 100644 --- a/src/spartan/mod.rs +++ b/src/spartan/mod.rs @@ -26,6 +26,7 @@ use itertools::Itertools as _; use polys::multilinear::SparsePolynomial; use rayon::{iter::IntoParallelRefIterator, prelude::*}; +use ref_cast::RefCast; // Creates a vector of the first `n` powers of `s`. fn powers(s: &E::Scalar, n: usize) -> Vec { @@ -36,7 +37,8 @@ fn powers(s: &E::Scalar, n: usize) -> Vec { } /// A type that holds a witness to a polynomial evaluation instance -#[derive(Debug)] +#[repr(transparent)] +#[derive(Debug, RefCast)] struct PolyEvalWitness { p: Vec, // polynomial } @@ -48,39 +50,43 @@ impl PolyEvalWitness { /// /// We allow the input polynomials to have different sizes, and interpret smaller ones as /// being padded with 0 to the maximum size of all polynomials. - fn batch_diff_size(W: Vec, s: E::Scalar) -> Self { + fn batch_diff_size(W: &[&Self], s: E::Scalar) -> Self { let powers = powers::(&s, W.len()); let size_max = W.iter().map(|w| w.p.len()).max().unwrap(); + let p_vec = W.par_iter().map(|w| &w.p); // Scale the input polynomials by the power of s - let p = W - .into_par_iter() - .zip_eq(powers.par_iter()) - .map(|(mut w, s)| { - if *s != E::Scalar::ONE { - w.p.par_iter_mut().for_each(|e| *e *= s); - } - w.p - }) - .reduce( - || vec![E::Scalar::ZERO; size_max], - |left, right| { - // Sum into the largest polynomial - let (mut big, small) = if left.len() > right.len() { - (left, right) + let p = zip_with!((p_vec, powers.par_iter()), |v, weight| { + // compute the weighted sum for each vector + v.iter() + .map(|&x| { + if *weight != E::Scalar::ONE { + x * *weight } else { - (right, left) - }; - - #[allow(clippy::disallowed_methods)] - big - .par_iter_mut() - .zip(small.par_iter()) - .for_each(|(b, s)| *b += s); - - big - }, - ); + x + } + }) + .collect::>() + }) + .reduce( + || vec![E::Scalar::ZERO; size_max], + |left, right| { + // Sum into the largest polynomial + let (mut big, small) = if left.len() > right.len() { + (left, right) + } else { + (right, left) + }; + + #[allow(clippy::disallowed_methods)] + big + .par_iter_mut() + .zip(small.par_iter()) + .for_each(|(b, s)| *b += s); + + big + }, + ); Self { p } } @@ -96,22 +102,8 @@ impl PolyEvalWitness { .iter() .skip(1) .for_each(|p| assert_eq!(p.len(), p_vec[0].len())); - - let powers_of_s = powers::(s, p_vec.len()); - - let p = zip_with!(par_iter, (p_vec, powers_of_s), |v, weight| { - // compute the weighted sum for each vector - v.iter().map(|&x| x * *weight).collect::>() - }) - .reduce( - || vec![E::Scalar::ZERO; p_vec[0].len()], - |acc, v| { - // perform vector addition to combine the weighted vectors - acc.into_iter().zip_eq(v).map(|(x, y)| x + y).collect() - }, - ); - - Self { p } + let instances = p_vec.iter().map(|p| Self::ref_cast(p)).collect::>(); + Self::batch_diff_size(&instances, *s) } } @@ -168,21 +160,8 @@ impl PolyEvalInstance { } fn batch(c_vec: &[Commitment], x: Vec, e_vec: &[E::Scalar], s: &E::Scalar) -> Self { - let num_instances = c_vec.len(); - assert_eq!(e_vec.len(), num_instances); - - let powers_of_s = powers::(s, num_instances); - // Weighted sum of evaluations - let e = zip_with!(par_iter, (e_vec, powers_of_s), |e, p| *e * p).sum(); - // Weighted sum of commitments - let c = zip_with!(par_iter, (c_vec, powers_of_s), |c, p| *c * *p) - .reduce(Commitment::::default, |acc, item| acc + item); - - Self { - c, - x, - e, - } + let sizes = vec![x.len(); e_vec.len()]; + Self::batch_diff_size(c_vec, e_vec, &sizes, x, *s) } } @@ -236,7 +215,53 @@ mod tests { use proptest::collection::vec; use proptest::prelude::*; - proptest!{ + impl PolyEvalWitness { + fn alt_batch(p_vec: &[&Vec], s: &E::Scalar) -> Self { + p_vec + .iter() + .skip(1) + .for_each(|p| assert_eq!(p.len(), p_vec[0].len())); + + let powers_of_s = powers::(s, p_vec.len()); + + let p = zip_with!(par_iter, (p_vec, powers_of_s), |v, weight| { + // compute the weighted sum for each vector + v.iter().map(|&x| x * *weight).collect::>() + }) + .reduce( + || vec![E::Scalar::ZERO; p_vec[0].len()], + |acc, v| { + // perform vector addition to combine the weighted vectors + acc.into_iter().zip_eq(v).map(|(x, y)| x + y).collect() + }, + ); + + Self { p } + } + } + + impl PolyEvalInstance { + fn alt_batch( + c_vec: &[Commitment], + x: Vec, + e_vec: &[E::Scalar], + s: &E::Scalar, + ) -> Self { + let num_instances = c_vec.len(); + assert_eq!(e_vec.len(), num_instances); + + let powers_of_s = powers::(s, num_instances); + // Weighted sum of evaluations + let e = zip_with!(par_iter, (e_vec, powers_of_s), |e, p| *e * p).sum(); + // Weighted sum of commitments + let c = zip_with!(par_iter, (c_vec, powers_of_s), |c, p| *c * *p) + .reduce(Commitment::::default, |acc, item| acc + item); + + Self { c, x, e } + } + } + + proptest! { #[test] fn test_pe_witness_batch_diff_size_batch( s in any::>(), @@ -246,9 +271,9 @@ mod tests { ) { // when the vectors are the same size, batch_diff_size and batch agree - let res = PolyEvalWitness::::batch(&vecs.iter().by_ref().collect::>(), &s.0); - let witnesses = vecs.into_iter().map(|v| PolyEvalWitness{ p: v}).collect::>>(); - let res2 = PolyEvalWitness::::batch_diff_size(witnesses, s.0); + let res = PolyEvalWitness::::alt_batch(&vecs.iter().by_ref().collect::>(), &s.0); + let witnesses = vecs.iter().map(PolyEvalWitness::ref_cast).collect::>(); + let res2 = PolyEvalWitness::::batch_diff_size(&witnesses, s.0); prop_assert_eq!(res.p, res2.p); } @@ -264,9 +289,9 @@ mod tests { let size = vecs.iter().map(|v| v.len()).max().unwrap_or(0); // when the vectors are not the same size, batch agrees with the padded version of the input let padded_vecs = vecs.iter().cloned().map(|mut v| {v.resize(size, Scalar::ZERO); v}).collect::>(); - let res = PolyEvalWitness::::batch(&padded_vecs.iter().by_ref().collect::>(), &s.0); - let witnesses = vecs.into_iter().map(|v| PolyEvalWitness{ p: v}).collect::>>(); - let res2 = PolyEvalWitness::::batch_diff_size(witnesses, s.0); + let res = PolyEvalWitness::::alt_batch(&padded_vecs.iter().by_ref().collect::>(), &s.0); + let witnesses = vecs.iter().map(PolyEvalWitness::ref_cast).collect::>(); + let res2 = PolyEvalWitness::::batch_diff_size(&witnesses, s.0); prop_assert_eq!(res.p, res2.p); } @@ -285,10 +310,10 @@ mod tests { let (c_vec, e_vec, x_vec) = vecs_tuple; let c_vecs = c_vec.into_iter().map(|c| Commitment::{ comm: c }).collect::>(); // when poly evals are all for the max # of variables, batch_diff_size and batch agree - let res = PolyEvalInstance::::batch( - &c_vecs, - x_vec.clone(), - &e_vec, + let res = PolyEvalInstance::::alt_batch( + &c_vecs, + x_vec.clone(), + &e_vec, &s.0); let sizes = vec![x_vec.len(); x_vec.len()]; diff --git a/src/spartan/snark.rs b/src/spartan/snark.rs index 5e8a8c1ac..1b4412d5a 100644 --- a/src/spartan/snark.rs +++ b/src/spartan/snark.rs @@ -493,7 +493,7 @@ pub(in crate::spartan) fn batch_eval_prove( PolyEvalInstance::batch_diff_size(&comms, &claims_batch_left, &num_rounds, r, gamma); // P = ∑ᵢ γⁱ⋅Pᵢ - let w_joint = PolyEvalWitness::batch_diff_size(w_vec, gamma); + let w_joint = PolyEvalWitness::batch_diff_size(&w_vec.iter().by_ref().collect::>(), gamma); Ok((u_joint, w_joint, sc_proof_batch, claims_batch_left)) } From 8a63a3acab9cbaddc320b50a69b4290eaaca9498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Sun, 11 Feb 2024 16:02:07 -0500 Subject: [PATCH 5/5] chore: clippy --- src/r1cs/util.rs | 1 + src/spartan/batched.rs | 2 +- src/spartan/snark.rs | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/r1cs/util.rs b/src/r1cs/util.rs index f082a1c1e..2f0e77f58 100644 --- a/src/r1cs/util.rs +++ b/src/r1cs/util.rs @@ -1,4 +1,5 @@ use ff::PrimeField; +use group::Group; #[cfg(not(target_arch = "wasm32"))] use proptest::prelude::*; diff --git a/src/spartan/batched.rs b/src/spartan/batched.rs index 8ad0b908e..a72de8410 100644 --- a/src/spartan/batched.rs +++ b/src/spartan/batched.rs @@ -347,7 +347,7 @@ impl> BatchedRelaxedR1CSSNARKTrait }; let (batched_u, batched_w, sc_proof_batch, claims_batch_left) = - batch_eval_prove(u_vec, w_vec, &mut transcript)?; + batch_eval_prove(u_vec, &w_vec, &mut transcript)?; let eval_arg = EE::prove( ck, diff --git a/src/spartan/snark.rs b/src/spartan/snark.rs index 1b4412d5a..81f23e9a2 100644 --- a/src/spartan/snark.rs +++ b/src/spartan/snark.rs @@ -245,7 +245,7 @@ impl> RelaxedR1CSSNARKTrait for Relax ]; let (batched_u, batched_w, sc_proof_batch, claims_batch_left) = - batch_eval_prove(u_vec, w_vec, &mut transcript)?; + batch_eval_prove(u_vec, &w_vec, &mut transcript)?; let eval_arg = EE::prove( ck, @@ -428,7 +428,7 @@ impl> RelaxedR1CSSNARKTrait for Relax /// the claims and resulting evaluations from Sumcheck. pub(in crate::spartan) fn batch_eval_prove( u_vec: Vec>, - w_vec: Vec>, + w_vec: &[PolyEvalWitness], transcript: &mut E::TE, ) -> Result< (