project screenshot 1
project screenshot 2
project screenshot 3
project screenshot 4

ZKBattleships

ZKBattleships is a web3 game, which makes use of ZKPs using the zknoid sdk.

ZKBattleships

Created At

ETHOnline 2024

Project Description

I am making a web3 version of battleships game which uses ZKPs for proving and verifying game states using the zknoid sdk. The game starts with players in lobby, from which two players are selected. Then we are made to place 5 ships of different sizes on a 10 by 10 board. Now players take chances and try to hit each others ships. First one to take down all the ships wins the game.

How it's Made

The project is built on a decentralized Web3 stack, leveraging zk-SNARKs for game state proofs via the zknoid SDK. The backend logic handles game mechanics, state transitions, and ZKP generation, ensuring the game is verifiable without revealing sensitive information.

We utilized o1js for cryptographic operations and managing players' moves, while proto-kit modules handled the game’s state management and assertions. Poseidon hashing ensures efficient board state commitments, while ZKPs verify each player’s actions—like hitting a ship or declaring victory—without leaking extra data.

The game includes both on-chain and off-chain components. The off-chain part (the frontend) was built with React and TypeScript for seamless interaction with the backend and the player interface, ensuring the game is fast, interactive, and user-friendly. On-chain, zknoid provided a clean abstraction for integrating zero-knowledge proofs into the game logic.

The use of zk-SNARKs and zknoid made it possible to prove the correctness of game events like winning or ship placements without revealing any specifics to the chain. This cryptographic proof setup ensures privacy and fairness throughout the game.

A particularly hacky aspect involved creating the "WinWitness"—a structure that validates both ship placements and hits using ZKPs while keeping the process lightweight for the player. This intricate balance between verifying state and maintaining a smooth gameplay experience was key to achieving the decentralized, trustless nature of the game.

background image mobile

Join the mailing list

Get the latest news and updates