Skip to content

Commit 721dad4

Browse files
committed
qol for running fuzzer
1 parent 08e5e01 commit 721dad4

File tree

4 files changed

+136
-2
lines changed

4 files changed

+136
-2
lines changed

yarn-project/simulator/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"build": "yarn clean && tsc -b",
2121
"build:dev": "tsc -b --watch",
2222
"clean": "rm -rf ./dest .tsbuildinfo",
23-
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
23+
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}",
24+
"build:fuzzer": "tsc scripts/fuzzing/avm_simulator_bin.ts --outDir dest/scripts/fuzzing --module commonjs --target es2022 --esModuleInterop --allowSyntheticDefaultImports --resolveJsonModule --skipLibCheck"
2425
},
2526
"inherits": [
2627
"../package.common.json"

yarn-project/simulator/scripts/fuzzing/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
Coverage based fuzzing AVM vs Brillig based on [ssa_fuzzer](https://github.com/noir-lang/noir/tree/master/tooling/ssa_fuzzer)
44

5+
# Requirements
6+
1) Cargo Fuzz: `cargo install cargo-fuzz`
7+
2) Rust Nightly compiler: `rustup install nightly`
8+
59
## Overview
610
How fuzz loop looks like:
711
1) Fuzzer generates Noir [SSA](https://en.wikipedia.org/wiki/Static_single-assignment_form), compiles it into Brillig bytecode and executes it
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Colors for output
5+
RED='\033[0;31m'
6+
GREEN='\033[0;32m'
7+
YELLOW='\033[1;33m'
8+
NC='\033[0m' # No Color
9+
10+
# Get the git root directory
11+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
12+
GIT_ROOT="$(cd "$SCRIPT_DIR" && git rev-parse --show-toplevel 2>/dev/null || echo "")"
13+
14+
# Default paths (relative to git root)
15+
DEFAULT_NOIR_ROOT="$GIT_ROOT/noir/noir-repo"
16+
DEFAULT_TRANSPILER_BIN="$GIT_ROOT/avm-transpiler/target/release/avm-transpiler"
17+
DEFAULT_SIMULATOR_BIN="$GIT_ROOT/yarn-project/simulator/dest/scripts/fuzzing/avm_simulator_bin.cjs"
18+
19+
# Usage information
20+
usage() {
21+
echo "Usage: $0 [OPTIONS]"
22+
echo ""
23+
echo "Options:"
24+
echo " --noir-path PATH Path to the Noir repository root"
25+
echo " Default: $DEFAULT_NOIR_ROOT"
26+
echo ""
27+
echo " --transpiler-path PATH Path to the avm_transpiler binary"
28+
echo " Default: $DEFAULT_TRANSPILER_BIN"
29+
echo ""
30+
echo " --simulator-path PATH Path to the avm_simulator_bin.cjs file"
31+
echo " Default: $DEFAULT_SIMULATOR_BIN"
32+
echo ""
33+
echo " -h, --help Show this help message"
34+
echo ""
35+
echo "Example:"
36+
echo " $0"
37+
echo " $0 --noir-path /path/to/noir"
38+
echo " $0 --transpiler-path /path/to/avm_transpiler --simulator-path /path/to/simulator.cjs"
39+
exit 1
40+
}
41+
42+
# Initialize with defaults
43+
NOIR_ROOT_DIR="$DEFAULT_NOIR_ROOT"
44+
TRANSPILER_BIN="$DEFAULT_TRANSPILER_BIN"
45+
SIMULATOR_BIN="$DEFAULT_SIMULATOR_BIN"
46+
47+
# Parse command line arguments
48+
while [[ $# -gt 0 ]]; do
49+
case $1 in
50+
--noir-path)
51+
NOIR_ROOT_DIR="$2"
52+
shift 2
53+
;;
54+
--transpiler-path)
55+
TRANSPILER_BIN="$2"
56+
shift 2
57+
;;
58+
--simulator-path)
59+
SIMULATOR_BIN="$2"
60+
shift 2
61+
;;
62+
-h|--help)
63+
usage
64+
;;
65+
*)
66+
echo -e "${RED}Error: Unknown option: $1${NC}"
67+
echo ""
68+
usage
69+
;;
70+
esac
71+
done
72+
73+
# Validate paths
74+
if [ ! -d "$NOIR_ROOT_DIR" ]; then
75+
echo -e "${RED}Error: Noir root directory does not exist: $NOIR_ROOT_DIR${NC}"
76+
exit 1
77+
fi
78+
79+
if [ ! -f "$TRANSPILER_BIN" ]; then
80+
echo -e "${RED}Error: AVM transpiler binary does not exist: $TRANSPILER_BIN${NC}"
81+
exit 1
82+
fi
83+
84+
if [ ! -f "$SIMULATOR_BIN" ]; then
85+
echo -e "${RED}Error: AVM simulator binary does not exist: $SIMULATOR_BIN${NC}"
86+
exit 1
87+
fi
88+
89+
# Check for ssa_fuzzer directory in noir-repo
90+
FUZZER_DIR="$NOIR_ROOT_DIR/tooling/ssa_fuzzer/fuzzer"
91+
if [ ! -d "$FUZZER_DIR" ]; then
92+
echo -e "${RED}Error: Fuzzer directory does not exist: $FUZZER_DIR${NC}"
93+
echo -e "${YELLOW}Make sure PATH_TO_NOIR_ROOT_DIR points to the Noir repository root.${NC}"
94+
exit 1
95+
fi
96+
97+
echo -e "${GREEN}Building fuzzer...${NC}"
98+
yarn build:fuzzer
99+
100+
echo -e "${GREEN}Checking for cargo-fuzz installation...${NC}"
101+
102+
# Check if cargo-fuzz is installed
103+
if ! cargo fuzz --version &> /dev/null; then
104+
echo -e "${RED}Error: cargo-fuzz is not installed.${NC}"
105+
echo ""
106+
echo -e "${YELLOW}To install cargo-fuzz, run:${NC}"
107+
echo -e " ${GREEN}cargo install cargo-fuzz${NC}"
108+
echo ""
109+
echo -e "${YELLOW}Note: cargo-fuzz requires a nightly Rust toolchain.${NC}"
110+
echo -e "If you don't have it, install with:${NC}"
111+
echo -e " ${GREEN}rustup install nightly${NC}"
112+
echo ""
113+
exit 1
114+
fi
115+
116+
echo -e "${GREEN}cargo-fuzz is installed: $(cargo fuzz --version)${NC}"
117+
echo -e "${GREEN}Build complete!${NC}"
118+
echo ""
119+
echo -e "${GREEN}Starting fuzzer with:${NC}"
120+
echo -e " Noir root: $NOIR_ROOT_DIR"
121+
echo -e " Transpiler: $TRANSPILER_BIN"
122+
echo -e " Simulator: $SIMULATOR_BIN"
123+
echo ""
124+
125+
# Run the fuzzer
126+
cd "$FUZZER_DIR"
127+
SIMULATOR_BIN_PATH="$SIMULATOR_BIN" TRANSPILER_BIN_PATH="$TRANSPILER_BIN" cargo +nightly fuzz run --fuzz-dir . brillig -- -max_len=10000

yarn-project/simulator/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,7 @@
4444
"path": "../noir-test-contracts.js"
4545
}
4646
],
47-
"include": ["src"]
47+
"include": ["src"],
48+
// Note(ilyas): This exclude kinda redundant now, but a reminder for when we move the fuzzer into /src/avm
49+
"exclude": ["scripts/fuzzing/avm_simulator_bin.ts"]
4850
}

0 commit comments

Comments
 (0)