PSE Core Program 2024 Capstone Project
PSE Core Program
In the past two months, I got into PSE Core Program and have intensively studied zero-knowledge cryptography. In the first five weeks, we have a curated list of materials to study, ranging from cryptographic primitives such as Merkle tree, symmetric and asymmetric encryption to going more in-depth about various zk-SNARK protocols such as Groth16 and PLONK, and finally being introduced to the frontier of cryptography, or so they are called, including multi-party computation (MPC) and fully homomorphic encryption (FHE).
In the last three weeks of the program, we are open to scoping and working on our project to put the previous learning into practice. We can either tackle issues from various PSE projects or develop our idea. I decided to build a dApp end-to-end, meaning:
- Having a zk-SNARK component generating proofs on the client side (front end),
- Having a smart contract component that verifies the proof on-chain and
- Building the front end that interacts with users and connects the above two components.
This way, I will be able to see how they connect and how each component interfaces with the others. So let this be the goal!
Capstone Project: Number Guessing Game 🎮
I decided to build a Number Guessing Game. In this game, the goal of each player is to guess the closest to the mean of submissions from all participating players. Each game is divided into multiple rounds. Players first commit to a guess between 1 and 100. The guess value and a randomly generated value, aka nullifier, are processed through a zk-SNARK circuit on the client side, and the commitment [Poseidon(guess, nullifier), Poseidon(nullifier)]
and proof are then submitted on-chain.
After all players have submitted their commitments and proofs, they open and reveal their commitments. Then, the game host will conclude the round. The mean of all guesses will be computed (on-chain), and the player who has submitted the guess closest to the mean will win the round. The player who wins three rounds first wins the game.
The following is the game flow:
- Alice (the first player) initiates a game and becomes the game host.
- In this phase, Other players can join the game. In this case, Bob, Charlie, and Dave join.
- Alice starts the game, and the first game round begins. No more players will be able to join.
- Players submit their commitment on-chain.
- Once all players finish submitting their commitments. They open the commitment. After all players open their commitments, the game host concludes the round. The mean of all submissions is computed, and the round winner is determined.
- If the winner has won three rounds, the game ends. Otherwise, another round begins.
The project is finally built, and you can try it out at:
- Project website: https://guessing.jimmychu0807.hk
- Project repository: https://github.com/jimmychu0807/PSE-core-capstone
- Smart contracts are deployed and verified on Optimism Seoplia testnet:
- Guessing Game Contract:
0x5Da4b2A07da92b26Cc64eE308a9A1A4E7D5c9544
- Commitment Submission Verifier:
0x97bc1d08465f70039dda8fe22bdedf110d2bd8a5
- Commitment Opening Verifier:
0x3044e5d78e1A2eb3c3189a3fC52C0846Ed1f3f7d
- Guessing Game Contract:
You can see the demo of a game walkthrough below: