Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor and simplify the design of traits #189

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions benches/common.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
use ark_ec::CurveGroup;
use ark_ff::PrimeField;
use criterion::*;

use folding_schemes::{
frontend::{utils::CustomFCircuit, FCircuit},
Error, FoldingScheme,
Error, FoldingScheme, SonobeCurve,
};

pub(crate) fn bench_ivc_opt<
C1: CurveGroup,
C2: CurveGroup,
C1: SonobeCurve<BaseField = C2::ScalarField, ScalarField = C2::BaseField>,
C2: SonobeCurve,
FS: FoldingScheme<C1, C2, CustomFCircuit<C1::ScalarField>>,
>(
c: &mut Criterion,
name: String,
n: usize,
prep_param: FS::PreprocessorParam,
) -> Result<(), Error>
where
C1: CurveGroup<BaseField = C2::ScalarField, ScalarField = C2::BaseField>,
C2::BaseField: PrimeField,
{
) -> Result<(), Error> {
let fcircuit_size = 1 << n; // 2^n

let f_circuit = CustomFCircuit::<C1::ScalarField>::new(fcircuit_size)?;
Expand Down
12 changes: 4 additions & 8 deletions benches/hypernova.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
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};
use ark_pallas::{constraints::GVar as pallas_GVar, Fr as pallas_Fr, Projective as pallas_G};
use ark_vesta::{constraints::GVar as vesta_GVar, Projective as vesta_G};
use ark_bn254::{Fr as bn_Fr, G1Projective as bn_G};
use ark_grumpkin::Projective as grumpkin_G;
use ark_pallas::{Fr as pallas_Fr, Projective as pallas_G};
use ark_vesta::Projective as vesta_G;

