Skip to content

Commit a18afe0

Browse files
oskarthhuitseekersrinathsetty
authored
Chore/sync upstream (#51)
Sync upstream --------- Co-authored-by: François Garillot <4142+huitseeker@users.noreply.github.com> Co-authored-by: Srinath Setty <srinath@microsoft.com>
1 parent 5f24446 commit a18afe0

30 files changed

+434
-387
lines changed

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "nova-snark"
3-
version = "0.22.0"
3+
version = "0.23.0"
44
authors = ["Srinath Setty <srinath@microsoft.com>"]
55
edition = "2021"
66
description = "Recursive zkSNARKs without trusted setup"
@@ -28,7 +28,6 @@ num-traits = "0.2"
2828
num-integer = "0.1"
2929
serde = { version = "1.0", features = ["derive"] }
3030
bincode = "1.3"
31-
flate2 = "1.0"
3231
bitvec = "1.0"
3332
byteorder = "1.4.3"
3433
thiserror = "1.0"
@@ -45,10 +44,12 @@ getrandom = { version = "0.2.0", default-features = false, features = ["js"] }
4544
[dev-dependencies]
4645
criterion = { version = "0.4", features = ["html_reports"] }
4746
rand = "0.8.4"
47+
flate2 = "1.0"
4848
hex = "0.4.3"
4949
pprof = { version = "0.11" }
5050
cfg-if = "1.0.0"
5151
sha2 = "0.10.7"
52+
proptest = "1.2.0"
5253

5354
[[bench]]
5455
name = "recursive-snark"

benches/compressed-snark.rs

Lines changed: 94 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ type G1 = pasta_curves::pallas::Point;
1717
type G2 = pasta_curves::vesta::Point;
1818
type EE1 = nova_snark::provider::ipa_pc::EvaluationEngine<G1>;
1919
type EE2 = nova_snark::provider::ipa_pc::EvaluationEngine<G2>;
20+
// SNARKs without computational commitments
2021
type S1 = nova_snark::spartan::snark::RelaxedR1CSSNARK<G1, EE1>;
2122
type S2 = nova_snark::spartan::snark::RelaxedR1CSSNARK<G2, EE2>;
23+
// SNARKs with computational commitments
24+
type SS1 = nova_snark::spartan::ppsnark::RelaxedR1CSSNARK<G1, EE1>;
25+
type SS2 = nova_snark::spartan::ppsnark::RelaxedR1CSSNARK<G2, EE2>;
2226
type C1 = NonTrivialTestCircuit<<G1 as Group>::Scalar>;
2327
type C2 = TrivialTestCircuit<<G2 as Group>::Scalar>;
2428

@@ -31,13 +35,13 @@ cfg_if::cfg_if! {
3135
criterion_group! {
3236
name = compressed_snark;
3337
config = Criterion::default().warm_up_time(Duration::from_millis(3000)).with_profiler(pprof::criterion::PProfProfiler::new(100, pprof::criterion::Output::Flamegraph(None)));
34-
targets = bench_compressed_snark
38+
targets = bench_compressed_snark, bench_compressed_snark_with_computational_commitments
3539
}
3640
} else {
3741
criterion_group! {
3842
name = compressed_snark;
3943
config = Criterion::default().warm_up_time(Duration::from_millis(3000));
40-
targets = bench_compressed_snark
44+
targets = bench_compressed_snark, bench_compressed_snark_with_computational_commitments
4145
}
4246
}
4347
}
@@ -61,7 +65,7 @@ fn bench_compressed_snark(c: &mut Criterion) {
6165
let c_secondary = TrivialTestCircuit::default();
6266

6367
// Produce public parameters
64-
let pp = PublicParams::<G1, G2, C1, C2>::setup(c_primary.clone(), c_secondary.clone());
68+
let pp = PublicParams::<G1, G2, C1, C2>::setup(&c_primary, &c_secondary);
6569

6670
// Produce prover and verifier keys for CompressedSNARK
6771
let (pk, vk) = CompressedSNARK::<_, _, _, _, S1, S2>::setup(&pp).unwrap();
@@ -129,6 +133,93 @@ fn bench_compressed_snark(c: &mut Criterion) {
129133
}
130134
}
131135

