LokartBC / ZKBattleship_secure

Creative Commons Attribution Share Alike 4.0 International
0 stars 0 forks source link

ZKBattleship secure

A secure and complete Zero Knowledge Proof Battleship game. The circuits can proove:

  1. that a grid is valid
  2. wether a target hits a ship
  3. which ships where drowned by the past series or targets

Circuit implementations in circom (which can then be used with snarkjs).

License: Creative Commons

Prerequisite

circom installation

Structure

circuits/ main folder holds the implementation of the circuits
circuits/compile/ subfolder contains shell scripts to generate circuits and proofs
circuits/input/ subfolder contains inputs used for testing

Build circuits

cd circuits/compile

# make power of tau ceremony (phase 1) once for the project, default is power=12, use power=13 here
./pau_phase1 $power
# compile circuit, example circuitName = shipHash
./compile_circuit.sh circuitName
# make power of tau ceremony (phase 2) once for each circuit
./pau_phase2 circuitName
# generate proof 
./gen_proof circuitName input.json
# verify proof 
./verify_proof circuitName
# generate verifiere.sol
./gen_verifier circuitName

Use circuits

initGrid.circom

Checks the positions of the ships are okay (no ships out of bounds or colliding). It generates a hash that should be shared with opponent to initiate a game and proove in the next steps that the ship positions stay the same.

inputs:

output:

battleShipHit.circom

inputs:

output:

battleShipDrowned.circom

inputs:

outputs:

Test circuits

Inputs are provided as test examples.

initGrid:

battleShipHit:

battleShipDrowned: