The power of secrets: Zero-knowledge proofs and game development
October 03, 2023

The power of secrets: Zero-knowledge proofs and game development

We’re all aware that the gaming industry desperately needs new tools to solve its long-standing privacy and data security issues. Although studio-owned platforms are user-friendly, they often leave much to be desired regarding how safely your data is being handled. We’ve all seen some of our favorite online games be victims of DDoS attacks or the myriad gaming data leaks in the past few years.

We need to rethink the way privacy in video games works, and zero-knowledge (ZK) technology can help game devs and players move forward. So as gaming shifts towards using bootstrapped, open-source, and privacy-enhancing frameworks, game developers can focus on the most crucial part: telling good stories.

What could gaming look like with zero-knowledge built in? 

Overall, more privacy can help indie games scale without you needing to be in charge of everything or beholden to the whims of a larger studio. It’s not only an infrastructure solution; it’s the answer to a significant bottleneck in every indie developer’s pipeline.

ZKgames are nothing new: experiments by Kryha, Demox Labs, and other Aleo Community members explore similar approaches to showing simple examples of the power of zero-knowledge on a technical and gameplay level. But is there a place in the gaming industry for zero-knowledge proofs for games, and what can this technology bring to the table that traditional methods of intrigue and mystery in games can't?

In this article, you’ll find out how ZK can make existing games better, more interesting, and more fun. To answer this question, I set out to create the framework for my own ZK game, with cryptography at the heart of the storyline. 

Creating a zero-knowledge storyline 

A common framework indie game makers use is the “Core Gameplay Loop” concept. In a nutshell, you’re supposed to consider what activities will keep people coming back and design the core gameplay mechanics around them.

In traditional games, the gameplay loop often revolves around a series of tasks or quests that the player must complete to progress. For the game we’re conceptualizing in this piece, I wanted these tasks to be more than just arbitrary objectives; they needed to be cryptographic challenges solvable through ZK proofs.

I took inspiration from the Monkey Island and King’s Quest games and started looking for the core gameplay beats and interactions that made them classics. In essence, they’re linear games where your progress is bookended by a challenge. With that in mind, our ZK game will center around similar interactions, framed around an air of mystery and intrigue. The rudimentary version of how this game runs looks like this: You update your state by acquiring special items to drive the narrative forward. These “Artifacts,” as I came to call them, act as the proof that pushes the player to their next objective. 

I thought it would be interesting if each Artifact unlocked secret dialog options with NPCs. After deciding that I wanted Artifacts to be at the core of this game, I wanted to add a suspicion mechanic with the NPCs. That would serve as another layer of proof verification, sort of a trial to ensure you have the required Artifact.

The challenge was to make the ZK elements fit and enhance the story and gameplay. And that's where the real fun began.

Here’s the gameplay loop I created:

  • Trigger: The player initiates dialog with an NPC.

  • Suspicion: They gain some sort of context, but are met with a blocker.

  • Test: The NPC initiates a SNARK check that verifies whether the player meets the conditions to continue the dialog. Or the player solves a puzzle using an Artifact (another, separate proof). For the first instance, the test is passed without revealing the Artifact itself. In contrast, they reveal it in the puzzle-solving instance, which automatically “dissolves the Artifact’s power.” In other words, the player reveals the contents of their proof, which can still be helpful in future dialog with NPCs.

  • Outcome: The player passes the NPC verification and gains a puzzle clue or unlocks the puzzle itself by revealing the artifact. What they find in these two instances points them toward the next step in their mission.

I analyzed this gameplay loop to understand better how SNARKs function in the game, which also determined the role of each verification in advancing the gameplay.

Proof 1: ZK Artifacts

First, ZK Artifacts are scattered throughout the game world. These can be items of significance to the plot, like a key, a tool, or a document. You discover them by solving puzzles or passing trust checks with key NPCs.

