Skip to content

Commit 92bdc9f

Browse files
committed
refactor: Refactor public parameters setup to remove optionality of commitment key size hint
- Converted `CommitmentKeyHint<G>` from a boxed dynamic trait object to a direct dynamic trait object in `r1cs/mod.rs`. - Changed the `commitment_key` function to always require a commitment key floor, eliminating the need for default behavior when a floor function isn't provided. - Updated the `r1cs_shape` function across various files to take in a `CommitmentKeyHint` instead of it being optional and introduce a closure as an argument. - Relevant modifications and updates were made in the `r1cs_shape` and `commitment_key` function calls within the test functions for various modules. - Ported use of commitment key hint to Supernova, closing microsoft#53. - This PR puts Arecibo in line with microsoft#203
1 parent 16cfdff commit 92bdc9f

17 files changed

Lines changed: 63 additions & 61 deletions

File tree

benches/compressed-snark.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ fn bench_compressed_snark(c: &mut Criterion) {
6969
let pp = PublicParams::<G1, G2, C1, C2>::new(
7070
&c_primary,
7171
&c_secondary,
72-
Some(S1::commitment_key_floor()),
73-
Some(S2::commitment_key_floor()),
72+
&*S1::commitment_key_floor(),
73+
&*S2::commitment_key_floor(),
7474
);
7575

7676
// Produce prover and verifier keys for CompressedSNARK
@@ -156,8 +156,8 @@ fn bench_compressed_snark_with_computational_commitments(c: &mut Criterion) {
156156
let pp = PublicParams::<G1, G2, C1, C2>::new(
157157
&c_primary,
158158
&c_secondary,
159-
Some(SS1::commitment_key_floor()),
160-
Some(SS2::commitment_key_floor()),
159+
&*SS1::commitment_key_floor(),
160+
&*SS2::commitment_key_floor(),
161161
);
162162
// Produce prover and verifier keys for CompressedSNARK
163163
let (pk, vk) = CompressedSNARK::<_, _, _, _, SS1, SS2>::setup(&pp).unwrap();

benches/compute-digest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ fn bench_compute_digest(c: &mut Criterion) {
3030
PublicParams::<G1, G2, C1, C2>::new(
3131
black_box(&C1::new(10)),
3232
black_box(&C2::default()),
33-
black_box(None),
34-
black_box(None),
33+
black_box(&(|_| 0)),
34+
black_box(&(|_| 0)),
3535
)
3636
})
3737
});

