You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Creates a new game. Checks the game ID isn't taken (player1 must be zero address), then writes a new `Race` struct with the caller as player1 and an expiration time.
@@ -207,7 +219,7 @@ After both players have revealed, this compares track scores, determines the win
207
219
208
220
#### The `Race` struct ([`src/race.nr`](./src/race.nr))
209
221
210
-
The `Race` struct (lines 8-38) stores all public game state. It has 17 fields:
222
+
The `Race` struct (lines 10-39) stores all public game state. It has 17 fields:
211
223
212
224
```rust
213
225
pubstructRace {
@@ -240,7 +252,7 @@ Key methods:
240
252
241
253
This is the "aha moment" — the part with no Ethereum equivalent.
242
254
243
-
#### `play_round()` (line 99-131)
255
+
#### `play_round()` (line 110-150)
244
256
245
257
```rust
246
258
#[external("private")]
@@ -276,7 +288,7 @@ Three things happen here that have no direct Ethereum equivalent:
276
288
2.**Creating a private note** — `.insert(GameRoundNote::new(...))` stores the round choices as an encrypted note. Only the player can read it later. The `.deliver(MessageDelivery.CONSTRAINED_ONCHAIN)` commits the note's hash on-chain without revealing the content.
277
289
3.**Enqueuing a public call** — `self.enqueue(...)` schedules a public function to run after the private proof is verified. This updates the round counter publicly (so both players can see progress) without revealing the point allocation.
278
290
279
-
#### `finish_game()` (line 149-184)
291
+
#### `finish_game()` (line 172-216)
280
292
281
293
```rust
282
294
#[external("private")]
@@ -332,8 +344,8 @@ The `#[note]` macro makes this a private state primitive. Each note stores one r
332
344
333
345
Two functions are marked `#[only_self]`, meaning they can only be called by the contract itself (via `self.enqueue(...)`):
334
346
335
-
-**`validate_and_play_round`** (line 136-142) — Validates the round is sequential and increments the player's round counter
336
-
-**`validate_finish_game_and_reveal`** (line 189-211) — Stores the player's revealed track totals, checking they haven't already been revealed
347
+
-**`validate_and_play_round`** (line 155-165) — Validates the round is sequential and increments the player's round counter
348
+
-**`validate_finish_game_and_reveal`** (line 221-251) — Stores the player's revealed track totals, checking they haven't already been revealed
337
349
338
350
**Key insight:** On Ethereum, commit-reveal requires at least 2 transactions (one to commit, one to reveal after a delay). On Aztec, the "commit" happens automatically when a private function creates a note — the data is committed on-chain (as a hash) without ever being visible. The "reveal" is a separate transaction, but the privacy was enforced by the protocol the whole time.
> **Important:** Always call `.simulate()` before `.send()`. Simulation runs the transaction locally and surfaces revert reasons immediately. Without it, a failing transaction hangs until timeout with an opaque error.
698
+
684
699
**Run it:**
685
700
686
701
```bash
@@ -700,13 +715,17 @@ The output includes the contract address, admin address, and instantiation data
0 commit comments