Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions compiler/noirc_evaluator/src/acir/acir_context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1076,23 +1076,11 @@ impl<F: AcirField> AcirContext<F> {
&mut self,
lhs: AcirVar,
rhs: AcirVar,
typ: NumericType,
bit_size: u32,
predicate: AcirVar,
) -> Result<AcirVar, RuntimeError> {
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`.
Expand Down Expand Up @@ -1182,8 +1170,11 @@ impl<F: AcirField> AcirContext<F> {
// - 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::<F>(max_bits));
Expand Down
18 changes: 13 additions & 5 deletions compiler/noirc_evaluator/src/acir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<FieldElement>();
let result = match binary.operator {
BinaryOp::Add { .. } => self.acir_context.add_var(lhs, rhs),
BinaryOp::Sub { .. } => self.acir_context.sub_var(lhs, rhs),
Expand All @@ -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"
),
Expand Down
Loading