use folding_schemes::{
commitment::pedersen::Pedersen,
Expand All @@ -30,9 +30,7 @@ fn bench_hypernova_ivc(c: &mut Criterion) {
vesta_G,
HyperNova<
pallas_G,
pallas_GVar,
vesta_G,
vesta_GVar,
CustomFCircuit<pallas_Fr>,
Pedersen<pallas_G>,
Pedersen<vesta_G>,
Expand Down Expand Up @@ -60,9 +58,7 @@ fn bench_hypernova_ivc(c: &mut Criterion) {
grumpkin_G,
HyperNova<
bn_G,
bn_GVar,
grumpkin_G,
grumpkin_GVar,
CustomFCircuit<bn_Fr>,
Pedersen<bn_G>,
Pedersen<grumpkin_G>,
Expand Down
12 changes: 4 additions & 8 deletions benches/nova.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
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};
use ark_pallas::{constraints::GVar as pallas_GVar, Fr as pallas_Fr, Projective as pallas_G};
use ark_vesta::{constraints::GVar as vesta_GVar, Projective as vesta_G};
use ark_bn254::{Fr as bn_Fr, G1Projective as bn_G};
use ark_grumpkin::Projective as grumpkin_G;
use ark_pallas::{Fr as pallas_Fr, Projective as pallas_G};
use ark_vesta::Projective as vesta_G;

use folding_schemes::{
commitment::pedersen::Pedersen,
Expand All @@ -30,9 +30,7 @@ fn bench_nova_ivc(c: &mut Criterion) {
vesta_G,
Nova<
pallas_G,
pallas_GVar,
vesta_G,
vesta_GVar,
CustomFCircuit<pallas_Fr>,
Pedersen<pallas_G>,
Pedersen<vesta_G>,
Expand All @@ -53,9 +51,7 @@ fn bench_nova_ivc(c: &mut Criterion) {
grumpkin_G,
Nova<
bn_G,
bn_GVar,
grumpkin_G,
grumpkin_GVar,
CustomFCircuit<bn_Fr>,
Pedersen<bn_G>,
Pedersen<grumpkin_G>,
Expand Down
12 changes: 4 additions & 8 deletions benches/protogalaxy.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
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};
use ark_pallas::{constraints::GVar as pallas_GVar, Fr as pallas_Fr, Projective as pallas_G};
use ark_vesta::{constraints::GVar as vesta_GVar, Projective as vesta_G};
use ark_bn254::{Fr as bn_Fr, G1Projective as bn_G};
use ark_grumpkin::Projective as grumpkin_G;
use ark_pallas::{Fr as pallas_Fr, Projective as pallas_G};
use ark_vesta::Projective as vesta_G;

use folding_schemes::{
commitment::pedersen::Pedersen,
Expand All @@ -30,9 +30,7 @@ fn bench_protogalaxy_ivc(c: &mut Criterion) {
vesta_G,
ProtoGalaxy<
pallas_G,
pallas_GVar,
vesta_G,
vesta_GVar,
CustomFCircuit<pallas_Fr>,
Pedersen<pallas_G>,
Pedersen<vesta_G>,
Expand All @@ -57,9 +55,7 @@ fn bench_protogalaxy_ivc(c: &mut Criterion) {
grumpkin_G,
ProtoGalaxy<
bn_G,
bn_GVar,
grumpkin_G,
grumpkin_GVar,
CustomFCircuit<bn_Fr>,
Pedersen<bn_G>,
Pedersen<grumpkin_G>,
Expand Down
9 changes: 3 additions & 6 deletions examples/circom_full_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
/// - generate the Solidity contract that verifies the proof
/// - verify the proof in the EVM
///
use ark_bn254::{constraints::GVar, Bn254, Fr, G1Projective as G1};
use ark_bn254::{Bn254, Fr, G1Projective as G1};

use ark_groth16::Groth16;
use ark_grumpkin::{constraints::GVar as GVar2, Projective as G2};
use ark_grumpkin::Projective as G2;

use std::path::PathBuf;
use std::time::Instant;
Expand Down Expand Up @@ -67,13 +67,10 @@ fn main() -> Result<(), Error> {
let f_circuit_params = (r1cs_path.into(), wasm_path.into(), 1, 2);
let f_circuit = CircomFCircuit::<Fr>::new(f_circuit_params)?;

pub type N =
Nova<G1, GVar, G2, GVar2, CircomFCircuit<Fr>, KZG<'static, Bn254>, Pedersen<G2>, false>;
pub type N = Nova<G1, G2, CircomFCircuit<Fr>, KZG<'static, Bn254>, Pedersen<G2>, false>;
pub type D = DeciderEth<
G1,
GVar,
G2,
GVar2,
CircomFCircuit<Fr>,
KZG<'static, Bn254>,
Pedersen<G2>,
Expand Down
6 changes: 2 additions & 4 deletions examples/external_inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#![allow(non_camel_case_types)]
#![allow(clippy::upper_case_acronyms)]

use ark_bn254::{constraints::GVar, Bn254, Fr, G1Projective as Projective};
use ark_bn254::{Bn254, Fr, G1Projective as Projective};
use ark_crypto_primitives::{
crh::{
poseidon::constraints::{CRHGadget, CRHParametersVar},
Expand All @@ -12,7 +12,7 @@ use ark_crypto_primitives::{
sponge::{poseidon::PoseidonConfig, Absorb},
};
use ark_ff::PrimeField;
use ark_grumpkin::{constraints::GVar as GVar2, Projective as Projective2};
use ark_grumpkin::Projective as Projective2;
use ark_r1cs_std::alloc::AllocVar;
use ark_r1cs_std::fields::fp::FpVar;
use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError};
Expand Down Expand Up @@ -169,9 +169,7 @@ fn main() -> Result<(), Error> {
/// trait, and the rest of our code would be working without needing to be updated.
type N = Nova<
Projective,
GVar,
Projective2,
GVar2,
ExternalInputsCircuit<Fr>,
KZG<'static, Bn254>,
Pedersen<Projective2>,
Expand Down
20 changes: 5 additions & 15 deletions examples/full_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
/// - generate the Solidity contract that verifies the proof
/// - verify the proof in the EVM
///
use ark_bn254::{constraints::GVar, Bn254, Fr, G1Projective as G1};
use ark_bn254::{Bn254, Fr, G1Projective as G1};
use ark_ff::PrimeField;
use ark_groth16::Groth16;
use ark_grumpkin::{constraints::GVar as GVar2, Projective as G2};
use ark_grumpkin::Projective as G2;
use ark_r1cs_std::alloc::AllocVar;
use ark_r1cs_std::fields::fp::FpVar;
use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError};
Expand Down Expand Up @@ -76,19 +76,9 @@ fn main() -> Result<(), Error> {

let f_circuit = CubicFCircuit::<Fr>::new(())?;

pub type N =
Nova<G1, GVar, G2, GVar2, CubicFCircuit<Fr>, KZG<'static, Bn254>, Pedersen<G2>, false>;
pub type D = DeciderEth<
G1,
GVar,
G2,
GVar2,
CubicFCircuit<Fr>,
KZG<'static, Bn254>,
Pedersen<G2>,
Groth16<Bn254>,
N,
>;
pub type N = Nova<G1, G2, CubicFCircuit<Fr>, KZG<'static, Bn254>, Pedersen<G2>, false>;
pub type D =
DeciderEth<G1, G2, CubicFCircuit<Fr>, KZG<'static, Bn254>, Pedersen<G2>, Groth16<Bn254>, N>;

let poseidon_config = poseidon_canonical_config::<Fr>();
let mut rng = ark_std::rand::rngs::OsRng;
Expand Down
6 changes: 2 additions & 4 deletions examples/multi_inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError};
use core::marker::PhantomData;
use std::time::Instant;

use ark_bn254::{constraints::GVar, Bn254, Fr, G1Projective as Projective};
use ark_grumpkin::{constraints::GVar as GVar2, Projective as Projective2};
use ark_bn254::{Bn254, Fr, G1Projective as Projective};
use ark_grumpkin::Projective as Projective2;

use folding_schemes::commitment::{kzg::KZG, pedersen::Pedersen};
use folding_schemes::folding::nova::{Nova, PreprocessorParam};
Expand Down Expand Up @@ -123,9 +123,7 @@ fn main() -> Result<(), Error> {
/// trait, and the rest of our code would be working without needing to be updated.
type N = Nova<
Projective,
GVar,
Projective2,
GVar2,
MultiInputsFCircuit<Fr>,
KZG<'static, Bn254>,
Pedersen<Projective2>,
Expand Down
19 changes: 5 additions & 14 deletions examples/noir_full_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
/// - generate the Solidity contract that verifies the proof
/// - verify the proof in the EVM
///
use ark_bn254::{constraints::GVar, Bn254, Fr, G1Projective as G1};
use ark_bn254::{Bn254, Fr, G1Projective as G1};

use ark_groth16::Groth16;
use ark_grumpkin::{constraints::GVar as GVar2, Projective as G2};
use ark_grumpkin::Projective as G2;

use experimental_frontends::noir::NoirFCircuit;
use folding_schemes::{
Expand Down Expand Up @@ -49,18 +49,9 @@ fn main() -> Result<(), Error> {
0,
))?;

pub type N = Nova<G1, GVar, G2, GVar2, NoirFCircuit<Fr>, KZG<'static, Bn254>, Pedersen<G2>>;
pub type D = DeciderEth<
G1,
GVar,
G2,
GVar2,
NoirFCircuit<Fr>,
KZG<'static, Bn254>,
Pedersen<G2>,
Groth16<Bn254>,
N,
>;
pub type N = Nova<G1, G2, NoirFCircuit<Fr>, KZG<'static, Bn254>, Pedersen<G2>>;
pub type D =
DeciderEth<G1, G2, NoirFCircuit<Fr>, KZG<'static, Bn254>, Pedersen<G2>, Groth16<Bn254>, N>;

let poseidon_config = poseidon_canonical_config::<Fr>();
let mut rng = ark_std::rand::rngs::OsRng;
Expand Down
17 changes: 4 additions & 13 deletions examples/noname_full_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
/// - generate the Solidity contract that verifies the proof
/// - verify the proof in the EVM
///
use ark_bn254::{constraints::GVar, Bn254, Fr, G1Projective as G1};
use ark_bn254::{Bn254, Fr, G1Projective as G1};
use noname::backends::r1cs::R1csBn254Field;

use ark_groth16::Groth16;
use ark_grumpkin::{constraints::GVar as GVar2, Projective as G2};
use ark_grumpkin::Projective as G2;

use experimental_frontends::noname::NonameFCircuit;
use folding_schemes::{
Expand Down Expand Up @@ -61,20 +61,11 @@ fn main() -> Result<(), Error> {
let f_circuit_params = (NONAME_CIRCUIT_EXTERNAL_INPUTS.to_owned(), 2, 2);
let f_circuit = NonameFCircuit::<Fr, R1csBn254Field>::new(f_circuit_params)?;

pub type N = Nova<
G1,
GVar,
G2,
GVar2,
NonameFCircuit<Fr, R1csBn254Field>,
KZG<'static, Bn254>,
Pedersen<G2>,
>;
pub type N =
Nova<G1, G2, NonameFCircuit<Fr, R1csBn254Field>, KZG<'static, Bn254>, Pedersen<G2>>;
pub type D = DeciderEth<
G1,
GVar,
G2,
GVar2,
NonameFCircuit<Fr, R1csBn254Field>,
KZG<'static, Bn254>,
Pedersen<G2>,
Expand Down
6 changes: 2 additions & 4 deletions examples/sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError};
use core::marker::PhantomData;
use std::time::Instant;

use ark_bn254::{constraints::GVar, Bn254, Fr, G1Projective as Projective};
use ark_grumpkin::{constraints::GVar as GVar2, Projective as Projective2};
use ark_bn254::{Bn254, Fr, G1Projective as Projective};
use ark_grumpkin::Projective as Projective2;

use folding_schemes::commitment::{kzg::KZG, pedersen::Pedersen};
use folding_schemes::folding::nova::{Nova, PreprocessorParam};
Expand Down Expand Up @@ -107,9 +107,7 @@ fn main() -> Result<(), Error> {
/// trait, and the rest of our code would be working without needing to be updated.
type N = Nova<
Projective,
GVar,
Projective2,
GVar2,
Sha256FCircuit<Fr>,
KZG<'static, Bn254>,
Pedersen<Projective2>,
Expand Down
5 changes: 2 additions & 3 deletions folding-schemes/src/arith/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use ark_ec::CurveGroup;
use ark_relations::r1cs::SynthesisError;
use ark_std::rand::RngCore;

use crate::{commitment::CommitmentScheme, folding::traits::Dummy, Error};
use crate::{commitment::CommitmentScheme, folding::traits::Dummy, Error, SonobeCurve};

pub mod ccs;
pub mod r1cs;
Expand Down Expand Up @@ -123,7 +122,7 @@ pub trait ArithSerializer {
/// in a plain R1CS.
///
/// [HyperNova]: https://eprint.iacr.org/2023/573.pdf
pub trait ArithSampler<C: CurveGroup, W, U>: Arith<W, U> {
pub trait ArithSampler<C: SonobeCurve, W, U>: Arith<W, U> {
/// Samples a random witness and instance that satisfy the constraint system.
fn sample_witness_instance<CS: CommitmentScheme<C, true>>(
&self,
Expand Down
10 changes: 5 additions & 5 deletions folding-schemes/src/arith/r1cs/circuits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub mod tests {
},
CRHScheme, CRHSchemeGadget,
};
use ark_ec::CurveGroup;

use ark_ff::BigInteger;
use ark_pallas::{Fq, Fr, Projective};
use ark_r1cs_std::{eq::EqGadget, fields::fp::FpVar, uint8::UInt8};
Expand All @@ -104,7 +104,7 @@ pub mod tests {
rand::{thread_rng, Rng},
One, UniformRand,
};
use ark_vesta::{constraints::GVar as GVar2, Projective as Projective2};
use ark_vesta::Projective as Projective2;

use super::*;
use crate::arith::{
Expand All @@ -131,9 +131,9 @@ pub mod tests {
},
FCircuit,
};
use crate::Error;
use crate::{Error, SonobeCurve};

fn prepare_instances<C: CurveGroup, CS: CommitmentScheme<C>, R: Rng>(
fn prepare_instances<C: SonobeCurve, CS: CommitmentScheme<C>, R: Rng>(
mut rng: R,
r1cs: &R1CS<C::ScalarField>,
z: &[C::ScalarField],
Expand Down Expand Up @@ -295,7 +295,7 @@ pub mod tests {
// non-natively
let cs = ConstraintSystem::<Fr>::new_ref();
let wVar = CycleFoldWitnessVar::new_witness(cs.clone(), || Ok(w))?;
let uVar = CycleFoldCommittedInstanceVar::<_, GVar2>::new_witness(cs.clone(), || Ok(u))?;
let uVar = CycleFoldCommittedInstanceVar::new_witness(cs.clone(), || Ok(u))?;
let r1csVar =
R1CSMatricesVar::<Fq, NonNativeUintVar<Fr>>::new_witness(cs.clone(), || Ok(r1cs))?;
r1csVar.enforce_relation(&wVar, &uVar)?;
Expand Down
Loading
Loading