Arbitrum Stylus: A New Standard for Smart Contract Composability

CN
1 year ago
Arbitrum Stylus is a milestone project aimed at creating a new standard for the composability of smart contracts by unifying the execution environment of EVM and WASM.

Written by: Rachel Bousfield, Jay Yu

Translated by: DeepTech TechFlow

Note: This article is from the Stanford Blockchain Review, and DeepTech TechFlow is a partner of the Stanford Blockchain Review and has exclusive authorization for translation and reprinting.

Introduction

From processing bytecode on Etherscan to guarding against various code vulnerabilities in Solidity, the EVM technology stack for blockchain development is significantly different from the Web2 technology stack familiar to many developers (such as Rust, C++, or Python), creating a "gap" between the Solidity-EVM technology stack and mainstream languages. With the continuous development of the blockchain field, there is an urgent need to bridge this developer gap and achieve more composable Web3 development.

In this article, we will introduce Offchain Labs' latest project Arbitrum Stylus, which made its debut at the Blockchain Applications Stanford Summit (BASS) during the Stanford Blockchain Week. Arbitrum Stylus is a milestone project aimed at creating a new standard for the composability of smart contracts by unifying the execution environment of EVM and WASM. First, we will discuss some of the motivations behind the project, then delve into some implementation details, and finally discuss the project's impact in the Web3 space.

Motivation Behind Arbitrum Stylus

The development of Arbitrum Stylus aims to address two key issues in blockchain development: (1) the accessibility of blockchain development, and (2) the efficiency of smart contract execution.

Simplifying Blockchain Development

According to the Electric Capital Developer Report, there are currently about 20,000 monthly active blockchain developers. Although this number has grown significantly in recent years, it still lags far behind the millions (or even tens of millions) of developers in mainstream general-purpose languages such as Rust or C++. As the blockchain field continues to evolve, there is a need to simplify the process of attracting millions of new smart contract developers.

One of the best ways to achieve this is to integrate the smart contract development process with existing mainstream languages such as Rust or C++. Many non-EVM ecosystems, such as Solana and Cosmos, have adopted this approach, with Rust becoming the de facto smart contract language for these ecosystems. However, so far, the EVM ecosystem has mainly relied on its own unique programming language, Solidity, for writing smart contracts. However, Arbitrum Stylus aims to change this by allowing blockchain developers to write smart contracts in mainstream languages like Rust and then deploy them on EVM-compatible blockchains.

Improving Smart Contract Execution Efficiency

In recent years, with the popularization of decentralized applications, the demand for on-chain computation has significantly increased, especially on the Ethereum network. The surge in network demand has led to high gas fees. This has further driven innovation in increasing the throughput of public blockchain transactions, with Arbitrum being one of the prominent projects in this area. This includes the flagship project Arbitrum One L2 chain and the Arbitrum Nitro technology stack.

Arbitrum Stylus is a natural extension of all these efforts and is the latest solution in the Arbitrum toolkit. Unlike previous solutions that focus on optimizing efficiency between transactions (such as batch processing transactions through Rollups), Stylus focuses on optimizing the execution level within transactions, especially the execution of each transaction. By allowing contracts to execute in WebAssembly (WASM), Stylus achieves faster contract execution speeds, promises lower gas fees, and makes accessing memory costs 100-500 times cheaper than using EVM.

Stylus: Providing WASM + EVM Composability

WebAssembly and Arbitrum Nitro

To understand why Stylus is more efficient and composable than traditional EVM engines, it is necessary to first understand the role of WebAssembly or WASM. WASM is an assembly language, which means it is essentially machine-readable binary code, as opposed to human-readable languages like Rust or C++. These human-readable languages require a "compiler" to translate them into machine-readable "assembly language" before they can be executed.

Specifically, WASM is an assembly language optimized for web browsers, aimed at improving the execution speed of primarily JavaScript-based web applications. By being a portable, modular, and easy-to-execute assembly language, WASM allows developers to write code snippets directly in various mainstream languages such as Rust or C++.

