Skip to content

Commit

Permalink
docs: Improve code readability and testing robustness
Browse files Browse the repository at this point in the history
- Improved readability of CurveCycleEquipped function comment in traits module by adding backticks around function name.
  • Loading branch information
huitseeker committed Feb 5, 2024
1 parent 696c96f commit 0dc08a9
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 46 deletions.
2 changes: 1 addition & 1 deletion benches/common/supernova/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub mod targets;
use anyhow::anyhow;
use arecibo::{
supernova::{NonUniformCircuit, StepCircuit, TrivialTestCircuit},
traits::{CurveCycleEquipped, Engine, Dual},
traits::{CurveCycleEquipped, Dual, Engine},
};
use bellpepper_core::{num::AllocatedNum, ConstraintSystem, SynthesisError};
use core::marker::PhantomData;
Expand Down
14 changes: 4 additions & 10 deletions src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,8 @@ mod tests {
{
let tc1 = TrivialCircuit::default();
// Initialize the shape and ck for the primary
let circuit1: NovaAugmentedCircuit<
'_,
Dual<E1>,
TrivialCircuit<<Dual<E1> as Engine>::Base>,
> = NovaAugmentedCircuit::new(primary_params, None, &tc1, ro_consts1.clone());
let circuit1: NovaAugmentedCircuit<'_, Dual<E1>, TrivialCircuit<<Dual<E1> as Engine>::Base>> =
NovaAugmentedCircuit::new(primary_params, None, &tc1, ro_consts1.clone());
let mut cs: TestShapeCS<E1> = TestShapeCS::new();
let _ = circuit1.synthesize(&mut cs);
let (shape1, ck1) = cs.r1cs_shape_and_key(&*default_ck_hint());
Expand Down Expand Up @@ -425,11 +422,8 @@ mod tests {
None,
None,
);
let circuit1: NovaAugmentedCircuit<
'_,
Dual<E1>,
TrivialCircuit<<Dual<E1> as Engine>::Base>,
> = NovaAugmentedCircuit::new(primary_params, Some(inputs1), &tc1, ro_consts1);
let circuit1: NovaAugmentedCircuit<'_, Dual<E1>, TrivialCircuit<<Dual<E1> 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();
// Make sure that this is satisfiable
Expand Down
20 changes: 5 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,7 @@ where
let l_w_secondary = w_secondary;
let l_u_secondary = u_secondary;
let r_W_secondary = RelaxedR1CSWitness::<Dual<E1>>::default(r1cs_secondary);
let r_U_secondary =
RelaxedR1CSInstance::<Dual<E1>>::default(&pp.ck_secondary, r1cs_secondary);
let r_U_secondary = RelaxedR1CSInstance::<Dual<E1>>::default(&pp.ck_secondary, r1cs_secondary);

assert!(
!(zi_primary.len() != pp.F_arity_primary || zi_secondary.len() != pp.F_arity_secondary),
Expand Down Expand Up @@ -506,10 +505,7 @@ where
/// Create a new `RecursiveSNARK` (or updates the provided `RecursiveSNARK`)
/// by executing a step of the incremental computation
#[tracing::instrument(skip_all, name = "nova::RecursiveSNARK::prove_step")]
pub fn prove_step<
C1: StepCircuit<E1::Scalar>,
C2: StepCircuit<<Dual<E1> as Engine>::Scalar>,
>(
pub fn prove_step<C1: StepCircuit<E1::Scalar>, C2: StepCircuit<<Dual<E1> as Engine>::Scalar>>(
&mut self,
pp: &PublicParams<E1>,
c_primary: &C1,
Expand Down Expand Up @@ -552,9 +548,7 @@ where
Some(self.zi_primary.clone()),
Some(r_U_secondary_i),
Some(l_u_secondary_i),
Some(Commitment::<Dual<E1>>::decompress(
&nifs_secondary.comm_T,
)?),
Some(Commitment::<Dual<E1>>::decompress(&nifs_secondary.comm_T)?),
);

let circuit_primary: NovaAugmentedCircuit<'_, Dual<E1>, C1> = NovaAugmentedCircuit::new(
Expand Down Expand Up @@ -991,8 +985,7 @@ pub fn circuit_digest<E1: CurveCycleEquipped, C: StepCircuit<E1::Scalar>>(
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<Dual<E1>> =
ROConstantsCircuit::<Dual<E1>>::default();
let ro_consts_circuit: ROConstantsCircuit<Dual<E1>> = ROConstantsCircuit::<Dual<E1>>::default();

// Initialize ck for the primary
let augmented_circuit: NovaAugmentedCircuit<'_, Dual<E1>, C> =
Expand Down Expand Up @@ -1638,10 +1631,7 @@ mod tests {
let (zn_primary, zn_secondary) = res.unwrap();

assert_eq!(zn_primary, vec![<E1 as Engine>::Scalar::ONE]);
assert_eq!(
zn_secondary,
vec![<Dual<E1> as Engine>::Scalar::from(5u64)]
);
assert_eq!(zn_secondary, vec![<Dual<E1> as Engine>::Scalar::from(5u64)]);
}

#[test]
Expand Down
7 changes: 2 additions & 5 deletions src/supernova/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
scalar_as_base,
traits::{
commitment::{CommitmentEngineTrait, CommitmentTrait},
AbsorbInROTrait, CurveCycleEquipped, Engine, ROConstants, ROConstantsCircuit, ROTrait, Dual,
AbsorbInROTrait, CurveCycleEquipped, Dual, Engine, ROConstants, ROConstantsCircuit, ROTrait,
},
Commitment, CommitmentKey, R1CSWithArity,
};
Expand Down Expand Up @@ -717,10 +717,7 @@ where
/// executing a step of the incremental computation
#[allow(clippy::too_many_arguments)]
#[tracing::instrument(skip_all, name = "supernova::RecursiveSNARK::prove_step")]
pub fn prove_step<
C1: StepCircuit<E1::Scalar>,
C2: StepCircuit<<Dual<E1> as Engine>::Scalar>,
>(
pub fn prove_step<C1: StepCircuit<E1::Scalar>, C2: StepCircuit<<Dual<E1> as Engine>::Scalar>>(
&mut self,
pp: &PublicParams<E1>,
c_primary: &C1,
Expand Down
2 changes: 1 addition & 1 deletion src/supernova/snark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
r1cs::{R1CSInstance, RelaxedR1CSWitness},
traits::{
snark::{BatchedRelaxedR1CSSNARKTrait, RelaxedR1CSSNARKTrait},
AbsorbInROTrait, CurveCycleEquipped, Engine, ROTrait, Dual,
AbsorbInROTrait, CurveCycleEquipped, Dual, Engine, ROTrait,
},
};
use crate::{errors::NovaError, scalar_as_base, RelaxedR1CSInstance, NIFS};
Expand Down
23 changes: 11 additions & 12 deletions src/supernova/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,18 +496,17 @@ fn test_recursive_circuit_with<E1>(
let zero1 = <<Dual<E1> as Engine>::Base as Field>::ZERO;
let z0 = vec![zero1; arity1];
let mut cs1 = SatisfyingAssignment::<E1>::new();
let inputs1: SuperNovaAugmentedCircuitInputs<'_, Dual<E1>> =
SuperNovaAugmentedCircuitInputs::new(
scalar_as_base::<E1>(zero1), // pass zero for testing
zero1,
&z0,
None,
None,
None,
None,
Some(zero1),
zero1,
);
let inputs1: SuperNovaAugmentedCircuitInputs<'_, Dual<E1>> = SuperNovaAugmentedCircuitInputs::new(
scalar_as_base::<E1>(zero1), // pass zero for testing
zero1,
&z0,
None,
None,
None,
None,
Some(zero1),
zero1,
);
let step_circuit = TrivialTestCircuit::default();
let circuit1: SuperNovaAugmentedCircuit<
'_,
Expand Down
4 changes: 2 additions & 2 deletions src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ pub trait Engine: Clone + Copy + Debug + Send + Sync + Sized + Eq + PartialEq {

/// This is a convenience trait to pair engines which fields are in a curve cycle relationship
pub trait CurveCycleEquipped: Engine {
/// The secondary Engine of `Self`
/// The secondary `Engine` of `Self`
type Secondary: Engine<Base = <Self as Engine>::Scalar, Scalar = <Self as Engine>::Base>;
}

/// Convenience projection to the Secondary Engine of a CurveCycleEquipped
/// Convenience projection to the secondary `Engine` of a `CurveCycleEquipped`
pub type Dual<E> = <E as CurveCycleEquipped>::Secondary;

/// A helper trait to absorb different objects in RO
Expand Down

0 comments on commit 0dc08a9

Please sign in to comment.