Giving an Operating System to Dapps

EDCON 2020 · August 2020 · 15:29

Erick de Moura explains Cartesi’s approach to running application logic off-chain in a deterministic Linux environment on a RISC-V virtual machine. He describes state commitments and an interactive dispute process for settling incorrect claims on-chain, then uses a tower-defense game to show how mainstream software and intensive computation can support Ethereum applications.

Speakers

Topics

From EDCON 2020, hosted by EDCON.

Transcript

[Music] hi my name is eric demoden founder and ceo at cartesian cartesi is a project that started in early 2018 with the objective to make the apps easier to build and much more powerful we have been building a blockchain agnostic second layer infrastructure that allows the apps to uh move intensive computation over massive amounts of data off-chain while retaining decentralization and the same security guarantees of the

underlying blockchain also all the data involved can remain private among the interested parties in the application well so far there are quite a few projects that that are also attaining these uh features in one way or another but what really sets cartesia apart is the fact that the app logic can actually be built using mainstream traditional software stacks on a real operating system so actually we provide a linux runtime environment where the app logic can run so you can use mainstream software stacks and

also os resources like the file system that's quite unique especially if you compare this to the very limited um runtime environments and language let's say of solidity in which developers even struggle to convert numbers to string now a few weeks ago we released the alpha version of our first product the the card stk the cart sdk is a product that provides superpowers to ethereum the apps and smart contracts so uh smart contracts are able to

specify a computation in the form of the full linux os and program that runs within it and this computation will run by the card nodes that uh are run by the interested parties themselves so actually the app developer can choose a set of nodes that will run and verify computation of chain typically uh the uh the the nodes will be run either by the the app user themselves or by people or organizations that they trust the important thing about the way that these nodes achieve consensus of chain is that as long as we have at least one

honest node uh the honest node is always able to ensure that the correct results of the computation is persisted on chain so we have a way now that's already available that smart contracts on ethereum are able to specify these complex and intensive computations to run off chain while retaining decentralization and the security guarantees of the main chain so here's a graphical representation of what i just said uh you have a d-app contract that's able to specify the computation and the d-card nodes that are involved run this computation of chain uh sorry a claimer node presents the

results to the blockchain and the other validating nodes are able to verify the claim presented and if one of the nodes see that the claim is false that node is able to start a dispute and enforce that the correct results is persisted on chain so at the heart of the cartesian node we can find our vm which is called the cartesian machine the cartesian machine emulates a risk 5 isa and is able to boots an entire linux os

it is deterministic reproducible and self-contained these are fundamental properties to make sure that consensus is achieved the other important feature is that the cartesian machine is transparent and it's able to produce a merkle tree root hash of these of its entire estates and also merkle proofs of parts of the states that show that the part of the state is consistent with the with the the full state hash it also is able to prove that the execution of one single microprocessor instruction advances the

uh the machine from one stage to the next and from one hash represent the states to the next state hash this is very important because we also need a mirror implementation of the risk 5 isa uh in order for the blockchain to verify the proof that one instruction actually takes uh the one state to the next state which is fundamental for the dispute resolution protocol uh finally uh when the developer is creating uh their the app they need to provide a cartesian machine

template it's basically a template that receives a rom specification a ram image that will contain typically the the linux kernel a root file system flash drive and a set of inputs flash drives and one output flash drive so everything in the cartesi machine is configurable actually the the app developer is able to choose the amount of ram and number position and lengths of the uh of the drives uh over a 64-bit physical address space of the machine everything is configurable by the app

developer according to the the app needs so for the cartesian machine templates of course the input drives are empty at the beginning because these input drives are going to be replaced by drives that are going to be fulfilled with the actual information that is coming at runtime when the app is running here we have a sample of how we could instantiate a cartesian machine using the command line interface so you can easily see that through this command one can pass a wrong image a ram image specify the the amount of ram uh the root file system is giving through a flash drive

and when the machine boots it just executes uh the sample command ls slash bin and then it holds the cartesian machine provides other ways to for one to manipulate it from the outside so we also have a lua programming language interface a c plus plus interface and most importantly a gr pc interface that's fundamental for the cartesian machine to work inside the nodes uh and interacting with the blockchain uh from the inside of the cartesian machine you know the the program sees a full computer and a full linux operating system so it

