diff --git a/src/circuit.rs b/src/circuit.rs index ebe68f7..9acc65d 100644 --- a/src/circuit.rs +++ b/src/circuit.rs @@ -29,13 +29,13 @@ use bellperson::{ use ff::Field; #[derive(Debug, Clone)] -pub struct NIFSVerifierCircuitParams { +pub struct NovaAugmentedCircuitParams { limb_width: usize, n_limbs: usize, is_primary_circuit: bool, // A boolean indicating if this is the primary circuit } -impl NIFSVerifierCircuitParams { +impl NovaAugmentedCircuitParams { pub fn new(limb_width: usize, n_limbs: usize, is_primary_circuit: bool) -> Self { Self { limb_width, @@ -46,7 +46,7 @@ impl NIFSVerifierCircuitParams { } #[derive(Debug)] -pub struct NIFSVerifierCircuitInputs { +pub struct NovaAugmentedCircuitInputs { params: G::Scalar, // Hash(Shape of u2, Gens for u2). Needed for computing the challenge. i: G::Base, z0: G::Base, @@ -56,7 +56,7 @@ pub struct NIFSVerifierCircuitInputs { T: Option>, } -impl NIFSVerifierCircuitInputs +impl NovaAugmentedCircuitInputs where G: Group, { @@ -83,27 +83,28 @@ where } } -/// Circuit that encodes only the folding verifier -pub struct NIFSVerifierCircuit +/// The augmented circuit F' in Nova that includes a step circuit F +/// and the circuit for the verifier in Nova's non-interactive folding scheme +pub struct NovaAugmentedCircuit where G: Group, SC: StepCircuit, { - params: NIFSVerifierCircuitParams, + params: NovaAugmentedCircuitParams, ro_consts: HashFuncConstantsCircuit, - inputs: Option>, + inputs: Option>, step_circuit: SC, // The function that is applied for each step } -impl NIFSVerifierCircuit +impl NovaAugmentedCircuit where G: Group, SC: StepCircuit, { /// Create a new verification circuit for the input relaxed r1cs instances pub fn new( - params: NIFSVerifierCircuitParams, - inputs: Option>, + params: NovaAugmentedCircuitParams, + inputs: Option>, step_circuit: SC, ro_consts: HashFuncConstantsCircuit, ) -> Self { @@ -250,7 +251,7 @@ where } } -impl Circuit<::Base> for NIFSVerifierCircuit +impl Circuit<::Base> for NovaAugmentedCircuit where G: Group, SC: StepCircuit, @@ -361,14 +362,14 @@ mod tests { #[test] fn test_verification_circuit() { // In the following we use 1 to refer to the primary, and 2 to refer to the secondary circuit - let params1 = NIFSVerifierCircuitParams::new(BN_LIMB_WIDTH, BN_N_LIMBS, true); - let params2 = NIFSVerifierCircuitParams::new(BN_LIMB_WIDTH, BN_N_LIMBS, false); + let params1 = NovaAugmentedCircuitParams::new(BN_LIMB_WIDTH, BN_N_LIMBS, true); + let params2 = NovaAugmentedCircuitParams::new(BN_LIMB_WIDTH, BN_N_LIMBS, false); let ro_consts1: HashFuncConstantsCircuit = PoseidonConstantsCircuit::new(); let ro_consts2: HashFuncConstantsCircuit = PoseidonConstantsCircuit::new(); // Initialize the shape and gens for the primary - let circuit1: NIFSVerifierCircuit::Base>> = - NIFSVerifierCircuit::new( + let circuit1: NovaAugmentedCircuit::Base>> = + NovaAugmentedCircuit::new( params1.clone(), None, TrivialTestCircuit::default(), @@ -380,8 +381,8 @@ mod tests { assert_eq!(cs.num_constraints(), 20584); // Initialize the shape and gens for the secondary - let circuit2: NIFSVerifierCircuit::Base>> = - NIFSVerifierCircuit::new( + let circuit2: NovaAugmentedCircuit::Base>> = + NovaAugmentedCircuit::new( params2.clone(), None, TrivialTestCircuit::default(), @@ -395,10 +396,10 @@ mod tests { // Execute the base case for the primary let zero1 = <::Base as Field>::zero(); let mut cs1: SatisfyingAssignment = SatisfyingAssignment::new(); - let inputs1: NIFSVerifierCircuitInputs = - NIFSVerifierCircuitInputs::new(shape2.get_digest(), zero1, zero1, None, None, None, None); - let circuit1: NIFSVerifierCircuit::Base>> = - NIFSVerifierCircuit::new( + let inputs1: NovaAugmentedCircuitInputs = + NovaAugmentedCircuitInputs::new(shape2.get_digest(), zero1, zero1, None, None, None, None); + let circuit1: NovaAugmentedCircuit::Base>> = + NovaAugmentedCircuit::new( params1, Some(inputs1), TrivialTestCircuit::default(), @@ -412,7 +413,7 @@ mod tests { // Execute the base case for the secondary let zero2 = <::Base as Field>::zero(); let mut cs2: SatisfyingAssignment = SatisfyingAssignment::new(); - let inputs2: NIFSVerifierCircuitInputs = NIFSVerifierCircuitInputs::new( + let inputs2: NovaAugmentedCircuitInputs = NovaAugmentedCircuitInputs::new( shape1.get_digest(), zero2, zero2, @@ -421,8 +422,8 @@ mod tests { Some(inst1), None, ); - let circuit: NIFSVerifierCircuit::Base>> = - NIFSVerifierCircuit::new( + let circuit: NovaAugmentedCircuit::Base>> = + NovaAugmentedCircuit::new( params2, Some(inputs2), TrivialTestCircuit::default(), diff --git a/src/lib.rs b/src/lib.rs index b59d524..b09f75f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,7 +25,7 @@ use crate::bellperson::{ solver::SatisfyingAssignment, }; use ::bellperson::{Circuit, ConstraintSystem}; -use circuit::{NIFSVerifierCircuit, NIFSVerifierCircuitInputs, NIFSVerifierCircuitParams}; +use circuit::{NovaAugmentedCircuit, NovaAugmentedCircuitInputs, NovaAugmentedCircuitParams}; use constants::{BN_LIMB_WIDTH, BN_N_LIMBS}; use core::marker::PhantomData; use errors::NovaError; @@ -58,8 +58,8 @@ where r1cs_gens_secondary: R1CSGens, r1cs_shape_secondary: R1CSShape, r1cs_shape_padded_secondary: R1CSShape, - nifs_params_primary: NIFSVerifierCircuitParams, - nifs_params_secondary: NIFSVerifierCircuitParams, + augmented_circuit_params_primary: NovaAugmentedCircuitParams, + augmented_circuit_params_secondary: NovaAugmentedCircuitParams, _p_c1: PhantomData, _p_c2: PhantomData, } @@ -73,8 +73,10 @@ where { /// Create a new `PublicParams` pub fn setup(c_primary: C1, c_secondary: C2) -> Self { - let nifs_params_primary = NIFSVerifierCircuitParams::new(BN_LIMB_WIDTH, BN_N_LIMBS, true); - let nifs_params_secondary = NIFSVerifierCircuitParams::new(BN_LIMB_WIDTH, BN_N_LIMBS, false); + let augmented_circuit_params_primary = + NovaAugmentedCircuitParams::new(BN_LIMB_WIDTH, BN_N_LIMBS, true); + let augmented_circuit_params_secondary = + NovaAugmentedCircuitParams::new(BN_LIMB_WIDTH, BN_N_LIMBS, false); let ro_consts_primary: HashFuncConstants = HashFuncConstants::::new(); let ro_consts_secondary: HashFuncConstants = HashFuncConstants::::new(); @@ -86,8 +88,8 @@ where HashFuncConstantsCircuit::::new(); // Initialize gens for the primary - let circuit_primary: NIFSVerifierCircuit = NIFSVerifierCircuit::new( - nifs_params_primary.clone(), + let circuit_primary: NovaAugmentedCircuit = NovaAugmentedCircuit::new( + augmented_circuit_params_primary.clone(), None, c_primary, ro_consts_circuit_primary.clone(), @@ -98,8 +100,8 @@ where let r1cs_shape_padded_primary = r1cs_shape_primary.pad(); // Initialize gens for the secondary - let circuit_secondary: NIFSVerifierCircuit = NIFSVerifierCircuit::new( - nifs_params_secondary.clone(), + let circuit_secondary: NovaAugmentedCircuit = NovaAugmentedCircuit::new( + augmented_circuit_params_secondary.clone(), None, c_secondary, ro_consts_circuit_secondary.clone(), @@ -120,8 +122,8 @@ where r1cs_gens_secondary, r1cs_shape_secondary, r1cs_shape_padded_secondary, - nifs_params_primary, - nifs_params_secondary, + augmented_circuit_params_primary, + augmented_circuit_params_secondary, _p_c1: Default::default(), _p_c2: Default::default(), } @@ -181,7 +183,7 @@ where None => { // base case for the primary let mut cs_primary: SatisfyingAssignment = SatisfyingAssignment::new(); - let inputs_primary: NIFSVerifierCircuitInputs = NIFSVerifierCircuitInputs::new( + let inputs_primary: NovaAugmentedCircuitInputs = NovaAugmentedCircuitInputs::new( pp.r1cs_shape_secondary.get_digest(), G1::Scalar::zero(), z0_primary, @@ -191,8 +193,8 @@ where None, ); - let circuit_primary: NIFSVerifierCircuit = NIFSVerifierCircuit::new( - pp.nifs_params_primary.clone(), + let circuit_primary: NovaAugmentedCircuit = NovaAugmentedCircuit::new( + pp.augmented_circuit_params_primary.clone(), Some(inputs_primary), c_primary.clone(), pp.ro_consts_circuit_primary.clone(), @@ -204,7 +206,7 @@ where // base case for the secondary let mut cs_secondary: SatisfyingAssignment = SatisfyingAssignment::new(); - let inputs_secondary: NIFSVerifierCircuitInputs = NIFSVerifierCircuitInputs::new( + let inputs_secondary: NovaAugmentedCircuitInputs = NovaAugmentedCircuitInputs::new( pp.r1cs_shape_primary.get_digest(), G2::Scalar::zero(), z0_secondary, @@ -213,8 +215,8 @@ where Some(u_primary.clone()), None, ); - let circuit_secondary: NIFSVerifierCircuit = NIFSVerifierCircuit::new( - pp.nifs_params_secondary.clone(), + let circuit_secondary: NovaAugmentedCircuit = NovaAugmentedCircuit::new( + pp.augmented_circuit_params_secondary.clone(), Some(inputs_secondary), c_secondary.clone(), pp.ro_consts_circuit_secondary.clone(), @@ -275,7 +277,7 @@ where )?; let mut cs_primary: SatisfyingAssignment = SatisfyingAssignment::new(); - let inputs_primary: NIFSVerifierCircuitInputs = NIFSVerifierCircuitInputs::new( + let inputs_primary: NovaAugmentedCircuitInputs = NovaAugmentedCircuitInputs::new( pp.r1cs_shape_secondary.get_digest(), G1::Scalar::from(r_snark.i as u64), z0_primary, @@ -285,8 +287,8 @@ where Some(nifs_secondary.comm_T.decompress()?), ); - let circuit_primary: NIFSVerifierCircuit = NIFSVerifierCircuit::new( - pp.nifs_params_primary.clone(), + let circuit_primary: NovaAugmentedCircuit = NovaAugmentedCircuit::new( + pp.augmented_circuit_params_primary.clone(), Some(inputs_primary), c_primary.clone(), pp.ro_consts_circuit_primary.clone(), @@ -309,7 +311,7 @@ where )?; let mut cs_secondary: SatisfyingAssignment = SatisfyingAssignment::new(); - let inputs_secondary: NIFSVerifierCircuitInputs = NIFSVerifierCircuitInputs::new( + let inputs_secondary: NovaAugmentedCircuitInputs = NovaAugmentedCircuitInputs::new( pp.r1cs_shape_primary.get_digest(), G2::Scalar::from(r_snark.i as u64), z0_secondary, @@ -319,8 +321,8 @@ where Some(nifs_primary.comm_T.decompress()?), ); - let circuit_secondary: NIFSVerifierCircuit = NIFSVerifierCircuit::new( - pp.nifs_params_secondary.clone(), + let circuit_secondary: NovaAugmentedCircuit = NovaAugmentedCircuit::new( + pp.augmented_circuit_params_secondary.clone(), Some(inputs_secondary), c_secondary.clone(), pp.ro_consts_circuit_secondary.clone(),