Skip to content

Commit

Permalink
add: test vectors for test_from_u512
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnevadoc committed Nov 23, 2023
1 parent a566667 commit 0b18f73
Show file tree
Hide file tree
Showing 2 changed files with 220 additions and 50 deletions.
135 changes: 110 additions & 25 deletions src/pluto_eris/fields/fp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,31 +445,116 @@ mod test {
assert_ne!(Fp::ZETA * Fp::ZETA, Fp::ONE);
}

// TODO Compute valid test cases
// #[test]
// fn test_from_u512() {
// assert_eq!(
// Fp::from_raw([
// 0x0000000000000000,
// 0x0000000000000000,
// 0x0000000000000000,
// 0x7e7140b5196b9e6f,
// 0x9abac9e4157b6172,
// 0xf04bc41062fd7322,
// 0x1185fa9c9fef6326,
// ]),
// Fp::from_u512([
// 0xaaaaaaaaaaaaaaaa,
// 0xaaaaaaaaaaaaaaaa,
// 0xaaaaaaaaaaaaaaaa,
// 0xaaaaaaaaaaaaaaaa,
// 0xaaaaaaaaaaaaaaaa,
// 0xaaaaaaaaaaaaaaaa,
// 0xaaaaaaaaaaaaaaaa,
// 0xaaaaaaaaaaaaaaaa
// ])
// );
// }
#[test]
fn test_from_u512() {
const N_VECS: usize = 10;
let expected_results = [
Fp::from_raw([
0x93638251ffeffed3,
0x4d32f4d20020be11,
0x9c39ee168df390f0,
0xaeef355d313cce4b,
0xc97c592ef6030675,
0xd7bc83d286537318,
0x01d4a87b24f91154,
]),
Fp::from_raw([
0x63e0a8f1beefc612,
0xbb28d56dae950a42,
0x5264111f4a5ea3ad,
0xbebe71c829f662f7,
0xa760708568d6060c,
0x617d8b0cda3f6328,
0x03096ea964e009c0,
]),
Fp::from_raw([
0xdeaedbda63b3e431,
0x65892bc45ec174c8,
0x83ad8d96c18556c7,
0x3fce5f9d2c537fbe,
0x001666753a4972d1,
0x9f7f457a48d6d322,
0x20b2fadc6bf4004d,
]),
Fp::from_raw([
0x6eea9cbd68b174cf,
0x63aa4abda18f73e6,
0x0a6ccc999b1c7864,
0x0f90b43928625cc2,
0x55f541b0680af76b,
0x2045de539849b035,
0x1d5d7b5f6e8cc333,
]),
Fp::from_raw([
0x673df0f69b71a763,
0x215a1362cfe53e1e,
0x7028d2b3766b0f40,
0x996ac521f57a7f05,
0x5006663a5c8cea53,
0xd7ead2b7c71e460d,
0x0f7c36b781cba9ed,
]),
Fp::from_raw([
0x2eed10e8f00b189d,
0xe6c79fb4600e94d4,
0x2a9066b23daac6d4,
0x476d275780b553fe,
0xc3f2296317f71051,
0xb1d2bb5373270c43,
0x0e18a3597be61302,
]),
Fp::from_raw([
0x7fbbc6b3e494ca68,
0x2afcc7335152430b,
0x93d5bd3acbccf3b3,
0x61a76bb383622b8c,
0x93efc4d40d7fac4d,
0x0a791ad7698655a7,
0x22b10d5c1090eec8,
]),
Fp::from_raw([
0x596eec60211ad67b,
0xf23f57b9f9db8c07,
0x33e66f105ffc5e45,
0xb10ef45226f3ae42,
0xb98a559ccfc0ba32,
0x819ba919d0b6e9b5,
0x20f73876330a90e8,
]),
Fp::from_raw([
0xbade57a48e2d9868,
0xe61829ffe983fcfc,
0xd0d080b774c31996,
0xa1d712ef206b4a2f,
0x7957f20173071cf6,
0xf850f49359458652,
0x17ba9f9aa08b9ee2,
]),
Fp::from_raw([
0xd0239c8282ccc372,
0xfa20a695ee8f6288,
0x269f2ef315e029a5,
0xcc915da35e10b4e6,
0x8406f6977aadce0f,
0xd7d5d8bc4497465a,
0x08ce8bee1323d4f9,
]),
];

let mut seeded_rng = XorShiftRng::seed_from_u64(0u64);
let uniform_bytes = std::iter::from_fn(|| {
let mut bytes = [0u8; 64];
seeded_rng.fill_bytes(&mut bytes);
Some(bytes)
})
.take(N_VECS)
.collect::<Vec<_>>();

for i in 0..N_VECS {
let p = Fp::from_uniform_bytes(&uniform_bytes[i]);
assert_eq!(expected_results[i], p);
}
}