doesn't know that it is in a emulated environment at all let's give it a break for some time to talk about some cool application that we delivered at the beginning of this year crypts is a tower defense game in which the players compete uh against each other for the high score it's fully decentralized it runs on ethereum thanks to cartesi what's cool about crypts is that is that it involves heavy processing you have billions or even trillions of microprocessor instruction steps that are required to run in order to

verify a gameplay and of course doing that on chain would be impossible due to the computational limits of the blockchain the second important thing is that uh crypts was implemented using typescript and it does among other things compression and decompression of files which of course would also be impossible to do on ethereum because the concept of files is not there so here we have a fully decentralized tower defense game uh involving heavy computation and mainstream software stacks and os resources totally working on ethereum thanks to

cartesi so if you want to try you can just download it's open source you can even use it as a template to build your own game let's go back to how cartesi works so we spent some time talking about the risk 5 vm architecture which is one of the pillars of the technology and the other pillar is the local consensus protocol i like to spend some more times talking about the local consensus protocol it's a very important aspect of the system if you were to develop a game on ethereum or any blockchain supporting smart contracts

and let's say alice and bob would challenge each other on this game then for every every single game move that alice or bob do uh it becomes a transaction in the ethereum blockchain and that transaction with the entailed computation needs to be emulated by around 12 000 full nodes in the network and of course the 12 000 nodes are not interested at all in the results of the match between alice and bob that doesn't concern them so it's really a waste to involve so many people doing this computation uh for

for the two players that are competing in the game so the smart approach here is to instead let alice and bob play the game totally off chain uh and at the end of the game uh when let's say alice wins the game she just goes to the blockchain and a single transaction is needed only to settle the resolution of the game and perhaps give alice her token reward or something like this of course it only works if it prevents any kind of cheating that could happen from bob so uh if bob is honest and he recognizes that alice won the game

then everything runs smoothly alice just shows presents blockchain and that she was the the winner now of course bob can go evil and he can pretend to be the the winner of the game and then we need to have some mechanism so that that's that alice can infallibly prove to the blockchain that she actually won the game and that's the mechanism that's behind cartesi so for for this to work well we also need an incentive structure because we don't want uh these things to happen right you don't want bob to go evil and try to cheat that should be the

exception so what happens if bob tries to cheat is that alice can go to the blockchain and start a dispute resolution protocol for that she places a collateral deposits on a smart contract and she is not worried because she knows that she can prove to the blockchain she won the game and she's gonna recover later her collateral back now two things can happen uh first uh the the challenge challenging period just expires and alice wins by timeout because bob didn't show up and the blockchain assumes that alice won the game and returns to her the collateral there are the

possibilities that bob goes crazy and really tries to fight back against alice uh of course he's gonna lose because he cannot prove to the blockchain whereas alice is able to prove that she's a rightful winner and in that case alice is twice as happy because she not only recovers her collateral proves she won the game but she also gets the collateral that has been slashed from bob so how it all works together cartesi is a blockchain agnostic um second layer infrastructure that allows the apps to move intensive

computation over massive amounts of data of chain while retaining decentralization and the same security guarantees of the underlying blockchain in the rare cases of disputes the blockchain is used as a supreme court and only a negligible amount of the original computation needs to be run on chain we also saw that the cartesian machine employs mercurized representations of its internal states and that's fundamental for the system to achieve consensus we also saw that we have enough chain and a non-chain implementation of the risk 5 isa the on-chain implementation is necessary to make sure that in case disputes happen the blockchain

can verify one microprocessor in step instruction so that the honest claimer can make sure his claim succeeds on the blockchain the algorithm that we use for dispute resolution is an interactive dispute resolution protocol called the verification game it's a protocol that's used by other projects like truebit if you want to know more about this protocol we have extensive documentation explaining this on our website on our tech paper and uh you can just go to cartesia.org from there you're able to find all the documentation you need to

understand cartesi in depth you can also find our contacts from there and it will be a pleasure to talk more to you thank you you