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
4 changes: 2 additions & 2 deletions .github/workflows/nightly-fuzz-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ env:
# On regular PRs we run deterministic fuzzing to avoid flaky tests on CI.
# In the nightly tests we want to explore uncharted territory.
NOIR_AST_FUZZER_FORCE_NON_DETERMINISTIC: 1
# Tell arbtest how long it can run the tests for.
NOIR_AST_FUZZER_FORCE_BUDGET_SECS: 300
# How long should we run the fuzzing for, in seconds.
NOIR_AST_FUZZER_BUDGET_SECS: 300

jobs:
ast-fuzz:
Expand Down
4 changes: 2 additions & 2 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
Similar to the `stdlib` tests, some appear multiple times due to being executed with different compilation options. To only execute them once, by the default configuration, we can use the following variant:

```shell
cargo test -p nargo_cli --test execute forcebrillig_false_inliner_i64_min

Check warning on line 58 in TESTING.md

View workflow job for this annotation

GitHub Actions / Code

Unknown word (forcebrillig)
```

A specific test can be similarly executed by name, for example the following command executes all projects that include `sha256` in their name:
Expand Down Expand Up @@ -104,7 +104,7 @@
Should it find any problems, the test would print a _seed_ which we can use to replicate the test, for example:

```shell
NOIR_ARBTEST_SEED=0x6819c61400001000 cargo test -p noir_ast_fuzzer_fuzz comptime_vs_brillig
NOIR_AST_FUZZER_SEED=0x6819c61400001000 cargo test -p noir_ast_fuzzer_fuzz comptime_vs_brillig
```

