diff --git a/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs b/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs index 8e6237a40f4..a2a85498f16 100644 --- a/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs +++ b/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs @@ -596,10 +596,12 @@ impl GeneratedAcir { // we now have lhs+offset <= rhs <=> lhs_offset <= rhs_offset let bit_size = bit_size_u128(rhs_offset); - // r = 2^bit_size - rhs_offset + // r = 2^bit_size - rhs_offset -1, is of bit size 'bit_size' by construtction let r = (1_u128 << bit_size) - rhs_offset - 1; + // however, since it is a constant, we can compute it's actual bit size + let r_bit_size = bit_size_u128(r); // witness = lhs_offset + r - assert!(bits + bit_size < FieldElement::max_num_bits()); //we need to ensure lhs_offset + r does not overflow + assert!(bits + r_bit_size < FieldElement::max_num_bits()); //we need to ensure lhs_offset + r does not overflow let mut aor = lhs_offset; aor.q_c += FieldElement::from(r); let witness = self.get_or_create_witness(&aor); @@ -607,7 +609,6 @@ impl GeneratedAcir { self.range_constraint(witness, bit_size)?; return Ok(()); } - // General case: lhs_offset<=rhs <=> rhs-lhs_offset>=0 <=> rhs-lhs_offset is a 'bits' bit integer let sub_expression = rhs - &lhs_offset; //rhs-lhs_offset let w = self.create_witness_for_expression(&sub_expression); diff --git a/tooling/nargo_cli/tests/execution_success/regression_2854/Nargo.toml b/tooling/nargo_cli/tests/execution_success/regression_2854/Nargo.toml new file mode 100644 index 00000000000..33bd007d898 --- /dev/null +++ b/tooling/nargo_cli/tests/execution_success/regression_2854/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "regression_2854" +type = "bin" +authors = [""] +compiler_version = "0.1" + +[dependencies] diff --git a/tooling/nargo_cli/tests/execution_success/regression_2854/Prover.toml b/tooling/nargo_cli/tests/execution_success/regression_2854/Prover.toml new file mode 100644 index 00000000000..07890234a19 --- /dev/null +++ b/tooling/nargo_cli/tests/execution_success/regression_2854/Prover.toml @@ -0,0 +1 @@ +x = "3" diff --git a/tooling/nargo_cli/tests/execution_success/regression_2854/src/main.nr b/tooling/nargo_cli/tests/execution_success/regression_2854/src/main.nr new file mode 100644 index 00000000000..10ada5faeec --- /dev/null +++ b/tooling/nargo_cli/tests/execution_success/regression_2854/src/main.nr @@ -0,0 +1,3 @@ +fn main(x: Field) -> pub i127 { + x as i127 +} \ No newline at end of file