Skip to content

Commit caa1255

Browse files
committed
refactor: Refactor supernova module to avoid needless pass-by-value
- Modified `SuperNovaAugmentedCircuitParams` to be passed by reference in `test_recursive_circuit_with` function and associated instances in `test.rs`. - Updated `SuperNovaAugmentedCircuit::new` method to match changes in the `test_recursive_circuit_with` function. - Revamped arguments handling in `synthesize_non_base_case` and `synthesize` functions in `circuit.rs`, changing from owned types to references to reduce unnecessary cloning. - Altered function body to accommodate the changes for referenced values in `circuit.rs`.
1 parent 74293b6 commit caa1255

3 files changed

Lines changed: 34 additions & 35 deletions

File tree

.cargo/config

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
xclippy = [
88
"clippy", "--all-targets", "--",
99
"-Wclippy::all",
10-
"-Wclippy::all",
1110
"-Wclippy::match_same_arms",
1211
"-Wclippy::cast_lossless",
1312
"-Wclippy::dbg_macro",

src/supernova/circuit.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -315,16 +315,16 @@ impl<'a, G: Group, SC: StepCircuit<G::Base>> SuperNovaAugmentedCircuit<'a, G, SC
315315
fn synthesize_non_base_case<CS: ConstraintSystem<<G as Group>::Base>>(
316316
&self,
317317
mut cs: CS,
318-
params: AllocatedNum<G::Base>,
319-
i: AllocatedNum<G::Base>,
320-
z_0: Vec<AllocatedNum<G::Base>>,
321-
z_i: Vec<AllocatedNum<G::Base>>,
318+
params: &AllocatedNum<G::Base>,
319+
i: &AllocatedNum<G::Base>,
320+
z_0: &[AllocatedNum<G::Base>],
321+
z_i: &[AllocatedNum<G::Base>],
322322
U: &[AllocatedRelaxedR1CSInstance<G>],
323-
u: AllocatedR1CSInstance<G>,
324-
T: AllocatedPoint<G>,
323+
u: &AllocatedR1CSInstance<G>,
324+
T: &AllocatedPoint<G>,
325325
arity: usize,
326326
last_augmented_circuit_index: &AllocatedNum<G::Base>,
327-
program_counter: Option<AllocatedNum<G::Base>>,
327+
program_counter: &Option<AllocatedNum<G::Base>>,
328328
num_augmented_circuits: usize,
329329
) -> Result<
330330
(
@@ -344,8 +344,8 @@ impl<'a, G: Group, SC: StepCircuit<G::Base>> SuperNovaAugmentedCircuit<'a, G, SC
344344
+ 2 * arity // zo, z1
345345
+ num_augmented_circuits * (7 + 2 * self.params.n_limbs), // #num_augmented_circuits * (7 + [X0, X1]*#num_limb)
346346
);
347-
ro.absorb(&params);
348-
ro.absorb(&i);
347+
ro.absorb(params);
348+
ro.absorb(i);
349349

350350
if self.params.is_primary_circuit {
351351
if let Some(program_counter) = program_counter.as_ref() {
@@ -355,10 +355,10 @@ impl<'a, G: Group, SC: StepCircuit<G::Base>> SuperNovaAugmentedCircuit<'a, G, SC
355355
}
356356
}
357357

358-
for e in &z_0 {
358+
for e in z_0 {
359359
ro.absorb(e);
360360
}
361-
for e in &z_i {
361+
for e in z_i {
362362
ro.absorb(e);
363363
}
364364

@@ -382,9 +382,9 @@ impl<'a, G: Group, SC: StepCircuit<G::Base>> SuperNovaAugmentedCircuit<'a, G, SC
382382
)?;
383383
let U_fold = U_to_fold.fold_with_r1cs(
384384
cs.namespace(|| "compute fold of U and u"),
385-
&params,
386-
&u,
387-
&T,
385+
params,
386+
u,
387+
T,
388388
self.ro_consts.clone(),
389389
self.params.limb_width,
390390
self.params.n_limbs,
@@ -488,16 +488,16 @@ impl<'a, G: Group, SC: StepCircuit<G::Base>> SuperNovaAugmentedCircuit<'a, G, SC
488488
let (last_augmented_circuit_index_checked, U_next_non_base, check_non_base_pass) = self
489489
.synthesize_non_base_case(
490490
cs.namespace(|| "synthesize non base case"),
491-
params.clone(),
492-
i.clone(),
493-
z_0.clone(),
494-
z_i.clone(),
491+
&params,
492+
&i,
493+
&z_0,
494+
&z_i,
495495
&U,
496-
u.clone(),
497-
T,
496+
&u,
497+
&T,
498498
arity,
499499
&last_augmented_circuit_index,
500-
program_counter.clone(),
500+
&program_counter,
501501
num_augmented_circuits,
502502
)?;
503503

src/supernova/test.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ where
228228
}
229229

230230
fn print_constraints_name_on_error_index<G1, G2, C1, C2>(
231-
err: SuperNovaError,
231+
err: &SuperNovaError,
232232
running_claim: &RunningClaim<G1, G2, C1, C2>,
233233
num_augmented_circuits: usize,
234234
) where
@@ -238,7 +238,7 @@ fn print_constraints_name_on_error_index<G1, G2, C1, C2>(
238238
C2: StepCircuit<G2::Scalar>,
239239
{
240240
match err {
241-
SuperNovaError::UnSatIndex(msg, index) if msg == "r_primary" => {
241+
SuperNovaError::UnSatIndex(msg, index) if *msg == "r_primary" => {
242242
let circuit_primary: SuperNovaAugmentedCircuit<'_, G2, C1> = SuperNovaAugmentedCircuit::new(
243243
&running_claim.params.augmented_circuit_params_primary,
244244
None,
@@ -249,10 +249,10 @@ fn print_constraints_name_on_error_index<G1, G2, C1, C2>(
249249
let mut cs: TestShapeCS<G1> = TestShapeCS::new();
250250
let _ = circuit_primary.synthesize(&mut cs);
251251
cs.constraints
252-
.get(index)
252+
.get(*index)
253253
.tap_some(|constraint| debug!("{msg} failed at constraint {}", constraint.3));
254254
}
255-
SuperNovaError::UnSatIndex(msg, index) if msg == "r_secondary" || msg == "l_secondary" => {
255+
SuperNovaError::UnSatIndex(msg, index) if *msg == "r_secondary" || *msg == "l_secondary" => {
256256
let circuit_secondary: SuperNovaAugmentedCircuit<'_, G1, C2> = SuperNovaAugmentedCircuit::new(
257257
&running_claim.params.augmented_circuit_params_secondary,
258258
None,
@@ -263,7 +263,7 @@ fn print_constraints_name_on_error_index<G1, G2, C1, C2>(
263263
let mut cs: TestShapeCS<G2> = TestShapeCS::new();
264264
let _ = circuit_secondary.synthesize(&mut cs);
265265
cs.constraints
266-
.get(index)
266+
.get(*index)
267267
.tap_some(|constraint| debug!("{msg} failed at constraint {}", constraint.3));
268268
}
269269
_ => (),
@@ -440,7 +440,7 @@ where
440440
)
441441
.map_err(|err| {
442442
print_constraints_name_on_error_index(
443-
err,
443+
&err,
444444
&running_claims[augmented_circuit_index],
445445
test_rom.num_circuits(),
446446
)
@@ -478,8 +478,8 @@ fn test_trivial_nivc() {
478478

479479
// In the following we use 1 to refer to the primary, and 2 to refer to the secondary circuit
480480
fn test_recursive_circuit_with<G1, G2>(
481-
primary_params: SuperNovaAugmentedCircuitParams,
482-
secondary_params: SuperNovaAugmentedCircuitParams,
481+
primary_params: &SuperNovaAugmentedCircuitParams,
482+
secondary_params: &SuperNovaAugmentedCircuitParams,
483483
ro_consts1: ROConstantsCircuit<G2>,
484484
ro_consts2: ROConstantsCircuit<G1>,
485485
num_constraints_primary: usize,
@@ -492,7 +492,7 @@ fn test_recursive_circuit_with<G1, G2>(
492492
let step_circuit1 = TrivialTestCircuit::default();
493493
let arity1 = step_circuit1.arity();
494494
let circuit1: SuperNovaAugmentedCircuit<'_, G2, TrivialTestCircuit<<G2 as Group>::Base>> =
495-
SuperNovaAugmentedCircuit::new(&primary_params, None, &step_circuit1, ro_consts1.clone(), 2);
495+
SuperNovaAugmentedCircuit::new(primary_params, None, &step_circuit1, ro_consts1.clone(), 2);
496496
let mut cs: ShapeCS<G1> = ShapeCS::new();
497497
if let Err(e) = circuit1.synthesize(&mut cs) {
498498
panic!("{}", e)
@@ -505,7 +505,7 @@ fn test_recursive_circuit_with<G1, G2>(
505505
let arity2 = step_circuit2.arity();
506506
let circuit2: SuperNovaAugmentedCircuit<'_, G1, TrivialSecondaryCircuit<<G1 as Group>::Base>> =
507507
SuperNovaAugmentedCircuit::new(
508-
&secondary_params,
508+
secondary_params,
509509
None,
510510
&step_circuit2,
511511
ro_consts2.clone(),
@@ -535,7 +535,7 @@ fn test_recursive_circuit_with<G1, G2>(
535535
);
536536
let step_circuit = TrivialTestCircuit::default();
537537
let circuit1: SuperNovaAugmentedCircuit<'_, G2, TrivialTestCircuit<<G2 as Group>::Base>> =
538-
SuperNovaAugmentedCircuit::new(&primary_params, Some(inputs1), &step_circuit, ro_consts1, 2);
538+
SuperNovaAugmentedCircuit::new(primary_params, Some(inputs1), &step_circuit, ro_consts1, 2);
539539
if let Err(e) = circuit1.synthesize(&mut cs1) {
540540
panic!("{}", e)
541541
}
@@ -561,7 +561,7 @@ fn test_recursive_circuit_with<G1, G2>(
561561
let step_circuit = TrivialSecondaryCircuit::default();
562562
let circuit2: SuperNovaAugmentedCircuit<'_, G1, TrivialSecondaryCircuit<<G1 as Group>::Base>> =
563563
SuperNovaAugmentedCircuit::new(
564-
&secondary_params,
564+
secondary_params,
565565
Some(inputs2),
566566
&step_circuit,
567567
ro_consts2,
@@ -584,5 +584,5 @@ fn test_recursive_circuit() {
584584
let ro_consts1: ROConstantsCircuit<G2> = PoseidonConstantsCircuit::default();
585585
let ro_consts2: ROConstantsCircuit<G1> = PoseidonConstantsCircuit::default();
586586

587-
test_recursive_circuit_with::<G1, G2>(params1, params2, ro_consts1, ro_consts2, 9835, 12035);
587+
test_recursive_circuit_with::<G1, G2>(&params1, &params2, ro_consts1, ro_consts2, 9835, 12035);
588588
}

0 commit comments

Comments
 (0)