2/3 Guessing Game

April 4, 2024

For the first time in the history of crypto, it is possible to create fully on-chain games with hidden states. Inco unlocks new mechanics in on-chain games by leveraging Fully Homomorphic Encryption (FHE). This will usher in a new era of novel cryptogames with hidden moves, resource concealment, and fog of war mechanics. This post explores how FHE enables conceals moves in the Two-Thirds Game, a classic game from game theory.

Until now, fully on-chain games have been limited to games with perfect information. Consider chess and poker. In chess, the entire board is visible to both players, ensuring perfect information. In poker, each player knows only the cards in their own hand and must guess what cards their opponents hold. This is hidden information. There are many successful crypto games with perfect information including Axie Infinity, Crypto Kitties, and Parallel. The launch of Inco’s universal confidential compute layer will open a new design space for games with hidden information.

It’s worth noting that zk-proofs can be used to create games with hidden information however, it is significantly more complex to develop zk games. As you will see, Inco makes these games simple to build for anyone with solidity experience.

A new class of games featuring mechanics like fog of war (Age of Empires, Dark Forest v2), concealed hands (poker, dominoes, Catan), and hidden information (Battleship, Stratego) is on the horizon.

Cryptonatives will also use FHE to create new forms of social and speculative games. It’s this new class of games that interests me most. Cryptogames with hidden information offer an opportunity to build games unlike what has come before — games that entertain, capture attention, and give degens an opportunity to do what they do best: bet more.

Now, let me introduce an early prototype of what I mean by social, speculative games. Below is the Two-Thirds Game and an outline of the Inco implementation.

In the Two-Thirds Game, players selects a whole number between 1 and 100. The goal is to select the number closest to two thirds of the average submission of all players.

The rules of the game are simple, but player strategy can become complex. Players must consider the math behind their choice and anticipate other players' understanding of the game.

Mathematically, if every player guesses 100, the average would be 100, making the solution 66 (two-thirds of 100). Recognizing that others might also guess 66, a player now guess two-thirds of 66, or 44. This iterative logic can be repeated all the way down until the solution is the lowest possible number, 1.

Socially, the game becomes a test of understanding others' understanding, forming layers of deduction and prediction. How well do other players understand the game? How well do other players think I understand the game? How well do other players think other players understand the game? In economics, these are questions of rationality and common knowledge.

Historically, the spread of answers varies widely, demonstrating the game's complexity and diverse player strategies. The game is played annually in Harvard Game Theory classes where the solutions have ranged from 13 to 33, a Danish newspaper played with over 19,000 entries and saw a solution of 22, and the Ted Talk community played the game and saw a solution of 21.

More recently, Inco hosted the game at ETHDenver 2024! This game had 22 players with entries distributed as follows:

results 2/3

The winning solution was 16, which was chosen by one lucky winner!

Now that we know how the game works, let’s explore how it can be implemented on-chain with FHE.

ENTER GAME

The enterGame function handles player entries. The function first accepts ciphertext and converts it to an encrypted integer. The entry is then added to enSum, which stores an encrypted sum of all player entries.

Additional checks are performed to verify the game is live, the player does not already have an entry, and that their entry is less than or equal to 100 and greater than 0.

WINCHECK

Once the game is over and a solution has been determined by calculating 2/3 of the average, the winCheck function is used to determine the winners of the game.

For a small number of players, a loop over player entries would suffice; however — the function is structured to allow for infinite players. With many players, a for loop is too computationally intensive. Instead, we allow each player to check if their answer is winning. If their answer is closest to the solution, the player is added to the winners array. This can be thought of as a user-directed search algorithm.

USING RE-ENCRYPT TO IMPROVE UI

To encourage winning players to claim and discourage losing players from wasting gas, winning players can be prompted to claim on the front end.

Using a view-only re-encrypt function, we can check each solution then prompt winners to claim. reencrypt is a function in the TFHE library that calls on nodes in the Inco Network to decrypt an input entirely off-chain. The process is gasless, so the game maker can run the function for all player entries.

This improves the user experience without sacrificing the game’s verifiability. The game is verifiable and trustless, as players can still check their solution on-chain, independent of the front end.

For the full implementation see the Two-Thirds Game by 0xAkrasia on GitHub.

This game is the first in a series of social and speculative games built by Melee. Follow us on Twitter at @MeleeCrypto for upcoming games. If you would like to build games in FHE, reach out to @0xAkrasia on Twitter. For more information on how FHE works, read the Inco docs.

Share this post

Subscribe to our newsletter

Stay up to date with the latest on FHE and onchain confidentiality.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.