From 43bf0193e93cc2d01bd51d9a4a5de101c29f73f9 Mon Sep 17 00:00:00 2001 From: Ben Savage Date: Sat, 16 Mar 2024 14:13:19 +1000 Subject: [PATCH] Removing one more iter_mut --- .../ipa_prf/malicious_security/lagrange.rs | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/ipa-core/src/protocol/ipa_prf/malicious_security/lagrange.rs b/ipa-core/src/protocol/ipa_prf/malicious_security/lagrange.rs index 7ef171fe2f..e95ccc4c12 100644 --- a/ipa-core/src/protocol/ipa_prf/malicious_security/lagrange.rs +++ b/ipa-core/src/protocol/ipa_prf/malicious_security/lagrange.rs @@ -35,23 +35,28 @@ where // assertion that field is large enough // when it is large enough, `F::try_from().unwrap()` below does not panic assert!( - F::BITS > usize::BITS - N::USIZE.leading_zeros(), + F::PRIME.into() < u128::from(N::U64), "Field size {} is not large enough to hold {} points", - F::BITS, - N::USIZE + F::PRIME.into(), + N::U64 ); // assertion that table is not too large for the stack assert!(::Size::USIZE * N::USIZE < 2024); - let mut denominator = GenericArray::generate(|_| F::ONE); - for (d, i) in denominator.iter_mut().zip(0u64..) { - for j in (0..N::U64).filter(|&j| i != j) { - *d *= F::try_from(u128::from(i)).unwrap() - F::try_from(u128::from(j)).unwrap(); - } - *d = d.invert(); + Self { + denominator: (0..u128::from(N::U64)) + .into_iter() + .map(|i| { + (0..u128::from(N::U64)) + .into_iter() + .filter(|&j| i != j) + .map(|j| F::try_from(i).unwrap() - F::try_from(j).unwrap()) + .fold(F::ONE, |acc, a| acc * a) + .invert() + }) + .collect(), } - Self { denominator } } }