Cartesi 🛠 Build more powerful DApps using familiar stacks and libraries - Gabriel Barros
ETHGlobal·Mon, Oct 9, 2023, 12:00 AM
Join Gabriel Barros of Cartesi for a workshop titled "Build more powerful DApps using familiar stacks and libraries" Thank you for joining us for ETHSanFrancisco—our first west-coast hackathon in nearly four years. This was officially our biggest event ever 🎉 👥 1700 attendees 🗺 from 46 countries 🌱 38% new to web3 📮 284 projects And: ETHGlobal just turned five! 5️⃣🎂 Thanks to every single one of you for making this community great 💙 --------------------------- Follow us: https://twitter.com/ETHGlobal Check us out: https://ethglobal.com Email us at: hello@ethglobal.com #ethereum #web3 #blockchain #eth
Transcript
foreign [Applause] [Music] so for today I'm gonna be presenting to you a little bit about optimistic relax and also how critazzi uses it uh for our technology in what it can offer to whoever builds in it and um first uh we're gonna start with a quick overview of Cortez just very briefly and then I'm gonna compare a little bit uh numbers I view the differences between web two three and how it looks when you build on cartesi and then I'm gonna explain a little bit about uh Roll-Ups finally I'm gonna present to you a very simple a small simple code of our cortezid app written in Python so here is a tab written in Python that works right now inside the advertising machine I don't expect you to understand it right now but it's just to show that it's a simple playing Python and you can have libraries and you can have interactions within the machine you can have access to other apis that you develop so it's really a server um used as a dab so cartesi is a foundation that has been working on this since 2018 we've been a while building stuff uh so it's not just some new company coming up when Road Labs showed up um and uh the team has been building this machine for a long while and then the relapse uh technique appeared and it just feel like a glove so we adapted the machine to to be a real love solution and scale ethereum so the main idea behind courtesy but I guess to some extent uh our relapse is that ethereum is awesome uh there is a lot of interesting stuff about it namely like uh it is secure it's a censorship resistant uh it strives to be decentralized and that's really good but that comes out with a lot of consequences and costs uh it is low it gets to be very expensive and that means uh we are always building a process of gentrification of the network so we are evicting depths they are now profitable even though they may be important for the communities and for the newcomer developers cumbersome because you need to understand about machine architecture you need to learn how the evm works and then uh a new language like solidity Viper and even low level stuff if you actually need to go that far so it limits you in several ways even though it brings another a lot of new interesting features so the main idea is like why what if we could have complex computation inside a blockchain and maintain security guarantees so the curtasis solution is uh transparent VM so instead of being another evm based Network a sidechain or even a lot relapse will have a risk 5 emulator risk 5 is an instruction set for a generous purpose processor just like the ones on your hand for your computer or your phone so you can think of it like a Docker machine of sorts or a virtualbox and uh we made it deterministic so we got something verse 5 is open source open harder to be more specific so uh we got it from the community and we made it deterministic and we applied it to blockchain so um here's things that you get so like any company and person can build on top of risk five it's auditable it's more secure because of that because a lot of people has have been working in this project it's a platform processor like I said so you can run an operational system inside it inside it so that's why we were able to Port Linux to the blockchain uh we made a deterministic so that means you can dispute any computation that happens on it and of course because it is a full machine it's very uh able to do massive computation and you can expand on it like you would do in any server or server application uh the main difference between most optimistic relapse and what we do at Cortez is like we have a local consensus so if you think about ethereum the more computers you add to the network you're adding on security decentralization but you're not adding processing power you're not adding throughput however with local consensus or depth specific relapse what you have is adapts that don't fight for the resources they don't fight amongst themselves they have their own sets of validators or what that means is now as the more depths you have out there you're actually increasing the overall capacity of ethereum to process things and that is all really good and possible because of the dispute protocol so whenever you have a problem whenever there isn't a disagreement between validators it is not a majority consensus it's really uh it really goes back to ethereum and uses it as a judge so the same emulator I just talked to you about the one risk five that you can run on a machine for catasi node is also implemented in solidity for the evm so whatever process you can do I've chain you can do on chain as well but with this verification game dispute you actually go down to the very instructional cycle that you disagree with the other node and you only need to prove one instruction cycle on the ethereum machine and that is possible because the machine is unmertilized so you know exactly why the instruction cycle needs to access like the memory States and you just need to upload this section of the machine in other worker proofs for it that means that even if there is collusion among validator nodes of a specific tap as long as you have one known as validator you can go back to ethereum and have the correct settlement so how does optimistic prolapse actually work any Roll-Ups in general but using this specifically so you start with the ethereum blockchain and whatever you do you're always making State transitionings uh inside the domain chain the Roll-Ups it changes a little bit so you go there to a certain block and you basically State the initial state of your computation outside you say hey I'm starting a new machine here and this is the state in people who join your roll up basically they are agreeing with you that the initial stage is correct then you state outside for a amount of time that you specify mostly nowadays we've been using seven days because of the security guarantees of it so for seven days you go on doing things off chain uh when the time is up you go back to the main chain you say hey after all that's happened this is the new stage of the machine and people have the chance to verify whether or not you're telling the truth if they disagree they can go back and do the dispute and uh fight you on exactly where you might have been wrong however if they agree after seven days everything is settled all this computation does not need to happen again inside of you and so that's why optimistic relapse they expand the main chain they are tied to in computational resources so the overview here's just a baseline so you always have some kind of a UI mostly nowadays browser then you have the software for the browser that you want the UI to to work with then you're going to have a connection it can be a socket connection it can be https for instance with a set of servers they are centralized and they connect to a set of databases that are centralized as well that's how web2 Works mostly we are very familiar with that where three especially with ethereum you change the landscape because now your business logic doesn't leave anywhere physically it's in the blockchain itself supposedly everybody is running their own notes so they can just communicate but there are no local nodes uh Honestly though we know uh we've been using inferior too much we've been using quick nobody and why not it is what it is however it's much more secure because whenever there is any issues anybody can just spin up their own full node or even a light node and make sure that the information they're receiving is correct uh with courtesy is very similar here just did a very clean version of it and we're gonna break it down but these two are connecting to notes just like ethereum nodes so supposedly people should be running their own uh validator node a validator slash reader node of their adapt they are connecting to and inside a curtising machine I made a shirt to have this image over here because uh we are used to the evm but how would a Docker like machine work right so there is no access to the internet I need to stress this point a lot so because it's a Linux server it doesn't mean it needs to have internet connection it communicates uh through the blockchain and that communication happens using Linux drives and that's cumbersome and difficult to use so instead of teaching you how to use the operational system to that level we've created this HTTP dispatcher it's an API that's running inside a machine that wraps up all this uh complexity and just changes it into several four endpoints they are really simple to use so by just doing Ras communication with these four endpoints you can receive information and output information back to the blockchain so now it's the blown up version of it so first you still see the Json RPC over there and that's because we have the data availability problem so blockchain is both data and computational power optimistic collapse they're not solving the data problem they're just solving the computational problem so what it means is if we are playing chess in a relapse you've seen a need to be able to prove that the moves happened so if we don't have the base layer as a data availability source for the for the information it means people can cheat by just denying information so let's say I'm playing someone someone here and they are about to lose they can say no I never did this move how am I supposed to prove that they actually did it now you post this information to ethereum and now you have a proof that they actually did the move in the chessboard um so that's why we still have the Json RPC communication so he's still communicating with ethereal node and people should be posting their transactions eventually if you think about other Solutions uh other projects that have the same solution so like arbitrine or optimism you're gonna see they use sequencers for that but effectively what they're doing is posting the things uh to ethereal Network and then at the very end you see there is a graphical API so this graphical API is easy it is useful for you when you're handling the UI what is being sent what is being produced uh from the node so we have three main outputs from the curtising node we have a report which is basically just a log you can still act if you're running the node you can still access the full log of the process but it's really good way of having a clear and clean access to the machine when you are using other processes so report for instance is very useful I'm sorry it's very useful uh as a ethereum call for instance so if you're checking a balance of your C20 you don't want to make a transaction you just want the AVM to tell you what is the balance at the current state so you can generate reports for that we're gonna see this um a notice it's like an ethereum event however with the spin you can prove that the event happened so if somebody creates a game and there is like events about winners and losers of the game and suddenly another project shows up and say you know what I want to create a badge for whoever wins 10 games now the person have a PR has a problem because how they are supposed to use the ethereum events to prove they won you can't you can't do that on chain however the notice that you produce here on the Christmas machine is a tie tied to the Cortez machine state so you have a marker proof that the notice happened so it's usually useful in that way the voucher is just like they notice in that sense so it's probable but it's also gonna become a transaction so we call it voucher because you still need to wait for the seven day window so it's not truly a transaction until the moment it is so whenever the Roll-Ups is settled you can as a user or as a developer you can automatize that as well you can pick up the voucher for instance a withdrawal request and go to the system to develop system and say hey I have a valid voucher I would like to execute it so it becomes a true transaction and ethereum so you can use that to interact with other smash contracts and apps and finally we have the HTTP rest there and that's the your direct communication with the node so the ethereum call was talking about would be actually done through the inspect request so you send a quick um a quick request to the machine it's gonna wake up spin up do whatever you program it to do and die and roll back to the initial state so it doesn't affect the internal state of the machine long term so it's really useful for uh populating UI data is to use it for for you to be debugging the internal state of the of your program um and whatever else you can think that this does not need to uh transition the state so going back to the code I showed you before you're gonna notice at the very beginning the um I'm sorry one second that we are actually importing python libraries this is not a python-like library this is a python domain specific something for blockchain this is truly python running uh it was just compiled for risk five on the yellow side uh we created a utility for people a CLI that it's based on Hard Hat by the way that helps you send quick uh data to the machine so you don't have to be developing your own scripts just to test things out so here uh we're basically creating a new transaction and sending hello there uh payload and then you can use the same CLI to list any new notices new reports or vouchers that was created uh since you last call it um so here I have an example of a pythonia code app so it's supposed to send back whatever I send it to it so going back there you're going to notice that I grabbed the information for the httpd special I was talking before the the rest API the mix things easier from the environment so you don't need to hard code it anywhere and here I'm um how to say I'm I'm signing up two types of handlers so there's too many uh too high level of handlers inside a criticizing machine when it comes to these requests one is the advanced stage so that's those ones I was talking about whenever there is an input you're actually gonna change the state of the machine and the inspect state is those that come from the HTTP inspect request I just talked about the ephemera stuff and here comes the most important request in this program so whenever you start this program you actually starting things up right like uh uh registering starting your process heating up the machine in a way so basically uh the very first time your machine wakes up you need to tell the architecture that it is done it's ready it's like deploying a new contract so you call this finish endpoint over here so what it does is tells the uh wrapper that I told you it gets that information and tells the framework that it's ready to accept new requests so from the perspective of your code the machine went to sleep over here so the line 24 your program dies for a second Whenever there is a new request wakes up exactly at the line 24 and resolves the post request returning to response their new request now we just unwrap the Json request we check what type of requests we have which is the of the type Advance or inspect since it is input that I've sent it's going to be a handle Advanced type so we're gonna go there to the function you're gonna see them grabbing the data from the data the payload from the data I just received and I'm just putting you back into a new notice so I'm creating a notice right now I'm not going to do anything with this data because it's an echo and now I just need to call the notice endpoint to create a new notice with that um I've basically concluded most of the things that this needs to do so line nine is just making sure that I finish with a accept state because if you reject you roll back the machine so you're gonna see that in line 27 I'm sorry go forward yeah lines 27 I'm just refilling the Finish status with accept and because we are in a loop I'm gonna go back to the Finish state so I'm gonna go back to the post on one second I'm gonna go back here and cue the machine again I'm just telling the framework I'm done I've done other process that I needed if I was sending an HTTP request you would come here to the handouts inspect and in this case I can only produce reports so like I said notices and vouchers they come with proof and because this is gonna be rolled back there is no proof for those so you can create as much as you like it's just not going to do anything the framework doesn't enforce you it does not break your machine just don't do anything so here I'm creating a report and if I were to list the reports later I would see on the other side finish accept now supposedly I would be listing the new notices and you would see the the payload over there um that's it for the workshop uh I'm open for questions now if you have some so she asked me if I can change the state of a smart contract on chain while the operation system so yes but through the voucher so let's say I need to transfer uh tokens to somebody uh we create a voucher that will be later executed and the execution of a transaction is actually changing the state that was my contract right so that's how I would talk back with the native ethereum depths so uh we saw there that we have inputs being sent to the machine how that that is possible on the ethereum network we are actually deploying a set of contracts for the roll-up architecture in the set of contracts are actually an alias for the auction code you see here so this step this characteristic app actually has a ethereum address whenever you interact with it it's actually an input and whatever vouchers get executed it's executed with the message sender from that address so uh all the other apps understand that it's coming from these address that it doesn't know what it is exactly but it's basically the characterized app so there is an alias there a proxy and an alias at the same time does it make sense yes sir are you sure so it's not private key based so it's a set of validators right so you have a set of validators they're enabled to interact with that and act um as owners so to speak but it's also a voting in a sense that's why you have the seven day window so if anybody has anything [Music] um they they see is wrong they can dispute that and it can keep disputing for a while until you get to the correct State and that means nobody's is the owner exactly but they are like responsible people for that does it make sense it's like a voting season in a way in a way by either ensure that execution is correct because you have the emulator on chain as well so that's a good question because it is an absolute specific roll-up as a developer you define what is the requirements so if it needs to run on a calculator just don't use too much resources on your dap but if you needed to do like machine learning or something it can be as beefy as you want your validator node yes yes but you need to be mindful as you are developing like what kind of knows do I want to have do I want to have all my users running it so if I went to my users running it maybe I don't should be putting the node to be so busy right otherwise simple computers won't be running it so it's like on the dab developer to decide what they want because of the the other slide I show like this one every uh dap is it's only little networking away so you decide yes yes so if you say that's only gonna be like 12 liters sure maybe like a chess game and that's fine if you want something that is a bit bigger but 10 is fine sure then if you want to have something that everybody is able to at least validate then you need to be mindful of that but there's no like intrinsic limitations just like Docker in a way are we good here so we are here for throughout the whole weekend uh at the table we are you are so well welcome to to visit us and ask us any question so at the very end uh have a link tree for Cortez here if you want to check for communications medium and why not thank you [Applause]
Automatic transcript — names and jargon may be misspelled.