Skip to content

Commit

Permalink
removing one more iter_mut in the denominators
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminsavage committed Mar 16, 2024
1 parent cf90dcc commit c8be623
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions ipa-core/src/protocol/ipa_prf/malicious_security/lagrange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
u128::from(N::U64) < F::PRIME.into(),
"Field size {} is not large enough to hold {} points",
F::BITS,
N::USIZE
F::PRIME.into(),

Check warning on line 40 in ipa-core/src/protocol/ipa_prf/malicious_security/lagrange.rs

View check run for this annotation

Codecov / codecov/patch

ipa-core/src/protocol/ipa_prf/malicious_security/lagrange.rs#L40

Added line #L40 was not covered by tests
N::U64
);

// assertion that table is not too large for the stack
assert!(<F as Serializable>::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 }
}
}

Expand Down

0 comments on commit c8be623

Please sign in to comment.