diff --git a/compiler/noirc_evaluator/src/ssa/opt/remove_bit_shifts.rs b/compiler/noirc_evaluator/src/ssa/opt/remove_bit_shifts.rs index e8e23bbb79..6cc5239e7a 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/remove_bit_shifts.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/remove_bit_shifts.rs @@ -134,7 +134,7 @@ impl Context<'_> { let pow = self.pow(base, rhs); let pow = self.insert_cast(pow, typ); - // Unchecked mul because predicate is 0 or 1 + // Unchecked mul because `predicate` will be 1 or 0 ( FieldElement::max_num_bits(), self.insert_binary(predicate, BinaryOp::Mul { unchecked: true }, pow), @@ -218,8 +218,8 @@ impl Context<'_> { let rhs_bits = rhs_bits[0]; let one = self.field_constant(FieldElement::one()); let mut r = one; + // All operations are unchecked as we're acting on Field types (which are always unchecked) for i in 1..bit_size + 1 { - // All of these operations are unchecked because they deal with fields let r_squared = self.insert_binary(r, BinaryOp::Mul { unchecked: true }, r); let a = self.insert_binary(r_squared, BinaryOp::Mul { unchecked: true }, lhs); let idx = self.field_constant(FieldElement::from((bit_size - i) as i128)); diff --git a/compiler/noirc_evaluator/src/ssa/ssa_gen/context.rs b/compiler/noirc_evaluator/src/ssa/ssa_gen/context.rs index d9da8c94d9..f54abf4760 100644 --- a/compiler/noirc_evaluator/src/ssa/ssa_gen/context.rs +++ b/compiler/noirc_evaluator/src/ssa/ssa_gen/context.rs @@ -329,6 +329,7 @@ impl<'a> FunctionContext<'a> { BinaryOp::Mul { unchecked: true }, two_complement, ); + // Unchecked addition because either `positive_predicate` or `negative_predicate` will be 0 self.builder.insert_binary( positive_predicate, BinaryOp::Add { unchecked: true }, @@ -488,7 +489,7 @@ impl<'a> FunctionContext<'a> { //Check the result has the same sign as its inputs let result_sign = self.builder.insert_binary(result, BinaryOp::Lt, half_width); let sign_diff = self.builder.insert_binary(result_sign, BinaryOp::Eq, lhs_sign); - // Unchecked mul because sign_diff is a boolean + // Unchecked multiplication because boolean inputs let sign_diff_with_predicate = self.builder.insert_binary( sign_diff, BinaryOp::Mul { unchecked: true }, @@ -522,7 +523,7 @@ impl<'a> FunctionContext<'a> { let not_same = self.builder.insert_not(same_sign); let not_same_sign_field = self.insert_safe_cast(not_same, NumericType::unsigned(bit_size), location); - // This shouldn't overflow so it's unchecked + // TODO: should this be unchecked? let positive_maximum_with_offset = self.builder.insert_binary( half_width, BinaryOp::Add { unchecked: true },