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
9 changes: 8 additions & 1 deletion tooling/ast_fuzzer/minimizer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The minimizer is an experimental tool with the primary goal to help reduce the size of Noir examples found
by the AST fuzzer that fail due to some reason, and require minimization before a bug ticket can be opened.

It relies on [cvise](https://github.com/marxin/cvise?tab=readme-ov-file) to try and make the Noir program

Check warning on line 6 in tooling/ast_fuzzer/minimizer/README.md

View workflow job for this annotation

GitHub Actions / Code

Unknown word (cvise)
smaller, while preserving some error message we receive from `nargo`.

The tool requires [Docker](https://docs.docker.com/engine/install/) being installed on the developer machine.
Expand All @@ -12,8 +12,8 @@

### Build a Docker image

`cvise` has binaries published for Linux; in the interest of being cross platform, we build a Docker image

Check warning on line 15 in tooling/ast_fuzzer/minimizer/README.md

View workflow job for this annotation

GitHub Actions / Code

Unknown word (cvise)
that contains `cvise` and `nargo`, which it repeatedly invokes to compile the Noir code.

Check warning on line 16 in tooling/ast_fuzzer/minimizer/README.md

View workflow job for this annotation

GitHub Actions / Code

Unknown word (cvise)

Execute the following command to build the image. This needs to be done every time `nargo` itself changes:

Expand All @@ -29,12 +29,19 @@
With that, we need to invoke the `minimize.sh` script as follows:

```shell
tooling/ast_fuzzer/minimizer/scripts/minimize.sh "<error-message>" execute path/to/main.nr
tooling/ast_fuzzer/minimizer/scripts/minimize.sh "<error-message>" execute [compile options...] path/to/main.nr
```

The command can be `compile` or `execute`. The latter needs a `Prover.toml` file, which can be given following
the path to `main.nr`, or it is assumed to be in the parent directory of `main.nr`, like a regular Noir project.

You can also supply `nargo` compilation options. This is useful for cases where we want to minimize a program
that only fails under certain compilation conditions (e.g., experimental features, different compilation pipeline). Example usage:

```shell
tooling/ast_fuzzer/minimizer/scripts/minimize.sh "<error-message>" execute -Zenums --minimal-ssa path/to/main.nr
```

The script makes a `main.nr.bkp` backup file, because the tool will minimize the Noir code in-place.

## Examples
Expand Down Expand Up @@ -192,13 +199,13 @@

```console
❯ tooling/ast_fuzzer/minimizer/scripts/scripts/minimize.sh "condition value is not a boolean: MismatchedBitSize" execute test_programs/execution_success/fuzz_testing/src/main.nr
C-Vise cannot run because the interestingness test does not return

Check warning on line 202 in tooling/ast_fuzzer/minimizer/README.md

View workflow job for this annotation

GitHub Actions / Code

Unknown word (interestingness)
zero. Please ensure that it does so not only in the directory where
you are invoking C-Vise, but also in an arbitrary temporary
directory containing only the files that are being reduced. In other
words, running these commands:

DIR=`mktemp -d`

Check warning on line 208 in tooling/ast_fuzzer/minimizer/README.md

View workflow job for this annotation

GitHub Actions / Code

Unknown word (mktemp)
cp /noir/main.nr $DIR
cd $DIR
/noir/check.sh
Expand All @@ -209,14 +216,14 @@
to the same file that is passed as an argument to C-Vise.
```

So `cvise` is telling us that the script the tool prepared did not return 0, which is because it looked for an error message that did not appear in the output.

Check warning on line 219 in tooling/ast_fuzzer/minimizer/README.md

View workflow job for this annotation

GitHub Actions / Code

Unknown word (cvise)

Try again, with the correct message:

```console
❯ tooling/ast_fuzzer/minimizer/scripts/minimize.sh "Bit size for rhs 254 does not match op bit size 1" execute test_programs/execution_success/fuzz_testing/src/main.nr
00:00:00 INFO ===< 9 >===
00:00:00 INFO running 14 interestingness tests in parallel

Check warning on line 226 in tooling/ast_fuzzer/minimizer/README.md

View workflow job for this annotation

GitHub Actions / Code

Unknown word (interestingness)
00:00:00 INFO INITIAL PASSES
00:00:00 INFO ===< BlankPass >===
00:00:00 INFO ===< LinesPass::0 >===
Expand All @@ -239,7 +246,7 @@
The end result is much smaller:

<details>
<summary>`main.nr` minimized by `cvise`</summary>

Check warning on line 249 in tooling/ast_fuzzer/minimizer/README.md

View workflow job for this annotation

GitHub Actions / Code

Unknown word (cvise)

```rust
global G_A: [bool] = [true];
Expand Down Expand Up @@ -359,7 +366,7 @@
};
a = -216918869032603336751134960482740787067;
};
"OULD"

