From 8e0438adb11cdbcb404116a63f51970369102c62 Mon Sep 17 00:00:00 2001 From: Marcos Villagra <71292159+mdvillagra@users.noreply.github.com> Date: Mon, 25 Sep 2023 10:31:17 -0400 Subject: [PATCH] changed order of evaluation to avoid underflow (#575) --- math/src/unsigned_integer/element.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/src/unsigned_integer/element.rs b/math/src/unsigned_integer/element.rs index fea84a98e..d76e54ec7 100644 --- a/math/src/unsigned_integer/element.rs +++ b/math/src/unsigned_integer/element.rs @@ -707,7 +707,7 @@ impl UnsignedInteger { while i > 0 { i -= 1; if NUM_LIMBS - 1 <= i * 2 { - let index = 2 * i - NUM_LIMBS + 1; + let index = 2 * i + 1 - NUM_LIMBS; let cs = lo.limbs[index] as u128 + a.limbs[i] as u128 * a.limbs[i] as u128 + c; c = cs >> 64; lo.limbs[index] = cs as u64;