[Day 2 - 08] Evaluate(Building.on(StarkNet)) with Guiltygyoza

BUIDL Vietnam 2022 · September 2022 · 29:48

Guiltygyoza, co-founder of Topology, shares a year of lessons from building on StarkNet, a ZK rollup that settles on Ethereum. They walk through game-like experiments that test what verifiable computation can do onchain: a Tic-Tac-Toe agent trained with reinforcement learning, neural network inference on handwritten digits, physics and three-body simulations, 3D models and MIDI music hosted onchain, puzzle-based minting, and a fighting game played by AI agents in smart contracts. It ends with ideas for an operating system for the world computer.

Speakers

Topics

From BUIDL Vietnam 2022, hosted by Kryptoplanet.

Transcript

and our next speaker we call them a wizard at topology whether it's black magic or not I don't know yet at the first on-chain reality ofs.net topology team is working hard to render the impossible possible with the future of digital world so now please join me to welcome the next speaker guilty Goya to the stage to speak about game 2.0 foreign [Music]

I am guilty gyoza or Gigi I'm co-founder of topology and I'm not going to talk about game 2.0 today I changed the topic a few days ago I'm going to talk about our experience and Lessons Learned From building on starknet and starknet is a ZK roll up that settles on layer 1 ethereum we're going to talk about the mission of our company our approach what we did for the last 12 months what we learned from what we did and what we think is going to happen next so control Kim and I started typology with a conviction a conviction is we think verifiable computation with ZK

snork and ZK Stark is going to change a lot of things it's going to be one of the driving forces that transform house Society functions and we want to help drive that Force towards a good direction and our hypothesis is that we don't know we don't know where the future holds for us we know that this is the beginning of something quite unfathomably large think of it as another super cycle and we're at the beginning of a new internet to be built and so with the mentality of thinking we don't know anything to paraphrase Brett Victor once we admit that we don't know we can do anything we are free and we can try and

experiment anything so our approach is we are making different kinds of game-like applications in order to test the limit of what our current infrastructure allows so we did for the past 12 months starting last October the first thing we did is we started with artificial intelligence because you know it's very interesting to have autonomous agents on blockchain which is an autonomous platform so what this is is this is a reinforcement learning agent or Q learning agent the most vanilla uh flavor of reinforcement learning trained off chain converted into Cairo smart contracts then put on Stark net and it's

able to play Tic-Tac-Toe with you and so as a user if you submit a transaction to a contract making a move on the board the AI will run the computation make a decision and make a counter move on the board and give the world back to you so we have um it's Timeless Asian on a blockchain playing a very very simple game with the user and then moving moving on from there I think it's just interesting to be able to run some kind of neural network on the blockchain and so this is what we did uh basically we trained a two layer DNN or deep deep neural network of chain in the uh Plano Jupiter notebook and then we have a script that converted the

pytorch model into a bunch of kind of smart contracts that collectively perform inference on the mnist data set and so what you're looking at here is a input Vector that basically represents the handwritten two feeds to Fed to the Kylie small contract which compute through the model and give you back the inference result which is the digit two that it predicts and um after AI I think we had a lot of fun doing things with physics simulation and so this is basically rigid rigid body with the numerical simulation running and covers my contract and so this this is very industry standard numerical

methods right so you have remembering high school or college level physics you have a set of differential equations that Define how these different physical objects interact with each other right so on the left you have rigid body constrained by Springs and on the right you have two bodies that are constrained by gravitational forces and so in a Car Smart contract we can write program that basically approximately the solution to those differential equations so then we can solve how these physical systems evolve and this is the PDF files but um really the demo was an animation that shows that these objects are moving um relatively to each other according to

the forces in the fields that constrain them so once we started doing two body you know why not extend it to uh three body and we're a huge fan of the three body problem which is the Sci-Fi novel written by Chinese sci-fi novelist so this is simulation of three sons and Tiny Planet the tiny planet is the blue pale blue dot on the right of the screen and you so basically the small contract would solve the differential equations as a function of time and so the off chain client can visualize this how this three body plus one which is a restricted 40 body problem evolves over

time and so you can look at the planet revolving around these three Suns which are all revolving around each other foreign and then we started to do more like a game-like application right so this is basically a 2d rigid body constraint and a axis line bounding box that's uh bounce against each other and there's gravity at work at the background and so what you're looking at is a python visualization of the physical state of the system that are completely computed on chain so the client side basically just visualize it all the compute happens in a correspond contract on Stark Stark net thank you

and then we switched gear a little bit so we started to think about what if we can touch different sensory modalities and do some applications with it from blockchain so this is a designer friend making um two axes in 3D representation and the file format is the standard gltf file format so what we did is we wrote a script that transformed the gltf file into cairosmart contracts that represent the file and we put it on starknet and so when you call the function a view function that does not change the state of the blockchain you're getting back some representation and you can parse it and basically recover the 3D model so

