Skip to content

Commit

Permalink
reduce ~65% proving time in HyperNova by removing the not-needed cs.f…
Browse files Browse the repository at this point in the history
…inalize calls
  • Loading branch information
arnaucube committed Dec 16, 2024
1 parent 83d1383 commit d8d414b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
7 changes: 6 additions & 1 deletion benches/hypernova.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use criterion::*;
use pprof::criterion::{Output, PProfProfiler};

use ark_bn254::{constraints::GVar as bn_GVar, Fr as bn_Fr, G1Projective as bn_G};
use ark_grumpkin::{constraints::GVar as grumpkin_GVar, Projective as grumpkin_G};
Expand Down Expand Up @@ -79,5 +80,9 @@ fn bench_hypernova_ivc(c: &mut Criterion) {
}
}

criterion_group!(benches, bench_hypernova_ivc);
criterion_group! {
name = benches;
config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
targets = bench_hypernova_ivc
}
criterion_main!(benches);
7 changes: 6 additions & 1 deletion benches/protogalaxy.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use criterion::*;
use pprof::criterion::{Output, PProfProfiler};

use ark_bn254::{constraints::GVar as bn_GVar, Fr as bn_Fr, G1Projective as bn_G};
use ark_grumpkin::{constraints::GVar as grumpkin_GVar, Projective as grumpkin_G};
Expand Down Expand Up @@ -73,5 +74,9 @@ fn bench_protogalaxy_ivc(c: &mut Criterion) {
}
}

criterion_group!(benches, bench_protogalaxy_ivc);
criterion_group! {
name = benches;
config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
targets = bench_protogalaxy_ivc
}
criterion_main!(benches);
12 changes: 10 additions & 2 deletions folding-schemes/src/folding/hypernova/circuits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,11 @@ where
Ok(ccs)
}

/// Returns the cs (ConstraintSystem) and the CCS out of the AugmentedFCircuit
/// Returns the cs (ConstraintSystem) and the CCS out of the AugmentedFCircuit.
/// Notice that in order to be able to internally call the `extract_r1cs` function, this method
/// calls the `cs.finalize` method which consumes a noticeable portion of the time. If the CCS
/// is not needed, directly generate the ConstraintSystem without calling the `finalize` method
/// will save computing time.
#[allow(clippy::type_complexity)]
pub fn compute_cs_ccs(
&self,
Expand Down Expand Up @@ -1429,7 +1433,11 @@ mod tests {
cf_U_i = cf_U_i1;
}

let (cs, _) = augmented_f_circuit.compute_cs_ccs()?;
let cs = ConstraintSystem::<Fr>::new_ref();
augmented_f_circuit
.clone()
.generate_constraints(cs.clone())?;
let cs = cs.into_inner().ok_or(Error::NoInnerConstraintSystem)?;
assert!(cs.is_satisfied()?);

let (r1cs_w_i1, r1cs_x_i1) = extract_w_x::<Fr>(&cs); // includes 1 and public inputs
Expand Down
11 changes: 8 additions & 3 deletions folding-schemes/src/folding/hypernova/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use ark_crypto_primitives::sponge::{
use ark_ec::CurveGroup;
use ark_ff::{BigInteger, PrimeField};
use ark_r1cs_std::prelude::CurveVar;
use ark_relations::r1cs::{ConstraintSynthesizer, ConstraintSystem};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize, Compress, SerializationError};
use ark_std::{fmt::Debug, marker::PhantomData, rand::RngCore, One, Zero};

Expand Down Expand Up @@ -427,15 +428,17 @@ where
cf_cmT: None,
};

let (cs, _) = augmented_f_circuit.compute_cs_ccs()?;
let cs = ConstraintSystem::<C1::ScalarField>::new_ref();
augmented_f_circuit.generate_constraints(cs.clone())?;
let cs = cs.into_inner().ok_or(Error::NoInnerConstraintSystem)?;

#[cfg(test)]
assert!(cs.is_satisfied()?);

let (r1cs_w_i1, r1cs_x_i1) = extract_w_x::<C1::ScalarField>(&cs); // includes 1 and public inputs

#[cfg(test)]
assert_eq!(r1cs_x_i1[0], augmented_f_circuit.x.unwrap());
assert_eq!(r1cs_x_i1[0], u_i1_x);

let r1cs_z = [
vec![C1::ScalarField::one()],
Expand Down Expand Up @@ -932,7 +935,9 @@ where
self.cf_U_i = cf_U_i1;
}

let (cs, _) = augmented_f_circuit.compute_cs_ccs()?;
let cs = ConstraintSystem::<C1::ScalarField>::new_ref();
augmented_f_circuit.generate_constraints(cs.clone())?;
let cs = cs.into_inner().ok_or(Error::NoInnerConstraintSystem)?;

#[cfg(test)]
assert!(cs.is_satisfied()?);
Expand Down

0 comments on commit d8d414b

Please sign in to comment.