The Radically Simple Guide to: The Power of Linux in Web3
Your go-to guide to understanding the power of Linux onchain.
Written By Cartesi Foundation
Cartesi can help DeFi scale in a new direction. Automated market makers and collateralized lending protocols are getting more experimental with every iteration, but there’s a different kind of growth that’s necessary. What if DeFi markets could count on open, on-chain versions of all the heavyweight analytics and risk management systems that are commonplace in Wall Street?
Start building a DeFi dApp with Cartesi to find out, or keep reading to understand this better.
The ebbs and flows of the DeFi market are unavoidable. Volatility and risk are an inescapable part of any market. But as anyone in TradFi knows, they also become safer and more efficient when participants have better tools at their disposal.
So far, anything ranging from placing simple stop orders to running complex financial analysis has needed to happen in off-chain, server-based, web2 fashion. The Ethereum Virtual Machine doesn’t have the building blocks that would let developers create these applications on-chain so they’re only available through centralized services.
Let’s take a look at logarithms, for example. This is a basic mathematical concept used for building financial analysis tools. Building a program that works with logarithms is fairly simple for regular programmers.
Outside of web3, developers have access to libraries upon libraries of premade code that they can use in their programs for free. They just have to type import math
or import numpy
if they’re working with Python and they’ll have different options for working with logarithms, all of which are battle-tested for bugs and run well.
Someone has already taught the computer how to do this in another program so other developers don’t have to think about it or even see it. All the necessary instructions are combined into a single program that is labeled and can be reused when necessary. In computer science, this is called abstraction.
Doing this on the Ethereum Virtual Machine, however, is a pain. The modules and libraries of premade code for Solidity are very limited. On top of coding the dApp itself, developers also have to reinvent the wheel and teach the Ethereum Virtual Machine how to work with logarithms, step by step.
Then we have the cost of doing this as another problem. Every step for calculating a logarithm on the Ethereum Virtual Machine would consist of a series of instructions called opcodes, and every single one of these costs a specific amount of money. This is why some dApp transactions have greater gas fees than others — you're asking the dApp to do more, and each instruction adds to the bill.
A good way to visualize what this means is to look at the opcode table for the Ethereum Virtual Machine. It breaks down how much gas each instruction costs.
For context, calculating a logarithm would have hundreds of these. It’s safe to say that a full implementation of a typical risk management software would have billions of instructions. We can quickly figure out that it would cost more to use this dApp than what it might save us.
Either way, the Ethereum Virtual Machine has a 30 million gas cap per block, so the limit is also there by design. At a minimum of 3 gas per useful opcode, the largest amount of instructions the Ethereum Virtual Machine can handle is 10 million — and this is shared among the entire network. This limited processing power is another problem we’ve also seen in web3 gaming.
There are very good reasons for these limitations. However, when we combine the need to reinvent the wheel and then the need to pay for every spin, it’s easy to understand why there haven't been more complex DeFi tools built on-chain.
The good news is that there is a workaround to the workarounds. Cartesi lets DeFi developers have access to both more expressivity and more resources.
The math module and numpy library are perfectly accessible on the Cartesi Virtual Machine. Working on it is like working on a traditional Linux setup where all the small steps for calculating a logarithm are already figured out, packaged, and ready to use. We’re back to typing import math
or import numpy
and having all we need.
(This is what we call abstraction scalability, referred to as “content scalability” in this post.)
What’s more, we no longer have that 10 million cap on instructions. The Cartesi Virtual Machine has no hard limit on this, it has proven to handle over 3,617,821,902 instructions in the average interval between Ethereum blocks.
Now developers can work on financial tools that build upon what Wall Street already has instead of reinventing everything from scratch. The best part is that they’re still working in a decentralized, on-chain web3 environment.
The dApps that are built on the Cartesi Virtual Machine are taken back to the Ethereum blockchain, any EVM-compatible chain or L2, using Cartesi Rollups. Technically known as app-specific rollups, these are a way to take all the calculations that happened in the Cartesi Virtual Machine and use the underlying chain to secure them in relatively inexpensive transactions.
This is key. Not only are we working with familiar and battle-tested programs with the Cartesi Virtual Machine, we’re also getting a smaller bill for using them with Cartesi Rollups. Developers have all the advantages of building applications on Linux and all the advantages of having them live on-chain at a small fraction of the cost.
But why is it important to have these applications live on-chain in the first place? It’s not obvious, but there are practical implications, not just philosophical reasons.
A great example of what can be done and why it’s important for DeFi is risk. Right now, there isn’t a way for DeFi lending protocols to have actionable, on-chain information on how good an asset is as collateral or how much of it would be risky to hold. All they have is information on its current price via oracles.
The $61 million USD exploit on Curve Finance shows why this is a big problem. The protocol’s founder had substantial loans backed by the native CRV token that were affected by the exploit. They were left at risk of liquidations that could’ve spread throughout DeFi as a whole, including protocols like Aave and Frax Finance.
However, a spread could’ve been avoided with simple on-chain risk controls.
The generalized version of a problematic pattern here can be summarized like this:
Traditionally, this problem is solved by risk analysis tools that determine how good of a guarantee an asset can be. If they existed on-chain, Naive Finance could check statistical estimations based on the token’s historical price before approving the loan. The protocol would’ve seen through the pump and denied Bob the $100 million.
All of this would happen automatically and on-chain. But if it costs so much time and money to teach the Ethereum Virtual Machine to calculate logarithms, nobody has even bothered with a tool that runs statistics on historical price data — even though there’s grave need for it.
In the Cartesi ecosystem we have a different scenario…
Nucleus is a hackathon winning project that demonstrates how complex financial analysis could be built for DeFi. Besides all the traditional lending protocol features, it’s able to set limits on collaterals based on an analysis of on-chain data represented within Cartesi.
On the surface, Nucleus looks like a regular lending protocol. On the backend, it has all the complex statistical processes needed for risk analysis handled by open-source Python code available in libraries like numpy and others. They were implemented on the Cartesi Virtual Machine and were then taken on-chain via Cartesi’s app-specific rollups.
Having this tool live on-chain also means it can be used and referenced by other DeFi protocols. It could even be designed to be a public good. A project like Nucleus could make DeFi systematically safer.
Moreover, the need for proper risk analysis and management is not just for big TVL lending protocols. Ultimately, this is how any market participant is able to make informed decisions and avoid undesirable behaviors.
The possibilities of DeFi with Cartesi
Nucleus is just one example of how an expressive and inexpensive DeFi dApp can let market participants work with familiar tools on-chain. There are other projects experimenting with these possibilities in the Cartesi ecosystem at varying stages of development:
Other ideas for what could be built include:
The interesting thing about DeFi is that it explores what can be done with money when it becomes programmable. Cartesi ensures that DeFi can expand all these fascinating financial experiments and, at the same time, make use of all the battle-tested tools that have supported traditional finance for decades.
This is the new design space for DeFi. Let us know what dApp you would build by joining the community, participating in the Blue Sky Ideas forum, or joining us on Discord.
You can also check out what other teams are building. Better yet, start building your own DeFi dApp and apply for a Cartesi Community Grant.
And stay tuned for the first dApp based on Cartesi Rollups deployed on-chain…
Join our newsletter to stay up to date on features and releases
Your go-to guide to understanding the power of Linux onchain.
Written By Cartesi Foundation
Exciting news! The Cartesi
Written By CARTESI FOUNDATION
Introducing the Cartesi ecosystem's
Written By Brandon Isaacson
© 2024 The Cartesi Foundation. All rights reserved.