The zk-Mastermind Game: A pioneer Cardano Dapp

Hey there! We're thrilled to announce the release of the beta version of our Mastermind game. This demo serves as a showcase for a Zero-Knowledge Dapp, leveraging the powerful capabilities of the Hydra protocol. It marks a significant milestone for Cardano in the realm of Zero-Knowledge technology.

First of all, this was made possible through funding from Project Catalyst as part of our F10 proposal. We extend our sincere gratitude to the entire community whose support has been key to complete this endeavour. Special thanks go to the numerous platforms like Gimbalabs, LATAM Townhall, Asia Townhall, and Proof of Integrity for opening spaces where we could present our idea. Additionally, we are deeply appreciative of the continous assistance provided by the Hydra and the Aiken & CF team during the dapp development process.

The objective of this project was to push forward the boundaries of what's achievable on Cardano in the field of Zero-Knowledge cryptography. Two important zk-validators were developed for this demo: One that it is built entirely from Plutus V2 primitives and an optimized one using the Plutus V3 primitives. Given the actual mainnet budget constraints and the dynamic of the game, we opted to leverage the Hydra protocol to facilitate seamless and rapid transactions. This decision was imperative as certain operations of the validators proved to be computionally expensive, and the game is designed to be played at range of 10 to 20 transactions, making the Hydra protocol an ideal fit for supporting this dApp. However, with the upcoming hard fork, we will be able to deploy similar dApps with equivalent cryptographic properties directly on the L1 layer.

How the game works?

Mastermind is a guessing game of two players, a CM (code master) arranges a secret array of colored balls and a CB (code breaker) tries to find out the secret. During the game the CM will give clues to the CB in each try; one clue is the white peg where the CB finds out a correct color ball but in incorrect order; additionally, when the CB find a ball that matches the order and color, a black peg will be provided by the CM as a clue. In our implementation, the CB wins whenever he/she finds out the secret array (4 black pegs) within 10 turns; on the other hand, if the CB can’t find the solution within 10 turns the CM wins. Also, to make it more exciting… the players bet and arbitrary quantity of tokens. For example, the CM can open the game commiting 15 Hada, later another player can join as a CB betting the same with a 30 Hada in total. Whenever one of them wins, they can claim the total ammount.

But this game poses a problem... What if the CM wants to trick the CB with wrong clues? What happens if the CM omits some clues to confuse the CB opponent? Well, here the Zero-Knowledge part comes into play. With this cryptographic primitive, we can construct plausible statements of secret data. Specifically, we can say, "the CM's clues are correct given the current CB guess" without directly needing to disclose the secret array to demonstrate it. Thus, the smart contract can take this proofs to check wether a clue is malicious or not. This sets an interesting example where we can keep some information secret (the color array) but still be able to prove some information about this secret. This feature opens new possibilities about what can be made in Cardano!

The demo will be available in our website to all of you to play and have fun with your friends. We launched a transparency page in the website where all the code and outputs of the catalyst proposal can be found. In this regard, the verification functions of the zk-proofs that we used in the game smart contracts are open source, plus we developed our own incremental commit components for Hydra which also are available. We hope that these advancements serve to catalyze new applications and use-cases in our ecosystem!

Greets!

Modulo-p team