Cartesi 🛠Build decentralized Linux applications (with the stacks you’re used to) - Gabriel Barros
ETHGlobal·Mon, Oct 9, 2023, 12:00 AM
Join Gabriel Barros from Cartesi for a workshop titled "Build decentralized Linux applications (with the stacks you’re used to)." Thank you to everyone who joined us for ETHBogotá 🇨🇴 and helped us kick off Devcon Week. With over 1400 attendees from 62 different countries, ETHBogotá was our biggest hackathon in Latin America ever! ------------------------------------------- Follow us: https://twitter.com/ETHGlobal​ Check us out: https://ethglobal.co​m Email us at: hello@ethglobal.com #ethereum #web3 #blockchain #eth
Transcript
foreign [Applause] [Music] guys so I saw some of you at uh at the booth already um today I'm gonna talk about how Cortez is bringing Linux to the blockchain and I'm going to explain how that's possible and I'm gonna show you a python example of how that works so this is a quick overview of what we are going to do over here so I'm gonna talk a little bit about Cortez what it is how long we've been around and I'm gonna do a live comparison between web3 web 2 and Cortez development and then I'm gonna actually talk about criticism I'm going to introduce you to relapse for those who are not familiar with it and then I'm gonna go diving to the code however I want to keep you hooked this is the code we are going to investigate together so this 25 207 line python code that's actually importing uh libraries for from normal python it's actually running on a virtual machine that can act as a roll-up for ethereum for instance this is actual smart contract uh this one here uh is doing an echo python so whatever you send it you send it back on the blockchain for you is a company that was founded in 2018 these guys have been working a long time trying to bring a risk five I'm gonna talk about risk five but a processor a true processor to the blockchain how to make a deterministic so you can do like normal computations um and uh and that's why they're calling it the blockchain OS because uh we actually brought the Linux for it so the overall idea I guess you're all familiar with it so I'm just gonna run through it is that ethereum is awesome it's secure it's somewhat since censorship resistant decentralized there's all these good features about ethereum however it becomes it's low it is expensive so adapts are actually fighting for space resource uh inside of of the blocks to actually be processed and it comes with a lot of friction for developers that are just coming to blockchain so you have 30 years of experience doesn't matter you're gonna start over all over again you know so the idea is what if we can do a complex computations and maintain the main layers security guarantees so here's the the courtesy response to that first we use a transparent VM so you are able to actually see the whole code is not a complete somewhere complicated but it's open source uh like the Alaska I was saying compiler stuff is hard but in any case it's open to everybody to investigate it and it is using uh their risk five like I said so risk 5 is a open harder platform just like open source but for hardware and it comes with a lot of security guarantees already because uh it's being audited by several companies and people it it has been updated uh it keeps getting updated throughout the time so that's nice um any person is allowed to build on top of it and it is a platform processor which means you can actually have any kind of OS on on it it's a very robust machine and the only thing that we need to actually adapt is uh to build a deterministic emulator so we made risk 5 deterministic and because of that we could actually make the emulator for evm as well so whenever you run the computation of chain it is possible to actually run the same computation on ethereum right now in fact one of our acceptance tests is to actually do the the whole risk five acceptance tests on chain so we of course it's a test Network a local test net but we do it on the AVM just to prove that the version that we have on chain is the same exact version that we've developed in C plus so that allows you to have massive computation on as a layer two and with that you developed the the whole way this works uh the the idea of to actually have the massive competition now become yeah and not a limiter again is to have at local consensus I guess people here are more familiar with uh app Centric roll-ups so because of that instead of having a lot of computation doing the same work over and over again effectively only having a single machine which is the way the ethereum works you can actually have computational resources um dedicated to each application so every application is it is its own Road lab if you use the advertising framework uh finally the most important thing it's actually make it work with the blockchain right so that's where the dispute protocol uh comes in uh it's not any novelty it's actually being discussed for a long time so here we are using the verification game the overall idea is um you get the whole computation you did of chain let's say it took like 3 000 Cycles CPU Cycles you find exactly where the validators diverge and you only have to execute a single CPU instruction cycle on ethereum which makes validating the whole process really cheap so the um how to say the end result is ethereum becomes a judge so it means that if you have I don't know like four people playing a poker game and one of them win and the other three start to collude against the 1.1 that single honest validator that's all that you need a single honest validator to come to ethereum and complain about the end result and then ethereum is going to judge who is talking who's telling the truth so you guarantee the correct settlement of computation so for those who are not familiar with burlaps the overall idea is you have the main chain it has its own blocks at some point you initiate the process you tell ethereum here's the initial state of my rollup and you go on with your life for a little while of chain doing computations and once you're done or once you want to do a checkpoint because that's the idea of roll up you always check pointing your process you go back to the blockchain and with optimistic relapse you actually have like a seven day window for now like that's their agreed good uh time span for uh disputes so you have a seven day window to actually complain about anything that went wrong on that um block of computation so to speak so how it comes uh how everything got gets together right so before in web 2 you used to have like a some kind of a front end a few apis uh defined by you to be run in a centralized server or a set of centralized servers talking to a set of centralized databases right that's the main web 2 idea so ethereum comes up and say you know you know what like uh the business logic whatever is most important you can actually decentralize that so if you're a way to to deploy your front end you can use ipfs which is really nice and you communicate with a blockchain doesn't change that too much the overall idea is to you have the same feel as the ethereum you are supposed to have a set of nodes that you communicate with just like what happens with ethereum to have your backhand be the the base of your app the main difference is um instead of burden the the developer with all the little things needed to actually communicate back to ethereum we developed these uh H we are calling here HTTP dispatcher it's just an API that encapsulates all the complexities of communicating with the blockchain back so basically what you need is just to communicate with that rest API so there is a definition of that there's three endpoints you get to learn how the endpoints work and now you can develop your solid I'm sorry your smart contract in any language that's the overall idea and I'm gonna show that in Python so how he actually looks like we have the three main pieces of of apis the first one is the Json rpcs just there so that one is still like uh ethereum so you have a data availability issue right uh you are suddenly on uh compute on process like on computational disputes but it's still uh again and chicken situation if you don't have an agreement what was the input input that you had for that process so the idea yes let's keep using ethereum or any other layer one networks to just communicate what we're I don't know our chess moves for instance so you have the Json PC there still to do inputs to the roll ups however you have the graphical API that we developed and the graphql API is mostly so you can check on three things that we have on a Cartesian machine so over here we have report and notice they are similar but different enough so report is any kind of log that you log within the Cortez machine think of it as a developer a developer debug log so it's not provable it's ephemeral it you cannot do much with that it's just to help you out while you're checking the health of a process or you're developing your dap however the notice is our version of ethereum events with a Twist so right now if uh erc20 token says there was a transfer transfer between an AMD party of some of them out it's trustworthy enough if you're wearing this year node however you have no proof that the event actually exists you have to be running the node to trust the event the notice however comes with its own proof so the notice is part of the machine state so if you go back to ethereum and you have to integrate other dabs and interact with other apps inside ethereum or even on other optimistic relapse you can build upon the idea of having notices so let's say you have a transfer happening inside the ethereum machine it doesn't need to be a direct call you just need to say hey I actually won the game let's say an nft generating situation so in order to win this badge like uh the winner like you have to prove that you won 10 times the game you just collect the 10 notice and you can put it to to be proven on ethereum for instance so that's how it is different from event and voucher the final one is basically a transa ethereum transaction that is yet to be so whenever your roll up dap wants to communicate back to a Smart Contracting solidity for instance it creates a voucher and if the optimistic relapse settles and there is no disputes on that after the seven day window the voucher becomes executable so it becomes actually an ethereum transaction so you as a user could just call it an and claim the voucher or you could let the validators on the network do it for you there there is like uh fees and other stuff going on on that so that's why you have the graphql API because if you want to populate your front end with that kind of information you can access it directly uh calling the node finally we have an ATP rest uh API that works like if call for those who are familiar with ethereum basically is any call that you do to the machine that is not State transitioning so we ensure that this call we always roll back to the initial state of the machine that's the main difference and that um call only can generate reports because that's what I said before right it's something that um it's not not provable so the idea is to have pre-depth communication you can use it to grab data for your UI and you can use it as a debugging solution as well it's easier to check up on on the state of your machine of your program so now I go back to the python the python example so to this yellow side over here we have a tool on our roll up examples uh repository but basically they're encapsulating um JavaScript code like to how to actually call stuff uh through the Json RPC right just uh it's a helper too and over the blue side I have the actual python daf so we're gonna start sending like a payload with just hello there that it is just a transaction call data nothing special about it and we're gonna start checking what happens on the code so from the beginning you can see that I can use all the support uh python offers me and I'm gonna start using requests because I want to talk to the API that I just talked about right I want to be able to do HTTP requests I grab from the environment where is the actual URL for the HTTP API within the machine so we um we provide you with the environment variable to us for you so you can actually just grab it without Harding hard coding it on your code and here we have the two types of handlers uh I was just talking about but from the api's perspective within the the machine here are the two types if you receive an inspect State kind of a request it means that the whole machine the whole emulator will revert back oh something happened okay now we're back uh so if we refer back to the previous state before the requests however if it is Advanced State it's basically telling you you know uh This is Gonna Change the stage so you should do it properly basically and with that it's just the high level you can subscribe and create as many endpoints as you wish it's just like solidity in a sense uh insert at the solidity code you basically have the entry point and you do all the switch for the functions right here you have the main Loop so the idea is that this machine halts it doesn't stop it just helps so every time you finish a request processing the request it just halts at the end and wakes up at the next input so this finish over here is actually a kind of like a next so it's actually saying hey I'm ready wake me up whenever you have something so you stop over here so as we begin for the first time in the code you're gonna see that I have like finished status accept and that's what I'm sending to the to the emulator uh beneath it and it's gonna Halt and then when I say hello there you're gonna wake up the code exactly at this line and from here on out we are just gonna process this request so I send an input so it should be an advanced State kind of uh request so we're gonna just pick up the Json data from there actually go to the Handler that is responsible for that so that's the advanced State and add a function at this time I'm just gonna create a notice just the notice with the same data I just received so uh I get grab the data payload and put it in the notice payload back it's just a simple program in this case and I'm gonna call the API creating a notice that's what that's doing it's not gonna hold the machine it's just saying hey here's something that it is an output from this process and I can call it as many times as I wish okay and the result is accept again uh it's all fine so uh I'm just gonna jump over the inspect for a second so I would just add to the status accept and because I I am in a loop I'm gonna end up here to finish again sending the accept status halting the whole machine however if I had a Handler of the type inspect meaning instead of sending an input over there I would actually try to inspect the machine saying hello there you would go to this different Handler you would create just a report just like the notice is not that different uh when you see the code and it's the same I just finished and whenever I ask for the the helper to list all the new notices that there is there you're gonna see that the machine would return you with the hello there as a payload and that's the overall idea do you guys have questions I guess it's too much yes oh yes so yeah it's still a blockchain environment so in a sense you're not connected to the internet you can have internet at the testing machine when you're first building it so remember the roll ups example thing I was doing like initial state so let's say You're Building your machine building your adapter and you need data so I don't know Docker images and npm installs and things you can have that for sure but once you're in the roll up environment you don't have that access anymore make sense go ahead so there is the cost of deployment of the Roll-Ups itself like the set of smart contracts and stuff it's not the high I don't actually have a right figure for you right now but it should be something around for like 50 or something for ethereum right now but just just so you have all the instruction points so to speak on ethereum because this staff actually has a a mirror address on ethereum so other apps can communicate it uh through it back to the courtesy relapse but in terms of actual cost of running this thing is up to the developer you you say do you want to charge people for using it do you wanna just you and all the developers run the notes do you want to incentivize your users to run the nodes it's up to you in the sense Cortez is more like a framework really because it's really app specific you tell the parameters don't you don't like the seven days because you're doing a simple game like if really simple low stakes maybe it's just five hours for for your roll up settlement we know [Music] make sense you had a question I mean it's up to the DAP developer if it is something that makes sense I guess sure but yeah right now we're in the middle right we understand that mostly we're still gonna have like um these service providers running the nodes and people kind of like trusting them yeah any more questions okay thank you [Applause]
Automatic transcript — names and jargon may be misspelled.