An article to understand the role of Validity Rollups and Cairo VM

Validity Rollups are the most promising way to increase Ethereum throughput in a secure and decentralized manner; zkEVM and Cairo VM (CVM) are the two types of VMs used in Validity Rollups.

**Written by:**StarkWare

Compilation: Bump Man

TL;DR

  • Validity Rollups are the most promising way to increase Ethereum throughput in a secure and decentralized manner; zkEVM and Cairo VM (CVM) are the two types of VMs used in Validity Rollups.
  • zkEVM focuses on Ethereum compatibility at the expense of performance and scalability.
  • The Cairo VM used in Starknet prioritizes performance and scalability over compatibility.

Rollups are a hot topic this year when talking about scaling Ethereum. Among the various types of rollups, we believe that Validity Rollups (VRs), also known as zk-rollups, are the most promising way to increase Ethereum's throughput in a secure and decentralized manner. At the heart of this scaling solution is verifiable computation using proofs of validity. Here's how they work:

Instead of processing every transaction on the Ethereum mainnet, the operator offloads transaction execution to an off-chain environment. This off-chain environment acts as layer 2, meaning the layer that runs on top of Ethereum.

After processing a large number of transactions, layer 2 operators return results to apply to the state of Ethereum, along with proofs of validity to verify the integrity of off-chain execution. This proof guarantees that all transactions in a batch are valid and autonomously verified by the on-chain validator contract. This allows Ethereum to apply the result to its state.

Validity Rollups

*Note: Validity Rollups are often incorrectly called Zero-Knowledge Rollups, but this is not accurate. Most Validity Rollups do not use ZKPs, nor are they used for privacy purposes. Therefore, the term "Validity Rollup" is more accurate. *

off-chain virtual machine

Before moving on, the first question we need to answer is: What is a virtual machine (VM)? Simply put, it's an environment in which programs can run, just like a Mac running the Windows operating system. It transitions between states after performing computations on some inputs. The Ethereum Virtual Machine (EVM) is the VM that runs Ethereum smart contracts.

A zero-knowledge virtual machine (zkVM) is a program execution environment that, together with program output, allows generation of proofs of validity that can be easily verified. This proof of validity proves that the program has been executed correctly. When the term "zkEVM" is used, it generally refers to an aggregation that utilizes the Ethereum Virtual Machine (EVM) and can attest to the execution of the EVM. This terminology can be misleading because the EVM itself does not generate these proofs; instead, the proofs are generated by a separate proof mechanism that starts with the results of the EVM's execution. Also, these proofs are about validity, not privacy, so they are not exactly zero-knowledge proofs. Nevertheless, for the sake of consistency, we will stick to the traditional term "zkEVM" throughout this article.

While all Validity Rollups aim to scale Ethereum with proof-of-validity, they differ in the choice of VMs to execute off-chain transactions. Many Validity Rollups choose to replicate the design of the EVM (hence the term "zkEVM rollups"), attempting to replicate Ethereum on L2 rollups. Starknet uses a new type of VM - the Cairo VM (CVM) - specifically designed to optimize validity proof efficiency.

These two methods have their own advantages and disadvantages, but zkEVM trades performance for Ethereum compatibility, while Cairo VM prioritizes performance over compatibility and scalability.

zkEVM approach

zkEVM is a Validity Rollup whose goal is to fully bring the Ethereum experience to Layer-2 blockchains. It aims to replicate the Ethereum developer environment as a rollup. With zkEVM, developers do not need to change their code or abandon their EVM tools (and smart contracts) when writing smart contracts or porting smart contracts to more scalable solutions.

A major disadvantage of this approach is that it reduces the scaling potential of validity proofs. Since zkEVM is aimed at being compatible with Ethereum, it is slower and more resource intensive. Unlike CVM, EVM was not designed with proof efficiency in mind. This limits the use of optimizations that can improve efficiency and scalability, ultimately affecting the overall performance of the system.

Provability of EVM

The core challenge of the zkEVM approach is rooted in the original blueprint of the EVM - it was not designed to operate in the context of proof-of-validity. As a result, efforts to mirror its functionality fail to unlock the full potential of validity proofs, resulting in suboptimal levels of efficiency. This inefficiency ultimately drags down the overall performance of the system. Compatibility of EVM with validity proofs is hampered by:

The EVM employs a stack-based model, while the Efficiency Proof is more efficient for a register-based model. The stack-based nature of the EVM makes proving the correctness of its execution and providing direct support for its native toolchain more difficult.

