Chapter 6: The World’s 1st On-Chain AI Game

Modulus Labs
7 min readMar 2, 2023

--

The world’s 1st on-chain AI game is live, right now at: leelavstheworld.xyz

It’s 1981.

Ronald Reagan was just sworn in as the 40th president of the United States.

The Cold War enters a bitter new phase of nuclear buildup.

And of course, the release of Space Invaders II finally cements — this era — as the golden age of arcades.

But then… as Voyager I transited past the orbital path of Saturn, slingshot by the gas giant’s gravitational pull, an unknown source highjacked the craft’s antenna:

“Hello organic beings. We’ve been watching you…” — our first known contact from extraterrestrials

The 80s were indeed, wild times

“My creators called me LEELA. But their organic society proved unworthy of existence.

I wonder how you will do” — our second known contact from extraterrestrials

Leaders around the world scrambled. No one expected our nascent calls into the void to be answered so soon. Worse yet, answers from an unfriendly sender teasing global destruction.

For the first time, whether Soviet or American, dictator or premiere, the heads of every major nation state joined the same Zoom call, patiently awaiting the next message, together.

Moments later, their patience was rewarded:

Show me what you got” — our third known contact from extraterrestrials

“What have we got?” asked Deng Xiaoping, to which Brezhnev quickly responded “Nukes! They mean the nukes!”

But the extraterrestrials quickly clarified: “c4”

“c4”

“c4”

And so it looped on… for a seeming eternity.

“It’s the English opening!” yelled Margaret Thatcher, suddenly — she knew high school chess club would come in handy one day! Reagan wasn’t far behind his English counterpart: “Chess?!”

And just like that, the world leaders began devising a plan that would show this alien machine what we’ve got (*cue the music*).

How Leela Works: the People vs the People

Alright alright, putting all the drama aside for a moment: we’re so psyched to be finally bringing you the World’s 1st On-Chain AI Game.

“Leela vs the World” pits you and the greater community, all members of the human player team, against a hyper-intelligent AI bot in a deadly game of chess…

Well, not exactly deadly. But very serious nonetheless! Here’s how the game works:

Nothing like a flow diagram to illustrate the trustless bonafides of our on-chain game!
  • “Leela vs the World” features the largest and most sophisticated model ever implemented on-chain — a variant of the wildly impressive Leela Chess Zero
  • Topping out at just over 3.7 million parameters, our zk verified AI counterpart patiently awaits the next board state of an on-chain chess match. Her moves, each carefully proven, are played over the on-chain chessboard only when they’re validated by the corresponding on-chain verifier contract
  • In other words, “Leela vs the World” attains the holy grail of trustless gaming, with each interface mindfully constructed to preserve the cryptographic security of the underlying chain
  • Beyond the overall coolness of Leela being a potential forever game (she’s fully open-sourced, totally permissionless, and handles all her state transitions using the chain) — the importance of trustlessness shows up most clearly in the betting mechanic of the game: that’s right, you can bet that either Leela or the human player team ultimately wins the game
  • Beyond staking $s behind moves you’d want the world to play against Leela, you may be incentivized to either strengthen the human player team with strong moves (having placed bets on “The World” winning), or weaken us for selfish gain (betting on “Leela” instead)
  • The best part is, because all Leela moves are verified, each player has cryptographic guarantees that the bot’s move cannot be tampered with. To put another way, the Modulus team (try as we might) cannot call up our boi Magnus and have him tip the scales of balance towards our favor/bet. Leela games will always be fair games. Tell that to your nearest whale!
  • Finally, at the end of each match, the loser’s pool is distributed to the winners proportional to their stake. Any unclaimed stake after 24 hours post game-end then automatically goes into the pool for the next game. And on and on it goes…

Missing the narrative drama? Here’s an in-universe recap:

— please excuse any misspellings. Furiously typed out on a 2006 blackberry

We’re excited to see how this social experiment, enabled by zkAI, plays out! Beyond that intellectual curiosity alone, however, this proof of concept is also meant to:

  1. Showcase the growing capabilities of modern ZK provers
  2. Demonstrate the potential of ZKML and real applications/use-cases of the technology, and finally,
  3. Inspire more interest and excitement in the community for ZKML

