This project implements a Tic-Tac-Toe game called ZiK-ZaK-Zoo using the SP1 framework. It demonstrates how to create a provable game where a player can generate a proof of their win against a computer opponent.
ZiK-ZaK-Zoo is a Tic-Tac-Toe variant where:
- The human player uses 'Z' as their symbol
- The computer uses 'K' as its symbol
- The game board is represented by numbers 0-8
The game logic includes:
- A simple random number generator for the computer's moves (LCR with MMIX parameters)
- Board state management
- Win condition checking
The project consists of several key components:
- Game Logic Library (
lib/src/lib.rs
) - Main Game Script (
script/src/bin/main.rs
) - Provable Program (
program/src/main.rs
)
- The player plays a game against the computer.
- The game records the seed used for the random number generator and the player's moves.
- After the game, if the player wins, they can generate a proof of their win.
- This proof can be verified on-chain, confirming the player's victory without revealing the exact moves.
There are three main ways to interact with this project:
This runs the game without generating a proof:
cd script
cargo run --release -- --execute
This generates a proof of the game outcome:
cd script
cargo run --release -- --prove
- The game logic is implemented in Rust and compiled to RISC-V architecture.
- The SP1 framework is used to generate zero-knowledge proofs of game outcomes.
- The project includes scripts for executing the game, generating proofs, and retrieving verification keys.
For those interested in the implementation details:
- The main game logic can be found in the
lib/src/lib.rs
file. - The script that runs the game and generates proofs is in
script/src/bin/main.rs
. - The provable program that verifies the game outcome is in
program/src/main.rs
.
This project serves as an example of how to create provable games using zero-knowledge proofs, which can be useful for on-chain gaming applications where fairness and verifiability are crucial -- although this part is not implemented in this repo.