zkAcademy #6: Is gaming the best usecase for zk tech? with Starknet, presented by Union Build

7 Nov 2023 · 33:40

The Rollup hosts Rohit, a longtime Starknet contributor with a role at the Starknet Foundation and an active contributor to JediSwap, to make the case for gaming as zk technology's best use case. They cover how Starknet's zk-rollup architecture enables persistent, multiplayer on-chain worlds, digital asset ownership, and resistance to shutdown or censorship compared to traditional Web2 games.

Topics

Transcript

[Music] [Music] [Applause] hey everyone uh today I'm going to talk about um what bringing games onchain means and how uh onchain games unlock new kind of gaming experience or like even help in some ways expanding the gaming space

gaming industry in general and all of that is uh possible because of the zero knowledge technology and ZK VMS like stocket and and some other which might be in develop M so uh first uh let's talk about uh why web3 games why do they matter or or sometimes we call them onchain games as well so onchain games promise a new kind of world uh in this world uh the games provides true ownership to the users uh what do we mean by ownership like users uh truly on their in-game items it could

be uh like a swad in a in a game you have or it could be ingame currencies you have so users or players uh can use these assets freely uh they can use these assets outside of the game as well they can take it outside of the game can sell these assets uh in an open market as well uh the second benefit is hardness so uh I'm not sure how many people are familiar with vitalik's story into Bitcoin like he how he came to found ethereum so essentially like he he used to play a game a lot and he lost access to one of his game item uh and

that made him really sad and uh basically it made him think like if there could be a way uh in which like the rules of the game uh he he can have assurity on like the rules of the game like this is what is going to follow so hardness means like players can be assured that the algorithm of a game uh the rules of a game doesn't chain doesn't change arbitrarily that there is a due process uh of changing the rules and and players are upfront know about that and at the same time like uh with Onan games it also gives players freedom in terms of if a game game changes their rules like in some kind of

consensus uh the players can Fork the game keep the original logic of the game and keep playing the original game so there can be like two alternative version of the same game so it gives that uh freedom of fork uh and as a result like player always no player are always in control of what they are exactly playing the third benefit is composability uh just like in D the the biggest benefit of D has been composability where a smart contract of a can use the smart contract of Unis swap uh to use the swap functionality so similarly in case of games onchain games will enable the composable world where uh one game can use the logic of another

game into its own smart contact for an example um imagine like uh you are playing a game of Minecraft and in that game of Minecraft you might have a function called run uh someone can uh create a micro game uh and use the Run function which was actually used in the Minecraft game and they use the same function in their own game so like different like games can start collaborating in a very different way where like different smart contracts are using Code of other smart contracts and the fourth and one of the most important is privacy so privacy is something like which doesn't exist today at all in in

any gaming world uh where it matters for an example like uh a game of poker or you don't want to reveal what cards you hold to your opponent uh or even to uh a server like because you don't know someone somebody who is having access to the server can start playing against you as an opponent so they have access to your cards and they can play unfairly against you so onchain games or web3 games enable all the these benefits uh like on on a metaphorical level like they basically bring the same thing to games what uh D brought to finance like defi made Finance more open composable uh some something which is

like they can expect like hardness and and and like lot of other things similarly onchain games all these benefits to the gaming world but uh building onchain games is really hard uh especially it's it's really hard with uh evm uh and languages like solidity uh and thanks to uh the newer applications uh or newer implementations of z kvms uh one of the example is stocket uh they help some of the challenges so we'll go into like uh what are the challenges and like how it is solved by ZK and ZK VMS like stocket so uh one of the biggest

challenge when you are creating games on something like solidity uh using solidity is so solidity was never optimized to build complex application solidity uh was created seven years ago it was created in the constraint of what could be on chain uh and and in that world like uh when ethereum was trying to do everything on chain from settlement to execution uh to data stories everything and now we are moving into an uh you can say Layer Two world where you are trying to bring computation offchain and settlement onchain but solidity was never designed uh keeping these kind of applications in mind so as a result uh solidity had this

