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

Improve the design of circuit, config, and instances for CycleFold #158

Open
wants to merge 4 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
614 changes: 387 additions & 227 deletions folding-schemes/src/folding/circuits/cyclefold.rs

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion folding-schemes/src/folding/circuits/decider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ pub trait DeciderEnabledNIFS<
fn fold_field_elements_gadget(
arith: &A,
transcript: &mut PoseidonSpongeVar<CF1<C>>,
pp_hash: FpVar<CF1<C>>,
U: RU::Var,
U_vec: Vec<FpVar<CF1<C>>>,
u: IU::Var,
Expand Down
15 changes: 7 additions & 8 deletions folding-schemes/src/folding/circuits/decider/off_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// More details can be found at the documentation page:
/// https://privacy-scaling-explorations.github.io/sonobe-docs/design/nova-decider-offchain.html
use ark_crypto_primitives::sponge::{
constraints::{AbsorbGadget, CryptographicSpongeVar},
constraints::AbsorbGadget,
poseidon::{constraints::PoseidonSpongeVar, PoseidonConfig},
};
use ark_r1cs_std::{alloc::AllocVar, eq::EqGadget, fields::fp::FpVar};
Expand All @@ -27,6 +27,7 @@ use crate::{
nova::{decider_eth_circuit::WitnessVar, nifs::nova_circuits::CommittedInstanceVar},
traits::{CommittedInstanceOps, CommittedInstanceVarOps, Dummy, WitnessOps, WitnessVarOps},
},
transcript::TranscriptVar,
Curve,
};

Expand Down Expand Up @@ -177,10 +178,10 @@ where
let kzg_evaluations = Vec::new_input(cs.clone(), || Ok(self.kzg_evaluations))?;

// `sponge` is for digest computation.
let sponge = PoseidonSpongeVar::new(cs.clone(), &self.poseidon_config);
// notice that `pp_hash` has already been absorbed during init.
let sponge = PoseidonSpongeVar::new_with_pp_hash(&self.poseidon_config, &pp_hash)?;
// `transcript` is for challenge generation.
let mut transcript = sponge.clone();
// notice that the `pp_hash` is absorbed inside the ChallengeGadget::get_challenge_gadget call

// 1. enforce `U_{i+1}` and `W_{i+1}` satisfy `arith`
arith.enforce_relation(&W_i1, &U_i1)?;
Expand All @@ -189,15 +190,14 @@ where
u_i.enforce_incoming()?;

// 3. u_i.x[0] == H(i, z_0, z_i, U_i), u_i.x[1] == H(cf_U_i)
let (u_i_x, U_i_vec) = U_i.hash(&sponge, &pp_hash, &i, &z_0, &z_i)?;
let (cf_u_i_x, _) = cf_U_i.hash(&sponge, pp_hash.clone())?;
let (u_i_x, U_i_vec) = U_i.hash(&sponge, &i, &z_0, &z_i)?;
let (cf_u_i_x, _) = cf_U_i.hash(&sponge)?;
u_i.get_public_inputs().enforce_equal(&[u_i_x, cf_u_i_x])?;

// 6.1. partially enforce `NIFS.V(U_i, u_i) = U_{i+1}`.
D::fold_field_elements_gadget(
&self.arith,
&mut transcript,
pp_hash,
U_i,
U_i_vec,
u_i,
Expand Down Expand Up @@ -281,8 +281,7 @@ impl<C2: Curve> ConstraintSynthesizer<CF1<C2>> for GenericOffchainDeciderCircuit
let kzg_evaluations = Vec::new_input(cs.clone(), || Ok(self.kzg_evaluations))?;

// `transcript` is for challenge generation.
let mut transcript = PoseidonSpongeVar::new(cs.clone(), &self.poseidon_config);
transcript.absorb(&pp_hash)?;
let mut transcript = PoseidonSpongeVar::new_with_pp_hash(&self.poseidon_config, &pp_hash)?;

// 5. enforce `cf_U_i` and `cf_W_i` satisfy `cf_r1cs`
cf_r1cs.enforce_relation(&cf_W_i, &cf_U_i)?;
Expand Down
10 changes: 5 additions & 5 deletions folding-schemes/src/folding/circuits/decider/on_chain.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// This file implements the onchain (Ethereum's EVM) decider circuit. For non-ethereum use cases,
/// other more efficient approaches can be used.
use ark_crypto_primitives::sponge::{
constraints::{AbsorbGadget, CryptographicSpongeVar},
constraints::AbsorbGadget,
poseidon::{constraints::PoseidonSpongeVar, PoseidonConfig},
};
use ark_r1cs_std::{alloc::AllocVar, eq::EqGadget, fields::fp::FpVar};
Expand All @@ -22,6 +22,7 @@ use crate::{
},
traits::{CommittedInstanceOps, CommittedInstanceVarOps, Dummy, WitnessOps, WitnessVarOps},
},
transcript::TranscriptVar,
Curve,
};

Expand Down Expand Up @@ -211,7 +212,7 @@ where
let kzg_evaluations = Vec::new_input(cs.clone(), || Ok(self.kzg_evaluations))?;

// `sponge` is for digest computation.
let sponge = PoseidonSpongeVar::new(cs.clone(), &self.poseidon_config);
let sponge = PoseidonSpongeVar::new_with_pp_hash(&self.poseidon_config, &pp_hash)?;
// `transcript` is for challenge generation.
let mut transcript = sponge.clone();

Expand All @@ -226,8 +227,8 @@ where
u_i.enforce_incoming()?;

// 3. u_i.x[0] == H(i, z_0, z_i, U_i), u_i.x[1] == H(cf_U_i)
let (u_i_x, U_i_vec) = U_i.hash(&sponge, &pp_hash, &i, &z_0, &z_i)?;
let (cf_u_i_x, _) = cf_U_i.hash(&sponge, pp_hash.clone())?;
let (u_i_x, U_i_vec) = U_i.hash(&sponge, &i, &z_0, &z_i)?;
let (cf_u_i_x, _) = cf_U_i.hash(&sponge)?;
u_i.get_public_inputs().enforce_equal(&[u_i_x, cf_u_i_x])?;

#[cfg(feature = "light-test")]
Expand Down Expand Up @@ -286,7 +287,6 @@ where
D::fold_field_elements_gadget(
&self.arith,
&mut transcript,
pp_hash,
U_i,
U_i_vec,
u_i,
Expand Down
Loading
Loading