Check warning on line 369 in tooling/ast_fuzzer/minimizer/README.md

View workflow job for this annotation

GitHub Actions / Code

Unknown word (OULD)
};
true
}
Expand Down Expand Up @@ -393,7 +400,7 @@
```console
❯ tooling/ast_fuzzer/minimizer/scripts/minimize.sh "Cannot return references from an if expression" execute $PWD/test_programs/execution_success/fuzz_testing/src/main.nr
00:00:00 INFO ===< 10 >===
00:00:00 INFO running 14 interestingness tests in parallel

Check warning on line 403 in tooling/ast_fuzzer/minimizer/README.md

View workflow job for this annotation

GitHub Actions / Code

Unknown word (interestingness)
00:00:00 INFO INITIAL PASSES
00:00:00 INFO ===< BlankPass >===
00:00:00 INFO ===< LinesPass::0 >===
Expand Down
3 changes: 2 additions & 1 deletion tooling/ast_fuzzer/minimizer/scripts/docker-entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ set -e
# If it's not present, it means the latest reduction step was not interesting.
# We could have the script read env vars on the fly instead of splicing them in verbatim,
# but this is perhaps closer to how `cvise` wants an parameterless script.

cat > check.sh <<EOF
nargo new test_project
cp main.nr test_project/src
cp /noir/Prover.toml test_project
cd test_project
nargo $CMD 2>&1 | grep "$MSG"
nargo $CMD $OPTIONS 2>&1 | grep "$MSG"
EOF

chmod +x check.sh
Expand Down
23 changes: 21 additions & 2 deletions tooling/ast_fuzzer/minimizer/scripts/minimize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

function usage {
echo $1
echo "usage: ./minimize.sh 'error message' (compile|execute) path/to/main.nr [path/to/Prover.toml]"
echo "usage: ./minimize.sh 'error message' (compile|execute) [compile options...] path/to/main.nr [path/to/Prover.toml]"
exit 1
}

Expand All @@ -16,7 +16,25 @@ if [ -z "$CMD" ]; then
usage "missing command"
fi

MAIN_PATH=$1; shift
# Grab everything until we hit a .nr file. These are our compile options.
OPTIONS=()
while [[ $# -gt 0 ]]; do
case "$1" in
*.nr)
MAIN_PATH=$1
shift
break
;;
*)
OPTIONS+=("$1")
shift
;;
esac
done

# Build a string from the array of options
OPTIONS="${OPTIONS[*]}"
Comment thread
vezenovm marked this conversation as resolved.

if [ -z "$MAIN_PATH" ]; then
usage "missing path to main.nr"
fi
Expand Down Expand Up @@ -47,4 +65,5 @@ exec docker run --init -it --rm \
-v "$PROVER_PATH":/noir/Prover.toml \
-e MSG="$MSG" \
-e CMD="$CMD" \
-e OPTIONS="$OPTIONS" \
noir-minimizer
Loading