perf(scalar_mul_le): use add_mixed for conditional subtraction

This commit is contained in:
Youssef El Housni
2025-01-31 14:49:02 -05:00
parent e6bcd582aa
commit b120f9e111

View File

@@ -350,10 +350,10 @@ where
// We can convert to projective safely because the result is guaranteed to be
// non-zero by the condition on `affine_bits.len()`, and by the fact
// that `accumulator` is non-zero
let result = accumulator.into_projective();
*mul_result += accumulator.into_projective();
// If bits[0] is 0, then we have to subtract `self`; else, we subtract zero.
let subtrahend = bits[0].select(&Self::zero(), &initial_acc_value)?;
*mul_result += result - subtrahend;
let neg = NonZeroAffineVar::new(initial_acc_value.x, initial_acc_value.y.negate()?);
*mul_result = bits[0].select(mul_result, &mul_result.add_mixed(&neg)?)?;
// Now, let's finish off the rest of the bits using our complete formulae
for bit in proj_bits.iter().rev().skip(1).rev() {