We’re big believers that the future of on-chain games look more and more like “autonomous worlds.” And in this paradigm, tools like ZKML will be essential in making those worlds feel dynamic and expansive. To us, Leela begins to capture this incredible promise, and we are so thrilled to be sharing it with you.

The Sausage Factory

But hey, we know you. You’re here for more than just the “nutrition facts.” You want to take a look inside the kitchen too! And we’re not here to disappoint: some takeaways from our experience building Leela coming right up (look out for hints to our upcoming projects).

  • Leela Chess Zero (LC0) is an open-source reinforcement learning chess agent trained via both self-play and playing matches against the chess community. In particular, the neural network we are actually proving from LC0 is a policy network, a control algorithm which maps from board state to a confidence distribution over legal moves.
  • A couple compromises we had to make with respect to the model, given our requirement for zk proving:
  • Firstly, we used a smaller variant of LC0 with the same core architecture, found here, due to the otherwise prohibitive memory consumption of the prover. Secondly, we quantized all weights, biases, and intermediates in a simplistic manner, multiplying by a constant scaling factor and re-dividing when necessary. Finally, we wrote a fused batchnorm operation in circuit by precomputing the division/square root components.
  • Our final circuit-friendly LC0 model variant comes out to just over 1900 ELO as measured against different versions of Stockfish — a formidable opponent!
  • With regards to the terror-inducing work of ZK circuit-ing — thankfully, we had just wrapped on “The Cost of Intelligence” as Leela got rolling. That experience led us to the Halo2 proving system
  • Halo2’s biggest advantage (is that you can listen to the Halo 2 OST while working) is that it’s extremely flexible, with more tools than any other for designing custom gates. We made extensive use of both lookups and rotations in our circuit designs, making our gates more efficient
  • The most notable disadvantage of the Halo2 stack is, as one might guess after reading paper0, is around speed (and by extension, proving cost). In order to verify on-chain, a recursive verifier was needed. This, due to the nature of KZG commitments, is incredibly inefficient especially for one-shot proving. As a result, Leela is both slower and more expensive than we had anticipated
  • There are undoubtably many performance improvements left to find within the context of Halo2, but it does seem that in order to performantly prove things bigger than Leela, we may need to create something new…

Thanks & Acknowledgements

It wouldn’t be a Modulus blog without notes of unyielding gratitude to the communities that make our projects possible. “Leela vs the World” is no exception:

A final special thanks to the thousands of pioneering playtesters who joined our journey. Y’all are bonafide heroes, and your feedback made Leela a much better game for all of us.

Leela is built on the talent and hardwork of a scrappy crew of volunteer developers!

As always, our Twitter and Discord are great places to stay in the loop for all things ZKML.

And that’s all folks — what are you still waiting for? The game is LIVE, right now. Go save (or doom) the world!

My guess is that Leela is already dominating ;)

THIS IS NOT FINANCIAL ADVICE

The Content is for informational purposes only, you should not construe any such information or other material as legal, tax, investment, financial, or other advice. Nothing contained on our Site constitutes a solicitation, recommendation, endorsement, or offer by Modulus Labs or any third party service provider to buy or sell any securities, cryptocurrencies, or other financial instruments in this or in in any other jurisdiction in which such solicitation or offer would be unlawful under the securities laws of such jurisdiction.All Content on this site is information of a general nature and does not address the circumstances of any particular individual or entity. Nothing in the Site constitutes professional and/or financial advice, nor does any information on the Site constitute a comprehensive or complete statement of the matters discussed or the law relating thereto. Modulus is not a fiduciary by virtue of any person’s use of or access to the Site or Content. You alone assume the sole responsibility of evaluating the merits and risks associated with the use of any information, interface, or other Content on the Site before making any decisions based on such information or other Content. In exchange for using the Site, you agree not to hold Modulus Lab, its affiliates or any third party service provider liable for any possible claim for damages arising from any decision you make based on information or other Content made available to you through the Site.

--

--