Skip to content

Commit 1211a03

Browse files
authored
feat(protocol-fuzzer): local repo setup (no docker) (#22387)
Added setup-local.sh for running against a locally-built sandbox, along with some small related improvements. Tested on mainframe off the current next.
2 parents 270105c + 90af740 commit 1211a03

9 files changed

Lines changed: 399 additions & 38 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
/target
22
contracts/target/
33
*.sw?
4+
# Symlink to yarn-project/node_modules created by setup-local.sh.
5+
/node_modules

noir-projects/protocol-fuzzer/README.md

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
A state-machine fuzzer for Aztec contract interactions. It talks to a running
2-
sandbox via a persistent Node.js HTTP bridge (`bridge.mjs`), compares the
2+
sandbox via a persistent Node.js HTTP bridge (`wallet-bridge.mjs`), compares the
33
sandbox's behavior to an in-memory model, and asserts on any divergence.
44

55
Two machines are available:
@@ -19,16 +19,22 @@ it uses the standard `Token` contract that ships with the wallet CLI:
1919
cargo run -- token --max-steps 100
2020
```
2121

22-
The **side-effect** machine requires the **nightly** sandbox because it deploys custom
23-
contracts compiled against the nightly's aztec-nr. Use `setup-nightly-sandbox.sh` to
24-
automate the full setup (defaults to the last tested nightly tag; pass `--latest` to
25-
try the newest one). See `SANDBOX_INSTRUCTIONS.md` for manual steps.
22+
The **side-effect** machine requires custom contracts. There are two ways to set it up:
2623

24+
**Local setup** (no Docker, uses your repo build):
25+
```
26+
bash setup-local.sh # compiles contracts, starts anvil + node + bridge
27+
cargo run -- side-effect --artifacts-dir contracts/target --max-steps 100
2728
```
28-
bash setup-nightly-sandbox.sh
2929

30+
**Nightly Docker setup** (defaults to the last tested nightly tag; pass `--latest` for newest):
31+
```
32+
bash setup-nightly-sandbox.sh
3033
cargo run -- side-effect --max-steps 100
3134
```
35+
The nightly script places artifacts at `/tmp/` inside the container (the default `--artifacts-dir`).
36+
37+
See `SANDBOX_INSTRUCTIONS.md` for manual nightly steps and troubleshooting.
3238

3339
To replay a specific failure seed:
3440

@@ -44,8 +50,15 @@ cargo run -- side-effect --max-steps 100000 --seed 0x5a7211231dcd6500
4450
--seed 0xHEX Replay a specific seed
4551
--max-steps N Max fuzzing steps (default: 400)
4652
--max-batch-size N Max parallel sends per batch (default: 8)
53+
--artifacts-dir DIR Contract artifact directory (side-effect only, default: /tmp)
4754
```
4855

56+
> **Note:** `--artifacts-dir` is resolved on the host and sent as-is to the bridge.
57+
> For **local** setup the bridge runs on the host, so use the real path (e.g.
58+
> `contracts/target`). For **nightly Docker** the bridge runs inside the container,
59+
> so the path must be valid inside it — the default `/tmp` works because the nightly
60+
> script places artifacts at `/tmp/*.json` inside the container.
61+
4962
### Parallel batching
5063

5164
Consecutive non-conflicting state-changing commands are batched and fired concurrently,
@@ -64,12 +77,16 @@ Conflict rules (conservative -- false positives only reduce batch size):
6477
To verify that the sandbox is running correctly, run the integration smoke tests:
6578

6679
```
67-
cargo test -- --ignored --nocapture
80+
ARTIFACTS_DIR=contracts/target cargo test -- --ignored --nocapture
6881
```
6982

7083
These are `#[ignore]`d by default because they require a running sandbox. With
7184
bridge + fast slots, a full suite run takes ~1-2 minutes (~5-13s per transaction).
7285

86+
Environment variables for tests:
87+
- `ARTIFACTS_DIR` -- contract artifact directory (default: `/tmp`)
88+
- `BRIDGE_URL` -- bridge server URL (default: `http://localhost:8089`)
89+
7390
## Contracts
7491

7592
Contract sources live in `contracts/` within this crate, not in `noir-contracts/`. They
@@ -82,9 +99,9 @@ with oracle calls (like `utilityLog`) that the nightly PXE doesn't support.
8299
- **Parent** (`contracts/parent_contract/`) -- forwards calls to SideEffect for
83100
cross-contract call testing
84101

85-
Artifacts are built by `setup-nightly-sandbox.sh` inside the nightly container and
86-
placed in `contracts/target/` (not checked into git).
102+
Artifacts are built by `setup-local.sh` or `setup-nightly-sandbox.sh` and placed in
103+
`contracts/target/`. Pre-built artifacts are checked into git for convenience.
87104

88-
The setup script auto-detects the nightly commit by matching the container's nargo
89-
hash against `origin/next`. See `SANDBOX_INSTRUCTIONS.md` for the full build pipeline,
90-
version matrix, and troubleshooting.
105+
The nightly setup script auto-detects the nightly commit by matching the container's
106+
nargo hash against `origin/next`. See `SANDBOX_INSTRUCTIONS.md` for the full build
107+
pipeline, version matrix, and troubleshooting.

noir-projects/protocol-fuzzer/SANDBOX_INSTRUCTIONS.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Protocol Fuzzer: Running with Nightly Docker Sandbox
22

3+
> **For local development** (no Docker), use `setup-local.sh` instead. It starts
4+
> anvil, the Aztec node, compiles contracts, and launches the bridge — all on the
5+
> host. See `README.md` for quick-start instructions.
6+
37
## Overview
48

59
The protocol fuzzer has two state machines:
@@ -9,7 +13,7 @@ The protocol fuzzer has two state machines:
913
- **side-effect**: Fuzzes note lifecycle, nullifier emission, and cross-contract calls via
1014
custom `SideEffect` and `Parent` contracts. **Requires the nightly sandbox.**
1115

12-
Both machines talk to the sandbox via a persistent Node.js HTTP bridge (`bridge.mjs`)
16+
Both machines talk to the sandbox via a persistent Node.js HTTP bridge (`wallet-bridge.mjs`)
1317
that keeps a single CLIWallet instance alive across requests.
1418

1519
## Why the nightly sandbox?
@@ -69,7 +73,7 @@ for the next block. Four things bring per-transaction time from ~35s down to ~4-
6973

7074
1. **Fast slots.** The setup script starts the sandbox with 5-second L1/L2 slot durations
7175
(default 36s/12s) and disables sequencer timetable enforcement.
72-
2. **Persistent bridge.** `bridge.mjs` keeps a single Node.js wallet instance alive inside
76+
2. **Persistent bridge.** `wallet-bridge.mjs` keeps a single Node.js wallet instance alive inside
7377
the container. Without it, each operation would shell out to the CLI wallet, paying a
7478
~1.5s Node.js cold-start every time.
7579
3. **Parallel batching.** The fuzzer buffers consecutive non-conflicting sends and fires
@@ -216,14 +220,14 @@ done
216220

217221
### 5. Start the bridge server
218222

219-
The bridge server (`bridge.mjs`) runs inside the container and provides a persistent
223+
The bridge server (`wallet-bridge.mjs`) runs inside the container and provides a persistent
220224
HTTP API that the fuzzer calls:
221225

222226
```bash
223-
docker cp bridge.mjs aztec-sandbox-nightly:/usr/src/yarn-project/bridge.mjs
227+
docker cp wallet-bridge.mjs aztec-sandbox-nightly:/usr/src/yarn-project/wallet-bridge.mjs
224228

225229
docker exec -d aztec-sandbox-nightly \
226-
bash -c 'cd /usr/src/yarn-project && exec node --no-warnings bridge.mjs > /tmp/bridge.log 2>&1'
230+
bash -c 'cd /usr/src/yarn-project && exec node --no-warnings wallet-bridge.mjs > /tmp/bridge.log 2>&1'
227231

228232
# Wait for it to start
229233
curl -s http://localhost:8089/health # {"ok":true}
@@ -317,7 +321,7 @@ on every operation.
317321

318322
### How the bridge works
319323

320-
`bridge.mjs` runs inside the container and lazily initializes a `CLIWallet` instance
324+
`wallet-bridge.mjs` runs inside the container and lazily initializes a `CLIWallet` instance
321325
on the first request. The Rust fuzzer resolves aliases (`accounts:test0`,
322326
`contracts:test0`) to hex addresses before sending them to the bridge via HTTP POST.
323327

@@ -344,7 +348,7 @@ on the first request. The Rust fuzzer resolves aliases (`accounts:test0`,
344348
| wallet CLI | `node --no-warnings /usr/src/yarn-project/cli-wallet/dest/bin/index.js` |
345349
| sandbox CLI | `node --no-warnings /usr/src/yarn-project/aztec/dest/bin/index.js` |
346350
| anvil | `/opt/foundry/bin/anvil` |
347-
| bridge server | `/usr/src/yarn-project/bridge.mjs` |
351+
| bridge server | `/usr/src/yarn-project/wallet-bridge.mjs` |
348352
| bridge log | `/tmp/bridge.log` |
349353

350354
## Stopping

0 commit comments

Comments
 (0)