Implementation of an on chain rock paper scissors game using zero knowledge proofs for hiding the first throw until after the second throw has been played on chain. Oh and only Arbibots can play.
So much fancy tech for a silly game? Yes.
- Player 1 starts a round by submitting a zk proof that they have thrown a 0 (rock) 1 (paper) or 2 (scissors) without revealing which play it was
- Player 2 responds by submitting a throw in the clear
- Player 1 submits a second zk proof revealing what their original throw was and a winner (or tie) is calculated and stored on chain
Must have circom, foundry, and node installed and functioning
yarnRun the following two sections from ./circuits
./scripts/circomBuild.sh # compile the circuitsOption 1: use all the files provided in the ./circuits/ceremony/ dir
./scripts/snarksCodeGen.shOption 2: Prep the ceremony yourself. Get an appropriate trusted powers of tau file, or generate your own. I used powersOfTau28_hez_final_11.ptau from here
./scripts/snarksCeremony.sh # finish the snarks ceremony for each circuit
./scripts/snarksCodeGen.shI have modified the solidity generated by snarksjs, the only thing required from the snarks codegen is the verifyingKey function from the ...Verifier2.sol output files. This must replace the same related functions in ./contracts/src/AttestValidMoveVerifier.sol and ./contracts/src/RevealMoveVerifier.sol after circuit or ceremony changes.
Run through a snarksjs cli proof generation and verification test:
./scripts/testProof.shOutput of the above test is used as valid proofs in solidity test files.
WARNING: All tests are written using the provided complete ceremony. If you modify the circuits or the ceremony tests will break.
from ./contracts
forge buildforge testSnarksJS generated verifier code licensed under the GPL-3.0 (🤮) license, see LICENSE-GPL3.
All other files including interface, circuits, and game functionality licensed under the MIT license, see LICENSE.