diff --git a/src/bn256/fq.rs b/src/bn256/fq.rs index f9c2e692..35714424 100644 --- a/src/bn256/fq.rs +++ b/src/bn256/fq.rs @@ -291,6 +291,7 @@ mod test { crate::field_testing_suite!(Fq, "quadratic_residue"); crate::field_testing_suite!(Fq, "bits"); crate::field_testing_suite!(Fq, "serialization_check"); + crate::field_testing_suite!(Fq, "constants", MODULUS_STR); use crate::ff_ext::Legendre; use rand_core::OsRng; diff --git a/src/bn256/fq2.rs b/src/bn256/fq2.rs index 0ffc2514..a116f2fd 100644 --- a/src/bn256/fq2.rs +++ b/src/bn256/fq2.rs @@ -418,6 +418,7 @@ impl From for Fq2 { } } +// This trait is only implemented to satisfy the requirement of CurveExt impl PrimeField for Fq2 { type Repr = Fq2Bytes; diff --git a/src/bn256/fr.rs b/src/bn256/fr.rs index c9776be9..28f8c476 100644 --- a/src/bn256/fr.rs +++ b/src/bn256/fr.rs @@ -339,6 +339,7 @@ mod test { crate::field_testing_suite!(Fr, "quadratic_residue"); crate::field_testing_suite!(Fr, "bits"); crate::field_testing_suite!(Fr, "serialization_check"); + crate::field_testing_suite!(Fr, "constants", MODULUS_STR); use rand_core::OsRng; @@ -360,12 +361,6 @@ mod test { } } - #[test] - fn test_delta() { - assert_eq!(Fr::DELTA, GENERATOR.pow([1u64 << Fr::S])); - assert_eq!(Fr::DELTA, Fr::MULTIPLICATIVE_GENERATOR.pow([1u64 << Fr::S])); - } - #[test] fn test_from_u512() { assert_eq!( diff --git a/src/pluto_eris/fields/fp.rs b/src/pluto_eris/fields/fp.rs index 21d2541f..ec4b9ea9 100644 --- a/src/pluto_eris/fields/fp.rs +++ b/src/pluto_eris/fields/fp.rs @@ -408,6 +408,7 @@ mod test { crate::field_testing_suite!(Fp, "quadratic_residue"); crate::field_testing_suite!(Fp, "bits"); crate::field_testing_suite!(Fp, "serialization_check"); + crate::field_testing_suite!(Fp, "constants", MODULUS_STR); use rand_core::OsRng; @@ -429,12 +430,6 @@ mod test { } } - #[test] - fn test_delta() { - assert_eq!(Fp::DELTA, GENERATOR.pow([1u64 << Fp::S])); - assert_eq!(Fp::DELTA, Fp::MULTIPLICATIVE_GENERATOR.pow([1u64 << Fp::S])); - } - #[test] fn test_zeta() { assert_eq!(Fp::ZETA * Fp::ZETA * Fp::ZETA, Fp::ONE); diff --git a/src/pluto_eris/fields/fq.rs b/src/pluto_eris/fields/fq.rs index 405c5188..e3d2b348 100644 --- a/src/pluto_eris/fields/fq.rs +++ b/src/pluto_eris/fields/fq.rs @@ -399,6 +399,7 @@ mod test { crate::field_testing_suite!(Fq, "quadratic_residue"); crate::field_testing_suite!(Fq, "bits"); crate::field_testing_suite!(Fq, "serialization_check"); + crate::field_testing_suite!(Fq, "constants", MODULUS_STR); use rand_core::OsRng; @@ -426,12 +427,6 @@ mod test { assert_ne!(Fq::ZETA * Fq::ZETA, Fq::ONE); } - #[test] - fn test_delta() { - assert_eq!(Fq::DELTA, GENERATOR.pow([1u64 << Fq::S])); - assert_eq!(Fq::DELTA, Fq::MULTIPLICATIVE_GENERATOR.pow([1u64 << Fq::S])); - } - #[test] fn test_from_u512() { const N_VECS: usize = 10; diff --git a/src/secp256k1/fp.rs b/src/secp256k1/fp.rs index 65c3f42c..943addb4 100644 --- a/src/secp256k1/fp.rs +++ b/src/secp256k1/fp.rs @@ -299,6 +299,7 @@ mod test { crate::field_testing_suite!(Fp, "quadratic_residue"); crate::field_testing_suite!(Fp, "bits"); crate::field_testing_suite!(Fp, "serialization_check"); + crate::field_testing_suite!(Fp, "constants", MODULUS_STR); use rand_core::OsRng; @@ -320,29 +321,4 @@ mod test { assert!(a == b || a == negb); } } - - #[test] - fn test_constants() { - assert_eq!( - Fp::MODULUS, - "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f", - ); - - assert_eq!(Fp::from(2) * Fp::TWO_INV, Fp::ONE); - } - - #[test] - fn test_delta() { - assert_eq!(Fp::DELTA, MULTIPLICATIVE_GENERATOR.pow([1u64 << Fp::S])); - } - - #[test] - fn test_root_of_unity() { - assert_eq!(Fp::ROOT_OF_UNITY.pow_vartime([1 << Fp::S]), Fp::one()); - } - - #[test] - fn test_inv_root_of_unity() { - assert_eq!(Fp::ROOT_OF_UNITY_INV, Fp::ROOT_OF_UNITY.invert().unwrap()); - } } diff --git a/src/secp256k1/fq.rs b/src/secp256k1/fq.rs index 07863753..a6e19a75 100644 --- a/src/secp256k1/fq.rs +++ b/src/secp256k1/fq.rs @@ -306,6 +306,7 @@ mod test { crate::field_testing_suite!(Fq, "quadratic_residue"); crate::field_testing_suite!(Fq, "bits"); crate::field_testing_suite!(Fq, "serialization_check"); + crate::field_testing_suite!(Fq, "constants", MODULUS_STR); use rand_core::OsRng; @@ -327,29 +328,4 @@ mod test { assert!(a == b || a == negb); } } - - #[test] - fn test_constants() { - assert_eq!( - Fq::MODULUS, - "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141", - ); - - assert_eq!(Fq::from(2) * Fq::TWO_INV, Fq::ONE); - } - - #[test] - fn test_delta() { - assert_eq!(Fq::DELTA, Fq::MULTIPLICATIVE_GENERATOR.pow([1u64 << Fq::S])); - } - - #[test] - fn test_root_of_unity() { - assert_eq!(Fq::ROOT_OF_UNITY.pow_vartime([1 << Fq::S]), Fq::one()); - } - - #[test] - fn test_inv_root_of_unity() { - assert_eq!(Fq::ROOT_OF_UNITY_INV, Fq::ROOT_OF_UNITY.invert().unwrap()); - } } diff --git a/src/secp256r1/fp.rs b/src/secp256r1/fp.rs index dcd2a021..098a12b1 100644 --- a/src/secp256r1/fp.rs +++ b/src/secp256r1/fp.rs @@ -317,6 +317,7 @@ mod test { crate::field_testing_suite!(Fp, "quadratic_residue"); crate::field_testing_suite!(Fp, "bits"); crate::field_testing_suite!(Fp, "serialization_check"); + crate::field_testing_suite!(Fp, "constants", MODULUS_STR); use rand_core::OsRng; @@ -338,29 +339,4 @@ mod test { assert!(a == b || a == negb); } } - - #[test] - fn test_constants() { - assert_eq!( - Fp::MODULUS, - "0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff", - ); - - assert_eq!(Fp::from(2) * Fp::TWO_INV, Fp::ONE); - } - - #[test] - fn test_delta() { - assert_eq!(Fp::DELTA, MULTIPLICATIVE_GENERATOR.pow([1u64 << Fp::S])); - } - - #[test] - fn test_root_of_unity() { - assert_eq!(Fp::ROOT_OF_UNITY.pow_vartime([1 << Fp::S]), Fp::one()); - } - - #[test] - fn test_inv_root_of_unity() { - assert_eq!(Fp::ROOT_OF_UNITY_INV, Fp::ROOT_OF_UNITY.invert().unwrap()); - } } diff --git a/src/secp256r1/fq.rs b/src/secp256r1/fq.rs index f4f94df4..6f7adbfa 100644 --- a/src/secp256r1/fq.rs +++ b/src/secp256r1/fq.rs @@ -306,6 +306,7 @@ mod test { crate::field_testing_suite!(Fq, "quadratic_residue"); // crate::field_testing_suite!(Fq, "bits"); crate::field_testing_suite!(Fq, "serialization_check"); + crate::field_testing_suite!(Fq, "constants", MODULUS_STR); use rand_core::OsRng; @@ -333,29 +334,4 @@ mod test { assert!(a == b || a == negb); } } - - #[test] - fn test_constants() { - assert_eq!( - Fq::MODULUS, - "0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551", - ); - - assert_eq!(Fq::from(2) * Fq::TWO_INV, Fq::ONE); - } - - #[test] - fn test_delta() { - assert_eq!(Fq::DELTA, Fq::MULTIPLICATIVE_GENERATOR.pow([1u64 << Fq::S])); - } - - #[test] - fn test_root_of_unity() { - assert_eq!(Fq::ROOT_OF_UNITY.pow_vartime([1 << Fq::S]), Fq::one()); - } - - #[test] - fn test_inv_root_of_unity() { - assert_eq!(Fq::ROOT_OF_UNITY_INV, Fq::ROOT_OF_UNITY.invert().unwrap()); - } } diff --git a/src/tests/field.rs b/src/tests/field.rs index 0073ad03..6b3c9479 100644 --- a/src/tests/field.rs +++ b/src/tests/field.rs @@ -439,4 +439,26 @@ macro_rules! field_testing_suite { end_timer!(start); } }; + + ($field: ident, "constants", $modulus_str: expr) => { + #[test] + fn test_primefield_constants() { + assert_eq!($field::MODULUS, $modulus_str); + assert_eq!( + $field::ROOT_OF_UNITY_INV, + $field::ROOT_OF_UNITY.invert().unwrap() + ); + assert_eq!($field::from(2) * $field::TWO_INV, $field::ONE); + if $field::S != 0 { + assert_eq!( + $field::ROOT_OF_UNITY.pow_vartime([1 << $field::S]), + $field::one() + ); + assert_eq!( + $field::DELTA, + $field::MULTIPLICATIVE_GENERATOR.pow([1u64 << $field::S]) + ); + } + } + }; }