diff --git a/crates/nargo_cli/tests/compile_failure/div_by_zero_modulo/Nargo.toml b/crates/nargo_cli/tests/compile_failure/div_by_zero_modulo/Nargo.toml new file mode 100644 index 00000000000..d3b69d8c41b --- /dev/null +++ b/crates/nargo_cli/tests/compile_failure/div_by_zero_modulo/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "div_by_zero_modulo" +type = "bin" +authors = [""] +compiler_version = "0.10.5" + +[dependencies] \ No newline at end of file diff --git a/crates/nargo_cli/tests/compile_failure/div_by_zero_modulo/Prover.toml b/crates/nargo_cli/tests/compile_failure/div_by_zero_modulo/Prover.toml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/nargo_cli/tests/compile_failure/div_by_zero_modulo/src/main.nr b/crates/nargo_cli/tests/compile_failure/div_by_zero_modulo/src/main.nr new file mode 100644 index 00000000000..f20c39486e0 --- /dev/null +++ b/crates/nargo_cli/tests/compile_failure/div_by_zero_modulo/src/main.nr @@ -0,0 +1,7 @@ +fn main() { + let a: u32 = 6; + let b = 3; + let c = 0; + let res = (a*b) % c; + assert(res != 5); +} \ No newline at end of file diff --git a/crates/noirc_evaluator/src/ssa/ir/instruction.rs b/crates/noirc_evaluator/src/ssa/ir/instruction.rs index e57ae55209b..f7bb4e704e0 100644 --- a/crates/noirc_evaluator/src/ssa/ir/instruction.rs +++ b/crates/noirc_evaluator/src/ssa/ir/instruction.rs @@ -634,7 +634,8 @@ impl Binary { // If the rhs of a division is zero, attempting to evaluate the divison will cause a compiler panic. // Thus, we do not evaluate this divison as we want to avoid triggering a panic, // and division by zero should be handled by laying down constraints during ACIR generation. - if matches!(self.operator, BinaryOp::Div) && rhs == FieldElement::zero() { + if matches!(self.operator, BinaryOp::Div | BinaryOp::Mod) && rhs == FieldElement::zero() + { return SimplifyResult::None; } return match self.eval_constants(dfg, lhs, rhs, operand_type) {