diff --git a/benches/common/supernova/mod.rs b/benches/common/supernova/mod.rs index 27e9155cc..6deee3622 100644 --- a/benches/common/supernova/mod.rs +++ b/benches/common/supernova/mod.rs @@ -7,7 +7,7 @@ pub mod targets; use anyhow::anyhow; use arecibo::{ supernova::{NonUniformCircuit, StepCircuit, TrivialTestCircuit}, - traits::{CurveCycleEquipped, Engine, SecEng}, + traits::{CurveCycleEquipped, Engine, Dual}, }; use bellpepper_core::{num::AllocatedNum, ConstraintSystem, SynthesisError}; use core::marker::PhantomData; @@ -94,7 +94,7 @@ where E1: CurveCycleEquipped, { type C1 = NonTrivialTestCircuit; - type C2 = TrivialTestCircuit< as Engine>::Scalar>; + type C2 = TrivialTestCircuit< as Engine>::Scalar>; fn num_circuits(&self) -> usize { self.num_circuits diff --git a/src/circuit.rs b/src/circuit.rs index b51445fc2..7a051a763 100644 --- a/src/circuit.rs +++ b/src/circuit.rs @@ -375,7 +375,7 @@ mod tests { poseidon::PoseidonConstantsCircuit, Bn256Engine, GrumpkinEngine, PallasEngine, Secp256k1Engine, Secq256k1Engine, VestaEngine, }, - traits::{circuit::TrivialCircuit, snark::default_ck_hint, CurveCycleEquipped, SecEng}, + traits::{circuit::TrivialCircuit, snark::default_ck_hint, CurveCycleEquipped, Dual}, }; use expect_test::{expect, Expect}; @@ -383,7 +383,7 @@ mod tests { fn test_recursive_circuit_with( primary_params: &NovaAugmentedCircuitParams, secondary_params: &NovaAugmentedCircuitParams, - ro_consts1: ROConstantsCircuit>, + ro_consts1: ROConstantsCircuit>, ro_consts2: ROConstantsCircuit, expected_num_constraints_primary: &Expect, expected_num_constraints_secondary: &Expect, @@ -394,8 +394,8 @@ mod tests { // Initialize the shape and ck for the primary let circuit1: NovaAugmentedCircuit< '_, - SecEng, - TrivialCircuit< as Engine>::Base>, + Dual, + TrivialCircuit< as Engine>::Base>, > = NovaAugmentedCircuit::new(primary_params, None, &tc1, ro_consts1.clone()); let mut cs: TestShapeCS = TestShapeCS::new(); let _ = circuit1.synthesize(&mut cs); @@ -407,16 +407,16 @@ mod tests { // Initialize the shape and ck for the secondary let circuit2: NovaAugmentedCircuit<'_, E1, TrivialCircuit<::Base>> = NovaAugmentedCircuit::new(secondary_params, None, &tc2, ro_consts2.clone()); - let mut cs: TestShapeCS> = TestShapeCS::new(); + let mut cs: TestShapeCS> = TestShapeCS::new(); let _ = circuit2.synthesize(&mut cs); let (shape2, ck2) = cs.r1cs_shape_and_key(&*default_ck_hint()); expected_num_constraints_secondary.assert_eq(&cs.num_constraints().to_string()); // Execute the base case for the primary - let zero1 = < as Engine>::Base as Field>::ZERO; + let zero1 = < as Engine>::Base as Field>::ZERO; let mut cs1 = SatisfyingAssignment::::new(); - let inputs1: NovaAugmentedCircuitInputs> = NovaAugmentedCircuitInputs::new( + let inputs1: NovaAugmentedCircuitInputs> = NovaAugmentedCircuitInputs::new( scalar_as_base::(zero1), // pass zero for testing zero1, vec![zero1], @@ -427,8 +427,8 @@ mod tests { ); let circuit1: NovaAugmentedCircuit< '_, - SecEng, - TrivialCircuit< as Engine>::Base>, + Dual, + TrivialCircuit< as Engine>::Base>, > = NovaAugmentedCircuit::new(primary_params, Some(inputs1), &tc1, ro_consts1); let _ = circuit1.synthesize(&mut cs1); let (inst1, witness1) = cs1.r1cs_instance_and_witness(&shape1, &ck1).unwrap(); @@ -437,9 +437,9 @@ mod tests { // Execute the base case for the secondary let zero2 = <::Base as Field>::ZERO; - let mut cs2 = SatisfyingAssignment::>::new(); + let mut cs2 = SatisfyingAssignment::>::new(); let inputs2: NovaAugmentedCircuitInputs = NovaAugmentedCircuitInputs::new( - scalar_as_base::>(zero2), // pass zero for testing + scalar_as_base::>(zero2), // pass zero for testing zero2, vec![zero2], None, diff --git a/src/lib.rs b/src/lib.rs index fc67a0c2e..94abee6d3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,7 +28,7 @@ pub mod traits; pub mod supernova; use once_cell::sync::OnceCell; -use traits::{CurveCycleEquipped, SecEng}; +use traits::{CurveCycleEquipped, Dual}; use crate::digest::{DigestComputer, SimpleDigestible}; use crate::{ @@ -97,13 +97,13 @@ where F_arity_primary: usize, F_arity_secondary: usize, ro_consts_primary: ROConstants, - ro_consts_circuit_primary: ROConstantsCircuit>, + ro_consts_circuit_primary: ROConstantsCircuit>, ck_primary: Arc>, circuit_shape_primary: R1CSWithArity, - ro_consts_secondary: ROConstants>, + ro_consts_secondary: ROConstants>, ro_consts_circuit_secondary: ROConstantsCircuit, - ck_secondary: Arc>>, - circuit_shape_secondary: R1CSWithArity>, + ck_secondary: Arc>>, + circuit_shape_secondary: R1CSWithArity>, augmented_circuit_params_primary: NovaAugmentedCircuitParams, augmented_circuit_params_secondary: NovaAugmentedCircuitParams, #[serde(skip, default = "OnceCell::new")] @@ -121,7 +121,7 @@ where where E1: CurveCycleEquipped, ::Repr: Abomonation, - < as Engine>::Scalar as PrimeField>::Repr: Abomonation, + < as Engine>::Scalar as PrimeField>::Repr: Abomonation, )] pub struct FlatPublicParams where @@ -130,13 +130,13 @@ where F_arity_primary: usize, F_arity_secondary: usize, ro_consts_primary: ROConstants, - ro_consts_circuit_primary: ROConstantsCircuit>, + ro_consts_circuit_primary: ROConstantsCircuit>, ck_primary: CommitmentKey, circuit_shape_primary: R1CSWithArity, - ro_consts_secondary: ROConstants>, + ro_consts_secondary: ROConstants>, ro_consts_circuit_secondary: ROConstantsCircuit, - ck_secondary: CommitmentKey>, - circuit_shape_secondary: R1CSWithArity>, + ck_secondary: CommitmentKey>, + circuit_shape_secondary: R1CSWithArity>, augmented_circuit_params_primary: NovaAugmentedCircuitParams, augmented_circuit_params_secondary: NovaAugmentedCircuitParams, } @@ -243,11 +243,11 @@ where /// /// let pp = PublicParams::setup(&circuit1, &circuit2, ck_hint1, ck_hint2); /// ``` - pub fn setup, C2: StepCircuit< as Engine>::Scalar>>( + pub fn setup, C2: StepCircuit< as Engine>::Scalar>>( c_primary: &C1, c_secondary: &C2, ck_hint1: &CommitmentKeyHint, - ck_hint2: &CommitmentKeyHint>, + ck_hint2: &CommitmentKeyHint>, ) -> Self { let augmented_circuit_params_primary = NovaAugmentedCircuitParams::new(BN_LIMB_WIDTH, BN_N_LIMBS, true); @@ -255,18 +255,18 @@ where NovaAugmentedCircuitParams::new(BN_LIMB_WIDTH, BN_N_LIMBS, false); let ro_consts_primary: ROConstants = ROConstants::::default(); - let ro_consts_secondary: ROConstants> = ROConstants::>::default(); + let ro_consts_secondary: ROConstants> = ROConstants::>::default(); let F_arity_primary = c_primary.arity(); let F_arity_secondary = c_secondary.arity(); // ro_consts_circuit_primary are parameterized by E2 because the type alias uses E2::Base = E1::Scalar - let ro_consts_circuit_primary: ROConstantsCircuit> = - ROConstantsCircuit::>::default(); + let ro_consts_circuit_primary: ROConstantsCircuit> = + ROConstantsCircuit::>::default(); let ro_consts_circuit_secondary: ROConstantsCircuit = ROConstantsCircuit::::default(); // Initialize ck for the primary - let circuit_primary: NovaAugmentedCircuit<'_, SecEng, C1> = NovaAugmentedCircuit::new( + let circuit_primary: NovaAugmentedCircuit<'_, Dual, C1> = NovaAugmentedCircuit::new( &augmented_circuit_params_primary, None, c_primary, @@ -285,7 +285,7 @@ where c_secondary, ro_consts_circuit_secondary.clone(), ); - let mut cs: ShapeCS> = ShapeCS::new(); + let mut cs: ShapeCS> = ShapeCS::new(); let _ = circuit_secondary.synthesize(&mut cs); let (r1cs_shape_secondary, ck_secondary) = cs.r1cs_shape_and_key(ck_hint2); let ck_secondary = Arc::new(ck_secondary); @@ -357,22 +357,22 @@ where E1: CurveCycleEquipped, { z0_primary: Vec, - z0_secondary: Vec< as Engine>::Scalar>, + z0_secondary: Vec< as Engine>::Scalar>, r_W_primary: RelaxedR1CSWitness, r_U_primary: RelaxedR1CSInstance, - r_W_secondary: RelaxedR1CSWitness>, - r_U_secondary: RelaxedR1CSInstance>, - l_w_secondary: R1CSWitness>, - l_u_secondary: R1CSInstance>, + r_W_secondary: RelaxedR1CSWitness>, + r_U_secondary: RelaxedR1CSInstance>, + l_w_secondary: R1CSWitness>, + l_u_secondary: R1CSInstance>, /// Buffer for memory needed by the primary fold-step buffer_primary: ResourceBuffer, /// Buffer for memory needed by the secondary fold-step - buffer_secondary: ResourceBuffer>, + buffer_secondary: ResourceBuffer>, i: usize, zi_primary: Vec, - zi_secondary: Vec< as Engine>::Scalar>, + zi_secondary: Vec< as Engine>::Scalar>, } impl RecursiveSNARK @@ -380,12 +380,12 @@ where E1: CurveCycleEquipped, { /// Create new instance of recursive SNARK - pub fn new, C2: StepCircuit< as Engine>::Scalar>>( + pub fn new, C2: StepCircuit< as Engine>::Scalar>>( pp: &PublicParams, c_primary: &C1, c_secondary: &C2, z0_primary: &[E1::Scalar], - z0_secondary: &[ as Engine>::Scalar], + z0_secondary: &[ as Engine>::Scalar], ) -> Result { if z0_primary.len() != pp.F_arity_primary || z0_secondary.len() != pp.F_arity_secondary { return Err(NovaError::InvalidInitialInputLength); @@ -396,7 +396,7 @@ where // base case for the primary let mut cs_primary = SatisfyingAssignment::::new(); - let inputs_primary: NovaAugmentedCircuitInputs> = NovaAugmentedCircuitInputs::new( + let inputs_primary: NovaAugmentedCircuitInputs> = NovaAugmentedCircuitInputs::new( scalar_as_base::(pp.digest()), E1::Scalar::ZERO, z0_primary.to_vec(), @@ -406,7 +406,7 @@ where None, ); - let circuit_primary: NovaAugmentedCircuit<'_, SecEng, C1> = NovaAugmentedCircuit::new( + let circuit_primary: NovaAugmentedCircuit<'_, Dual, C1> = NovaAugmentedCircuit::new( &pp.augmented_circuit_params_primary, Some(inputs_primary), c_primary, @@ -417,10 +417,10 @@ where cs_primary.r1cs_instance_and_witness(r1cs_primary, &pp.ck_primary)?; // base case for the secondary - let mut cs_secondary = SatisfyingAssignment::>::new(); + let mut cs_secondary = SatisfyingAssignment::>::new(); let inputs_secondary: NovaAugmentedCircuitInputs = NovaAugmentedCircuitInputs::new( pp.digest(), - as Engine>::Scalar::ZERO, + as Engine>::Scalar::ZERO, z0_secondary.to_vec(), None, None, @@ -450,9 +450,9 @@ where // IVC proof for the secondary circuit let l_w_secondary = w_secondary; let l_u_secondary = u_secondary; - let r_W_secondary = RelaxedR1CSWitness::>::default(r1cs_secondary); + let r_W_secondary = RelaxedR1CSWitness::>::default(r1cs_secondary); let r_U_secondary = - RelaxedR1CSInstance::>::default(&pp.ck_secondary, r1cs_secondary); + RelaxedR1CSInstance::>::default(&pp.ck_secondary, r1cs_secondary); assert!( !(zi_primary.len() != pp.F_arity_primary || zi_secondary.len() != pp.F_arity_secondary), @@ -467,7 +467,7 @@ where let zi_secondary = zi_secondary .iter() .map(|v| v.get_value().ok_or(SynthesisError::AssignmentMissing)) - .collect:: as Engine>::Scalar>, _>>()?; + .collect:: as Engine>::Scalar>, _>>()?; let buffer_primary = ResourceBuffer { l_w: None, @@ -482,7 +482,7 @@ where l_u: None, ABC_Z_1: R1CSResult::default(r1cs_secondary.num_cons), ABC_Z_2: R1CSResult::default(r1cs_secondary.num_cons), - T: r1cs::default_T::>(r1cs_secondary.num_cons), + T: r1cs::default_T::>(r1cs_secondary.num_cons), }; Ok(Self { @@ -508,7 +508,7 @@ where #[tracing::instrument(skip_all, name = "nova::RecursiveSNARK::prove_step")] pub fn prove_step< C1: StepCircuit, - C2: StepCircuit< as Engine>::Scalar>, + C2: StepCircuit< as Engine>::Scalar>, >( &mut self, pp: &PublicParams, @@ -545,19 +545,19 @@ where pp.circuit_shape_primary.r1cs_shape.num_io + 1, pp.circuit_shape_primary.r1cs_shape.num_vars, ); - let inputs_primary: NovaAugmentedCircuitInputs> = NovaAugmentedCircuitInputs::new( + let inputs_primary: NovaAugmentedCircuitInputs> = NovaAugmentedCircuitInputs::new( scalar_as_base::(pp.digest()), E1::Scalar::from(self.i as u64), self.z0_primary.to_vec(), Some(self.zi_primary.clone()), Some(r_U_secondary_i), Some(l_u_secondary_i), - Some(Commitment::>::decompress( + Some(Commitment::>::decompress( &nifs_secondary.comm_T, )?), ); - let circuit_primary: NovaAugmentedCircuit<'_, SecEng, C1> = NovaAugmentedCircuit::new( + let circuit_primary: NovaAugmentedCircuit<'_, Dual, C1> = NovaAugmentedCircuit::new( &pp.augmented_circuit_params_primary, Some(inputs_primary), c_primary, @@ -584,13 +584,13 @@ where &mut self.buffer_primary.ABC_Z_2, )?; - let mut cs_secondary = SatisfyingAssignment::>::with_capacity( + let mut cs_secondary = SatisfyingAssignment::>::with_capacity( pp.circuit_shape_secondary.r1cs_shape.num_io + 1, pp.circuit_shape_secondary.r1cs_shape.num_vars, ); let inputs_secondary: NovaAugmentedCircuitInputs = NovaAugmentedCircuitInputs::new( pp.digest(), - as Engine>::Scalar::from(self.i as u64), + as Engine>::Scalar::from(self.i as u64), self.z0_secondary.to_vec(), Some(self.zi_secondary.clone()), Some(r_U_primary_i), @@ -618,7 +618,7 @@ where self.zi_secondary = zi_secondary .iter() .map(|v| v.get_value().ok_or(SynthesisError::AssignmentMissing)) - .collect:: as Engine>::Scalar>, _>>()?; + .collect:: as Engine>::Scalar>, _>>()?; self.l_u_secondary = l_u_secondary; self.l_w_secondary = l_w_secondary; @@ -634,8 +634,8 @@ where pp: &PublicParams, num_steps: usize, z0_primary: &[E1::Scalar], - z0_secondary: &[ as Engine>::Scalar], - ) -> Result<(Vec, Vec< as Engine>::Scalar>), NovaError> { + z0_secondary: &[ as Engine>::Scalar], + ) -> Result<(Vec, Vec< as Engine>::Scalar>), NovaError> { // number of steps cannot be zero let is_num_steps_zero = num_steps == 0; @@ -660,7 +660,7 @@ where // check if the output hashes in R1CS instances point to the right running instances let (hash_primary, hash_secondary) = { - let mut hasher = as Engine>::RO::new( + let mut hasher = as Engine>::RO::new( pp.ro_consts_secondary.clone(), NUM_FE_WITHOUT_IO_FOR_CRHF + 2 * pp.F_arity_primary, ); @@ -679,7 +679,7 @@ where NUM_FE_WITHOUT_IO_FOR_CRHF + 2 * pp.F_arity_secondary, ); hasher2.absorb(scalar_as_base::(pp.digest())); - hasher2.absorb( as Engine>::Scalar::from(num_steps as u64)); + hasher2.absorb( as Engine>::Scalar::from(num_steps as u64)); for e in z0_secondary { hasher2.absorb(*e); } @@ -695,7 +695,7 @@ where }; if hash_primary != self.l_u_secondary.X[0] - || hash_secondary != scalar_as_base::>(self.l_u_secondary.X[1]) + || hash_secondary != scalar_as_base::>(self.l_u_secondary.X[1]) { return Err(NovaError::ProofVerifyError); } @@ -738,7 +738,7 @@ where } /// Get the outputs after the last step of computation. - pub fn outputs(&self) -> (&[E1::Scalar], &[ as Engine>::Scalar]) { + pub fn outputs(&self) -> (&[E1::Scalar], &[ as Engine>::Scalar]) { (&self.zi_primary, &self.zi_secondary) } @@ -754,7 +754,7 @@ pub struct ProverKey where E1: CurveCycleEquipped, S1: RelaxedR1CSSNARKTrait, - S2: RelaxedR1CSSNARKTrait>, + S2: RelaxedR1CSSNARKTrait>, { pk_primary: S1::ProverKey, pk_secondary: S2::ProverKey, @@ -767,12 +767,12 @@ pub struct VerifierKey where E1: CurveCycleEquipped, S1: RelaxedR1CSSNARKTrait, - S2: RelaxedR1CSSNARKTrait>, + S2: RelaxedR1CSSNARKTrait>, { F_arity_primary: usize, F_arity_secondary: usize, ro_consts_primary: ROConstants, - ro_consts_secondary: ROConstants>, + ro_consts_secondary: ROConstants>, pp_digest: E1::Scalar, vk_primary: S1::VerifierKey, vk_secondary: S2::VerifierKey, @@ -785,25 +785,25 @@ pub struct CompressedSNARK where E1: CurveCycleEquipped, S1: RelaxedR1CSSNARKTrait, - S2: RelaxedR1CSSNARKTrait>, + S2: RelaxedR1CSSNARKTrait>, { r_U_primary: RelaxedR1CSInstance, r_W_snark_primary: S1, - r_U_secondary: RelaxedR1CSInstance>, - l_u_secondary: R1CSInstance>, - nifs_secondary: NIFS>, + r_U_secondary: RelaxedR1CSInstance>, + l_u_secondary: R1CSInstance>, + nifs_secondary: NIFS>, f_W_snark_secondary: S2, zn_primary: Vec, - zn_secondary: Vec< as Engine>::Scalar>, + zn_secondary: Vec< as Engine>::Scalar>, } impl CompressedSNARK where E1: CurveCycleEquipped, S1: RelaxedR1CSSNARKTrait, - S2: RelaxedR1CSSNARKTrait>, + S2: RelaxedR1CSSNARKTrait>, { /// Creates prover and verifier keys for `CompressedSNARK` pub fn setup( @@ -894,8 +894,8 @@ where vk: &VerifierKey, num_steps: usize, z0_primary: &[E1::Scalar], - z0_secondary: &[ as Engine>::Scalar], - ) -> Result<(Vec, Vec< as Engine>::Scalar>), NovaError> { + z0_secondary: &[ as Engine>::Scalar], + ) -> Result<(Vec, Vec< as Engine>::Scalar>), NovaError> { // the number of steps cannot be zero if num_steps == 0 { return Err(NovaError::ProofVerifyError); @@ -911,7 +911,7 @@ where // check if the output hashes in R1CS instances point to the right running instances let (hash_primary, hash_secondary) = { - let mut hasher = as Engine>::RO::new( + let mut hasher = as Engine>::RO::new( vk.ro_consts_secondary.clone(), NUM_FE_WITHOUT_IO_FOR_CRHF + 2 * vk.F_arity_primary, ); @@ -930,7 +930,7 @@ where NUM_FE_WITHOUT_IO_FOR_CRHF + 2 * vk.F_arity_secondary, ); hasher2.absorb(scalar_as_base::(vk.pp_digest)); - hasher2.absorb( as Engine>::Scalar::from(num_steps as u64)); + hasher2.absorb( as Engine>::Scalar::from(num_steps as u64)); for e in z0_secondary { hasher2.absorb(*e); } @@ -946,7 +946,7 @@ where }; if hash_primary != self.l_u_secondary.X[0] - || hash_secondary != scalar_as_base::>(self.l_u_secondary.X[1]) + || hash_secondary != scalar_as_base::>(self.l_u_secondary.X[1]) { return Err(NovaError::ProofVerifyError); } @@ -991,11 +991,11 @@ pub fn circuit_digest>( let augmented_circuit_params = NovaAugmentedCircuitParams::new(BN_LIMB_WIDTH, BN_N_LIMBS, true); // ro_consts_circuit are parameterized by G2 because the type alias uses G2::Base = G1::Scalar - let ro_consts_circuit: ROConstantsCircuit> = - ROConstantsCircuit::>::default(); + let ro_consts_circuit: ROConstantsCircuit> = + ROConstantsCircuit::>::default(); // Initialize ck for the primary - let augmented_circuit: NovaAugmentedCircuit<'_, SecEng, C> = + let augmented_circuit: NovaAugmentedCircuit<'_, Dual, C> = NovaAugmentedCircuit::new(&augmented_circuit_params, None, circuit, ro_consts_circuit); let mut cs: ShapeCS = ShapeCS::new(); let _ = augmented_circuit.synthesize(&mut cs); @@ -1080,18 +1080,18 @@ mod tests { where E1: CurveCycleEquipped, E1::GE: DlogGroup, - as Engine>::GE: DlogGroup, + as Engine>::GE: DlogGroup, T1: StepCircuit, - T2: StepCircuit< as Engine>::Scalar>, + T2: StepCircuit< as Engine>::Scalar>, EE1: EvaluationEngineTrait, - EE2: EvaluationEngineTrait>, + EE2: EvaluationEngineTrait>, // this is due to the reliance on Abomonation ::Repr: Abomonation, - < as Engine>::Scalar as PrimeField>::Repr: Abomonation, + < as Engine>::Scalar as PrimeField>::Repr: Abomonation, { // this tests public parameters with a size specifically intended for a spark-compressed SNARK let ck_hint1 = &*SPrime::::ck_floor(); - let ck_hint2 = &*SPrime::, EE2>::ck_floor(); + let ck_hint2 = &*SPrime::, EE2>::ck_floor(); let pp = PublicParams::::setup(circuit1, circuit2, ck_hint1, ck_hint2); let digest_str = pp @@ -1174,7 +1174,7 @@ mod tests { E1: CurveCycleEquipped, { let test_circuit1 = TrivialCircuit::<::Scalar>::default(); - let test_circuit2 = TrivialCircuit::< as Engine>::Scalar>::default(); + let test_circuit2 = TrivialCircuit::< as Engine>::Scalar>::default(); // produce public parameters let pp = PublicParams::::setup( @@ -1191,7 +1191,7 @@ mod tests { &test_circuit1, &test_circuit2, &[::Scalar::ZERO], - &[ as Engine>::Scalar::ZERO], + &[ as Engine>::Scalar::ZERO], ) .unwrap(); @@ -1204,7 +1204,7 @@ mod tests { &pp, num_steps, &[::Scalar::ZERO], - &[ as Engine>::Scalar::ZERO], + &[ as Engine>::Scalar::ZERO], ); assert!(res.is_ok()); } @@ -1239,7 +1239,7 @@ mod tests { &circuit_primary, &circuit_secondary, &[::Scalar::ONE], - &[ as Engine>::Scalar::ZERO], + &[ as Engine>::Scalar::ZERO], ) .unwrap(); @@ -1252,7 +1252,7 @@ mod tests { &pp, i + 1, &[::Scalar::ONE], - &[ as Engine>::Scalar::ZERO], + &[ as Engine>::Scalar::ZERO], ); assert!(res.is_ok()); } @@ -1262,7 +1262,7 @@ mod tests { &pp, num_steps, &[::Scalar::ONE], - &[ as Engine>::Scalar::ZERO], + &[ as Engine>::Scalar::ZERO], ); assert!(res.is_ok()); @@ -1270,14 +1270,14 @@ mod tests { // sanity: check the claimed output with a direct computation of the same assert_eq!(zn_primary, vec![::Scalar::ONE]); - let mut zn_secondary_direct = vec![ as Engine>::Scalar::ZERO]; + let mut zn_secondary_direct = vec![ as Engine>::Scalar::ZERO]; for _i in 0..num_steps { zn_secondary_direct = circuit_secondary.clone().output(&zn_secondary_direct); } assert_eq!(zn_secondary, zn_secondary_direct); assert_eq!( zn_secondary, - vec![ as Engine>::Scalar::from(2460515u64)] + vec![ as Engine>::Scalar::from(2460515u64)] ); } @@ -1292,10 +1292,10 @@ mod tests { where E1: CurveCycleEquipped, EE1: EvaluationEngineTrait, - EE2: EvaluationEngineTrait>, + EE2: EvaluationEngineTrait>, // this is due to the reliance on Abomonation ::Repr: Abomonation, - < as Engine>::Scalar as PrimeField>::Repr: Abomonation, + < as Engine>::Scalar as PrimeField>::Repr: Abomonation, { let circuit_primary = TrivialCircuit::default(); let circuit_secondary = CubicCircuit::default(); @@ -1316,7 +1316,7 @@ mod tests { &circuit_primary, &circuit_secondary, &[::Scalar::ONE], - &[ as Engine>::Scalar::ZERO], + &[ as Engine>::Scalar::ZERO], ) .unwrap(); @@ -1330,7 +1330,7 @@ mod tests { &pp, num_steps, &[::Scalar::ONE], - &[ as Engine>::Scalar::ZERO], + &[ as Engine>::Scalar::ZERO], ); assert!(res.is_ok()); @@ -1338,14 +1338,14 @@ mod tests { // sanity: check the claimed output with a direct computation of the same assert_eq!(zn_primary, vec![::Scalar::ONE]); - let mut zn_secondary_direct = vec![ as Engine>::Scalar::ZERO]; + let mut zn_secondary_direct = vec![ as Engine>::Scalar::ZERO]; for _i in 0..num_steps { zn_secondary_direct = circuit_secondary.clone().output(&zn_secondary_direct); } assert_eq!(zn_secondary, zn_secondary_direct); assert_eq!( zn_secondary, - vec![ as Engine>::Scalar::from(2460515u64)] + vec![ as Engine>::Scalar::from(2460515u64)] ); // produce the prover and verifier keys for compressed snark @@ -1361,7 +1361,7 @@ mod tests { &vk, num_steps, &[::Scalar::ONE], - &[ as Engine>::Scalar::ZERO], + &[ as Engine>::Scalar::ZERO], ); assert!(res.is_ok()); } @@ -1384,10 +1384,10 @@ mod tests { where E1: CurveCycleEquipped, EE1: EvaluationEngineTrait, - EE2: EvaluationEngineTrait>, + EE2: EvaluationEngineTrait>, // this is due to the reliance on Abomonation ::Repr: Abomonation, - < as Engine>::Scalar as PrimeField>::Repr: Abomonation, + < as Engine>::Scalar as PrimeField>::Repr: Abomonation, { let circuit_primary = TrivialCircuit::default(); let circuit_secondary = CubicCircuit::default(); @@ -1408,7 +1408,7 @@ mod tests { &circuit_primary, &circuit_secondary, &[::Scalar::ONE], - &[ as Engine>::Scalar::ZERO], + &[ as Engine>::Scalar::ZERO], ) .unwrap(); @@ -1422,7 +1422,7 @@ mod tests { &pp, num_steps, &[::Scalar::ONE], - &[ as Engine>::Scalar::ZERO], + &[ as Engine>::Scalar::ZERO], ); assert!(res.is_ok()); @@ -1430,14 +1430,14 @@ mod tests { // sanity: check the claimed output with a direct computation of the same assert_eq!(zn_primary, vec![::Scalar::ONE]); - let mut zn_secondary_direct = vec![ as Engine>::Scalar::ZERO]; + let mut zn_secondary_direct = vec![ as Engine>::Scalar::ZERO]; for _i in 0..num_steps { zn_secondary_direct = CubicCircuit::default().output(&zn_secondary_direct); } assert_eq!(zn_secondary, zn_secondary_direct); assert_eq!( zn_secondary, - vec![ as Engine>::Scalar::from(2460515u64)] + vec![ as Engine>::Scalar::from(2460515u64)] ); // run the compressed snark with Spark compiler @@ -1455,7 +1455,7 @@ mod tests { &vk, num_steps, &[::Scalar::ONE], - &[ as Engine>::Scalar::ZERO], + &[ as Engine>::Scalar::ZERO], ); assert!(res.is_ok()); } @@ -1472,10 +1472,10 @@ mod tests { where E1: CurveCycleEquipped, EE1: EvaluationEngineTrait, - EE2: EvaluationEngineTrait>, + EE2: EvaluationEngineTrait>, // this is due to the reliance on Abomonation ::Repr: Abomonation, - < as Engine>::Scalar as PrimeField>::Repr: Abomonation, + < as Engine>::Scalar as PrimeField>::Repr: Abomonation, { // y is a non-deterministic advice representing the fifth root of the input at a step. #[derive(Clone, Debug)] @@ -1552,7 +1552,7 @@ mod tests { // produce non-deterministic advice let (z0_primary, roots) = FifthRootCheckingCircuit::new(num_steps); - let z0_secondary = vec![ as Engine>::Scalar::ZERO]; + let z0_secondary = vec![ as Engine>::Scalar::ZERO]; // produce a recursive SNARK let mut recursive_snark = RecursiveSNARK::::new( @@ -1599,7 +1599,7 @@ mod tests { E1: CurveCycleEquipped, { let test_circuit1 = TrivialCircuit::<::Scalar>::default(); - let test_circuit2 = CubicCircuit::< as Engine>::Scalar>::default(); + let test_circuit2 = CubicCircuit::< as Engine>::Scalar>::default(); // produce public parameters let pp = PublicParams::::setup( @@ -1617,7 +1617,7 @@ mod tests { &test_circuit1, &test_circuit2, &[::Scalar::ONE], - &[ as Engine>::Scalar::ZERO], + &[ as Engine>::Scalar::ZERO], ) .unwrap(); @@ -1631,7 +1631,7 @@ mod tests { &pp, num_steps, &[::Scalar::ONE], - &[ as Engine>::Scalar::ZERO], + &[ as Engine>::Scalar::ZERO], ); assert!(res.is_ok()); @@ -1640,7 +1640,7 @@ mod tests { assert_eq!(zn_primary, vec![::Scalar::ONE]); assert_eq!( zn_secondary, - vec![ as Engine>::Scalar::from(5u64)] + vec![ as Engine>::Scalar::from(5u64)] ); } diff --git a/src/supernova/circuit.rs b/src/supernova/circuit.rs index b1e062342..f9f27c934 100644 --- a/src/supernova/circuit.rs +++ b/src/supernova/circuit.rs @@ -713,7 +713,7 @@ mod tests { Secp256k1Engine, Secq256k1Engine, VestaEngine, }, supernova::circuit::TrivialTestCircuit, - traits::{snark::default_ck_hint, CurveCycleEquipped, SecEng}, + traits::{snark::default_ck_hint, CurveCycleEquipped, Dual}, }; use expect_test::{expect, Expect}; @@ -721,7 +721,7 @@ mod tests { fn test_supernova_recursive_circuit_with( primary_params: &SuperNovaAugmentedCircuitParams, secondary_params: &SuperNovaAugmentedCircuitParams, - ro_consts1: ROConstantsCircuit>, + ro_consts1: ROConstantsCircuit>, ro_consts2: ROConstantsCircuit, num_constraints_primary: &Expect, num_constraints_secondary: &Expect, @@ -733,8 +733,8 @@ mod tests { // Initialize the shape and ck for the primary let circuit1: SuperNovaAugmentedCircuit< '_, - SecEng, - TrivialTestCircuit< as Engine>::Base>, + Dual, + TrivialTestCircuit< as Engine>::Base>, > = SuperNovaAugmentedCircuit::new( primary_params, None, @@ -758,17 +758,17 @@ mod tests { ro_consts2.clone(), num_augmented_circuits, ); - let mut cs: TestShapeCS> = TestShapeCS::new(); + let mut cs: TestShapeCS> = TestShapeCS::new(); let _ = circuit2.synthesize(&mut cs); let (shape2, ck2) = cs.r1cs_shape_and_key(&*default_ck_hint()); num_constraints_secondary.assert_eq(&cs.num_constraints().to_string()); // Execute the base case for the primary - let zero1 = < as Engine>::Base as Field>::ZERO; + let zero1 = < as Engine>::Base as Field>::ZERO; let mut cs1 = SatisfyingAssignment::::new(); let vzero1 = vec![zero1]; - let inputs1: SuperNovaAugmentedCircuitInputs<'_, SecEng> = + let inputs1: SuperNovaAugmentedCircuitInputs<'_, Dual> = SuperNovaAugmentedCircuitInputs::new( scalar_as_base::(zero1), // pass zero for testing zero1, @@ -782,8 +782,8 @@ mod tests { ); let circuit1: SuperNovaAugmentedCircuit< '_, - SecEng, - TrivialTestCircuit< as Engine>::Base>, + Dual, + TrivialTestCircuit< as Engine>::Base>, > = SuperNovaAugmentedCircuit::new( primary_params, Some(inputs1), @@ -798,10 +798,10 @@ mod tests { // Execute the base case for the secondary let zero2 = <::Base as Field>::ZERO; - let mut cs2 = SatisfyingAssignment::>::new(); + let mut cs2 = SatisfyingAssignment::>::new(); let vzero2 = vec![zero2]; let inputs2: SuperNovaAugmentedCircuitInputs<'_, E1> = SuperNovaAugmentedCircuitInputs::new( - scalar_as_base::>(zero2), // pass zero for testing + scalar_as_base::>(zero2), // pass zero for testing zero2, &vzero2, None, diff --git a/src/supernova/mod.rs b/src/supernova/mod.rs index 9343acb67..c2d702656 100644 --- a/src/supernova/mod.rs +++ b/src/supernova/mod.rs @@ -14,7 +14,7 @@ use crate::{ scalar_as_base, traits::{ commitment::{CommitmentEngineTrait, CommitmentTrait}, - AbsorbInROTrait, CurveCycleEquipped, Engine, ROConstants, ROConstantsCircuit, ROTrait, SecEng, + AbsorbInROTrait, CurveCycleEquipped, Engine, ROConstants, ROConstantsCircuit, ROTrait, Dual, }, Commitment, CommitmentKey, R1CSWithArity, }; @@ -89,14 +89,14 @@ where circuit_shapes: Vec>, ro_consts_primary: ROConstants, - ro_consts_circuit_primary: ROConstantsCircuit>, + ro_consts_circuit_primary: ROConstantsCircuit>, ck_primary: Arc>, // This is shared between all circuit params augmented_circuit_params_primary: SuperNovaAugmentedCircuitParams, - ro_consts_secondary: ROConstants>, + ro_consts_secondary: ROConstants>, ro_consts_circuit_secondary: ROConstantsCircuit, - ck_secondary: Arc>>, - circuit_shape_secondary: R1CSWithArity>, + ck_secondary: Arc>>, + circuit_shape_secondary: R1CSWithArity>, augmented_circuit_params_secondary: SuperNovaAugmentedCircuitParams, /// Digest constructed from this `PublicParams`' parameters @@ -114,14 +114,14 @@ where E1: CurveCycleEquipped, { ro_consts_primary: ROConstants, - ro_consts_circuit_primary: ROConstantsCircuit>, + ro_consts_circuit_primary: ROConstantsCircuit>, ck_primary: Arc>, // This is shared between all circuit params augmented_circuit_params_primary: SuperNovaAugmentedCircuitParams, - ro_consts_secondary: ROConstants>, + ro_consts_secondary: ROConstants>, ro_consts_circuit_secondary: ROConstantsCircuit, - ck_secondary: Arc>>, - circuit_shape_secondary: R1CSWithArity>, + ck_secondary: Arc>>, + circuit_shape_secondary: R1CSWithArity>, augmented_circuit_params_secondary: SuperNovaAugmentedCircuitParams, digest: E1::Scalar, @@ -134,21 +134,21 @@ where where E1: CurveCycleEquipped, ::Repr: Abomonation, - < as Engine>::Scalar as PrimeField>::Repr: Abomonation, + < as Engine>::Scalar as PrimeField>::Repr: Abomonation, )] pub struct FlatAuxParams where E1: CurveCycleEquipped, { ro_consts_primary: ROConstants, - ro_consts_circuit_primary: ROConstantsCircuit>, + ro_consts_circuit_primary: ROConstantsCircuit>, ck_primary: CommitmentKey, // This is shared between all circuit params augmented_circuit_params_primary: SuperNovaAugmentedCircuitParams, - ro_consts_secondary: ROConstants>, + ro_consts_secondary: ROConstants>, ro_consts_circuit_secondary: ROConstantsCircuit, - ck_secondary: CommitmentKey>, - circuit_shape_secondary: R1CSWithArity>, + ck_secondary: CommitmentKey>, + circuit_shape_secondary: R1CSWithArity>, augmented_circuit_params_secondary: SuperNovaAugmentedCircuitParams, #[abomonate_with(::Repr)] @@ -241,7 +241,7 @@ where pub fn setup>( non_uniform_circuit: &NC, ck_hint1: &CommitmentKeyHint, - ck_hint2: &CommitmentKeyHint>, + ck_hint2: &CommitmentKeyHint>, ) -> Self { let num_circuits = non_uniform_circuit.num_circuits(); @@ -249,15 +249,15 @@ where SuperNovaAugmentedCircuitParams::new(BN_LIMB_WIDTH, BN_N_LIMBS, true); let ro_consts_primary: ROConstants = ROConstants::::default(); // ro_consts_circuit_primary are parameterized by E2 because the type alias uses E2::Base = E1::Scalar - let ro_consts_circuit_primary: ROConstantsCircuit> = - ROConstantsCircuit::>::default(); + let ro_consts_circuit_primary: ROConstantsCircuit> = + ROConstantsCircuit::>::default(); let circuit_shapes = (0..num_circuits) .map(|i| { let c_primary = non_uniform_circuit.primary_circuit(i); let F_arity = c_primary.arity(); // Initialize ck for the primary - let circuit_primary: SuperNovaAugmentedCircuit<'_, SecEng, NC::C1> = + let circuit_primary: SuperNovaAugmentedCircuit<'_, Dual, NC::C1> = SuperNovaAugmentedCircuit::new( &augmented_circuit_params_primary, None, @@ -281,7 +281,7 @@ where let augmented_circuit_params_secondary = SuperNovaAugmentedCircuitParams::new(BN_LIMB_WIDTH, BN_N_LIMBS, false); - let ro_consts_secondary = ROConstants::>::default(); + let ro_consts_secondary = ROConstants::>::default(); let c_secondary = non_uniform_circuit.secondary_circuit(); let F_arity_secondary = c_secondary.arity(); let ro_consts_circuit_secondary: ROConstantsCircuit = ROConstantsCircuit::::default(); @@ -294,7 +294,7 @@ where ro_consts_circuit_secondary.clone(), num_circuits, ); - let mut cs: ShapeCS> = ShapeCS::new(); + let mut cs: ShapeCS> = ShapeCS::new(); circuit_secondary .synthesize(&mut cs) .expect("circuit synthesis failed"); @@ -487,7 +487,7 @@ where /// Buffer for memory needed by the primary fold-step buffer_primary: ResourceBuffer, /// Buffer for memory needed by the secondary fold-step - buffer_secondary: ResourceBuffer>, + buffer_secondary: ResourceBuffer>, // Relaxed instances for the primary circuits // Entries are `None` if the circuit has not been executed yet @@ -495,14 +495,14 @@ where r_U_primary: Vec>>, // Inputs and outputs of the secondary circuit - z0_secondary: Vec< as Engine>::Scalar>, - zi_secondary: Vec< as Engine>::Scalar>, + z0_secondary: Vec< as Engine>::Scalar>, + zi_secondary: Vec< as Engine>::Scalar>, // Relaxed instance for the secondary circuit - r_W_secondary: RelaxedR1CSWitness>, - r_U_secondary: RelaxedR1CSInstance>, + r_W_secondary: RelaxedR1CSWitness>, + r_U_secondary: RelaxedR1CSInstance>, // Proof for the secondary circuit to be accumulated into r_secondary in the next iteration - l_w_secondary: R1CSWitness>, - l_u_secondary: R1CSInstance>, + l_w_secondary: R1CSWitness>, + l_u_secondary: R1CSInstance>, } impl RecursiveSNARK @@ -517,7 +517,7 @@ where c_primary: &C0::C1, c_secondary: &C0::C2, z0_primary: &[E1::Scalar], - z0_secondary: &[ as Engine>::Scalar], + z0_secondary: &[ as Engine>::Scalar], ) -> Result { let num_augmented_circuits = non_uniform_circuit.num_circuits(); let circuit_index = non_uniform_circuit.initial_circuit_index(); @@ -544,7 +544,7 @@ where // base case for the primary let mut cs_primary = SatisfyingAssignment::::new(); let program_counter = E1::Scalar::from(circuit_index as u64); - let inputs_primary: SuperNovaAugmentedCircuitInputs<'_, SecEng> = + let inputs_primary: SuperNovaAugmentedCircuitInputs<'_, Dual> = SuperNovaAugmentedCircuitInputs::new( scalar_as_base::(pp.digest()), E1::Scalar::ZERO, @@ -557,7 +557,7 @@ where E1::Scalar::ZERO, // u_index is always zero for the primary circuit ); - let circuit_primary: SuperNovaAugmentedCircuit<'_, SecEng, C0::C1> = + let circuit_primary: SuperNovaAugmentedCircuit<'_, Dual, C0::C1> = SuperNovaAugmentedCircuit::new( &pp.augmented_circuit_params_primary, Some(inputs_primary), @@ -584,12 +584,12 @@ where })?; // base case for the secondary - let mut cs_secondary = SatisfyingAssignment::>::new(); - let u_primary_index = as Engine>::Scalar::from(circuit_index as u64); + let mut cs_secondary = SatisfyingAssignment::>::new(); + let u_primary_index = as Engine>::Scalar::from(circuit_index as u64); let inputs_secondary: SuperNovaAugmentedCircuitInputs<'_, E1> = SuperNovaAugmentedCircuitInputs::new( pp.digest(), - as Engine>::Scalar::ZERO, + as Engine>::Scalar::ZERO, z0_secondary, None, // zi = None for basecase None, // U = Empty list of accumulators for the primary circuits @@ -634,7 +634,7 @@ where let l_u_secondary = u_secondary; // Initialize relaxed instance/witness pair for the secondary circuit proofs - let r_W_secondary = RelaxedR1CSWitness::>::default(r1cs_secondary); + let r_W_secondary = RelaxedR1CSWitness::>::default(r1cs_secondary); let r_U_secondary = RelaxedR1CSInstance::default(&*pp.ck_secondary, r1cs_secondary); // Outputs of the two circuits and next program counter thus far. @@ -655,7 +655,7 @@ where v.get_value() .ok_or(NovaError::from(SynthesisError::AssignmentMissing).into()) }) - .collect:: as Engine>::Scalar>, SuperNovaError>>()?; + .collect:: as Engine>::Scalar>, SuperNovaError>>()?; // handle the base case by initialize U_next in next round let r_W_primary_initial_list = (0..num_augmented_circuits) @@ -687,7 +687,7 @@ where l_u: None, ABC_Z_1: R1CSResult::default(r1cs_secondary.num_cons), ABC_Z_2: R1CSResult::default(r1cs_secondary.num_cons), - T: r1cs::default_T::>(r1cs_secondary.num_cons), + T: r1cs::default_T::>(r1cs_secondary.num_cons), }; Ok(Self { @@ -719,7 +719,7 @@ where #[tracing::instrument(skip_all, name = "supernova::RecursiveSNARK::prove_step")] pub fn prove_step< C1: StepCircuit, - C2: StepCircuit< as Engine>::Scalar>, + C2: StepCircuit< as Engine>::Scalar>, >( &mut self, pp: &PublicParams, @@ -761,9 +761,9 @@ where pp[circuit_index].r1cs_shape.num_io + 1, pp[circuit_index].r1cs_shape.num_vars, ); - let T = Commitment::>::decompress(&nifs_secondary.comm_T) + let T = Commitment::>::decompress(&nifs_secondary.comm_T) .map_err(SuperNovaError::NovaError)?; - let inputs_primary: SuperNovaAugmentedCircuitInputs<'_, SecEng> = + let inputs_primary: SuperNovaAugmentedCircuitInputs<'_, Dual> = SuperNovaAugmentedCircuitInputs::new( scalar_as_base::(self.pp_digest), E1::Scalar::from(self.i as u64), @@ -776,7 +776,7 @@ where E1::Scalar::ZERO, ); - let circuit_primary: SuperNovaAugmentedCircuit<'_, SecEng, C1> = + let circuit_primary: SuperNovaAugmentedCircuit<'_, Dual, C1> = SuperNovaAugmentedCircuit::new( &pp.augmented_circuit_params_primary, Some(inputs_primary), @@ -831,7 +831,7 @@ where ) .map_err(SuperNovaError::NovaError)?; - let mut cs_secondary = SatisfyingAssignment::>::with_capacity( + let mut cs_secondary = SatisfyingAssignment::>::with_capacity( pp.circuit_shape_secondary.r1cs_shape.num_io + 1, pp.circuit_shape_secondary.r1cs_shape.num_vars, ); @@ -840,14 +840,14 @@ where let inputs_secondary: SuperNovaAugmentedCircuitInputs<'_, E1> = SuperNovaAugmentedCircuitInputs::new( self.pp_digest, - as Engine>::Scalar::from(self.i as u64), + as Engine>::Scalar::from(self.i as u64), &self.z0_secondary, Some(&self.zi_secondary), Some(&r_U_primary_i), Some(&l_u_primary), Some(&binding), None, // pc is always None for secondary circuit - as Engine>::Scalar::from(circuit_index as u64), + as Engine>::Scalar::from(circuit_index as u64), ); let circuit_secondary: SuperNovaAugmentedCircuit<'_, E1, C2> = SuperNovaAugmentedCircuit::new( @@ -887,7 +887,7 @@ where v.get_value() .ok_or(NovaError::from(SynthesisError::AssignmentMissing).into()) }) - .collect:: as Engine>::Scalar>, SuperNovaError>>()?; + .collect:: as Engine>::Scalar>, SuperNovaError>>()?; if zi_primary.len() != pp[circuit_index].F_arity || zi_secondary.len() != pp.circuit_shape_secondary.F_arity @@ -912,8 +912,8 @@ where &self, pp: &PublicParams, z0_primary: &[E1::Scalar], - z0_secondary: &[ as Engine>::Scalar], - ) -> Result<(Vec, Vec< as Engine>::Scalar>), SuperNovaError> { + z0_secondary: &[ as Engine>::Scalar], + ) -> Result<(Vec, Vec< as Engine>::Scalar>), SuperNovaError> { // number of steps cannot be zero if self.i == 0 { debug!("must verify on valid RecursiveSNARK where i > 0"); @@ -993,7 +993,7 @@ where true, // is_primary ); - let mut hasher = as Engine>::RO::new(pp.ro_consts_secondary.clone(), num_absorbs); + let mut hasher = as Engine>::RO::new(pp.ro_consts_secondary.clone(), num_absorbs); hasher.absorb(self.pp_digest); hasher.absorb(E1::Scalar::from(self.i as u64)); hasher.absorb(self.program_counter); @@ -1018,7 +1018,7 @@ where ); let mut hasher = ::RO::new(pp.ro_consts_primary.clone(), num_absorbs); hasher.absorb(scalar_as_base::(self.pp_digest)); - hasher.absorb( as Engine>::Scalar::from(self.i as u64)); + hasher.absorb( as Engine>::Scalar::from(self.i as u64)); for e in z0_secondary { hasher.absorb(*e); @@ -1045,7 +1045,7 @@ where ); return Err(SuperNovaError::NovaError(NovaError::ProofVerifyError)); } - if hash_secondary != scalar_as_base::>(self.l_u_secondary.X[1]) { + if hash_secondary != scalar_as_base::>(self.l_u_secondary.X[1]) { debug!( "hash_secondary {:?} not equal l_u_secondary.X[1] {:?}", hash_secondary, self.l_u_secondary.X[1] @@ -1115,7 +1115,7 @@ where /// The type of the step-circuits on the primary type C1: StepCircuit; /// The type of the step-circuits on the secondary - type C2: StepCircuit< as Engine>::Scalar>; + type C2: StepCircuit< as Engine>::Scalar>; /// Initial circuit index, defaults to zero. fn initial_circuit_index(&self) -> usize { @@ -1157,10 +1157,10 @@ pub fn circuit_digest>( SuperNovaAugmentedCircuitParams::new(BN_LIMB_WIDTH, BN_N_LIMBS, true); // ro_consts_circuit are parameterized by E2 because the type alias uses E2::Base = E1::Scalar - let ro_consts_circuit = ROConstantsCircuit::>::default(); + let ro_consts_circuit = ROConstantsCircuit::>::default(); // Initialize ck for the primary - let augmented_circuit: SuperNovaAugmentedCircuit<'_, SecEng, C> = + let augmented_circuit: SuperNovaAugmentedCircuit<'_, Dual, C> = SuperNovaAugmentedCircuit::new( &augmented_circuit_params, None, diff --git a/src/supernova/snark.rs b/src/supernova/snark.rs index f681e16d5..c32babe0f 100644 --- a/src/supernova/snark.rs +++ b/src/supernova/snark.rs @@ -6,7 +6,7 @@ use crate::{ r1cs::{R1CSInstance, RelaxedR1CSWitness}, traits::{ snark::{BatchedRelaxedR1CSSNARKTrait, RelaxedR1CSSNARKTrait}, - AbsorbInROTrait, CurveCycleEquipped, Engine, ROTrait, SecEng, + AbsorbInROTrait, CurveCycleEquipped, Engine, ROTrait, Dual, }, }; use crate::{errors::NovaError, scalar_as_base, RelaxedR1CSInstance, NIFS}; @@ -20,7 +20,7 @@ pub struct ProverKey where E1: CurveCycleEquipped, S1: BatchedRelaxedR1CSSNARKTrait, - S2: RelaxedR1CSSNARKTrait>, + S2: RelaxedR1CSSNARKTrait>, { pk_primary: S1::ProverKey, pk_secondary: S2::ProverKey, @@ -32,7 +32,7 @@ pub struct VerifierKey where E1: CurveCycleEquipped, S1: BatchedRelaxedR1CSSNARKTrait, - S2: RelaxedR1CSSNARKTrait>, + S2: RelaxedR1CSSNARKTrait>, { vk_primary: S1::VerifierKey, vk_secondary: S2::VerifierKey, @@ -45,28 +45,28 @@ pub struct CompressedSNARK where E1: CurveCycleEquipped, S1: BatchedRelaxedR1CSSNARKTrait, - S2: RelaxedR1CSSNARKTrait>, + S2: RelaxedR1CSSNARKTrait>, { r_U_primary: Vec>, r_W_snark_primary: S1, - r_U_secondary: RelaxedR1CSInstance>, - l_u_secondary: R1CSInstance>, - nifs_secondary: NIFS>, + r_U_secondary: RelaxedR1CSInstance>, + l_u_secondary: R1CSInstance>, + nifs_secondary: NIFS>, f_W_snark_secondary: S2, num_steps: usize, program_counter: E1::Scalar, zn_primary: Vec, - zn_secondary: Vec< as Engine>::Scalar>, + zn_secondary: Vec< as Engine>::Scalar>, } impl CompressedSNARK where E1: CurveCycleEquipped, S1: BatchedRelaxedR1CSSNARKTrait, - S2: RelaxedR1CSSNARKTrait>, + S2: RelaxedR1CSSNARKTrait>, { /// Creates prover and verifier keys for `CompressedSNARK` pub fn setup( @@ -180,8 +180,8 @@ where pp: &PublicParams, vk: &VerifierKey, z0_primary: &[E1::Scalar], - z0_secondary: &[ as Engine>::Scalar], - ) -> Result<(Vec, Vec< as Engine>::Scalar>), SuperNovaError> { + z0_secondary: &[ as Engine>::Scalar], + ) -> Result<(Vec, Vec< as Engine>::Scalar>), SuperNovaError> { let last_circuit_idx = field_as_usize(self.program_counter); let num_field_primary_ro = 3 // params_next, i_new, program_counter_new @@ -199,7 +199,7 @@ where // witnesses provided by the prover let (hash_primary, hash_secondary) = { let mut hasher = - as Engine>::RO::new(pp.ro_consts_secondary.clone(), num_field_primary_ro); + as Engine>::RO::new(pp.ro_consts_secondary.clone(), num_field_primary_ro); hasher.absorb(pp.digest()); hasher.absorb(E1::Scalar::from(self.num_steps as u64)); @@ -219,7 +219,7 @@ where ::RO::new(pp.ro_consts_primary.clone(), num_field_secondary_ro); hasher2.absorb(scalar_as_base::(pp.digest())); - hasher2.absorb( as Engine>::Scalar::from(self.num_steps as u64)); + hasher2.absorb( as Engine>::Scalar::from(self.num_steps as u64)); for e in z0_secondary { hasher2.absorb(*e); @@ -244,7 +244,7 @@ where return Err(NovaError::ProofVerifyError.into()); } - if hash_secondary != scalar_as_base::>(self.l_u_secondary.X[1]) { + if hash_secondary != scalar_as_base::>(self.l_u_secondary.X[1]) { return Err(NovaError::ProofVerifyError.into()); } @@ -439,7 +439,7 @@ mod test { impl NonUniformCircuit for TestCircuit { type C1 = Self; - type C2 = TrivialSecondaryCircuit< as Engine>::Scalar>; + type C2 = TrivialSecondaryCircuit< as Engine>::Scalar>; fn num_circuits(&self) -> usize { 2 @@ -462,9 +462,9 @@ mod test { where E1: CurveCycleEquipped, S1: BatchedRelaxedR1CSSNARKTrait, - S2: RelaxedR1CSSNARKTrait>, + S2: RelaxedR1CSSNARKTrait>, ::Repr: Abomonation, - < as Engine>::Scalar as PrimeField>::Repr: Abomonation, + < as Engine>::Scalar as PrimeField>::Repr: Abomonation, { const NUM_STEPS: usize = 6; @@ -474,7 +474,7 @@ mod test { let pp = PublicParams::setup(&test_circuits[0], &*S1::ck_floor(), &*S2::ck_floor()); let z0_primary = vec![E1::Scalar::from(17u64)]; - let z0_secondary = vec![ as Engine>::Scalar::ZERO]; + let z0_secondary = vec![ as Engine>::Scalar::ZERO]; let mut recursive_snark = RecursiveSNARK::new( &pp, @@ -622,7 +622,7 @@ mod test { impl NonUniformCircuit for BigTestCircuit { type C1 = Self; - type C2 = TrivialSecondaryCircuit< as Engine>::Scalar>; + type C2 = TrivialSecondaryCircuit< as Engine>::Scalar>; fn num_circuits(&self) -> usize { 2 @@ -645,9 +645,9 @@ mod test { where E1: CurveCycleEquipped, S1: BatchedRelaxedR1CSSNARKTrait, - S2: RelaxedR1CSSNARKTrait>, + S2: RelaxedR1CSSNARKTrait>, ::Repr: Abomonation, - < as Engine>::Scalar as PrimeField>::Repr: Abomonation, + < as Engine>::Scalar as PrimeField>::Repr: Abomonation, { const NUM_STEPS: usize = 4; @@ -657,7 +657,7 @@ mod test { let pp = PublicParams::setup(&test_circuits[0], &*S1::ck_floor(), &*S2::ck_floor()); let z0_primary = vec![E1::Scalar::from(17u64)]; - let z0_secondary = vec![ as Engine>::Scalar::ZERO]; + let z0_secondary = vec![ as Engine>::Scalar::ZERO]; let mut recursive_snark = RecursiveSNARK::new( &pp, diff --git a/src/supernova/test.rs b/src/supernova/test.rs index 9b481cfb6..c0d8e3939 100644 --- a/src/supernova/test.rs +++ b/src/supernova/test.rs @@ -225,7 +225,7 @@ where fn print_constraints_name_on_error_index< E1, C1: StepCircuit, - C2: StepCircuit< as Engine>::Scalar>, + C2: StepCircuit< as Engine>::Scalar>, >( err: &SuperNovaError, pp: &PublicParams, @@ -237,7 +237,7 @@ fn print_constraints_name_on_error_index< { match err { SuperNovaError::UnSatIndex(msg, index) if *msg == "r_primary" => { - let circuit_primary: SuperNovaAugmentedCircuit<'_, SecEng, C1> = + let circuit_primary: SuperNovaAugmentedCircuit<'_, Dual, C1> = SuperNovaAugmentedCircuit::new( &pp.augmented_circuit_params_primary, None, @@ -259,7 +259,7 @@ fn print_constraints_name_on_error_index< pp.ro_consts_circuit_secondary.clone(), num_augmented_circuits, ); - let mut cs: TestShapeCS> = TestShapeCS::new(); + let mut cs: TestShapeCS> = TestShapeCS::new(); let _ = circuit_secondary.synthesize(&mut cs); cs.constraints .get(*index) @@ -316,7 +316,7 @@ where E1: CurveCycleEquipped, { type C1 = TestROMCircuit; - type C2 = TrivialSecondaryCircuit< as Engine>::Scalar>; + type C2 = TrivialSecondaryCircuit< as Engine>::Scalar>; fn num_circuits(&self) -> usize { 2 @@ -384,7 +384,7 @@ where .iter() .map(|opcode| ::Scalar::from(*opcode as u64)), ); - let z0_secondary = vec![ as Engine>::Scalar::ONE]; + let z0_secondary = vec![ as Engine>::Scalar::ONE]; let mut recursive_snark_option: Option> = None; @@ -452,7 +452,7 @@ fn test_trivial_nivc() { fn test_recursive_circuit_with( primary_params: &SuperNovaAugmentedCircuitParams, secondary_params: &SuperNovaAugmentedCircuitParams, - ro_consts1: ROConstantsCircuit>, + ro_consts1: ROConstantsCircuit>, ro_consts2: ROConstantsCircuit, num_constraints_primary: &Expect, num_constraints_secondary: &Expect, @@ -464,8 +464,8 @@ fn test_recursive_circuit_with( let arity1 = step_circuit1.arity(); let circuit1: SuperNovaAugmentedCircuit< '_, - SecEng, - TrivialTestCircuit< as Engine>::Base>, + Dual, + TrivialTestCircuit< as Engine>::Base>, > = SuperNovaAugmentedCircuit::new(primary_params, None, &step_circuit1, ro_consts1.clone(), 2); let mut cs: ShapeCS = ShapeCS::new(); if let Err(e) = circuit1.synthesize(&mut cs) { @@ -485,7 +485,7 @@ fn test_recursive_circuit_with( ro_consts2.clone(), 2, ); - let mut cs: ShapeCS> = ShapeCS::new(); + let mut cs: ShapeCS> = ShapeCS::new(); if let Err(e) = circuit2.synthesize(&mut cs) { panic!("{}", e) } @@ -493,10 +493,10 @@ fn test_recursive_circuit_with( num_constraints_secondary.assert_eq(&cs.num_constraints().to_string()); // Execute the base case for the primary - let zero1 = < as Engine>::Base as Field>::ZERO; + let zero1 = < as Engine>::Base as Field>::ZERO; let z0 = vec![zero1; arity1]; let mut cs1 = SatisfyingAssignment::::new(); - let inputs1: SuperNovaAugmentedCircuitInputs<'_, SecEng> = + let inputs1: SuperNovaAugmentedCircuitInputs<'_, Dual> = SuperNovaAugmentedCircuitInputs::new( scalar_as_base::(zero1), // pass zero for testing zero1, @@ -511,8 +511,8 @@ fn test_recursive_circuit_with( let step_circuit = TrivialTestCircuit::default(); let circuit1: SuperNovaAugmentedCircuit< '_, - SecEng, - TrivialTestCircuit< as Engine>::Base>, + Dual, + TrivialTestCircuit< as Engine>::Base>, > = SuperNovaAugmentedCircuit::new(primary_params, Some(inputs1), &step_circuit, ro_consts1, 2); if let Err(e) = circuit1.synthesize(&mut cs1) { panic!("{}", e) @@ -524,9 +524,9 @@ fn test_recursive_circuit_with( // Execute the base case for the secondary let zero2 = <::Base as Field>::ZERO; let z0 = vec![zero2; arity2]; - let mut cs2 = SatisfyingAssignment::>::new(); + let mut cs2 = SatisfyingAssignment::>::new(); let inputs2: SuperNovaAugmentedCircuitInputs<'_, E1> = SuperNovaAugmentedCircuitInputs::new( - scalar_as_base::>(zero2), // pass zero for testing + scalar_as_base::>(zero2), // pass zero for testing zero2, &z0, None, @@ -801,7 +801,7 @@ where E1: CurveCycleEquipped, { type C1 = Self; - type C2 = TrivialSecondaryCircuit< as Engine>::Scalar>; + type C2 = TrivialSecondaryCircuit< as Engine>::Scalar>; fn num_circuits(&self) -> usize { 2 @@ -825,7 +825,7 @@ where E1: CurveCycleEquipped, // this is due to the reliance on Abomonation <::Scalar as PrimeField>::Repr: Abomonation, - < as Engine>::Scalar as PrimeField>::Repr: Abomonation, + < as Engine>::Scalar as PrimeField>::Repr: Abomonation, { let circuit_secondary = TrivialSecondaryCircuit::default(); @@ -834,7 +834,7 @@ where // produce non-deterministic hint let (z0_primary, roots) = RootCheckingCircuit::new(num_steps); assert_eq!(num_steps, roots.len()); - let z0_secondary = vec![ as Engine>::Scalar::ZERO]; + let z0_secondary = vec![ as Engine>::Scalar::ZERO]; // produce public parameters let pp = PublicParams::::setup(&roots[0], &*default_ck_hint(), &*default_ck_hint()); diff --git a/src/traits/mod.rs b/src/traits/mod.rs index ed67d0d68..8f2c46653 100644 --- a/src/traits/mod.rs +++ b/src/traits/mod.rs @@ -62,7 +62,7 @@ pub trait CurveCycleEquipped: Engine { } /// Convenience projection to the Secondary Engine of a CurveCycleEquipped -pub type SecEng = ::Secondary; +pub type Dual = ::Secondary; /// A helper trait to absorb different objects in RO pub trait AbsorbInROTrait {