From 9a5f5448d6d30a2d06179d98c085c1f547b6b338 Mon Sep 17 00:00:00 2001 From: Tom French Date: Thu, 18 Jan 2024 10:12:59 +0000 Subject: [PATCH 1/2] fix: maintain type when simplifying `x ^ x` --- compiler/noirc_evaluator/src/ssa/ir/instruction.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/noirc_evaluator/src/ssa/ir/instruction.rs b/compiler/noirc_evaluator/src/ssa/ir/instruction.rs index 457fe41de9..dbad562b6f 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/instruction.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/instruction.rs @@ -1002,7 +1002,7 @@ impl Binary { return SimplifyResult::SimplifiedTo(self.lhs); } if dfg.resolve(self.lhs) == dfg.resolve(self.rhs) { - let zero = dfg.make_constant(FieldElement::zero(), Type::bool()); + let zero = dfg.make_constant(FieldElement::zero(), operand_type); return SimplifyResult::SimplifiedTo(zero); } } From 2184ad2992140af75bfa0a83f687d3d1e5eb15c4 Mon Sep 17 00:00:00 2001 From: Tom French Date: Thu, 18 Jan 2024 10:29:07 +0000 Subject: [PATCH 2/2] chore: add regression test for xor issue --- .../noir_test_success/regression_4080/Nargo.toml | 5 +++++ .../noir_test_success/regression_4080/Prover.toml | 1 + .../noir_test_success/regression_4080/src/main.nr | 8 ++++++++ 3 files changed, 14 insertions(+) create mode 100644 test_programs/noir_test_success/regression_4080/Nargo.toml create mode 100644 test_programs/noir_test_success/regression_4080/Prover.toml create mode 100644 test_programs/noir_test_success/regression_4080/src/main.nr diff --git a/test_programs/noir_test_success/regression_4080/Nargo.toml b/test_programs/noir_test_success/regression_4080/Nargo.toml new file mode 100644 index 0000000000..a38baf389d --- /dev/null +++ b/test_programs/noir_test_success/regression_4080/Nargo.toml @@ -0,0 +1,5 @@ +[package] +name = "regression_4080" +type = "bin" +authors = [""] +[dependencies] diff --git a/test_programs/noir_test_success/regression_4080/Prover.toml b/test_programs/noir_test_success/regression_4080/Prover.toml new file mode 100644 index 0000000000..0e5dfd5638 --- /dev/null +++ b/test_programs/noir_test_success/regression_4080/Prover.toml @@ -0,0 +1 @@ +x = "5" diff --git a/test_programs/noir_test_success/regression_4080/src/main.nr b/test_programs/noir_test_success/regression_4080/src/main.nr new file mode 100644 index 0000000000..781d3e33ea --- /dev/null +++ b/test_programs/noir_test_success/regression_4080/src/main.nr @@ -0,0 +1,8 @@ +// This test checks that `var^var` is assigned the correct type. +// https://github.com/noir-lang/noir/issues/4080 + +#[test(should_fail_with = "attempt to add with overflow")] +fn main() { + let var1: u8 = ((255 + 1) ^ (255 + 1)) - ((255 + 1) - (255 + 1)); + assert_eq(var1, 0); +}