Browse Source

name changes for improved clarity (#93)

main
Srinath Setty 2 years ago
committed by GitHub
parent
commit
87a5b07bdd
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 48 deletions
  1. +26
    -25
      src/circuit.rs
  2. +25
    -23
      src/lib.rs

+ 26
- 25
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<G: Group> {
pub struct NovaAugmentedCircuitInputs<G: Group> {
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<Commitment<G>>,
}
impl<G> NIFSVerifierCircuitInputs<G>
impl<G> NovaAugmentedCircuitInputs<G>
where
G: Group,
{
@ -83,27 +83,28 @@ where
}
}
/// Circuit that encodes only the folding verifier
pub struct NIFSVerifierCircuit<G, SC>
/// 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<G, SC>
where
G: Group,
SC: StepCircuit<G::Base>,
{
params: NIFSVerifierCircuitParams,
params: NovaAugmentedCircuitParams,
ro_consts: HashFuncConstantsCircuit<G>,
inputs: Option<NIFSVerifierCircuitInputs<G>>,
inputs: Option<NovaAugmentedCircuitInputs<G>>,
step_circuit: SC, // The function that is applied for each step
}
impl<G, SC> NIFSVerifierCircuit<G, SC>
impl<G, SC> NovaAugmentedCircuit<G, SC>
where
G: Group,
SC: StepCircuit<G::Base>,
{
/// Create a new verification circuit for the input relaxed r1cs instances
pub fn new(
params: NIFSVerifierCircuitParams,
inputs: Option<NIFSVerifierCircuitInputs<G>>,
params: NovaAugmentedCircuitParams,
inputs: Option<NovaAugmentedCircuitInputs<G>>,
step_circuit: SC,
ro_consts: HashFuncConstantsCircuit<G>,
) -> Self {
@ -250,7 +251,7 @@ where
}
}
impl<G, SC> Circuit<<G as Group>::Base> for NIFSVerifierCircuit<G, SC>
impl<G, SC> Circuit<<G as Group>::Base> for NovaAugmentedCircuit<G, SC>
where
G: Group,
SC: StepCircuit<G::Base>,
@ -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<G2> = PoseidonConstantsCircuit::new();
let ro_consts2: HashFuncConstantsCircuit<G1> = PoseidonConstantsCircuit::new();
// Initialize the shape and gens for the primary
let circuit1: NIFSVerifierCircuit<G2, TrivialTestCircuit<<G2 as Group>::Base>> =
NIFSVerifierCircuit::new(
let circuit1: NovaAugmentedCircuit<G2, TrivialTestCircuit<<G2 as Group>::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<G1, TrivialTestCircuit<<G1 as Group>::Base>> =
NIFSVerifierCircuit::new(
let circuit2: NovaAugmentedCircuit<G1, TrivialTestCircuit<<G1 as Group>::Base>> =
NovaAugmentedCircuit::new(
params2.clone(),
None,
TrivialTestCircuit::default(),
@ -395,10 +396,10 @@ mod tests {
// Execute the base case for the primary
let zero1 = <<G2 as Group>::Base as Field>::zero();
let mut cs1: SatisfyingAssignment<G1> = SatisfyingAssignment::new();
let inputs1: NIFSVerifierCircuitInputs<G2> =
NIFSVerifierCircuitInputs::new(shape2.get_digest(), zero1, zero1, None, None, None, None);
let circuit1: NIFSVerifierCircuit<G2, TrivialTestCircuit<<G2 as Group>::Base>> =
NIFSVerifierCircuit::new(
let inputs1: NovaAugmentedCircuitInputs<G2> =
NovaAugmentedCircuitInputs::new(shape2.get_digest(), zero1, zero1, None, None, None, None);
let circuit1: NovaAugmentedCircuit<G2, TrivialTestCircuit<<G2 as Group>::Base>> =
NovaAugmentedCircuit::new(
params1,
Some(inputs1),
TrivialTestCircuit::default(),
@ -412,7 +413,7 @@ mod tests {
// Execute the base case for the secondary
let zero2 = <<G1 as Group>::Base as Field>::zero();
let mut cs2: SatisfyingAssignment<G2> = SatisfyingAssignment::new();
let inputs2: NIFSVerifierCircuitInputs<G1> = NIFSVerifierCircuitInputs::new(
let inputs2: NovaAugmentedCircuitInputs<G1> = NovaAugmentedCircuitInputs::new(
shape1.get_digest(),
zero2,
zero2,
@ -421,8 +422,8 @@ mod tests {
Some(inst1),
None,
);
let circuit: NIFSVerifierCircuit<G1, TrivialTestCircuit<<G1 as Group>::Base>> =
NIFSVerifierCircuit::new(
let circuit: NovaAugmentedCircuit<G1, TrivialTestCircuit<<G1 as Group>::Base>> =
NovaAugmentedCircuit::new(
params2,
Some(inputs2),
TrivialTestCircuit::default(),

+ 25
- 23
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<G2>,
r1cs_shape_secondary: R1CSShape<G2>,
r1cs_shape_padded_secondary: R1CSShape<G2>,
nifs_params_primary: NIFSVerifierCircuitParams,
nifs_params_secondary: NIFSVerifierCircuitParams,
augmented_circuit_params_primary: NovaAugmentedCircuitParams,
augmented_circuit_params_secondary: NovaAugmentedCircuitParams,
_p_c1: PhantomData<C1>,
_p_c2: PhantomData<C2>,
}
@ -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<G1> = HashFuncConstants::<G1>::new();
let ro_consts_secondary: HashFuncConstants<G2> = HashFuncConstants::<G2>::new();
@ -86,8 +88,8 @@ where
HashFuncConstantsCircuit::<G1>::new();
// Initialize gens for the primary
let circuit_primary: NIFSVerifierCircuit<G2, C1> = NIFSVerifierCircuit::new(
nifs_params_primary.clone(),
let circuit_primary: NovaAugmentedCircuit<G2, C1> = 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<G1, C2> = NIFSVerifierCircuit::new(
nifs_params_secondary.clone(),
let circuit_secondary: NovaAugmentedCircuit<G1, C2> = 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<G1> = SatisfyingAssignment::new();
let inputs_primary: NIFSVerifierCircuitInputs<G2> = NIFSVerifierCircuitInputs::new(
let inputs_primary: NovaAugmentedCircuitInputs<G2> = NovaAugmentedCircuitInputs::new(
pp.r1cs_shape_secondary.get_digest(),
G1::Scalar::zero(),
z0_primary,
@ -191,8 +193,8 @@ where
None,
);
let circuit_primary: NIFSVerifierCircuit<G2, C1> = NIFSVerifierCircuit::new(
pp.nifs_params_primary.clone(),
let circuit_primary: NovaAugmentedCircuit<G2, C1> = 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<G2> = SatisfyingAssignment::new();
let inputs_secondary: NIFSVerifierCircuitInputs<G1> = NIFSVerifierCircuitInputs::new(
let inputs_secondary: NovaAugmentedCircuitInputs<G1> = 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<G1, C2> = NIFSVerifierCircuit::new(
pp.nifs_params_secondary.clone(),
let circuit_secondary: NovaAugmentedCircuit<G1, C2> = 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<G1> = SatisfyingAssignment::new();
let inputs_primary: NIFSVerifierCircuitInputs<G2> = NIFSVerifierCircuitInputs::new(
let inputs_primary: NovaAugmentedCircuitInputs<G2> = 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<G2, C1> = NIFSVerifierCircuit::new(
pp.nifs_params_primary.clone(),
let circuit_primary: NovaAugmentedCircuit<G2, C1> = 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<G2> = SatisfyingAssignment::new();
let inputs_secondary: NIFSVerifierCircuitInputs<G1> = NIFSVerifierCircuitInputs::new(
let inputs_secondary: NovaAugmentedCircuitInputs<G1> = 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<G1, C2> = NIFSVerifierCircuit::new(
pp.nifs_params_secondary.clone(),
let circuit_secondary: NovaAugmentedCircuit<G1, C2> = NovaAugmentedCircuit::new(
pp.augmented_circuit_params_secondary.clone(),
Some(inputs_secondary),
c_secondary.clone(),
pp.ro_consts_circuit_secondary.clone(),

Loading…
Cancel
Save