arbitary restriction in terms of contract size what could be the maximum file size of a contract of a of a smart contract because of that uh like it it doesn't matter for def applications because def applications are usually uh smaller applications simpler applications uh in terms of logic but when you are writing gaming applications you might have a much larger code base so for that uh people who are creating games in solidity they come up with this hacky Solutions one of the solution is called diamond pattern so you start splitting your code into multiple different smart contracts arbitrarily now imagine like you are um creating a

game and as a game developer all you want want to care about is like you can easily write the the functions the logic of the game but now you have to take care of okay the the Contex sizes well okay this file size could be maximum this so you start uh splitting the code into different files and then your code becomes really messy because like some part of the code is somewhere and some part of the code is somewhere else so it becomes really messy writing code with solidity uh so uh like some of the layer to Solutions are are coming up with their own uh ZK native languages so Cairo is one example so Cairo is built uh it's a superior language to build large complex onchain applications so

why because for an example there is no contact size limit so you can like freely write your code however you you want to do uh similarly like uh many of the games will want to write uh ZK Logic on the client side sometimes you want to prove on the client side that uh I hold this card you don't want to put that information on chin because if you put that information on chin then it becomes public everyone knows that so if you don't want to put it on chin you need to achieve client side privacy or you need to basically Implement client side zero knowledge logic so something like that is not possible with solidity uh to achieve that with something like solidity you will need to write your own custom circuit with uh something like

circom as a language which is very very complex uh and like again as a game developer you don't want to get into that so Cairo helps with both uh it helps you write logic in a much simpler way like without any of these limitations it helps you write ZK logic with the same language you don't need to learn another language to achieve that also is uh optimized for computationally expensive applications you you can write application which require uh more comput complex computation it's it's optimized for that uh one another problem is like uh you don't get any privacy with public blockchain so when you are creating games uh sometimes you need to have

privacy for an example if you are uh playing a game of fer as I mentioned you don't want to reveal your cards to your opponent or not even to a server so if a game is run on a blockchain pretty much everyone can see that so that's where as I mentioned client side privacy comes into the picture and uh this this is possible by Cairo as I mentioned so with Cairo or or or something similar to that you can achieve ZK proof creation and verification on the client Side by client I mean like your users mobile device or their laptops or or their desktops so this enables uh creating poker in a very uh trustless way where you do not have to trust a server to

execute the the poker game like something like this doesn't exist today like even if you are playing at any poker website you are basically trusting the website to not see your cards and does not play against you but with this you get the assurity because even the server cannot see what cards you hold uh so it gives like birth to this completely new paradigm uh in in case of these kind of games similarly like it it applies to games like uh Tower Defense kind of games as well where you do not want your opponent to see what kind of Defense you have set up because if if my opponent already see what kind of Defense I have set up then I can basically create the the opponent can create the counter unit against that

defense so privacy becomes important and this is enabled by ZK and ZK VMS uh another problem is web3 as we all know web 3 games don't scale well uh because they rely on the underlying blockchain technology like blockchains are not scalable if if you think about like whole Layer Two space combined today like all layer TOS combined have done maximum of 70 or 80 transaction per second uh if you like do the math it could be maybe like some Millions few Millions less than 10 million transaction per day uh if you think about even one single game uh like which which could be a very good fit for

uh for like Onin games like Minecraft uh that itself has is probably 25 million to 50 million daily active users and that's just users they do billions of actions every day so blockchains cannot handle any that that kind of scale so uh how do you solve that uh again like you sol that by running your application specific environments which we call apin or layer 3es and when you do that you basically get as much scale as any web to application how because now you can run all the computation on an AWS server or like a centralized server so you do everything on a centralized server and whatever you do uh you create a validity

proof of that and then you submit it on a blockchain so you do the onchain validation that yes uh all the logic all the computation that has been done it was done correctly so now this gives uh games the same level of scale as any uh web2 game scale but at the same time with all the benefits of blockchain like which is it still remains trustless because if you run the computation incorrectly then the validity proof will not be valid on chain and the settlement will not happen and uh last and not the least like uh we know like web 3 games have really really bad user experience uh like if we want to reach to a scale where billions of people play games onch

