## ZKML for On-Chain Games and Autonomous Worlds ![for_respected_patron.png](https://hackmd.io/_uploads/SJaQVXLX6.png) At EZKL, we've already seen a number of creative instances where ZKML, and more broadly zero-knowledge computation, have been implemented onchain. Examples like noya.ai and [cryptoidol.tech](https://cryptoidol.tech) prove that when you combine the verifiable compute power of blockchains with the trustless affordances of ZK, new forms of applications that previously were unfeasible are now possible. Games like [Dark Forest](https://zkga.me/) and [ZK Hunt](https://0xparc.org/blog/zk-hunt) have been pioneers in using the privacy affordances of zero-knowledge proofs to create games with fog-of-war or hidden information mechanics. We believe that the verifiability of computation is an underexplored set of tools for on-chain game developers, and we’ve seen an increasing amount of developer and player energy focused on this paradigm. Broadly, we've seen the flourishing of three principal methods for ZKML game-design that have inklings of popularity with both game designers and players. 1. The Model is the Game 2. ZKML as Digital Physics 3. ZKML for Lore and Narrative The earliest explorations that we've seen in the merger of on-chain games and ZKML are ones where the ZKML model IS the game. Here, players interact directly with the ZKML model, and this interaction constitutes the entirety of the game dynamics. A representative example of this is the [cryptoidol](https://cryptoidol.tech/) game that we developed internally. Here players vie to be canonized as the best singer in an eternally running singing contest. They sing into the browser and generate a proof that they were correctly judged by a public judging model. They can then submit their score and associated proof on-chain to be inserted into a running leaderboard. Another example of this is the [onchain-tictactoe](https://github.com/JSeam2/onchain-tictactoe) library, where a neural network is trained on tictactoe telemetry data to recognize winning game patterns, such that games can be played off-chain and then submitted and settled on-chain in their final state. ![image.png](https://hackmd.io/_uploads/SyAIl7LQp.png) > 1. Here the model is the game and all interactions the player has are directly with the ZKML model. Most interactions will be single player. This pattern, of a neural network encoding the "rules" of the game, bridges into the next design paradigm where ZKML helps create "on-chain physics" for a world. Though the tictactoe model leverages a neural network, this design pattern requires a slight shift in thinking about what ZKML enables. In some sense, when ZKML is focused on neural network "inference" (i.e post training predictions), there is nothing that constrains the computations that are "ZK'ed" to be exclusive to ML. Matrix multiplication can be used to model state transitions for an AW's state, like say a world's weather. A game that exemplified this idea was BabyGaya (sadly no longer online), where the entire world state was altered at each block using ZK'ed matrix multiplication that _anyone_ could run. ![image.png](https://hackmd.io/_uploads/SkTx-X87p.png) > 2. Here the player interacts with the world the ZKML model creates. Many players can interact with this shared state. Finally, the third pattern, perhaps the most ambitious, is one where ZKML is leveraged to build a world's lore and narrative. Here ML models can be used to create NPCs and storylines that are small parts of a larger whole. This could for instance be an a language model writing a world's narrative as the game progresses, or writing storylines for individual NPCs. As a first exploration in this we created our own on-chain NPC (fully fleshed out demo pending), which we call the "worm". Here we implement a generative model, described [here](https://github.com/TuragaLab/wormvae), which models the voltage activations (given sensory inputs) of the C. Elegans nervous system. We generate sensory inputs for the worm using an on-chain game engine such as [MUD](https://github.com/latticexyz/mud?plain=1), and then generate proofs that update the worm's brain activity given the on-chain sensory environment. Anyone can run these proofs and keep the worm "alive" on-chain, effectively creating an autonomous agent that other games and interfaces can leverage within their own games. Reusable and permisionless NPCs that are shared across games and worlds then become possible 🥳. ![image.png](https://hackmd.io/_uploads/H120WXLXa.png) > 3. Here the world's lore such as its narratives and the characters the player encounters are generated by a zkml model. As before, many players can participate in this lore and experience this narrative. Though still in its infancy, on-chain game development gives game designers truly new affordances. Current on-chain game development frameworks have lowered the barrier to entry for the creation of AW, but what they lack is a general purpose compute engine. Given that ZKML libraries are broadly useful for creating both powerful ML models AND for general purpose computations, we believe that easy to use ZKML libraries can complement game engines like MUD as the physics and computation engine for AW.