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
21 changes: 14 additions & 7 deletions tooling/ast_fuzzer/fuzz/src/targets/orig_vs_morph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -365,19 +365,25 @@ mod rules {
}

/// Construct all rules that we can apply on a program.
pub fn all() -> Vec<Rule> {
vec![
pub fn collect(config: &Config) -> Vec<Rule> {
let mut rules = vec![
num_add_zero(),
num_sub_zero(),
num_mul_one(),
num_div_one(),
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 <op> <rhs>`
Expand Down Expand Up @@ -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!(
Expand Down
8 changes: 6 additions & 2 deletions tooling/ast_fuzzer/src/compare/compiled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_, _, _),
Expand Down
2 changes: 1 addition & 1 deletion tooling/ast_fuzzer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl Default for Config {
("assign", 30),
("if", 10),
("match", 10),
("for", 30),
("for", 37),
("let", 25),
("call", 5),
("constrain", 4),
Expand Down
Loading