When the `NOIR_ARBTEST_SEED` is present, or when there is a non-panicky error, the tests will print out the Noir AST and the `Prover.toml` file which can be used to reproduce the problem as an integration test.
When the `NOIR_AST_FUZZER_SEED` is present, or when there is a non-panicky error, the tests will print out the Noir AST and the `Prover.toml` file which can be used to reproduce the problem as an integration test.
2 changes: 1 addition & 1 deletion tooling/ast_fuzzer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ To get quick feedback about whether there are any easy-to-discover bugs, we can
cargo test -p noir_ast_fuzzer_fuzz arbtest
```

Unlike `cargo fuzz`, these don't "ramp up" the complexity of the code, but go full tilt from the beginning, and only run for a limited amount of time (e.g. 10 seconds). Upon failure they print a hexadecimal `seed`, which can be used with the `NOIR_ARBTEST_SEED` env var to replicate the error.
Unlike `cargo fuzz`, these don't "ramp up" the complexity of the code, but go full tilt from the beginning, and only run for a limited amount of time (e.g. 10 seconds). Upon failure they print a hexadecimal `seed`, which can be used with the `NOIR_AST_FUZZER_SEED` env var to replicate the error.

## Minimizing Noir

Expand Down
2 changes: 1 addition & 1 deletion tooling/ast_fuzzer/fuzz/src/targets/acir_vs_brillig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn fuzz(u: &mut Unstructured) -> eyre::Result<()> {
mod tests {

/// ```ignore
/// NOIR_ARBTEST_SEED=0x6819c61400001000 \
/// NOIR_AST_FUZZER_SEED=0x6819c61400001000 \
/// NOIR_AST_FUZZER_SHOW_AST=1 \
/// cargo test -p noir_ast_fuzzer_fuzz acir_vs_brillig
/// ```
Expand Down
2 changes: 1 addition & 1 deletion tooling/ast_fuzzer/fuzz/src/targets/comptime_vs_brillig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn fuzz(u: &mut Unstructured) -> eyre::Result<()> {
mod tests {

/// ```ignore
/// NOIR_ARBTEST_SEED=0x6819c61400001000 \
/// NOIR_AST_FUZZER_SEED=0x6819c61400001000 \
/// NOIR_AST_FUZZER_SHOW_AST=1 \
/// cargo test -p noir_ast_fuzzer_fuzz comptime_vs_brillig
/// ```
Expand Down
2 changes: 1 addition & 1 deletion tooling/ast_fuzzer/fuzz/src/targets/min_vs_full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn fuzz(u: &mut Unstructured) -> eyre::Result<()> {
#[cfg(test)]
mod tests {
/// ```ignore
/// NOIR_ARBTEST_SEED=0x6819c61400001000 \
/// NOIR_AST_FUZZER_SEED=0x6819c61400001000 \
/// NOIR_AST_FUZZER_SHOW_AST=1 \
/// cargo test -p noir_ast_fuzzer_fuzz min_vs_full
/// ```
Expand Down
21 changes: 11 additions & 10 deletions tooling/ast_fuzzer/fuzz/src/targets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,21 @@ mod tests {
use crate::bool_from_env;

fn seed_from_env() -> Option<u64> {
let Ok(seed) = std::env::var("NOIR_ARBTEST_SEED") else { return None };
let Ok(seed) = std::env::var("NOIR_AST_FUZZER_SEED") else { return None };
let seed = u64::from_str_radix(seed.trim_start_matches("0x"), 16)
.unwrap_or_else(|e| panic!("failed to parse seed '{seed}': {e}"));
Some(seed)
}

/// How long to let non-deterministic tests run for.
fn budget() -> Duration {
std::env::var("NOIR_AST_FUZZER_BUDGET_SECS").ok().map_or(BUDGET, |b| {
Duration::from_secs(
b.parse().unwrap_or_else(|e| panic!("failed to parse budget; got {b}: {e}")),
)
})
}

/// Check if we are running on CI.
fn is_running_in_ci() -> bool {
std::env::var("CI").is_ok()
Expand All @@ -36,20 +45,12 @@ mod tests {
bool_from_env("NOIR_AST_FUZZER_FORCE_NON_DETERMINISTIC")
}

/// How long to let non-deterministic tests run for.
fn budget() -> Duration {
std::env::var("NOIR_AST_FUZZER_BUDGET_SECS").ok().map_or(BUDGET, |b| {
let secs = b.parse().unwrap_or_else(|e| panic!("failed to parse budget; got {b}: {e}"));
Duration::from_secs(secs)
})
}

/// `cargo fuzz` takes a long time to ramp up the complexity.
/// This test catches crash bugs much faster.
///
/// Run it with for example:
/// ```ignore
/// NOIR_ARBTEST_SEED=0x6819c61400001000 \
/// NOIR_AST_FUZZER_SEED=0x6819c61400001000 \
/// NOIR_AST_FUZZER_SHOW_AST=1 \
/// cargo test -p noir_ast_fuzzer_fuzz acir_vs_brillig
/// ```
Expand Down
2 changes: 1 addition & 1 deletion tooling/ast_fuzzer/fuzz/src/targets/orig_vs_morph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ mod helpers {
#[cfg(test)]
mod tests {
/// ```ignore
/// NOIR_ARBTEST_SEED=0xb2fb5f0b00100000 \
/// NOIR_AST_FUZZER_SEED=0xb2fb5f0b00100000 \
/// NOIR_AST_FUZZER_SHOW_AST=1 \
/// cargo test -p noir_ast_fuzzer_fuzz orig_vs_morph
/// ```
Expand Down
2 changes: 1 addition & 1 deletion tooling/ast_fuzzer/fuzz/src/targets/pass_vs_prev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn clone_ssa(ssa: &Ssa) -> Ssa {
#[cfg(test)]
mod tests {
/// ```ignore
/// NOIR_ARBTEST_SEED=0x6819c61400001000 \
/// NOIR_AST_FUZZER_SEED=0x6819c61400001000 \
/// NOIR_AST_FUZZER_SHOW_AST=1 \
/// cargo test -p noir_ast_fuzzer_fuzz pass_vs_prev
/// ```
Expand Down
7 changes: 7 additions & 0 deletions tooling/ast_fuzzer/src/compare/compiled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ impl<P> CompareCompiled<P> {
let blackbox_solver = Bn254BlackBoxSolver(false);
let initial_witness = self.abi.encode(&self.input_map, None).wrap_err("abi::encode")?;

log::debug!(
"ABI input:\n{}",
noirc_abi::input_parser::Format::Toml
.serialize(&self.input_map, &self.abi)
.unwrap_or_else(|e| format!("failed to serialize inputs: {e}"))
);

let do_exec = |program| {
let mut print = Vec::new();

Expand Down
2 changes: 1 addition & 1 deletion tooling/ast_fuzzer/tests/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use noirc_evaluator::{
};

fn seed_from_env() -> Option<u64> {
let Ok(seed) = std::env::var("NOIR_ARBTEST_SEED") else { return None };
let Ok(seed) = std::env::var("NOIR_AST_FUZZER_SEED") else { return None };
let seed = u64::from_str_radix(seed.trim_start_matches("0x"), 16)
.unwrap_or_else(|e| panic!("failed to parse seed '{seed}': {e}"));
Some(seed)
Expand Down
2 changes: 1 addition & 1 deletion tooling/ast_fuzzer/tests/smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use noirc_abi::input_parser::Format;
use noirc_evaluator::{brillig::BrilligOptions, ssa};

fn seed_from_env() -> Option<u64> {
let Ok(seed) = std::env::var("NOIR_ARBTEST_SEED") else { return None };
let Ok(seed) = std::env::var("NOIR_AST_FUZZER_SEED") else { return None };
let seed = u64::from_str_radix(seed.trim_start_matches("0x"), 16)
.unwrap_or_else(|e| panic!("failed to parse seed '{seed}': {e}"));
Some(seed)
Expand Down
Loading