ZK9: Web3 game development utilizing zkWASM virtual machine - Sinka Gao (Delphinus Lab)
17 Apr 2023 · 44:53
Sinka Gao of Delphinus Lab, speaking at Zero Knowledge Summit 9 in Lisbon, presents zkWASM, a zero-knowledge virtual machine built on Halo2 that runs unmodified WebAssembly bytecode. The talk walks through building a browser-based game with a standard web2 toolchain and generating proofs with the zkWASM emulator so players can redeem on-chain rewards for verified in-game achievements.
Speakers
Topics
Transcript
foreign [Music] assembly and what is a Serial knowledge virtual machine that supports webassembly and how these two can be integrated together to bring us new paradigms of coding your website applications and in the second scenario I would like to introduce our architectural purely designed for web gaming development and in the third section I'm going to demonstrate how to develop a client assigned a full on chain web game using
our webassembly Virtual Machine by developing a game from scratch and in the fourth section I'm going to introduce a little bit more about how to extend this architecture to support client server server architecture and at the end at fifth section I'm going to introduce about the approving service two layers of filming service and building Primitives and storage and the Rhythm generation Etc and in the end I'm going to show you the proving service and discuss a little bit about the Privacy when you're utilizing a probing server okay let's start so uh section one the brief of
webassembly and website secret emulator so I'm going to show a diagram like this this is a diagram that I sealed from a pitch from the web assembly Edge so when I introduce webassembly these guys always discuss webassembly sorry um because I need to Auto tab a little bit so I'm not sure so let's see so I okay look it's that clear now okay I steal this
uh graph from the webassembly edge so they put an emphasis on how good the web assembly is by showing that there are lots of applications the Frameworks can run on the webassembly virtual machine and the webassembly virtual machine now becomes a a standard for the browser applications because now you can call webassembly application apis from Pure JavaScript typescript and you can run application in a environment like Linux Max and browsers and even SEO for rtos and it can become the back end for the majority of the languages like uh
and just some acceleration about this JavaScript and python because as far as I know at this stage there's no translation from python or JavaScript to webassembly but the web assembly can be generated from assembly script which is very similar to JavaScript it's called another version of typescript so that means webassembly is kind of very popular to support various generic languages so this is also this act the the host apis building in the web assembly can be used to integrate with lots of language extensions so in calculation
um I think um there was some edge trying to sell the web assembly by telling that the web assembly by code is kind of awesome right and so now because it's awesome and uh but it's not used by web3 right so so we try to actually leverage the awesome webassembly byte code by providing a Serial knowledge virtual machine that supports a webassembly by code and uh so last year I guess a talk at CK proof talking about the architecture and arithmetic of this virtual machine so I'm going to skim this a little bit and just show you that this is this is a circuit architecture right with this architecture you can
encode in web assembly semantics in Halo 2 right so which is our arithmetic back-end so when we implement this webassembly virtual machine and support all the instruction formats except except floatcoin then we are happy to say that we have the ability to leverage the web assembly by code by running webassembly applications in our awesome CK virtual machine right so that gives us a way to connect awesome outside world of web3 a web 2 to our website okay people can check out our source code and our full design of the arithmetic circuit here
so now we combine this together I will combine this so we have this room we have a our webassembly virtual machine we put the application in it and the application becomes an automatic roll up for this room and it runs the native webassembly by code and by running the website by code in this our serial knowledge webassembly virtual machine the generous proof and prove somehow delegate back into the Instagram so we can do some settlement here right so that's the architecture and today I'm not going to introduce all the sdks that we have for the web assembly but I'm going to
introduce our game SD card which color Runner so that using this SDK you you can call the small game and run that in the browser and talk with Instagram and also get information from this room from a security layer that provided by some of my friends will introduce this friends in the later section okay so now this is a brief of about what is webassembly ecosystem and what we can do with the webassembly CQ virtual machine okay now let's dive into the game before I start coding a game I give you a brief about a why game is kind of a very key scenario so that we are going to Target the first
of all is that I'm going to introduce how the game is currently coded in Webster world so uh some some guy tells this kind of architecture to be web 2.5 because the game engine is running outside the the chain right at a certain stage uh some kind of party city plans triggers a job so it's not a transaction this is not a transaction so each room or a blockchain is a transaction base what is a job based because it can interact with different users in this game so in this job at some stage it will actually communicate with the on-chained data so maybe okay to some transfer maintain entities and sometimes okay to some penalty
calculation yeah and so the problem of this uh I mean the advantage of this architecture is that it's very efficient but it won't change upgrade the game it's it's pretty easy you change the key path right at certain stages change the untrained data but it's not very secure just imagine that you have an empty that last night it was maybe one million but after that someone changed the logic of the game then your Mt was nothing right so it's not very secure both for the game and for the users who play that um yeah so this is a call Web 2.5 gaming engines okay
and now uh so where is this there's no title here sorry I think there's a elimination coming very soon but a little bit delay so here we're talking about that to secure so we still have the same thing for point one but to secure the outside logic of the gameplay um outside of the blockchain so people can encoding some of the logic into CK circuits right so with the ck6 enhanced architecture we can say the data modification is triggered by a successful verification of a proof so in the contract it's very fast
approved and share some kind of the convention with inputs and then do the settlement right so this architecture is a big Improvement of the previous one but the problem is that it's only it's very hard to reason about the weather semantics of the circuit is exactly same of the semantics of the game right you have a game you have a circuit and you want to convince people okay if the circus constraint is satisfied then the game is somehow running in the same manner but it's not not very easy to prove right you have to do lots of auditing and you have to check the circuits to check the constraints and every time in particular
every time you upgrade the game you still have to upgrade the circuits right so that is uh really a popular architecture I think maybe we need to go right but now once we have the serial knowledge virtual machine um things change because we can imagine that this code this gaming block is not building in traditional language but building some kind of byte code that can run on a virtual machine or you can replace this our virtual muscle version with any virtual machine like cardio VM risk zero um any
virtual machine so so the benefits that usually if you have a virtual machine do not have to reason about that the semantics of this is actually the semantics of the initial game engine right um but the problem is that so if we have this kind of architecture the upgrading is not that easy because every time you upgrade in the game it generates a new hash for the image right it's not very easy to upgrade and there's other problems when utilizing this architecture is because when you so for example if you imagine that you have a gaming that developed on a browser right how could you interact with this game machine so if you have babies so for example carry a virtual machine then you have to actually install the carrier virtual machine uh in the browser right
we have any other other kind of any kind of a virtual machine have the installed virtual machine there so that you can make sure that every transaction here actually follows the byte code so the problem is that the integration effort will be a little bit higher than before because everything written here is the targeted by the colors that you are going to interpret in a virtual machine so to solve these problems we because we are currently focusing on the application browser applications so we replace this virtual machine bit in the architecture by a webassembly virtual machine that means we load of webassembly uh natively in the browser right we interact with them and after that we
using the virtual machine emulated by the code and then we upload our proof uh to the blockchain and then do the to the settlement now it Still Remains us two problems the first problem is that it's not very easy to upgrade it's not very easy to upgrade and the second problem is that because the virtual machine takes a lot of time to actually do generator proof so that means we cannot support a very high TPS games but I'm not going to solve the problem today but so in the rest of the talk I'm going to show you how to leverage this architecture and build a builder game okay let's do the game uh so I need to put the Mac down because
I need typing okay so I'd like to thanks for uh guys who are from the secret cross team to develop this game for me um and the game is pretty straightforward it's a a g of 2048 game so that means you have a game you move it blocks you combine blocks that generate a larger block and at the end you have some kind of uh Rewards or some kind of Mark you can upload the proof of the whole transaction of the game to the blockchain and then get it but let's look source code architecture
okay so let's start with this um this actually uh game quality C right so nothing special here and once you make that it generates uh webassembly the Genesis oh okay well that's bigger sorry um that big enough one more one more okay good okay
so that means uh you're right to program hello um so what did you do with a webassembly you can run our webassembly virtual machine locally via CLI but you can also um using a H I cannot using a proving service uh maybe it's a webassembly virtual machine improving server so you'll upload the web assembly straight through this webassembly virtual machine right yeah upload that after you uploaded that you can maybe trigger some tasks to do the proof but now I'm going to do that step by step so
I now I have upgraded that online license that means we have established are an application file you can establish the application locally you can also establish application on our um online service but it's not very important so once you can you have done this you see that it is very natural to actually load the web assembly into our gaming execution environment here you pause the web of family here sorry if you want to see the okay
so I didn't get what's the question sorry I sorry the name of the Rebel that's open source yes open source everything he has open source so yeah oh you want the name of the rifle okay so it has um okay okay so game is provided by secret cross team um [Music] make a new game
so now you have this you know the game and then you provide some kind of environment and you cannot make a circle for that because the ability table of memory kind of memories um the reply it's not kind of a standard function into the JavaScript environment we're providing the provided and now you have a generator webassembly you have upload that into the webassembly proving service we're loading them and now it's time to play yeah so now tune in again so so in this game it's just a 20048 game so
the idea is that every time you press your button top down left right it gets input into the web assembly right get input into the web assembly and so this becomes the private input foreign you play for a while so usually I play
this game for about even some steps I found and it doesn't work then I give up this game let's start all over again until I find a way until I find a way that uh I get some good results by very good move and by selling some good stuff and to get some currency and once you're happy with the gameplay once you have it with gameplay you can generator proof I mean here are the um proof that I have enough light the numbers General one um submit a proof you see that okay uh we have eight steps and there will be somebody putting
everything in the in a sequence all right so the biggest difference to the web assembly virtual machine that's really exclusion and this part of the institution will not only gives you the results but also gives you improved right so I'm going to submit that okay confirm uh sorry uh usually do not have to start um but because I'm doing a good demo so I'm so so you get a pending task right so and this is now doing our non-gpu machine so it will be a little bit slow um so now so just imagine that we have submitted you can check over here with this instance you have this kind of
lots of scripts and some auxiliary data so I'm going to just introduce a little bit about the proof that we generated from the foreign I'm proving that actually with all my transaction inputs I get the currency here sorry let me show you so I get the currency here but you do have coding your program in your world right coded like
camera into the frequency and then you generate what you mean um look at the thing called um the idea that you you do not have to um [Applause] if you look at a c code you you have you see that the entry of this function right is by completely right so there's a command so every time
the impact on this again then you generate a few months of inputs right before we have some kind of simulation functions implemented C and loaded in JavaScript and in the end you're just encoding all the sequence and put that into DCP right what you will get after playing like this was the average support to like some standard Library functions like in memory yeah yeah but uh yeah maybe some open source guy will
contribute to the float point I I would expect but currently I'm trying to just push the boundary okay so now uh your general proof so last time or general proof oh it fails uh for I don't know what's the reason but maybe it's not stable the test is unstable someone may be also using the using the testing board but now once you actually have the proof transcript and in the instance I'm going to introduce a little bit about the instance and proof so the proof is constant because content we have this auxiliary data with a lot of cash order in wealth of
security from that I'm again on the contract and once you do the verified on channel it ask you to actually play the guess so the guest field is still having but eventually you have a patch you know aggregation service you can reduce the price because it's constant proof size so I think in the future it wouldn't want to be a problem but also currently in a test net it's also not a problem okay I do the one with my with my test token
so okay so now let's recap um oh sorry okay let's recap what we have already done in this section so we introduce how and we can we catch the steps we have introduced how to load the Watson image we have introduced how to load the awesome image model and the gameplay the proof and now let's back to the settlement because with the generator proof [Applause]
a very simple example about how you can actually design your convention or payback you can design a contract there's a record here so so in the end you I will share all the diffractions and you need to actually create so basically you run a contract attention and then you verify because the contractor in our in our service right so basically you can call a contract in um in our service so for for those who actually get a very good deploy let's see whether so for example um if you have a look at this image um you'll find that okay this image is
deployed at this address so so that means um when you design the settlement contract call a verified function that is related to your application you give them all instruments if that succeeds you can design your convention about okay what creeps or what part of the instance tells how much token you have to transferred how much energy you have to read or how much penalty you would like to charge so it's basically um you can Define it and then obviously because you want to do something again you always would
like to kill mistake of your monthly trade in a contract your control right you run properly okay so now uh we need to dive into a little bit about the hard part of the game plan because uh improve a previous section we're talking about small games but instead allowing the problem but in the real world the games that don't only run in the
cloud also drives in a server so how could we make a uniform architecture so that all not only support the client but also actually support the server so we need to actually provide infrastructure that combines the client and the server and because we're dealing with webassembly we can do coding the RPC in web assembly remote form but the remote costs have been now encoded in the host function in the web assembly there's a function category called host functions the colorful function is equal to core remote functions that is provided by the host so now we can split
architecture of the webassembly virtual machine into true path the first part is the just a circuit and the second part okay so within this architecture all applications can design their own circuits we have sdkf whole circles they can use but they can develop their own whole circuits and every time a client decide web assembly caught in RPC you can think that as calling a host circuit that gives you the witness in the front end and you can generate the proof for the guest webassembly virtual machine okay it's a little bit tricky here
because once you generate proof for this web assembly gas virtual machine you actually do not prove that the whole core is found called somehow valid right you have the witness for the whole circuit but it did not actually prove the the whole circuit is cracked that means the backhand side needs proof the sequence of the host core is correct using a host circuit okay and this looks like this this constitution will have a soft API right the whole API is actually taking a
and gives you B so include through some encoding this is right like this so that means every time you excluding this you will Define the cement of this by a local argument here right and then you touch this the other costs now in the whole figure you give them the same column right it starts with this circuit also prove that a dashboard and then in this soft circuit will prove that the source of code to one actually uh generous B is a is the value okay so now I have two proofs with they have a guest Group Health hospital
and then you just calling our fashion service um and in the back which is true through two things the first thing is that this is a very true and these are very true and the second thing through with that yeah these two proof shares the same host for a few times by checking the house and that means combined it to look at a server cloud architecture oh this bundle proof I think I've already explained this this will try to concentrate okay
so now let's talk about the common Primitives in the whole circuit so basically we only provide a minimum costability guys like with the signatures foreign active ability to get information back from the Israel so that means in our game we've been different from the from by these applications okay and all the common properties are
implemented using much more automatically our Primitives stories within the past and the relevances to be free and yeah so it's nothing true nothing special I think all the ckvm implementation have this and okay let's see a little bit more about the attractions because this is a whole circle that we have lesson from the Israel making program with web assembly virtual machine by calling this concept like good opponent to try to this is School
all the Logics standard combination of an attestation circuit and gaster with this you can develop some more sophisticated games and not only talk to the ethernet but also receive information from Israel and uh this is kind of attestation I just wanted interesting one thing so this is not an application of the global data structure of research actually happens so this is it's a special circuit because most of the circle circles is actually carried
on on the server right but this kind of shows streaming himself because that provided by some server by monitoring the Eastern events okay um oh I'm going to talk a little bit quick so the last section is the privacy and approving service so I I have actually already showed you the I mean the proving service um so it's it's kind of very easy to manipulate so you will write any programs and you build it here oh sorry am I out of the internet connection
right that button didn't work it's an online service if there's some internet problem from randomly downloading the bandwidth but yeah so once you get a binary you create a new application you choose application upload that and generate a new application but within this framework there's a majority problems that we face is because the proof is delegated to the proving Services all the weaknesses are leaking right so it will play some kind of card game right so that means media service the oil card or maybe some other ones that are hack into the server
proving server can see all your inputs okay so so I think this actually uh a big problem of actually delegates proving to the approval node um so huh this is the cloud improving service so let's figure out which bit is very risky and which bit is not so for the applications then we can get a fetched by the gas system improval right the customer you can say you can imagine from what approval if the fluid store is called
feed by the game supplier right because you can still trust the centralized gaming provider but when you actually delegate the service proving service to some kind of a post service all right that means this Parliament service will approved by uh decentralized approvals and delivery so so this is the risky this is industry and what we prefer is that we can cook everything in the client side in our architecture at the moment we
probably um Benchmark this and push the performance a little bit harder but today I'm going to introduce a way to actually into two ways actually two ways to solve the problems of getting the flow one is actually here I'm not sure whether I get all the ideas from this paper but I think we have um yet [Music] [Music]
give you something about actually distributed and the complexity actually increased by effect of two according to this paper so but we actually have to implement this yeah what do we Implement so we Implement a way to preserving the Privacy by preventing approval in the field of web assembly washing machine that means if you want to find something you can create a circuit verify the statement you need your private circuit and generative proof editing these web assembly virtual machine we will play a function for the
top 2016 to verify and you can upload the witness of this gratification truth so that the guest circles proving the statement without knowing the actual weakness and this is done I think you can find in that improving communication here and the idea is pretty simple for example you won't prove that you know two numbers that multiply together equal to a very large number but you do not want to actually leak the information that you know that you know the two numbers right to implement that you
uh okay so let me show you the code to implement that you somehow create our circuit it's it's a circumstick and a compiled circuit gets set up and then after that you use the setup to generate uh verify lip to do the verification in in C code or any code that be compiled that can be compiled into a webassembly right so that means we have used the CPA webassembly version information that
multiply together equal to a target number and this technique can be used on anything that you want to hide and we are going to supplement actually two verifiers one is the row 16 other is the plug so just remaining another problem is that we will look at this code we find that you need to calculate a pair of four right so even in our Optimum life you do a carrying of one improving of caring well you can environment with one GPU if you want before there
are a lot of overhead but we will somehow optimize this but currently the fact is that even you choose if you want to choose this approach to hide the information and provide privacy in your serological web assembly then you are really the cost of 20 more seconds but I think for small games with very low GPS if you hang up in your gaming or gambling or some kind of game 20 is 5 25 but I'm not sure but currently that's what we have okay I think
yeah that's all about it and I would like also to give the partners that provides me all the code for demo and for everyone we haven't have any questions yeah right decades
but in the random place at this game at the beginning of the day you pick something from your last Point here we will sign up [Music] foreign [Music] thank you
oh so in the in the second part so uh initially what you're what you're doing is in the guest mode you're putting the inputs for each move right and you're generating the pull through all of those and your solution to hide the inputs is to generate the proof or the proof generator for all the previous games all right and and then what's the input so the input for that second growth is the proof of the previous proof itself except for the product s yeah basically experiences and how long does it take for the single group
um the batching kind of have been long at the moment um [Music] right sorry [Music]
so we want to know the student side for both of you and you know I'm asking like uber what did you how big you want three years foreign there is a
I'm not sure this is a very uh you can see the game here but not very up to date I'm going to upload everything to the oh sorry uh I'm going to upload everything uh once I finish the talk but you can you can find the sketch provided by CK cross team um everything you can download from South Dakota but but you yeah oh yeah you can search theology webassembly virtual machine and open open this web yeah and I found that too and I copied that
oh sorry I didn't get Okay so yeah I think that's for today thank you very much [Applause]