essentially we're trying to test the hypothesis that we can put three models directly on the blockchain and then we switched gear again so we've covered a visual side and then we move on to the audio side so what if we can host and manipulate music on a blockchain so this is the experiment that we transform a midi file into small contracts and put it on starknet and not just the static mini file but we have sort of we injected hooks into the representation so that when you call the function you can feed as input the tempo multiplier you want and then you will get back the midi file that plays the

music according to the tempo modified multiplier so you can play the music faster and slower there is a separate experiment that we did which uh didn't change the tempo but it changed the tone so you can shift the key down or up shift or downshift the key it will return the media file to you which you can just plug into any standard Midi player and listen to the music so what's happening on starknet is the program host the midi file and it also has hook that allows you to manipulate the midi file whether it's changing key or changing the tempo and then we move back to games because um game is a wonderful way of experimenting you know different sensory modalities you can do multiplayer you

can do you can experiment with networking you can spare with you can experiment with how the client talks to the blockchain and so on so this is a tiny demo that we did which is the the failure game so you as a player will submit a momentum to the white ball and uh the wobble will bounce around the scene interacting with other rigid bodies and your goal is to maximize your score right so the color circle will give you a different score when you collide with it the dark circle will reset your score back to zero when you collide with it and so the goal is to find an initial momentum that can maximize your score and then we involve this concept into something that we're calling soft to Mint the idea is that we can have a token that is minted not by the Merit of

you wanting to buy it with some Capital power but you solving a puzzle that's very fun and Chained and so you can mean a token that represents you know the solution to a puzzle and it's all on a blockchain so the first supplement where we collaborate with Matchbox style um was this project that it was solve the physics puzzle on the previous slide and when you find a solution the contract will mint will basically record your account as a solution to the puzzle and then that puzzle is solved basically you found a solution and your solution can never be found Again by anyone else so you can you kind of own that solution and then we did something else we

evolved soft to Mint into the Next Generation which sort of deviate away from physics puzzle but more like a traditional puzzle so this is a puzzle where you're supposed to find a closed path on the screen that passed through all the color circles and the color squares and you have to go straight through the color circle and you have to turn a corner of the colors squares there are additional constraints but basically the idea is to draw a path that satisfied these constraints and we have 50 different puzzles each puzzles can only be solved once by a different account so you can't solve more than one puzzle unless you change or you know create a separate account so idea is that we can have a system

that filters participants by their willingness to solve puzzles or you know their position of specific knowledge the purpose of ultimate 2.0 is we want to get play testers because at the same time we um we're building a game called Isaac Isaac as in first name of Isaac Newton Isaac is a three-body problem game so three body problem game is a game where everyone lives on the planet and the planet is situated in a solar system only that the system has three Suns and so it's a very hostile environment I can imagine the planet would get close to a sun and get super hot or get far away from the Sun and it's freezing and most importantly when the

planet crash into a sun everyone dies so this game is a massive Co-op game where players work together to Pilot their planet away from disaster and the way they would pilot their planet is to play the resource management game by building factories and Pipelines so that they can Harvest materials and eventually they can build engines and these engines are huge nuclear engines imagine mounted on the ground and when you launch the engine you are kicking your planet in the reverse Direction and so that's the way players are piloting their planet around their stunts and the softimin 2.0 is basically a puzzle where we can get play testers that are willing to read our code they have some basic

Proficiency in blockchain programming and we hope we were hoping that these play testers will give us more valuable feedback than just a general Place public play testing and so finally this is the latest experiment so we were experimenting with with sort of circling back to where we where this all begin putting Artificial Intelligence on chain so this is a fighting game um what's special about this game is this game is not played by you pounding on keyboards or remember the move set and doing key combos instead this game is played by two AI agents against each other AI agents exist on the chain in the form of small contracts that

Define and control the behavior of these characters if you know the there's a famous game on ethereum called the Xerox Monaco roughly a couple months ago by Paradigm basically the same idea only that the K mechanics here is a fighting game instead of a racing game and so what you're looking on the uh up on the top of the slide is a female character whose behavior is controlled by a smart contract and on the bottom you have two characters interacting with each other and you have you're looking at hitboxes and hurt boxes visualized for you so what's happening on a blockchain is every frame the small contract would compute each artificial intelligence what action they want to make according

to the stimulus that they get and then the small contract performs some kind of physics simulation that calculates the consequence of these agents making their actions and then the small content would change the state of these characters where they're getting hit or whether they are you know hitting uh hitting the opponent it's everything on chain except for the visuals the visual is uh rendered off chain in the client so these are all the experiments that we did for the past 12 months and the followings are what we learned from the experiments so number one we recognize that as on chain maximalist we are oftentimes playing with this barrier

