Skip to content

Commit

Permalink
more running claims API
Browse files Browse the repository at this point in the history
  • Loading branch information
winston-h-zhang committed Sep 21, 2023
1 parent beb7aac commit 7009e58
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 83 deletions.
42 changes: 34 additions & 8 deletions benches/recursive-snark-supernova.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use criterion::*;
use ff::PrimeField;
use nova_snark::{
supernova::NonUniformCircuit,
supernova::RecursiveSNARK,
supernova::{RecursiveSNARK, RunningClaimParams},
traits::{
circuit_supernova::{StepCircuit, TrivialTestCircuit},
Group,
Expand Down Expand Up @@ -99,7 +99,8 @@ fn bench_one_augmented_circuit_recursive_snark(c: &mut Criterion) {

let bench: NonUniformBench<G1, G2, TrivialTestCircuit<<G2 as Group>::Scalar>> =
NonUniformBench::new(1, num_cons);
let running_claims = bench.setup_running_claims();
let running_claim_params = RunningClaimParams::new(&bench);
let running_claims = bench.setup_running_claims(&running_claim_params);

// Bench time to produce a recursive SNARK;
// we execute a certain number of warm-up steps since executing
Expand All @@ -119,9 +120,10 @@ fn bench_one_augmented_circuit_recursive_snark(c: &mut Criterion) {

let mut recursive_snark = recursive_snark_option.unwrap_or_else(|| {
RecursiveSNARK::iter_base_step(
&running_claim_params[0],
&running_claims[0],
&bench.primary_circuit(0),
running_claims.digest(),
running_claim_params.digest(),
Some(program_counter),
0,
1,
Expand All @@ -132,6 +134,7 @@ fn bench_one_augmented_circuit_recursive_snark(c: &mut Criterion) {
});

let res = recursive_snark.prove_step(
&running_claim_params[0],
&running_claims[0],
&bench.primary_circuit(0),
&z0_primary,
Expand All @@ -141,7 +144,12 @@ fn bench_one_augmented_circuit_recursive_snark(c: &mut Criterion) {
println!("res failed {:?}", e);
}
assert!(res.is_ok());
let res = recursive_snark.verify(&running_claims[0], &z0_primary, &z0_secondary);
let res = recursive_snark.verify(
&running_claim_params[0],
&running_claims[0],
&z0_primary,
&z0_secondary,
);
if let Err(e) = &res {
println!("res failed {:?}", e);
}
Expand All @@ -158,6 +166,7 @@ fn bench_one_augmented_circuit_recursive_snark(c: &mut Criterion) {
// produce a recursive SNARK for a step of the recursion
assert!(black_box(&mut recursive_snark.clone())
.prove_step(
black_box(&running_claim_params[0]),
black_box(&running_claims[0]),
&bench.primary_circuit(0),
black_box(&[<G1 as Group>::Scalar::from(2u64)]),
Expand All @@ -172,6 +181,7 @@ fn bench_one_augmented_circuit_recursive_snark(c: &mut Criterion) {
b.iter(|| {
assert!(black_box(&mut recursive_snark.clone())
.verify(
black_box(&running_claim_params[0]),
black_box(&running_claims[0]),
black_box(&[<G1 as Group>::Scalar::from(2u64)]),
black_box(&[<G2 as Group>::Scalar::from(2u64)]),
Expand Down Expand Up @@ -199,7 +209,8 @@ fn bench_two_augmented_circuit_recursive_snark(c: &mut Criterion) {

let bench: NonUniformBench<G1, G2, TrivialTestCircuit<<G2 as Group>::Scalar>> =
NonUniformBench::new(2, num_cons);
let running_claims = bench.setup_running_claims();
let running_claim_params = RunningClaimParams::new(&bench);
let running_claims = bench.setup_running_claims(&running_claim_params);

// Bench time to produce a recursive SNARK;
// we execute a certain number of warm-up steps since executing
Expand All @@ -220,9 +231,10 @@ fn bench_two_augmented_circuit_recursive_snark(c: &mut Criterion) {

let mut recursive_snark = recursive_snark_option.unwrap_or_else(|| {
RecursiveSNARK::iter_base_step(
&running_claim_params[0],
&running_claims[0],
&bench.primary_circuit(0),
running_claims.digest(),
running_claim_params.digest(),
Some(program_counter),
0,
2,
Expand All @@ -234,6 +246,7 @@ fn bench_two_augmented_circuit_recursive_snark(c: &mut Criterion) {

if selected_augmented_circuit == 0 {
let res = recursive_snark.prove_step(
&running_claim_params[0],
&running_claims[0],
&bench.primary_circuit(0),
&z0_primary,
Expand All @@ -243,13 +256,19 @@ fn bench_two_augmented_circuit_recursive_snark(c: &mut Criterion) {
println!("res failed {:?}", e);
}
assert!(res.is_ok());
let res = recursive_snark.verify(&running_claims[0], &z0_primary, &z0_secondary);
let res = recursive_snark.verify(
&running_claim_params[0],
&running_claims[0],
&z0_primary,
&z0_secondary,
);
if let Err(e) = &res {
println!("res failed {:?}", e);
}
assert!(res.is_ok());
} else if selected_augmented_circuit == 1 {
let res = recursive_snark.prove_step(
&running_claim_params[0],
&running_claims[1],
&bench.primary_circuit(1),
&z0_primary,
Expand All @@ -259,7 +278,12 @@ fn bench_two_augmented_circuit_recursive_snark(c: &mut Criterion) {
println!("res failed {:?}", e);
}
assert!(res.is_ok());
let res = recursive_snark.verify(&running_claims[1], &z0_primary, &z0_secondary);
let res = recursive_snark.verify(
&running_claim_params[0],
&running_claims[1],
&z0_primary,
&z0_secondary,
);
if let Err(e) = &res {
println!("res failed {:?}", e);
}
Expand All @@ -280,6 +304,7 @@ fn bench_two_augmented_circuit_recursive_snark(c: &mut Criterion) {
// produce a recursive SNARK for a step of the recursion
assert!(black_box(&mut recursive_snark.clone())
.prove_step(
black_box(&running_claim_params[0]),
black_box(&running_claims[0]),
&bench.primary_circuit(0),
black_box(&[<G1 as Group>::Scalar::from(2u64)]),
Expand All @@ -294,6 +319,7 @@ fn bench_two_augmented_circuit_recursive_snark(c: &mut Criterion) {
b.iter(|| {
assert!(black_box(&mut recursive_snark.clone())
.verify(
black_box(&running_claim_params[0]),
black_box(&running_claims[0]),
black_box(&[<G1 as Group>::Scalar::from(2u64)]),
black_box(&[<G2 as Group>::Scalar::from(2u64)]),
Expand Down
6 changes: 5 additions & 1 deletion src/provider/pasta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ macro_rules! impl_traits {
type CE = CommitmentEngine<Self>;

#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
#[tracing::instrument(skip_all, level = "trace", name = "<_ as Group>::vartime_multiscalar_mul")]
#[tracing::instrument(
skip_all,
level = "trace",
name = "<_ as Group>::vartime_multiscalar_mul"
)]
fn vartime_multiscalar_mul(
scalars: &[Self::Scalar],
bases: &[Self::PreprocessedGroupElement],
Expand Down
6 changes: 5 additions & 1 deletion src/r1cs/sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ impl<F: PrimeField> SparseMatrix<F> {

/// Multiply by a dense vector; uses rayon/gpu.
/// This does not check that the shape of the matrix/vector are compatible.
#[tracing::instrument(skip_all, level = "trace", name = "SparseMatrix::multiply_vec_unchecked")]
#[tracing::instrument(
skip_all,
level = "trace",
name = "SparseMatrix::multiply_vec_unchecked"
)]
pub fn multiply_vec_unchecked(&self, vector: &[F]) -> Vec<F> {
self
.indptr
Expand Down
Loading

0 comments on commit 7009e58

Please sign in to comment.