Table of contents
Introduction
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.
Technical details
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
Overview
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.
Running locally
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).
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:
Then, open another tab in terminal and:
Testing the circuit
Deployment
This project has been deployed at this address and there is currently support for the Sepolia network.
Related posts
I have written the following posts to explain in detail this project:
Notes
This project is released under GNU General Public License v3.0.