Rollups: Cartesi Node

Unleashing blockchain’s true potential

Felipe Argento
Cartesi
8 min readAug 24, 2021

--

As of 2022 Descartes has now been renamed as Cartesi Compute.

Written by: Gabriel Coutinho and Felipe Argento

Introduction

Alfred Whitehead has said that “civilization advances by extending the number of important operations which we can perform without thinking about them”, and the same can be said about technology of all kinds. In software, this manifests itself as pre-existing libraries, tools, operating systems, compilers, interpreters, and many other components, wherein we can build upon them without thinking about the underlying system. Modern software is very intricate, and we are only able to build it by virtue of the accumulated knowledge contained in these pre-existing tools.

This concept is at the core of Cartesi: enabling the number of important operations one can do without giving them thought. Current blockchain technologies do not have this characteristic: the computers in which smart contracts are executed are novel, in all the bad ways. None of the software that has been developed and matured over the past forty years can actually run on them. There’s no ecosystem to speak of. As such, it is impossible to develop intricate software for current blockchains: all the abstractions would have to be built from the ground up.

Imagine the hypothetical scenario of going to a computer store to buy a new computer. You’re offered a super-fast one that was just released, but it cannot run anything that exists today: applications, libraries, tools, operating systems, compilers, interpreters, you name it. It can only run its own flavor of machine code. The vendor could try to persuade you by saying “ah, but new software can be developed, from the ground up, for this specific computer”. Which, in many ways, is how software used to be developed before high-level compilers and operating systems. Performance notwithstanding, such a computer would be useless. There’s a reason why we’ve outgrown old software practices. Without any of the abstractions painstakingly built and iterated over for the past decades, no one in their right minds would even consider buying such a computer.

Layer-1 smart contracts are much like this computer, except they are also super slow. Layer-2 smart contracts are presented as a faster computer, but without tackling the lack of a mature ecosystem, their usefulness is rather limited.

Cartesi, besides computational scalability, extends what one can do without thinking by bringing decades of accumulated computer science knowledge into the blockchain.

Running mainstream tools, libraries, operating systems, and programming languages has another vital consequence: it lowers the entry barrier for non-blockchain developers. In this sense, Cartesi gives developers the resources to create intricate DApps in a much more accessible way. We believe that by leveraging more developers to build DApps on a computer that offers both computational scalability and a mature ecosystem, we will unleash the true potential of blockchains.

Previously, we’ve written how Cartesi addresses computational scalability with our on-chain components. The ideas detailed there are crucial for understanding this article. Here, we’ll focus on the off-chain components, and how to solve the lack of a mature ecosystem for smart contracts. We’ll go through the reasoning behind the core of Cartesi, and how it enables running things like Linux and all of its toolchains inside Ethereum.

Cartesi Machine

The Cartesi Machine is the computer we’ve designed and built to enable extending the number of operations one can perform without giving them thought. To this end, the underlying machine architecture had to be supported by modern toolchains and have an extensive software infrastructure. The implementation also had to be transparent and auditable, which required the architecture to be open source and relatively simple. With all those characteristics in mind, RISC-V was the perfect architecture for our machine.

The RISC-V project was born at UC Berkeley and quickly gained traction, now being supported by a vibrant community of developers. It is distant from a toy architecture: RISC-V supports direct native hardware implementation and is able to run a wide variety of software infrastructures, such as the Linux kernel, the GNU toolchain, GCC, and LLVM.

In our marketing campaign (and in the above paragraph), we often mention the possibility of running Linux. However, RISC-V is not restricted to Linux: it is compatible with other operating systems that may be interesting for blockchain applications. A cool example is the seL4, an open-source security-focused kernel that has end-to-end proof of implementation correctness.

Other important software that runs on RISC-V is various compilers and interpreters. This enables writing software using modern programming languages along with their entire ecosystem. Programmers won’t have to reinvent the wheel in Solidity: they can just use Python and import NumPy.

The RISC-V ISA can be implemented in a variety of different ways. Our design decisions and modifications are thoroughly explained on our techpaper, which can be found here for more technical readers. There are two main characteristics, however, that should be highlighted: the machine is deterministic and its entire state can be summarized by a single hash.

In this context, deterministic means that the complete state for a computation and all the intermediary state changes are fully specified and reproducible. In other words, giving a particular input to a particular Cartesi Machine will always produce the same outputs and state changes.

