From 3acfb5b7d2d5ad1a4f00b1cb8d5077bba7c4a03f Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Sat, 2 Jul 2022 14:22:17 -0400 Subject: [PATCH] Use a do-while in multiexp, first to please a friend, and then to annoy them It's also legitimately cleaner code. --- crypto/multiexp/src/batch.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crypto/multiexp/src/batch.rs b/crypto/multiexp/src/batch.rs index 81765563..95a09df5 100644 --- a/crypto/multiexp/src/batch.rs +++ b/crypto/multiexp/src/batch.rs @@ -22,11 +22,12 @@ impl BatchVerifier where ::Scalar: PrimeF let u = if self.0.len() == 0 { G::Scalar::one() } else { - let mut weight = G::Scalar::random(&mut *rng); + let mut weight; // Ensure it's non-zero, as a zero scalar would cause this item to pass no matter what - while weight.is_zero().into() { + while { weight = G::Scalar::random(&mut *rng); - } + weight.is_zero().into() + } {} weight }; self.0.push((id, pairs.into_iter().map(|(scalar, point)| (scalar * u, point)).collect()));