* Simplify the field and curve tests using macros * minor * remove redundant code Co-authored-by: weikeng <w.k@berkeley.edu>update-to-latest-arkworks
@ -1,78 +1,15 @@ |
|||
use ark_ec::{AffineCurve, PairingEngine, ProjectiveCurve};
|
|||
use ark_ec::{AffineCurve, PairingEngine};
|
|||
use ark_ff::{Field, One, PrimeField};
|
|||
use ark_std::rand::Rng;
|
|||
use ark_std::test_rng;
|
|||
use ark_std::{rand::Rng, test_rng};
|
|||
|
|||
use crate::*;
|
|||
|
|||
use ark_algebra_test_templates::{curves::*, groups::*};
|
|||
use ark_algebra_test_templates::{
|
|||
curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, groups::*, msm::*,
|
|||
};
|
|||
|
|||
#[test]
|
|||
fn test_g1_projective_curve() {
|
|||
curve_tests::<G1Projective>();
|
|||
use core::ops::MulAssign;
|
|||
|
|||
sw_tests::<g1::Parameters>();
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_g1_projective_group() {
|
|||
let mut rng = test_rng();
|
|||
let a: G1Projective = rng.gen();
|
|||
let b: G1Projective = rng.gen();
|
|||
group_test(a, b);
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_g1_generator() {
|
|||
let generator = G1Affine::prime_subgroup_generator();
|
|||
assert!(generator.is_on_curve());
|
|||
assert!(generator.is_in_correct_subgroup_assuming_on_curve());
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_g2_projective_curve() {
|
|||
curve_tests::<G2Projective>();
|
|||
|
|||
sw_tests::<g2::Parameters>();
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_g2_projective_group() {
|
|||
let mut rng = test_rng();
|
|||
let a: G2Projective = rng.gen();
|
|||
let b: G2Projective = rng.gen();
|
|||
group_test(a, b);
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_g2_generator() {
|
|||
let generator = G2Affine::prime_subgroup_generator();
|
|||
assert!(generator.is_on_curve());
|
|||
assert!(generator.is_in_correct_subgroup_assuming_on_curve());
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_bilinearity() {
|
|||
let mut rng = test_rng();
|
|||
let a: G1Projective = rng.gen();
|
|||
let b: G2Projective = rng.gen();
|
|||
let s: Fr = rng.gen();
|
|||
|
|||
let sa = a.mul(s.into_repr());
|
|||
let sb = b.mul(s.into_repr());
|
|||
|
|||
let ans1 = BW6_761::pairing(sa, b);
|
|||
let ans2 = BW6_761::pairing(a, sb);
|
|||
let ans3 = BW6_761::pairing(a, b).pow(s.into_repr());
|
|||
|
|||
assert_eq!(ans1, ans2);
|
|||
assert_eq!(ans2, ans3);
|
|||
|
|||
assert_ne!(ans1, Fq6::one());
|
|||
assert_ne!(ans2, Fq6::one());
|
|||
assert_ne!(ans3, Fq6::one());
|
|||
|
|||
assert_eq!(ans1.pow(Fr::characteristic()), Fq6::one());
|
|||
assert_eq!(ans2.pow(Fr::characteristic()), Fq6::one());
|
|||
assert_eq!(ans3.pow(Fr::characteristic()), Fq6::one());
|
|||
}
|
|||
generate_g1_test!(bw6_761; curve_tests; sw_tests;);
|
|||
generate_g2_test!(bw6_761; curve_tests; sw_tests;);
|
|||
generate_bilinearity_test!(BW6_761, Fq6);
|
@ -1,52 +1,14 @@ |
|||
use ark_ff::{Field, PrimeField};
|
|||
use ark_ff::{Field, One, PrimeField, SquareRootField, UniformRand, Zero};
|
|||
use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize};
|
|||
use ark_std::rand::Rng;
|
|||
use ark_std::test_rng;
|
|||
use ark_std::{rand::Rng, test_rng};
|
|||
|
|||
use crate::*;
|
|||
|
|||
use ark_algebra_test_templates::fields::*;
|
|||
use ark_algebra_test_templates::{
|
|||
fields::*, generate_field_serialization_test, generate_field_test,
|
|||
};
|
|||
|
|||
#[test]
|
|||
fn test_fr() {
|
|||
let mut rng = test_rng();
|
|||
let a: Fr = rng.gen();
|
|||
let b: Fr = rng.gen();
|
|||
field_test(a, b);
|
|||
sqrt_field_test(a);
|
|||
primefield_test::<Fr>();
|
|||
}
|
|||
use core::ops::{AddAssign, MulAssign, SubAssign};
|
|||
|
|||
#[test]
|
|||
fn test_fq() {
|
|||
let mut rng = test_rng();
|
|||
let a: Fq = rng.gen();
|
|||
let b: Fq = rng.gen();
|
|||
field_test(a, b);
|
|||
primefield_test::<Fq>();
|
|||
sqrt_field_test(a);
|
|||
|
|||
let byte_size = a.serialized_size();
|
|||
let (_, buffer_size) = buffer_bit_byte_size(Fq::size_in_bits());
|
|||
assert_eq!(byte_size, buffer_size);
|
|||
field_serialization_test::<Fq>(byte_size);
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_fq3() {
|
|||
let mut rng = test_rng();
|
|||
let a: Fq3 = rng.gen();
|
|||
let b: Fq3 = rng.gen();
|
|||
field_test(a, b);
|
|||
sqrt_field_test(a);
|
|||
frobenius_test::<Fq3, _>(Fq::characteristic(), 13);
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_fq6() {
|
|||
let mut rng = test_rng();
|
|||
let a: Fq6 = rng.gen();
|
|||
let b: Fq6 = rng.gen();
|
|||
field_test(a, b);
|
|||
frobenius_test::<Fq6, _>(Fq::characteristic(), 13);
|
|||
}
|
|||
generate_field_test!(bw6_761; fq3; fq6;);
|
|||
generate_field_serialization_test!(bw6_761;);
|
@ -1,78 +1,15 @@ |
|||
use ark_ec::{AffineCurve, PairingEngine, ProjectiveCurve};
|
|||
use ark_ec::{AffineCurve, PairingEngine};
|
|||
use ark_ff::{Field, One, PrimeField};
|
|||
use ark_std::rand::Rng;
|
|||
use ark_std::test_rng;
|
|||
use ark_std::{rand::Rng, test_rng};
|
|||
|
|||
use crate::*;
|
|||
|
|||
use ark_algebra_test_templates::{curves::*, groups::*};
|
|||
use ark_algebra_test_templates::{
|
|||
curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test, groups::*, msm::*,
|
|||
};
|
|||
|
|||
#[test]
|
|||
fn test_g1_projective_curve() {
|
|||
curve_tests::<G1Projective>();
|
|||
use core::ops::MulAssign;
|
|||
|
|||
sw_tests::<g1::Parameters>();
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_g1_projective_group() {
|
|||
let mut rng = test_rng();
|
|||
let a: G1Projective = rng.gen();
|
|||
let b: G1Projective = rng.gen();
|
|||
group_test(a, b);
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_g1_generator() {
|
|||
let generator = G1Affine::prime_subgroup_generator();
|
|||
assert!(generator.is_on_curve());
|
|||
assert!(generator.is_in_correct_subgroup_assuming_on_curve());
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_g2_projective_curve() {
|
|||
curve_tests::<G2Projective>();
|
|||
|
|||
sw_tests::<g2::Parameters>();
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_g2_projective_group() {
|
|||
let mut rng = test_rng();
|
|||
let a: G2Projective = rng.gen();
|
|||
let b: G2Projective = rng.gen();
|
|||
group_test(a, b);
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_g2_generator() {
|
|||
let generator = G2Affine::prime_subgroup_generator();
|
|||
assert!(generator.is_on_curve());
|
|||
assert!(generator.is_in_correct_subgroup_assuming_on_curve());
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_bilinearity() {
|
|||
let mut rng = test_rng();
|
|||
let a: G1Projective = rng.gen();
|
|||
let b: G2Projective = rng.gen();
|
|||
let s: Fr = rng.gen();
|
|||
|
|||
let sa = a.mul(s.into_repr());
|
|||
let sb = b.mul(s.into_repr());
|
|||
|
|||
let ans1 = CP6_782::pairing(sa, b);
|
|||
let ans2 = CP6_782::pairing(a, sb);
|
|||
let ans3 = CP6_782::pairing(a, b).pow(s.into_repr());
|
|||
|
|||
assert_eq!(ans1, ans2);
|
|||
assert_eq!(ans2, ans3);
|
|||
|
|||
assert_ne!(ans1, Fq6::one());
|
|||
assert_ne!(ans2, Fq6::one());
|
|||
assert_ne!(ans3, Fq6::one());
|
|||
|
|||
assert_eq!(ans1.pow(Fr::characteristic()), Fq6::one());
|
|||
assert_eq!(ans2.pow(Fr::characteristic()), Fq6::one());
|
|||
assert_eq!(ans3.pow(Fr::characteristic()), Fq6::one());
|
|||
}
|
|||
generate_g1_test!(cp6_782; curve_tests; sw_tests;);
|
|||
generate_g2_test!(cp6_782; curve_tests; sw_tests;);
|
|||
generate_bilinearity_test!(CP6_782, Fq6);
|
@ -1,52 +1,14 @@ |
|||
use ark_ff::{Field, PrimeField};
|
|||
use ark_ff::{Field, One, PrimeField, SquareRootField, UniformRand, Zero};
|
|||
use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize};
|
|||
use ark_std::rand::Rng;
|
|||
use ark_std::test_rng;
|
|||
use ark_std::{rand::Rng, test_rng};
|
|||
|
|||
use crate::*;
|
|||
|
|||
use ark_algebra_test_templates::fields::*;
|
|||
use ark_algebra_test_templates::{
|
|||
fields::*, generate_field_serialization_test, generate_field_test,
|
|||
};
|
|||
|
|||
#[test]
|
|||
fn test_fr() {
|
|||
let mut rng = test_rng();
|
|||
let a: Fr = rng.gen();
|
|||
let b: Fr = rng.gen();
|
|||
field_test(a, b);
|
|||
sqrt_field_test(a);
|
|||
primefield_test::<Fr>();
|
|||
}
|
|||
use core::ops::{AddAssign, MulAssign, SubAssign};
|
|||
|
|||
#[test]
|
|||
fn test_fq() {
|
|||
let mut rng = test_rng();
|
|||
let a: Fq = rng.gen();
|
|||
let b: Fq = rng.gen();
|
|||
field_test(a, b);
|
|||
primefield_test::<Fq>();
|
|||
sqrt_field_test(a);
|
|||
|
|||
let byte_size = a.serialized_size();
|
|||
let (_, buffer_size) = buffer_bit_byte_size(Fq::size_in_bits());
|
|||
assert_eq!(byte_size, buffer_size);
|
|||
field_serialization_test::<Fq>(byte_size);
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_fq3() {
|
|||
let mut rng = test_rng();
|
|||
let a: Fq3 = rng.gen();
|
|||
let b: Fq3 = rng.gen();
|
|||
field_test(a, b);
|
|||
sqrt_field_test(a);
|
|||
frobenius_test::<Fq3, _>(Fq::characteristic(), 13);
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_fq6() {
|
|||
let mut rng = test_rng();
|
|||
let a: Fq6 = rng.gen();
|
|||
let b: Fq6 = rng.gen();
|
|||
field_test(a, b);
|
|||
frobenius_test::<Fq6, _>(Fq::characteristic(), 13);
|
|||
}
|
|||
generate_field_test!(cp6_782; fq3; fq6;);
|
|||
generate_field_serialization_test!(cp6_782;);
|
@ -1,91 +1,17 @@ |
|||
use ark_ec::{AffineCurve, PairingEngine, ProjectiveCurve};
|
|||
use ark_ff::{Field, One, PrimeField, UniformRand};
|
|||
use ark_std::rand::Rng;
|
|||
use ark_std::test_rng;
|
|||
use ark_std::{rand::Rng, test_rng};
|
|||
|
|||
use crate::*;
|
|||
|
|||
use ark_algebra_test_templates::{curves::*, groups::*};
|
|||
use ark_algebra_test_templates::{
|
|||
curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test,
|
|||
generate_product_of_pairings_test, groups::*, msm::*,
|
|||
};
|
|||
|
|||
#[test]
|
|||
fn test_g1_projective_curve() {
|
|||
curve_tests::<G1Projective>();
|
|||
use core::ops::MulAssign;
|
|||
|
|||
sw_tests::<g1::Parameters>();
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_g1_projective_group() {
|
|||
let mut rng = test_rng();
|
|||
let a: G1Projective = rng.gen();
|
|||
let b: G1Projective = rng.gen();
|
|||
group_test(a, b);
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_g1_generator() {
|
|||
let generator = G1Affine::prime_subgroup_generator();
|
|||
assert!(generator.is_on_curve());
|
|||
assert!(generator.is_in_correct_subgroup_assuming_on_curve());
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_g2_projective_curve() {
|
|||
curve_tests::<G2Projective>();
|
|||
|
|||
sw_tests::<g2::Parameters>();
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_g2_projective_group() {
|
|||
let mut rng = test_rng();
|
|||
let a: G2Projective = rng.gen();
|
|||
let b: G2Projective = rng.gen();
|
|||
group_test(a, b);
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_g2_generator() {
|
|||
let generator = G2Affine::prime_subgroup_generator();
|
|||
assert!(generator.is_on_curve());
|
|||
assert!(generator.is_in_correct_subgroup_assuming_on_curve());
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_bilinearity() {
|
|||
let mut rng = test_rng();
|
|||
let a: G1Projective = rng.gen();
|
|||
let b: G2Projective = rng.gen();
|
|||
let s: Fr = rng.gen();
|
|||
|
|||
let sa = a.mul(s.into_repr());
|
|||
let sb = b.mul(s.into_repr());
|
|||
|
|||
let ans1 = MNT4_298::pairing(sa, b);
|
|||
let ans2 = MNT4_298::pairing(a, sb);
|
|||
let ans3 = MNT4_298::pairing(a, b).pow(s.into_repr());
|
|||
|
|||
assert_eq!(ans1, ans2);
|
|||
assert_eq!(ans2, ans3);
|
|||
|
|||
assert_ne!(ans1, Fq4::one());
|
|||
assert_ne!(ans2, Fq4::one());
|
|||
assert_ne!(ans3, Fq4::one());
|
|||
|
|||
assert_eq!(ans1.pow(Fr::characteristic()), Fq4::one());
|
|||
assert_eq!(ans2.pow(Fr::characteristic()), Fq4::one());
|
|||
assert_eq!(ans3.pow(Fr::characteristic()), Fq4::one());
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_product_of_pairings() {
|
|||
let rng = &mut test_rng();
|
|||
|
|||
let a = G1Projective::rand(rng).into_affine();
|
|||
let b = G2Projective::rand(rng).into_affine();
|
|||
let c = G1Projective::rand(rng).into_affine();
|
|||
let d = G2Projective::rand(rng).into_affine();
|
|||
let ans1 = MNT4_298::pairing(a, b) * &MNT4_298::pairing(c, d);
|
|||
let ans2 = MNT4_298::product_of_pairings(&[(a.into(), b.into()), (c.into(), d.into())]);
|
|||
assert_eq!(ans1, ans2);
|
|||
}
|
|||
generate_g1_test!(mnt4_298; curve_tests; sw_tests;);
|
|||
generate_g2_test!(mnt4_298; curve_tests; sw_tests;);
|
|||
generate_bilinearity_test!(MNT4_298, Fq4);
|
|||
generate_product_of_pairings_test!(MNT4_298);
|
@ -1,46 +1,9 @@ |
|||
use ark_ff::Field;
|
|||
use ark_std::rand::Rng;
|
|||
use ark_ff::{Field, One, SquareRootField, UniformRand, Zero};
|
|||
use ark_std::test_rng;
|
|||
|
|||
use crate::*;
|
|||
use ark_algebra_test_templates::{fields::*, generate_field_test};
|
|||
|
|||
use ark_algebra_test_templates::fields::*;
|
|||
use core::ops::{AddAssign, MulAssign, SubAssign};
|
|||
|
|||
#[test]
|
|||
fn test_fr() {
|
|||
let mut rng = test_rng();
|
|||
let a: Fr = rng.gen();
|
|||
let b: Fr = rng.gen();
|
|||
field_test(a, b);
|
|||
sqrt_field_test(a);
|
|||
primefield_test::<Fr>();
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_fq() {
|
|||
let mut rng = test_rng();
|
|||
let a: Fq = rng.gen();
|
|||
let b: Fq = rng.gen();
|
|||
field_test(a, b);
|
|||
sqrt_field_test(a);
|
|||
primefield_test::<Fq>();
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_fq2() {
|
|||
let mut rng = test_rng();
|
|||
let a: Fq2 = rng.gen();
|
|||
let b: Fq2 = rng.gen();
|
|||
field_test(a, b);
|
|||
sqrt_field_test(a);
|
|||
frobenius_test::<Fq2, _>(Fq::characteristic(), 13);
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_fq4() {
|
|||
let mut rng = test_rng();
|
|||
let a: Fq4 = rng.gen();
|
|||
let b: Fq4 = rng.gen();
|
|||
field_test(a, b);
|
|||
frobenius_test::<Fq4, _>(Fq::characteristic(), 13);
|
|||
}
|
|||
generate_field_test!(mnt4_298; fq2; fq4;);
|
@ -1,91 +1,16 @@ |
|||
use ark_ec::{AffineCurve, PairingEngine, ProjectiveCurve};
|
|||
use ark_ff::{Field, One, PrimeField, UniformRand};
|
|||
use ark_std::rand::Rng;
|
|||
use ark_std::test_rng;
|
|||
use ark_std::{rand::Rng, test_rng};
|
|||
|
|||
use crate::*;
|
|||
use ark_algebra_test_templates::{
|
|||
curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test,
|
|||
generate_product_of_pairings_test, groups::*, msm::*,
|
|||
};
|
|||
|
|||
use ark_algebra_test_templates::{curves::*, groups::*};
|
|||
use core::ops::MulAssign;
|
|||
|
|||
#[test]
|
|||
fn test_g1_projective_curve() {
|
|||
curve_tests::<G1Projective>();
|
|||
|
|||
sw_tests::<g1::Parameters>();
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_g1_projective_group() {
|
|||
let mut rng = test_rng();
|
|||
let a: G1Projective = rng.gen();
|
|||
let b: G1Projective = rng.gen();
|
|||
group_test(a, b);
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_g1_generator() {
|
|||
let generator = G1Affine::prime_subgroup_generator();
|
|||
assert!(generator.is_on_curve());
|
|||
assert!(generator.is_in_correct_subgroup_assuming_on_curve());
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_g2_projective_curve() {
|
|||
curve_tests::<G2Projective>();
|
|||
|
|||
sw_tests::<g2::Parameters>();
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_g2_projective_group() {
|
|||
let mut rng = test_rng();
|
|||
let a: G2Projective = rng.gen();
|
|||
let b: G2Projective = rng.gen();
|
|||
group_test(a, b);
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_g2_generator() {
|
|||
let generator = G2Affine::prime_subgroup_generator();
|
|||
assert!(generator.is_on_curve());
|
|||
assert!(generator.is_in_correct_subgroup_assuming_on_curve());
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_bilinearity() {
|
|||
let mut rng = test_rng();
|
|||
let a: G1Projective = rng.gen();
|
|||
let b: G2Projective = rng.gen();
|
|||
let s: Fr = rng.gen();
|
|||
|
|||
let sa = a.mul(s.into_repr());
|
|||
let sb = b.mul(s.into_repr());
|
|||
|
|||
let ans1 = MNT4_753::pairing(sa, b);
|
|||
let ans2 = MNT4_753::pairing(a, sb);
|
|||
let ans3 = MNT4_753::pairing(a, b).pow(s.into_repr());
|
|||
|
|||
assert_eq!(ans1, ans2);
|
|||
assert_eq!(ans2, ans3);
|
|||
|
|||
assert_ne!(ans1, Fq4::one());
|
|||
assert_ne!(ans2, Fq4::one());
|
|||
assert_ne!(ans3, Fq4::one());
|
|||
|
|||
assert_eq!(ans1.pow(Fr::characteristic()), Fq4::one());
|
|||
assert_eq!(ans2.pow(Fr::characteristic()), Fq4::one());
|
|||
assert_eq!(ans3.pow(Fr::characteristic()), Fq4::one());
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_product_of_pairings() {
|
|||
let rng = &mut test_rng();
|
|||
|
|||
let a = G1Projective::rand(rng).into_affine();
|
|||
let b = G2Projective::rand(rng).into_affine();
|
|||
let c = G1Projective::rand(rng).into_affine();
|
|||
let d = G2Projective::rand(rng).into_affine();
|
|||
let ans1 = MNT4_753::pairing(a, b) * &MNT4_753::pairing(c, d);
|
|||
let ans2 = MNT4_753::product_of_pairings(&[(a.into(), b.into()), (c.into(), d.into())]);
|
|||
assert_eq!(ans1, ans2);
|
|||
}
|
|||
generate_g1_test!(mnt4_753; curve_tests; sw_tests;);
|
|||
generate_g2_test!(mnt4_753; curve_tests; sw_tests;);
|
|||
generate_bilinearity_test!(MNT4_753, Fq4);
|
|||
generate_product_of_pairings_test!(MNT4_753);
|
@ -1,46 +1,9 @@ |
|||
use ark_ff::Field;
|
|||
use ark_std::rand::Rng;
|
|||
use ark_ff::{Field, One, SquareRootField, UniformRand, Zero};
|
|||
use ark_std::test_rng;
|
|||
|
|||
use crate::*;
|
|||
use ark_algebra_test_templates::{fields::*, generate_field_test};
|
|||
|
|||
use ark_algebra_test_templates::fields::*;
|
|||
use core::ops::{AddAssign, MulAssign, SubAssign};
|
|||
|
|||
#[test]
|
|||
fn test_fr() {
|
|||
let mut rng = test_rng();
|
|||
let a: Fr = rng.gen();
|
|||
let b: Fr = rng.gen();
|
|||
field_test(a, b);
|
|||
sqrt_field_test(a);
|
|||
primefield_test::<Fr>();
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_fq() {
|
|||
let mut rng = test_rng();
|
|||
let a: Fq = rng.gen();
|
|||
let b: Fq = rng.gen();
|
|||
field_test(a, b);
|
|||
sqrt_field_test(a);
|
|||
primefield_test::<Fq>();
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_fq2() {
|
|||
let mut rng = test_rng();
|
|||
let a: Fq2 = rng.gen();
|
|||
let b: Fq2 = rng.gen();
|
|||
field_test(a, b);
|
|||
sqrt_field_test(a);
|
|||
frobenius_test::<Fq2, _>(Fq::characteristic(), 13);
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_fq4() {
|
|||
let mut rng = test_rng();
|
|||
let a: Fq4 = rng.gen();
|
|||
let b: Fq4 = rng.gen();
|
|||
field_test(a, b);
|
|||
frobenius_test::<Fq4, _>(Fq::characteristic(), 13);
|
|||
}
|
|||
generate_field_test!(mnt4_753; fq2; fq4;);
|
@ -1,91 +1,17 @@ |
|||
use ark_ec::{AffineCurve, PairingEngine, ProjectiveCurve};
|
|||
use ark_ff::{Field, One, PrimeField, UniformRand};
|
|||
use ark_std::rand::Rng;
|
|||
use ark_std::test_rng;
|
|||
use ark_std::{rand::Rng, test_rng};
|
|||
|
|||
use crate::*;
|
|||
|
|||
use ark_algebra_test_templates::{curves::*, groups::*};
|
|||
use ark_algebra_test_templates::{
|
|||
curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test,
|
|||
generate_product_of_pairings_test, groups::*, msm::*,
|
|||
};
|
|||
|
|||
#[test]
|
|||
fn test_g1_projective_curve() {
|
|||
curve_tests::<G1Projective>();
|
|||
use core::ops::MulAssign;
|
|||
|
|||
sw_tests::<g1::Parameters>();
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_g1_projective_group() {
|
|||
let mut rng = test_rng();
|
|||
let a: G1Projective = rng.gen();
|
|||
let b: G1Projective = rng.gen();
|
|||
group_test(a, b);
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_g1_generator() {
|
|||
let generator = G1Affine::prime_subgroup_generator();
|
|||
assert!(generator.is_on_curve());
|
|||
assert!(generator.is_in_correct_subgroup_assuming_on_curve());
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_g2_projective_curve() {
|
|||
curve_tests::<G2Projective>();
|
|||
|
|||
sw_tests::<g2::Parameters>();
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_g2_projective_group() {
|
|||
let mut rng = test_rng();
|
|||
let a: G2Projective = rng.gen();
|
|||
let b: G2Projective = rng.gen();
|
|||
group_test(a, b);
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_g2_generator() {
|
|||
let generator = G2Affine::prime_subgroup_generator();
|
|||
assert!(generator.is_on_curve());
|
|||
assert!(generator.is_in_correct_subgroup_assuming_on_curve());
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_bilinearity() {
|
|||
let mut rng = test_rng();
|
|||
let a: G1Projective = rng.gen();
|
|||
let b: G2Projective = rng.gen();
|
|||
let s: Fr = rng.gen();
|
|||
|
|||
let sa = a.mul(s.into_repr());
|
|||
let sb = b.mul(s.into_repr());
|
|||
|
|||
let ans1 = MNT6_298::pairing(sa, b);
|
|||
let ans2 = MNT6_298::pairing(a, sb);
|
|||
let ans3 = MNT6_298::pairing(a, b).pow(s.into_repr());
|
|||
|
|||
assert_eq!(ans1, ans2);
|
|||
assert_eq!(ans2, ans3);
|
|||
|
|||
assert_ne!(ans1, Fq6::one());
|
|||
assert_ne!(ans2, Fq6::one());
|
|||
assert_ne!(ans3, Fq6::one());
|
|||
|
|||
assert_eq!(ans1.pow(Fr::characteristic()), Fq6::one());
|
|||
assert_eq!(ans2.pow(Fr::characteristic()), Fq6::one());
|
|||
assert_eq!(ans3.pow(Fr::characteristic()), Fq6::one());
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_product_of_pairings() {
|
|||
let rng = &mut test_rng();
|
|||
|
|||
let a = G1Projective::rand(rng).into_affine();
|
|||
let b = G2Projective::rand(rng).into_affine();
|
|||
let c = G1Projective::rand(rng).into_affine();
|
|||
let d = G2Projective::rand(rng).into_affine();
|
|||
let ans1 = MNT6_298::pairing(a, b) * &MNT6_298::pairing(c, d);
|
|||
let ans2 = MNT6_298::product_of_pairings(&[(a.into(), b.into()), (c.into(), d.into())]);
|
|||
assert_eq!(ans1, ans2);
|
|||
}
|
|||
generate_g1_test!(mnt6_298; curve_tests; sw_tests;);
|
|||
generate_g2_test!(mnt6_298; curve_tests; sw_tests;);
|
|||
generate_bilinearity_test!(MNT6_298, Fq6);
|
|||
generate_product_of_pairings_test!(MNT6_298);
|
@ -1,91 +1,17 @@ |
|||
use ark_ec::{AffineCurve, PairingEngine, ProjectiveCurve};
|
|||
use ark_ff::{Field, One, PrimeField, UniformRand};
|
|||
use ark_std::rand::Rng;
|
|||
use ark_std::test_rng;
|
|||
use ark_std::{rand::Rng, test_rng};
|
|||
|
|||
use crate::*;
|
|||
|
|||
use ark_algebra_test_templates::{curves::*, groups::*};
|
|||
use ark_algebra_test_templates::{
|
|||
curves::*, generate_bilinearity_test, generate_g1_test, generate_g2_test,
|
|||
generate_product_of_pairings_test, groups::*, msm::*,
|
|||
};
|
|||
|
|||
#[test]
|
|||
fn test_g1_projective_curve() {
|
|||
curve_tests::<G1Projective>();
|
|||
use core::ops::MulAssign;
|
|||
|
|||
sw_tests::<g1::Parameters>();
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_g1_projective_group() {
|
|||
let mut rng = test_rng();
|
|||
let a: G1Projective = rng.gen();
|
|||
let b: G1Projective = rng.gen();
|
|||
group_test(a, b);
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_g1_generator() {
|
|||
let generator = G1Affine::prime_subgroup_generator();
|
|||
assert!(generator.is_on_curve());
|
|||
assert!(generator.is_in_correct_subgroup_assuming_on_curve());
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_g2_projective_curve() {
|
|||
curve_tests::<G2Projective>();
|
|||
|
|||
sw_tests::<g2::Parameters>();
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_g2_projective_group() {
|
|||
let mut rng = test_rng();
|
|||
let a: G2Projective = rng.gen();
|
|||
let b: G2Projective = rng.gen();
|
|||
group_test(a, b);
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_g2_generator() {
|
|||
let generator = G2Affine::prime_subgroup_generator();
|
|||
assert!(generator.is_on_curve());
|
|||
assert!(generator.is_in_correct_subgroup_assuming_on_curve());
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_bilinearity() {
|
|||
let mut rng = test_rng();
|
|||
let a: G1Projective = rng.gen();
|
|||
let b: G2Projective = rng.gen();
|
|||
let s: Fr = rng.gen();
|
|||
|
|||
let sa = a.mul(s.into_repr());
|
|||
let sb = b.mul(s.into_repr());
|
|||
|
|||
let ans1 = MNT6_753::pairing(sa, b);
|
|||
let ans2 = MNT6_753::pairing(a, sb);
|
|||
let ans3 = MNT6_753::pairing(a, b).pow(s.into_repr());
|
|||
|
|||
assert_eq!(ans1, ans2);
|
|||
assert_eq!(ans2, ans3);
|
|||
|
|||
assert_ne!(ans1, Fq6::one());
|
|||
assert_ne!(ans2, Fq6::one());
|
|||
assert_ne!(ans3, Fq6::one());
|
|||
|
|||
assert_eq!(ans1.pow(Fr::characteristic()), Fq6::one());
|
|||
assert_eq!(ans2.pow(Fr::characteristic()), Fq6::one());
|
|||
assert_eq!(ans3.pow(Fr::characteristic()), Fq6::one());
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_product_of_pairings() {
|
|||
let rng = &mut test_rng();
|
|||
|
|||
let a = G1Projective::rand(rng).into_affine();
|
|||
let b = G2Projective::rand(rng).into_affine();
|
|||
let c = G1Projective::rand(rng).into_affine();
|
|||
let d = G2Projective::rand(rng).into_affine();
|
|||
let ans1 = MNT6_753::pairing(a, b) * &MNT6_753::pairing(c, d);
|
|||
let ans2 = MNT6_753::product_of_pairings(&[(a.into(), b.into()), (c.into(), d.into())]);
|
|||
assert_eq!(ans1, ans2);
|
|||
}
|
|||
generate_g1_test!(mnt6_753; curve_tests; sw_tests;);
|
|||
generate_g2_test!(mnt6_753; curve_tests; sw_tests;);
|
|||
generate_bilinearity_test!(MNT6_753, Fq6);
|
|||
generate_product_of_pairings_test!(MNT6_753);
|