diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
commit | 9835e2ae736235810b4ea1c162ca5e65c547e770 (patch) | |
tree | 3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/ff/tests/derive.rs | |
parent | Releasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff) | |
download | rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip |
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/ff/tests/derive.rs')
-rw-r--r-- | vendor/ff/tests/derive.rs | 53 |
1 files changed, 51 insertions, 2 deletions
diff --git a/vendor/ff/tests/derive.rs b/vendor/ff/tests/derive.rs index bfa2cd2df..fa6ee20e9 100644 --- a/vendor/ff/tests/derive.rs +++ b/vendor/ff/tests/derive.rs @@ -38,10 +38,59 @@ mod full_limbs { } #[test] +fn constants() { + use ff::{Field, PrimeField}; + + assert_eq!( + Bls381K12Scalar::MODULUS, + "0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001", + ); + + assert_eq!( + Bls381K12Scalar::from(2) * Bls381K12Scalar::TWO_INV, + Bls381K12Scalar::ONE, + ); + + assert_eq!( + Bls381K12Scalar::ROOT_OF_UNITY * Bls381K12Scalar::ROOT_OF_UNITY_INV, + Bls381K12Scalar::ONE, + ); + + // ROOT_OF_UNITY^{2^s} mod m == 1 + assert_eq!( + Bls381K12Scalar::ROOT_OF_UNITY.pow(&[1u64 << Bls381K12Scalar::S, 0, 0, 0]), + Bls381K12Scalar::ONE, + ); + + // DELTA^{t} mod m == 1 + assert_eq!( + Bls381K12Scalar::DELTA.pow(&[ + 0xfffe5bfeffffffff, + 0x09a1d80553bda402, + 0x299d7d483339d808, + 0x73eda753, + ]), + Bls381K12Scalar::ONE, + ); +} + +#[test] +fn from_u128() { + use ff::{Field, PrimeField}; + + assert_eq!(Bls381K12Scalar::from_u128(1), Bls381K12Scalar::ONE); + assert_eq!(Bls381K12Scalar::from_u128(2), Bls381K12Scalar::from(2)); + assert_eq!( + Bls381K12Scalar::from_u128(u128::MAX), + Bls381K12Scalar::from_str_vartime("340282366920938463463374607431768211455").unwrap(), + ); +} + +#[test] fn batch_inversion() { use ff::{BatchInverter, Field}; - let one = Bls381K12Scalar::one(); + let one = Bls381K12Scalar::ONE; // [1, 2, 3, 4] let values: Vec<_> = (0..4) @@ -55,7 +104,7 @@ fn batch_inversion() { // Test BatchInverter::invert_with_external_scratch { let mut elements = values.clone(); - let mut scratch_space = vec![Bls381K12Scalar::zero(); elements.len()]; + let mut scratch_space = vec![Bls381K12Scalar::ZERO; elements.len()]; BatchInverter::invert_with_external_scratch(&mut elements, &mut scratch_space); for (a, a_inv) in values.iter().zip(elements.into_iter()) { assert_eq!(*a * a_inv, one); |