diff --git a/acvm-repo/acir_field/src/field_element.rs b/acvm-repo/acir_field/src/field_element.rs index 81582b9fbac..2c14aefee2a 100644 --- a/acvm-repo/acir_field/src/field_element.rs +++ b/acvm-repo/acir_field/src/field_element.rs @@ -174,10 +174,6 @@ impl FieldElement { self.0 } - fn is_negative(&self) -> bool { - self.neg().num_bits() < self.num_bits() - } - fn fits_in_u128(&self) -> bool { self.num_bits() <= 128 } @@ -278,7 +274,10 @@ impl AcirField for FieldElement { } fn to_i128(self) -> i128 { - let is_negative = self.is_negative(); + // Negative integers are represented by the range [p + i128::MIN, p) whilst + // positive integers are represented by the range [0, i128::MAX). + // We can then differentiate positive from negative values by their MSB. + let is_negative = self.neg().num_bits() < self.num_bits(); let bytes = if is_negative { self.neg() } else { self }.to_be_bytes(); i128::from_be_bytes(bytes[16..32].try_into().unwrap()) * if is_negative { -1 } else { 1 } }