|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Aztec Starter — a Pod Racing game contract built with Noir on the Aztec network. Two players allocate points across 5 tracks over 3 rounds with private state; scores are revealed at the end (commit-reveal pattern). The player who wins more tracks (best of 5) wins. |
| 8 | + |
| 9 | +**Aztec version: `4.0.0-devnet.2-patch.1`** — pinned across `Nargo.toml`, `package.json`, `config/*.json`, and README. All must stay in sync when updating. |
| 10 | + |
| 11 | +## Build & Development Commands |
| 12 | + |
| 13 | +Always use `yarn compile` or `aztec compile` to compile contracts, never `nargo compile`. |
| 14 | + |
| 15 | +```bash |
| 16 | +yarn compile # Compile Noir contract (aztec compile) |
| 17 | +yarn codegen # Generate TS artifacts from compiled contract |
| 18 | +yarn compile && yarn codegen # Full rebuild (always run both together) |
| 19 | +yarn clean # Remove compiled artifacts (src/artifacts, target) |
| 20 | +yarn clear-store # Remove PXE data store (rm -rf ./store) |
| 21 | +``` |
| 22 | + |
| 23 | +## Testing |
| 24 | + |
| 25 | +Two independent test systems: |
| 26 | + |
| 27 | +```bash |
| 28 | +yarn test:nr # Noir TXE tests — no network needed, runs in simulator |
| 29 | +yarn test:js # TypeScript E2E tests — requires running local network |
| 30 | +yarn test # Runs both (test:js then test:nr) |
| 31 | +``` |
| 32 | + |
| 33 | +**E2E tests require a running local network:** |
| 34 | + |
| 35 | +```bash |
| 36 | +aztec start --local-network # Start local network first |
| 37 | +rm -rf ./store # Always clear store after network restart |
| 38 | +``` |
| 39 | + |
| 40 | +Jest config: `jest.integration.config.json` — 600s test timeout, ESM mode via `ts-jest`, matches `./src/**/*.test.ts`. |
| 41 | + |
| 42 | +Run a single E2E test: |
| 43 | + |
| 44 | +```bash |
| 45 | +NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --no-cache --runInBand --config jest.integration.config.json -t "test name pattern" |
| 46 | +``` |
| 47 | + |
| 48 | +## Deployment & Scripts |
| 49 | + |
| 50 | +All scripts support `::devnet` suffix for devnet targeting (sets `AZTEC_ENV=devnet`): |
| 51 | + |
| 52 | +```bash |
| 53 | +yarn deploy # Deploy contract to local network |
| 54 | +yarn deploy::devnet # Deploy contract to devnet |
| 55 | +yarn deploy-account # Deploy a Schnorr account |
| 56 | +yarn multiple-wallet # Deploy from one wallet, interact from another |
| 57 | +yarn profile # Profile a transaction deployment |
| 58 | +``` |
| 59 | + |
| 60 | +## Environment Configuration |
| 61 | + |
| 62 | +- `AZTEC_ENV` variable selects config: `local-network` (default) or `devnet` |
| 63 | +- Config files: `config/local-network.json`, `config/devnet.json` |
| 64 | +- `config/config.ts` — singleton `ConfigManager` loads the appropriate JSON based on `AZTEC_ENV` |
| 65 | +- `.env` stores secrets (SECRET, SIGNING_KEY, SALT, contract keys) — never commit |
| 66 | + |
| 67 | +## Project Structure |
| 68 | + |
| 69 | +**Contract (Noir):** |
| 70 | + |
| 71 | +- `src/main.nr` — PodRacing contract: public functions (`create_game`, `join_game`, `finalize_game`), private functions (`play_round`, `finish_game`), and internal `#[only_self]` validators |
| 72 | +- `src/race.nr` — `Race` struct: public game state (players, round counters, track scores, end_block) |
| 73 | +- `src/game_round_note.nr` — `GameRoundNote`: private note storing one round's point allocation per player |
| 74 | + |
| 75 | +**Tests (Noir TXE):** |
| 76 | + |
| 77 | +- `src/test/mod.nr` — test module root |
| 78 | +- `src/test/pod_racing.nr` — unit tests using TXE simulator (`env.call_public`, `env.call_private`, `env.public_context_at`) |
| 79 | +- `src/test/utils.nr` — test setup helper |
| 80 | +- `src/test/helpers.nr` — test helpers (game setup, allocation strategies) |
| 81 | + |
| 82 | +**Tests (TypeScript E2E):** |
| 83 | + |
| 84 | +- `src/test/e2e/index.test.ts` — full game lifecycle tests against real network |
| 85 | +- `src/test/e2e/accounts.test.ts` — account tests |
| 86 | +- `src/test/e2e/public_logging.test.ts` — logging tests |
| 87 | + |
| 88 | +**TypeScript utilities:** |
| 89 | + |
| 90 | +- `src/utils/setup_wallet.ts` — creates `EmbeddedWallet` with environment-aware config (prover enabled on devnet) |
| 91 | +- `src/utils/create_account_from_env.ts` — Schnorr account from env vars |
| 92 | +- `src/utils/deploy_account.ts` — account deployment with sponsored fees |
| 93 | +- `src/utils/sponsored_fpc.ts` — SponsoredFPC (Fee Payment Contract) setup |
| 94 | + |
| 95 | +**Generated (do not edit):** |
| 96 | + |
| 97 | +- `src/artifacts/PodRacing.ts` — generated by `yarn codegen` |
| 98 | +- `target/` — compiled contract output |
| 99 | + |
| 100 | +## Key Architectural Patterns |
| 101 | + |
| 102 | +- **ESM project**: `"type": "module"` in package.json. All TS scripts run via `node --loader ts-node/esm`. |
| 103 | +- **Private-public interaction**: `play_round` is private (creates `GameRoundNote` notes), then enqueues a public call (`validate_and_play_round`) to update round counters. `finish_game` reads private notes, sums them, and enqueues a public call to reveal totals. |
| 104 | +- **Fee payment**: All transactions use `SponsoredFeePaymentMethod` via the SponsoredFPC contract. |
| 105 | +- **Wallet setup**: `EmbeddedWallet.create()` with `ephemeral: true` for tests; prover is enabled only on devnet. |
| 106 | +- **PXE store**: Data persists in `./store`. Must delete after local network restart to avoid stale state errors. |
| 107 | + |
| 108 | +## Version Update Procedure |
| 109 | + |
| 110 | +When updating the Aztec version, update all of these locations: |
| 111 | + |
| 112 | +1. `Nargo.toml` — `aztec` dependency tag |
| 113 | +2. `package.json` — all `@aztec/*` dependency versions |
| 114 | +3. `config/local-network.json` and `config/devnet.json` — `settings.version` |
| 115 | +4. `README.md` — install command version |
0 commit comments