diff --git a/src/bls12381/fq12.rs b/src/bls12381/fq12.rs index 6202bf08..8f11de93 100644 --- a/src/bls12381/fq12.rs +++ b/src/bls12381/fq12.rs @@ -294,5 +294,5 @@ mod test { setup_f12_test_funcs!(Fq12, Fq6, Fq2); test_fq12!(f12_mul_by_014_, 500); test_fq12!(f12_mul_by_034_, 500); - test_frobenius!(Fq12, 8, Fq::MODULUS_LIMBS); + test_frobenius!(Fq12, Fq, 8); } diff --git a/src/bls12381/fq2.rs b/src/bls12381/fq2.rs index 539481de..40579fef 100644 --- a/src/bls12381/fq2.rs +++ b/src/bls12381/fq2.rs @@ -65,7 +65,7 @@ impl ExtField for Fq2 { mod test { use super::*; - use crate::{arith_test, legendre_test, serde_test, test}; + use crate::{arith_test, f2_tests, legendre_test, serde_test, test, test_frobenius}; use rand_core::RngCore; // constants_test!(Fq2); @@ -77,16 +77,8 @@ mod test { serde_test!(Fq2); // test_uniform_bytes!(Fq2, 1000, L 96); - crate::f2_tests!(Fq2, Fq); - crate::test_frobenius!( - Fq2, - 20, - // Frobenius endomorphism power parameter for extension field - // ϕ: E → E - // (x, y) ↦ (x^p, y^p) - // p: modulus of base field (Here, Fq::MODULUS) - Fq::MODULUS_LIMBS - ); + f2_tests!(Fq2, Fq); + test_frobenius!(Fq2, Fq, 20); #[test] fn test_fq2_mul_nonresidue() { diff --git a/src/bls12381/fq6.rs b/src/bls12381/fq6.rs index 9ccff8c5..deee0e5a 100644 --- a/src/bls12381/fq6.rs +++ b/src/bls12381/fq6.rs @@ -299,7 +299,7 @@ mod test { test_fq6!(f6_mul_nonresidue_, 1000); test_fq6!(f6_mul_by_1_, 1000); test_fq6!(f6_mul_by_01_, 1000); - test_frobenius!(Fq6, 10, Fq::MODULUS_LIMBS); + test_frobenius!(Fq6, Fq, 10); #[test] fn test_fq6_mul_nonresidue() { diff --git a/src/bn256/fq12.rs b/src/bn256/fq12.rs index bfdc72d1..d390d398 100644 --- a/src/bn256/fq12.rs +++ b/src/bn256/fq12.rs @@ -222,14 +222,5 @@ mod test { setup_f12_test_funcs!(Fq12, Fq6, Fq2); test_fq12!(f12_mul_by_014_, 500); test_fq12!(f12_mul_by_034_, 500); - test_frobenius!( - Fq12, - 8, - [ - 0x3c208c16d87cfd47, - 0x97816a916871ca8d, - 0xb85045b68181585d, - 0x30644e72e131a029, - ] - ); + test_frobenius!(Fq12, Fq, 8); } diff --git a/src/bn256/fq2.rs b/src/bn256/fq2.rs index d352db4c..61c72427 100644 --- a/src/bn256/fq2.rs +++ b/src/bn256/fq2.rs @@ -68,7 +68,7 @@ impl ExtField for Fq2 { mod test { use super::*; - use crate::{arith_test, legendre_test, serde_test, test}; + use crate::{arith_test, f2_tests, legendre_test, serde_test, test, test_frobenius}; use rand_core::RngCore; // constants_test!(Fq2); @@ -80,17 +80,8 @@ mod test { serde_test!(Fq2); // test_uniform_bytes!(Fq2, 1000, L 96); - crate::f2_tests!(Fq2, Fq); - crate::test_frobenius!( - Fq2, - 20, - [ - 0x3c208c16d87cfd47, - 0x97816a916871ca8d, - 0xb85045b68181585d, - 0x30644e72e131a029, - ] - ); + f2_tests!(Fq2, Fq); + test_frobenius!(Fq2, Fq, 20); #[test] fn test_fq2_squaring() { diff --git a/src/bn256/fq6.rs b/src/bn256/fq6.rs index b34aa635..480db5a7 100644 --- a/src/bn256/fq6.rs +++ b/src/bn256/fq6.rs @@ -226,15 +226,6 @@ mod test { test_fq6!(f6_mul_nonresidue_, 1000); test_fq6!(f6_mul_by_1_, 1000); test_fq6!(f6_mul_by_01_, 1000); - test_frobenius!( - Fq6, - 10, - [ - 0x3c208c16d87cfd47, - 0x97816a916871ca8d, - 0xb85045b68181585d, - 0x30644e72e131a029 - ] - ); + test_frobenius!(Fq6, Fq, 10); // test_uniform_bytes!(Fq6, 1000, L 96); } diff --git a/src/pluto_eris/fp12.rs b/src/pluto_eris/fp12.rs index 8d2eb92f..9b48f7db 100644 --- a/src/pluto_eris/fp12.rs +++ b/src/pluto_eris/fp12.rs @@ -280,20 +280,5 @@ mod test { setup_f12_test_funcs!(Fp12, Fp6, Fp2); test_fp12!(f12_mul_by_014_, 500); test_fp12!(f12_mul_by_034_, 500); - test_frobenius!( - Fp12, - 8, - // ϕ: E → E - // (x, y) ↦ (x^p, y^p) - // p: modulus of base field (Here, Fp::MODULUS) - [ - 0x9ffffcd300000001, - 0xa2a7e8c30006b945, - 0xe4a7a5fe8fadffd6, - 0x443f9a5cda8a6c7b, - 0xa803ca76f439266f, - 0x0130e0000d7f70e4, - 0x2400000000002400, - ] - ); + test_frobenius!(Fp12, Fp, 8); } diff --git a/src/pluto_eris/fp2.rs b/src/pluto_eris/fp2.rs index 25578ebf..5d0f4c18 100644 --- a/src/pluto_eris/fp2.rs +++ b/src/pluto_eris/fp2.rs @@ -91,19 +91,7 @@ mod test { // test_uniform_bytes!(Fp2, 1000, L 96); crate::f2_tests!(Fp2, Fp); - crate::test_frobenius!( - Fp2, - 20, - [ - 0x9ffffcd300000001, - 0xa2a7e8c30006b945, - 0xe4a7a5fe8fadffd6, - 0x443f9a5cda8a6c7b, - 0xa803ca76f439266f, - 0x0130e0000d7f70e4, - 0x2400000000002400, - ] - ); + crate::test_frobenius!(Fp2, Fp, 20); #[test] fn test_fp2_squaring() { @@ -148,9 +136,9 @@ mod test { 0xbc, 0xe5, ]); for _ in 0..1000 { - let a = Fp2::random(&mut rng); + let mut a = Fp2::random(&mut rng); let mut b = a; - a.mul_by_nonresidue(); + a = a.mul_by_nonresidue(); b.mul_assign(&Fp2::NON_RESIDUE); assert_eq!(a, b); diff --git a/src/pluto_eris/fp6.rs b/src/pluto_eris/fp6.rs index 33f9318c..18129f53 100644 --- a/src/pluto_eris/fp6.rs +++ b/src/pluto_eris/fp6.rs @@ -273,31 +273,13 @@ mod test { test_fp6!(f6_mul_nonresidue_, 1000); test_fp6!(f6_mul_by_1_, 1000); test_fp6!(f6_mul_by_01_, 1000); - test_frobenius!( - Fp6, - 10, - [ - 0x9ffffcd300000001, - 0xa2a7e8c30006b945, - 0xe4a7a5fe8fadffd6, - 0x443f9a5cda8a6c7b, - 0xa803ca76f439266f, - 0x0130e0000d7f70e4, - 0x2400000000002400, - ] - ); + test_frobenius!(Fp6, Fp, 10); #[test] - fn test_fq2_mul_nonresidue() { - let nqr = Fp6 { - c0: Fp2::ZERO, - c1: Fp2::ONE, - c2: Fp2::ZERO, - }; - + fn test_fp6_mul_nonresidue() { let e = Fp6::random(rand_core::OsRng); let a0 = e.mul_by_nonresidue(); - let a1 = e * nqr; + let a1 = e * Fp6::NON_RESIDUE; assert_eq!(a0, a1); } diff --git a/src/tests/field/extensions.rs b/src/tests/field/extensions.rs index eb1180b3..4c1b2a38 100644 --- a/src/tests/field/extensions.rs +++ b/src/tests/field/extensions.rs @@ -170,7 +170,6 @@ macro_rules! setup_f12_test_funcs { c2: $base_field_2::zero(), }, }); - assert_eq!(a, b); } } @@ -179,7 +178,7 @@ macro_rules! setup_f12_test_funcs { #[macro_export] macro_rules! test_frobenius { - ($field:ident, $size: expr, $frobenius_param: expr) => { + ($field:ident, $base: ident, $size: expr) => { fn test_frobenius(mut rng: impl RngCore, n: usize) { for _ in 0..n { for i in 0..12 { @@ -187,7 +186,7 @@ macro_rules! test_frobenius { let mut b = a; for _ in 0..i { - a = a.pow($frobenius_param); + a = a.pow($base::MODULUS_LIMBS); } b.frobenius_map(i);