Ghosts is a zk-table-game for anyone. It is a simple fun game.
Ghosts Link:
https://zku-final-project.vercel.app/
Demo video: https://youtu.be/HGzqmTf_CA4 https://youtu.be/eyf8ahx3Jvw
The project has three main folders:
- contracts
- frontend
The contracts folder contains all the smart contracts and circuits.
Each player commits their proofs that prove they chose four good ghosts and four evil ghosts. In the circuit, good or evil is represented by binaries. Good is 1 and evil is 0. The binaries are 2**8 = 256 patterns, and it is vulnerable by brute force attack. Therefore the circuit requires a private salt.
The main contract is Ghosts.sol. In the contract, the whole game system is implemented such as game start, move pieces and check winning conditions. In the contract, each player has to submit their proof when they start a game.
Frontend UI is implemented by next.js and hosted in Vercel.
With running hardhat nodes(npx hardhat node
), in contracts directory,
yarn install
sh ./scripts/compile-circuit.sh
npx hardhat run --network localhost scripts/deploy.js
copy the Ghosts address and paste it to the contractAddress variable in /frontend/src/utils/getContract.ts
In frontend directory,
yarn install
yarn dev
In contracts directory, you can test contracts and circuits.
yarn install
sh ./scripts/compile-circuit.sh
yarn test
In test directory,
- ghosts-test.js tests the smart contract in Ghosts.sol
- verifier-circuits-test.js tests the circuit in Ghosts.circom
- verifier-test.js test the smart contract in verifier.sol which is auto generated from Ghosts.circom
- Connect your metamask wallet, then you are in a game.
- Select 4 indices that good ghosts are placed, and click Start Game
- In your turn, pick one ghost and move it.
- When your ghost is got, you have to reveal the ghost's type before you move your ghost.
- Winning conditions are following,
- You get all the opponent's good ghosts.
- The opponents get all your evil ghosts.
- Your good ghost gets the opponent side red square and declare win.
- After you win, you can claim ERC20 coins.
- Players can buy NFT by the utility token
- Players use the NFT for ghosts images in games