diff --git a/tooling/ast_fuzzer/fuzz/src/targets/orig_vs_morph.rs b/tooling/ast_fuzzer/fuzz/src/targets/orig_vs_morph.rs index 0ba20d1908b..5c90230f587 100644 --- a/tooling/ast_fuzzer/fuzz/src/targets/orig_vs_morph.rs +++ b/tooling/ast_fuzzer/fuzz/src/targets/orig_vs_morph.rs @@ -17,9 +17,9 @@ use noirc_frontend::monomorphization::ast::{ }; pub fn fuzz(u: &mut Unstructured) -> eyre::Result<()> { - let rules = rules::all(); - let max_rewrites = 10; let config = default_config(u)?; + let rules = rules::collect(&config); + let max_rewrites = 10; let inputs = CompareMorph::arb( u, config, @@ -365,8 +365,8 @@ mod rules { } /// Construct all rules that we can apply on a program. - pub fn all() -> Vec { - vec![ + pub fn collect(config: &Config) -> Vec { + let mut rules = vec![ num_add_zero(), num_sub_zero(), num_mul_one(), @@ -374,10 +374,16 @@ mod rules { bool_or_self(), bool_xor_self(), bool_xor_rand(), - num_commute(), any_inevitable(), int_break_up(), - ] + ]; + if config.avoid_overflow { + // When we can overflowing instruction, then swapping around the LHS and RHS + // of a binary operation can swap failures. We could visit the expressions to rule + // out a potential failure on both sides at the same time, or just skip this rule. + rules.push(num_commute()); + } + rules } /// Transform any numeric value `x` into `x ` @@ -629,7 +635,8 @@ mod helpers { use crate::targets::orig_vs_morph::VariableContext; /// Check if an expression can have a side effect, in which case duplicating or reordering it could - /// change the behavior of the program. + /// change the behavior of the program. This doesn't concern about failures, just observable changes + /// the state of the program. pub(super) fn has_side_effect(expr: &Expression) -> bool { expr::exists(expr, |expr| { matches!( diff --git a/tooling/ast_fuzzer/src/compare/compiled.rs b/tooling/ast_fuzzer/src/compare/compiled.rs index 7f81f3e8bf4..0bba573469b 100644 --- a/tooling/ast_fuzzer/src/compare/compiled.rs +++ b/tooling/ast_fuzzer/src/compare/compiled.rs @@ -206,11 +206,15 @@ impl Comparable for NargoErrorWithTypes { ( SolvingError(OpcodeResolutionError::UnsatisfiedConstrain { .. }, _), AssertionFailed(_, _, _), - ) => msg2.as_ref().is_some_and(|msg| msg.contains("divide by zero")), + ) => msg2.as_ref().is_some_and(|msg| { + msg.contains("divide by zero") || msg.contains("divisor of zero") + }), ( AssertionFailed(_, _, _), SolvingError(OpcodeResolutionError::UnsatisfiedConstrain { .. }, _), - ) => msg1.is_some_and(|msg| msg.contains("divide by zero")), + ) => msg1.is_some_and(|msg| { + msg.contains("divide by zero") || msg.contains("divisor of zero") + }), ( SolvingError(OpcodeResolutionError::IndexOutOfBounds { .. }, _), AssertionFailed(_, _, _), diff --git a/tooling/ast_fuzzer/src/lib.rs b/tooling/ast_fuzzer/src/lib.rs index 1166864a6e6..115c6da2ee8 100644 --- a/tooling/ast_fuzzer/src/lib.rs +++ b/tooling/ast_fuzzer/src/lib.rs @@ -103,7 +103,7 @@ impl Default for Config { ("assign", 30), ("if", 10), ("match", 10), - ("for", 30), + ("for", 37), ("let", 25), ("call", 5), ("constrain", 4),