From 3c4c67f114e77f496267bcc474caeb137880e46d Mon Sep 17 00:00:00 2001 From: Weikeng Chen Date: Fri, 2 Sep 2022 16:31:58 -0700 Subject: [PATCH] Sync with the recent changes in ark-algebra on pairing and testing (#116) * 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 Co-authored-by: Pratyush Mishra --- Cargo.toml | 3 +- bls12_377/Cargo.toml | 2 +- bls12_377/src/curves/g1.rs | 4 +- bls12_377/src/curves/g2.rs | 2 +- bls12_377/src/curves/tests.rs | 2 +- bls12_381/Cargo.toml | 2 +- bls12_381/src/curves/g1.rs | 4 +- bls12_381/src/curves/g2.rs | 4 +- bls12_381/src/curves/tests.rs | 43 +- bls12_381/src/fields/tests.rs | 17 +- bn254/Cargo.toml | 2 +- bn254/src/curves/g1.rs | 2 +- bn254/src/curves/g2.rs | 2 +- bn254/src/curves/tests.rs | 21 +- bn254/src/fields/tests.rs | 19 +- bw6_761/Cargo.toml | 2 +- bw6_761/LICENSE-APACHE | 1 + bw6_761/LICENSE-MIT | 1 + bw6_761/src/curves/g1.rs | 2 +- bw6_761/src/curves/g2.rs | 2 +- bw6_761/src/curves/tests.rs | 17 +- bw6_761/src/fields/tests.rs | 15 +- cp6_782/Cargo.toml | 3 +- cp6_782/LICENSE-APACHE | 1 + cp6_782/LICENSE-MIT | 1 + cp6_782/src/curves/g1.rs | 40 ++ cp6_782/src/curves/g2.rs | 40 ++ cp6_782/src/curves/mod.rs | 57 +-- cp6_782/src/curves/tests.rs | 16 +- cp6_782/src/fields/tests.rs | 15 +- curve-benches/Cargo.toml | 8 +- curve-benches/benches/bls12_377.rs | 5 +- curve-benches/benches/bls12_381.rs | 5 +- curve-benches/benches/bn254.rs | 7 +- curve-benches/benches/bw6_761.rs | 7 +- curve-benches/benches/cp6_782.rs | 8 +- curve-benches/benches/ed_on_bls12_381.rs | 4 +- curve-benches/benches/mnt4_298.rs | 7 +- curve-benches/benches/mnt4_753.rs | 7 +- curve-benches/benches/mnt6_298.rs | 7 +- curve-benches/benches/mnt6_753.rs | 7 +- curve-benches/benches/pallas.rs | 4 +- curve-benches/benches/vesta.rs | 4 +- curve-benches/build.rs | 9 - curve-benches/src/lib.rs | 8 - curve-benches/src/macros/ec.rs | 258 ---------- curve-benches/src/macros/field.rs | 455 ------------------ curve-benches/src/macros/mod.rs | 11 - curve-benches/src/macros/pairing.rs | 72 --- curve-benches/src/macros/utils.rs | 36 -- curve-constraint-tests/Cargo.toml | 2 +- curve-constraint-tests/LICENSE-APACHE | 1 + curve-constraint-tests/LICENSE-MIT | 1 + ed_on_bls12_377/Cargo.toml | 2 +- ed_on_bls12_377/LICENSE-APACHE | 1 + ed_on_bls12_377/LICENSE-MIT | 1 + ed_on_bls12_377/src/curves/mod.rs | 4 +- ed_on_bls12_377/src/curves/tests.rs | 2 +- ed_on_bls12_381/Cargo.toml | 2 +- ed_on_bls12_381/LICENSE-APACHE | 1 + ed_on_bls12_381/LICENSE-MIT | 1 + ed_on_bls12_381/src/curves/mod.rs | 6 +- ed_on_bls12_381/src/curves/tests.rs | 2 +- ed_on_bls12_381_bandersnatch/Cargo.toml | 2 +- ed_on_bls12_381_bandersnatch/LICENSE-APACHE | 1 + ed_on_bls12_381_bandersnatch/LICENSE-MIT | 1 + .../src/curves/mod.rs | 5 +- .../src/curves/tests.rs | 2 +- ed_on_bn254/Cargo.toml | 2 +- ed_on_bn254/LICENSE-APACHE | 1 + ed_on_bn254/LICENSE-MIT | 1 + ed_on_bn254/src/curves/mod.rs | 4 +- ed_on_bn254/src/curves/tests.rs | 2 +- ed_on_bw6_761/Cargo.toml | 2 +- ed_on_bw6_761/LICENSE-APACHE | 1 + ed_on_bw6_761/LICENSE-MIT | 1 + ed_on_cp6_782/Cargo.toml | 2 +- ed_on_cp6_782/LICENSE-APACHE | 1 + ed_on_cp6_782/LICENSE-MIT | 1 + ed_on_cp6_782/src/curves/mod.rs | 4 +- ed_on_cp6_782/src/curves/tests.rs | 2 +- ed_on_mnt4_298/Cargo.toml | 2 +- ed_on_mnt4_298/LICENSE-APACHE | 1 + ed_on_mnt4_298/LICENSE-MIT | 1 + ed_on_mnt4_298/src/curves/mod.rs | 4 +- ed_on_mnt4_298/src/curves/tests.rs | 2 +- ed_on_mnt4_753/Cargo.toml | 2 +- ed_on_mnt4_753/LICENSE-APACHE | 1 + ed_on_mnt4_753/LICENSE-MIT | 1 + ed_on_mnt4_753/src/curves/mod.rs | 4 +- ed_on_mnt4_753/src/curves/tests.rs | 2 +- mnt4_298/Cargo.toml | 2 +- mnt4_298/src/curves/g2.rs | 2 +- mnt4_298/src/curves/tests.rs | 2 +- mnt4_753/Cargo.toml | 2 +- mnt4_753/src/curves/g2.rs | 2 +- mnt4_753/src/curves/tests.rs | 2 +- mnt6_298/LICENSE-APACHE | 1 + mnt6_298/LICENSE-MIT | 1 + mnt6_298/src/curves/g2.rs | 2 +- mnt6_298/src/curves/tests.rs | 2 +- mnt6_753/LICENSE-APACHE | 1 + mnt6_753/LICENSE-MIT | 1 + mnt6_753/src/curves/g2.rs | 2 +- mnt6_753/src/curves/tests.rs | 2 +- pallas/LICENSE-APACHE | 1 + pallas/LICENSE-MIT | 1 + pallas/src/curves/mod.rs | 2 +- pallas/src/curves/tests.rs | 2 +- vesta/LICENSE-APACHE | 1 + vesta/LICENSE-MIT | 1 + vesta/src/curves/mod.rs | 2 +- vesta/src/curves/tests.rs | 2 +- 113 files changed, 313 insertions(+), 1075 deletions(-) create mode 120000 bw6_761/LICENSE-APACHE create mode 120000 bw6_761/LICENSE-MIT create mode 120000 cp6_782/LICENSE-APACHE create mode 120000 cp6_782/LICENSE-MIT delete mode 100644 curve-benches/build.rs delete mode 100644 curve-benches/src/lib.rs delete mode 100644 curve-benches/src/macros/ec.rs delete mode 100644 curve-benches/src/macros/field.rs delete mode 100644 curve-benches/src/macros/mod.rs delete mode 100644 curve-benches/src/macros/pairing.rs delete mode 100644 curve-benches/src/macros/utils.rs create mode 120000 curve-constraint-tests/LICENSE-APACHE create mode 120000 curve-constraint-tests/LICENSE-MIT create mode 120000 ed_on_bls12_377/LICENSE-APACHE create mode 120000 ed_on_bls12_377/LICENSE-MIT create mode 120000 ed_on_bls12_381/LICENSE-APACHE create mode 120000 ed_on_bls12_381/LICENSE-MIT create mode 120000 ed_on_bls12_381_bandersnatch/LICENSE-APACHE create mode 120000 ed_on_bls12_381_bandersnatch/LICENSE-MIT create mode 120000 ed_on_bn254/LICENSE-APACHE create mode 120000 ed_on_bn254/LICENSE-MIT create mode 120000 ed_on_bw6_761/LICENSE-APACHE create mode 120000 ed_on_bw6_761/LICENSE-MIT create mode 120000 ed_on_cp6_782/LICENSE-APACHE create mode 120000 ed_on_cp6_782/LICENSE-MIT create mode 120000 ed_on_mnt4_298/LICENSE-APACHE create mode 120000 ed_on_mnt4_298/LICENSE-MIT create mode 120000 ed_on_mnt4_753/LICENSE-APACHE create mode 120000 ed_on_mnt4_753/LICENSE-MIT create mode 120000 mnt6_298/LICENSE-APACHE create mode 120000 mnt6_298/LICENSE-MIT create mode 120000 mnt6_753/LICENSE-APACHE create mode 120000 mnt6_753/LICENSE-MIT create mode 120000 pallas/LICENSE-APACHE create mode 120000 pallas/LICENSE-MIT create mode 120000 vesta/LICENSE-APACHE create mode 120000 vesta/LICENSE-MIT diff --git a/Cargo.toml b/Cargo.toml index 1a082be..8a2ec70 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" } \ No newline at end of file diff --git a/bls12_377/Cargo.toml b/bls12_377/Cargo.toml index 63ac9fa..76b737d 100644 --- a/bls12_377/Cargo.toml +++ b/bls12_377/Cargo.toml @@ -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 } diff --git a/bls12_377/src/curves/g1.rs b/bls12_377/src/curves/g1.rs index 6b8051f..57e6192 100644 --- a/bls12_377/src/curves/g1.rs +++ b/bls12_377/src/curves/g1.rs @@ -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() } } @@ -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() } } diff --git a/bls12_377/src/curves/g2.rs b/bls12_377/src/curves/g2.rs index c84ab24..fadf608 100644 --- a/bls12_377/src/curves/g2.rs +++ b/bls12_377/src/curves/g2.rs @@ -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() } } diff --git a/bls12_377/src/curves/tests.rs b/bls12_377/src/curves/tests.rs index a000bd2..cfa277f 100755 --- a/bls12_377/src/curves/tests.rs +++ b/bls12_377/src/curves/tests.rs @@ -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, diff --git a/bls12_381/Cargo.toml b/bls12_381/Cargo.toml index eca364c..da69275 100644 --- a/bls12_381/Cargo.toml +++ b/bls12_381/Cargo.toml @@ -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 } diff --git a/bls12_381/src/curves/g1.rs b/bls12_381/src/curves/g1.rs index 721d0e5..8f2e1b4 100644 --- a/bls12_381/src/curves/g1.rs +++ b/bls12_381/src/curves/g1.rs @@ -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; @@ -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() } diff --git a/bls12_381/src/curves/g2.rs b/bls12_381/src/curves/g2.rs index d94458d..a3c7db7 100644 --- a/bls12_381/src/curves/g2.rs +++ b/bls12_381/src/curves/g2.rs @@ -3,7 +3,7 @@ use ark_ec::{ bls12::Bls12Parameters, models::CurveConfig, short_weierstrass::{Affine, SWCurveConfig}, - AffineCurve, + AffineRepr, }; use ark_ff::{Field, MontFp, Zero}; @@ -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() } diff --git a/bls12_381/src/curves/tests.rs b/bls12_381/src/curves/tests.rs index cfba3d2..a74f19c 100755 --- a/bls12_381/src/curves/tests.rs +++ b/bls12_381/src/curves/tests.rs @@ -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; 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] @@ -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; } @@ -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; } diff --git a/bls12_381/src/fields/tests.rs b/bls12_381/src/fields/tests.rs index 1891e63..ddeb3bd 100644 --- a/bls12_381/src/fields/tests.rs +++ b/bls12_381/src/fields/tests.rs @@ -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() { diff --git a/bn254/Cargo.toml b/bn254/Cargo.toml index 9f23ed8..d1450a8 100644 --- a/bn254/Cargo.toml +++ b/bn254/Cargo.toml @@ -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 } diff --git a/bn254/src/curves/g1.rs b/bn254/src/curves/g1.rs index 56fefff..6b55614 100644 --- a/bn254/src/curves/g1.rs +++ b/bn254/src/curves/g1.rs @@ -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() } } diff --git a/bn254/src/curves/g2.rs b/bn254/src/curves/g2.rs index f4ef127..1a792d0 100644 --- a/bn254/src/curves/g2.rs +++ b/bn254/src/curves/g2.rs @@ -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() } } diff --git a/bn254/src/curves/tests.rs b/bn254/src/curves/tests.rs index 270d139..6e21e5e 100755 --- a/bn254/src/curves/tests.rs +++ b/bn254/src/curves/tests.rs @@ -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; msm); +test_pairing!(pairing; crate::Bn254); diff --git a/bn254/src/fields/tests.rs b/bn254/src/fields/tests.rs index b49e20c..56fb769 100644 --- a/bn254/src/fields/tests.rs +++ b/bn254/src/fields/tests.rs @@ -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() { diff --git a/bw6_761/Cargo.toml b/bw6_761/Cargo.toml index 36e5be4..f442370 100644 --- a/bw6_761/Cargo.toml +++ b/bw6_761/Cargo.toml @@ -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 } diff --git a/bw6_761/LICENSE-APACHE b/bw6_761/LICENSE-APACHE new file mode 120000 index 0000000..965b606 --- /dev/null +++ b/bw6_761/LICENSE-APACHE @@ -0,0 +1 @@ +../LICENSE-APACHE \ No newline at end of file diff --git a/bw6_761/LICENSE-MIT b/bw6_761/LICENSE-MIT new file mode 120000 index 0000000..76219eb --- /dev/null +++ b/bw6_761/LICENSE-MIT @@ -0,0 +1 @@ +../LICENSE-MIT \ No newline at end of file diff --git a/bw6_761/src/curves/g1.rs b/bw6_761/src/curves/g1.rs index 022a731..08ddc3c 100644 --- a/bw6_761/src/curves/g1.rs +++ b/bw6_761/src/curves/g1.rs @@ -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() } diff --git a/bw6_761/src/curves/g2.rs b/bw6_761/src/curves/g2.rs index 31a2334..a57b012 100644 --- a/bw6_761/src/curves/g2.rs +++ b/bw6_761/src/curves/g2.rs @@ -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() } diff --git a/bw6_761/src/curves/tests.rs b/bw6_761/src/curves/tests.rs index 34ec0c2..1a8d4ed 100644 --- a/bw6_761/src/curves/tests.rs +++ b/bw6_761/src/curves/tests.rs @@ -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; msm); +test_pairing!(pairing; crate::BW6_761); diff --git a/bw6_761/src/fields/tests.rs b/bw6_761/src/fields/tests.rs index e4a0cf1..d7b1853 100644 --- a/bw6_761/src/fields/tests.rs +++ b/bw6_761/src/fields/tests.rs @@ -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); diff --git a/cp6_782/Cargo.toml b/cp6_782/Cargo.toml index 2259173..9971616 100644 --- a/cp6_782/Cargo.toml +++ b/cp6_782/Cargo.toml @@ -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 } diff --git a/cp6_782/LICENSE-APACHE b/cp6_782/LICENSE-APACHE new file mode 120000 index 0000000..965b606 --- /dev/null +++ b/cp6_782/LICENSE-APACHE @@ -0,0 +1 @@ +../LICENSE-APACHE \ No newline at end of file diff --git a/cp6_782/LICENSE-MIT b/cp6_782/LICENSE-MIT new file mode 120000 index 0000000..76219eb --- /dev/null +++ b/cp6_782/LICENSE-MIT @@ -0,0 +1 @@ +../LICENSE-MIT \ No newline at end of file diff --git a/cp6_782/src/curves/g1.rs b/cp6_782/src/curves/g1.rs index caa1bea..83ecb11 100644 --- a/cp6_782/src/curves/g1.rs +++ b/cp6_782/src/curves/g1.rs @@ -1,6 +1,7 @@ use ark_ec::{ models::{short_weierstrass::SWCurveConfig, CurveConfig}, short_weierstrass::{Affine, Projective}, + AffineRepr, CurveGroup, }; use ark_ff::MontFp; @@ -9,6 +10,45 @@ use crate::{Fq, Fr}; pub type G1Affine = Affine; pub type G1Projective = Projective; +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct G1Prepared(pub G1Affine); + +impl From for G1Prepared { + fn from(other: G1Affine) -> Self { + G1Prepared(other) + } +} + +impl From for G1Prepared { + fn from(q: G1Projective) -> Self { + q.into_affine().into() + } +} + +impl<'a> From<&'a G1Affine> for G1Prepared { + fn from(other: &'a G1Affine) -> Self { + G1Prepared(*other) + } +} + +impl<'a> From<&'a G1Projective> for G1Prepared { + fn from(q: &'a G1Projective) -> Self { + q.into_affine().into() + } +} + +impl G1Prepared { + pub fn is_zero(&self) -> bool { + self.0.is_identity() + } +} + +impl Default for G1Prepared { + fn default() -> Self { + G1Prepared(G1Affine::generator()) + } +} + #[derive(Clone, Default, PartialEq, Eq)] pub struct Parameters; diff --git a/cp6_782/src/curves/g2.rs b/cp6_782/src/curves/g2.rs index d891540..1913ff1 100644 --- a/cp6_782/src/curves/g2.rs +++ b/cp6_782/src/curves/g2.rs @@ -1,6 +1,7 @@ use ark_ec::{ models::CurveConfig, short_weierstrass::{Affine, Projective, SWCurveConfig}, + AffineRepr, CurveGroup, }; use ark_ff::{Field, MontFp}; @@ -9,6 +10,45 @@ use crate::{Fq, Fq3, Fr}; pub type G2Affine = Affine; pub type G2Projective = Projective; +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct G2Prepared(pub G2Affine); + +impl From for G2Prepared { + fn from(other: G2Affine) -> Self { + G2Prepared(other) + } +} + +impl From for G2Prepared { + fn from(q: G2Projective) -> Self { + q.into_affine().into() + } +} + +impl<'a> From<&'a G2Affine> for G2Prepared { + fn from(other: &'a G2Affine) -> Self { + G2Prepared(*other) + } +} + +impl<'a> From<&'a G2Projective> for G2Prepared { + fn from(q: &'a G2Projective) -> Self { + q.into_affine().into() + } +} + +impl G2Prepared { + pub fn is_zero(&self) -> bool { + self.0.is_identity() + } +} + +impl Default for G2Prepared { + fn default() -> Self { + G2Prepared(G2Affine::generator()) + } +} + #[derive(Clone, Default, PartialEq, Eq)] pub struct Parameters; diff --git a/cp6_782/src/curves/mod.rs b/cp6_782/src/curves/mod.rs index 3a0b70d..8bf111e 100644 --- a/cp6_782/src/curves/mod.rs +++ b/cp6_782/src/curves/mod.rs @@ -1,17 +1,19 @@ -use ark_ec::{models::short_weierstrass::SWCurveConfig, PairingEngine}; +use ark_ec::pairing::{MillerLoopOutput, PairingOutput}; +use ark_ec::{models::short_weierstrass::SWCurveConfig, pairing::Pairing}; use ark_ff::{ biginteger::BigInteger832, fields::{BitIteratorBE, Field}, BigInt, CyclotomicMultSubgroup, One, }; +use itertools::Itertools; use crate::{Fq, Fq3, Fq6, Fr}; pub mod g1; -pub use self::g1::{G1Affine, G1Projective}; +pub use self::g1::{G1Affine, G1Prepared, G1Projective}; pub mod g2; -pub use self::g2::{G2Affine, G2Projective}; +pub use self::g2::{G2Affine, G2Prepared, G2Projective}; #[cfg(test)] mod tests; @@ -21,40 +23,39 @@ pub type GT = Fq6; #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub struct CP6_782; -impl PairingEngine for CP6_782 { - type Fr = Fr; - type G1Projective = G1Projective; +impl Pairing for CP6_782 { + type ScalarField = Fr; + type G1 = G1Projective; type G1Affine = G1Affine; - type G1Prepared = G1Affine; - type G2Projective = G2Projective; + type G1Prepared = G1Prepared; + type G2 = G2Projective; type G2Affine = G2Affine; - type G2Prepared = G2Affine; - type Fq = Fq; - type Fqe = Fq3; - type Fqk = Fq6; - - fn miller_loop<'a, I>(i: I) -> Self::Fqk - where - I: IntoIterator, - { - let mut result = Self::Fqk::one(); - for &(ref p, ref q) in i { - result *= &CP6_782::ate_miller_loop(p, q); - } - result + type G2Prepared = G2Prepared; + type TargetField = Fq6; + + fn multi_miller_loop( + a: impl IntoIterator>, + b: impl IntoIterator>, + ) -> MillerLoopOutput { + let mut result = Self::TargetField::one(); + a.into_iter().zip_eq(b).for_each(|(p, q)| { + let (p, q) = (p.into(), q.into()); + result *= &CP6_782::ate_miller_loop(&p, &q); + }); + + MillerLoopOutput(result) } - fn final_exponentiation(r: &Self::Fqk) -> Option { - Some(CP6_782::final_exponentiation(r)) + fn final_exponentiation(r: MillerLoopOutput) -> Option> { + Some(PairingOutput(CP6_782::final_exponentiation(&r.0))) } } impl CP6_782 { - pub fn ate_pairing(p: &G1Affine, q: &G2Affine) -> GT { - CP6_782::final_exponentiation(&CP6_782::ate_miller_loop(p, q)) - } + fn ate_miller_loop(p: &G1Prepared, q: &G2Prepared) -> Fq6 { + let p = p.0; + let q = q.0; - fn ate_miller_loop(p: &G1Affine, q: &G2Affine) -> Fq6 { let px = p.x; let py = p.y; let qx = q.x; diff --git a/cp6_782/src/curves/tests.rs b/cp6_782/src/curves/tests.rs index 791098a..aa3f59b 100644 --- a/cp6_782/src/curves/tests.rs +++ b/cp6_782/src/curves/tests.rs @@ -1,13 +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::{Field, One, PrimeField}; -use ark_std::{rand::Rng, test_rng}; -use core::ops::MulAssign; +use ark_algebra_test_templates::*; +use ark_ff::Field; use crate::*; -generate_g1_test!(cp6_782; curve_tests; sw_tests;); -generate_g2_test!(cp6_782; curve_tests; sw_tests;); -generate_bilinearity_test!(CP6_782, Fq6); +test_group!(g1; G1Projective; sw); +test_group!(g2; G2Projective; sw); +test_group!(pairing_output; ark_ec::pairing::PairingOutput; msm); +test_pairing!(pairing; crate::CP6_782); diff --git a/cp6_782/src/fields/tests.rs b/cp6_782/src/fields/tests.rs index b9e8970..d7b1853 100644 --- a/cp6_782/src/fields/tests.rs +++ b/cp6_782/src/fields/tests.rs @@ -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!(cp6_782; fq3; fq6_2_on_3; mont(13, 6); ); -generate_field_serialization_test!(cp6_782;); +test_field!(fr; Fr; mont_prime_field); +test_field!(fq; Fq; mont_prime_field); +test_field!(fq3; Fq3); +test_field!(fq6; Fq6); diff --git a/curve-benches/Cargo.toml b/curve-benches/Cargo.toml index 5bda0c9..2b17fc0 100644 --- a/curve-benches/Cargo.toml +++ b/curve-benches/Cargo.toml @@ -16,11 +16,10 @@ repository = "https://github.com/arkworks-rs/curves" documentation = "https://docs.rs/algebra/" keywords = ["cryptography", "finite-fields", "elliptic-curves", "pairing"] categories = ["cryptography"] -include = ["Cargo.toml", "src", "README.md", "LICENSE-APACHE", "LICENSE-MIT"] +include = ["Cargo.toml", "README.md", "LICENSE-APACHE", "LICENSE-MIT"] license = "MIT/Apache-2.0" -edition = "2018" +edition = "2021" publish = false -build = "build.rs" ################################# Dependencies ################################ @@ -32,6 +31,7 @@ ark-std = { version = "^0.3.0", default-features = false } ark-ec = { version = "^0.3.0", default-features = false } ark-ff = { version = "^0.3.0", default-features = false } ark-serialize = { version = "^0.3.0", default-features = false } +ark-algebra-bench-templates = { version = "^0.3.0", default-features = false } ark-mnt4-298 = { path = "../mnt4_298" } ark-mnt6-298 = { path = "../mnt6_298" } @@ -48,7 +48,7 @@ ark-vesta = { path = "../vesta" } [features] asm = [ "ark-ff/asm"] -parallel = [ "ark-ff/parallel", "ark-ec/parallel", ] +parallel = [ "ark-ff/parallel", "ark-ec/parallel" ] n_fold = [] [build-dependencies] diff --git a/curve-benches/benches/bls12_377.rs b/curve-benches/benches/bls12_377.rs index 49bc9f1..c75574b 100644 --- a/curve-benches/benches/bls12_377.rs +++ b/curve-benches/benches/bls12_377.rs @@ -1,11 +1,12 @@ -use ark_curve_benches::*; +use ark_algebra_bench_templates::*; use ark_std::ops::{AddAssign, MulAssign, SubAssign}; use ark_bls12_377::{ fq::Fq, fq2::Fq2, fr::Fr, Bls12_377, Fq12, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2, }; -use ark_ec::{PairingEngine, ProjectiveCurve}; +use ark_ec::bls12::{G1Prepared, G2Prepared}; +use ark_ec::{CurveGroup, Group}; use ark_ff::{ biginteger::{BigInteger256 as FrRepr, BigInteger384 as FqRepr}, BigInteger, Field, PrimeField, UniformRand, diff --git a/curve-benches/benches/bls12_381.rs b/curve-benches/benches/bls12_381.rs index 9090817..47f3b19 100644 --- a/curve-benches/benches/bls12_381.rs +++ b/curve-benches/benches/bls12_381.rs @@ -1,11 +1,12 @@ -use ark_curve_benches::*; +use ark_algebra_bench_templates::*; use ark_std::ops::{AddAssign, MulAssign, SubAssign}; use ark_bls12_381::{ fq::Fq, fq2::Fq2, fr::Fr, Bls12_381, Fq12, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2, }; -use ark_ec::{PairingEngine, ProjectiveCurve}; +use ark_ec::bls12::{G1Prepared, G2Prepared}; +use ark_ec::{CurveGroup, Group}; use ark_ff::{ biginteger::{BigInteger256 as FrRepr, BigInteger384 as FqRepr}, BigInteger, Field, PrimeField, UniformRand, diff --git a/curve-benches/benches/bn254.rs b/curve-benches/benches/bn254.rs index 1d6e2ca..cbab93c 100644 --- a/curve-benches/benches/bn254.rs +++ b/curve-benches/benches/bn254.rs @@ -1,11 +1,14 @@ -use ark_curve_benches::*; +use ark_algebra_bench_templates::*; use ark_std::ops::{AddAssign, MulAssign, SubAssign}; use ark_bn254::{ fq::Fq, fq2::Fq2, fr::Fr, Bn254, Fq12, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2, }; -use ark_ec::{PairingEngine, ProjectiveCurve}; +use ark_ec::{ + bn::{G1Prepared, G2Prepared}, + CurveGroup, Group, +}; use ark_ff::{biginteger::BigInteger256 as Repr, BigInteger, Field, PrimeField, UniformRand}; mod g1 { diff --git a/curve-benches/benches/bw6_761.rs b/curve-benches/benches/bw6_761.rs index 2e8dd42..fe2ed52 100644 --- a/curve-benches/benches/bw6_761.rs +++ b/curve-benches/benches/bw6_761.rs @@ -1,11 +1,14 @@ -use ark_curve_benches::*; +use ark_algebra_bench_templates::*; use ark_std::ops::{AddAssign, MulAssign, SubAssign}; use ark_bw6_761::{ fq::Fq, fq3::Fq3, fr::Fr, Fq6, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2, BW6_761, }; -use ark_ec::{PairingEngine, ProjectiveCurve}; +use ark_ec::{ + bw6::{G1Prepared, G2Prepared}, + CurveGroup, Group, +}; use ark_ff::{ biginteger::{BigInteger384 as FrRepr, BigInteger768 as FqRepr}, BigInteger, Field, PrimeField, UniformRand, diff --git a/curve-benches/benches/cp6_782.rs b/curve-benches/benches/cp6_782.rs index 58c7930..e733639 100644 --- a/curve-benches/benches/cp6_782.rs +++ b/curve-benches/benches/cp6_782.rs @@ -1,11 +1,11 @@ -use ark_curve_benches::*; +use ark_algebra_bench_templates::*; use ark_std::ops::{AddAssign, MulAssign, SubAssign}; use ark_cp6_782::{ - fq::Fq, fq3::Fq3, fr::Fr, Fq6, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2, - CP6_782, + fq::Fq, fq3::Fq3, fr::Fr, Fq6, G1Affine, G1Prepared, G1Projective as G1, G2Affine, G2Prepared, + G2Projective as G2, CP6_782, }; -use ark_ec::{PairingEngine, ProjectiveCurve}; +use ark_ec::{CurveGroup, Group}; use ark_ff::{ biginteger::{BigInteger384 as FrRepr, BigInteger832 as FqRepr}, BigInteger, Field, PrimeField, UniformRand, diff --git a/curve-benches/benches/ed_on_bls12_381.rs b/curve-benches/benches/ed_on_bls12_381.rs index e9b6893..0e1555f 100644 --- a/curve-benches/benches/ed_on_bls12_381.rs +++ b/curve-benches/benches/ed_on_bls12_381.rs @@ -1,7 +1,7 @@ -use ark_curve_benches::*; +use ark_algebra_bench_templates::*; use ark_std::ops::{AddAssign, MulAssign, SubAssign}; -use ark_ec::ProjectiveCurve; +use ark_ec::{CurveGroup, Group}; use ark_ed_on_bls12_381::{fq::Fq, fr::Fr, EdwardsAffine as GAffine, EdwardsProjective as G}; use ark_ff::{biginteger::BigInteger256 as Repr, BigInteger, Field, PrimeField, UniformRand}; diff --git a/curve-benches/benches/mnt4_298.rs b/curve-benches/benches/mnt4_298.rs index 31e71ef..5ff031e 100644 --- a/curve-benches/benches/mnt4_298.rs +++ b/curve-benches/benches/mnt4_298.rs @@ -1,7 +1,10 @@ -use ark_curve_benches::*; +use ark_algebra_bench_templates::*; use ark_std::ops::{AddAssign, MulAssign, SubAssign}; -use ark_ec::{PairingEngine, ProjectiveCurve}; +use ark_ec::{ + mnt4::{G1Prepared, G2Prepared}, + CurveGroup, Group, +}; use ark_ff::{biginteger::BigInteger320 as FqRepr, BigInteger, Field, PrimeField, UniformRand}; use ark_mnt4_298::{ fq::Fq, fq2::Fq2, fr::Fr, Fq4, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2, diff --git a/curve-benches/benches/mnt4_753.rs b/curve-benches/benches/mnt4_753.rs index 7bb384c..468d7b6 100644 --- a/curve-benches/benches/mnt4_753.rs +++ b/curve-benches/benches/mnt4_753.rs @@ -1,7 +1,10 @@ -use ark_curve_benches::*; +use ark_algebra_bench_templates::*; use ark_std::ops::{AddAssign, MulAssign, SubAssign}; -use ark_ec::{PairingEngine, ProjectiveCurve}; +use ark_ec::{ + mnt4::{G1Prepared, G2Prepared}, + CurveGroup, Group, +}; use ark_ff::{biginteger::BigInteger768 as FqRepr, BigInteger, Field, PrimeField, UniformRand}; use ark_mnt4_753::{ fq::Fq, fq2::Fq2, fr::Fr, Fq4, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2, diff --git a/curve-benches/benches/mnt6_298.rs b/curve-benches/benches/mnt6_298.rs index d1974bb..629ed6b 100644 --- a/curve-benches/benches/mnt6_298.rs +++ b/curve-benches/benches/mnt6_298.rs @@ -1,7 +1,10 @@ -use ark_curve_benches::*; +use ark_algebra_bench_templates::*; use ark_std::ops::{AddAssign, MulAssign, SubAssign}; -use ark_ec::{PairingEngine, ProjectiveCurve}; +use ark_ec::{ + mnt6::{G1Prepared, G2Prepared}, + CurveGroup, Group, +}; use ark_ff::{biginteger::BigInteger320 as FqRepr, BigInteger, Field, PrimeField, UniformRand}; use ark_mnt6_298::{ fq::Fq, fq3::Fq3, fr::Fr, Fq6, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2, diff --git a/curve-benches/benches/mnt6_753.rs b/curve-benches/benches/mnt6_753.rs index cf6034d..1ea318f 100644 --- a/curve-benches/benches/mnt6_753.rs +++ b/curve-benches/benches/mnt6_753.rs @@ -1,7 +1,10 @@ -use ark_curve_benches::*; +use ark_algebra_bench_templates::*; use ark_std::ops::{AddAssign, MulAssign, SubAssign}; -use ark_ec::{PairingEngine, ProjectiveCurve}; +use ark_ec::{ + mnt6::{G1Prepared, G2Prepared}, + CurveGroup, Group, +}; use ark_ff::{biginteger::BigInteger768 as FqRepr, BigInteger, Field, PrimeField, UniformRand}; use ark_mnt6_753::{ fq::Fq, fq3::Fq3, fr::Fr, Fq6, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2, diff --git a/curve-benches/benches/pallas.rs b/curve-benches/benches/pallas.rs index e8bec42..043f86f 100644 --- a/curve-benches/benches/pallas.rs +++ b/curve-benches/benches/pallas.rs @@ -1,7 +1,7 @@ -use ark_curve_benches::*; +use ark_algebra_bench_templates::*; use ark_std::ops::{AddAssign, MulAssign, SubAssign}; -use ark_ec::ProjectiveCurve; +use ark_ec::{CurveGroup, Group}; use ark_ff::{biginteger::BigInteger256 as Repr, BigInteger, Field, PrimeField, UniformRand}; use ark_pallas::{fq::Fq, fr::Fr, Affine as GAffine, Projective as G}; diff --git a/curve-benches/benches/vesta.rs b/curve-benches/benches/vesta.rs index 2044fe1..b6cc6c0 100644 --- a/curve-benches/benches/vesta.rs +++ b/curve-benches/benches/vesta.rs @@ -1,7 +1,7 @@ -use ark_curve_benches::*; +use ark_algebra_bench_templates::*; use ark_std::ops::{AddAssign, MulAssign, SubAssign}; -use ark_ec::ProjectiveCurve; +use ark_ec::{CurveGroup, Group}; use ark_ff::{biginteger::BigInteger256 as Repr, BigInteger, Field, PrimeField, UniformRand}; use ark_vesta::{fq::Fq, fr::Fr, Affine as GAffine, Projective as G}; diff --git a/curve-benches/build.rs b/curve-benches/build.rs deleted file mode 100644 index f71f6fb..0000000 --- a/curve-benches/build.rs +++ /dev/null @@ -1,9 +0,0 @@ -extern crate rustc_version; - -use rustc_version::{version_meta, Channel}; - -fn main() { - if version_meta().expect("nightly check failed").channel == Channel::Nightly { - println!("cargo:rustc-cfg=nightly"); - } -} diff --git a/curve-benches/src/lib.rs b/curve-benches/src/lib.rs deleted file mode 100644 index faa053b..0000000 --- a/curve-benches/src/lib.rs +++ /dev/null @@ -1,8 +0,0 @@ -#![allow(unused_macros, unused_imports)] -#[macro_use] -pub mod macros; -pub use macros::*; - -#[macro_use] -pub extern crate bencher; -pub use bencher::*; diff --git a/curve-benches/src/macros/ec.rs b/curve-benches/src/macros/ec.rs deleted file mode 100644 index 63a5230..0000000 --- a/curve-benches/src/macros/ec.rs +++ /dev/null @@ -1,258 +0,0 @@ -#[macro_export] -macro_rules! ec_bench { - ($projective:ty, $affine:ty) => { - fn rand(b: &mut $crate::bencher::Bencher) { - let mut rng = ark_std::test_rng(); - b.iter(|| <$projective>::rand(&mut rng)); - } - - fn mul_assign(b: &mut $crate::bencher::Bencher) { - const SAMPLES: usize = 1000; - - let mut rng = ark_std::test_rng(); - - let v: Vec<($projective, Fr)> = (0..SAMPLES) - .map(|_| (<$projective>::rand(&mut rng), Fr::rand(&mut rng))) - .collect(); - - let mut count = 0; - b.iter(|| { - let mut tmp = v[count].0; - tmp *= v[count].1; - count = (count + 1) % SAMPLES; - tmp - }); - } - - fn add_assign(b: &mut $crate::bencher::Bencher) { - const SAMPLES: usize = 1000; - - let mut rng = ark_std::test_rng(); - - let v: Vec<($projective, $projective)> = (0..SAMPLES) - .map(|_| (<$projective>::rand(&mut rng), <$projective>::rand(&mut rng))) - .collect(); - - let mut count = 0; - b.iter(|| { - let mut tmp = v[count].0; - n_fold!(tmp, v, add_assign, count); - count = (count + 1) % SAMPLES; - tmp - }); - } - - fn sub_assign(b: &mut $crate::bencher::Bencher) { - const SAMPLES: usize = 1000; - - let mut rng = ark_std::test_rng(); - - let v: Vec<($projective, $projective)> = (0..SAMPLES) - .map(|_| (<$projective>::rand(&mut rng), <$projective>::rand(&mut rng))) - .collect(); - - let mut count = 0; - b.iter(|| { - let mut tmp = v[count].0; - n_fold!(tmp, v, sub_assign, count); - count = (count + 1) % SAMPLES; - tmp - }); - } - - fn double(b: &mut $crate::bencher::Bencher) { - const SAMPLES: usize = 1000; - - let mut rng = ark_std::test_rng(); - - let v: Vec<$projective> = (0..SAMPLES) - .map(|_| <$projective>::rand(&mut rng)) - .collect(); - - let mut count = 0; - b.iter(|| { - let mut tmp = v[count]; - n_fold!(tmp, double_in_place); - count = (count + 1) % SAMPLES; - tmp - }); - } - - fn add_assign_mixed(b: &mut $crate::bencher::Bencher) { - const SAMPLES: usize = 1000; - - let mut rng = ark_std::test_rng(); - - let v: Vec<($projective, $affine)> = (0..SAMPLES) - .map(|_| { - ( - <$projective>::rand(&mut rng), - <$projective>::rand(&mut rng).into(), - ) - }) - .collect(); - - let mut count = 0; - b.iter(|| { - let mut tmp = v[count].0; - n_fold!(tmp, v, add_assign_mixed, count); - count = (count + 1) % SAMPLES; - tmp - }); - } - - fn deser(b: &mut $crate::bencher::Bencher) { - use ark_ec::ProjectiveCurve; - use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; - const SAMPLES: usize = 1000; - - let mut rng = ark_std::test_rng(); - - let mut num_bytes = 0; - let tmp = <$projective>::rand(&mut rng).into_affine(); - let v: Vec<_> = (0..SAMPLES) - .flat_map(|_| { - let mut bytes = Vec::with_capacity(1000); - tmp.serialize(&mut bytes).unwrap(); - num_bytes = bytes.len(); - bytes - }) - .collect(); - - let mut count = 0; - b.iter(|| { - count = (count + 1) % SAMPLES; - let index = count * num_bytes; - <$affine>::deserialize(&v[index..(index + num_bytes)]).unwrap() - }); - } - - fn ser(b: &mut $crate::bencher::Bencher) { - use ark_ec::ProjectiveCurve; - use ark_serialize::CanonicalSerialize; - const SAMPLES: usize = 1000; - - let mut rng = ark_std::test_rng(); - - let mut v: Vec<_> = (0..SAMPLES) - .map(|_| <$projective>::rand(&mut rng)) - .collect(); - let v = <$projective>::batch_normalization_into_affine(v.as_mut_slice()); - let mut bytes = Vec::with_capacity(1000); - - let mut count = 0; - b.iter(|| { - let tmp = v[count]; - count = (count + 1) % SAMPLES; - bytes.clear(); - tmp.serialize(&mut bytes) - }); - } - - fn deser_unchecked(b: &mut $crate::bencher::Bencher) { - use ark_ec::ProjectiveCurve; - use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; - const SAMPLES: usize = 1000; - - let mut rng = ark_std::test_rng(); - - let mut num_bytes = 0; - let tmp = <$projective>::rand(&mut rng).into_affine(); - let v: Vec<_> = (0..SAMPLES) - .flat_map(|_| { - let mut bytes = Vec::with_capacity(1000); - tmp.serialize_unchecked(&mut bytes).unwrap(); - num_bytes = bytes.len(); - bytes - }) - .collect(); - - let mut count = 0; - b.iter(|| { - count = (count + 1) % SAMPLES; - let index = count * num_bytes; - <$affine>::deserialize_unchecked(&v[index..(index + num_bytes)]).unwrap() - }); - } - - fn ser_unchecked(b: &mut $crate::bencher::Bencher) { - use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; - const SAMPLES: usize = 1000; - - let mut rng = ark_std::test_rng(); - - let mut v: Vec<_> = (0..SAMPLES) - .map(|_| <$projective>::rand(&mut rng)) - .collect(); - let v = <$projective>::batch_normalization_into_affine(v.as_mut_slice()); - let mut bytes = Vec::with_capacity(1000); - - let mut count = 0; - b.iter(|| { - let tmp = v[count]; - count = (count + 1) % SAMPLES; - bytes.clear(); - tmp.serialize_unchecked(&mut bytes) - }); - } - - fn deser_uncompressed(b: &mut $crate::bencher::Bencher) { - use ark_ec::ProjectiveCurve; - use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; - const SAMPLES: usize = 1000; - - let mut rng = ark_std::test_rng(); - - let mut num_bytes = 0; - let tmp = <$projective>::rand(&mut rng).into_affine(); - let v: Vec<_> = (0..SAMPLES) - .flat_map(|_| { - let mut bytes = Vec::with_capacity(1000); - tmp.serialize_uncompressed(&mut bytes).unwrap(); - num_bytes = bytes.len(); - bytes - }) - .collect(); - - let mut count = 0; - b.iter(|| { - count = (count + 1) % SAMPLES; - let index = count * num_bytes; - <$affine>::deserialize_uncompressed(&v[index..(index + num_bytes)]).unwrap() - }); - } - - fn msm_131072(b: &mut $crate::bencher::Bencher) { - use ark_ec::msm::VariableBaseMSM; - use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; - const SAMPLES: usize = 131072; - - let mut rng = ark_std::test_rng(); - - let g = <$projective>::rand(&mut rng).into_affine(); - let v: Vec<_> = (0..SAMPLES).map(|_| g).collect(); - let scalars: Vec<_> = (0..SAMPLES) - .map(|_| Fr::rand(&mut rng).into_bigint()) - .collect(); - b.bench_n(1, |b| { - b.iter(|| <$projective as VariableBaseMSM>::msm_bigint(&v, &scalars)); - }) - } - - $crate::benchmark_group!( - group_ops, - rand, - mul_assign, - add_assign, - sub_assign, - add_assign_mixed, - double, - ser, - deser, - ser_unchecked, - deser_unchecked, - deser_uncompressed, - msm_131072, - ); - }; -} diff --git a/curve-benches/src/macros/field.rs b/curve-benches/src/macros/field.rs deleted file mode 100644 index 23de5d7..0000000 --- a/curve-benches/src/macros/field.rs +++ /dev/null @@ -1,455 +0,0 @@ -#[macro_export] -macro_rules! f_bench { - // Use this for base fields - ($f:ident, $f_type:ty, $f_repr:ident, $f_repr_type:ty, $modname:ident) => { - pub mod $modname { - use super::*; - field_common!($f, $f_type); - sqrt!($f, $f_type); - prime_field!($f, $f_type, $f_repr, $f_repr_type); - $crate::benchmark_group!( - $modname, - // common stuff - add_assign, - sub_assign, - double, - negate, - mul_assign, - square, - inverse, - ser, - deser, - ser_unchecked, - deser_unchecked, - // sqrt field stuff - sqrt, - // prime field stuff - repr_add_nocarry, - repr_sub_noborrow, - repr_num_bits, - repr_mul2, - repr_div2, - into_repr, - from_repr, - ); - } - use $modname::$modname; - }; - // use this for intermediate fields - (extension, $f:ident, $f_type:ty, $modname:ident) => { - mod $modname { - use super::*; - field_common!($f, $f_type); - sqrt!($f, $f_type); - $crate::benchmark_group!( - $modname, - // common stuff - add_assign, - sub_assign, - double, - negate, - mul_assign, - square, - inverse, - ser, - deser, - ser_unchecked, - deser_unchecked, - // sqrt field stuff - sqrt, - ); - } - use $modname::$modname; - }; - // Use this for the full extension field Fqk - (target, $f:ident, $f_type:ty, $modname:ident) => { - mod $modname { - use super::*; - field_common!($f, $f_type); - $crate::benchmark_group!( - $modname, - // common stuff - add_assign, - sub_assign, - double, - negate, - mul_assign, - square, - inverse, - ser, - deser, - ser_unchecked, - deser_unchecked, - ); - } - use $modname::$modname; - }; -} - -#[macro_export] -macro_rules! field_common { - ($f:ident, $f_type:ty) => { - fn add_assign(b: &mut $crate::bencher::Bencher) { - const SAMPLES: usize = 1000; - - let mut rng = ark_std::test_rng(); - - let v: Vec<_> = (0..SAMPLES) - .map(|_| ($f::rand(&mut rng), $f::rand(&mut rng))) - .collect(); - - let mut count = 0; - b.iter(|| { - let mut tmp = v[count].0; - n_fold!(tmp, v, add_assign, count); - count = (count + 1) % SAMPLES; - tmp - }); - } - - fn sub_assign(b: &mut $crate::bencher::Bencher) { - const SAMPLES: usize = 1000; - - let mut rng = ark_std::test_rng(); - - let v: Vec<_> = (0..SAMPLES) - .map(|_| ($f::rand(&mut rng), $f::rand(&mut rng))) - .collect(); - - let mut count = 0; - b.iter(|| { - let mut tmp = v[count].0; - n_fold!(tmp, v, sub_assign, count); - count = (count + 1) % SAMPLES; - tmp - }); - } - - fn double(b: &mut $crate::bencher::Bencher) { - const SAMPLES: usize = 1000; - - let mut rng = ark_std::test_rng(); - - let v: Vec<$f_type> = (0..SAMPLES).map(|_| $f::rand(&mut rng)).collect(); - - let mut count = 0; - b.iter(|| { - let mut tmp = v[count]; - n_fold!(tmp, double_in_place); - count = (count + 1) % SAMPLES; - tmp - }); - } - - fn negate(b: &mut $crate::bencher::Bencher) { - const SAMPLES: usize = 1000; - - let mut rng = ark_std::test_rng(); - - let v: Vec<$f_type> = (0..SAMPLES).map(|_| $f::rand(&mut rng)).collect(); - - let mut count = 0; - b.iter(|| { - let mut tmp = v[count]; - tmp = -tmp; - count = (count + 1) % SAMPLES; - tmp - }); - } - - fn mul_assign(b: &mut $crate::bencher::Bencher) { - const SAMPLES: usize = 1000; - - let mut rng = ark_std::test_rng(); - - let v: Vec<_> = (0..SAMPLES) - .map(|_| ($f::rand(&mut rng), $f::rand(&mut rng))) - .collect(); - - let mut count = 0; - b.iter(|| { - let mut tmp = v[count].0; - n_fold!(tmp, v, mul_assign, count); - count = (count + 1) % SAMPLES; - tmp - }); - } - - fn square(b: &mut $crate::bencher::Bencher) { - const SAMPLES: usize = 1000; - - let mut rng = ark_std::test_rng(); - - let v: Vec<$f_type> = (0..SAMPLES).map(|_| $f::rand(&mut rng)).collect(); - - let mut count = 0; - b.iter(|| { - let mut tmp = v[count]; - n_fold!(tmp, square_in_place); - count = (count + 1) % SAMPLES; - tmp - }); - } - - fn inverse(b: &mut $crate::bencher::Bencher) { - const SAMPLES: usize = 1000; - - let mut rng = ark_std::test_rng(); - - let v: Vec<$f_type> = (0..SAMPLES).map(|_| $f::rand(&mut rng)).collect(); - - let mut count = 0; - b.iter(|| { - let tmp = v[count].inverse(); - count = (count + 1) % SAMPLES; - tmp - }); - } - - fn deser(b: &mut $crate::bencher::Bencher) { - use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; - const SAMPLES: usize = 1000; - - let mut rng = ark_std::test_rng(); - - let mut num_bytes = 0; - let v: Vec<_> = (0..SAMPLES) - .flat_map(|_| { - let mut bytes = Vec::with_capacity(1000); - let tmp = $f::rand(&mut rng); - tmp.serialize(&mut bytes).unwrap(); - num_bytes = bytes.len(); - bytes - }) - .collect(); - - let mut count = 0; - b.iter(|| { - count = (count + 1) % SAMPLES; - let index = count * num_bytes; - <$f_type>::deserialize(&v[index..(index + num_bytes)]).unwrap() - }); - } - - fn ser(b: &mut $crate::bencher::Bencher) { - use ark_serialize::CanonicalSerialize; - const SAMPLES: usize = 1000; - - let mut rng = ark_std::test_rng(); - - let v: Vec<$f_type> = (0..SAMPLES).map(|_| $f::rand(&mut rng)).collect(); - let mut bytes = Vec::with_capacity(1000); - - let mut count = 0; - b.iter(|| { - let tmp = v[count]; - count = (count + 1) % SAMPLES; - bytes.clear(); - tmp.serialize(&mut bytes) - }); - } - - fn deser_unchecked(b: &mut $crate::bencher::Bencher) { - use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; - const SAMPLES: usize = 1000; - - let mut rng = ark_std::test_rng(); - - let mut num_bytes = 0; - let v: Vec<_> = (0..SAMPLES) - .flat_map(|_| { - let mut bytes = Vec::with_capacity(1000); - let tmp = $f::rand(&mut rng); - tmp.serialize_unchecked(&mut bytes).unwrap(); - num_bytes = bytes.len(); - bytes - }) - .collect(); - - let mut count = 0; - b.iter(|| { - count = (count + 1) % SAMPLES; - let index = count * num_bytes; - <$f_type>::deserialize_unchecked(&v[index..(index + num_bytes)]).unwrap() - }); - } - - fn ser_unchecked(b: &mut $crate::bencher::Bencher) { - use ark_serialize::CanonicalSerialize; - const SAMPLES: usize = 1000; - - let mut rng = ark_std::test_rng(); - - let v: Vec<$f_type> = (0..SAMPLES).map(|_| $f::rand(&mut rng)).collect(); - let mut bytes = Vec::with_capacity(1000); - - let mut count = 0; - b.iter(|| { - let tmp = v[count]; - count = (count + 1) % SAMPLES; - bytes.clear(); - tmp.serialize_unchecked(&mut bytes) - }); - } - }; -} - -#[macro_export] -macro_rules! sqrt { - ($f:ident, $f_type:ty) => { - pub fn sqrt(b: &mut $crate::bencher::Bencher) { - const SAMPLES: usize = 1000; - - let mut rng = ark_std::test_rng(); - - let v: Vec<$f_type> = (0..SAMPLES) - .map(|_| { - let mut tmp = $f::rand(&mut rng); - tmp.square_in_place(); - tmp - }) - .collect(); - - let mut count = 0; - b.iter(|| { - count = (count + 1) % SAMPLES; - v[count].sqrt() - }); - } - }; -} - -#[macro_export] -macro_rules! prime_field { - ($f:ident, $f_type:ty, $f_repr:ident, $f_repr_type:ty) => { - fn repr_add_nocarry(b: &mut $crate::bencher::Bencher) { - const SAMPLES: usize = 1000; - - let mut rng = ark_std::test_rng(); - - let v: Vec<_> = (0..SAMPLES) - .map(|_| { - let mut tmp1 = $f_repr::rand(&mut rng); - let mut tmp2 = $f_repr::rand(&mut rng); - // Shave a few bits off to avoid overflow. - for _ in 0..3 { - tmp1.div2(); - tmp2.div2(); - } - (tmp1, tmp2) - }) - .collect(); - - let mut count = 0; - b.iter(|| { - let mut tmp = v[count].0; - n_fold!(tmp, v, add_with_carry, count); - count = (count + 1) % SAMPLES; - tmp - }); - } - - fn repr_sub_noborrow(b: &mut $crate::bencher::Bencher) { - const SAMPLES: usize = 1000; - - let mut rng = ark_std::test_rng(); - - let v: Vec<_> = (0..SAMPLES) - .map(|_| { - let tmp1 = $f_repr::rand(&mut rng); - let mut tmp2 = tmp1; - // Ensure tmp2 is smaller than tmp1. - for _ in 0..10 { - tmp2.div2(); - } - (tmp1, tmp2) - }) - .collect(); - - let mut count = 0; - b.iter(|| { - let mut tmp = v[count].0; - n_fold!(tmp, v, sub_with_borrow, count); - count = (count + 1) % SAMPLES; - tmp; - }); - } - - fn repr_num_bits(b: &mut $crate::bencher::Bencher) { - const SAMPLES: usize = 1000; - - let mut rng = ark_std::test_rng(); - - let v: Vec<$f_repr_type> = (0..SAMPLES).map(|_| $f_repr::rand(&mut rng)).collect(); - - let mut count = 0; - b.iter(|| { - let tmp = v[count].num_bits(); - count = (count + 1) % SAMPLES; - tmp; - }); - } - - fn repr_mul2(b: &mut $crate::bencher::Bencher) { - const SAMPLES: usize = 1000; - - let mut rng = ark_std::test_rng(); - - let v: Vec<$f_repr_type> = (0..SAMPLES).map(|_| $f_repr::rand(&mut rng)).collect(); - - let mut count = 0; - b.iter(|| { - let mut tmp = v[count]; - n_fold!(tmp, mul2); - count = (count + 1) % SAMPLES; - tmp; - }); - } - - fn repr_div2(b: &mut $crate::bencher::Bencher) { - const SAMPLES: usize = 1000; - - let mut rng = ark_std::test_rng(); - - let v: Vec<$f_repr_type> = (0..SAMPLES).map(|_| $f_repr::rand(&mut rng)).collect(); - - let mut count = 0; - b.iter(|| { - let mut tmp = v[count]; - n_fold!(tmp, div2); - count = (count + 1) % SAMPLES; - tmp; - }); - } - - fn into_repr(b: &mut $crate::bencher::Bencher) { - const SAMPLES: usize = 1000; - - let mut rng = ark_std::test_rng(); - - let v: Vec<$f_type> = (0..SAMPLES).map(|_| $f::rand(&mut rng)).collect(); - - let mut count = 0; - b.iter(|| { - count = (count + 1) % SAMPLES; - v[count].into_bigint(); - }); - } - - fn from_repr(b: &mut $crate::bencher::Bencher) { - const SAMPLES: usize = 1000; - - let mut rng = ark_std::test_rng(); - - let v: Vec<$f_repr_type> = (0..SAMPLES) - .map(|_| $f::rand(&mut rng).into_bigint()) - .collect(); - - let mut count = 0; - b.iter(|| { - count = (count + 1) % SAMPLES; - let _ = $f::from(v[count]); - }); - } - }; -} diff --git a/curve-benches/src/macros/mod.rs b/curve-benches/src/macros/mod.rs deleted file mode 100644 index 0785770..0000000 --- a/curve-benches/src/macros/mod.rs +++ /dev/null @@ -1,11 +0,0 @@ -#[macro_use] -mod utils; - -#[macro_use] -mod ec; - -#[macro_use] -mod field; - -#[macro_use] -mod pairing; diff --git a/curve-benches/src/macros/pairing.rs b/curve-benches/src/macros/pairing.rs deleted file mode 100644 index 5bd64e7..0000000 --- a/curve-benches/src/macros/pairing.rs +++ /dev/null @@ -1,72 +0,0 @@ -#[macro_export] -macro_rules! pairing_bench { - ($curve:ident, $pairing_field:ident) => { - fn miller_loop(b: &mut $crate::bencher::Bencher) { - const SAMPLES: usize = 1000; - - let mut rng = ark_std::test_rng(); - - let g1s = (0..SAMPLES).map(|_| G1::rand(&mut rng)).collect::>(); - let g2s = (0..SAMPLES).map(|_| G2::rand(&mut rng)).collect::>(); - let g1s = G1::batch_normalization_into_affine(&g1s); - let g2s = G2::batch_normalization_into_affine(&g2s); - let prepared = g1s - .into_iter() - .zip(g2s) - .map(|(g1, g2)| (g1.into(), g2.into())) - .collect::::G1Prepared, - <$curve as PairingEngine>::G2Prepared, - )>>(); - let mut count = 0; - b.iter(|| { - let tmp = - $curve::miller_loop(&[(prepared[count].0.clone(), prepared[count].1.clone())]); - count = (count + 1) % SAMPLES; - tmp - }); - } - - fn final_exponentiation(b: &mut $crate::bencher::Bencher) { - const SAMPLES: usize = 1000; - - let mut rng = ark_std::test_rng(); - - let v: Vec<_> = (0..SAMPLES) - .map(|_| { - ( - G1Affine::from(G1::rand(&mut rng)).into(), - G2Affine::from(G2::rand(&mut rng)).into(), - ) - }) - .map(|(p, q)| $curve::miller_loop(&[(p, q)])) - .collect(); - - let mut count = 0; - b.iter(|| { - let tmp = $curve::final_exponentiation(&v[count]); - count = (count + 1) % SAMPLES; - tmp - }); - } - - fn full_pairing(b: &mut $crate::bencher::Bencher) { - const SAMPLES: usize = 1000; - - let mut rng = ark_std::test_rng(); - - let v: Vec<(G1, G2)> = (0..SAMPLES) - .map(|_| (G1::rand(&mut rng), G2::rand(&mut rng))) - .collect(); - - let mut count = 0; - b.iter(|| { - let tmp = $curve::pairing(v[count].0, v[count].1); - count = (count + 1) % SAMPLES; - tmp - }); - } - - $crate::benchmark_group!(pairing, miller_loop, final_exponentiation, full_pairing,); - }; -} diff --git a/curve-benches/src/macros/utils.rs b/curve-benches/src/macros/utils.rs deleted file mode 100644 index 2968bca..0000000 --- a/curve-benches/src/macros/utils.rs +++ /dev/null @@ -1,36 +0,0 @@ -#[macro_export] -macro_rules! n_fold { - ($tmp:ident, $v:ident, $func:ident, $count:ident) => { - $tmp.$func(&$v[$count].1); - }; - - ($tmp:ident, $func:ident) => { - $tmp.$func(); - }; -} - -/// Defines a function called `$group_name` that returns the test description -/// values for the listed functions `$function`. -#[macro_export] -macro_rules! benchmark_group { - ($group_name:ident, $($function:path),+) => { - pub fn $group_name() -> ::std::vec::Vec<$crate::TestDescAndFn> { - use $crate::{TestDescAndFn, TestFn, TestDesc}; - use std::borrow::Cow; - let mut benches = ::std::vec::Vec::new(); - $( - benches.push(TestDescAndFn { - desc: TestDesc { - name: Cow::from(module_path!().to_string() + "::" + stringify!($function)), - ignore: false, - }, - testfn: TestFn::StaticBenchFn($function), - }); - )+ - benches - } - }; - ($group_name:ident, $($function:path,)+) => { - benchmark_group!($group_name, $($function),+); - }; -} diff --git a/curve-constraint-tests/Cargo.toml b/curve-constraint-tests/Cargo.toml index 801fd52..e43fce6 100644 --- a/curve-constraint-tests/Cargo.toml +++ b/curve-constraint-tests/Cargo.toml @@ -10,7 +10,7 @@ keywords = ["cryptography", "finite-fields", "elliptic-curves", "r1cs" ] categories = ["cryptography"] include = ["Cargo.toml", "src", "README.md", "LICENSE-APACHE", "LICENSE-MIT"] license = "MIT/Apache-2.0" -edition = "2018" +edition = "2021" [dependencies] ark-std = { version = "^0.3.0", default-features = false } diff --git a/curve-constraint-tests/LICENSE-APACHE b/curve-constraint-tests/LICENSE-APACHE new file mode 120000 index 0000000..965b606 --- /dev/null +++ b/curve-constraint-tests/LICENSE-APACHE @@ -0,0 +1 @@ +../LICENSE-APACHE \ No newline at end of file diff --git a/curve-constraint-tests/LICENSE-MIT b/curve-constraint-tests/LICENSE-MIT new file mode 120000 index 0000000..76219eb --- /dev/null +++ b/curve-constraint-tests/LICENSE-MIT @@ -0,0 +1 @@ +../LICENSE-MIT \ No newline at end of file diff --git a/ed_on_bls12_377/Cargo.toml b/ed_on_bls12_377/Cargo.toml index cdd52ff..0b6550e 100644 --- a/ed_on_bls12_377/Cargo.toml +++ b/ed_on_bls12_377/Cargo.toml @@ -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 } diff --git a/ed_on_bls12_377/LICENSE-APACHE b/ed_on_bls12_377/LICENSE-APACHE new file mode 120000 index 0000000..965b606 --- /dev/null +++ b/ed_on_bls12_377/LICENSE-APACHE @@ -0,0 +1 @@ +../LICENSE-APACHE \ No newline at end of file diff --git a/ed_on_bls12_377/LICENSE-MIT b/ed_on_bls12_377/LICENSE-MIT new file mode 120000 index 0000000..76219eb --- /dev/null +++ b/ed_on_bls12_377/LICENSE-MIT @@ -0,0 +1 @@ +../LICENSE-MIT \ No newline at end of file diff --git a/ed_on_bls12_377/src/curves/mod.rs b/ed_on_bls12_377/src/curves/mod.rs index f4caaa7..4aae1e1 100644 --- a/ed_on_bls12_377/src/curves/mod.rs +++ b/ed_on_bls12_377/src/curves/mod.rs @@ -43,8 +43,8 @@ impl TECurveConfig for EdwardsParameters { /// Multiplication by `a` is just negation. /// Is `a` 1 or -1? #[inline(always)] - fn mul_by_a(elem: &Self::BaseField) -> Self::BaseField { - -*elem + fn mul_by_a(elem: Self::BaseField) -> Self::BaseField { + -elem } } diff --git a/ed_on_bls12_377/src/curves/tests.rs b/ed_on_bls12_377/src/curves/tests.rs index 0222891..753ad4e 100644 --- a/ed_on_bls12_377/src/curves/tests.rs +++ b/ed_on_bls12_377/src/curves/tests.rs @@ -1,5 +1,5 @@ use ark_algebra_test_templates::curves::*; -use ark_ec::AffineCurve; +use ark_ec::AffineRepr; use crate::*; diff --git a/ed_on_bls12_381/Cargo.toml b/ed_on_bls12_381/Cargo.toml index f391662..d88b956 100644 --- a/ed_on_bls12_381/Cargo.toml +++ b/ed_on_bls12_381/Cargo.toml @@ -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 } diff --git a/ed_on_bls12_381/LICENSE-APACHE b/ed_on_bls12_381/LICENSE-APACHE new file mode 120000 index 0000000..965b606 --- /dev/null +++ b/ed_on_bls12_381/LICENSE-APACHE @@ -0,0 +1 @@ +../LICENSE-APACHE \ No newline at end of file diff --git a/ed_on_bls12_381/LICENSE-MIT b/ed_on_bls12_381/LICENSE-MIT new file mode 120000 index 0000000..76219eb --- /dev/null +++ b/ed_on_bls12_381/LICENSE-MIT @@ -0,0 +1 @@ +../LICENSE-MIT \ No newline at end of file diff --git a/ed_on_bls12_381/src/curves/mod.rs b/ed_on_bls12_381/src/curves/mod.rs index 7fd3657..893fee3 100644 --- a/ed_on_bls12_381/src/curves/mod.rs +++ b/ed_on_bls12_381/src/curves/mod.rs @@ -70,7 +70,7 @@ impl TECurveConfig for JubjubParameters { /// COEFF_A = -1 const COEFF_A: Fq = MontFp!("-1"); - /// COEFF_D = (10240/10241) mod q + /// COEFF_D = -(10240/10241) mod q const COEFF_D: Fq = MontFp!("19257038036680949359750312669786877991949435402254120286184196891950884077233"); @@ -81,8 +81,8 @@ impl TECurveConfig for JubjubParameters { /// Multiplication by `a` is simply negation here. #[inline(always)] - fn mul_by_a(elem: &Self::BaseField) -> Self::BaseField { - -(*elem) + fn mul_by_a(elem: Self::BaseField) -> Self::BaseField { + -elem } } diff --git a/ed_on_bls12_381/src/curves/tests.rs b/ed_on_bls12_381/src/curves/tests.rs index dd5473e..1b65ddb 100644 --- a/ed_on_bls12_381/src/curves/tests.rs +++ b/ed_on_bls12_381/src/curves/tests.rs @@ -1,5 +1,5 @@ use ark_algebra_test_templates::curves::*; -use ark_ec::{AffineCurve, ProjectiveCurve}; +use ark_ec::{AffineRepr, ProjectiveCurve}; use ark_ff::Zero; use ark_std::{ops::Mul, str::FromStr}; diff --git a/ed_on_bls12_381_bandersnatch/Cargo.toml b/ed_on_bls12_381_bandersnatch/Cargo.toml index 1f1092b..d864781 100644 --- a/ed_on_bls12_381_bandersnatch/Cargo.toml +++ b/ed_on_bls12_381_bandersnatch/Cargo.toml @@ -8,7 +8,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 } diff --git a/ed_on_bls12_381_bandersnatch/LICENSE-APACHE b/ed_on_bls12_381_bandersnatch/LICENSE-APACHE new file mode 120000 index 0000000..965b606 --- /dev/null +++ b/ed_on_bls12_381_bandersnatch/LICENSE-APACHE @@ -0,0 +1 @@ +../LICENSE-APACHE \ No newline at end of file diff --git a/ed_on_bls12_381_bandersnatch/LICENSE-MIT b/ed_on_bls12_381_bandersnatch/LICENSE-MIT new file mode 120000 index 0000000..76219eb --- /dev/null +++ b/ed_on_bls12_381_bandersnatch/LICENSE-MIT @@ -0,0 +1 @@ +../LICENSE-MIT \ No newline at end of file diff --git a/ed_on_bls12_381_bandersnatch/src/curves/mod.rs b/ed_on_bls12_381_bandersnatch/src/curves/mod.rs index 612934c..e21c665 100644 --- a/ed_on_bls12_381_bandersnatch/src/curves/mod.rs +++ b/ed_on_bls12_381_bandersnatch/src/curves/mod.rs @@ -83,9 +83,8 @@ impl TECurveConfig for BandersnatchParameters { /// Multiplication by `a` is multiply by `-5`. #[inline(always)] - fn mul_by_a(elem: &Self::BaseField) -> Self::BaseField { - let t = (*elem).double().double(); - -(t + *elem) + fn mul_by_a(elem: Self::BaseField) -> Self::BaseField { + elem.double().double() * elem } } diff --git a/ed_on_bls12_381_bandersnatch/src/curves/tests.rs b/ed_on_bls12_381_bandersnatch/src/curves/tests.rs index 626c3c4..dac40a7 100644 --- a/ed_on_bls12_381_bandersnatch/src/curves/tests.rs +++ b/ed_on_bls12_381_bandersnatch/src/curves/tests.rs @@ -1,5 +1,5 @@ use ark_algebra_test_templates::curves::*; -use ark_ec::{AffineCurve, ProjectiveCurve}; +use ark_ec::{AffineRepr, ProjectiveCurve}; use ark_ff::Zero; use ark_std::{ops::Mul, str::FromStr}; diff --git a/ed_on_bn254/Cargo.toml b/ed_on_bn254/Cargo.toml index ef69a38..f9f497d 100644 --- a/ed_on_bn254/Cargo.toml +++ b/ed_on_bn254/Cargo.toml @@ -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 } diff --git a/ed_on_bn254/LICENSE-APACHE b/ed_on_bn254/LICENSE-APACHE new file mode 120000 index 0000000..965b606 --- /dev/null +++ b/ed_on_bn254/LICENSE-APACHE @@ -0,0 +1 @@ +../LICENSE-APACHE \ No newline at end of file diff --git a/ed_on_bn254/LICENSE-MIT b/ed_on_bn254/LICENSE-MIT new file mode 120000 index 0000000..76219eb --- /dev/null +++ b/ed_on_bn254/LICENSE-MIT @@ -0,0 +1 @@ +../LICENSE-MIT \ No newline at end of file diff --git a/ed_on_bn254/src/curves/mod.rs b/ed_on_bn254/src/curves/mod.rs index 89a94ee..772f381 100644 --- a/ed_on_bn254/src/curves/mod.rs +++ b/ed_on_bn254/src/curves/mod.rs @@ -40,8 +40,8 @@ impl TECurveConfig for EdwardsParameters { const COEFF_A: Fq = Fq::ONE; #[inline(always)] - fn mul_by_a(elem: &Self::BaseField) -> Self::BaseField { - *elem + fn mul_by_a(elem: Self::BaseField) -> Self::BaseField { + elem } /// COEFF_D = 168696/168700 mod q diff --git a/ed_on_bn254/src/curves/tests.rs b/ed_on_bn254/src/curves/tests.rs index bebe212..f8c46e2 100644 --- a/ed_on_bn254/src/curves/tests.rs +++ b/ed_on_bn254/src/curves/tests.rs @@ -1,5 +1,5 @@ use ark_algebra_test_templates::curves::*; -use ark_ec::{AffineCurve, ProjectiveCurve}; +use ark_ec::{AffineRepr, ProjectiveCurve}; use ark_ff::Zero; use ark_std::{ops::Mul, str::FromStr}; diff --git a/ed_on_bw6_761/Cargo.toml b/ed_on_bw6_761/Cargo.toml index 32b6ca6..2f94372 100644 --- a/ed_on_bw6_761/Cargo.toml +++ b/ed_on_bw6_761/Cargo.toml @@ -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-ed-on-cp6-782 = { version = "^0.3.0", path = "../ed_on_cp6_782", default-features = false } diff --git a/ed_on_bw6_761/LICENSE-APACHE b/ed_on_bw6_761/LICENSE-APACHE new file mode 120000 index 0000000..965b606 --- /dev/null +++ b/ed_on_bw6_761/LICENSE-APACHE @@ -0,0 +1 @@ +../LICENSE-APACHE \ No newline at end of file diff --git a/ed_on_bw6_761/LICENSE-MIT b/ed_on_bw6_761/LICENSE-MIT new file mode 120000 index 0000000..76219eb --- /dev/null +++ b/ed_on_bw6_761/LICENSE-MIT @@ -0,0 +1 @@ +../LICENSE-MIT \ No newline at end of file diff --git a/ed_on_cp6_782/Cargo.toml b/ed_on_cp6_782/Cargo.toml index 537f2c9..0b160ab 100644 --- a/ed_on_cp6_782/Cargo.toml +++ b/ed_on_cp6_782/Cargo.toml @@ -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 } diff --git a/ed_on_cp6_782/LICENSE-APACHE b/ed_on_cp6_782/LICENSE-APACHE new file mode 120000 index 0000000..965b606 --- /dev/null +++ b/ed_on_cp6_782/LICENSE-APACHE @@ -0,0 +1 @@ +../LICENSE-APACHE \ No newline at end of file diff --git a/ed_on_cp6_782/LICENSE-MIT b/ed_on_cp6_782/LICENSE-MIT new file mode 120000 index 0000000..76219eb --- /dev/null +++ b/ed_on_cp6_782/LICENSE-MIT @@ -0,0 +1 @@ +../LICENSE-MIT \ No newline at end of file diff --git a/ed_on_cp6_782/src/curves/mod.rs b/ed_on_cp6_782/src/curves/mod.rs index 0955a25..875279a 100644 --- a/ed_on_cp6_782/src/curves/mod.rs +++ b/ed_on_cp6_782/src/curves/mod.rs @@ -41,8 +41,8 @@ impl TECurveConfig for EdwardsParameters { /// Multiplication by `a` is just negation. #[inline(always)] - fn mul_by_a(elem: &Self::BaseField) -> Self::BaseField { - -*elem + fn mul_by_a(elem: Self::BaseField) -> Self::BaseField { + -elem } } diff --git a/ed_on_cp6_782/src/curves/tests.rs b/ed_on_cp6_782/src/curves/tests.rs index 0222891..753ad4e 100644 --- a/ed_on_cp6_782/src/curves/tests.rs +++ b/ed_on_cp6_782/src/curves/tests.rs @@ -1,5 +1,5 @@ use ark_algebra_test_templates::curves::*; -use ark_ec::AffineCurve; +use ark_ec::AffineRepr; use crate::*; diff --git a/ed_on_mnt4_298/Cargo.toml b/ed_on_mnt4_298/Cargo.toml index f8eb332..fb62bae 100644 --- a/ed_on_mnt4_298/Cargo.toml +++ b/ed_on_mnt4_298/Cargo.toml @@ -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 } diff --git a/ed_on_mnt4_298/LICENSE-APACHE b/ed_on_mnt4_298/LICENSE-APACHE new file mode 120000 index 0000000..965b606 --- /dev/null +++ b/ed_on_mnt4_298/LICENSE-APACHE @@ -0,0 +1 @@ +../LICENSE-APACHE \ No newline at end of file diff --git a/ed_on_mnt4_298/LICENSE-MIT b/ed_on_mnt4_298/LICENSE-MIT new file mode 120000 index 0000000..76219eb --- /dev/null +++ b/ed_on_mnt4_298/LICENSE-MIT @@ -0,0 +1 @@ +../LICENSE-MIT \ No newline at end of file diff --git a/ed_on_mnt4_298/src/curves/mod.rs b/ed_on_mnt4_298/src/curves/mod.rs index 293ddb6..db791da 100644 --- a/ed_on_mnt4_298/src/curves/mod.rs +++ b/ed_on_mnt4_298/src/curves/mod.rs @@ -54,8 +54,8 @@ impl TECurveConfig for EdwardsParameters { /// Multiplication by `a` is just negation. #[inline(always)] - fn mul_by_a(elem: &Self::BaseField) -> Self::BaseField { - -*elem + fn mul_by_a(elem: Self::BaseField) -> Self::BaseField { + -elem } } diff --git a/ed_on_mnt4_298/src/curves/tests.rs b/ed_on_mnt4_298/src/curves/tests.rs index bcc49a6..4db121c 100644 --- a/ed_on_mnt4_298/src/curves/tests.rs +++ b/ed_on_mnt4_298/src/curves/tests.rs @@ -1,5 +1,5 @@ use ark_algebra_test_templates::curves::*; -use ark_ec::AffineCurve; +use ark_ec::AffineRepr; use crate::*; diff --git a/ed_on_mnt4_753/Cargo.toml b/ed_on_mnt4_753/Cargo.toml index 672189b..f57c056 100644 --- a/ed_on_mnt4_753/Cargo.toml +++ b/ed_on_mnt4_753/Cargo.toml @@ -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 } diff --git a/ed_on_mnt4_753/LICENSE-APACHE b/ed_on_mnt4_753/LICENSE-APACHE new file mode 120000 index 0000000..965b606 --- /dev/null +++ b/ed_on_mnt4_753/LICENSE-APACHE @@ -0,0 +1 @@ +../LICENSE-APACHE \ No newline at end of file diff --git a/ed_on_mnt4_753/LICENSE-MIT b/ed_on_mnt4_753/LICENSE-MIT new file mode 120000 index 0000000..76219eb --- /dev/null +++ b/ed_on_mnt4_753/LICENSE-MIT @@ -0,0 +1 @@ +../LICENSE-MIT \ No newline at end of file diff --git a/ed_on_mnt4_753/src/curves/mod.rs b/ed_on_mnt4_753/src/curves/mod.rs index c5a763c..de530fd 100644 --- a/ed_on_mnt4_753/src/curves/mod.rs +++ b/ed_on_mnt4_753/src/curves/mod.rs @@ -41,8 +41,8 @@ impl TECurveConfig for EdwardsParameters { /// Multiplication by `a` is just negation. #[inline(always)] - fn mul_by_a(elem: &Self::BaseField) -> Self::BaseField { - -*elem + fn mul_by_a(elem: Self::BaseField) -> Self::BaseField { + -elem } } diff --git a/ed_on_mnt4_753/src/curves/tests.rs b/ed_on_mnt4_753/src/curves/tests.rs index 0222891..753ad4e 100644 --- a/ed_on_mnt4_753/src/curves/tests.rs +++ b/ed_on_mnt4_753/src/curves/tests.rs @@ -1,5 +1,5 @@ use ark_algebra_test_templates::curves::*; -use ark_ec::AffineCurve; +use ark_ec::AffineRepr; use crate::*; diff --git a/mnt4_298/Cargo.toml b/mnt4_298/Cargo.toml index 02d0c41..054b0d6 100644 --- a/mnt4_298/Cargo.toml +++ b/mnt4_298/Cargo.toml @@ -10,7 +10,7 @@ keywords = ["cryptography", "finite-fields" ] 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 } diff --git a/mnt4_298/src/curves/g2.rs b/mnt4_298/src/curves/g2.rs index 39e79dd..5b7e97e 100644 --- a/mnt4_298/src/curves/g2.rs +++ b/mnt4_298/src/curves/g2.rs @@ -60,7 +60,7 @@ impl SWCurveConfig for Parameters { const GENERATOR: G2Affine = G2Affine::new_unchecked(G2_GENERATOR_X, G2_GENERATOR_Y); #[inline(always)] - fn mul_by_a(elt: &Fq2) -> Fq2 { + fn mul_by_a(elt: Fq2) -> Fq2 { Fq2::new(MUL_BY_A_C0 * &elt.c0, MUL_BY_A_C1 * &elt.c1) } } diff --git a/mnt4_298/src/curves/tests.rs b/mnt4_298/src/curves/tests.rs index f44f717..16e3dbe 100644 --- a/mnt4_298/src/curves/tests.rs +++ b/mnt4_298/src/curves/tests.rs @@ -2,7 +2,7 @@ use ark_algebra_test_templates::{ curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, generate_product_of_pairings_test, msm::*, }; -use ark_ec::{AffineCurve, PairingEngine, ProjectiveCurve}; +use ark_ec::{AffineRepr, PairingEngine, ProjectiveCurve}; use ark_ff::{Field, One, PrimeField, UniformRand}; use ark_std::{rand::Rng, test_rng}; use core::ops::MulAssign; diff --git a/mnt4_753/Cargo.toml b/mnt4_753/Cargo.toml index ea8ec9d..f327e57 100644 --- a/mnt4_753/Cargo.toml +++ b/mnt4_753/Cargo.toml @@ -10,7 +10,7 @@ keywords = ["cryptography", "finite-fields" ] 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 } diff --git a/mnt4_753/src/curves/g2.rs b/mnt4_753/src/curves/g2.rs index ce18150..820d520 100644 --- a/mnt4_753/src/curves/g2.rs +++ b/mnt4_753/src/curves/g2.rs @@ -67,7 +67,7 @@ impl SWCurveConfig for Parameters { const GENERATOR: G2Affine = G2Affine::new_unchecked(G2_GENERATOR_X, G2_GENERATOR_Y); #[inline(always)] - fn mul_by_a(elt: &Fq2) -> Fq2 { + fn mul_by_a(elt: Fq2) -> Fq2 { Fq2::new(MUL_BY_A_C0 * &elt.c0, MUL_BY_A_C1 * &elt.c1) } } diff --git a/mnt4_753/src/curves/tests.rs b/mnt4_753/src/curves/tests.rs index bdab587..742e24e 100644 --- a/mnt4_753/src/curves/tests.rs +++ b/mnt4_753/src/curves/tests.rs @@ -2,7 +2,7 @@ use ark_algebra_test_templates::{ curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, generate_product_of_pairings_test, msm::*, }; -use ark_ec::{AffineCurve, PairingEngine, ProjectiveCurve}; +use ark_ec::{AffineRepr, PairingEngine, ProjectiveCurve}; use ark_ff::{Field, One, PrimeField, UniformRand}; use ark_std::{rand::Rng, test_rng}; use core::ops::MulAssign; diff --git a/mnt6_298/LICENSE-APACHE b/mnt6_298/LICENSE-APACHE new file mode 120000 index 0000000..965b606 --- /dev/null +++ b/mnt6_298/LICENSE-APACHE @@ -0,0 +1 @@ +../LICENSE-APACHE \ No newline at end of file diff --git a/mnt6_298/LICENSE-MIT b/mnt6_298/LICENSE-MIT new file mode 120000 index 0000000..76219eb --- /dev/null +++ b/mnt6_298/LICENSE-MIT @@ -0,0 +1 @@ +../LICENSE-MIT \ No newline at end of file diff --git a/mnt6_298/src/curves/g2.rs b/mnt6_298/src/curves/g2.rs index 7c3f7d3..c325980 100644 --- a/mnt6_298/src/curves/g2.rs +++ b/mnt6_298/src/curves/g2.rs @@ -63,7 +63,7 @@ impl SWCurveConfig for Parameters { const GENERATOR: G2Affine = G2Affine::new_unchecked(G2_GENERATOR_X, G2_GENERATOR_Y); #[inline(always)] - fn mul_by_a(elt: &Fq3) -> Fq3 { + fn mul_by_a(elt: Fq3) -> Fq3 { Fq3::new( MUL_BY_A_C0 * &elt.c1, MUL_BY_A_C1 * &elt.c2, diff --git a/mnt6_298/src/curves/tests.rs b/mnt6_298/src/curves/tests.rs index fe7ee99..8896a1d 100644 --- a/mnt6_298/src/curves/tests.rs +++ b/mnt6_298/src/curves/tests.rs @@ -2,7 +2,7 @@ use ark_algebra_test_templates::{ curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, generate_product_of_pairings_test, msm::*, }; -use ark_ec::{AffineCurve, PairingEngine, ProjectiveCurve}; +use ark_ec::{AffineRepr, PairingEngine, ProjectiveCurve}; use ark_ff::{Field, One, PrimeField, UniformRand}; use ark_std::{rand::Rng, test_rng}; use core::ops::MulAssign; diff --git a/mnt6_753/LICENSE-APACHE b/mnt6_753/LICENSE-APACHE new file mode 120000 index 0000000..965b606 --- /dev/null +++ b/mnt6_753/LICENSE-APACHE @@ -0,0 +1 @@ +../LICENSE-APACHE \ No newline at end of file diff --git a/mnt6_753/LICENSE-MIT b/mnt6_753/LICENSE-MIT new file mode 120000 index 0000000..76219eb --- /dev/null +++ b/mnt6_753/LICENSE-MIT @@ -0,0 +1 @@ +../LICENSE-MIT \ No newline at end of file diff --git a/mnt6_753/src/curves/g2.rs b/mnt6_753/src/curves/g2.rs index ba419a2..1b07142 100644 --- a/mnt6_753/src/curves/g2.rs +++ b/mnt6_753/src/curves/g2.rs @@ -88,7 +88,7 @@ impl SWCurveConfig for Parameters { const GENERATOR: G2Affine = G2Affine::new_unchecked(G2_GENERATOR_X, G2_GENERATOR_Y); #[inline(always)] - fn mul_by_a(elt: &Fq3) -> Fq3 { + fn mul_by_a(elt: Fq3) -> Fq3 { Fq3::new( MUL_BY_A_C0 * &elt.c1, MUL_BY_A_C1 * &elt.c2, diff --git a/mnt6_753/src/curves/tests.rs b/mnt6_753/src/curves/tests.rs index 85883ad..7fc2dc9 100644 --- a/mnt6_753/src/curves/tests.rs +++ b/mnt6_753/src/curves/tests.rs @@ -2,7 +2,7 @@ use ark_algebra_test_templates::{ curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, generate_product_of_pairings_test, msm::*, }; -use ark_ec::{AffineCurve, PairingEngine, ProjectiveCurve}; +use ark_ec::{AffineRepr, PairingEngine, ProjectiveCurve}; use ark_ff::{Field, One, PrimeField, UniformRand}; use ark_std::{rand::Rng, test_rng}; use core::ops::MulAssign; diff --git a/pallas/LICENSE-APACHE b/pallas/LICENSE-APACHE new file mode 120000 index 0000000..965b606 --- /dev/null +++ b/pallas/LICENSE-APACHE @@ -0,0 +1 @@ +../LICENSE-APACHE \ No newline at end of file diff --git a/pallas/LICENSE-MIT b/pallas/LICENSE-MIT new file mode 120000 index 0000000..76219eb --- /dev/null +++ b/pallas/LICENSE-MIT @@ -0,0 +1 @@ +../LICENSE-MIT \ No newline at end of file diff --git a/pallas/src/curves/mod.rs b/pallas/src/curves/mod.rs index 809d151..0ed568e 100644 --- a/pallas/src/curves/mod.rs +++ b/pallas/src/curves/mod.rs @@ -37,7 +37,7 @@ impl SWCurveConfig for PallasParameters { const GENERATOR: Affine = Affine::new_unchecked(G_GENERATOR_X, G_GENERATOR_Y); #[inline(always)] - fn mul_by_a(_: &Self::BaseField) -> Self::BaseField { + fn mul_by_a(_: Self::BaseField) -> Self::BaseField { Self::BaseField::zero() } } diff --git a/pallas/src/curves/tests.rs b/pallas/src/curves/tests.rs index 0d21436..2d22aae 100755 --- a/pallas/src/curves/tests.rs +++ b/pallas/src/curves/tests.rs @@ -1,5 +1,5 @@ use ark_algebra_test_templates::curves::{curve_tests, sw_tests}; -use ark_ec::AffineCurve; +use ark_ec::AffineRepr; use crate::{Affine, PallasParameters, Projective}; diff --git a/vesta/LICENSE-APACHE b/vesta/LICENSE-APACHE new file mode 120000 index 0000000..965b606 --- /dev/null +++ b/vesta/LICENSE-APACHE @@ -0,0 +1 @@ +../LICENSE-APACHE \ No newline at end of file diff --git a/vesta/LICENSE-MIT b/vesta/LICENSE-MIT new file mode 120000 index 0000000..76219eb --- /dev/null +++ b/vesta/LICENSE-MIT @@ -0,0 +1 @@ +../LICENSE-MIT \ No newline at end of file diff --git a/vesta/src/curves/mod.rs b/vesta/src/curves/mod.rs index 7231196..28d5261 100644 --- a/vesta/src/curves/mod.rs +++ b/vesta/src/curves/mod.rs @@ -36,7 +36,7 @@ impl SWCurveConfig for VestaParameters { const GENERATOR: Affine = Affine::new_unchecked(G_GENERATOR_X, G_GENERATOR_Y); #[inline(always)] - fn mul_by_a(_: &Self::BaseField) -> Self::BaseField { + fn mul_by_a(_: Self::BaseField) -> Self::BaseField { Self::BaseField::zero() } } diff --git a/vesta/src/curves/tests.rs b/vesta/src/curves/tests.rs index 2ea62f1..ad3bd43 100755 --- a/vesta/src/curves/tests.rs +++ b/vesta/src/curves/tests.rs @@ -1,5 +1,5 @@ use ark_algebra_test_templates::curves::{curve_tests, sw_tests}; -use ark_ec::AffineCurve; +use ark_ec::AffineRepr; use crate::{Affine, Projective, VestaParameters};