CaptainZ

CaptainZ

Prompt Engineer. Focusing on AI, ZKP and Onchain Game. 每周一篇严肃/深度长文。专注于AI,零知识证明,全链游戏,还有心理学。
twitter

StarkNet: How to Use ZKP to Create Verifiable On-Chain Games

Blockchain games have failed to fulfill their promises. The limitations of scale and high costs have restricted most blockchain games to tokenizing game assets. However, with cheap and fast transactions on Starknet and the new Dojo on-chain game engine, game assets can not only be privately owned but also have their game logic verified on the chain.

The global gaming market is estimated to be worth $245 billion by 2023, making it one of the largest segments in the global entertainment industry. With its promise of unlimited interoperability, blockchain games offer a more exciting open space for the gaming world compared to the current scenario. Just as multiplayer games have added a new dimension to the gaming ecosystem, on-chain games can become more interesting and relevant.

However, this promise has faced the challenges of expensive and slow transactions, which are two issues that games absolutely cannot have. Therefore, creating successful on-chain games has been nearly impossible.

But with the maturity of rollup technology, the promise of on-chain games is finally being realized.

In this article, we will explore how high TPS supported by Starknet enables on-chain games. We will also look at Dojo, the first community-built verifiable game engine, and how it empowers builders using Starknet. Finally, we will discuss the future of Dojo and its unlocking potential for blockchain games.

Cryptogames#

When we talk about blockchain games, the two most popular concepts empowered by blockchain are ownership of in-game assets and interoperability.

Ownership of in-game assets means that game assets belong to the user's wallet. In other words, they do not belong to the game developers or a simple email account stored on a central server, and game developers cannot remotely delete them. In blockchain games, the assets you create or earn truly belong to you.

Once these assets belong to you, interoperability can be achieved. With interoperability, characters and assets from one game can be transferred to another game or world. If you have invested hundreds of hours in a game but decide to stop playing, you can take those hard-earned assets to the new game of your choice.

To achieve these two concepts, games must be built on-chain. This means that all in-game assets, actions taken by players, and any other state changes must be done as transactions on the blockchain (either individually or as aggregated transactions pushed periodically). On a relatively decentralized blockchain, the cost of a single transaction can range from a few cents to hundreds of dollars (during congestion) and may take several minutes or longer. Clearly, this makes operating large-scale game infrastructure on such platforms extremely expensive, slow, and impractical.

Starknet and Cheap Computation#

However, with the emergence of rollup mechanisms like Starknet, everything is changing.

Starknet is a Layer 2 rollup mechanism developed by StarkWare (commonly known as ZK-Rollup) that significantly reduces the cost of computation and storage using an encryption system called STARKs.

Starknet (along with Cairo, the smart contract language of Starknet) allows decentralized applications to process high transaction rates at minimal cost while still leveraging the security of Ethereum. This cheap and fast transaction is exactly what is needed to fulfill the promise of blockchain games. Now games can be fully on-chain, fast, and affordable.

But even with the ability to be on-chain, for blockchain games to thrive, they need a second key building block: a verifiable game engine.

What is a Game Engine#

A game engine is a software framework that makes beautiful scenes, fast player movements, and realistic character behaviors possible in your favorite games. Game engines typically include libraries and support programs that provide developers with a framework so they don't have to recreate basic systems (such as physics, graphics, and game mechanics) from scratch for each game. Game engines can also include audio and video processing, rendering 3D effects, and AI features.

Game engines are the stage on which games are built.

Most of the games we love to play owe their existence to the two most popular game engines in the world: Unity and Unreal Engine. Unreal Engine, developed by Epic Games, has been used in popular games like Fortnite, Street Fighter V, and Gears of War series. Unity, another major player in the game engine industry, has turned games like Hearthstone, Ori and the Blind Forest, and Pokémon Go into reality.

With Starknet fulfilling the promise of encrypted games, a wave of projects has started building games on Starknet. However, what is still missing is an encrypted game engine that allows developers to build games on-chain without having to write custom code for basic physics, logic, and game mechanics.

Dojo - The First Verifiable On-Chain Game Engine#

Dojo is an encrypted game engine. It is a community-built verifiable game engine and toolchain for building on-chain games and autonomous worlds. It turns the promise of encrypted games into reality.

The number of games using Dojo on Starknet is rapidly growing. Some of the most popular ones include:

Influence - A grand strategy MMO set in a distant asteroid belt with a player-owned open economy. Users can buy NFTs to explore and develop asteroids. All asteroids exist in the same world, and players can interact with each other.

