From faf1dab3d32e5b3bbd3c091570820fa2e57eca6f Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 10 Mar 2025 10:53:11 +0100 Subject: [PATCH] refactor: switch branch order --- .../pallet-bonded-coins/src/curves/polynomial.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pallets/pallet-bonded-coins/src/curves/polynomial.rs b/pallets/pallet-bonded-coins/src/curves/polynomial.rs index fe9b546d1..da1fec37d 100644 --- a/pallets/pallet-bonded-coins/src/curves/polynomial.rs +++ b/pallets/pallet-bonded-coins/src/curves/polynomial.rs @@ -153,7 +153,10 @@ where .ok_or(ArithmeticError::Overflow)?; // Calculate m * (high^2 + high * low + low^2) - let term1 = if self.m != Coefficient::from_num(0u8) { + let term1 = if self.m == Coefficient::from_num(0u8) { + // if m is 0 the product is 0 + Ok(self.m) + } else { let high_low_mul = high.checked_mul(low).ok_or(ArithmeticError::Overflow)?; let high_square = square(high)?; let low_square = square(low)?; @@ -166,18 +169,15 @@ where .ok_or(ArithmeticError::Overflow)?; self.m.checked_mul(cubic_term).ok_or(ArithmeticError::Overflow) - } else { - // if m is 0 the product is 0 - Ok(self.m) }?; // Calculate n * (high + low) - let term2 = if self.n != Coefficient::from_num(0u8) { - let high_plus_low = high.checked_add(low).ok_or(ArithmeticError::Overflow)?; - self.n.checked_mul(high_plus_low).ok_or(ArithmeticError::Overflow) - } else { + let term2 = if self.n == Coefficient::from_num(0u8) { // if n is 0 the product is 0 Ok(self.n) + } else { + let high_plus_low = high.checked_add(low).ok_or(ArithmeticError::Overflow)?; + self.n.checked_mul(high_plus_low).ok_or(ArithmeticError::Overflow) }?; // Final calculation with factored (high - low)