where we're calling chain climb barrier um the barrier between the blockchain and the client or kind of between web3 and web 2 in a sense and the difficulty here is it is really difficult to synchronize State across the chain climb barrier it may be simple if you have some accounts only some tokens but when you talk about fully Unchained games with full-blown physical States and characters having their own States and you want the client to visualize everything you have to transmit all those information from the blockchain to the client through that barrier and um then the bottleneck becomes well do you have enough bandwidth through inferior or you think maybe inferior is not really decentralized are there other

ways maybe you want to run your phone out but you can't ask your players to run photo it has too much effort so how do we do the second thing we recognize is again with the chain climb barrier our approach is we let the contract emit events and the events carry state divs to the to the game and so collectively when you collect all the events you can forward the entire you can recover the state of the entire game and this is kind of the model of functional programming right where you are you have separation between State and logic events basically carry all the state divs so that on the logic side if you forward the events you can fast forward the state but we argue that we don't have a good

enough structure to do this the third lesson that we learned is that we can't run arbitrarily complex programs right so um on ethereum there's like block gas limit you can't do something more complex than what a block yes limit allows you to do on starknet there's something called Step count and step count basically represents the complexity of your of computation if you if you exceed that step count your transaction simply doesn't go through and um it's quite easy for us to go beyond the step count so going back to the physics simulation if we add one more rigid body to the scene we are complicating the simulation because

there's so much more pairwise interactions and collisions that need to be handled and so by merely adding more physical objects we can play with the step count and the limitation and there's one way one very clumsy way to solve this all right so imagine you want to run a super complex compute that according to the step count per transaction takes 10 transactions to complete um one way to do this is you can basically stay within the step count limit for each transaction and you cache your state in the next transaction you read out your state from the cache and resume your simulation and just do it at the boundary of every transaction and you can also talk about well we can plug in keeper Network or gelato or yagi

which is the keeper buttons darknet for automating transaction but I think it's quite clear that this is a very clumsy way these are abstractions that programmers shouldn't be dealing with as in programmers should be able to pay more to do more compute instead of having to do the caching and re-caching themselves fourth lesson we we learned is we are using Yaki heavily to automate transactions for our game but obviously yeah so oh so what Yaki is yaki is like a registry that you can uh put up tasks you can say my smart contract wants to be invoked whenever there's a one bit that goes to one and if one if that signal goes to zero then I don't want you to invoke my function

so by doing this small contracts can be automated but we argue that transaction automation is something that should be part of the OS protocol it shouldn't be an application built on top of the OS next lesson is we feel that we don't have it we don't have enough standards when it comes to composability or you know functional uh compositionality it's all about having type systems and type matching so you can change functions together you can build bigger systems with a smaller substance subsystems in a very modular way but in order to do that things need to be able to glue together and the reason and the reason for things

to be able to go together is because they adhere to certain shapes that's basically type systems in programming language and um on in the D5 space we have various ways to Define uh token standards right contract interfaces so that when contracts adhere to those contract standards we can compose function and we know that they're all we're basically chaining an erc20 operation to another erc20 operation and so on and we can do this in an atomic transaction but we would argue that these standards are not verifiable in a sense that as small country developers you would have to to security audits to make sure that your contracts adhere to the Token

standard it's not it's not an automatic thing you have to manually make sure that your contract your the boundary of your program adheres to certain type in certain interface what if we can enforce that matching in an autonomous way autonomously verifiable way the next lesson is quite obvious that we don't reuse Library we um we import libraries and then we redeploy everything on blockchain and so there's obviously an issue of stapleo where every single protocol is redeploying all the common libraries by open zap plane for example and um it has a lot of consequence so stay

bloat is something that's external to blockchain uh protocol developers and application developers right and once it's external people don't care maybe Vitality will write a blog post someday that will help solve a staple but as a protocol developer I do what I want um another opportunity that's lost by not reusing library on chain is we're not using Version Control enough and by not reusing Library we can also we are also losing the opportunity to distribute value to these libraries right so we have these Version Control um system called git and we use git basically it's a version our software developed in a web 2 space and then we Deploy on chain but on a blockchain

there's no concept of Version Control and because I'm not doing that we can build a system that distribute value to library builders the library Builders activities in their history and their log and their reviews and their efforts are all off the blockchain it's not on the blockchain and it's really hard to build a system that reward them in a credible neutral way and our last lesson is basically we feel like the workflow as a blockchain programmer is super fragmented right you would open up web apps to help you explore the blockchain the blockchain Explorer um you would open various web apps that can help you monitor the blockchain in