Realms - A strategy game with an 8000-tile map of land with specific names, shapes, sizes, and geographical features that provide on-chain utility to landowners (users), such as resource generation and interchangeable house prototypes, allowing for economic gameplay.

CafeCosmos - A land-based on-chain game where users must efficiently manage resources. This includes resource gathering, farming, animal husbandry, crafting appliances and furniture, and trading assets, among others.

Dojo Components#

The Dojo ecosystem consists of the following components:

  • ECS (Entity Component System) written in Cairo
  • Sozu Migration Planner
  • Torii Network and Index Stack
  • Katana RPC Development Network

The ECS system is a design pattern used in game development to improve code maintainability. The ECS system allows game developers to add unique functionalities (components) to game objects (entities), making the entire scene work as an integrated system. The ECS framework of Dojo, specifically designed for blockchain-based game development, enhances modularity, efficiency, and flexibility, which is crucial for managing the unique challenges of blockchain environments. This enables the creation of complex, dynamic games on the blockchain, supporting diverse game mechanics and interactions while leveraging the transparency and decentralization advantages of blockchain technology. As Dojo is written in Cairo, it maximizes the efficiency of the code that needs to be proven.

Sozu is a toolchain specifically written for building and migrating planning. In other words, Sozu can be used to deploy a game "world" on Starknet. With a simple sozo migrate command, an instance of a game world can be deployed on-chain. Sozo is currently only available as a command-line interface (CLI) tool. However, a graphical user interface (GUI) is currently under development.

Torii is a comprehensive indexing and networking layer for the Dojo world. Built on top of Dojo, the Torii system aims to index any events happening in the game world deployed on-chain. It systematically organizes the state of the Dojo world, making querying data from clients convenient and efficient. Considering the many changes in the state of the game - imagine every click as a state change - an efficient querying system is a useful feature on the Dojo stack. Queries on Torii use GraphQL.

Katana is an extremely fast local Starknet node designed to support local development of Dojo. Katana allows developers to test their applications on this "development net" for quick local development. Developers can use the Katana network to test transactions sent in the game. Katana provides convenient RPC methods to change the configuration of the network as needed (e.g., changing block time or allowing zero-fee transactions). Additionally, Katana supports version v0.3.0 of the Starknet JSON-RPC specification (the latest version as of June 2023). Local Starknet JSON calls like starknet_getTransactionReceipt, starknet_getStorageAt, etc., can be used on Katana.

The Future of Dojo and Cryptogames#

The Dojo community continues to research and develop to drive the advancement of cryptogames. In addition to improving existing components, the main developers are also working on:

  • L3s for games
  • Optimistic rollup updates
  • Client-side proofs
  • Cross-chain asset transfers

L3s for games - Dojo is researching the feasibility of developing games as L3s on Starknet. This means deploying a separate chain on Starknet that periodically proves the execution of its transactions and submits the proofs to Starknet (L2). Starknet aggregates this proof with other transactions on the network and submits it to Ethereum L1, where the proof is verified. This solution can increase the scalability of games, potentially by several orders of magnitude. (As an additional step, imagine building a disposable new layer on the game layer every time a player attempts a level in the game.)

Optimistic rollup updates - How many times have we sat quietly waiting for the "transaction in progress..." text in our wallets to turn green and show "verified"? Many times. If every action of a player in the game is sent as a separate transaction, players will waste a lot of time waiting for transactions to be accepted. Optimistic rollup updates - one of the additional features Dojo is perfecting as part of the stack - solve this problem by allowing players to continue playing optimistically in the client (the browser itself) while transactions are being executed. If, for some reason, the result of the transaction differs from what was run in the browser, the game will coordinate the change.

Client-side proofs - Alongside optimistic updates running on the client, Dojo is exploring the possibility of client-side proofs for parts of transactions sent on-chain. This would allow games built on top of Dojo to effectively hide some of the inputs passed by users, as zero-knowledge proofs (ZK proofs) can be created on the client to attest to these inputs. In turn, this ZK proof can be sent to the sorter on-chain to execute the rest of the transaction.

Utilizing storage proofs - Storage proofs are an encryption method used to store blockchain information in a way that allows it to be shared across chains. Similar to oracles, they provide proof of the authenticity of information. However, unlike oracles, they do not require trust in a third party to provide this proof - with storage proofs, trust is built into the storage. Storage proofs also allow for proving the validity of the state of another chain or layer built on top of Ethereum.

Dojo is working with the Herodotus team to implement storage proofs in Dojo, making cross-chain asset transfers unnecessary. Ownership of assets from different chains can be proven using storage proofs, and users will be able to use their assets in different games on different chains or layers.

Original article: https://starkware.co/resource/dojo-on-starknet-game-on/

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.