With the upgrade of Arbitrum's Nitro, as all disputes on-chain are executed in WASM, this means Nitro has an effective fraud system for any dispute on any WASM. Since Arbitrum Nitro is able to provide fraud proofs for any WASM code, it means it can provide fraud proofs for any program compiled into WASM.

Arbitrum Stylus primarily adds a WASM execution engine based on one of the major WASM engines, Wasmer, on top of the WASM fraud proofs inherited from Arbitrum Nitro. With both an execution engine and a fraud proof engine, this allows smart contracts to be fully written, executed, and proven in WASM. Given that many mainstream languages like Rust and C++ can be directly compiled into WASM, this is also how Arbitrum Stylus enables blockchain developers to write, deploy, and execute smart contracts in various mainstream general-purpose languages.

Consistency of EVM + Engine

Arbitrum Stylus provides developers with the additional option of writing contracts in Rust and other WASM-compatible languages without giving up the ability to write and execute smart contracts using Solidity. By having both EVM and WASM as parallel execution engines, Stylus also provides an option for developers to use Solidity in one part of the application and Rust in another.

However, this raises a question: how does Stylus VM manage consistency between two different engines? How does it know when to switch between EVM and WASM VM?

First, Solidity and other EVM-based contracts are compiled into the same bytecode and then executed as in a pure EVM engine. WASM-based smart contracts, such as those written in Rust, will have an additional "header" attached at the beginning of the contract. Therefore, when calling these contracts, the Stylus VM is able to identify which contracts require the EVM engine and which contracts require the WASM engine. This design also takes into account a high degree of interoperability, where contracts written in WASM can call contracts written in Solidity, and vice versa. This is also the primary way in which Stylus differs from other blockchains adopting WASM execution engines: Stylus ensures that WASM contracts are fully composable and interoperable with EVM contracts, allowing backward compatibility and the ability for WASM contracts to tap into EVM liquidity.

Looking at Stylus's EVM and WASM dual engines from another perspective, the blockchain can be seen as a "world state machine" that undergoes specific state transitions based on certain state transactions defined in the EVM. In Ethereum, on-chain state is represented using a Trie structure, which is a tree data structure used for efficient storage and retrieval of data. Both the EVM and WASM engines of Stylus use the same Trie structure to read from and write to the "world state machine." Both engines produce a given state change to update the world state; the only difference is how they compute this state change.

Cost Savings from EVM + Engine Implementation

As mentioned earlier, using a WASM execution engine can achieve significant cost savings by improving execution efficiency. Now let's take a look at how this is achieved. For this, let's consider a simple ADD instruction, such as 2 + 3.

In the EVM, we need to perform the following steps:

  • Pay gas fees, requiring multiple memory table lookups;

  • Consider tracing, even if disabled;

  • Pop two items from the simulated stack;

  • Add them together;

  • Push the result.

We can see that only step 4 actually involves the addition of these two integers, while all other steps are "boilerplate instructions" within the EVM system that incur high gas fees compared to the computation itself.

On the other hand, suppose we use WASM to perform this simple ADD operation. We only need one step:

  1. Execute a single x86 or ARM ADD instruction.

We can see that this is 150 times cheaper than EVM's addition. With all these gas savings, Stylus VM even introduces a new "gas" subunit called "ink," currently defined as 1/10000 of 1 gas, and can even be configured by the owner of the chain.

However, all these gas savings come with a limitation, as gas is required to activate the Stylus VM, currently set at a fixed rate of 114,000,000 gas. Additionally, calling the Stylus program itself currently requires approximately 128-2048 gas. Therefore, activating the WASM environment just to optimize a single ADD operation of two integers may not be economical. However, for memory-intensive smart contracts, all these savings will offset each other, offsetting this "activation cost." For example, a call in the EVM that allocates 3.8 MB of RAM will cost approximately 32 million gas, while in the Stylus WASM VM it only requires 64,000 gas, saving 500 times. A related implication is that memory-intensive applications are simply not feasible on pure EVM, as they quickly run into various gas limitations. However, in the Stylus VM, with the use of the WASM runtime, this becomes entirely feasible, as RAM usage with the WASM runtime is lower.

