Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Commit

Permalink
Sync with the recent changes in ark-algebra on pairing and testing (#116
Browse files Browse the repository at this point in the history
)

* Fix another typo in the Jubjub curve comment

* fix

* progress

* get_point_from_x_unchecked

* fix

* soft link

* Fix Bandersnatch

* Fix Edwards form of Bandersnatch

* Actually fix ed_on_bls12_381_bandersnatch/src/curves/mod.rs

* fix

* fix

* curve-benches

* fix the last mul_by_a; fmt

Co-authored-by: onewayfunc <[email protected]>
Co-authored-by: Pratyush Mishra <[email protected]>
  • Loading branch information
3 people authored Sep 2, 2022
1 parent 4228924 commit 3c4c67f
Show file tree
Hide file tree
Showing 113 changed files with 313 additions and 1,075 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ debug = true
ark-ec = { git = "https://github.com/arkworks-rs/algebra" }
ark-ff = { git = "https://github.com/arkworks-rs/algebra" }
ark-serialize = { git = "https://github.com/arkworks-rs/algebra" }
ark-algebra-bench-templates = { git = "https://github.com/arkworks-rs/algebra" }
ark-algebra-test-templates = { git = "https://github.com/arkworks-rs/algebra" }
ark-r1cs-std = { git = "https://github.com/arkworks-rs/r1cs-std" }
ark-std = { git = "https://github.com/arkworks-rs/std" }
ark-std = { git = "https://github.com/arkworks-rs/std" }
2 changes: 1 addition & 1 deletion bls12_377/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ keywords = ["cryptography", "finite-fields", "elliptic-curves" ]
categories = ["cryptography"]
include = ["Cargo.toml", "src", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
license = "MIT/Apache-2.0"
edition = "2018"
edition = "2021"

[dependencies]
ark-ff = { version="^0.3.0", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions bls12_377/src/curves/g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl SWCurveConfig for Parameters {
const GENERATOR: G1SWAffine = G1SWAffine::new_unchecked(G1_GENERATOR_X, G1_GENERATOR_Y);

#[inline(always)]
fn mul_by_a(_: &Self::BaseField) -> Self::BaseField {
fn mul_by_a(_: Self::BaseField) -> Self::BaseField {
Self::BaseField::zero()
}
}
Expand Down Expand Up @@ -106,7 +106,7 @@ impl TECurveConfig for Parameters {

/// Multiplication by `a` is multiply by `-1`.
#[inline(always)]
fn mul_by_a(elem: &Self::BaseField) -> Self::BaseField {
fn mul_by_a(elem: Self::BaseField) -> Self::BaseField {
elem.neg()
}
}
Expand Down
2 changes: 1 addition & 1 deletion bls12_377/src/curves/g2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl SWCurveConfig for Parameters {
const GENERATOR: G2Affine = G2Affine::new_unchecked(G2_GENERATOR_X, G2_GENERATOR_Y);

#[inline(always)]
fn mul_by_a(_: &Self::BaseField) -> Self::BaseField {
fn mul_by_a(_: Self::BaseField) -> Self::BaseField {
Self::BaseField::zero()
}
}
Expand Down
2 changes: 1 addition & 1 deletion bls12_377/src/curves/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use ark_algebra_test_templates::{
generate_bilinearity_test, generate_g1_generator_raw_test, generate_g1_test, generate_g2_test,
msm::test_var_base_msm,
};
use ark_ec::{models::short_weierstrass::SWCurveConfig, AffineCurve, PairingEngine};
use ark_ec::{models::short_weierstrass::SWCurveConfig, AffineRepr, PairingEngine};
use ark_ff::{
fields::{Field, PrimeField},
One, Zero,
Expand Down
2 changes: 1 addition & 1 deletion bls12_381/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ keywords = ["cryptography", "finite-fields", "elliptic-curves" ]
categories = ["cryptography"]
include = ["Cargo.toml", "src", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
license = "MIT/Apache-2.0"
edition = "2018"
edition = "2021"

[dependencies]
ark-ff = { version="^0.3.0", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions bls12_381/src/curves/g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use ark_ec::{
bls12::Bls12Parameters,
models::CurveConfig,
short_weierstrass::{Affine, SWCurveConfig},
AffineCurve, ProjectiveCurve,
AffineRepr, Group,
};
use ark_ff::{Field, MontFp, Zero};
use ark_std::ops::Neg;
Expand Down Expand Up @@ -40,7 +40,7 @@ impl SWCurveConfig for Parameters {
const GENERATOR: G1Affine = G1Affine::new_unchecked(G1_GENERATOR_X, G1_GENERATOR_Y);

#[inline(always)]
fn mul_by_a(_: &Self::BaseField) -> Self::BaseField {
fn mul_by_a(_: Self::BaseField) -> Self::BaseField {
Self::BaseField::zero()
}

Expand Down
4 changes: 2 additions & 2 deletions bls12_381/src/curves/g2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use ark_ec::{
bls12::Bls12Parameters,
models::CurveConfig,
short_weierstrass::{Affine, SWCurveConfig},
AffineCurve,
AffineRepr,
};
use ark_ff::{Field, MontFp, Zero};

Expand Down Expand Up @@ -51,7 +51,7 @@ impl SWCurveConfig for Parameters {
const GENERATOR: G2Affine = G2Affine::new_unchecked(G2_GENERATOR_X, G2_GENERATOR_Y);

#[inline(always)]
fn mul_by_a(_: &Self::BaseField) -> Self::BaseField {
fn mul_by_a(_: Self::BaseField) -> Self::BaseField {
Self::BaseField::zero()
}

Expand Down
43 changes: 13 additions & 30 deletions bls12_381/src/curves/tests.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
use ark_algebra_test_templates::{
curves::*, generate_bilinearity_test, generate_g1_generator_raw_test, generate_g1_test,
generate_g2_test, msm::*,
};
use ark_ec::{
models::short_weierstrass::SWCurveConfig, AffineCurve, PairingEngine, ProjectiveCurve,
};
use ark_ff::{
fields::{Field, PrimeField},
One, UniformRand, Zero,
};
use ark_algebra_test_templates::*;
use ark_ec::{AffineRepr, CurveGroup};
use ark_ff::{fields::Field, One, UniformRand, Zero};
use ark_std::{rand::Rng, test_rng};
use core::ops::{AddAssign, MulAssign};

use crate::{g1, g2, Bls12_381, Fq, Fq12, Fq2, Fr, G1Affine, G1Projective, G2Affine, G2Projective};
use crate::{Bls12_381, Fq, Fq2, Fr, G1Affine, G1Projective, G2Affine, G2Projective};

generate_g1_test!(bls12_381; curve_tests; sw_tests;);
generate_g2_test!(bls12_381; curve_tests; sw_tests;);
generate_bilinearity_test!(Bls12_381, Fq12);
generate_g1_generator_raw_test!(bls12_381, 4);
test_group!(g1; G1Projective; sw);
test_group!(g2; G2Projective; sw);
test_group!(pairing_output; ark_ec::pairing::PairingOutput<Bls12_381>; msm);
test_pairing!(pairing; crate::Bls12_381);

#[test]
fn test_g1_endomorphism_beta() {
assert!(g1::BETA.pow(&[3u64]).is_one());
assert!(crate::g1::BETA.pow(&[3u64]).is_one());
}

#[test]
Expand All @@ -38,12 +29,8 @@ fn test_g1_subgroup_non_membership_via_endomorphism() {
let x = Fq::rand(&mut rng);
let greatest = rng.gen();

if let Some(p) = G1Affine::get_point_from_x(x, greatest) {
if !p
.into_projective()
.mul_bigint(Fr::characteristic())
.is_zero()
{
if let Some(p) = G1Affine::get_point_from_x_unchecked(x, greatest) {
if !p.mul_bigint(Fr::characteristic()).is_zero() {
assert!(!p.is_in_correct_subgroup_assuming_on_curve());
return;
}
Expand All @@ -65,12 +52,8 @@ fn test_g2_subgroup_non_membership_via_endomorphism() {
let x = Fq2::rand(&mut rng);
let greatest = rng.gen();

if let Some(p) = G2Affine::get_point_from_x(x, greatest) {
if !p
.into_projective()
.mul_bigint(Fr::characteristic())
.is_zero()
{
if let Some(p) = G2Affine::get_point_from_x_unchecked(x, greatest) {
if !p.mul_bigint(Fr::characteristic()).is_zero() {
assert!(!p.is_in_correct_subgroup_assuming_on_curve());
return;
}
Expand Down
17 changes: 8 additions & 9 deletions bls12_381/src/fields/tests.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
use ark_algebra_test_templates::{
fields::*, generate_field_serialization_test, generate_field_test,
};
use ark_algebra_test_templates::*;
use ark_ff::{
biginteger::{BigInt, BigInteger, BigInteger384},
fields::{FftField, Field, Fp12Config, Fp2Config, Fp6Config, PrimeField},
One, UniformRand, Zero,
};
use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize};
use ark_std::{
cmp::Ordering,
ops::{AddAssign, MulAssign, SubAssign},
rand::Rng,
test_rng, vec,
vec,
};

use crate::{Fq, Fq12, Fq12Config, Fq2, Fq2Config, Fq6, Fq6Config, FqConfig, Fr, FrConfig};
use crate::{Fq, Fq12, Fq12Config, Fq2, Fq2Config, Fq6, Fq6Config, Fr};

generate_field_test!(bls12_381; fq2; fq6; fq12; mont(6, 4); );
generate_field_serialization_test!(bls12_381; fq2; fq6; fq12;);
test_field!(fr; Fr; mont_prime_field);
test_field!(fq; Fq; mont_prime_field);
test_field!(fq2; Fq2);
test_field!(fq6; Fq6);
test_field!(fq12; Fq12);

#[test]
fn test_negative_one() {
Expand Down
2 changes: 1 addition & 1 deletion bn254/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ keywords = ["cryptography", "finite-fields", "elliptic-curves" ]
categories = ["cryptography"]
include = ["Cargo.toml", "src", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
license = "MIT/Apache-2.0"
edition = "2018"
edition = "2021"

[dependencies]
ark-ff = { version="^0.3.0", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion bn254/src/curves/g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl SWCurveConfig for Parameters {
const GENERATOR: G1Affine = G1Affine::new_unchecked(G1_GENERATOR_X, G1_GENERATOR_Y);

#[inline(always)]
fn mul_by_a(_: &Self::BaseField) -> Self::BaseField {
fn mul_by_a(_: Self::BaseField) -> Self::BaseField {
Self::BaseField::zero()
}
}
Expand Down
2 changes: 1 addition & 1 deletion bn254/src/curves/g2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl SWCurveConfig for Parameters {
const GENERATOR: G2Affine = G2Affine::new_unchecked(G2_GENERATOR_X, G2_GENERATOR_Y);

#[inline(always)]
fn mul_by_a(_: &Self::BaseField) -> Self::BaseField {
fn mul_by_a(_: Self::BaseField) -> Self::BaseField {
Self::BaseField::zero()
}
}
Expand Down
21 changes: 7 additions & 14 deletions bn254/src/curves/tests.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
use ark_algebra_test_templates::{
curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, msm::*,
};
use ark_ec::{AffineCurve, PairingEngine};
use ark_ff::{
fields::{Field, PrimeField},
One,
};
use ark_std::{rand::Rng, test_rng};
use core::ops::MulAssign;
use ark_algebra_test_templates::*;
use ark_ff::fields::Field;

use crate::{g1, g2, Bn254, Fq12, Fr, G1Affine, G1Projective, G2Affine, G2Projective};
use crate::{Bn254, G1Projective, G2Projective};

generate_g1_test!(bn254; curve_tests; sw_tests;);
generate_g2_test!(bn254; curve_tests; sw_tests;);
generate_bilinearity_test!(Bn254, Fq12);
test_group!(g1; G1Projective; sw);
test_group!(g2; G2Projective; sw);
test_group!(pairing_output; ark_ec::pairing::PairingOutput<Bn254>; msm);
test_pairing!(pairing; crate::Bn254);
19 changes: 9 additions & 10 deletions bn254/src/fields/tests.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
use ark_algebra_test_templates::{
fields::*, generate_field_serialization_test, generate_field_test,
};
use ark_algebra_test_templates::*;
use ark_ff::{
biginteger::{BigInt, BigInteger, BigInteger256},
fields::{FftField, Field, Fp6Config, PrimeField},
One, UniformRand, Zero,
};
use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize};
use ark_std::{rand::Rng, test_rng};
use core::{
use ark_std::{
cmp::Ordering,
ops::{AddAssign, MulAssign, SubAssign},
ops::{AddAssign, MulAssign},
};

use crate::{Fq, Fq12, Fq2, Fq6, Fq6Config, FqConfig, Fr, FrConfig};
use crate::{Fq, Fq12, Fq2, Fq6, Fq6Config, Fr};

generate_field_test!(bn254; fq2; fq6; fq12; mont(4, 4); );
generate_field_serialization_test!(bn254; fq2; fq6; fq12;);
test_field!(fr; Fr; mont_prime_field);
test_field!(fq; Fq; mont_prime_field);
test_field!(fq2; Fq2);
test_field!(fq6; Fq6);
test_field!(fq12; Fq12);

#[test]
fn test_fq_repr_from() {
Expand Down
2 changes: 1 addition & 1 deletion bw6_761/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ keywords = ["cryptography", "finite-fields", "elliptic-curves" ]
categories = ["cryptography"]
include = ["Cargo.toml", "src", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
license = "MIT/Apache-2.0"
edition = "2018"
edition = "2021"

[dependencies]
ark-ff = { version="^0.3.0", default-features = false }
Expand Down
1 change: 1 addition & 0 deletions bw6_761/LICENSE-APACHE
1 change: 1 addition & 0 deletions bw6_761/LICENSE-MIT
2 changes: 1 addition & 1 deletion bw6_761/src/curves/g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl SWCurveConfig for Parameters {
/// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y)
const GENERATOR: G1Affine = G1Affine::new_unchecked(G1_GENERATOR_X, G1_GENERATOR_Y);
#[inline(always)]
fn mul_by_a(_elem: &Self::BaseField) -> Self::BaseField {
fn mul_by_a(_elem: Self::BaseField) -> Self::BaseField {
use ark_ff::Zero;
Self::BaseField::zero()
}
Expand Down
2 changes: 1 addition & 1 deletion bw6_761/src/curves/g2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl SWCurveConfig for Parameters {
const GENERATOR: G2Affine = G2Affine::new_unchecked(G2_GENERATOR_X, G2_GENERATOR_Y);

#[inline(always)]
fn mul_by_a(_elem: &Self::BaseField) -> Self::BaseField {
fn mul_by_a(_elem: Self::BaseField) -> Self::BaseField {
use ark_ff::Zero;
Self::BaseField::zero()
}
Expand Down
17 changes: 6 additions & 11 deletions bw6_761/src/curves/tests.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
use ark_algebra_test_templates::{
curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, msm::*,
};
use ark_ec::{AffineCurve, PairingEngine};
use ark_ff::{Field, One, PrimeField};
use ark_std::{rand::Rng, test_rng};
use core::ops::MulAssign;

use crate::*;
use ark_algebra_test_templates::*;
use ark_ff::Field;

generate_g1_test!(bw6_761; curve_tests; sw_tests;);
generate_g2_test!(bw6_761; curve_tests; sw_tests;);
generate_bilinearity_test!(BW6_761, Fq6);
test_group!(g1; G1Projective; sw);
test_group!(g2; G2Projective; sw);
test_group!(pairing_output; ark_ec::pairing::PairingOutput<BW6_761>; msm);
test_pairing!(pairing; crate::BW6_761);
15 changes: 5 additions & 10 deletions bw6_761/src/fields/tests.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
use ark_algebra_test_templates::{
fields::*, generate_field_serialization_test, generate_field_test,
};
use ark_ff::{Field, One, PrimeField, UniformRand, Zero};
use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize};
use ark_std::{rand::Rng, test_rng};
use core::ops::{AddAssign, MulAssign, SubAssign};

use crate::*;
use ark_algebra_test_templates::*;

generate_field_test!(bw6_761; fq3; fq6_2_on_3; false; mont(12, 6); );
generate_field_serialization_test!(bw6_761;);
test_field!(fr; Fr; mont_prime_field);
test_field!(fq; Fq; mont_prime_field);
test_field!(fq3; Fq3);
test_field!(fq6; Fq6);
3 changes: 2 additions & 1 deletion cp6_782/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ keywords = ["cryptography", "finite-fields", "elliptic-curves" ]
categories = ["cryptography"]
include = ["Cargo.toml", "src", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
license = "MIT/Apache-2.0"
edition = "2018"
edition = "2021"

[dependencies]
ark-ff = { version = "^0.3.0", default-features = false }
ark-ec = { version = "^0.3.0", default-features = false }
ark-std = { version = "^0.3.0", default-features = false }
ark-bls12-377 = { version = "^0.3.0", path = "../bls12_377", default-features = false, features = [ "base_field" ] }
itertools = { version = "0.10", default-features = false }

[dev-dependencies]
ark-serialize = { version = "^0.3.0", default-features = false }
Expand Down
1 change: 1 addition & 0 deletions cp6_782/LICENSE-APACHE
1 change: 1 addition & 0 deletions cp6_782/LICENSE-MIT
Loading

0 comments on commit 3c4c67f

Please sign in to comment.