Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Params to Config & fix test code to new ff #91

Merged
merged 2 commits into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/bits/uint8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ impl<ConstraintF: Field> AllocVar<u8, ConstraintF> for UInt8<ConstraintF> {
}
}

/// Parses the `Vec<UInt8<ConstraintF>>` in fixed-sized `ConstraintF::Params::CAPACITY` chunks and
/// Parses the `Vec<UInt8<ConstraintF>>` in fixed-sized `ConstraintF::MODULUS_BIT_SIZE - 1` chunks and
/// converts each chunk, which is assumed to be little-endian, to its `FpVar<ConstraintF>`
/// representation.
/// This is the gadget counterpart to the `[u8]` implementation of
Expand Down Expand Up @@ -363,7 +363,7 @@ mod test {
use crate::fields::fp::FpVar;
use crate::prelude::AllocationMode::{Constant, Input, Witness};
use crate::{prelude::*, ToConstraintFieldGadget, Vec};
use ark_ff::{FpParameters, PrimeField, ToConstraintField};
use ark_ff::{PrimeField, ToConstraintField};
use ark_relations::r1cs::{ConstraintSystem, SynthesisError};
use ark_std::rand::distributions::Uniform;
use ark_std::rand::Rng;
Expand Down Expand Up @@ -475,7 +475,7 @@ mod test {
#[test]
fn test_uint8_to_constraint_field() -> Result<(), SynthesisError> {
let mut rng = ark_std::test_rng();
let max_size = (<Fr as PrimeField>::Params::CAPACITY / 8) as usize;
let max_size = ((<Fr as PrimeField>::MODULUS_BIT_SIZE - 1) / 8) as usize;

let modes = [Input, Witness, Constant];
for mode in &modes {
Expand Down
2 changes: 1 addition & 1 deletion src/fields/fp/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ mod test {
fn test_cmp() {
let mut rng = ark_std::test_rng();
fn rand_in_range<R: Rng>(rng: &mut R) -> Fr {
let pminusonedivtwo: Fr = Fr::modulus_minus_one_div_two().into();
let pminusonedivtwo: Fr = Fr::MODULUS_MINUS_ONE_DIV_TWO.into();
let mut r;
loop {
r = Fr::rand(rng);
Expand Down
24 changes: 12 additions & 12 deletions src/fields/fp12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ use ark_relations::r1cs::SynthesisError;
/// A degree-12 extension field constructed as the tower of a
/// quadratic extension over a cubic extension over a quadratic extension field.
/// This is the R1CS equivalent of `ark_ff::fp12_2over3over2::Fp12<P>`.
pub type Fp12Var<P> = QuadExtVar<Fp6Var<<P as Fp12Parameters>::Fp6Params>, Fp12ParamsWrapper<P>>;
pub type Fp12Var<P> = QuadExtVar<Fp6Var<<P as Fp12Config>::Fp6Config>, Fp12ConfigWrapper<P>>;

type Fp2Params<P> = <<P as Fp12Parameters>::Fp6Params as Fp6Config>::Fp2Params;
type Fp2Config<P> = <<P as Fp12Config>::Fp6Config as Fp6Config>::Fp2Config;

impl<P: Fp12Parameters> QuadExtVarConfig<Fp6Var<P::Fp6Params>> for Fp12ParamsWrapper<P> {
fn mul_base_field_var_by_frob_coeff(fe: &mut Fp6Var<P::Fp6Params>, power: usize) {
impl<P: Fp12Config> QuadExtVarConfig<Fp6Var<P::Fp6Config>> for Fp12ConfigWrapper<P> {
fn mul_base_field_var_by_frob_coeff(fe: &mut Fp6Var<P::Fp6Config>, power: usize) {
fe.c0 *= Self::FROBENIUS_COEFF_C1[power % Self::DEGREE_OVER_BASE_PRIME_FIELD];
fe.c1 *= Self::FROBENIUS_COEFF_C1[power % Self::DEGREE_OVER_BASE_PRIME_FIELD];
fe.c2 *= Self::FROBENIUS_COEFF_C1[power % Self::DEGREE_OVER_BASE_PRIME_FIELD];
}
}

impl<P: Fp12Parameters> Fp12Var<P> {
impl<P: Fp12Config> Fp12Var<P> {
/// Multiplies by a sparse element of the form `(c0 = (c0, c1, 0), c1 = (0,
/// d1, 0))`.
#[inline]
pub fn mul_by_014(
&self,
c0: &Fp2Var<Fp2Params<P>>,
c1: &Fp2Var<Fp2Params<P>>,
d1: &Fp2Var<Fp2Params<P>>,
c0: &Fp2Var<Fp2Config<P>>,
c1: &Fp2Var<Fp2Config<P>>,
d1: &Fp2Var<Fp2Config<P>>,
) -> Result<Self, SynthesisError> {
let v0 = self.c0.mul_by_c0_c1_0(&c0, &c1)?;
let v1 = self.c1.mul_by_0_c1_0(&d1)?;
Expand All @@ -42,9 +42,9 @@ impl<P: Fp12Parameters> Fp12Var<P> {
#[inline]
pub fn mul_by_034(
&self,
c0: &Fp2Var<Fp2Params<P>>,
d0: &Fp2Var<Fp2Params<P>>,
d1: &Fp2Var<Fp2Params<P>>,
c0: &Fp2Var<Fp2Config<P>>,
d0: &Fp2Var<Fp2Config<P>>,
d1: &Fp2Var<Fp2Config<P>>,
) -> Result<Self, SynthesisError> {
let a0 = &self.c0.c0 * c0;
let a1 = &self.c0.c1 * c0;
Expand All @@ -64,7 +64,7 @@ impl<P: Fp12Parameters> Fp12Var<P> {
/// Squares `self` when `self` is in the cyclotomic subgroup.
pub fn cyclotomic_square(&self) -> Result<Self, SynthesisError> {
if characteristic_square_mod_6_is_one(Fp12::<P>::characteristic()) {
let fp2_nr = <P::Fp6Params as Fp6Config>::NONRESIDUE;
let fp2_nr = <P::Fp6Config as Fp6Config>::NONRESIDUE;

let z0 = &self.c0.c0;
let z4 = &self.c0.c1;
Expand Down
6 changes: 3 additions & 3 deletions src/fields/fp2.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::fields::{fp::FpVar, quadratic_extension::*};
use ark_ff::fields::{Fp2Config, Fp2ParamsWrapper, QuadExtConfig};
use ark_ff::fields::{Fp2Config, Fp2ConfigWrapper, QuadExtConfig};

/// A quadratic extension field constructed over a prime field.
/// This is the R1CS equivalent of `ark_ff::Fp2<P>`.
pub type Fp2Var<P> = QuadExtVar<FpVar<<P as Fp2Config>::Fp>, Fp2ParamsWrapper<P>>;
pub type Fp2Var<P> = QuadExtVar<FpVar<<P as Fp2Config>::Fp>, Fp2ConfigWrapper<P>>;

impl<P: Fp2Config> QuadExtVarConfig<FpVar<P::Fp>> for Fp2ParamsWrapper<P> {
impl<P: Fp2Config> QuadExtVarConfig<FpVar<P::Fp>> for Fp2ConfigWrapper<P> {
fn mul_base_field_var_by_frob_coeff(fe: &mut FpVar<P::Fp>, power: usize) {
*fe *= Self::FROBENIUS_COEFF_C1[power % Self::DEGREE_OVER_BASE_PRIME_FIELD];
}
Expand Down
6 changes: 3 additions & 3 deletions src/fields/fp3.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::fields::{cubic_extension::*, fp::FpVar};
use ark_ff::fields::{CubicExtConfig, Fp3ParamsWrapper};
use ark_ff::fields::{CubicExtConfig, Fp3ConfigWrapper};
use ark_ff::Fp3Config;

/// A cubic extension field constructed over a prime field.
/// This is the R1CS equivalent of `ark_ff::Fp3<P>`.
pub type Fp3Var<P> = CubicExtVar<FpVar<<P as Fp3Config>::Fp>, Fp3ParamsWrapper<P>>;
pub type Fp3Var<P> = CubicExtVar<FpVar<<P as Fp3Config>::Fp>, Fp3ConfigWrapper<P>>;

impl<P: Fp3Config> CubicExtVarConfig<FpVar<P::Fp>> for Fp3ParamsWrapper<P> {
impl<P: Fp3Config> CubicExtVarConfig<FpVar<P::Fp>> for Fp3ConfigWrapper<P> {
fn mul_base_field_vars_by_frob_coeff(
c1: &mut FpVar<P::Fp>,
c2: &mut FpVar<P::Fp>,
Expand Down
8 changes: 4 additions & 4 deletions src/fields/fp4.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::fields::{fp2::Fp2Var, quadratic_extension::*};
use ark_ff::fields::{Fp4ParamsWrapper, QuadExtConfig};
use ark_ff::fields::{Fp4ConfigWrapper, QuadExtConfig};
use ark_ff::Fp4Config;

/// A quartic extension field constructed as the tower of a
/// quadratic extension over a quadratic extension field.
/// This is the R1CS equivalent of `ark_ff::Fp4<P>`.
pub type Fp4Var<P> = QuadExtVar<Fp2Var<<P as Fp4Config>::Fp2Params>, Fp4ParamsWrapper<P>>;
pub type Fp4Var<P> = QuadExtVar<Fp2Var<<P as Fp4Config>::Fp2Config>, Fp4ConfigWrapper<P>>;

impl<P: Fp4Config> QuadExtVarConfig<Fp2Var<P::Fp2Params>> for Fp4ParamsWrapper<P> {
fn mul_base_field_var_by_frob_coeff(fe: &mut Fp2Var<P::Fp2Params>, power: usize) {
impl<P: Fp4Config> QuadExtVarConfig<Fp2Var<P::Fp2Config>> for Fp4ConfigWrapper<P> {
fn mul_base_field_var_by_frob_coeff(fe: &mut Fp2Var<P::Fp2Config>, power: usize) {
fe.c0 *= Self::FROBENIUS_COEFF_C1[power % Self::DEGREE_OVER_BASE_PRIME_FIELD];
fe.c1 *= Self::FROBENIUS_COEFF_C1[power % Self::DEGREE_OVER_BASE_PRIME_FIELD];
}
Expand Down
6 changes: 3 additions & 3 deletions src/fields/fp6_2over3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use ark_ff::QuadExtConfig;
/// A sextic extension field constructed as the tower of a
/// quadratic extension over a cubic extension field.
/// This is the R1CS equivalent of `ark_ff::fp6_2over3::Fp6<P>`.
pub type Fp6Var<P> = QuadExtVar<Fp3Var<<P as Fp6Config>::Fp3Params>, Fp6ParamsWrapper<P>>;
pub type Fp6Var<P> = QuadExtVar<Fp3Var<<P as Fp6Config>::Fp3Config>, Fp6ConfigWrapper<P>>;

impl<P: Fp6Config> QuadExtVarConfig<Fp3Var<P::Fp3Params>> for Fp6ParamsWrapper<P> {
fn mul_base_field_var_by_frob_coeff(fe: &mut Fp3Var<P::Fp3Params>, power: usize) {
impl<P: Fp6Config> QuadExtVarConfig<Fp3Var<P::Fp3Config>> for Fp6ConfigWrapper<P> {
fn mul_base_field_var_by_frob_coeff(fe: &mut Fp3Var<P::Fp3Config>, power: usize) {
fe.c0 *= Self::FROBENIUS_COEFF_C1[power % Self::DEGREE_OVER_BASE_PRIME_FIELD];
fe.c1 *= Self::FROBENIUS_COEFF_C1[power % Self::DEGREE_OVER_BASE_PRIME_FIELD];
fe.c2 *= Self::FROBENIUS_COEFF_C1[power % Self::DEGREE_OVER_BASE_PRIME_FIELD];
Expand Down
18 changes: 9 additions & 9 deletions src/fields/fp6_3over2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ use ark_std::ops::MulAssign;
/// A sextic extension field constructed as the tower of a
/// cubic extension over a quadratic extension field.
/// This is the R1CS equivalent of `ark_ff::fp6_3over3::Fp6<P>`.
pub type Fp6Var<P> = CubicExtVar<Fp2Var<<P as Fp6Config>::Fp2Params>, Fp6ParamsWrapper<P>>;
pub type Fp6Var<P> = CubicExtVar<Fp2Var<<P as Fp6Config>::Fp2Config>, Fp6ConfigWrapper<P>>;

impl<P: Fp6Config> CubicExtVarConfig<Fp2Var<P::Fp2Params>> for Fp6ParamsWrapper<P> {
impl<P: Fp6Config> CubicExtVarConfig<Fp2Var<P::Fp2Config>> for Fp6ConfigWrapper<P> {
fn mul_base_field_vars_by_frob_coeff(
c1: &mut Fp2Var<P::Fp2Params>,
c2: &mut Fp2Var<P::Fp2Params>,
c1: &mut Fp2Var<P::Fp2Config>,
c2: &mut Fp2Var<P::Fp2Config>,
power: usize,
) {
*c1 *= Self::FROBENIUS_COEFF_C1[power % Self::DEGREE_OVER_BASE_PRIME_FIELD];
Expand All @@ -22,7 +22,7 @@ impl<P: Fp6Config> CubicExtVarConfig<Fp2Var<P::Fp2Params>> for Fp6ParamsWrapper<

impl<P: Fp6Config> Fp6Var<P> {
/// Multiplies `self` by a sparse element which has `c0 == c2 == zero`.
pub fn mul_by_0_c1_0(&self, c1: &Fp2Var<P::Fp2Params>) -> Result<Self, SynthesisError> {
pub fn mul_by_0_c1_0(&self, c1: &Fp2Var<P::Fp2Config>) -> Result<Self, SynthesisError> {
// Karatsuba multiplication
// v0 = a0 * b0 = 0

Expand Down Expand Up @@ -52,8 +52,8 @@ impl<P: Fp6Config> Fp6Var<P> {
/// Multiplies `self` by a sparse element which has `c2 == zero`.
pub fn mul_by_c0_c1_0(
&self,
c0: &Fp2Var<P::Fp2Params>,
c1: &Fp2Var<P::Fp2Params>,
c0: &Fp2Var<P::Fp2Config>,
c1: &Fp2Var<P::Fp2Config>,
) -> Result<Self, SynthesisError> {
let v0 = &self.c0 * c0;
let v1 = &self.c1 * c1;
Expand All @@ -77,8 +77,8 @@ impl<P: Fp6Config> Fp6Var<P> {
}
}

impl<P: Fp6Config> MulAssign<Fp2<P::Fp2Params>> for Fp6Var<P> {
fn mul_assign(&mut self, other: Fp2<P::Fp2Params>) {
impl<P: Fp6Config> MulAssign<Fp2<P::Fp2Config>> for Fp6Var<P> {
fn mul_assign(&mut self, other: Fp2<P::Fp2Config>) {
self.c0 *= other;
self.c1 *= other;
self.c2 *= other;
Expand Down
2 changes: 1 addition & 1 deletion src/fields/nonnative/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ pub(crate) use overhead;

/// Parameters for a specific `NonNativeFieldVar` instantiation
#[derive(Clone, Debug)]
pub struct NonNativeFieldParams {
pub struct NonNativeFieldConfig {
/// The number of limbs (`BaseField` elements) used to represent a `TargetField` element. Highest limb first.
pub num_limbs: usize,

Expand Down
6 changes: 3 additions & 3 deletions src/fields/nonnative/params.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use super::NonNativeFieldParams;
use super::NonNativeFieldConfig;

/// Obtain the parameters from a `ConstraintSystem`'s cache or generate a new one
#[must_use]
pub const fn get_params(
target_field_size: usize,
base_field_size: usize,
optimization_type: OptimizationType,
) -> NonNativeFieldParams {
) -> NonNativeFieldConfig {
let (num_of_limbs, limb_size) =
find_parameters(base_field_size, target_field_size, optimization_type);
NonNativeFieldParams {
NonNativeFieldConfig {
num_limbs: num_of_limbs,
bits_per_limb: limb_size,
}
Expand Down
6 changes: 3 additions & 3 deletions src/groups/curves/short_weierstrass/bls12/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ impl<P: Bls12Parameters> ToBytesGadget<P::Fp> for G1PreparedVar<P> {
}
}

type Fp2G<P> = Fp2Var<<P as Bls12Parameters>::Fp2Params>;
type Fp2G<P> = Fp2Var<<P as Bls12Parameters>::Fp2Config>;
type LCoeff<P> = (Fp2G<P>, Fp2G<P>);
/// Represents the cached precomputation that can be performed on a G2 element
/// which enables speeding up pairing computation.
#[derive(Derivative)]
#[derivative(
Clone(bound = "Fp2Var<P::Fp2Params>: Clone"),
Debug(bound = "Fp2Var<P::Fp2Params>: Debug")
Clone(bound = "Fp2Var<P::Fp2Config>: Clone"),
Debug(bound = "Fp2Var<P::Fp2Config>: Debug")
)]
pub struct G2PreparedVar<P: Bls12Parameters> {
#[doc(hidden)]
Expand Down
34 changes: 17 additions & 17 deletions src/groups/curves/short_weierstrass/mnt4/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ pub struct G1PreparedVar<P: MNT4Parameters> {
#[doc(hidden)]
pub y: FpVar<P::Fp>,
#[doc(hidden)]
pub x_twist: Fp2Var<P::Fp2Params>,
pub x_twist: Fp2Var<P::Fp2Config>,
#[doc(hidden)]
pub y_twist: Fp2Var<P::Fp2Params>,
pub y_twist: Fp2Var<P::Fp2Config>,
}

impl<P: MNT4Parameters> AllocVar<G1Prepared<P>, P::Fp> for G1PreparedVar<P> {
Expand Down Expand Up @@ -131,21 +131,21 @@ impl<P: MNT4Parameters> ToBytesGadget<P::Fp> for G1PreparedVar<P> {
}
}

type Fp2G<P> = Fp2Var<<P as MNT4Parameters>::Fp2Params>;
type Fp2G<P> = Fp2Var<<P as MNT4Parameters>::Fp2Config>;

/// Represents the cached precomputation that can be performed on a G2 element
/// which enables speeding up pairing computation.
#[derive(Derivative)]
#[derivative(Clone(bound = "P: MNT4Parameters"), Debug(bound = "P: MNT4Parameters"))]
pub struct G2PreparedVar<P: MNT4Parameters> {
#[doc(hidden)]
pub x: Fp2Var<P::Fp2Params>,
pub x: Fp2Var<P::Fp2Config>,
#[doc(hidden)]
pub y: Fp2Var<P::Fp2Params>,
pub y: Fp2Var<P::Fp2Config>,
#[doc(hidden)]
pub x_over_twist: Fp2Var<P::Fp2Params>,
pub x_over_twist: Fp2Var<P::Fp2Config>,
#[doc(hidden)]
pub y_over_twist: Fp2Var<P::Fp2Params>,
pub y_over_twist: Fp2Var<P::Fp2Config>,
#[doc(hidden)]
pub double_coefficients: Vec<AteDoubleCoefficientsVar<P>>,
#[doc(hidden)]
Expand Down Expand Up @@ -344,10 +344,10 @@ impl<P: MNT4Parameters> G2PreparedVar<P> {
#[derive(Derivative)]
#[derivative(Clone(bound = "P: MNT4Parameters"), Debug(bound = "P: MNT4Parameters"))]
pub struct AteDoubleCoefficientsVar<P: MNT4Parameters> {
pub c_h: Fp2Var<P::Fp2Params>,
pub c_4c: Fp2Var<P::Fp2Params>,
pub c_j: Fp2Var<P::Fp2Params>,
pub c_l: Fp2Var<P::Fp2Params>,
pub c_h: Fp2Var<P::Fp2Config>,
pub c_4c: Fp2Var<P::Fp2Config>,
pub c_j: Fp2Var<P::Fp2Config>,
pub c_l: Fp2Var<P::Fp2Config>,
}

impl<P: MNT4Parameters> AllocVar<AteDoubleCoefficients<P>, P::Fp> for AteDoubleCoefficientsVar<P> {
Expand Down Expand Up @@ -429,8 +429,8 @@ impl<P: MNT4Parameters> AteDoubleCoefficientsVar<P> {
#[derive(Derivative)]
#[derivative(Clone(bound = "P: MNT4Parameters"), Debug(bound = "P: MNT4Parameters"))]
pub struct AteAdditionCoefficientsVar<P: MNT4Parameters> {
pub c_l1: Fp2Var<P::Fp2Params>,
pub c_rz: Fp2Var<P::Fp2Params>,
pub c_l1: Fp2Var<P::Fp2Config>,
pub c_rz: Fp2Var<P::Fp2Config>,
}

impl<P: MNT4Parameters> AllocVar<AteAdditionCoefficients<P>, P::Fp>
Expand Down Expand Up @@ -488,8 +488,8 @@ impl<P: MNT4Parameters> AteAdditionCoefficientsVar<P> {

#[doc(hidden)]
pub struct G2ProjectiveExtendedVar<P: MNT4Parameters> {
pub x: Fp2Var<P::Fp2Params>,
pub y: Fp2Var<P::Fp2Params>,
pub z: Fp2Var<P::Fp2Params>,
pub t: Fp2Var<P::Fp2Params>,
pub x: Fp2Var<P::Fp2Config>,
pub y: Fp2Var<P::Fp2Config>,
pub z: Fp2Var<P::Fp2Config>,
pub t: Fp2Var<P::Fp2Config>,
}
Loading