games we cannot imagine like people installing a wallet plugin in their browser or or like approving every single uh transaction for any in-game action they do like let's say you just want to fight with an opponent sometimes you take out your sword sometime you use your special powers and all of that so imagine like if you need to approve a transaction using your metam mask or or a wallet for each of the those in game action like it will be like like you cannot even imagine that U another problem is like gas tokens like even to do those transaction you will need native tokens uh to pay for guess and like as a game player why do I care if I have this particular layer TOS stoken or not and

then like seed phrases one of the worst like you lose access to your whole game if you lose access to your seat phrase so like all of this creates really bad user experience and we can never imagine to have millions of users uh in a game so all of that is solved by account abstraction that is built natively within the chain uh that creates a superior user experience and that is again something uh which is done by ZK based or validity rollup uh uh like stocket so how what kind of benefits net account extraction enables like you can have inapp wallet so you don't need to install a plugin instead you can use in

browser wallet or in app wallets like your your uh application can save the keys within the application uh for for some kind of sessions uh you can use multi call so you don't need to uh confirm transaction for every action you do in the game instead of that uh you can combine all the calls together and you can put one single transaction to enable that you uh usually use uh something called session Keys session Keys is something like which is very known in web2 world as well like where if you log in on Facebook like it stays logged in for like two weeks even a month so how that happens is because it stores access tokens so uh session keys

are similar to that session Keys give an application access to transact on your behalf within a certificate within a specific logic which is preset which you know like this application can only sign these kind of transaction and for a limited period of time so this makes it very easy like you don't need to ever think about there is a wallet even like users don't even need to know about if there is a wallet in the back uh similarly like you can pay for the guest fees on behalf of the users using something called pay Master this is again another benefit of native account abstraction uh and you can use uh instead of seat phrases you can basically sign transaction using secure and clip which is part of any mobile

devices like any iPhone so you can basically like sign transaction using how like you sign how you use secure encl in um saving passwords or like using any iPhone applications so yeah uh Onin games U with including all these benefits like it creates a new world it creates uh Harmony between players and developers because it gives birth to an open open economy and whenever you have open economy they grow 10x larger than the closed economy so uh that's uh about it like uh feel free to check out and feel free to ping me if you want to learn more about Onin games amazing thanks r that was uh that

was really really fun to explore from a less technical angle the applications of ZK proofs and then also of the ZK VM in general um so I got I got a few questions I think first about the ZK VM and I think I can go back on these slides here so we're seeing like quite a few of these these virtual machines pop up and like this dude here building a game with solidity is clearly unhappy and he's clearly empowered building a game with Cairo um so you you explained a bit like how complex solidity is and why the architecture is not built for gaming so

what is it about the ZK VM is it is it primarily the scalability or is there is there other components to the ZK VM that make it opportunistic for gaming yeah so uh the whole point of virtual machine is running the execution like if you think from the fundamental perspective what is execution uh you want to do some kind of math some kind of computation right so uh like you now since like we want to do trustless computation what trustless means that you want to have the maximum resources available you want to make computation really cheap because if hundreds of

nodes have to run the same computation like it will cost every given the server cost right uh as a result that the games will become very expensive so instead of that what you want to do is you want to run the computation on a centralized server on one single server you don't want to duplicate the execution but you want to prove to a blockchain that whatever you did it was correct so now for that you need to basically create a validity proof or a ZK proof so ZK VMS are differentiated because they optimized they are optimized to create all these kind of of uh computation uh compared to evm evm is optimized for like running on ethereum executing on ethereum which is a distributed Network

so fundamentally like one brings the benefit of scalability and one brings the benefit of decentralization and since with uh games you need to achieve insane scalability you need to achieve for maximum uh concentration of computation but at the same time you need to maximize for trustless got it and that's how we avoid the situation with vitalic getting nerfed exactly very cool okay um and then the other question I had was a little bit off topic from the ZK topic and a little bit more on one of the uh one of the concept that we're exploring a little bit further maybe in our next educational series but I think this

