Skip to content

Commit

Permalink
Update the RecursiveSNARK API (Nova forward port) (lurk-lang#87)
Browse files Browse the repository at this point in the history
* Digest simplifications (lurk-lang#238)

* remove unused digest computations

* avoid a verifier having to recompute a digest

* update crate version

Restore digest computation and fix API inconsistency (lurk-lang#242)

* Revert "Digest simplifications (lurk-lang#238)"

This reverts commit 71ecb66.

* upgrade neptune

* make the public interface uniform wrt refs vs. copies

* simplify prove_step

* refactor: Adapt supernova RecursiveSNARK to Nova API changes

- Updated `RecursiveSNARK` struct in `supernova/mod.rs` to include `z0_primary` and `z0_secondary` fields, simplifying method parameters.
- Refactored `prove_step` method in `RecursiveSNARK` struct to leverage the new instance variables, `z0_primary` and `z0_secondary`,
- Replaced all usages of `z0_primary` and `z0_secondary` in function calls with their respective instance variables.

---------

Co-authored-by: Srinath Setty <[email protected]>
  • Loading branch information
huitseeker and srinathsetty authored Oct 30, 2023
1 parent 170818e commit f81bd4c
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 166 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nova-snark"
version = "0.24.0"
version = "0.26.0"
authors = ["Srinath Setty <[email protected]>"]
edition = "2021"
description = "Recursive zkSNARKs without trusted setup"
Expand Down
38 changes: 14 additions & 24 deletions benches/compressed-snark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,13 @@ fn bench_compressed_snark(c: &mut Criterion) {
&pp,
&c_primary,
&c_secondary,
vec![<G1 as Group>::Scalar::from(2u64)],
vec![<G2 as Group>::Scalar::from(2u64)],
);
&[<G1 as Group>::Scalar::from(2u64)],
&[<G2 as Group>::Scalar::from(2u64)],
)
.unwrap();

for i in 0..num_steps {
let res = recursive_snark.prove_step(
&pp,
&c_primary,
&c_secondary,
vec![<G1 as Group>::Scalar::from(2u64)],
vec![<G2 as Group>::Scalar::from(2u64)],
);
let res = recursive_snark.prove_step(&pp, &c_primary, &c_secondary);
assert!(res.is_ok());

// verify the recursive snark at each step of recursion
Expand Down Expand Up @@ -128,8 +123,8 @@ fn bench_compressed_snark(c: &mut Criterion) {
.verify(
black_box(&vk),
black_box(num_steps),
black_box(vec![<G1 as Group>::Scalar::from(2u64)]),
black_box(vec![<G2 as Group>::Scalar::from(2u64)]),
black_box(&[<G1 as Group>::Scalar::from(2u64)]),
black_box(&[<G2 as Group>::Scalar::from(2u64)]),
)
.is_ok());
})
Expand Down Expand Up @@ -173,18 +168,13 @@ fn bench_compressed_snark_with_computational_commitments(c: &mut Criterion) {
&pp,
&c_primary,
&c_secondary,
vec![<G1 as Group>::Scalar::from(2u64)],
vec![<G2 as Group>::Scalar::from(2u64)],
);
&[<G1 as Group>::Scalar::from(2u64)],
&[<G2 as Group>::Scalar::from(2u64)],
)
.unwrap();

for i in 0..num_steps {
let res = recursive_snark.prove_step(
&pp,
&c_primary,
&c_secondary,
vec![<G1 as Group>::Scalar::from(2u64)],
vec![<G2 as Group>::Scalar::from(2u64)],
);
let res = recursive_snark.prove_step(&pp, &c_primary, &c_secondary);
assert!(res.is_ok());

// verify the recursive snark at each step of recursion
Expand Down Expand Up @@ -219,8 +209,8 @@ fn bench_compressed_snark_with_computational_commitments(c: &mut Criterion) {
.verify(
black_box(&vk),
black_box(num_steps),
black_box(vec![<G1 as Group>::Scalar::from(2u64)]),
black_box(vec![<G2 as Group>::Scalar::from(2u64)]),
black_box(&[<G1 as Group>::Scalar::from(2u64)]),
black_box(&[<G2 as Group>::Scalar::from(2u64)]),
)
.is_ok());
})
Expand Down
10 changes: 0 additions & 10 deletions benches/recursive-snark-supernova.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ fn bench_one_augmented_circuit_recursive_snark(c: &mut Criterion) {
0,
&bench.primary_circuit(0),
&bench.secondary_circuit(),
&z0_primary,
&z0_secondary,
);
if let Err(e) = &res {
println!("res failed {:?}", e);
Expand All @@ -170,8 +168,6 @@ fn bench_one_augmented_circuit_recursive_snark(c: &mut Criterion) {
black_box(0),
&bench.primary_circuit(0),
&bench.secondary_circuit(),
black_box(&[<G1 as Group>::Scalar::from(2u64)]),
black_box(&[<G2 as Group>::Scalar::from(2u64)]),
)
.is_ok());
})
Expand Down Expand Up @@ -250,8 +246,6 @@ fn bench_two_augmented_circuit_recursive_snark(c: &mut Criterion) {
0,
&bench.primary_circuit(0),
&bench.secondary_circuit(),
&z0_primary,
&z0_secondary,
);
if let Err(e) = &res {
println!("res failed {:?}", e);
Expand All @@ -268,8 +262,6 @@ fn bench_two_augmented_circuit_recursive_snark(c: &mut Criterion) {
1,
&bench.primary_circuit(1),
&bench.secondary_circuit(),
&z0_primary,
&z0_secondary,
);
if let Err(e) = &res {
println!("res failed {:?}", e);
Expand Down Expand Up @@ -300,8 +292,6 @@ fn bench_two_augmented_circuit_recursive_snark(c: &mut Criterion) {
black_box(0),
&bench.primary_circuit(0),
&bench.secondary_circuit(),
black_box(&[<G1 as Group>::Scalar::from(2u64)]),
black_box(&[<G2 as Group>::Scalar::from(2u64)]),
)
.is_ok());
})
Expand Down
17 changes: 5 additions & 12 deletions benches/recursive-snark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,13 @@ fn bench_recursive_snark(c: &mut Criterion) {
&pp,
&c_primary,
&c_secondary,
vec![<G1 as Group>::Scalar::from(2u64)],
vec![<G2 as Group>::Scalar::from(2u64)],
);
&[<G1 as Group>::Scalar::from(2u64)],
&[<G2 as Group>::Scalar::from(2u64)],
)
.unwrap();