New Use Cases Unlocked by Using Stylus

  1. Memory-Intensive Applications

As mentioned above, one of the most exciting parts of Arbitrum Stylus is its on-chain enablement of memory-intensive applications. This opens the door to entirely new categories of applications, such as generative AI NFTs, high-frequency trading, and on-chain gaming. In fact, the Stylus VM could be a milestone technology, allowing AI (known for its high memory requirements) to have computational power on-chain and fully interoperate with EVM contracts.

  1. Composability of Alt-VM with EVM Liquidity

Furthermore, the EVM compatibility of Stylus and the ability for WASM-based contracts to interoperate with native Solidity contracts means that these WASM contracts can fully leverage the immense liquidity and user base on the EVM. Recall that we previously mentioned many alternative VMs, such as Solana and Cosmos, use languages that support WASM, such as Rust, to execute their smart contracts. The WASM engine of Stylus means that developers in these alternative VMs can easily migrate their contracts to the EVM ecosystem and immediately leverage EVM's liquidity.

  1. General Libraries, Precompilation, and Debugging Infrastructure

Another advantage of allowing developers to write smart contracts in mainstream languages like Rust and C++ is that developers can leverage a wide range of general libraries that support these mainstream languages, encompassing everything from on-chain computation to cryptographic primitives to file I/O.

More importantly, developers can benefit from the complex tooling infrastructure built for these mainstream languages. This includes not only advanced package managers but also familiar debugging infrastructure such as the GDB toolset in C/C++. All of this has the potential to greatly increase familiarity with Web3 development and make the onboarding process for blockchain development and the EVM stack much simpler.

  1. Bringing On-Chain Computation to IoT for DePIN

With the improved execution efficiency of WASM, the Stylus VM can open the door to integrating on-chain computation with portable devices in the Internet of Things (IoT), including everything from traffic lights to smart refrigerators to smartwatches. While WASM was initially designed for the browser environment, its portable, modular architecture and efficient execution make it an ideal choice for IoT devices that require small and efficient runtimes.

As a result, the WASM VM of Arbitrum Stylus is a natural choice for the growing trend of decentralized physical infrastructure networks (DePIN), which aim to leverage blockchain networks and novel token incentives to maintain physical infrastructure such as WiFi systems and solar batteries. As many aspects of DePIN rely on integrating the blockchain stack with IoT devices, Arbitrum Stylus can be a crucial entry point, allowing these devices to efficiently run WASM-based computations and access EVM liquidity through the Arbitrum ecosystem.

Conclusion

In this article, we have delved into the motivation, implementation, and impact of Arbitrum. By enabling developers to write and deploy smart contracts in various mainstream languages, Stylus makes blockchain development more accessible and efficient, combining mainstream composability with EVM liquidity to unlock a variety of novel applications, especially memory-intensive ones. Therefore, Stylus can be said to define the next generation of composable smart contracts, becoming a platform that blurs the boundaries between web2 and Web3 development, creating a more efficient, integrated, and high-performance blockchain development stack.

免责声明:本文章仅代表作者个人观点,不代表本平台的立场和观点。本文章仅供信息分享,不构成对任何人的任何投资建议。用户与作者之间的任何争议,与本平台无关。如网页中刊载的文章或图片涉及侵权,请提供相关的权利证明和身份证明发送邮件到support@aicoin.com,本平台相关工作人员将会进行核查。

返10%,送$600
链接:https://accounts.suitechsui.blue/zh-CN/register?ref=FRV6ZPAF&return_to=aHR0cHM6Ly93d3cuc3VpdGVjaHN1aS5hY2FkZW15L3poLUNOL2pvaW4_cmVmPUZSVjZaUEFG
Ad
Share To
APP

X

Telegram

Facebook

Reddit

CopyLink