Once an Artifact has been found, it will need to be verified. They will have both public data (e.g., a description or image) and secret data (e.g., a code or passphrase). When you find an artifact, you don't immediately know its significance. You can verify if it's one of the ZK Artifacts you need using their public data without revealing the secret data. Finally, players can find some clues by solving ZK puzzles or completing trust checks given by NPCs. Solving these will bring you closer to pinpointing the next step to take so you can finish a level.

Proof 2: NPC Trust Checks

When you first approach an NPC, they have a base trust level. This can be influenced by your actions and the Artifacts you possess.

However, at certain pivotal moments, NPCs will challenge you to prove your authenticity. Using ZK-SNARKs, you can validate your claims without revealing your identity or the specifics of your Artifacts.

As you gain an NPC's trust, they might provide you with clues about Artifact locations, assist you in challenges, or even give you unique Artifacts to solve the next puzzle.

The concept was starting to fall into place. Now, all we need is a story to tie everything together.

Creating a ZK story for a ZK world 

The cool part about building just the underlying mechanics for this game is that any of you can take and run with it to tell whatever stories you want. The above examples used Artifacts, but the suspicion and mystery mechanics underlying the concept lend themselves to some of the best scenarios out there for a game.

For example, what if your character is the archetypal time-traveling mad scientist? You’re testing your grand invention and end up stuck in a foreign period with the task of returning home without blowing your cover with the locals. Bingo, you’ve got a game.

You could also be a hacker/spy exploring a cyberpunk hellscape. Your task? To infiltrate the headquarters of a corrupt corporation and uncover a plot to destabilize the cypherpunk underground. And you know what? Make this one a JRPG.

Sci-fi is cool and all, but what if you could instead live in today’s world and be a privacy activist looking to help people protect their information from the ground up? You could even add some special challenges when debating with regulators and nay-sayers for an added challenge.

These are just some of the possibilities among many. My goal here is to show you just how versatile this primitive can be for all kinds of games. This isn’t my game; it belongs to all of us now. Similar to how “Battleship” and “Boloney!” became the go-to ZK games in all of Aleo’s events, this new game concept can spark builders like you to make the next great zero-knowledge game.

Resources for ZK game building 

If you’re looking to find some resources on how to build and deploy a ZK game on Aleo, here are some of the pieces of the puzzle that came in particularly handy when conceptualizing this game:

If I were to launch this game myself, I’d start by understanding how successful ZK game devs have launched their projects in the past, then build an understanding of Leo. Finally, I’d jump into the web app implementation part, which can be the trickiest: there may be only one Aleo blockchain, but there are thousands of ways to make an online game. 

Why ZK is defining the future of gaming 

It’s possible to run a similar version of this game on nothing but traditional rails, but it’s only through Aleo’s ZK infrastructure that this game can become more than just an idea. Sam Parker explains in this talk why Your Game Will Suck Without Zero Knowledge Proofs.

As an imperfect information game by design, this game framework relies on both the player and the NPCs not knowing specific details of the narrative from the beginning. Even if you were to introduce some randomness mechanic into the gameplay, a variable would still be stored somewhere in the code that players could use to cheat their way through a challenging level.

By relying on SNARKs, this game concept enables real experiences of surprise, intrigue, and even a competitive aspect when you consider how people may try and get to the end of a level in record time. No playthrough will be the same, as the proof unlocking the puzzle can be as dynamic or static as the person deploying the game chooses.

In the end, this experiment has helped us find a framework that can be used to launch games like “Papers Please,” “Mist,” and “Return of the Obra Dinn” in a way that doesn’t rely on the game designers plotting out every decision on a tree but rather peppering zero-knowledge proofs across a level and letting their verification drive the story forward. 

This is where blockchain games start to show their actual potential past the P2E casinos and gimmick NFT in-game items. So, the ball’s in your court now to iterate on what implementations you can find for this concept in your own ZK games.

Ready to try your hand at building a ZK game on Aleo? Check out our developer documentation or apply for a grant.