From 2fa1f98cd729967c3e69d3cb75ff3b15015810bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= <4142+huitseeker@users.noreply.github.com> Date: Wed, 13 Mar 2024 13:13:24 -0600 Subject: [PATCH] (easy) Nova forward ports + limit unused visibility for unchecked Sparse Matrix functions (#362) * chore: make unchecked methods private * update benchmark (#313) * cleanup unused visibility modifiers (#314) update doc * install protoco for lurk-rs --------- Co-authored-by: Srinath Setty --- .github/workflows/rust.yml | 1 + benches/compressed-snark.rs | 2 +- src/r1cs/sparse.rs | 8 ++++---- src/spartan/batched.rs | 4 ++-- src/spartan/polys/power.rs | 2 +- src/spartan/ppsnark.rs | 3 ++- src/spartan/snark.rs | 8 ++++---- 7 files changed, 15 insertions(+), 13 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index e8a82d632..ac1dca5d3 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -42,6 +42,7 @@ jobs: uses: lurk-lab/ci-workflows/.github/workflows/check-lurk-compiles.yml@main with: runner: "buildjet-8vcpu-ubuntu-2204" + packages: "pkg-config libssl-dev protobuf-compiler libprotobuf-dev" # Rustfmt, clippy, doctests code-quality: diff --git a/benches/compressed-snark.rs b/benches/compressed-snark.rs index 3efabcdb4..53790df22 100644 --- a/benches/compressed-snark.rs +++ b/benches/compressed-snark.rs @@ -27,7 +27,7 @@ type S1 = arecibo::spartan::snark::RelaxedR1CSSNARK; type S2 = arecibo::spartan::snark::RelaxedR1CSSNARK; // SNARKs with computation commitmnets type SS1 = arecibo::spartan::ppsnark::RelaxedR1CSSNARK; -type SS2 = arecibo::spartan::ppsnark::RelaxedR1CSSNARK; +type SS2 = arecibo::spartan::snark::RelaxedR1CSSNARK; // the computation commitment is not used for the trivial circuit // To run these benchmarks, first download `criterion` with `cargo install cargo-criterion`. // Then `cargo criterion --bench compressed-snark`. The results are located in `target/criterion/data/`. diff --git a/src/r1cs/sparse.rs b/src/r1cs/sparse.rs index d95d0810a..cfe0d483f 100644 --- a/src/r1cs/sparse.rs +++ b/src/r1cs/sparse.rs @@ -164,13 +164,13 @@ impl SparseMatrix { level = "trace", name = "SparseMatrix::multiply_vec_unchecked" )] - pub fn multiply_vec_unchecked(&self, vector: &[F]) -> Vec { + fn multiply_vec_unchecked(&self, vector: &[F]) -> Vec { let mut sink: Vec = Vec::with_capacity(self.indptr.len() - 1); self.multiply_vec_into_unchecked(vector, &mut sink); sink } - pub fn multiply_vec_into_unchecked(&self, vector: &[F], sink: &mut Vec) { + fn multiply_vec_into_unchecked(&self, vector: &[F], sink: &mut Vec) { self .indptr .par_windows(2) @@ -197,7 +197,7 @@ impl SparseMatrix { level = "trace", name = "SparseMatrix::multiply_vec_unchecked" )] - pub fn multiply_witness_unchecked(&self, W: &[F], u: &F, X: &[F]) -> Vec { + fn multiply_witness_unchecked(&self, W: &[F], u: &F, X: &[F]) -> Vec { // preallocate the result vector let mut sink = Vec::with_capacity(self.indptr.len() - 1); self.multiply_witness_into_unchecked(W, u, X, &mut sink); @@ -213,7 +213,7 @@ impl SparseMatrix { /// Multiply by a witness representing a dense vector; uses rayon to parallelize. /// This does not check that the shape of the matrix/vector are compatible. - pub fn multiply_witness_into_unchecked(&self, W: &[F], u: &F, X: &[F], sink: &mut Vec) { + fn multiply_witness_into_unchecked(&self, W: &[F], u: &F, X: &[F], sink: &mut Vec) { let num_vars = W.len(); self .indptr diff --git a/src/spartan/batched.rs b/src/spartan/batched.rs index 60abafe8a..8432cc997 100644 --- a/src/spartan/batched.rs +++ b/src/spartan/batched.rs @@ -17,7 +17,7 @@ use super::{ math::Math, polys::{eq::EqPolynomial, multilinear::MultilinearPolynomial}, powers, - snark::batch_eval_prove, + snark::batch_eval_reduce, sumcheck::SumcheckProof, PolyEvalInstance, PolyEvalWitness, }; @@ -348,7 +348,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_reduce(u_vec, &w_vec, &mut transcript)?; let eval_arg = EE::prove( ck, diff --git a/src/spartan/polys/power.rs b/src/spartan/polys/power.rs index 55bd2a4ad..fc0bb6996 100644 --- a/src/spartan/polys/power.rs +++ b/src/spartan/polys/power.rs @@ -27,7 +27,7 @@ impl PowPolynomial { /// Create powers the following powers of `t`: /// [t^{2^0}, t^{2^1}, ..., t^{2^{ell-1}}] - pub(in crate::spartan) fn squares(t: &Scalar, ell: usize) -> Vec { + pub fn squares(t: &Scalar, ell: usize) -> Vec { successors(Some(*t), |p: &Scalar| Some(p.square())) .take(ell) .collect::>() diff --git a/src/spartan/ppsnark.rs b/src/spartan/ppsnark.rs index 711f80039..aba5a98be 100644 --- a/src/spartan/ppsnark.rs +++ b/src/spartan/ppsnark.rs @@ -584,10 +584,11 @@ impl> RelaxedR1CSSNARKTrait for Relax let u: PolyEvalInstance = PolyEvalInstance::batch(&comm_vec, tau_coords.clone(), &eval_vec, &c); - // we now need to prove three claims + // we now need to prove four 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) // (2) eval_Az_at_tau + c * eval_Bz_at_tau + c^2 * eval_Cz_at_tau = \sum_y L_row(y) * (val_A(y) + c * val_B(y) + c^2 * val_C(y)) * L_col(y) // (3) L_row(i) = eq(tau, row(i)) and L_col(i) = z(col(i)) + // (4) Check that the witness polynomial W is well-formed e.g., it is padded with only zeros let gamma = transcript.squeeze(b"g")?; let r = transcript.squeeze(b"r")?; diff --git a/src/spartan/snark.rs b/src/spartan/snark.rs index 3c41735e2..636a0d7d8 100644 --- a/src/spartan/snark.rs +++ b/src/spartan/snark.rs @@ -250,7 +250,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_reduce(u_vec, &w_vec, &mut transcript)?; let eval_arg = EE::prove( ck, @@ -414,8 +414,8 @@ impl> RelaxedR1CSSNARKTrait for Relax } } -/// Proves a batch of polynomial evaluation claims using Sumcheck -/// reducing them to a single claim at the same point. +/// Reduces a batch of polynomial evaluation claims using Sumcheck +/// to a single claim at the same point. /// /// # Details /// @@ -428,7 +428,7 @@ impl> RelaxedR1CSSNARKTrait for Relax /// /// We allow the polynomial Pᵢ to have different sizes, by appropriately scaling /// the claims and resulting evaluations from Sumcheck. -pub(in crate::spartan) fn batch_eval_prove( +pub(in crate::spartan) fn batch_eval_reduce( u_vec: Vec>, w_vec: &[PolyEvalWitness], transcript: &mut E::TE,