The Ethereum storage layout relies heavily on Keccak and a large Merkle Patricia Tree, both of which are bad for validity proofs and impose a large proof burden. For example, Keccak is very fast for the x86 architecture (on which we typically run the EVM), but takes 90k steps to prove (built-in special build). Whereas Pedersen (a zk-friendly hash function) requires 32 steps. Even with recursive compression, using Keccak in zkEVM means a lot of prover resources that are ultimately paid for by the user.

As a result, various zkEVMs are designed to provide different levels of support for Ethereum tools - the more compatible a zkEVM is with Ethereum, the lower its performance. (For more information on zkEVM types, skip to the end of the article.)

Cairo-VM approach

The zkEVM solution puts a lot of development time into "making the EVM work for Validity Rollups", prioritizing compatibility over long-term performance and scalability. There is another option: use a brand new dedicated virtual machine and add support for Ethereum tools on top as an additional layer. This is the approach taken by Starknet, a permissionless Validity Rollup launching in November 2021. Starknet is the first Validity Rollup to offer a general-purpose smart contract platform on a fully composable network.

Starknet uses Cairo-VM (CVM), a high-level language of the same name. Cairo-VM is a VM designed for efficient generation of validity proofs of program execution.

Using Cairo (virtual machine and language), we have:

  1. Proof of effectiveness of optimization - every instruction has a valid algebraic representation

  2. A Rust-like language for writing provable programs

  3. Intermediate representation (Sierra) between high-level Cairo and Cairo assembly (VM instructions), allowing efficient execution of Cairo code

Developing a new language allows one to tailor it to the specific needs it is meant to fulfill, and to equip it with features that satisfy previously unmet needs.

Cairo and coding pluralism

In order to create a proof about the validity of some computation, the computation must first be expressed as a series of mathematical constraints describing the computation. The process can be tricky due to the challenge of optimizing calculations for efficiency and the need for specialized tools.

The Cairo language was originally designed to simplify this task and make it easier to add functionality and complex business logic to StarkEx. Cairo programs are compiled into algebraic machine code -- a sequence of numbers -- which is executed by a fixed VM. With Cairo, the entire complexity of generating mathematical constraints describing computations—a thorny problem of validity proofs—is abstracted away and captured by a fixed set of constraints (fewer than 50 constraints in total). As a result, developers can leverage validity proofs to extend their applications without needing to understand the underlying math and infrastructure, simply by writing code using a syntax they are familiar with.

Starknet is about innovation, and this is reflected in its diverse approach to coding. Cairo's ability to scale optimally with STARKs is not limited to those writing contracts natively in Cairo. Developers can choose the method that works best for them:

Write code natively in Cairo: With the release of Cairo 1.0, developers can now use the ergonomic and safe Rust language, which makes writing program logic easier and less error-prone.

Solidity Compatibility: Solidity developers can write code that can be used by Cairo VM. This approach provides a developer experience similar to Ethereum and makes Solidity smart contracts portable to Starknet. There are two ways to achieve this:

Translating: Translating refers to the process of converting source code written in one programming language into another language. The Nethermind team created the Warp transpiler for transpiling Solidity code to Cairo. Warp makes Solidity smart contracts portable to Starknet, effectively making it a Type 4 zkEVM. It has been used to translate and deploy Uniswap contracts with minimal changes.

zkEVM on Starknet: The Cairo VM can be used to attest to the execution of another VM. Kakarot is a zkEVM written in Cairo that can be used to run Ethereum smart contracts on Starknet. Cairo VM and zkEVM are not competing approaches, we can have both Cairo VM and zkEVM instead of choosing between Cairo VM and zkEVM!

Despite its short existence, Cairo is the fourth most popular smart contract language by TVL and has received over $350 million in funding.

Summarize

zkEVM aims to replicate the Ethereum environment as a rollup and allow developers to use familiar Ethereum tools. However, this approach inhibits the full potential of validity proofs and can be resource intensive.

Cairo VM is designed for validity proof systems without the limitations of EVM. It is backed by a new, secure and ergonomic Rust-inspired programming language called Cairo 1.0, forming a powerful tool aimed at gaining maximum efficiency by scaling Ethereum with STARK proofs.

It's been exciting to see what Cairo achieves each week, and the growth of different options for developers, such as Kakarot zkEVM and Warp. As the Starknet dApp enters production, demonstrating the power of Cairo, we believe it will be used for more ambitious projects in the future.

Thanks to the three avenues for STARK scaling outlined above, and others that will no doubt be made available in the coming months, developers now have unprecedented control over scaling the blockchain.

View Original
The content is for reference only, not a solicitation or offer. No investment, tax, or legal advice provided. See Disclaimer for more risks disclosure.
  • Reward
  • Comment
  • Share
Comment
0/400
No comments