#[test]
#[cfg(feature = "bits")]
Expand Down
135 changes: 110 additions & 25 deletions src/pluto_eris/fields/fq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,31 +436,116 @@ mod test {
assert_eq!(Fq::DELTA, Fq::MULTIPLICATIVE_GENERATOR.pow([1u64 << Fq::S]));
}

// TODO Compute valid test cases
// #[test]
// fn test_from_u512() {
// assert_eq!(
// Fq::from_raw([
// 0x0000000000000000,
// 0x0000000000000000,
// 0x0000000000000000,
// 0x7e7140b5196b9e6f,
// 0x9abac9e4157b6172,
// 0xf04bc41062fd7322,
// 0x1185fa9c9fef6326,
// ]),
// Fq::from_u512([
// 0xaaaaaaaaaaaaaaaa,
// 0xaaaaaaaaaaaaaaaa,
// 0xaaaaaaaaaaaaaaaa,
// 0xaaaaaaaaaaaaaaaa,
// 0xaaaaaaaaaaaaaaaa,
// 0xaaaaaaaaaaaaaaaa,
// 0xaaaaaaaaaaaaaaaa,
// 0xaaaaaaaaaaaaaaaa
// ])
// );
// }
#[test]
fn test_from_u512() {
const N_VECS: usize = 10;
let expected_results = [
Fq::from_raw([
0x93638251ffeffed3,
0xb17ab6ae332352b4,
0xbf2731af91057325,
0x7b700ef5a22260d0,
0xc97c59318d325250,
0xd7bc83d286537318,
0x01d4a87b24f91154,
]),
Fq::from_raw([
0x63e0a8f1beefc612,
0x080f69572a9ddaae,
0xb9ff1cf0e1f7c067,
0xd8d8bf5b522bc48b,
0xa7607085c7065359,
0x617d8b0cda3f6328,
0x03096ea964e009c0,
]),
Fq::from_raw([
0x5eaedbda63b3e431,
0x90ebbfa6f11a9266,
0x4528cf4d506c9f9b,
0x8c6ac679e9ac3856,
0x001666755d9c2c57,
0x9f7f457a48d6d322,
0x20b2fadc6bf4004d,
]),
Fq::from_raw([
0xeeea9cbd68b174cf,
0x84af9e4ce5a781a5,
0x3578772b5b482647,
0x6b202eb54b7df723,
0x55f541b1436b7660,
0x2045de539849b035,
0x1d5d7b5f6e8cc333,
]),
Fq::from_raw([
0xe73df0f69b71a763,
0xbccfb84010979d9d,
0x1ce3c87be8bf3247,
0x695fde61877cb617,
0x5006663bd0944209,
0xd7ead2b7c71e460d,
0x0f7c36b781cba9ed,
]),
Fq::from_raw([
0xaeed10e8f00b189d,
0x5190807038915743,
0x90b840c0a13b0307,
0x20fa8cc52c3a9a28,
0xc3f229646be29c1d,
0xb1d2bb5373270c43,
0x0e18a3597be61302,
]),
Fq::from_raw([
0xffbbc6b3e494ca68,
0x30d4a100158c1751,
0x0328dae560dff403,
0x1495c3ce50cce340,
0x93efc4d4d6ea0079,
0x0a791ad7698655a7,
0x22b10d5c1090eec8,
]),
Fq::from_raw([
0xd96eec60211ad67b,
0x4d081a969b3d8488,
0x57c9b5abbeec4cf0,
0x13ced15637e4b0eb,
0xb98a559f49b0071c,
0x819ba919d0b6e9b5,
0x20f73876330a90e8,
]),
Fq::from_raw([
0xbade57a48e2d9868,
0xc688e43e21f9d2fc,
0x848a82da9e1d75dc,
0xae5f4536b9d60aa7,
0x7957f2028c96467b,
0xf850f49359458652,
0x17ba9f9aa08b9ee2,
]),
Fq::from_raw([
0xd0239c8282ccc372,
0x4a777ad0b66181ea,
0x53737d5f19e61bfc,
0x5340b579fe7c4c83,
0x8406f69a0f89f90a,
0xd7d5d8bc4497465a,
0x08ce8bee1323d4f9,
]),
];

let mut seeded_rng = XorShiftRng::seed_from_u64(0u64);
let uniform_bytes = std::iter::from_fn(|| {
let mut bytes = [0u8; 64];
seeded_rng.fill_bytes(&mut bytes);
Some(bytes)
})
.take(N_VECS)
.collect::<Vec<_>>();

for i in 0..N_VECS {
let q = Fq::from_uniform_bytes(&uniform_bytes[i]);
assert_eq!(expected_results[i], q);
}
}

#[test]
#[cfg(feature = "bits")]
Expand Down

0 comments on commit 0b18f73

Please sign in to comment.