New Ethereum talks, every Monday. The week's conference uploads by event, in your inbox.

Loading player…

Cartesi 🛠 Build more powerful DApps using familiar stacks and libraries - Carlo Fragni

ETHGlobalMon, Oct 9, 2023, 12:00 AM

Join Carlo Fragni from Cartesi for a workshop titled "Build more powerful DApps using familiar stacks and libraries". And that wraps up 2022! ETHIndia 2022⎯the biggest Ethereum hackathon to this date with over 459 projects built within 36 hours. 🫂 2000 attendees from 🌆 321 cities that were 🌱 44% new to web3... ...joined forces in Bengaluru to write history. Thank you for taking part in it 🫶🔥 ----------------- Follow us: https://twitter.com/ETHGlobal​ Check us out: https://ethglobal.co​m Email us at: hello@ethglobal.com

Transcript

foreign [Applause] [Music] ER I'm a senior lead solution architect advertising and today we're going to talk about how can we do things using our attack right so basically what we will cover is an overview of cartesi an overview of how you can develop with it and I'm going to do some comparisons on how you do web free development web to development and then how you do it with Cortez array and a quick answer to Cortez rollups which is the product we use for enabling our Tech so just an overview of what this stack is about is this so basically the objective is having this really rich code that you can use for decentralized applications so if you develop on solidity you probably have faced a lot of issues like the size of the transactions or lacking libraries that do stuff that you're usually doing on web2 like parsing a string or something like that access and database all this stuff and that's what we want to bring we want you to have the same power and expressiveness and computational power that you have on web2 only available on web free in the decentralized fashion right so if you take a look in here this is a really simple example of DAP in cartesia this is an echo dab basically what it does is whatever we throw at it it just throws back at you okay and if you are into python you can see that this code is looks just like any regular web 2 python code right that's because we wrapper the whole framework and how we interface with it in a simple HTTP interface and that's has a couple of reasons because as most developers they're not webview developers right you have a really steep learning curve and in order to make it easier for web 2 developers to onboard we made the decision of providing this nice HTTP interface you comply to it you're used to it and now you have additionalized application right this is just a preview I'll just explain stuff and go back to this layer okay so let's go from overview of Cartesian basically we're bringing this new OS and it's we think it's pretty neat so we love affirm ethereum has security it has decentralization with censorship resistance we have all these thousands of nodes validating everything anyone wants to tamper with something it's really hard because you have to lie consistently with thousands of nodes in order to do this but ifuna also has this drawbacks right because since everyone on the network is validating everything it means that all the nodes on the network are producing all the computations and that makes it very limited because if you have the Ethereal Network and you don't have tiny transactions well we just throw a yo one loop at it you just hold to the entire network right or if you don't make it really really expensive like this well then you can just flood it with useless tiny computations and you hold the network anyway right so the idea on cartesia is can we get this really nice security guarantee use of the blockchain but enable really really large computations and also bring better tooling for development and that's what we go for okay so how do we do this well basically what we do yeah what we do is have this special VM we call the Cortez machine and this cartel machine provides the Linux runtime environment and uh there's the computations that happen inside the Cortez machine are secured by the blockchain right so this characterized machine is based on is based on risk five and what happens here is risk fives is an open Hardware specification done by the guys at Berkeley and it's really similar to what we have on our computers on our cell phones right and because of that it's compatible with Linux and another thing we do is that unlike in ethereum in which everything is running on the same VM so the AVM basically is running all the applications if some applications use more resources using a lot of things the other people want to lose it we have a VM per application so a VMware application we have a regular processor and Linux well we just enable a lot of things for you to use in there and the Cortez machine in order to do this needs to be deterministic so we put a lot of effort on making this risk 5 based machine that's amazing like clock floating Point instructions all the stuff that could generate entropy we just had to make it deterministic and uh yeah as I was saying to reach this stage in which you have a lot of computational resources what happens is we rely on local consensus and we have a ropes Solution on top of it so what happens is that unlike an ethereum in which everyone on the network is validating everything on Cortez we have different sets of validators per application so if you're interested in an application you can validate it if you're not you just let it go you don't have to watch and validate everything that's going on in the network okay and uh as I said so consensus is basically uh really strong on ethereum and others because if you want to tamper with a computation it's really hard to lie because you have a really large amount of nodes and I just told you guys that in order to scale what we do is not everyone validates everything so you can have a really small subset of the network validating a certain application so how do we keep it secure so basically when there's a dispute and you don't agree with the result it's not a matter of a local consensus with the people that are validating that application and you just pick up the majority and that's consensus no what we have is a is a dispute protocol we call it the verification game in which whenever this is dispute what we do is basically the the people that are disputing since they are running the same application on the same cart as machine and this deterministic they should reach the same result if they didn't it means that at least one of them did something that they shouldn't so we have this interactive protocol called the verification game in which it has two parts so so the first part is it tries to use this cardizing machine on both batteries off chain and they post a signature of the state so we basically opened all the Cortez machine State We've ran disk even processor State like the instruction counter everything we map it to RAM and then we divide it in 4k pages and these 4K pages are hashed and those are the leaves of a merku tree and then this root hash of the Mercury represents the whole state and you use this to check if you agree or not with the state of someone else's Cortez machine so when there's a dispute what you pick up is you pick up the whole computation let's say we have I don't know a million for instance Cycles on that computation so we do an enter search to search what's the first instruction we don't agree on what we do is okay I'm gonna post my root hash of the Merkel of the Cortez machine at 100 million 10 million cycle sorry 1 20 30 40 up to 100 and then you're gonna tell me okay so up to four for 40 million I agree 50 million onwards doesn't match so now we know the Divergence is between 5 million and 50 million then we drill down so 41 million 42 33 44 up to 50. and we go there and each time we divide the search Space by 10 so in logarithm number of interactions I don't know it's instruction 43 million 3007 that we don't agree cool now we know the instruction we don't agree but who did this right right because I'm claiming something or claiming something else that's a real special part so what we did and this is the second part of the the process is whenever we reach that instruction it's not my word against yours we just pick up at that instruction and we have a known chain implementation of the Cortez machine so we had this huge effort of making an on-changed set of contracts that can emulate each instruction of the advertising machine and this on chain emulator is the one that actually picks up the instruction and executed so it's not me it's not you it's the thousands of nodes of on ethereum or whatever base blockchain we're using that they're gonna say who did the execution right so this way we can have a really tiny set of validators and computations really large ones but still maintain the guarantees of the strong guarantees of security blockchain right so as I said it's an optimistic Loop solution in which we built so basically we do all these computations inside the Cortez machine and from time to time we just pick up the signature of the Cortez machine and put it on chain if someone disputed okay there's the verification game if not we move on that's Saturn stone and you can keep up the computation for the next step so how's the development of this so you guys are used to web2 web 2 is really simple you have a browser you use some framework like I don't know angular or react to whatever you want to the tools HTML CSS JavaScript as based Technologies and you'll do these nice interfaces and then you interact with a backend right generally using HTTP or https and then you have a service the service might use a database might use someone else's API this kind of stuff right really simple now when we go to webview we still have a similar front-end but now we need a special library to interact with the blockchain generally we have something that implements the Json RPC protocol so if first webc.js something else and then instead of talking to a backend this guy is actually talking to the blockchain like a node on ethereum or maybe a broker like in hero or Alchemy or something like that right and as you guys know you have multiple imitations and processing all this stuff it's hard very hard to look for data that's why we have services like the graph and stuff like this which are very popular help you on the indexing and this kind of thing and how does it look when you develop with protizing well basically you still have your front end in which you use whatever technology you want so if you have a browser you can still use angular view or react all this stuff and then you have a set of libraries to interact with the framework right and this framework there then it has a real nice machinery which takes all the abstraction of the verification game of all this this stuff from you and inside the Cortez machine we actually wrap as it as I told you guys all the framework on a HTTP interface so we have this HTTP dispatcher service which is the one that you're talking to when you're developing your application so from your development point of view you're just talking to a HTTP interface and that's it you don't have to care about the blockchain about reorgs about any of that we take care of that for you okay so just going a bit deeper on how this works so those libraries I said they basically use three different interfaces so we still need a Json RPC to talk about blockchain because whenever you're trying to reproduce computation well you need inputs right so you have a data availability problem if you're not using blockchain let's say I'm storing my input on ipfs for instance and then you say I cannot do your computation why I don't have the inputs okay from the blockchain point of view there's no way for you to say it's me lying about it not being rpfs or it's you lying that you didn't put it in there so that's why we need a Json RPC interface and we provide inputs through the blockchain the second interface we use sorry the second interface we use is a HTTP rest interface and that's used for something equivalent to if ethereum calls right so we have this inspect interface that on this inspecting surface basically we allow you to directly talk to the Cortez machine without any fees anything it's just HTTP connection directly to it and you can do whatever processing you want to query for state so let's say you have a chess game for instance if you open an application on a mobile phone and you want to know if you have ongoing games and watch the state of the game you probably need your client to go there and look at a graphql with something or an indexing or go directly to the blockchain check that you have a transaction which you started again check all the moves that our players did until you you have the current game State and you're actually good to go right so this inspect interface is to handle things like that so instead of doing that what you do is you go through this inspect interface you just call it the Cortez machine you give your address and you say hey what's up and then inside the Cortez machine you can process it on whatever language you want python C plus plus regular backend and then you can check oh yeah you have an ongoing game because I started in the in the database and yeah this is the game state in a Js Json and its white players turn so much easier than just going through the blockchain trying to reconstitute the data or using something like the graph to index a lot of data right and the third interfacing there which is the graph is a interface that we use to ease the outputs of the Cortez machine so the Cortez machine basically can use reports which is something you generally return when you're using this inspect interface then you have notices notices are a mechanism really really similar to what we have on ethereum events so when you want to have a statement and it makes sense forever like I want this match or something like this notices is what you want to go for and then we have this third interface which is which is vouchers so what vouchers are is a way for you to emit a transaction to interact with the blockchain from within the Cortez machine so since the cartels machine is deterministic and doesn't have outside the interfaces like internet and stuff like this inside the cortex machine you just do your transaction and then you put it on a voucher and the voucher is a really cool mechanism because you query it on graphql anyone can enforce it because after all it's a transaction that's signed by the application itself and then we have an incentive mechanism that when you submit the voucher and you force it you go to reward a bit and we got all these nice smart contracts on the framework that check if the voucher is valid if it was submitted already and all this guarantees that we should have right okay uh so let's go back to that initial code so how does it look like so basically this is an echo application as I said it's a really simple one when I referred it it throws back at you on the left side we have an example using this front-end console that's available on our Apple so the URL is down here but you can also query me for that later also available on our side so it's a simple application that in typescript that basically implements all those freeze interfaces are shown and on the right side we have a basic Echo application written in Python so that's the actual decentralized code right so what we have in here if you take a look is first we start using this front end and sending a payload so hello there so from the blockchain point of view we don't know what it is it's just a binary output binary input but your application knows that's a string right so inside your application that's regular python code as I said so we're importing OS because after all it's a Linux machine and that service that I mentioned that that has all the wrappers in HTTP interfaces well basically This Server is is listed somewhere and we settle an environment variable with it so we're using OS environment to load up that variable and we also use requests so people familiar with python know it so really well known uh HTTP library right and okay using that OS now we're picking up that environment variable so we know where to connect on the Cortez HTTP servers and now we have uh this dictionary here in which we settle Advanced State and map it to a method called handle Advanced and inspect State and map it to handle inspect so Advanced State inspect state are payload whenever you receive an input on the Cortez machine it can be from two different sources so it can be this input that came through the blockchain and is actually advancing your application state or it can be a direct query you do for example that chess in which I said so they're having a game stuff like that inspectors it will come with this metadata as in Spec state so you know it's something that's going to be thrown away afterwards right and the basic structure is you have this infinite Loop and this different Loop has an iterator okay in this iterator you're doing those two things when you call that finish endpoint you're putting a payload that's saying what you did with the previous input so let's say we're playing chess and I just do a legal move with the queen well it shouldn't happen right so you you refuse this input so in that payload you're gonna say that the status is reject now if you provide me with a valid input I'm just going to accept it and that's the input of this endpoint now what's the response the response only comes when there's something to process so once you call this guy it just pauses the Cortez machine and the Cortez machine is woken whenever the framework has something new for its process either inspect or a new input for the blockchain right and well this response there then you parse it and as I told you you have a special header on there request type which can be either Advanced state or in Spec State and given that we're going to use that dictionary in there to map to the right method to handle it and then we just call this method so handle Advanced which is the one we call in case it's Advanced State it's an app application really simple so it just picks up the payload that you received it creates a new dictionary with a payload entry and putting whatever you receive in there and then once again a simple call so you do a post on this notice endpoint with the payload that you just set on that dictionary and that's it you just emitted your first Cortez event which is a notice with the payload you received from the from the blockchain itself any return accepted because well that's valid so let's go forward so on the handle inspect which is the case for for this inspect API which is uh ephemeral same stuff only that this time we're picking up this payload and we're putting on a different endpoint on report report use this other interface in which I told you guys that it's meant to be ephemeral so whenever you do a report is it's not stored it's not there in Forever it's like an ethereum call response right and yeah that's it after you process it we just set up that finished status to accept a reject and do it again so now on the left side once we process this what happens is we emitted the notice in there right because we just sent this payload through the blockchain hello there we got in there and I noticed was emitted so we can still use this front-end application and use this really nice command yarn start to know this list and what this does is it goes to the Cartesian node to the graphql interface and says hey show me the notices and there it is you're going to have a notice sorry you're going to have a notice stating the epoch input and notice index and the below this is in there hello there so Epoch is but because we are Optimus grow solution right so all these time frames in which we validate stuff and then we roll up those we call epochs so that's the index of the epoch so in a given time frame you can have multiple inputs so you have the the index of the input and then a single input can generate multiple events right so we also have the another index for the the notice there and well that's it uh so basically we have a tracking here which has a ten thousand dollar USD price and uh it's divided in three so first place takes 5K second place takes 3K and third place takes 2K uh we have multiple resources available to help you guys so first of all we're here so you can just come at our booth and talk to us we also have multiple examples of code like we have this getting started which is echoing python in JavaScript in C plus plus in luo in multiple languages we also have some nice applications using machine learning or database like sqlite and uh yeah a lot of interesting stuff in there so you can give it a look we have a special Discord channel for this hackathon so if you scan our QR code on our booth you'll get there you also get a special badge that no one else will ever get just people attending this event and we also have the cortezidox available so yeah once again this is hackathon so you probably want to make the most most tracks to have more more chances right so if you want to mix our project with something else let's say you want to do a slot machine and you want to do it on top of polygon calling a smart contract on on chain link for a random number generation and then you want to feed it to Cortez machine to actually do the slot machine so you want jackpot or you you didn't get anything or something like that you can always come and discuss with us and we can help you integrating stuff and and figure it out right uh that's it hope you liked it if you have any doubts any anything just talk to me later or you can stop at your booth and yeah hope to see you guys doing something really nice on this hackathon thank you can you go back to like the starting of the slideshow this one starting of the slideshow next time the flowcharts this one yeah this one okay so uh let's say for the ethereum network right it's more secure because you need more notes to like there are many people right so you need more than at least half of the chain to uh for the uh uh request to uh get through right yeah basically when you when you reach consensus it's true and you need most of it yeah we have a different for different CMS we have dap a will have its own set dab B will have his own set right yeah so less number of members also does mean that it's more susceptible to like monopolizing right yeah as I said if we didn't if we just use consensus so like I'm playing poker with you and two other guys right if I just ask okay so what's the winner and then if we have like three people saying one guy is the winner well he's the winner and that's easy to manipulate right so you just have to temper it with three people but as I explained Whenever there are disputes we don't rely on the consensus of the nodes that are involved in that computation we actually engage on this verification game and then the consensus is based on the execution of that instruction that we came together as the Divergence instruction and this is done on chain on a blockchain with thousands of nodes like ethereum so I'm playing with you and two other guys poker we have a dispute it's not us that's settling we engage on this verification game and this verification game runs on top of the ethereum or another protocol with thousands of nodes and then even if the three of you are lying but I'm telling the truth I can still enforce the truth so uh what's really nice on this protocol of ours is that you don't need the the security guarantees is not most of the nodes it's at least one so a single pilot can enforce the correct result so we have computation with 100 validators 99 Roi but the single party can still challenge them all and enforce the correct result because in the end it's consensus of the underlying blockchain that settles it which in case it can be ethereum polygon hypnosis even other roll-up Solutions like optimism or Arboretum thank you yeah anyone else once okay uh foreign [Music] okay so basically the Cortez machine can have the size you want as long as the validator is willing to start it right so you can think of it kind of like a kind of like a decentralized AWS right so you set your application you say that your Cortez machine is I don't know two gigabytes of RAM for instance and 10 gigabytes of storage and then you say I'm willing to pay xctsi per epoc validated and then on the other side you have validators that will say okay I'm willing to start this car test machine I have the resources and yeah I'm willing to be uh to do to validate each block for the amount that you're proposing if not then you should probably raise your your fee and actually have a group of validators uh wanting that but uh going back to the storage itself so basically the validator is holding that characterized machine which in practice is a Docker container with this emulator inside and if he wants to store like a Cortez machine that has 10 gigabyte database so that's fine and yeah the database would be sorry inside the Cortez machine so off chain so you don't have to pay for a lot for for storage and stuff like this did I answer your question okay awesome anyone else this is got a question anything okay awesome it was great talking to you guys and uh well looking forward to whatever you're building have fun [Applause]

Automatic transcript — names and jargon may be misspelled.