Skip to content

Commit d1f3efd

Browse files
authored
feat: avm allow and ignore list for fuzzer preset (#19088)
This adds an ignore and allow list for lib fuzzer, this makes things a little bit faster for the tx fuzzer and **significantly** faster for the prover.fuzzer (in an upstream PR). This also adds some `build` commands for the fuzzing script because i kept forgetting
1 parent 2258dbc commit d1f3efd

File tree

5 files changed

+63
-14
lines changed

5 files changed

+63
-14
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Instrument vm2
2+
src:*/vm2/*
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Fuzzer instrumentation blocklist for AVM fuzzing
2+
# These directories contain heavy constraint/circuit code that we don't want instrumented
3+
# Format: src:<pattern> to match source files
4+
5+
# Exclude constraining code (circuit constraint generation)
6+
src:*barretenberg/vm2/constraining/*
7+
8+
# Exclude generated code (auto-generated circuit definitions)
9+
src:*barretenberg/vm2/generated/*

barretenberg/cpp/cmake/module.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ function(barretenberg_module_with_sources MODULE_NAME)
9191
PRIVATE
9292
-fsanitize=fuzzer-no-link
9393
)
94+
if(FUZZING_AVM)
95+
target_compile_options(
96+
${MODULE_NAME}_objects
97+
PRIVATE
98+
-fsanitize-coverage-allowlist=${CMAKE_SOURCE_DIR}/cmake/fuzzing-avm-allowlist.txt
99+
-fsanitize-coverage-ignorelist=${CMAKE_SOURCE_DIR}/cmake/fuzzing-avm-ignorelist.txt
100+
)
101+
endif()
94102
endif()
95103

96104
# enable msgpack downloading via dependency (solves race condition)

barretenberg/cpp/src/barretenberg/avm_fuzzer/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if(AVM AND FUZZING)
1+
if(FUZZING_AVM)
22
# Collect source files, excluding the harness subdirectory to avoid duplicate targets
33
file(GLOB_RECURSE SOURCE_FILES
44
"${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"

barretenberg/cpp/src/barretenberg/avm_fuzzer/run_fuzzer.sh

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ set -e
88
show_usage() {
99
echo "Usage: $0 <command> <fuzzer_type> [options] [-- fuzzer_args...]"
1010
echo "Commands:"
11+
echo " build <fuzzer_type> - Build the fuzzer binary"
1112
echo " fuzz <fuzzer_type> [--log] [-- args...] - Run the fuzzer (--log to tail fuzz-0.log)"
1213
echo " coverage <fuzzer_type> [type] - Generate coverage report (type: html or report, default: html)"
1314
echo " list-targets - List all available fuzzing targets"
@@ -118,22 +119,51 @@ else
118119
BUILD_CMAKE_FLAGS=""
119120
fi
120121

121-
# Check if fuzzer build/binary exists
122-
FUZZER_BIN="$BUILD_DIR/bin/$FUZZER_TYPE"
123-
if [ ! -d "$BUILD_DIR" ] || [ ! -f "$FUZZER_BIN" ]; then
124-
echo "Error: Fuzzer binary not found: $FUZZER_BIN"
125-
echo ""
126-
echo "Please build the fuzzer by running:"
127-
echo " cd $CPP_DIR"
122+
# Build function
123+
build_fuzzer() {
124+
echo "Building fuzzer: $FUZZER_TYPE"
125+
echo "Build directory: $BUILD_DIR"
126+
echo "Preset: $BUILD_PRESET"
128127
if [ -n "$BUILD_CMAKE_FLAGS" ]; then
129-
echo " cmake --preset $BUILD_PRESET $BUILD_CMAKE_FLAGS"
130-
else
131-
echo " cmake --preset $BUILD_PRESET"
128+
echo "Extra CMake flags: $BUILD_CMAKE_FLAGS"
132129
fi
133-
echo " cmake --build --preset $BUILD_PRESET --target $FUZZER_TYPE"
134130
echo ""
135-
echo "Use './run_fuzzer.sh list-targets' to see all available targets"
136-
exit 1
131+
132+
cd "$CPP_DIR"
133+
134+
# Configure if build dir doesn't exist or CMakeCache is missing
135+
if [ ! -f "$BUILD_DIR/CMakeCache.txt" ]; then
136+
echo "Configuring cmake..."
137+
if [ -n "$BUILD_CMAKE_FLAGS" ]; then
138+
cmake --preset "$BUILD_PRESET" $BUILD_CMAKE_FLAGS
139+
else
140+
cmake --preset "$BUILD_PRESET"
141+
fi
142+
fi
143+
144+
# Build the target
145+
echo "Building target: $FUZZER_TYPE"
146+
cmake --build "$BUILD_DIR" --target "$FUZZER_TYPE"
147+
148+
echo ""
149+
echo "Build complete: $FUZZER_BIN"
150+
}
151+
152+
# Check if fuzzer build/binary exists
153+
FUZZER_BIN="$BUILD_DIR/bin/$FUZZER_TYPE"
154+
155+
# Handle build command
156+
if [ "$COMMAND" = "build" ]; then
157+
build_fuzzer
158+
exit 0
159+
fi
160+
161+
# Auto-build if binary doesn't exist
162+
if [ ! -f "$FUZZER_BIN" ]; then
163+
echo "Fuzzer binary not found: $FUZZER_BIN"
164+
echo "Auto-building..."
165+
echo ""
166+
build_fuzzer
137167
fi
138168

139169
# Set corpus directory based on fuzzer type

0 commit comments

Comments
 (0)