different ways you would have Ides like Visual Studio code and then you would have other applications that help you do debugging um it was switched terminal and you start doing version controls and committing your your divs and it's just all over the place but then when you when you think about ethereum as the word computer it's something that's on the cloud it's not tangible when you think of ethereum there's no other than ethereum icon there's no visual representation of what ethereum is but imagine when we talk about Mac OS for example we talk about Apple computer we very quickly have the idea of what Apple computer is right it has a certain aesthetic guideline it has a certain standards of how their desktop and apps

um are structured and so on right now we don't have it and so what we think needs to happen next is that we think it's important to do a new layer of abstraction on a blockchain and this new layer of abstraction and first of all the reason why it's important to build abstraction is because we can as human programmers can do things at a higher level we can express more and we can forget about the low level details that should be handled by the machines and so this new layer of abstraction should do the following things number one we can try to distribute software from the blockchain so instead of Distributing software and do Version Control in the web 2 space we can distribute software directly from the

blockchain and for those of you who have followed domed who is an unchain Maximus doing nft experiments on ethereum Dom released an experiment called rose that basically compressed JavaScript libraries and put it on a in a solidly small contract which can then serve the JavaScript library to the client and then render the full 3d model so the pattern here is Dom is basically Distributing JavaScript logic from ethereum so we can extrapolate from that we can basically distribute any software from the blockchain and then when we can do that we can distribute software in a very decentralized way but then moving on to the second part

um second Point file system and Version Control we think that it will be super fun to have a file system on chain where when you think about the work computer you think about file system you can browse programs that sit on a blockchain and you can do version control of it imagine open a file browser only that every single file is basically sitting on the blockchain and then you can have version numbers and timestamp only the time is block time block number and block Heights the third point is we can do compilers on the blockchain the reason why compilers on the blockchain is interesting is because for programmers compilers are God they are they're the judge they basically dictate what is

legal in your code and what is not legal in your code and um one thing about building on blockchain is we want to move the law to the blockchain right we want to move the conditions that regulate how our tokens are transferred we want to move all the conditions that dictate how the game should be played on a blockchain and so on the programming side why don't we move the compiler to the blockchain so that we can verify that certain programs can compile and other program programs cannot compile so once we can do that we can then enforce composability because we can say this compiler will pass only if your program's output adheres to certain type so that you can have verifiable type and

once you can have verifiable type you can have verifiable objects that are composing with each other in a very autonomous way you don't even have to do security auditing as long as you're passing the test in the compiler on the blockchain it's guarantee that your program can compose the next point is it will be super cool to have a weight in blockchain programming so basically if we can do a synchronous programming it will feel like super power to programmers I think the connects talk yesterday talked about this concept called x-call basically I can have one line in my small contract that says I'm going to await some data to come back from a separate chain and then I would do the following things but you can generalize this to

uh base uh Universal asynchronous programming right you can basically say um a weight is a basic syntax feature of the future blockchain programming model so that instead of having to explicit machines and waiting for things to happen and then react to them we can basically have the super superpower of writing a line that says away something happened and I'll do the following things so that naturally we can we can think about doing indefinite program indefinite program is the idea that my small contract program is not a passive machine anymore it's alive there's always something going on it's waiting for something to come back upon which it

will react with a callback function or additional logic it's a program that runs indefinitely but then when you think about programs that run indefinitely it's consuming resource from the blockchain right and so we have to introduce the concept of process and processes this object in the operating system that regulates um task running and maintained by the system so once we have processed in um on our computer we can say my program inhabits this process and it's consuming such and such resource and I'm paying the gas for my process to be continued by the network and if my process goes idle then there is a policy where the

system will shut down or kill my process which is a basic um OS level operation the next point is once we can do all these we can do an IDE or integrated development environment so imagine you open up the future Visual Studio code and you look at the left panel that shows you the different programs only that every single one of these programs is actually on a blockchain it's mirrored from the blockchain and so basically your IDE is IDE looking at the blockchain directly it's not an ID looking at your local laptop file system anymore and once we can have that it feels like superpower because you can then reuse programs already on the blockchain

and once you can reuse these programs we can have value distribution system that says the libraries that are getting most reused will get value distribution as reward so that you can then talk about open source software development only that the programmers are not doing things for free they do things knowing that if my programs are getting used massively I will get rewarded by the system and finally I think it's a natural conclusion that all these things deserve a graphical user interface right a graphical user interface that visualize the file system for you visualizes that these files are Version Control it has an IDE running in the in the GUI interface allows you to program directly

on the world computer so basically the idea is that Bitcoin fails to us like the hard drive and ethereum wants to be the world computer and we think it's important to do an operating system for the world computer so then we can visualize and program directly on the work computer it becomes something tangible and visual and either program on that's the idea and I think we're still fleshing out a lot of the details involved in the system and we hope to make the plan public soon and so that we can maximize programmer contribution uh if you're interested let's build this together thank you