Skip to content
This repository was archived by the owner on Nov 26, 2026. It is now read-only.

Latest commit

 

History

History
185 lines (128 loc) · 8.33 KB

CLAUDE.md

File metadata and controls

185 lines (128 loc) · 8.33 KB

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

When answering questions about the Aztec network, protocol, SDK, or tooling, fetch https://docs.aztec.network/llms.txt for the current official docs index. Prefer it over training-data knowledge, which may be stale.

Project Overview

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.

Aztec version: 5.0.0-rc.2 — pinned across Nargo.toml, package.json, config/*.json, and README. All must stay in sync when updating.

Build & Development Commands

Always use yarn compile or aztec compile to compile contracts, never nargo compile.

yarn compile              # Compile Noir contract (aztec compile)
yarn codegen              # Generate TS artifacts from compiled contract
yarn compile && yarn codegen  # Full rebuild (always run both together)
yarn clean                # Remove compiled artifacts (src/artifacts, target)
yarn clear-store          # Remove PXE data store (rm -rf ./store)

Testing

Two independent test systems:

yarn test:nr              # Noir TXE tests — no network needed, runs in simulator
yarn test:js              # TypeScript E2E tests — requires running local network
yarn test                 # Runs both (test:js then test:nr)

E2E tests require a running local network:

aztec start --local-network   # Start local network first
rm -rf ./store                # Always clear store after network restart

Jest config: jest.integration.config.json — 600s test timeout, ESM mode via ts-jest, matches ./src/**/*.test.ts.

Run a single E2E test:

NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --no-cache --runInBand --config jest.integration.config.json -t "test name pattern"

Deployment & Scripts

All scripts support ::testnet suffixes for remote network targeting:

yarn deploy               # Deploy contract to local network
yarn deploy::testnet      # Deploy contract to testnet
yarn deploy-account       # Deploy a Schnorr account
yarn multiple-wallet      # Deploy from one wallet, interact from another
yarn profile              # Profile a transaction deployment
yarn read-logs            # Demo utility function for client-side debug logging
yarn read-logs::testnet   # Same on testnet

Environment Configuration

  • AZTEC_ENV variable selects config: local-network (default) or testnet
  • Config files: config/local-network.json, config/testnet.json
  • config/config.ts — singleton ConfigManager loads the appropriate JSON based on AZTEC_ENV
  • .env stores secrets (SECRET, SIGNING_KEY, SALT, contract keys) — never commit

Branch Model

  • next branch — default branch; used for local network development
  • testnet branch — used for testnet development; may run a different Aztec version

PRs target next. Testnet PRs target testnet. Each branch pins its own Aztec version independently.

Project Structure

Contract (Noir):

  • src/main.nr — PodRacing contract: public functions (create_game, join_game, finalize_game), private functions (play_round, finish_game), and internal #[only_self] validators
  • src/race.nr — Race struct: public game state (players, round counters, track scores, end_block)
  • src/game_round_note.nr — GameRoundNote: private note storing one round's point allocation per player

Tests (Noir TXE):

  • src/test/mod.nr — test module root
  • src/test/pod_racing.nr — unit tests using TXE simulator (env.call_public, env.call_private, env.public_context_at)
  • src/test/utils.nr — test setup helper
  • src/test/helpers.nr — test helpers (game setup, allocation strategies)

Tests (TypeScript E2E):

  • src/test/e2e/index.test.ts — full game lifecycle tests against real network
  • src/test/e2e/accounts.test.ts — account tests
  • src/test/e2e/public_logging.test.ts — logging tests

TypeScript utilities:

  • src/utils/setup_wallet.ts — creates EmbeddedWallet with environment-aware config
  • src/utils/create_account_from_env.ts — Schnorr account from env vars
  • src/utils/deploy_account.ts — account deployment with sponsored fees
  • src/utils/sponsored_fpc.ts — SponsoredFPC (Fee Payment Contract) setup

Generated (do not edit):

  • src/artifacts/PodRacing.ts — generated by yarn codegen
  • target/ — compiled contract output

Key Architectural Patterns

  • ESM project: "type": "module" in package.json. All TS scripts run via node --loader ts-node/esm.
  • 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.
  • Fee payment: All transactions use SponsoredFeePaymentMethod via the SponsoredFPC contract.
  • Wallet setup: EmbeddedWallet.create() with ephemeral: true for tests.
  • PXE store: Data persists in ./store. Must delete after local network restart to avoid stale state errors.

Simulate Before Send (IMPORTANT)

Always call .simulate() before .send() for every state-changing transaction. Simulation runs the transaction locally and surfaces revert reasons immediately. Without it, a failing transaction will hang until the send timeout (up to 600s) with an opaque error.

// Simulate first — surfaces revert reasons instantly
await contract.methods.create_game(gameId).simulate({ from: address });

// Then send — only after simulation succeeds
await contract.methods.create_game(gameId).send({
    from: address,
    fee: { paymentMethod },
    wait: { timeout: timeouts.txTimeout }
});

For deployments, store the deploy request to avoid constructing it twice:

const deployRequest = MyContract.deploy(wallet, ...args);
await deployRequest.simulate({ from: address });
const contract = await deployRequest.send({ ... });

Checklist:

  • Every .send() call must be preceded by a .simulate() call
  • .simulate() does not need fee parameters — only from is required
  • View/read-only calls (e.g. balance_of_private) already use .simulate() to return values — no .send() needed for those

Version Update Procedure

When updating the Aztec version, update all of these locations:

  1. Nargo.toml — aztec dependency tag
  2. package.json — all @aztec/* dependency versions
  3. config/local-network.json and/or config/testnet.json — settings.version (update the configs relevant to the branch you're on)
  4. README.md — install command version

Note: The next and testnet branches may pin different Aztec versions. Only update the config files relevant to the branch.

ONBOARDING.md Maintenance

ONBOARDING.md is generated — do not edit it directly. Edit docs/ONBOARDING.src.md instead, then rebuild:

yarn docs:build    # remark docs/ONBOARDING.src.md -o ONBOARDING.md

The source file uses #include_code directives (via the include_code remark plugin) to extract code snippets from source files at build time. Source files have // docs:start:<name> / // docs:end:<name> marker pairs that define snippet boundaries.

When making code changes:

  1. Source code snippets update automatically on rebuild — no manual copy needed
  2. If you add/remove/rename a marker, update the corresponding #include_code directive in docs/ONBOARDING.src.md
  3. Run yarn docs:build to regenerate ONBOARDING.md
  4. Phase 5 exercises and non-source prose still need manual updates in docs/ONBOARDING.src.md

Files with docs:start/docs:end markers:

  • src/main.nr — storage, constructor, create-game, join-game, play-round, validate-and-play-round, finish-game, validate-finish-game, finalize-game
  • src/race.nr — race-struct, calculate-winner
  • src/game_round_note.nr — game-round-note, game-round-note-new
  • src/test/utils.nr — test-setup
  • src/test/helpers.nr — allocation-strategies, setup-helpers
  • src/test/pod_racing.nr — test-initializer, test-fail-too-many-points
  • src/utils/sponsored_fpc.ts — get-sponsored-fpc