could be a good primer for that so I'm going to go all the way back to I think it was slide 10 or 11 or about native account abstraction because this is something that is available on the ZK VM on Stark net um and Native account abstraction is not quite available on ethereum uh until one of the EIP uh for account abstraction passes but we are seeing like certain layers of account abstraction put on top of ethereum um one of the best examples of this was friendtech and they allowed you to sign in with your Twitter they generated a

private key and you were able to interact with friendtech not using a seed phrase not downloading a browser extension but just by connecting your Twitter account so could you could you explain why starnet has native account abstraction and what what does the native mean with account abstraction yeah so when we are talking about evm uh so in evm like by default the account is an eoa like externally owned account right you have seed phrase and for that you have the uh for every transaction like somebody has to confirm a transaction a human being somebody has to confirm a

transac uh how you achieve account abstraction in evm is by having like a layer on top of this so you create something like what safe uh did basically you create smart contracts and then within that smart contract you write these logic that okay these uh this is how you can basically control uh this account this smart contract now like it does give you benefit of account abstraction but at the same time like think from the perspective of if if you are a user of ethereum now let's say you are using something like metamask how how will you differentiate like if if I am a native user or if I am a account abstracted

user like there are two kind of us users R right it will by default create uh conflicting user experience between different applications like there will always be conflict right it's it's not built natively like so native account extraction is by default every single account is a smart contract account so that's that's what is different in case of uh stocket and it is only possible in non evm chains because if you are looking for evm then you have to basically replicate the the code of evm and as a result you will have you'll have to apply 4337 kind of a thing which which is like an abstracted layer on top of the core protocol which is not the native account abstraction so this will by default create a unified

experience across all applications and I think that's the way to go because uh like at some point of time you will want to have users to have single kind of account like if you think about it Facebook is what someone uses across the different games or different application so similar l in games as well like you will like to see similar kind of experiences where a user will have one Social account and they will use it across games or social F applications or anything got it yeah that that makes sense I think we're all kind of like Curious and like patiently awaiting this uh this native account abstraction experience on ethereum um and it puts the chains that have the native

experience a little bit further ahead in terms of the experimentation that that can be done uh because yeah I think we're seeing these at like uh kind of a fragmented approach on ethereum but there isn't quite anything uh that uh takes that and runs with it like uh the fully native unified experience that that's currently available on Stark net um cool okay I think I got one more question and then Andy may have some questions as well um going back to uh going back to this slide about poker I think think uh is here so this is how I got started uh in Bitcoin and in cryptocurrency so like

this private so I was playing poker on a site and it said on the site it was provably fair and I always thought that was like quite curious because they had like a bunch of like fancy math there and it was like provably Fair odds on Sports and and on poker and at the time I was this was long before ZK proof technology this was like 2016 and it said provably fair and I was like oh it's on a blockchain that makes it provably fair but I really did not understand how that worked in the back end so so here you you did mention that the like in a poker game like my cards

are stored on my device but then how does like when it's time to like when the last card comes up and it's time to show your cards how does the game know that my cards are Ace King and someone else's cards are king queen and therefore I win the hand how does the game know that yeah so uh this is where like uh two things come into the picture one is the client side ZK and let me explain that and second is recursion I'm sure like you have heard of this word as well before so imagine like v3r playing the game of poker uh right now it's my chance and I have some cards and there

are three cards open on on the face as well like open cards right so uh I will play my turn like I'll say Okay I want to raise or whatever uh I will create a ZK proof on my device that ZK proof will have information that okay whatever turn I have played it basically aligns with the rules of the game There are rules of the game that could be put into the server right uh into the application logic so I'll create a ZK proof I'll send it to you Robi and then Robbie you will play your turn you will use my proof and you will create another proof on top of that so again you will have one single proof which was built on top of my proof then you will send that proof to Andy Andy will play his turn

and we'll recreate a proof and similarly we will keep playing turns and every time we will have one single proof like it will be with the person whoever is having their turn right now then let's the round finishes at the end of the round uh this we will have one single proof this will go onto the blockchain it will verify that all the computation was done correctly because even if one uh one play was wrong then the proof will not be verified right that's the benefit of recursion so now the benefit of that is like neither I revealed my card neither you revealed your card neither Andy revealed his card till the end of the game and then like the game will finish and you will basically settle on the Chain okay sense I think so so the benefit of recursion is that

