Skip to content

Commit

Permalink
fix: address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnevadoc committed Sep 25, 2024
1 parent ccff4dc commit fa3bb0e
Show file tree
Hide file tree
Showing 22 changed files with 66 additions and 51 deletions.
6 changes: 4 additions & 2 deletions src/bls12381/fq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ impl ExtField for Fq {
#[cfg(test)]
mod test {
use super::*;
use crate::{arith_test, constants_test, legendre_test, serde_test, test, test_uniform_bytes};
use crate::{
arith_test, constants_test, from_uniform_bytes_test, legendre_test, serde_test, test,
};

constants_test!(Fq);

Expand All @@ -46,7 +48,7 @@ mod test {
test!(arith, Fq, sqrt_test, 1000);

serde_test!(Fq PrimeFieldBits);
test_uniform_bytes!(Fq, 1000, L 64, L 96);
from_uniform_bytes_test!(Fq, 1000, L 64, L 96);

#[test]
fn test_fq_mul_nonresidue() {
Expand Down
4 changes: 2 additions & 2 deletions src/bls12381/fq12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ mod test {
};
}
use super::*;
use crate::{arith_test, setup_f12_test_funcs, test, test_frobenius};
use crate::{arith_test, frobenius_test, setup_f12_test_funcs, test};
use ff::Field;
use rand::RngCore;

Expand All @@ -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, Fq, 8);
frobenius_test!(Fq12, Fq, 8);
}
6 changes: 3 additions & 3 deletions src/bls12381/fq2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ mod test {

use super::*;
use crate::{
arith_test, constants_test, f2_tests, legendre_test, serde_test, test, test_frobenius,
arith_test, constants_test, f2_test, frobenius_test, legendre_test, serde_test, test,
};
use rand_core::RngCore;

Expand All @@ -78,8 +78,8 @@ mod test {

serde_test!(Fq2);

f2_tests!(Fq2, Fq);
test_frobenius!(Fq2, Fq, 20);
f2_test!(Fq2, Fq);
frobenius_test!(Fq2, Fq, 20);

#[test]
fn test_fq2_mul_nonresidue() {
Expand Down
4 changes: 2 additions & 2 deletions src/bls12381/fq6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ pub const FROBENIUS_COEFF_FQ6_C2: [Fq2; 6] = [
#[cfg(test)]
mod test {
use super::*;
use crate::{arith_test, setup_f6_test_funcs, test, test_frobenius};
use crate::{arith_test, frobenius_test, setup_f6_test_funcs, test};
use rand_core::RngCore;

macro_rules! test_fq6 {
Expand All @@ -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, Fq, 10);
frobenius_test!(Fq6, Fq, 10);

#[test]
fn test_fq6_mul_nonresidue() {
Expand Down
6 changes: 4 additions & 2 deletions src/bls12381/fr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ crate::impl_from_bool!(Fr);
#[cfg(test)]
mod test {
use super::Fr;
use crate::{arith_test, constants_test, legendre_test, serde_test, test, test_uniform_bytes};
use crate::{
arith_test, constants_test, from_uniform_bytes_test, legendre_test, serde_test, test,
};

constants_test!(Fr);

Expand All @@ -34,5 +36,5 @@ mod test {
test!(arith, Fr, sqrt_test, 1000);

serde_test!(Fr PrimeFieldBits);
test_uniform_bytes!(Fr, 1000, L 64);
from_uniform_bytes_test!(Fr, 1000, L 64);
}
6 changes: 4 additions & 2 deletions src/bn256/fq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ impl ExtField for Fq {
#[cfg(test)]
mod test {
use super::Fq;
use crate::{arith_test, constants_test, legendre_test, serde_test, test, test_uniform_bytes};
use crate::{
arith_test, constants_test, from_uniform_bytes_test, legendre_test, serde_test, test,
};

constants_test!(Fq);

Expand All @@ -45,5 +47,5 @@ mod test {
test!(arith, Fq, sqrt_test, 1000);

serde_test!(Fq PrimeFieldBits);
test_uniform_bytes!(Fq, 1000, L 64, L 48);
from_uniform_bytes_test!(Fq, 1000, L 64, L 48);
}
6 changes: 2 additions & 4 deletions src/bn256/fq12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,15 @@ mod test {
};
}
use super::*;
use crate::{arith_test, setup_f12_test_funcs, test, test_frobenius};
use crate::{arith_test, frobenius_test, setup_f12_test_funcs, test};
use ff::Field;
use rand::RngCore;

arith_test!(Fq12);
// TODO Compile problems with derive_serde feature
// serde_test!(Fq12);

// F12 specific
setup_f12_test_funcs!(Fq12, Fq6, Fq2);
test_fq12!(f12_mul_by_014_, 500);
test_fq12!(f12_mul_by_034_, 500);
test_frobenius!(Fq12, Fq, 8);
frobenius_test!(Fq12, Fq, 8);
}
6 changes: 3 additions & 3 deletions src/bn256/fq2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ mod test {

use super::*;
use crate::{
arith_test, constants_test, f2_tests, legendre_test, serde_test, test, test_frobenius,
arith_test, constants_test, f2_test, frobenius_test, legendre_test, serde_test, test,
};
use rand_core::RngCore;

Expand All @@ -80,8 +80,8 @@ mod test {

serde_test!(Fq2);

f2_tests!(Fq2, Fq);
test_frobenius!(Fq2, Fq, 20);
f2_test!(Fq2, Fq);
frobenius_test!(Fq2, Fq, 20);

#[test]
fn test_fq2_mul_nonresidue() {
Expand Down
5 changes: 2 additions & 3 deletions src/bn256/fq6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ pub const FROBENIUS_COEFF_FQ6_C2: [Fq2; 6] = [
#[cfg(test)]
mod test {
use super::*;
use crate::{arith_test, setup_f6_test_funcs, test, test_frobenius};
use crate::{arith_test, frobenius_test, setup_f6_test_funcs, test};
use rand_core::RngCore;

macro_rules! test_fq6 {
Expand All @@ -226,6 +226,5 @@ 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, Fq, 10);
// test_uniform_bytes!(Fq6, 1000, L 96);
frobenius_test!(Fq6, Fq, 10);
}
6 changes: 4 additions & 2 deletions src/bn256/fr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ mod table_tests;
#[cfg(test)]
mod test {
use super::Fr;
use crate::{arith_test, constants_test, legendre_test, serde_test, test, test_uniform_bytes};
use crate::{
arith_test, constants_test, from_uniform_bytes_test, legendre_test, serde_test, test,
};

constants_test!(Fr);

Expand All @@ -55,5 +57,5 @@ mod test {
test!(arith, Fr, sqrt_test, 1000);

serde_test!(Fr PrimeFieldBits);
test_uniform_bytes!(Fr, 1000, L 64, L 48);
from_uniform_bytes_test!(Fr, 1000, L 64, L 48);
}
6 changes: 4 additions & 2 deletions src/pluto_eris/fp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ impl ExtField for Fp {
#[cfg(test)]
mod test {
use super::Fp;
use crate::{arith_test, constants_test, legendre_test, serde_test, test, test_uniform_bytes};
use crate::{
arith_test, constants_test, from_uniform_bytes_test, legendre_test, serde_test, test,
};

constants_test!(Fp);

Expand All @@ -51,5 +53,5 @@ mod test {
test!(arith, Fp, sqrt_test, 1000);

serde_test!(Fp PrimeFieldBits);
test_uniform_bytes!(Fp, 1000, L 64, L 72, L 112);
from_uniform_bytes_test!(Fp, 1000, L 64, L 72, L 112);
}
6 changes: 2 additions & 4 deletions src/pluto_eris/fp12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,17 +268,15 @@ mod test {
};
}
use super::*;
use crate::{arith_test, setup_f12_test_funcs, test, test_frobenius};
use crate::{arith_test, frobenius_test, setup_f12_test_funcs, test};
use ff::Field;
use rand::RngCore;

arith_test!(Fp12);
// TODO Compile problems with derive_serde feature
// serde_test!(fp12);

// F12 specific
setup_f12_test_funcs!(Fp12, Fp6, Fp2);
test_fp12!(f12_mul_by_014_, 500);
test_fp12!(f12_mul_by_034_, 500);
test_frobenius!(Fp12, Fp, 8);
frobenius_test!(Fp12, Fp, 8);
}
4 changes: 2 additions & 2 deletions src/pluto_eris/fp2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ mod test {

serde_test!(Fp2);

crate::f2_tests!(Fp2, Fp);
crate::test_frobenius!(Fp2, Fp, 20);
crate::f2_test!(Fp2, Fp);
crate::frobenius_test!(Fp2, Fp, 20);

#[test]
fn test_fp2_squaring() {
Expand Down
4 changes: 2 additions & 2 deletions src/pluto_eris/fp6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ pub(crate) const FROBENIUS_COEFF_FP6_C2: [Fp2; 6] = [
#[cfg(test)]
mod test {
use super::*;
use crate::{arith_test, setup_f6_test_funcs, test, test_frobenius};
use crate::{arith_test, frobenius_test, setup_f6_test_funcs, test};
use rand_core::RngCore;

macro_rules! test_fp6 {
Expand All @@ -273,7 +273,7 @@ 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, Fp, 10);
frobenius_test!(Fp6, Fp, 10);

#[test]
fn test_fp6_mul_nonresidue() {
Expand Down
6 changes: 4 additions & 2 deletions src/pluto_eris/fq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ crate::impl_from_bool!(Fq);
#[cfg(test)]
mod test {
use super::Fq;
use crate::{arith_test, constants_test, legendre_test, serde_test, test, test_uniform_bytes};
use crate::{
arith_test, constants_test, from_uniform_bytes_test, legendre_test, serde_test, test,
};

constants_test!(Fq);

Expand All @@ -34,5 +36,5 @@ mod test {
test!(arith, Fq, sqrt_test, 1000);

serde_test!(Fq PrimeFieldBits);
test_uniform_bytes!(Fq, 1000, L 64, L 72, L 112);
from_uniform_bytes_test!(Fq, 1000, L 64, L 72, L 112);
}
6 changes: 4 additions & 2 deletions src/secp256k1/fp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ crate::impl_from_bool!(Fp);
#[cfg(test)]
mod test {
use super::Fp;
use crate::{arith_test, constants_test, legendre_test, serde_test, test, test_uniform_bytes};
use crate::{
arith_test, constants_test, from_uniform_bytes_test, legendre_test, serde_test, test,
};

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);
from_uniform_bytes_test!(Fp, 1000, L 64, L 48);
}
6 changes: 4 additions & 2 deletions src/secp256k1/fq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ crate::impl_from_bool!(Fq);
#[cfg(test)]
mod test {
use super::Fq;
use crate::{arith_test, constants_test, legendre_test, serde_test, test, test_uniform_bytes};
use crate::{
arith_test, constants_test, from_uniform_bytes_test, legendre_test, serde_test, test,
};

constants_test!(Fq);

Expand All @@ -34,5 +36,5 @@ mod test {
test!(arith, Fq, sqrt_test, 1000);

serde_test!(Fq);
test_uniform_bytes!(Fq, 1000, L 64, L 48);
from_uniform_bytes_test!(Fq, 1000, L 64, L 48);
}
6 changes: 4 additions & 2 deletions src/secp256r1/fp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ crate::impl_from_bool!(Fp);
#[cfg(test)]
mod test {
use super::Fp;
use crate::{arith_test, constants_test, legendre_test, serde_test, test, test_uniform_bytes};
use crate::{
arith_test, constants_test, from_uniform_bytes_test, legendre_test, serde_test, test,
};

constants_test!(Fp);

Expand All @@ -34,5 +36,5 @@ mod test {
test!(arith, Fp, sqrt_test, 1000);

serde_test!(Fp PrimeFieldBits);
test_uniform_bytes!(Fp, 1000, L 64, L 48);
from_uniform_bytes_test!(Fp, 1000, L 64, L 48);
}
6 changes: 4 additions & 2 deletions src/secp256r1/fq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ crate::impl_from_bool!(Fq);
#[cfg(test)]
mod test {
use super::Fq;
use crate::{arith_test, constants_test, legendre_test, serde_test, test, test_uniform_bytes};
use crate::{
arith_test, constants_test, from_uniform_bytes_test, legendre_test, serde_test, test,
};

constants_test!(Fq);

Expand All @@ -34,5 +36,5 @@ mod test {
test!(arith, Fq, sqrt_test, 1000);

serde_test!(Fq PrimeFieldBits);
test_uniform_bytes!(Fq, 1000, L 64, L 48);
from_uniform_bytes_test!(Fq, 1000, L 64, L 48);
}
4 changes: 2 additions & 2 deletions src/tests/field/extensions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// F2 tests
#[macro_export]
macro_rules! f2_tests {
macro_rules! f2_test {
($ext_field:ident,
$base_field:ident) => {
#[test]
Expand Down Expand Up @@ -177,7 +177,7 @@ macro_rules! setup_f12_test_funcs {
}

#[macro_export]
macro_rules! test_frobenius {
macro_rules! frobenius_test {
($field:ident, $base: ident, $size: expr) => {
fn test_frobenius(mut rng: impl RngCore, n: usize) {
for _ in 0..n {
Expand Down
1 change: 1 addition & 0 deletions src/tests/field/legendre.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use ff::PrimeField;
use rand::RngCore;

pub(crate) fn legendre_symbol_test<F: PrimeField + Legendre>(mut rng: impl RngCore, n: usize) {
assert_eq!(F::ZERO.legendre(), 0);
for _ in 0..n {
let a = F::random(&mut rng);
if a.legendre() == -1 {
Expand Down
7 changes: 3 additions & 4 deletions src/tests/field/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ macro_rules! serde_test {
($field:ident) => {
test!(serde, $field, from_to_repr_test, 100_000);
test!(serde, $field, from_to_raw_bytes_test, 100_000);
// test!($field, test_serialization_check, 1_000_000);
#[cfg(feature = "derive_serde")]
test!(serde, $field, derive_serde_test, 100_000);
};
Expand Down Expand Up @@ -107,7 +106,7 @@ pub(crate) fn from_uniform_bytes_test<F: PrimeField, const L: usize>(
}

#[macro_export]
macro_rules! test_uniform_bytes {
macro_rules! from_uniform_bytes_test {
($field:ident, $size:expr, L $L: expr ) => {
paste::paste! {
#[test]
Expand All @@ -122,7 +121,7 @@ macro_rules! test_uniform_bytes {
};

($field:ident,$size:expr, L $L:expr, $(L $rest:expr),+ ) => {
test_uniform_bytes!( $field, $size, L $L );
test_uniform_bytes! { $field, $size, $(L $rest),+ }
from_uniform_bytes_test!( $field, $size, L $L );
from_uniform_bytes_test! { $field, $size, $(L $rest),+ }
};
}

0 comments on commit fa3bb0e

Please sign in to comment.