diff --git a/crates/noirc_evaluator/src/ssa/ir/instruction.rs b/crates/noirc_evaluator/src/ssa/ir/instruction.rs index 433bf2013a7..30d9027180f 100644 --- a/crates/noirc_evaluator/src/ssa/ir/instruction.rs +++ b/crates/noirc_evaluator/src/ssa/ir/instruction.rs @@ -593,6 +593,11 @@ impl Binary { let zero = dfg.make_constant(FieldElement::zero(), Type::bool()); return SimplifyResult::SimplifiedTo(zero); } + if operand_type.is_unsigned() && rhs_is_zero { + // Unsigned values cannot be less than zero. + let zero = dfg.make_constant(FieldElement::zero(), Type::bool()); + return SimplifyResult::SimplifiedTo(zero); + } } BinaryOp::And => { if lhs_is_zero || rhs_is_zero { diff --git a/crates/noirc_evaluator/src/ssa/ir/types.rs b/crates/noirc_evaluator/src/ssa/ir/types.rs index 38dd6125121..e8110f0901b 100644 --- a/crates/noirc_evaluator/src/ssa/ir/types.rs +++ b/crates/noirc_evaluator/src/ssa/ir/types.rs @@ -37,6 +37,11 @@ pub(crate) enum Type { } impl Type { + /// Returns whether the `Type` represents an unsigned numeric type. + pub(crate) fn is_unsigned(&self) -> bool { + matches!(self, Type::Numeric(NumericType::Unsigned { .. })) + } + /// Create a new signed integer type with the given amount of bits. pub(crate) fn signed(bit_size: u32) -> Type { Type::Numeric(NumericType::Signed { bit_size })