/zkgames

Primary LanguageTypeScript

ZK Games

This project is a game built on top of Noir lang that generates proofs of the current state of the game. The game is "Jeu des petits chevaux" a french 🥖🥖 board game which consists of moving several pawns (called small horses) per player (between 1 and 4 per player in general), and taking them to the part reserved for their color. The first player to arrive on the last square wins the game.

Setup

Dependencies can be installed from the root of the package:

yarn
yarn install:noir
yarn install:sandbox

In addition to the usual javascript dependencies, this project requires nargo (package manager) and noir (a Domain Specific Language for SNARK proving systems) in addition to @aztec/aztec-cli.

The former are installed within yarn install:noir which executes

This sandbox requires Docker to be installed and running locally. In the event the image needs updating, you can run yarn install:sandbox.

Getting started

After yarn has run,yarn start:sandbox in one terminal will launch a local instance of the Aztec sandbox via Docker Compose and yarn start:dev will launch a frontend app for deploying and interacting with the PrivateToken contract.

At this point, http://localhost:5173 should provide a minimal smart contract frontend.

This folder should have the following directory structure:

|— README.md
|— package.json
|— src
       |-config.ts - PrivateToken specific configuration for the frontend.
       |             You may need to update this if you modify the contract functions.
       |— app
              |— [frontend React .tsx code files]
       |- scripts
              |- [helpers for frontend to interact with contract on the sandbox]
       |— contracts
              |— src
                     | The Noir smart contract source files are here.
                     |— main.nr - the cloned noir contract, your starting point
                     |- interface.nr - autogenerated from main.nr when you compile
               |— Nargo.toml [Noir build file, includes Aztec smart contract dependencies]
       |— artifacts
              |  These are both generated from `contracts/` by the compile command
              |— private_token_contract.json
              |— private_token.ts
       |— tests
              | A simple end2end test deploying and testing the Token on a local sandbox
              | using the front end helper methods in app/scripts/
              | The test requires the sandbox and anvil to be running (yarn start:sandbox).
              | You can run it via `yarn test:integration`.
              |- token.test.ts

Most relevant to you is likely src/contracts/main.nr (and the build config src/contracts/Nargo.toml). This contains the example PrivateToken logic that the frontend interacts with and is a good place to start writing Noir.

The src/artifacts folder can be re-generated from the command line with yarn compile.

This will generate a contract artifact and TypeScript class for the Aztec smart contract in src/contracts/main.nr, which the frontend uses to generate the UI.

After compiling, you can re-deploy the updated noir smart contract from the web UI. The function interaction forms are generated from parsing the contract artifact, so they should update automatically after you recompile.

Learn More

To learn more about Noir Smart Contract development, take a look at the following resources:

Deploy on Aztec3

Coming Soon :)