Skip to content

Commit 2fa1f98

Browse files
(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 <[email protected]>
1 parent ef677bf commit 2fa1f98

File tree

7 files changed

+15
-13
lines changed

7 files changed

+15
-13
lines changed

.github/workflows/rust.yml

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ jobs:
4242
uses: lurk-lab/ci-workflows/.github/workflows/check-lurk-compiles.yml@main
4343
with:
4444
runner: "buildjet-8vcpu-ubuntu-2204"
45+
packages: "pkg-config libssl-dev protobuf-compiler libprotobuf-dev"
4546

4647
# Rustfmt, clippy, doctests
4748
code-quality:

benches/compressed-snark.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type S1 = arecibo::spartan::snark::RelaxedR1CSSNARK<E1, EE1>;
2727
type S2 = arecibo::spartan::snark::RelaxedR1CSSNARK<E2, EE2>;
2828
// SNARKs with computation commitmnets
2929
type SS1 = arecibo::spartan::ppsnark::RelaxedR1CSSNARK<E1, EE1>;
30-
type SS2 = arecibo::spartan::ppsnark::RelaxedR1CSSNARK<E2, EE2>;
30+
type SS2 = arecibo::spartan::snark::RelaxedR1CSSNARK<E2, EE2>; // the computation commitment is not used for the trivial circuit
3131

3232
// To run these benchmarks, first download `criterion` with `cargo install cargo-criterion`.
3333
// Then `cargo criterion --bench compressed-snark`. The results are located in `target/criterion/data/<name-of-benchmark>`.

src/r1cs/sparse.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ impl<F: PrimeField> SparseMatrix<F> {
164164
level = "trace",
165165
name = "SparseMatrix::multiply_vec_unchecked"
166166
)]
167-
pub fn multiply_vec_unchecked(&self, vector: &[F]) -> Vec<F> {
167+
fn multiply_vec_unchecked(&self, vector: &[F]) -> Vec<F> {
168168
let mut sink: Vec<F> = Vec::with_capacity(self.indptr.len() - 1);
169169
self.multiply_vec_into_unchecked(vector, &mut sink);
170170
sink
171171
}
172172

173-
pub fn multiply_vec_into_unchecked(&self, vector: &[F], sink: &mut Vec<F>) {
173+
fn multiply_vec_into_unchecked(&self, vector: &[F], sink: &mut Vec<F>) {
174174
self
175175
.indptr
176176
.par_windows(2)
@@ -197,7 +197,7 @@ impl<F: PrimeField> SparseMatrix<F> {
197197
level = "trace",
198198
name = "SparseMatrix::multiply_vec_unchecked"
199199
)]
200-
pub fn multiply_witness_unchecked(&self, W: &[F], u: &F, X: &[F]) -> Vec<F> {
200+
fn multiply_witness_unchecked(&self, W: &[F], u: &F, X: &[F]) -> Vec<F> {
201201
// preallocate the result vector
202202
let mut sink = Vec::with_capacity(self.indptr.len() - 1);
203203
self.multiply_witness_into_unchecked(W, u, X, &mut sink);
@@ -213,7 +213,7 @@ impl<F: PrimeField> SparseMatrix<F> {
213213

214214
/// Multiply by a witness representing a dense vector; uses rayon to parallelize.
215215
/// This does not check that the shape of the matrix/vector are compatible.
216-
pub fn multiply_witness_into_unchecked(&self, W: &[F], u: &F, X: &[F], sink: &mut Vec<F>) {
216+
fn multiply_witness_into_unchecked(&self, W: &[F], u: &F, X: &[F], sink: &mut Vec<F>) {
217217
let num_vars = W.len();
218218
self
219219
.indptr

src/spartan/batched.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use super::{
1717
math::Math,
1818
polys::{eq::EqPolynomial, multilinear::MultilinearPolynomial},
1919
powers,
20-
snark::batch_eval_prove,
20+
snark::batch_eval_reduce,
2121
sumcheck::SumcheckProof,
2222
PolyEvalInstance, PolyEvalWitness,
2323
};
@@ -348,7 +348,7 @@ impl<E: Engine, EE: EvaluationEngineTrait<E>> BatchedRelaxedR1CSSNARKTrait<E>
348348
};
349349

350350
let (batched_u, batched_w, sc_proof_batch, claims_batch_left) =
351-
batch_eval_prove(u_vec, &w_vec, &mut transcript)?;
351+
batch_eval_reduce(u_vec, &w_vec, &mut transcript)?;
352352

353353
let eval_arg = EE::prove(
354354
ck,

src/spartan/polys/power.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl<Scalar: PrimeField> PowPolynomial<Scalar> {
2727

2828
/// Create powers the following powers of `t`:
2929
/// [t^{2^0}, t^{2^1}, ..., t^{2^{ell-1}}]
30-
pub(in crate::spartan) fn squares(t: &Scalar, ell: usize) -> Vec<Scalar> {
30+
pub fn squares(t: &Scalar, ell: usize) -> Vec<Scalar> {
3131
successors(Some(*t), |p: &Scalar| Some(p.square()))
3232
.take(ell)
3333
.collect::<Vec<_>>()

src/spartan/ppsnark.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -584,10 +584,11 @@ impl<E: Engine, EE: EvaluationEngineTrait<E>> RelaxedR1CSSNARKTrait<E> for Relax
584584
let u: PolyEvalInstance<E> =
585585
PolyEvalInstance::batch(&comm_vec, tau_coords.clone(), &eval_vec, &c);
586586

587-
// we now need to prove three claims
587+
// we now need to prove four claims
588588
// (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)
589589
// (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)
590590
// (3) L_row(i) = eq(tau, row(i)) and L_col(i) = z(col(i))
591+
// (4) Check that the witness polynomial W is well-formed e.g., it is padded with only zeros
591592
let gamma = transcript.squeeze(b"g")?;
592593
let r = transcript.squeeze(b"r")?;
593594

src/spartan/snark.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ impl<E: Engine, EE: EvaluationEngineTrait<E>> RelaxedR1CSSNARKTrait<E> for Relax
250250
];
251251

252252
let (batched_u, batched_w, sc_proof_batch, claims_batch_left) =
253-
batch_eval_prove(u_vec, &w_vec, &mut transcript)?;
253+
batch_eval_reduce(u_vec, &w_vec, &mut transcript)?;
254254

255255
let eval_arg = EE::prove(
256256
ck,
@@ -414,8 +414,8 @@ impl<E: Engine, EE: EvaluationEngineTrait<E>> RelaxedR1CSSNARKTrait<E> for Relax
414414
}
415415
}
416416

417-
/// Proves a batch of polynomial evaluation claims using Sumcheck
418-
/// reducing them to a single claim at the same point.
417+
/// Reduces a batch of polynomial evaluation claims using Sumcheck
418+
/// to a single claim at the same point.
419419
///
420420
/// # Details
421421
///
@@ -428,7 +428,7 @@ impl<E: Engine, EE: EvaluationEngineTrait<E>> RelaxedR1CSSNARKTrait<E> for Relax
428428
///
429429
/// We allow the polynomial Pᵢ to have different sizes, by appropriately scaling
430430
/// the claims and resulting evaluations from Sumcheck.
431-
pub(in crate::spartan) fn batch_eval_prove<E: Engine>(
431+
pub(in crate::spartan) fn batch_eval_reduce<E: Engine>(
432432
u_vec: Vec<PolyEvalInstance<E>>,
433433
w_vec: &[PolyEvalWitness<E>],
434434
transcript: &mut E::TE,

0 commit comments

Comments
 (0)