benches/recursive-snark-supernova.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ fn bench_one_augmented_circuit_recursive_snark(c: &mut Criterion) {
104104

105105
let bench: NonUniformBench<G1, G2, TrivialTestCircuit<<G2 as Group>::Scalar>> =
106106
NonUniformBench::new(1, num_cons);
107-
let pp = PublicParams::new(&bench);
107+
let pp = PublicParams::new(&bench, &(|_| 0), &(|_| 0));
108108

109109
// Bench time to produce a recursive SNARK;
110110
// we execute a certain number of warm-up steps since executing
@@ -206,7 +206,7 @@ fn bench_two_augmented_circuit_recursive_snark(c: &mut Criterion) {
206206

207207
let bench: NonUniformBench<G1, G2, TrivialTestCircuit<<G2 as Group>::Scalar>> =
208208
NonUniformBench::new(2, num_cons);
209-
let pp = PublicParams::new(&bench);
209+
let pp = PublicParams::new(&bench, &(|_| 0), &(|_| 0));
210210

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

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 = TrivialCircuit::default();
5757

5858
// Produce public parameters
59-
let pp = PublicParams::<G1, G2, C1, C2>::new(&c_primary, &c_secondary, None, None);
59+
let pp = PublicParams::<G1, G2, C1, C2>::new(&c_primary, &c_secondary, &(|_| 0), &(|_| 0));
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ fn bench_recursive_snark(c: &mut Criterion) {
155155

156156
// Produce public parameters
157157
let ttc = TrivialCircuit::default();
158-
let pp = PublicParams::<G1, G2, C1, C2>::new(&circuit_primary, &ttc, None, None);
158+
let pp = PublicParams::<G1, G2, C1, C2>::new(&circuit_primary, &ttc, &(|_| 0), &(|_| 0));
159159

160160
let circuit_secondary = TrivialCircuit::default();
161161
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
@@ -169,7 +169,7 @@ fn main() {
169169
G2,
170170
MinRootCircuit<<G1 as Group>::Scalar>,
171171
TrivialCircuit<<G2 as Group>::Scalar>,
172-
>::new(&circuit_primary, &circuit_secondary, None, None);
172+
>::new(&circuit_primary, &circuit_secondary, &(|_| 0), &(|_| 0));
173173
println!("PublicParams::setup, took {:?} ", start.elapsed());
174174

175175
println!(

examples/minroot_serde.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ fn main() {
167167
G2,
168168
MinRootCircuit<<G1 as Group>::Scalar>,
169169
TrivialCircuit<<G2 as Group>::Scalar>,
170-
>::new(&circuit_primary, &circuit_secondary, None, None);
170+
>::new(&circuit_primary, &circuit_secondary, &(|_| 0), &(|_| 0));
171171
println!("PublicParams::setup, took {:?} ", start.elapsed());
172172
encode(&pp, &mut file).unwrap()
173173
};
@@ -193,7 +193,7 @@ fn main() {
193193
G2,
194194
MinRootCircuit<<G1 as Group>::Scalar>,
195195
TrivialCircuit<<G2 as Group>::Scalar>,
196-
>::new(&circuit_primary, &circuit_secondary, None, None);
196+
>::new(&circuit_primary, &circuit_secondary, &(|_| 0), &(|_| 0));
197197
assert!(result.clone() == pp, "not equal!");
198198
assert!(remaining.is_empty());
199199
} else {

src/bellpepper/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ mod tests {
5050
// First create the shape
5151
let mut cs: ShapeCS<G> = ShapeCS::new();
5252
let _ = synthesize_alloc_bit(&mut cs);
53-
let (shape, ck) = cs.r1cs_shape_and_key(None);
53+
let (shape, ck) = cs.r1cs_shape_and_key(&(|_| 0));
5454

5555
// Now get the assignment
5656
let mut cs: SatisfyingAssignment<G> = SatisfyingAssignment::new();

src/bellpepper/r1cs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ pub trait NovaShape<G: Group> {
3030
/// `r1cs::R1CS::commitment_key`.
3131
fn r1cs_shape_and_key(
3232
&self,
33-
optfn: Option<CommitmentKeyHint<G>>,
33+
ck_hint: &CommitmentKeyHint<G>,
3434
) -> (R1CSShape<G>, CommitmentKey<G>) {
3535
let S = self.r1cs_shape();
36-
let ck = commitment_key(&S, optfn);
36+
let ck = commitment_key(&S, ck_hint);
3737

3838
(S, ck)
3939
}

src/circuit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ mod tests {
393393
NovaAugmentedCircuit::new(primary_params, None, &tc1, ro_consts1.clone());
394394
let mut cs: TestShapeCS<G1> = TestShapeCS::new();
395395
let _ = circuit1.synthesize(&mut cs);
396-
let (shape1, ck1) = cs.r1cs_shape_and_key(None);
396+
let (shape1, ck1) = cs.r1cs_shape_and_key(&(|_| 0));
397397
assert_eq!(cs.num_constraints(), num_constraints_primary);
398398

399399
let tc2 = TrivialCircuit::default();
@@ -402,7 +402,7 @@ mod tests {
402402
NovaAugmentedCircuit::new(secondary_params, None, &tc2, ro_consts2.clone());
403403
let mut cs: TestShapeCS<G2> = TestShapeCS::new();
404404
let _ = circuit2.synthesize(&mut cs);
405-
let (shape2, ck2) = cs.r1cs_shape_and_key(None);
405+
let (shape2, ck2) = cs.r1cs_shape_and_key(&(|_| 0));
406406
assert_eq!(cs.num_constraints(), num_constraints_secondary);
407407

408408
// Execute the base case for the primary

0 commit comments

Comments
 (0)