project screenshot 1
project screenshot 2
project screenshot 3

Invisible Empires

Invisible Empires is a fully on-chain implementation of the Risk board game. Built with Mina protocol, we prove that all game execution factors (such as allocating territory and rolling dice) is fair and trustless.

Invisible Empires

Created At

ETHGlobal Tokyo

Winner of

trophy

🥉 Mina — Best Use

Project Description

The project aims to create a decentralized implementation of the popular board game "Risk" using the Mina protocol. The game will allow players to compete against each other in a virtual world and conquer territories using armies, just like the traditional game.

The game will be implemented as a smart contract on the Mina blockchain, which will handle all the game logic, player actions, and state transitions. The smart contract will be written in Typescript and all the logic that runs will be generated into a proof that is verified on the Mina blockchain.

The game has a user-friendly front-end interface that allows players to interact with the smart contract and participate in the game. We allow a maximum of four players. Territories are currently laid out as a grid of buttons, but will soon look like a map as in the Risk game. The front-end interface is built with Next-js.

Players will be able to join the game by signing in with their Mina wallet. They will be assigned random territories across the map with each territory having 7 troops. They will then be able to deploy their troops to different territories on the game board and attack other players' armies. The game will be simultaneous, meaning players can attack as they choose as long as they have the troops to do so.

The game will incorporate the Poseidon hash function to determine the outcomes of battles, making it more unpredictable and exciting. We determine if the hash of the two player id's & the attacking player's nonce is even or odd, then use that to determine which side wins the battle and defeats the opposite troops. We wanted to use a recursive proof to verify the Poseidon hash in batches, but had a time constraint and had to move onto other things.

Overall, the project aims to provide a fun, engaging, and decentralized gaming experience to players around the world, while leveraging the unique features of the Mina protocol to ensure fairness, transparency, and security.

How it's Made

This project is fully built on Mina protocol. We implemented the entire project in Typescript. Our smart contract implements functions for starting a game, playing a move, and verifying a player. Our helper class defines a struct for a Territory and implements functions for attacking, serializing our state Field element (will discuss later), claiming & transferring territory ownership, checking for winners, and rolling the hash dice.

We used the Poseidon hash function to add some randomness to the dice roll. As described earlier, we used the attacking and defending user's id's + the attacking user's account nonce to generate a unique hash. If that hash was even, we'd give the attacker the win. If odd, the defender won.

One hacky thing in particular that we did was represent the entire game state with one 256 bit Field element. The first 80 bits were used to represent the 16 territories using 5 bits each. The first 2 bits defined the player that owned it, the last 3 bits defined the amount of troops that were left. We then used 16 more bits to count the number of territories each player owned. they all started with 4, but if someone reached 1111, they won the game.

background image mobile

Join the mailing list

Get the latest news and updates