diff --git a/crates/emulated/src/field_ops.rs b/crates/emulated/src/field_ops.rs index d0e3616..7844b39 100644 --- a/crates/emulated/src/field_ops.rs +++ b/crates/emulated/src/field_ops.rs @@ -9,7 +9,7 @@ use bellpepper_core::num::{AllocatedNum, Num}; use bellpepper_core::{ConstraintSystem, LinearCombination, SynthesisError}; use ff::{PrimeField, PrimeFieldBits}; use num_bigint::BigInt; -use num_traits::{One, Zero}; +use num_traits::One; use crate::field_element::{EmulatedFieldElement, EmulatedFieldParams, EmulatedLimbs}; use crate::util::{bigint_to_scalar, decompose, recompose}; @@ -435,11 +435,11 @@ where if a.is_constant() && b.is_constant() { let a_int = BigInt::from(a); let b_int = BigInt::from(b); - let mut res_int = a_int - b_int; - while res_int < BigInt::zero() { - res_int += P::modulus(); - } - res_int = res_int.rem(P::modulus()); + let res_int = if a_int > b_int { + (a_int - b_int).rem(P::modulus()) + } else { + P::modulus() - (b_int - a_int).rem(P::modulus()) + }; return Ok(Self::from(&res_int)); }