Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "div_by_zero_modulo"
type = "bin"
authors = [""]
compiler_version = "0.10.5"

[dependencies]
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn main() {
let a: u32 = 6;
let b = 3;
let c = 0;
let res = (a*b) % c;
assert(res != 5);
}
3 changes: 2 additions & 1 deletion crates/noirc_evaluator/src/ssa/ir/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down