136+
fn bench_compressed_snark_with_computational_commitments(c: &mut Criterion) {
137+
let num_samples = 10;
138+
let num_cons_verifier_circuit_primary = 9819;
139+
// we vary the number of constraints in the step circuit
140+
for &num_cons_in_augmented_circuit in [9819, 16384, 32768, 65536, 131072, 262144].iter() {
141+
// number of constraints in the step circuit
142+
let num_cons = num_cons_in_augmented_circuit - num_cons_verifier_circuit_primary;
143+
144+
let mut group = c.benchmark_group(format!(
145+
"CompressedSNARK-Commitments-StepCircuitSize-{num_cons}"
146+
));
147+
group
148+
.sampling_mode(SamplingMode::Flat)
149+
.sample_size(num_samples);
150+
151+
let c_primary = NonTrivialTestCircuit::new(num_cons);
152+
let c_secondary = TrivialTestCircuit::default();
153+
154+
// Produce public parameters
155+
let pp = PublicParams::<G1, G2, C1, C2>::setup(&c_primary, &c_secondary);
156+
157+
// Produce prover and verifier keys for CompressedSNARK
158+
let (pk, vk) = CompressedSNARK::<_, _, _, _, SS1, SS2>::setup(&pp).unwrap();
159+
160+
// produce a recursive SNARK
161+
let num_steps = 3;
162+
let mut recursive_snark: RecursiveSNARK<G1, G2, C1, C2> = RecursiveSNARK::new(
163+
&pp,
164+
&c_primary,
165+
&c_secondary,
166+
vec![<G1 as Group>::Scalar::from(2u64)],
167+
vec![<G2 as Group>::Scalar::from(2u64)],
168+
);
169+
170+
for i in 0..num_steps {
171+
let res = recursive_snark.prove_step(
172+
&pp,
173+
&c_primary,
174+
&c_secondary,
175+
vec![<G1 as Group>::Scalar::from(2u64)],
176+
vec![<G2 as Group>::Scalar::from(2u64)],
177+
);
178+
assert!(res.is_ok());
179+
180+
// verify the recursive snark at each step of recursion
181+
let res = recursive_snark.verify(
182+
&pp,
183+
i + 1,
184+
&[<G1 as Group>::Scalar::from(2u64)],
185+
&[<G2 as Group>::Scalar::from(2u64)],
186+
);
187+
assert!(res.is_ok());
188+
}
189+
190+
// Bench time to produce a compressed SNARK
191+
group.bench_function("Prove", |b| {
192+
b.iter(|| {
193+
assert!(CompressedSNARK::<_, _, _, _, SS1, SS2>::prove(
194+
black_box(&pp),
195+
black_box(&pk),
196+
black_box(&recursive_snark)
197+
)
198+
.is_ok());
199+
})
200+
});
201+
let res = CompressedSNARK::<_, _, _, _, SS1, SS2>::prove(&pp, &pk, &recursive_snark);
202+
assert!(res.is_ok());
203+
let compressed_snark = res.unwrap();
204+
205+
// Benchmark the verification time
206+
group.bench_function("Verify", |b| {
207+
b.iter(|| {
208+
assert!(black_box(&compressed_snark)
209+
.verify(
210+
black_box(&vk),
211+
black_box(num_steps),
212+
black_box(vec![<G1 as Group>::Scalar::from(2u64)]),
213+
black_box(vec![<G2 as Group>::Scalar::from(2u64)]),
214+
)
215+
.is_ok());
216+
})
217+
});
218+
219+
group.finish();
220+
}
221+
}
222+
132223
#[derive(Clone, Debug, Default)]
133224
struct NonTrivialTestCircuit<F: PrimeField> {
134225
num_cons: usize,

benches/compute-digest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ criterion_main!(compute_digest);
2727
fn bench_compute_digest(c: &mut Criterion) {
2828
c.bench_function("compute_digest", |b| {
2929
b.iter(|| {
30-
PublicParams::<G1, G2, C1, C2>::setup(black_box(C1::new(10)), black_box(C2::default()))
30+
PublicParams::<G1, G2, C1, C2>::setup(black_box(&C1::new(10)), black_box(&C2::default()))
3131
})
3232
});
3333
}

benches/recursive-snark.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn bench_recursive_snark(c: &mut Criterion) {
5656
let c_secondary = TrivialTestCircuit::default();
5757

5858
// Produce public parameters
59-
let pp = PublicParams::<G1, G2, C1, C2>::setup(c_primary.clone(), c_secondary.clone());
59+
let pp = PublicParams::<G1, G2, C1, C2>::setup(&c_primary, &c_secondary);
6060

6161
// Bench time to produce a recursive SNARK;
6262
// we execute a certain number of warm-up steps since executing

benches/sha256.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ fn bench_recursive_snark(c: &mut Criterion) {
200200
group.sample_size(10);
201201

202202
// Produce public parameters
203-
let pp =
204-
PublicParams::<G1, G2, C1, C2>::setup(circuit_primary.clone(), TrivialTestCircuit::default());
203+
let ttc = TrivialTestCircuit::default();
204+
let pp = PublicParams::<G1, G2, C1, C2>::setup(&circuit_primary, &ttc);
205205

206206
let circuit_secondary = TrivialTestCircuit::default();
207207
let z0_primary = vec![<G1 as Group>::Scalar::from(2u64)];

examples/minroot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ fn main() {
172172
G2,
173173
MinRootCircuit<<G1 as Group>::Scalar>,
174174
TrivialTestCircuit<<G2 as Group>::Scalar>,
175-
>::setup(circuit_primary.clone(), circuit_secondary.clone());
175+
>::setup(&circuit_primary, &circuit_secondary);
176176
println!("PublicParams::setup, took {:?} ", start.elapsed());
177177

178178
println!(

src/bellperson/r1cs.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ pub trait NovaShape<G: Group> {
2828
fn r1cs_shape(&self) -> (R1CSShape<G>, CommitmentKey<G>);
2929
}
3030

31-
impl<G: Group> NovaWitness<G> for SatisfyingAssignment<G>
32-
where
33-
G::Scalar: PrimeField,
34-
{
31+
impl<G: Group> NovaWitness<G> for SatisfyingAssignment<G> {
3532
fn r1cs_instance_and_witness(
3633
&self,
3734
shape: &R1CSShape<G>,
@@ -48,10 +45,7 @@ where
4845
}
4946
}
5047

51-
impl<G: Group> NovaShape<G> for ShapeCS<G>
52-
where
53-
G::Scalar: PrimeField,
54-
{
48+
impl<G: Group> NovaShape<G> for ShapeCS<G> {
5549
fn r1cs_shape(&self) -> (R1CSShape<G>, CommitmentKey<G>) {
5650
let mut A: Vec<(usize, usize, G::Scalar)> = Vec::new();
5751
let mut B: Vec<(usize, usize, G::Scalar)> = Vec::new();

src/bellperson/shape_cs.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ impl Ord for OrderedVariable {
4848

4949
#[allow(clippy::upper_case_acronyms)]
5050
/// `ShapeCS` is a `ConstraintSystem` for creating `R1CSShape`s for a circuit.
51-
pub struct ShapeCS<G: Group>
52-
where
53-
G::Scalar: PrimeField + Field,
54-
{
51+
pub struct ShapeCS<G: Group> {
5552
named_objects: HashMap<String, NamedObject>,
5653
current_namespace: Vec<String>,
5754
#[allow(clippy::type_complexity)]
@@ -92,10 +89,7 @@ fn proc_lc<Scalar: PrimeField>(
9289
map
9390
}
9491

95-
impl<G: Group> ShapeCS<G>
96-
where
97-
G::Scalar: PrimeField,
98-
{
92+
impl<G: Group> ShapeCS<G> {
9993
/// Create a new, default `ShapeCS`,
10094
pub fn new() -> Self {
10195
ShapeCS::default()
@@ -216,10 +210,7 @@ where
216210
}
217211
}
218212

219-
impl<G: Group> Default for ShapeCS<G>
220-
where
221-
G::Scalar: PrimeField,
222-
{
213+
impl<G: Group> Default for ShapeCS<G> {
223214
fn default() -> Self {
224215
let mut map = HashMap::new();
225216
map.insert("ONE".into(), NamedObject::Var(ShapeCS::<G>::one()));
@@ -233,10 +224,7 @@ where
233224
}
234225
}
235226

236-
impl<G: Group> ConstraintSystem<G::Scalar> for ShapeCS<G>
237-
where
238-
G::Scalar: PrimeField,
239-
{
227+
impl<G: Group> ConstraintSystem<G::Scalar> for ShapeCS<G> {
240228
type Root = Self;
241229

242230
fn alloc<F, A, AR>(&mut self, annotation: A, _f: F) -> Result<Variable, SynthesisError>

src/bellperson/solver.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
//! Support for generating R1CS witness using bellperson.
22
33
use crate::traits::Group;
4-
use ff::{Field, PrimeField};
4+
use ff::Field;
55

66
use bellperson::{
77
multiexp::DensityTracker, ConstraintSystem, Index, LinearCombination, SynthesisError, Variable,
88
};
99

1010
/// A `ConstraintSystem` which calculates witness values for a concrete instance of an R1CS circuit.
1111
#[derive(PartialEq)]
12-
pub struct SatisfyingAssignment<G: Group>
13-
where
14-
G::Scalar: PrimeField,
15-
{
12+
pub struct SatisfyingAssignment<G: Group> {
1613
// Density of queries
1714
a_aux_density: DensityTracker,
1815
b_input_density: DensityTracker,
@@ -29,10 +26,7 @@ where
2926
}
3027
use std::fmt;
3128

32-
impl<G: Group> fmt::Debug for SatisfyingAssignment<G>
33-
where
34-
G::Scalar: PrimeField,
35-
{
29+
impl<G: Group> fmt::Debug for SatisfyingAssignment<G> {
3630
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
3731
fmt
3832
.debug_struct("SatisfyingAssignment")
@@ -69,10 +63,7 @@ where
6963
}
7064
}
7165

72-
impl<G: Group> ConstraintSystem<G::Scalar> for SatisfyingAssignment<G>
73-
where
74-
G::Scalar: PrimeField,
75-
{
66+
impl<G: Group> ConstraintSystem<G::Scalar> for SatisfyingAssignment<G> {
7667
type Root = Self;
7768

7869
fn new() -> Self {

src/ccs/cccs.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use crate::{
1818
use bitvec::vec;
1919
use core::{cmp::max, marker::PhantomData};
2020
use ff::{Field, PrimeField};
21-
use flate2::{write::ZlibEncoder, Compression};
2221
use itertools::concat;
2322
use rayon::prelude::*;
2423
use serde::{Deserialize, Serialize};

0 commit comments

Comments
 (0)