Skip to content

Commit

Permalink
rollback to immutable stepcircuit instance
Browse files Browse the repository at this point in the history
  • Loading branch information
hero78119 committed Oct 6, 2023
1 parent 1e424da commit 61eb0fd
Show file tree
Hide file tree
Showing 8 changed files with 482 additions and 442 deletions.
30 changes: 15 additions & 15 deletions benches/compressed-snark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ fn bench_compressed_snark(c: &mut Criterion) {
let mut group = c.benchmark_group(format!("CompressedSNARK-StepCircuitSize-{num_cons}"));
group.sample_size(num_samples);

let mut c_primary = NonTrivialTestCircuit::new(num_cons);
let mut c_secondary = TrivialTestCircuit::default();
let c_primary = NonTrivialTestCircuit::new(num_cons);
let c_secondary = TrivialTestCircuit::default();

// Produce public parameters
let pp = PublicParams::<G1, G2, C1, C2>::setup(
Expand All @@ -81,17 +81,17 @@ fn bench_compressed_snark(c: &mut Criterion) {
let num_steps = 3;
let mut recursive_snark: RecursiveSNARK<G1, G2, C1, C2> = RecursiveSNARK::new(
&pp,
&mut c_primary,
&mut c_secondary,
&c_primary,
&c_secondary,
vec![<G1 as Group>::Scalar::from(2u64)],
vec![<G2 as Group>::Scalar::from(2u64)],
);

for i in 0..num_steps {
let res = recursive_snark.prove_step(
&pp,
&mut c_primary,
&mut c_secondary,
&c_primary,
&c_secondary,
vec![<G1 as Group>::Scalar::from(2u64)],
vec![<G2 as Group>::Scalar::from(2u64)],
);
Expand Down Expand Up @@ -155,13 +155,13 @@ fn bench_compressed_snark_with_computational_commitments(c: &mut Criterion) {
.sampling_mode(SamplingMode::Flat)
.sample_size(num_samples);

let mut c_primary = NonTrivialTestCircuit::new(num_cons);
let mut c_secondary = TrivialTestCircuit::default();
let c_primary = NonTrivialTestCircuit::new(num_cons);
let c_secondary = TrivialTestCircuit::default();

// Produce public parameters
let pp = PublicParams::<G1, G2, C1, C2>::setup(
&mut c_primary,
&mut c_secondary,
&c_primary,
&c_secondary,
Some(SS1::commitment_key_floor()),
Some(SS2::commitment_key_floor()),
)
Expand All @@ -173,17 +173,17 @@ fn bench_compressed_snark_with_computational_commitments(c: &mut Criterion) {
let num_steps = 3;
let mut recursive_snark: RecursiveSNARK<G1, G2, C1, C2> = RecursiveSNARK::new(
&pp,
&mut c_primary,
&mut c_secondary,
&c_primary,
&c_secondary,
vec![<G1 as Group>::Scalar::from(2u64)],
vec![<G2 as Group>::Scalar::from(2u64)],
);

for i in 0..num_steps {
let res = recursive_snark.prove_step(
&pp,
&mut c_primary,
&mut c_secondary,
&c_primary,
&c_secondary,
vec![<G1 as Group>::Scalar::from(2u64)],
vec![<G2 as Group>::Scalar::from(2u64)],
);
Expand Down Expand Up @@ -258,7 +258,7 @@ where
}

fn synthesize<CS: ConstraintSystem<F>>(
&mut self,
&self,
cs: &mut CS,
z: &[AllocatedNum<F>],
) -> Result<Vec<AllocatedNum<F>>, SynthesisError> {
Expand Down
2 changes: 1 addition & 1 deletion benches/compute-digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ where
}

fn synthesize<CS: ConstraintSystem<F>>(
&mut self,
&self,
cs: &mut CS,
z: &[AllocatedNum<F>],
) -> Result<Vec<AllocatedNum<F>>, SynthesisError> {
Expand Down
18 changes: 9 additions & 9 deletions src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ pub struct NovaAugmentedCircuit<'a, G: Group, SC: StepCircuit<G::Base>> {
params: &'a NovaAugmentedCircuitParams,
ro_consts: ROConstantsCircuit<G>,
inputs: Option<NovaAugmentedCircuitInputs<G>>,
step_circuit: &'a mut SC, // The function that is applied for each step
step_circuit: &'a SC, // The function that is applied for each step
}

impl<'a, G: Group, SC: StepCircuit<G::Base>> NovaAugmentedCircuit<'a, G, SC> {
/// Create a new verification circuit for the input relaxed r1cs instances
pub fn new(
pub const fn new(
params: &'a NovaAugmentedCircuitParams,
inputs: Option<NovaAugmentedCircuitInputs<G>>,
step_circuit: &'a mut SC,
step_circuit: &'a SC,
ro_consts: ROConstantsCircuit<G>,
) -> Self {
Self {
Expand Down Expand Up @@ -394,19 +394,19 @@ mod tests {
G1: Group<Base = <G2 as Group>::Scalar>,
G2: Group<Base = <G1 as Group>::Scalar>,
{
let mut ttc1 = TrivialTestCircuit::default();
let ttc1 = TrivialTestCircuit::default();
// Initialize the shape and ck for the primary
let circuit1: NovaAugmentedCircuit<'_, G2, TrivialTestCircuit<<G2 as Group>::Base>> =
NovaAugmentedCircuit::new(primary_params, None, &mut ttc1, ro_consts1.clone());
NovaAugmentedCircuit::new(primary_params, None, &ttc1, ro_consts1.clone());
let mut cs: TestShapeCS<G1> = TestShapeCS::new();
let _ = circuit1.synthesize(&mut cs);
let (shape1, ck1) = cs.r1cs_shape_and_key(None);
assert_eq!(cs.num_constraints(), num_constraints_primary);

let mut ttc2 = TrivialTestCircuit::default();
let ttc2 = TrivialTestCircuit::default();
// Initialize the shape and ck for the secondary
let circuit2: NovaAugmentedCircuit<'_, G1, TrivialTestCircuit<<G1 as Group>::Base>> =
NovaAugmentedCircuit::new(secondary_params, None, &mut ttc2, ro_consts2.clone());
NovaAugmentedCircuit::new(secondary_params, None, &ttc2, ro_consts2.clone());
let mut cs: TestShapeCS<G2> = TestShapeCS::new();
let _ = circuit2.synthesize(&mut cs);
let (shape2, ck2) = cs.r1cs_shape_and_key(None);
Expand All @@ -425,7 +425,7 @@ mod tests {
None,
);
let circuit1: NovaAugmentedCircuit<'_, G2, TrivialTestCircuit<<G2 as Group>::Base>> =
NovaAugmentedCircuit::new(primary_params, Some(inputs1), &mut ttc1, ro_consts1);
NovaAugmentedCircuit::new(primary_params, Some(inputs1), &ttc1, ro_consts1);
let _ = circuit1.synthesize(&mut cs1);
let (inst1, witness1) = cs1.r1cs_instance_and_witness(&shape1, &ck1).unwrap();
// Make sure that this is satisfiable
Expand All @@ -444,7 +444,7 @@ mod tests {
None,
);
let circuit2: NovaAugmentedCircuit<'_, G1, TrivialTestCircuit<<G1 as Group>::Base>> =
NovaAugmentedCircuit::new(secondary_params, Some(inputs2), &mut ttc2, ro_consts2);
NovaAugmentedCircuit::new(secondary_params, Some(inputs2), &ttc2, ro_consts2);
let _ = circuit2.synthesize(&mut cs2);
let (inst2, witness2) = cs2.r1cs_instance_and_witness(&shape2, &ck2).unwrap();
// Make sure that it is satisfiable
Expand Down
Loading

0 comments on commit 61eb0fd

Please sign in to comment.