The Cartesi machine runs off-chain. But to be useful, its results must be provable on-chain. This is where these two characteristics become important: the goal is to transpose this complex and powerful machine to the limited environment of the blockchain.

Because of its deterministic nature, once the machine and its inputs are agreed upon, two honest machines will always yield the same result. The system consists of interested parties running the same, previously agreed upon Cartesi machine outside the blockchain, and once completed, executing its side-effects to the blockchain.

It may seem that a dishonest adversary may try to fool the blockchain by claiming an untrue side-effect that benefits them. However, anyone interested in the computation has the ability to quickly notice the shady behavior, and use the blockchain to punish the bad actor and enforce the correct result. Through this fraud detection mechanism, we can run the Cartesi machine outside the blockchain and use its result safely inside the blockchain. This way, programmers can now code previously impossible DApps using their preferred programming language.

How can the blockchain do this? We have developed an arbitration system composed of many smart contracts. It offers users the ability to run interactive disputes, also known as verification games, to navigate the entire off-chain computation and detect a single RISC-V instruction in which fraudulent behavior took place. This instruction is then run on our matching blockchain RISC-V implementation. Yes, we coded a full RISC-V implementation in Solidity. If you want to learn how this machine can be used, check out the Cartesi Computev1 SDK documentation.

Rollups Machine

The rollups machine can be thought of as an ever-moving Cartesi machine. The first version of our Cartesi machine is executed once, representing a single computation. The Rollups machine, on the other hand, exists across time — continuously updating its state as users interact with it.

Users interact with the machine by sending it inputs, as described in detail by the rollups on-chain article. The machines are DApp specific and are in charge of processing inputs, executing the DApp’s logic for each one of them. On every input, the machine wakes up, processes the input — reaching a new state — and goes back to sleep.

New states are not the only side effect of processing an input. Outputs and messages may also be created by the machine for each input. These are used by the DApp to exert influence on layer-1. Outputs are transactions to be executed, and messages are layer-2 events that are logged.

Every once in a while, the Rollups off-chain machine publishes to the blockchain, a hash that summarizes its current state, and all new outputs and messages. This happens at the end of every epoch, as discussed in the on-chain article.

This hash is subjected to a similar dispute mechanism explained in the previous section. The main difference is that the checkpoint now summarizes a combination of things — creating the necessity of an extra arbitration step to figuring out where the fraudulent behavior actually took place.

In conclusion, the rollups rely on the blockchain for its source of truth and data availability, and rely on the Cartesi machine for computation: the input’s trustworthiness is secured by the blockchain’s consensus, and the output’s trustworthiness is secured by Cartesi’s fraud detection mechanism. As such, we’re able to leverage the power of the Cartesi machine to trustlessly execute DApps that were once impossible.

Infrastructure

Alongside this article, we are publishing the code of the first version of an important part of our rollups infrastructure: the piece that connects the on-chain code with the rollups machine described above.

The Rollups machine and the smart contracts live in fundamentally different environments. This creates the need for a middleware that manages and controls the communication between the blockchain and the machine.

As such, the middleware is responsible for first reading data from our smart contracts, then sending them to the machine to be processed, and finally publishing their results back to the blockchain. To this end, our middleware uses our previously released State Fold and Transaction Manager.

The middleware can be used by anyone who’s interested in the rollups state of affairs. We divide interested users into two roles, which run different types of nodes: readers and validators. Reader nodes are only interested in advancing their off-chain machine. They consume information from the blockchain but do not bother to enforce state updates, trusting that validators will ensure the validity of all on-chain state updates. Validators, on the other hand, have more responsibility: they not only watch the blockchain but also fight to ensure that the blockchain won’t accept that which didn’t happen.

The smart contracts and the middleware can be found on our Cartesi Compute v2 GitHub page.

Check them out, we’d love your feedback, as always we’d love for anyone who is interested in learning more or building with our Rollups to join the team on our Discord server

About Cartesi

Cartesi is a multi-chain layer-2 infrastructure that allows any software developer to create smart contracts with mainstream software tools and languages they are used to while achieving massive scalability and low costs. Cartesi combines a groundbreaking virtual machine, optimistic rollups, and side-chains to revolutionize the way developers create blockchain applications.

--

--