Here is demo of Seabattle game, implemented on Noir.
Circuits are available here.
Variation of the Battleship game is used:
The ocean is a 5x5 grid, on which each ship takes up one square. Each player has 3 ships. Ships cannot be positioned on the neighbor squares.
On every turn each ships can move or fire. Each ship can sustain 3 hits before sinking. Infromation about successfull hit or sinking must be announced to one's opponent.
Game ends when all ships are sunk for some player.
Use this description how to install noir from source.
git clone https://github.com/snjax/zkships.git
cd zkships/circuit
nargo build
nargo compile p
nargo contract
To test the circuit with some data, try
#
node test/generate_sample_inputs.js > Prover.toml
nargo prove p
Game UI:
Wallet connection:
Game creation:
Examples are availble here.
'nargo prove' fails with Segmentation fault error:
Segmentation fault (core dumped)
Code:
fn main(x : Field, y : pub Field) {
let flag = (x == 1) & (y == 2);
constrain flag == true;
}
'nargo build' fails with stack overflow error:
thread 'main' has overflowed its stack
fatal runtime error: stack overflow
Aborted (core dumped)
Code:
fn main(x : Field, y : pub Field) {
let flag = (x == 1) & (y == 2);
constrain flag | false == flag;
}
'nargo compile' can fail when Pedersen hash is used:
thread 'main' panicked at 'Cannot find witness assignment for GadgetInput { witness: Witness(5), num_bits: 254 }', crates/acvm/src/pwg/mod.rs:18:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Code:
use dep::std;
fn main(solnHash: pub Field, raw_data: [Field; 2], salt: Field) {
let mut state = 0;
for i in 0..2 {
state = state * 8 + raw_data[i];
};
state = state + salt;
let hash = std::haAsh::pedersen([state])[0];
constrain solnHash == hash;
}
Next patches were required for WASM worker: https://github.com/snjax/zkships/tree/master/worker/patches
Nargo build does not work on Mac computers with Apple silicon. System libraries path is incorrect in rust wrapper for barretenberg.