zk Connect Four is a zero-knowledge decentralised application that lets you play the game of Connect Four against a DQN agent-trained policy or against another user, and generate and verify a zk-SNARK proof to validate that a user knows who won a valid game without revealing any information.
The bulk of this application is made up of (i) circuits authored in Circom and tested using TypeScript, (ii) smart contracts written in Solidity using Hardhat and (iii) a React application written in TypeScript using Next.js.
The policy that is used to play against a user consists of a neural network which is optimized by a DQN agent in a reinforcement learning task using PyTorch.
- Circuits language: Circom
- Contracts language: Solidity
- Contracts framework: Hardhat
- Front-end framework: Next.js
- Front-end language: TypeScript
- Styling: PostCSS
- Python dependency manager: Poetry
- Machine learning framework: Pytorch
packages/*
: npm packages that contain code and configuration files that are used by other packages or services.apps/*
: workspaces that make up the bulk of the application.apps/circuits/*
: circuits workspace, it includes circuits written in Circom and a circuit unit test.apps/contracts/*
: smart contracts workspace which gathers contracts written in Solidity language, deploy scripts and a deployment json.apps/web/*
: front-end workspace which includes React functional components, CSSModules files, PostCSS mixins and a global css file.
Before running this application you will need to have pnpm and Circom installed in your computer and download the proper powers of Tau file and paste it to apps/circuits/ptau (more info in this readme file).
$ git clone https://github.com/albertobas/zk-connect-four.git
$ cd zk-connect-four
$ cp .env.example .env # fill in tha values for each variable in ./.env, NEXT_PUBLIC_NETWORK_NAME must be either sepolia or localhost.
$ pnpm install
$ pnpm dev
If you'd like to run this application locally and deploy the contracts on a local node, replace sepolia
for localhost
in the NEXT_PUBLIC_NETWORK_NAME
environment variable (and import the corresponding contract ABI and address in apps/web/src/components/enabled-verify-button.tsx
after deploying the contracts locally and exporting the data) and run:
$ pnpm node
Then, open another tab in terminal and:
$ pnpm compile && pnpm generate && pnpm deploy:contracts && pnpm export
$ pnpm dev
$ pnpm test
I have written the following posts to explain in detail this project: