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 all *Parameters to *Config #545

Merged
merged 11 commits into from
Dec 16, 2022
20 changes: 15 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

## Pending

- [\#528](https://github.com/arkworks-rs/algebra/pull/528) (`ark-ec`) Allow to overwrite the default implementation of the `msm` function provided by the `VariableBaseMSM` trait by a specialized version in `SWCurveConfig`.
- [\#521](https://github.com/arkworks-rs/algebra/pull/521) (`ark-poly`) Change `DensePolynomial::evaluate_over_domain` to not truncate terms higher than the size of the domain.

### Breaking changes

- [\#300](https://github.com/arkworks-rs/algebra/pull/300) (`ark-ec`) Change the implementation of `Hash` trait of `GroupProjective` to use the affine coordinates.
Expand Down Expand Up @@ -34,7 +31,7 @@
- [\#386](https://github.com/arkworks-rs/algebra/pull/386) (`ark-ff`) Remove `PrimeField::GENERATOR`, since it already exists on `FftField`.
- [\#393](https://github.com/arkworks-rs/algebra/pull/393) (`ark-ec`, `ark-ff`) Rename `FpXParams` to `FpXConfig` and `FpXParamsWrapper` to `FpXConfigWrapper`.
- [\#396](https://github.com/arkworks-rs/algebra/pull/396) (`ark-ec`) Remove `mul_bits` feature, and remove default implementations of `mul` and `mul_by_cofactor_to_projective`.
- [\#408](https://github.com/arkworks-rs/algebra/pull/408) (`ark-ff`) Change the output of `Display` formatting for BigInt & Fp from hex to decimal.
- [\#408](https://github.com/arkworks-rs/algebra/pull/408) (`ark-ff`) Change the output of `Display` formatting for `BigInt` and `Fp` from hex to decimal.
- [\#412](https://github.com/arkworks-rs/algebra/pull/412) (`ark-poly`) Rename UV/MVPolynomial to DenseUV/MVPolynomial.
- [\#417](https://github.com/arkworks-rs/algebra/pull/417) (`ark-ff`) Remove `ToBytes` and `FromBytes`.
- [\#418](https://github.com/arkworks-rs/algebra/pull/418) (`ark-ff`) Add `sums_of_products` to `Field` and `Fp`
Expand Down Expand Up @@ -93,7 +90,7 @@
- `miller_loop` → `multi_miller_loop`
- `pairing` → `multi_pairing`
- Change method signatures:
- `product_of_pairings` -> `multi_pairing`
- `product_of_pairings` `multi_pairing`
- take two references to element iterators instead of an iterator of tuples.
- `miller_loop` and `multi_miller_loop` now
- take two iterators over `impl Into<G1Prepared>` and `impl Into<G2Prepared>` as input, and
Expand Down Expand Up @@ -141,6 +138,17 @@
- Adds `impl<'a, 'b> Add/Sub/Mul/Div<&'a F> for &'b F`
- [\#517](https://github.com/arkworks-rs/algebra/pull/517) (`ark-ec`) Move the definition of the isogeny map of WB hash-to-curve to a separate struct
- [\#519](https://github.com/arkworks-rs/algebra/pull/519) (`ark-ec`) Refactor variable-base MSM to be checked by default, returning a `Result` if the lengths of the bases and scalars do not match.
- [\#545](https://github.com/arkworks-rs/algebra/pull/545) (`ark-ec`, `ark-ff`) Rename all `*Parameters` or `*Params` to `*Config`, including:
- `SWUParams` → `SWUConfig`
- `WBParams` → `WBConfig`
- `Bls12Parameters` → `Bls12Config`
- `G1Parameters` → `G1Config`
- `G2Parameters` → `G2Config`
- `BnParameters` → `BnConfig`
- `BW6Parameters` → `BW6Config`
- `MNT4Parameters` → `MNT4Config`
- `MNT6Parameters` → `MNT6Config`
- `GLVParameters` → `GLVConfig`

### Features

Expand All @@ -166,6 +174,7 @@
- Add convenience method `get_coset`.
- Add methods `coset_offset`, `coset_offset_inv` and `coset_offset_pow_size`.
- [\#539](https://github.com/arkworks-rs/algebra/pull/539) (`ark-ec`) Implement wNAF-based MSM, resulting in 5-10% speedups.
- [\#528](https://github.com/arkworks-rs/algebra/pull/528) (`ark-ec`) Allow to overwrite the default implementation of the `msm` function provided by the `VariableBaseMSM` trait by a specialized version in `SWCurveConfig`.

### Improvements

Expand All @@ -185,6 +194,7 @@
- [\#394](https://github.com/arkworks-rs/algebra/pull/394) (`ark-ff`, `ark-serialize`) Remove `EmptyFlags` construction checks.
- [\#442](https://github.com/arkworks-rs/algebra/pull/442) (`ark-ff`) Fix deserialization for modulo with 64 shaving bits.
- [\#460](https://github.com/arkworks-rs/algebra/pull/460) (`ark-ec`) Fix a corner case for ate pairing in BLS12 and BW6 models.
- [\#521](https://github.com/arkworks-rs/algebra/pull/521) (`ark-poly`) Change `DensePolynomial::evaluate_over_domain` to not truncate terms higher than the size of the domain.
- [\#526](https://github.com/arkworks-rs/algebra/pull/526) (`ark-ff`) Fix squaring for `Fp128`.

## v0.3.0
Expand Down
22 changes: 11 additions & 11 deletions ec/src/hashing/curve_maps/swu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
/// y^2 = x^3 + a*x + b where ab != 0. From [\[WB2019\]]
///
/// - [\[WB2019\]] <https://eprint.iacr.org/2019/403>
pub trait SWUParams: SWCurveConfig {
pub trait SWUConfig: SWCurveConfig {
/// An element of the base field that is not a square root see \[WB2019, Section 4\].
/// It is also convenient to have $g(b/ZETA * a)$ to be square. In general
/// we use a `ZETA` with low absolute value coefficients when they are
Expand All @@ -22,7 +22,7 @@ pub trait SWUParams: SWCurveConfig {
}

/// Represents the SWU hash-to-curve map defined by `P`.
pub struct SWUMap<P: SWUParams>(PhantomData<fn() -> P>);
pub struct SWUMap<P: SWUConfig>(PhantomData<fn() -> P>);

/// Trait defining a parity method on the Field elements based on [\[1\]] Section 4.1
///
Expand All @@ -34,7 +34,7 @@ pub fn parity<F: Field>(element: &F) -> bool {
.map_or(false, |x| x.into_bigint().is_odd())
}

impl<P: SWUParams> MapToCurve<Projective<P>> for SWUMap<P> {
impl<P: SWUConfig> MapToCurve<Projective<P>> for SWUMap<P> {
/// Constructs a new map if `P` represents a valid map.
fn new() -> Result<Self, HashToCurveError> {
// Verifying that ZETA is a non-square
Expand Down Expand Up @@ -171,9 +171,9 @@ mod test {

const F127_ONE: F127 = MontFp!("1");

struct TestSWUMapToCurveParams;
struct TestSWUMapToCurveConfig;

impl CurveConfig for TestSWUMapToCurveParams {
impl CurveConfig for TestSWUMapToCurveConfig {
const COFACTOR: &'static [u64] = &[1];

#[rustfmt::skip]
Expand All @@ -197,7 +197,7 @@ mod test {
/// pass
///
/// y^2 = x^3 + x + 63
impl SWCurveConfig for TestSWUMapToCurveParams {
impl SWCurveConfig for TestSWUMapToCurveConfig {
/// COEFF_A = 1
const COEFF_A: F127 = F127_ONE;

Expand All @@ -208,7 +208,7 @@ mod test {
const GENERATOR: Affine<Self> = Affine::new_unchecked(MontFp!("62"), MontFp!("70"));
}

impl SWUParams for TestSWUMapToCurveParams {
impl SWUConfig for TestSWUMapToCurveConfig {
const ZETA: F127 = MontFp!("-1");
}

Expand Down Expand Up @@ -237,9 +237,9 @@ mod test {
#[test]
fn hash_arbitary_string_to_curve_swu() {
let test_swu_to_curve_hasher = MapToCurveBasedHasher::<
Projective<TestSWUMapToCurveParams>,
Projective<TestSWUMapToCurveConfig>,
DefaultFieldHasher<Sha256, 128>,
SWUMap<TestSWUMapToCurveParams>,
SWUMap<TestSWUMapToCurveConfig>,
>::new(&[1])
.unwrap();

Expand All @@ -256,9 +256,9 @@ mod test {
/// elements should be mapped to curve successfully. everything can be mapped
#[test]
fn map_field_to_curve_swu() {
let test_map_to_curve = SWUMap::<TestSWUMapToCurveParams>::new().unwrap();
let test_map_to_curve = SWUMap::<TestSWUMapToCurveConfig>::new().unwrap();

let mut map_range: Vec<Affine<TestSWUMapToCurveParams>> = vec![];
let mut map_range: Vec<Affine<TestSWUMapToCurveConfig>> = vec![];
for current_field_element in 0..127 {
map_range.push(
test_map_to_curve
Expand Down
40 changes: 20 additions & 20 deletions ec/src/hashing/curve_maps/wb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
AffineRepr,
};

use super::swu::{SWUMap, SWUParams};
use super::swu::{SWUConfig, SWUMap};
type BaseField<MP> = <MP as CurveConfig>::BaseField;

/// [`IsogenyMap`] defines an isogeny between curves of
Expand Down Expand Up @@ -70,20 +70,20 @@ where
/// From [\[WB2019\]]
///
/// - [\[WB2019\]] <http://dx.doi.org/10.46586/tches.v2019.i4.154-179>
pub trait WBParams: SWCurveConfig + Sized {
pub trait WBConfig: SWCurveConfig + Sized {
// The isogenous curve should be defined over the same base field but it can have
// different scalar field type IsogenousCurveScalarField :
type IsogenousCurve: SWUParams<BaseField = BaseField<Self>>;
type IsogenousCurve: SWUConfig<BaseField = BaseField<Self>>;

const ISOGENY_MAP: IsogenyMap<'static, Self::IsogenousCurve, Self>;
}

pub struct WBMap<P: WBParams> {
pub struct WBMap<P: WBConfig> {
swu_field_curve_hasher: SWUMap<P::IsogenousCurve>,
curve_params: PhantomData<fn() -> P>,
}

impl<P: WBParams> MapToCurve<Projective<P>> for WBMap<P> {
impl<P: WBConfig> MapToCurve<Projective<P>> for WBMap<P> {
/// Constructs a new map if `P` represents a valid map.
fn new() -> Result<Self, HashToCurveError> {
match P::ISOGENY_MAP.apply(P::IsogenousCurve::GENERATOR) {
Expand Down Expand Up @@ -119,8 +119,8 @@ mod test {
use crate::{
hashing::{
curve_maps::{
swu::SWUParams,
wb::{IsogenyMap, WBMap, WBParams},
swu::SWUConfig,
wb::{IsogenyMap, WBConfig, WBMap},
},
map_to_curve_hasher::MapToCurveBasedHasher,
HashToCurve,
Expand All @@ -141,9 +141,9 @@ mod test {
const F127_ONE: F127 = MontFp!("1");

/// The struct defining our parameters for the target curve of hashing
struct TestWBF127MapToCurveParams;
struct TestWBF127MapToCurveConfig;

impl CurveConfig for TestWBF127MapToCurveParams {
impl CurveConfig for TestWBF127MapToCurveConfig {
const COFACTOR: &'static [u64] = &[1];

#[rustfmt::skip]
Expand All @@ -155,7 +155,7 @@ mod test {

/// E: Elliptic Curve defined by y^2 = x^3 + 3 over Finite
/// Field of size 127
impl SWCurveConfig for TestWBF127MapToCurveParams {
impl SWCurveConfig for TestWBF127MapToCurveConfig {
/// COEFF_A = 0
const COEFF_A: F127 = F127_ZERO;

Expand All @@ -171,12 +171,12 @@ mod test {
/// E_isogenous : Elliptic Curve defined by y^2 = x^3 + 109*x + 124 over Finite
/// Field of size 127
/// Isogenous to E : y^2 = x^3 + 3
struct TestSWU127MapToIsogenousCurveParams;
struct TestSWU127MapToIsogenousCurveConfig;

/// First we define the isogenous curve
/// sage: E_isogenous.order()
/// 127
impl CurveConfig for TestSWU127MapToIsogenousCurveParams {
impl CurveConfig for TestSWU127MapToIsogenousCurveConfig {
const COFACTOR: &'static [u64] = &[1];

#[rustfmt::skip]
Expand All @@ -188,7 +188,7 @@ mod test {

/// E_isogenous : Elliptic Curve defined by y^2 = x^3 + 109*x + 124 over Finite
/// Field of size 127
impl SWCurveConfig for TestSWU127MapToIsogenousCurveParams {
impl SWCurveConfig for TestSWU127MapToIsogenousCurveConfig {
/// COEFF_A = 109
const COEFF_A: F127 = MontFp!("109");

Expand All @@ -201,7 +201,7 @@ mod test {
}

/// SWU parameters for E_isogenous
impl SWUParams for TestSWU127MapToIsogenousCurveParams {
impl SWUConfig for TestSWU127MapToIsogenousCurveConfig {
/// NON-SQUARE = - 1
const ZETA: F127 = MontFp!("-1");
}
Expand All @@ -223,8 +223,8 @@ mod test {
/// - 46*x^8 - 61*x^7 - 16*x^6 - 55*x^5 + 18*x^4 + 23*x^3 - 24*x^2 - 18*x + 32)
const ISOGENY_MAP_TESTWBF127: IsogenyMap<
'_,
TestSWU127MapToIsogenousCurveParams,
TestWBF127MapToCurveParams,
TestSWU127MapToIsogenousCurveConfig,
TestWBF127MapToCurveConfig,
> = IsogenyMap {
x_map_numerator: &[
MontFp!("4"),
Expand Down Expand Up @@ -303,8 +303,8 @@ mod test {
MontFp!("1"),
],
};
impl WBParams for TestWBF127MapToCurveParams {
type IsogenousCurve = TestSWU127MapToIsogenousCurveParams;
impl WBConfig for TestWBF127MapToCurveConfig {
type IsogenousCurve = TestSWU127MapToIsogenousCurveConfig;

const ISOGENY_MAP: super::IsogenyMap<'static, Self::IsogenousCurve, Self> =
ISOGENY_MAP_TESTWBF127;
Expand All @@ -316,9 +316,9 @@ mod test {
fn hash_arbitrary_string_to_curve_wb() {
use sha2::Sha256;
let test_wb_to_curve_hasher = MapToCurveBasedHasher::<
Projective<TestWBF127MapToCurveParams>,
Projective<TestWBF127MapToCurveConfig>,
DefaultFieldHasher<Sha256, 128>,
WBMap<TestWBF127MapToCurveParams>,
WBMap<TestWBF127MapToCurveConfig>,
>::new(&[1])
.unwrap();

Expand Down
16 changes: 7 additions & 9 deletions ec/src/hashing/tests/suites.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ use ark_test_curves::{
};

use ark_ff::{Field, PrimeField};
use ark_test_curves::bls12_381::{
g1::Parameters as G1Parameters, g2::Parameters as G2Parameters, Fq, Fq2,
};
use ark_test_curves::bls12_381::{g1::Config as G1Config, g2::Config as G2Config, Fq, Fq2};
use sha2::Sha256;

#[test]
Expand All @@ -38,15 +36,15 @@ fn run_test_w(data: &SuiteVector) -> Result<(), Failed> {
let hasher;
let m;
let g1_mapper = MapToCurveBasedHasher::<
Projective<G1Parameters>,
Projective<G1Config>,
DefaultFieldHasher<Sha256, 128>,
WBMap<G1Parameters>,
WBMap<G1Config>,
>::new(dst)
.unwrap();
let g2_mapper = MapToCurveBasedHasher::<
Projective<G2Parameters>,
Projective<G2Config>,
DefaultFieldHasher<Sha256, 128>,
WBMap<G2Parameters>,
WBMap<G2Config>,
>::new(dst)
.unwrap();
match data.curve.as_str() {
Expand Down Expand Up @@ -79,7 +77,7 @@ fn run_test_w(data: &SuiteVector) -> Result<(), Failed> {
match data.curve.as_str() {
"BLS12-381 G1" => {
let got = g1_mapper.hash(&v.msg.as_bytes()).unwrap();
let want = Affine::<G1Parameters>::new_unchecked(
let want = Affine::<G1Config>::new_unchecked(
Fq::from_base_prime_field_elems(&x[..]).unwrap(),
Fq::from_base_prime_field_elems(&y[..]).unwrap(),
);
Expand All @@ -95,7 +93,7 @@ fn run_test_w(data: &SuiteVector) -> Result<(), Failed> {
},
"BLS12-381 G2" => {
let got = g2_mapper.hash(&v.msg.as_bytes()).unwrap();
let want = Affine::<G2Parameters>::new_unchecked(
let want = Affine::<G2Config>::new_unchecked(
Fq2::from_base_prime_field_elems(&x[..]).unwrap(),
Fq2::from_base_prime_field_elems(&y[..]).unwrap(),
);
Expand Down
28 changes: 14 additions & 14 deletions ec/src/models/bls12/g1.rs
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
use crate::{
bls12::Bls12Parameters,
bls12::Bls12Config,
short_weierstrass::{Affine, Projective},
AffineRepr, CurveGroup,
};
use ark_serialize::*;
use ark_std::vec::Vec;

pub type G1Affine<P> = Affine<<P as Bls12Parameters>::G1Parameters>;
pub type G1Projective<P> = Projective<<P as Bls12Parameters>::G1Parameters>;
pub type G1Affine<P> = Affine<<P as Bls12Config>::G1Config>;
pub type G1Projective<P> = Projective<<P as Bls12Config>::G1Config>;

#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(
Clone(bound = "P: Bls12Parameters"),
Debug(bound = "P: Bls12Parameters"),
PartialEq(bound = "P: Bls12Parameters"),
Eq(bound = "P: Bls12Parameters")
Clone(bound = "P: Bls12Config"),
Debug(bound = "P: Bls12Config"),
PartialEq(bound = "P: Bls12Config"),
Eq(bound = "P: Bls12Config")
)]
pub struct G1Prepared<P: Bls12Parameters>(pub G1Affine<P>);
pub struct G1Prepared<P: Bls12Config>(pub G1Affine<P>);

impl<P: Bls12Parameters> From<G1Affine<P>> for G1Prepared<P> {
impl<P: Bls12Config> From<G1Affine<P>> for G1Prepared<P> {
fn from(other: G1Affine<P>) -> Self {
G1Prepared(other)
}
}

impl<P: Bls12Parameters> From<G1Projective<P>> for G1Prepared<P> {
impl<P: Bls12Config> From<G1Projective<P>> for G1Prepared<P> {
fn from(q: G1Projective<P>) -> Self {
q.into_affine().into()
}
}

impl<'a, P: Bls12Parameters> From<&'a G1Affine<P>> for G1Prepared<P> {
impl<'a, P: Bls12Config> From<&'a G1Affine<P>> for G1Prepared<P> {
fn from(other: &'a G1Affine<P>) -> Self {
G1Prepared(*other)
}
}

impl<'a, P: Bls12Parameters> From<&'a G1Projective<P>> for G1Prepared<P> {
impl<'a, P: Bls12Config> From<&'a G1Projective<P>> for G1Prepared<P> {
fn from(q: &'a G1Projective<P>) -> Self {
q.into_affine().into()
}
}

impl<P: Bls12Parameters> G1Prepared<P> {
impl<P: Bls12Config> G1Prepared<P> {
pub fn is_zero(&self) -> bool {
self.0.is_zero()
}
}

impl<P: Bls12Parameters> Default for G1Prepared<P> {
impl<P: Bls12Config> Default for G1Prepared<P> {
fn default() -> Self {
G1Prepared(G1Affine::<P>::generator())
}
Expand Down
Loading