From ccff4dc87791af9f7d928b45a146802a6f6c42a2 Mon Sep 17 00:00:00 2001 From: David Nevado Date: Sun, 22 Sep 2024 12:49:34 +0200 Subject: [PATCH] chore: cleanup --- src/bls12381/fq2.rs | 7 ++++--- src/bn256/fq2.rs | 38 ++++---------------------------------- src/pluto_eris/fp2.rs | 3 +-- src/secp256k1/fp.rs | 2 -- src/tests/field/serde.rs | 25 +------------------------ 5 files changed, 10 insertions(+), 65 deletions(-) diff --git a/src/bls12381/fq2.rs b/src/bls12381/fq2.rs index 40579fef..21757810 100644 --- a/src/bls12381/fq2.rs +++ b/src/bls12381/fq2.rs @@ -65,17 +65,18 @@ impl ExtField for Fq2 { mod test { use super::*; - use crate::{arith_test, f2_tests, legendre_test, serde_test, test, test_frobenius}; + use crate::{ + arith_test, constants_test, f2_tests, legendre_test, serde_test, test, test_frobenius, + }; use rand_core::RngCore; - // constants_test!(Fq2); + constants_test!(Fq2); arith_test!(Fq2); legendre_test!(Fq2); test!(arith, Fq2, sqrt_test, 1000); serde_test!(Fq2); - // test_uniform_bytes!(Fq2, 1000, L 96); f2_tests!(Fq2, Fq); test_frobenius!(Fq2, Fq, 20); diff --git a/src/bn256/fq2.rs b/src/bn256/fq2.rs index 61c72427..d1618871 100644 --- a/src/bn256/fq2.rs +++ b/src/bn256/fq2.rs @@ -68,52 +68,22 @@ impl ExtField for Fq2 { mod test { use super::*; - use crate::{arith_test, f2_tests, legendre_test, serde_test, test, test_frobenius}; + use crate::{ + arith_test, constants_test, f2_tests, legendre_test, serde_test, test, test_frobenius, + }; use rand_core::RngCore; - // constants_test!(Fq2); - + constants_test!(Fq2); arith_test!(Fq2); legendre_test!(Fq2); test!(arith, Fq2, sqrt_test, 1000); serde_test!(Fq2); - // test_uniform_bytes!(Fq2, 1000, L 96); f2_tests!(Fq2, Fq); test_frobenius!(Fq2, Fq, 20); #[test] - fn test_fq2_squaring() { - let mut a = Fq2 { - c0: Fq::one(), - c1: Fq::one(), - }; // u + 1 - a.square_assign(); - assert_eq!( - a, - Fq2 { - c0: Fq::zero(), - c1: Fq::one() + Fq::one(), - } - ); // 2u - - let mut a = Fq2 { - c0: Fq::zero(), - c1: Fq::one(), - }; // u - a.square_assign(); - assert_eq!(a, { - let neg1 = -Fq::one(); - Fq2 { - c0: neg1, - c1: Fq::zero(), - } - }); // -1 - } - - #[test] - fn test_fq2_mul_nonresidue() { let e = Fq2::random(rand_core::OsRng); let a0 = e.mul_by_nonresidue(); diff --git a/src/pluto_eris/fp2.rs b/src/pluto_eris/fp2.rs index d8676cda..5dd98d12 100644 --- a/src/pluto_eris/fp2.rs +++ b/src/pluto_eris/fp2.rs @@ -80,7 +80,7 @@ impl ExtField for Fp2 { mod test { use super::*; - use crate::{arith_test, constants_test, legendre_test, serde_test, test, test_uniform_bytes}; + use crate::{arith_test, constants_test, legendre_test, serde_test, test}; use rand_core::RngCore; constants_test!(Fp2); @@ -90,7 +90,6 @@ mod test { test!(arith, Fp2, sqrt_test, 1000); serde_test!(Fp2); - test_uniform_bytes!(Fp2, 1000, L 128); crate::f2_tests!(Fp2, Fp); crate::test_frobenius!(Fp2, Fp, 20); diff --git a/src/secp256k1/fp.rs b/src/secp256k1/fp.rs index 5fae7bfd..b2bec7d5 100644 --- a/src/secp256k1/fp.rs +++ b/src/secp256k1/fp.rs @@ -28,11 +28,9 @@ mod test { use crate::{arith_test, constants_test, legendre_test, serde_test, test, test_uniform_bytes}; constants_test!(Fp); - arith_test!(Fp); legendre_test!(Fp); test!(arith, Fp, sqrt_test, 1000); - serde_test!(Fp PrimeFieldBits); test_uniform_bytes!(Fp, 1000, L 64, L 48); } diff --git a/src/tests/field/serde.rs b/src/tests/field/serde.rs index 834d9e88..f65086e3 100644 --- a/src/tests/field/serde.rs +++ b/src/tests/field/serde.rs @@ -51,29 +51,6 @@ where } } -// Test from_raw_bytes / to_raw_bytes -// TODO: Is this test redundant? It uses methods that are not exposed. -// IMO this can be removed. -// fn test_serialization_check(mut rng: impl RngCore, n: usize) { -// use crate::serde::SerdeObject; -// const LIMBS: usize = F::SIZE / 8; -// // failure check -// for _ in 0..n { -// let rand_word = [(); LIMBS].map(|_| rng.next_u64()); -// let a = F(rand_word); -// let rand_bytes = a.to_raw_bytes(); - -// match F::is_less_than_modulus(&rand_word) { -// false => { -// assert!(F::from_raw_bytes(&rand_bytes).is_none()); -// } -// _ => { -// assert_eq!(F::from_raw_bytes(&rand_bytes), Some(a)); -// } -// } -// } -// } - #[cfg(feature = "bits")] pub(crate) fn test_bits(mut rng: impl RngCore, n: usize) { for _ in 0..n { @@ -104,7 +81,7 @@ macro_rules! serde_test { } // Out of serde_tests macro, since it needs to be tested for several generic L. -// Tests from_uniform_bytes. +// Tests from_uniform_bytes **for prime fields only**. pub(crate) fn from_uniform_bytes_test( mut rng: impl RngCore, n: usize,