Skip to content

Commit

Permalink
(easy) Nova forward ports + limit unused visibility for unchecked Spa…
Browse files Browse the repository at this point in the history
…rse 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 <[email protected]>
  • Loading branch information
huitseeker and srinathsetty authored Mar 13, 2024
1 parent ef677bf commit 2fa1f98
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 13 deletions.
1 change: 1 addition & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion benches/compressed-snark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type S1 = arecibo::spartan::snark::RelaxedR1CSSNARK<E1, EE1>;
type S2 = arecibo::spartan::snark::RelaxedR1CSSNARK<E2, EE2>;
// SNARKs with computation commitmnets
type SS1 = arecibo::spartan::ppsnark::RelaxedR1CSSNARK<E1, EE1>;
type SS2 = arecibo::spartan::ppsnark::RelaxedR1CSSNARK<E2, EE2>;
type SS2 = arecibo::spartan::snark::RelaxedR1CSSNARK<E2, EE2>; // 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/<name-of-benchmark>`.
Expand Down
8 changes: 4 additions & 4 deletions src/r1cs/sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ impl<F: PrimeField> SparseMatrix<F> {
level = "trace",
name = "SparseMatrix::multiply_vec_unchecked"
)]
pub fn multiply_vec_unchecked(&self, vector: &[F]) -> Vec<F> {
fn multiply_vec_unchecked(&self, vector: &[F]) -> Vec<F> {
let mut sink: Vec<F> = 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<F>) {
fn multiply_vec_into_unchecked(&self, vector: &[F], sink: &mut Vec<F>) {
self
.indptr
.par_windows(2)
Expand All @@ -197,7 +197,7 @@ impl<F: PrimeField> SparseMatrix<F> {
level = "trace",
name = "SparseMatrix::multiply_vec_unchecked"
)]
pub fn multiply_witness_unchecked(&self, W: &[F], u: &F, X: &[F]) -> Vec<F> {
fn multiply_witness_unchecked(&self, W: &[F], u: &F, X: &[F]) -> Vec<F> {
// preallocate the result vector
let mut sink = Vec::with_capacity(self.indptr.len() - 1);
self.multiply_witness_into_unchecked(W, u, X, &mut sink);
Expand All @@ -213,7 +213,7 @@ impl<F: PrimeField> SparseMatrix<F> {

/// 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<F>) {
fn multiply_witness_into_unchecked(&self, W: &[F], u: &F, X: &[F], sink: &mut Vec<F>) {
let num_vars = W.len();
self
.indptr
Expand Down
4 changes: 2 additions & 2 deletions src/spartan/batched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -348,7 +348,7 @@ impl<E: Engine, EE: EvaluationEngineTrait<E>> BatchedRelaxedR1CSSNARKTrait<E>
};

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,
Expand Down
2 changes: 1 addition & 1 deletion src/spartan/polys/power.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl<Scalar: PrimeField> PowPolynomial<Scalar> {

/// 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<Scalar> {
pub fn squares(t: &Scalar, ell: usize) -> Vec<Scalar> {
successors(Some(*t), |p: &Scalar| Some(p.square()))
.take(ell)
.collect::<Vec<_>>()
Expand Down
3 changes: 2 additions & 1 deletion src/spartan/ppsnark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,10 +584,11 @@ impl<E: Engine, EE: EvaluationEngineTrait<E>> RelaxedR1CSSNARKTrait<E> for Relax
let u: PolyEvalInstance<E> =
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")?;

Expand Down
8 changes: 4 additions & 4 deletions src/spartan/snark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ impl<E: Engine, EE: EvaluationEngineTrait<E>> RelaxedR1CSSNARKTrait<E> 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,
Expand Down Expand Up @@ -414,8 +414,8 @@ impl<E: Engine, EE: EvaluationEngineTrait<E>> RelaxedR1CSSNARKTrait<E> 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
///
Expand All @@ -428,7 +428,7 @@ impl<E: Engine, EE: EvaluationEngineTrait<E>> RelaxedR1CSSNARKTrait<E> 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<E: Engine>(
pub(in crate::spartan) fn batch_eval_reduce<E: Engine>(
u_vec: Vec<PolyEvalInstance<E>>,
w_vec: &[PolyEvalWitness<E>],
transcript: &mut E::TE,
Expand Down

1 comment on commit 2fa1f98

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmarks

Table of Contents

Overview

This benchmark report shows the Arecibo GPU benchmarks.
NVIDIA L4
Intel(R) Xeon(R) CPU @ 2.20GHz
32 vCPUs
125 GB RAM
Workflow run: https://github.com/lurk-lab/arecibo/actions/runs/8270305178

Benchmark Results

RecursiveSNARK-NIVC-2

ref=ef677bf ref=2fa1f98
Prove-NumCons-6540 45.06 ms (✅ 1.00x) 45.33 ms (✅ 1.01x slower)
Verify-NumCons-6540 35.28 ms (✅ 1.00x) 36.13 ms (✅ 1.02x slower)
Prove-NumCons-1028888 322.88 ms (✅ 1.00x) 324.75 ms (✅ 1.01x slower)
Verify-NumCons-1028888 249.91 ms (✅ 1.00x) 250.80 ms (✅ 1.00x slower)

CompressedSNARK-NIVC-Commitments-2

ref=ef677bf ref=2fa1f98
Prove-NumCons-6540 10.81 s (✅ 1.00x) 10.92 s (✅ 1.01x slower)
Verify-NumCons-6540 51.62 ms (✅ 1.00x) 51.98 ms (✅ 1.01x slower)
Prove-NumCons-1028888 53.27 s (✅ 1.00x) 53.60 s (✅ 1.01x slower)
Verify-NumCons-1028888 52.31 ms (✅ 1.00x) 51.76 ms (✅ 1.01x faster)

Made with criterion-table

Please sign in to comment.