Skip to content

zk Connect Four is a zero-knowledge DApp 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.

License

Notifications You must be signed in to change notification settings

albertobas/zk-connect-four

Repository files navigation

zk Connect Four

GNU General Public License v3.0

zk Connect Four demo

About

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.

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).

$ 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

Testing the circuit

$ pnpm test

Related posts

I have written the following posts to explain in detail this project:

About

zk Connect Four is a zero-knowledge DApp 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.

Topics

Resources

License

Stars

Watchers

Forks