Skip to content

Commit

Permalink
supernova: restructure modules (#40)
Browse files Browse the repository at this point in the history
* modules reorg

* fix compression imports
  • Loading branch information
slumber authored Jan 19, 2024
1 parent ae0b3b4 commit 2a1f909
Show file tree
Hide file tree
Showing 28 changed files with 59 additions and 50 deletions.
2 changes: 1 addition & 1 deletion supernova/src/circuits/nova/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ pub mod sequential;
pub mod public_params;

pub use super::{NovaConstraintSynthesizer, StepCircuit};
pub use crate::multifold::Error;
pub use crate::folding::nova::cyclefold::Error;
10 changes: 5 additions & 5 deletions supernova/src/circuits/nova/pcd/augmented.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ use ark_std::Zero;
use crate::{
circuits::{NovaConstraintSynthesizer, StepCircuit},
commitment::CommitmentScheme,
gadgets::multifold::{
multifold, multifold_with_relaxed, primary, secondary, NonNativeAffineVar,
},
multifold::{
folding::nova::cyclefold::{
self,
nimfs::{NIMFSProof, R1CSInstance, R1CSShape, RelaxedR1CSInstance},
secondary::Circuit as SecondaryCircuit,
},
gadgets::cyclefold::{
multifold, multifold_with_relaxed, primary, secondary, NonNativeAffineVar,
},
};

pub const SQUEEZE_NATIVE_ELEMENTS_NUM: usize = 1;
Expand Down Expand Up @@ -298,7 +298,7 @@ where
NovaAugmentedCircuitInput::Base { vk, i, z_i } => {
let shape =
R1CSShape::<G1>::new(0, 0, AUGMENTED_CIRCUIT_NUM_IO, &[], &[], &[]).unwrap();
let shape_secondary = multifold::secondary::setup_shape::<G1, G2>()?;
let shape_secondary = cyclefold::secondary::setup_shape::<G1, G2>()?;

let U = RelaxedR1CSInstance::<G1, C1>::new(&shape);
let U_secondary = RelaxedR1CSInstance::<G2, C2>::new(&shape_secondary);
Expand Down
2 changes: 1 addition & 1 deletion supernova/src/circuits/nova/pcd/compression/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use ark_spartan::{

use super::PolyVectorCommitment;
use crate::{
multifold::nimfs::{R1CSShape, RelaxedR1CSInstance, RelaxedR1CSWitness},
folding::nova::cyclefold::nimfs::{R1CSShape, RelaxedR1CSInstance, RelaxedR1CSWitness},
r1cs::SparseMatrix,
};

Expand Down
2 changes: 1 addition & 1 deletion supernova/src/circuits/nova/pcd/compression/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ark_relations::r1cs::SynthesisError;
use ark_spartan::errors::ProofVerifyError;

use super::conversion::ConversionError;
pub use crate::multifold::Error as NovaError;
pub use crate::folding::nova::cyclefold::Error as NovaError;

#[derive(Debug)]
pub enum ProofError {
Expand Down
4 changes: 3 additions & 1 deletion supernova/src/circuits/nova/pcd/compression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ use super::PublicParams;
use crate::{
absorb::CryptographicSpongeExt,
commitment::CommitmentScheme,
multifold::nimfs::{NIMFSProof, R1CSInstance, RelaxedR1CSInstance, RelaxedR1CSWitness},
folding::nova::cyclefold::nimfs::{
NIMFSProof, R1CSInstance, RelaxedR1CSInstance, RelaxedR1CSWitness,
},
nova::pcd::{augmented::SQUEEZE_NATIVE_ELEMENTS_NUM, PCDNode},
StepCircuit, LOG_TARGET,
};
Expand Down
24 changes: 12 additions & 12 deletions supernova/src/circuits/nova/pcd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use super::{public_params, NovaConstraintSynthesizer, StepCircuit};
use crate::{
absorb::CryptographicSpongeExt,
commitment::CommitmentScheme,
multifold::{
folding::nova::cyclefold::{
self,
nimfs::{
NIMFSProof, R1CSInstance, R1CSShape, R1CSWitness, RelaxedR1CSInstance,
Expand Down Expand Up @@ -56,7 +56,7 @@ where
step_circuit: &SC,
aux1: &C1::SetupAux,
aux2: &C2::SetupAux,
) -> Result<public_params::PublicParams<G1, G2, C1, C2, RO, SC, Self>, multifold::Error> {
) -> Result<public_params::PublicParams<G1, G2, C1, C2, RO, SC, Self>, cyclefold::Error> {
let _span = tracing::debug_span!(target: LOG_TARGET, "setup").entered();

let i = G1::ScalarField::ZERO;
Expand All @@ -76,7 +76,7 @@ where
cs.finalize();

let shape = R1CSShape::from(cs);
let shape_secondary = multifold::secondary::setup_shape::<G1, G2>()?;
let shape_secondary = cyclefold::secondary::setup_shape::<G1, G2>()?;

let pp = C1::setup(shape.num_vars.max(shape.num_constraints), aux1);
let pp_secondary = C2::setup(
Expand Down Expand Up @@ -169,7 +169,7 @@ where
step_circuit: &SC,
i: usize,
z_i: &[G1::ScalarField],
) -> Result<Self, multifold::Error> {
) -> Result<Self, cyclefold::Error> {
Self::prove_step_with_commit_fn(params, step_circuit, i, z_i, |pp, w| w.commit::<C1>(pp))
}

Expand All @@ -181,7 +181,7 @@ where
i: usize,
z_i: &[G1::ScalarField],
mut commit_fn: impl FnMut(&C1::PP, &R1CSWitness<G1>) -> C1::Commitment,
) -> Result<Self, multifold::Error> {
) -> Result<Self, cyclefold::Error> {
let _span = tracing::debug_span!(
target: LOG_TARGET,
"prove_step",
Expand Down Expand Up @@ -249,7 +249,7 @@ where
step_circuit: &SC,
left_node: &Self,
right_node: &Self,
) -> Result<Self, multifold::Error> {
) -> Result<Self, cyclefold::Error> {
Self::prove_from_with_commit_fn(params, step_circuit, left_node, right_node, |pp, w| {
w.commit::<C1>(pp)
})
Expand All @@ -261,7 +261,7 @@ where
left_node: &Self,
right_node: &Self,
mut commit_fn: impl FnMut(&C1::PP, &R1CSWitness<G1>) -> C1::Commitment,
) -> Result<Self, multifold::Error> {
) -> Result<Self, cyclefold::Error> {
let _span = tracing::debug_span!(
target: LOG_TARGET,
"prove_from",
Expand Down Expand Up @@ -378,7 +378,7 @@ where
pub fn verify(
&self,
params: &PublicParams<G1, G2, C1, C2, RO, SC>,
) -> Result<(), multifold::Error> {
) -> Result<(), cyclefold::Error> {
let _span = tracing::debug_span!(
target: LOG_TARGET,
"verify",
Expand All @@ -387,8 +387,8 @@ where
)
.entered();

const NOT_SATISFIED_ERROR: multifold::Error =
multifold::Error::R1CS(crate::r1cs::Error::NotSatisfied);
const NOT_SATISFIED_ERROR: cyclefold::Error =
cyclefold::Error::R1CS(crate::r1cs::Error::NotSatisfied);
let PCDNode {
i,
j,
Expand Down Expand Up @@ -456,7 +456,7 @@ mod tests {
.unwrap()
}

fn ivc_base_step_with_cycle<G1, G2, C1, C2>() -> Result<(), multifold::Error>
fn ivc_base_step_with_cycle<G1, G2, C1, C2>() -> Result<(), cyclefold::Error>
where
G1: SWCurveConfig,
G2: SWCurveConfig<BaseField = G1::ScalarField, ScalarField = G1::BaseField>,
Expand Down Expand Up @@ -499,7 +499,7 @@ mod tests {
.unwrap()
}

fn ivc_multiple_steps_with_cycle<G1, G2, C1, C2>() -> Result<(), multifold::Error>
fn ivc_multiple_steps_with_cycle<G1, G2, C1, C2>() -> Result<(), cyclefold::Error>
where
G1: SWCurveConfig,
G2: SWCurveConfig<BaseField = G1::ScalarField, ScalarField = G1::BaseField>,
Expand Down
2 changes: 1 addition & 1 deletion supernova/src/circuits/nova/public_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use ark_serialize::{CanonicalDeserialize, CanonicalSerialize, CanonicalSerialize
use super::{Error, StepCircuit};
use crate::{
commitment::CommitmentScheme,
multifold::nimfs::{R1CSShape, SQUEEZE_ELEMENTS_BIT_SIZE},
folding::nova::cyclefold::nimfs::{R1CSShape, SQUEEZE_ELEMENTS_BIT_SIZE},
utils,
};

Expand Down
6 changes: 3 additions & 3 deletions supernova/src/circuits/nova/sequential/augmented.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ use ark_std::Zero;
use crate::{
circuits::{NovaConstraintSynthesizer, StepCircuit},
commitment::CommitmentScheme,
gadgets::multifold::{multifold, primary, secondary, NonNativeAffineVar},
multifold::{
folding::nova::cyclefold::{
self,
nimfs::{NIMFSProof, R1CSInstance, R1CSShape, RelaxedR1CSInstance},
secondary::Circuit as SecondaryCircuit,
},
gadgets::cyclefold::{multifold, primary, secondary, NonNativeAffineVar},
};

pub const SQUEEZE_NATIVE_ELEMENTS_NUM: usize = 1;
Expand Down Expand Up @@ -138,7 +138,7 @@ where
NovaAugmentedCircuitInput::Base { vk, z_0 } => {
let shape =
R1CSShape::<G1>::new(0, 0, AUGMENTED_CIRCUIT_NUM_IO, &[], &[], &[]).unwrap();
let shape_secondary = multifold::secondary::setup_shape::<G1, G2>()?;
let shape_secondary = cyclefold::secondary::setup_shape::<G1, G2>()?;

let U = RelaxedR1CSInstance::<G1, C1>::new(&shape);
let U_secondary = RelaxedR1CSInstance::<G2, C2>::new(&shape_secondary);
Expand Down
18 changes: 9 additions & 9 deletions supernova/src/circuits/nova/sequential/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use crate::{
absorb::CryptographicSpongeExt,
commitment::CommitmentScheme,
multifold::{
folding::nova::cyclefold::{
self,
nimfs::{
NIMFSProof, R1CSInstance, R1CSShape, R1CSWitness, RelaxedR1CSInstance,
Expand Down Expand Up @@ -53,7 +53,7 @@ where
step_circuit: &SC,
aux1: &C1::SetupAux,
aux2: &C2::SetupAux,
) -> Result<public_params::PublicParams<G1, G2, C1, C2, RO, SC, Self>, multifold::Error> {
) -> Result<public_params::PublicParams<G1, G2, C1, C2, RO, SC, Self>, cyclefold::Error> {
let _span = tracing::debug_span!(target: LOG_TARGET, "setup").entered();

let z_0 = vec![G1::ScalarField::ZERO; SC::ARITY];
Expand All @@ -71,7 +71,7 @@ where
cs.finalize();

let shape = R1CSShape::from(cs);
let shape_secondary = multifold::secondary::setup_shape::<G1, G2>()?;
let shape_secondary = cyclefold::secondary::setup_shape::<G1, G2>()?;

let pp = C1::setup(shape.num_vars.max(shape.num_constraints), aux1);
let pp_secondary = C2::setup(
Expand Down Expand Up @@ -221,7 +221,7 @@ where
.unwrap_or(0)
}

pub fn prove_step(self, step_circuit: &SC) -> Result<Self, multifold::Error> {
pub fn prove_step(self, step_circuit: &SC) -> Result<Self, cyclefold::Error> {
let _span = tracing::debug_span!(
target: LOG_TARGET,
"prove_step",
Expand Down Expand Up @@ -330,11 +330,11 @@ where
})
}

pub fn verify(&self, num_steps: usize) -> Result<(), multifold::Error> {
pub fn verify(&self, num_steps: usize) -> Result<(), cyclefold::Error> {
let _span = tracing::debug_span!(target: LOG_TARGET, "verify", %num_steps).entered();

const NOT_SATISFIED_ERROR: multifold::Error =
multifold::Error::R1CS(crate::r1cs::Error::NotSatisfied);
const NOT_SATISFIED_ERROR: cyclefold::Error =
cyclefold::Error::R1CS(crate::r1cs::Error::NotSatisfied);

let Some(non_base) = &self.non_base else {
return Err(NOT_SATISFIED_ERROR);
Expand Down Expand Up @@ -436,7 +436,7 @@ pub(crate) mod tests {
.unwrap()
}

fn ivc_base_step_with_cycle<G1, G2, C1, C2>() -> Result<(), multifold::Error>
fn ivc_base_step_with_cycle<G1, G2, C1, C2>() -> Result<(), cyclefold::Error>
where
G1: SWCurveConfig,
G2: SWCurveConfig<BaseField = G1::ScalarField, ScalarField = G1::BaseField>,
Expand Down Expand Up @@ -480,7 +480,7 @@ pub(crate) mod tests {
.unwrap()
}

fn ivc_multiple_steps_with_cycle<G1, G2, C1, C2>() -> Result<(), multifold::Error>
fn ivc_multiple_steps_with_cycle<G1, G2, C1, C2>() -> Result<(), cyclefold::Error>
where
G1: SWCurveConfig,
G2: SWCurveConfig<BaseField = G1::ScalarField, ScalarField = G1::BaseField>,
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use ark_std::{cfg_iter_mut, vec::Vec};
#[cfg(feature = "parallel")]
use rayon::prelude::*;

use crate::ml_sumcheck::{
use super::super::{
data_structures::ListOfProductsOfPolynomials,
protocol::{verifier::VerifierMsg, IPForMLSumcheck},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ark_ff::{Field, PrimeField};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::vec::Vec;

use crate::ml_sumcheck::{
use super::super::{
data_structures::PolynomialInfo,
protocol::{prover::ProverMsg, IPForMLSumcheck},
Error,
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions supernova/src/folding/hypernova/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod ml_sumcheck;
2 changes: 2 additions & 0 deletions supernova/src/folding/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod hypernova;
pub mod nova;
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
pub(crate) mod nimfs;
pub(crate) mod secondary;

use crate::r1cs::Error as R1CSError;

#[derive(Debug, Clone, Copy)]
pub enum Error {
R1CS(super::r1cs::Error),
R1CS(R1CSError),
Synthesis(ark_relations::r1cs::SynthesisError),

#[cfg(any(test, feature = "spartan"))]
InvalidPublicInput,
}

impl From<super::r1cs::Error> for Error {
fn from(error: super::r1cs::Error) -> Self {
impl From<R1CSError> for Error {
fn from(error: R1CSError) -> Self {
Self::R1CS(error)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{

pub(crate) mod relaxed;

pub use crate::nifs::{NIFSProof, SQUEEZE_ELEMENTS_BIT_SIZE};
pub use crate::folding::nova::nifs::{NIFSProof, SQUEEZE_ELEMENTS_BIT_SIZE};

pub(crate) type R1CSShape<G> = r1cs::R1CSShape<Projective<G>>;
pub(crate) type R1CSInstance<G, C> = r1cs::R1CSInstance<Projective<G>, C>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ark_ff::{Field, PrimeField};
use crate::{
absorb::CryptographicSpongeExt,
commitment::{Commitment, CommitmentScheme},
multifold::secondary,
folding::nova::cyclefold::secondary,
r1cs,
utils::{cast_field_element, cast_field_element_unique},
};
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions supernova/src/folding/nova/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod cyclefold;
pub mod nifs;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ark_crypto_primitives::sponge::{Absorb, CryptographicSponge, FieldElementSiz
use ark_ec::CurveGroup;
use ark_ff::{PrimeField, ToConstraintField};

use super::{
use crate::{
absorb::{AbsorbNonNative, CryptographicSpongeExt},
commitment::{Commitment, CommitmentScheme},
r1cs::{self, R1CSShape, RelaxedR1CSInstance, RelaxedR1CSWitness},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ pub(crate) mod primary;
pub(crate) mod secondary;

pub use super::nonnative::{cast_field_element_unique, short_weierstrass::NonNativeAffineVar};
use crate::{commitment::CommitmentScheme, multifold::nimfs::SQUEEZE_ELEMENTS_BIT_SIZE};
use crate::{
commitment::CommitmentScheme, folding::nova::cyclefold::nimfs::SQUEEZE_ELEMENTS_BIT_SIZE,
};

pub fn multifold<G1, G2, C1, C2, RO>(
config: &<RO::Var as CryptographicSpongeVar<G1::ScalarField, RO>>::Parameters,
Expand Down Expand Up @@ -326,7 +328,7 @@ where
mod tests {
use super::*;
use crate::{
multifold::{
folding::nova::cyclefold::{
nimfs::{NIMFSProof, RelaxedR1CSInstance, RelaxedR1CSWitness},
secondary as multifold_secondary,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use ark_std::fmt::Debug;
use super::NonNativeAffineVar;
use crate::{
commitment::CommitmentScheme,
multifold::nimfs::{R1CSInstance, RelaxedR1CSInstance},
folding::nova::cyclefold::nimfs::{R1CSInstance, RelaxedR1CSInstance},
};

#[must_use]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use ark_relations::r1cs::{ConstraintSystemRef, Namespace, SynthesisError};
use super::{cast_field_element_unique, NonNativeAffineVar};
use crate::{
commitment::CommitmentScheme,
multifold::{
folding::nova::cyclefold::{
nimfs::{R1CSInstance, RelaxedR1CSInstance},
secondary::{Circuit as SecondaryCircuit, Proof},
},
Expand Down
2 changes: 1 addition & 1 deletion supernova/src/gadgets/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub(crate) mod multifold;
pub(crate) mod cyclefold;
pub(crate) mod nonnative;
4 changes: 1 addition & 3 deletions supernova/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
#![allow(clippy::large_enum_variant)]

mod absorb;
mod ml_sumcheck;
mod multifold;
mod nifs;
mod provider;
mod utils;

mod circuits;
mod folding;
mod gadgets;

#[cfg(test)]
Expand Down

0 comments on commit 2a1f909

Please sign in to comment.