From 60e15d516052068f2c702c28f647b654ead9abd2 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Tue, 26 Jul 2022 05:31:15 -0400 Subject: [PATCH] Remove re-calculation of N Moves most BP assertions to debug. --- coins/monero/src/ringct/bulletproofs/core.rs | 9 ++++----- coins/monero/src/ringct/bulletproofs/scalar_vector.rs | 6 +++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/coins/monero/src/ringct/bulletproofs/core.rs b/coins/monero/src/ringct/bulletproofs/core.rs index 8988c595..04852ecc 100644 --- a/coins/monero/src/ringct/bulletproofs/core.rs +++ b/coins/monero/src/ringct/bulletproofs/core.rs @@ -19,8 +19,8 @@ use crate::{ }; pub(crate) const MAX_M: usize = 16; -pub(crate) const MAX_N: usize = 64; -const MAX_MN: usize = MAX_M * MAX_N; +const N: usize = 64; +const MAX_MN: usize = MAX_M * N; // Wrap random_scalar and hash_to_scalar into dalek_ff_group fn random_scalar(rng: &mut R) -> Scalar { @@ -49,7 +49,7 @@ lazy_static! { } pub(crate) fn vector_exponent(a: &ScalarVector, b: &ScalarVector) -> EdwardsPoint { - assert_eq!(a.len(), b.len()); + debug_assert_eq!(a.len(), b.len()); (a * &G_i[.. a.len()]) + (b * &H_i[.. b.len()]) } @@ -69,8 +69,7 @@ pub(crate) fn prove( let gamma = ScalarVector(commitments.iter().cloned().map(|c| Scalar(c.mask)).collect()); let logN = 6; - let N = 1 << logN; - assert_eq!(N, 64); + debug_assert_eq!(N, 1 << logN); let mut logM = 0; let mut M; diff --git a/coins/monero/src/ringct/bulletproofs/scalar_vector.rs b/coins/monero/src/ringct/bulletproofs/scalar_vector.rs index c9812c8f..53b1c73e 100644 --- a/coins/monero/src/ringct/bulletproofs/scalar_vector.rs +++ b/coins/monero/src/ringct/bulletproofs/scalar_vector.rs @@ -26,7 +26,7 @@ macro_rules! math_op { impl $Op for ScalarVector { type Output = ScalarVector; fn $op(self, b: ScalarVector) -> ScalarVector { - assert_eq!(self.len(), b.len()); + debug_assert_eq!(self.len(), b.len()); ScalarVector(self.0.iter().zip(b.0.iter()).map($f).collect()) } } @@ -34,7 +34,7 @@ macro_rules! math_op { impl $Op<&ScalarVector> for &ScalarVector { type Output = ScalarVector; fn $op(self, b: &ScalarVector) -> ScalarVector { - assert_eq!(self.len(), b.len()); + debug_assert_eq!(self.len(), b.len()); ScalarVector(self.0.iter().zip(b.0.iter()).map($f).collect()) } } @@ -87,7 +87,7 @@ pub(crate) fn inner_product(a: &ScalarVector, b: &ScalarVector) -> Scalar { impl Mul<&[EdwardsPoint]> for &ScalarVector { type Output = EdwardsPoint; fn mul(self, b: &[EdwardsPoint]) -> EdwardsPoint { - assert_eq!(self.len(), b.len()); + debug_assert_eq!(self.len(), b.len()); multiexp(&self.0.iter().cloned().zip(b.iter().cloned()).collect::>()) } }