for i in 0..num_warmup_steps {
let res = recursive_snark.prove_step(
&pp,
&c_primary,
&c_secondary,
vec![<G1 as Group>::Scalar::from(2u64)],
vec![<G2 as Group>::Scalar::from(2u64)],
);
let res = recursive_snark.prove_step(&pp, &c_primary, &c_secondary);
assert!(res.is_ok());

// verify the recursive snark at each step of recursion
Expand All @@ -99,8 +94,6 @@ fn bench_recursive_snark(c: &mut Criterion) {
black_box(&pp),
black_box(&c_primary),
black_box(&c_secondary),
black_box(vec![<G1 as Group>::Scalar::from(2u64)]),
black_box(vec![<G2 as Group>::Scalar::from(2u64)]),
)
.is_ok());
})
Expand Down
10 changes: 5 additions & 5 deletions benches/sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,17 @@ fn bench_recursive_snark(c: &mut Criterion) {
black_box(&pp),
black_box(&circuit_primary),
black_box(&circuit_secondary),
black_box(z0_primary.clone()),
black_box(z0_secondary.clone()),
);
black_box(&z0_primary),
black_box(&z0_secondary),
)
.unwrap();

// produce a recursive SNARK for a step of the recursion
assert!(recursive_snark
.prove_step(
black_box(&pp),
black_box(&circuit_primary),
black_box(&circuit_secondary),
black_box(z0_primary.clone()),
black_box(z0_secondary.clone()),
)
.is_ok());
})
Expand Down
26 changes: 11 additions & 15 deletions examples/minroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,23 +215,19 @@ fn main() {
type C2 = TrivialCircuit<<G2 as Group>::Scalar>;
// produce a recursive SNARK
println!("Generating a RecursiveSNARK...");
let mut recursive_snark: RecursiveSNARK<G1, G2, C1, C2> = RecursiveSNARK::<G1, G2, C1, C2>::new(
&pp,
&minroot_circuits[0],
&circuit_secondary,
z0_primary.clone(),
z0_secondary.clone(),
);
let mut recursive_snark: RecursiveSNARK<G1, G2, C1, C2> =
RecursiveSNARK::<G1, G2, C1, C2>::new(
&pp,
&minroot_circuits[0],
&circuit_secondary,
&z0_primary,
&z0_secondary,
)
.unwrap();

for (i, circuit_primary) in minroot_circuits.iter().take(num_steps).enumerate() {
let start = Instant::now();
let res = recursive_snark.prove_step(
&pp,
circuit_primary,
&circuit_secondary,
z0_primary.clone(),
z0_secondary.clone(),
);
let res = recursive_snark.prove_step(&pp, circuit_primary, &circuit_secondary);
assert!(res.is_ok());
println!(
"RecursiveSNARK::prove_step {}: {:?}, took {:?} ",
Expand Down Expand Up @@ -282,7 +278,7 @@ fn main() {
// verify the compressed SNARK
println!("Verifying a CompressedSNARK...");
let start = Instant::now();
let res = compressed_snark.verify(&vk, num_steps, z0_primary, z0_secondary);
let res = compressed_snark.verify(&vk, num_steps, &z0_primary, &z0_secondary);
println!(
"CompressedSNARK::verify: {:?}, took {:?}",
res.is_ok(),
Expand Down
Loading

0 comments on commit f81bd4c

Please sign in to comment.