like we don't we don't show our cards until until it's time to like show your cards at the end of the game yeah okay yeah exactly and and for an example like when I say uh the verification if I played the right turn and when will be done on your device that when I send you the ZK proofs your device will verify yes this ZK proof is correct for an example let's say on the face there are uh three jacks right and I folded uh no I I I did not fold let's say I went all in and I needed to show my cards and there were like Two Jacks as well so now it can't be Two Jacks right so the the logic the ZK proof will verify on okay no this logic is

incorrect like this is what the card has to be got it yeah that makes sense and did you uh did you have any questions here um I just was curious as to uh as to uh why why you think that the aspect of ZK uh technology is going to be the end all Beall or the biggest the biggest uh aspect of gaming is it because of the Privacy is it this uh is it because of this you can know something without having to know it and what would you say is the is the biggest reason of all the positives of ZKA technology that you

believe that it's going to lead the charge for gaming yeah I think like uh there are going to be two major components which will play a bigger role uh actually not two actually there could be more like all all the all the factors I have uh shared in my slides so privacy will play higher degree into games which involve money uh and like which involves secret some kind of secret on the player end so like poker or any kind of like card games in in that case like privacy is going to be the bigger angle uh composability is going to be the bigger angle for any like World building kind of games uh for an example like

Minecraft Clash of Clans Age of Empires all these games are World building games in in these games like what you do is like you have these uh economy you have items you have buildings you have armies and all of that so it could be used across cross games as well like uh the kind of characters you have I might use it in my game as well or the kind of logic you have I might use it in my game as well so in these kind of games I think composability will play a big role uh computation kind of thing uh I think will be applied to both uh like whether it's it's games like poke like computation is something you will need in most games uh so that that will be by

default a significant benefit of validity rollups like again it doesn't go like one only one benefit right because the way you are making games trustless is by using the validity proofs and if you are using the validity proofs or if you are using the on games then you need to solve for the scalability so scalability will be solved by uh like offchain computation layer three kind of environments which is something like we just started seeing uh getting into the ecosystem now like pretty much every major layer to ecosystem is working on app chains or layer three kind of an ecosystem so there there is going to be a lot of tooling that will help with that uh other than that I think like uh some games have this economic nature as well

so again like in World building games the economic nature kind of makes a lot of sense uh like where you have gold Wood Food these kind of currencies so like utilization of cross currencies across different games like this economic nature will also be a game changer I think in in some of the games sweet yeah I think uh I think we're finally starting to see the Pieces come together uh which is which is really cool for uh some of these hyper like hyperscale applications that have the ability to reach Millions if not billions of users um and we realize it's not the technology that's making that happen it's it's the consumer facing entertainment or information flow or the

value that it provides us so this has been yeah yeah and and like I think like that's how like we will get more users using onchain applications like instead of DIY or financial applications like if you think about it like Finance is boring for most people like if you'll talk to 100 people within your friends group probably 10 of them will be aware about like how Finance work or deal with Finance like 90% of them will most likely play a game or use a social application so I think social applications gaming applications this is what will bring uh crypto or like web 3 to billions of users and uh some some of

the shoutouts like I think it's still in early stages in in the sense like you still need all these tool links like stocket is for an example just twoy old and that is just stocket and we still need layer 3es for like these kind of things to succeed so layer 3es are still not live anywhere as such there are app EP are I think very new it's not mature uh there are no tooling for like client side ZK kind of logic what I mentioned like all of these things need to be built and uh some of the things some some of the teams are doing great work so like one of the team is dojo uh who is basically building like a game tools uh or tool chain for onen games think of

it like creating Unity or end Engine things like that for so that it make it makes it very easy for game developers to create games yeah I think I I think we heard of them at Stark new CC this past year the thing that they gave us a talk or at least were there um yeah super interesting yeah thank you Rie for coming on um and sharing your slides and your presentation about ZK and how it's going to play an impact and I think we can all agree that yeah gaming is going to be a huge sector to on board a ton of people without even knowing that they're using ZK tech technology which is which is exciting so thank you yeah thanks Andy thanks

Robbie