diff --git a/compiler/noirc_evaluator/src/acir/acir_context/mod.rs b/compiler/noirc_evaluator/src/acir/acir_context/mod.rs index 64d4ad31231..cc0c74b1384 100644 --- a/compiler/noirc_evaluator/src/acir/acir_context/mod.rs +++ b/compiler/noirc_evaluator/src/acir/acir_context/mod.rs @@ -1076,23 +1076,11 @@ impl AcirContext { &mut self, lhs: AcirVar, rhs: AcirVar, - typ: NumericType, bit_size: u32, predicate: AcirVar, ) -> Result { - match typ { - NumericType::Unsigned { .. } => { - let (_, remainder_var) = - self.euclidean_division_var(lhs, rhs, bit_size, predicate)?; - Ok(remainder_var) - } - NumericType::Signed { .. } => { - unreachable!("Signed modulo should have been removed before ACIRgen") - } - NumericType::NativeField => { - unreachable!("cannot module fields. This should have been caught by the frontend") - } - } + let (_, remainder_var) = self.euclidean_division_var(lhs, rhs, bit_size, predicate)?; + Ok(remainder_var) } /// Constrains the `AcirVar` variable to be of type `NumericType`. @@ -1182,8 +1170,11 @@ impl AcirContext { // - We assert at the beginning that `2^{max_bits+1}` does not overflow the field, so neither does c. // Ensure that 2^{max_bits + 1} is less than the field size - // - // TODO(https://github.com/noir-lang/noir/issues/10257): perhaps this should be a user error, instead of an assert + // In fact, `more_than_eq_var` is either called directly with the bit_size of an unsigned + // type, or via `less_than_var` which is also called with the bit_size of an unsigned type + // or with 64, so we can also assume that max_bits is at most 128, in which case the field + // size should be 129 or less for this assertion to fail. + assert!(max_bits <= 128); assert!(max_bits + 1 < F::max_num_bits()); let two_max_bits = self.add_constant(power_of_two::(max_bits)); diff --git a/compiler/noirc_evaluator/src/acir/mod.rs b/compiler/noirc_evaluator/src/acir/mod.rs index 63a00d05f0d..33344f2e470 100644 --- a/compiler/noirc_evaluator/src/acir/mod.rs +++ b/compiler/noirc_evaluator/src/acir/mod.rs @@ -717,7 +717,6 @@ impl<'a> Context<'a> { panic!("Checked signed operations should all be removed before ACIRgen") } - let bit_count = num_type.bit_size::(); let result = match binary.operator { BinaryOp::Add { .. } => self.acir_context.add_var(lhs, rhs), BinaryOp::Sub { .. } => self.acir_context.sub_var(lhs, rhs), @@ -727,15 +726,24 @@ impl<'a> Context<'a> { // this Eq instruction is being used for a constrain statement BinaryOp::Eq => self.acir_context.eq_var(lhs, rhs), BinaryOp::Lt => match num_type { - NumericType::Signed { .. } => { - panic!("ICE - signed less than should have been removed before ACIRgen") + NumericType::Unsigned { bit_size } => { + self.acir_context.less_than_var(lhs, rhs, bit_size) + } + _ => { + panic!("ICE: unexpected binary type for Lt operation: {num_type:?}") } - _ => self.acir_context.less_than_var(lhs, rhs, bit_count), }, BinaryOp::Xor => self.acir_context.xor_var(lhs, rhs, num_type), BinaryOp::And => self.acir_context.and_var(lhs, rhs, num_type), BinaryOp::Or => self.acir_context.or_var(lhs, rhs, num_type), - BinaryOp::Mod => self.acir_context.modulo_var(lhs, rhs, num_type, bit_count, predicate), + BinaryOp::Mod => match num_type { + NumericType::Unsigned { bit_size } => { + self.acir_context.modulo_var(lhs, rhs, bit_size, predicate) + } + _ => { + panic!("ICE: unexpected binary type for Mod operation: {num_type:?}") + } + }, BinaryOp::Shl | BinaryOp::Shr => unreachable!( "ICE - bit shift operators do not exist in ACIR and should have been replaced" ),