From 86a5ba378cc839e05b9c3d76ac75668232a3b4dd Mon Sep 17 00:00:00 2001 From: jfecher Date: Fri, 22 Sep 2023 12:15:35 -0500 Subject: [PATCH] fix: Fix subtract with underflow in flattening pass (#2796) --- compiler/noirc_evaluator/src/ssa/opt/flatten_cfg.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg.rs b/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg.rs index d57c2cc7933..7700c7051ab 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg.rs @@ -461,7 +461,7 @@ impl<'f> Context<'f> { let mut get_element = |array, typevars, len| { // The smaller slice is filled with placeholder data. Codegen for slice accesses must // include checks against the dynamic slice length so that this placeholder data is not incorrectly accessed. - if (len - 1) < index_value.to_u128() as usize { + if len <= index_value.to_u128() as usize { let zero = FieldElement::zero(); self.inserter.function.dfg.make_constant(zero, Type::field()) } else {