Arbitrum Stylus Paradigm Shift.

Esther Oche
9 min readJan 18, 2024

--

What’s Stylus?

Stylus is an upgrade to Arbitrum Nitro that allows smart contracts to be written in languages like Rust, C, and C++. This is important because these languages are more efficient than Solidity, which can lead to faster and cheaper smart contracts. Stylus also makes it possible to use new cryptography libraries and other features that are not possible with Solidity.

Stylus is entirely opt-in. Devs familiar with Solidity can continue to enjoy Arbitrum’s EVM-equivalent experience without any changes. This is because Stylus is entirely additive — a model we call EVM+. Stylus introduces a second, fully compatible virtual machine for executing WebAssembly that coordinates with the EVM to produce state transitions. And since the Stylus SDK uses solidity ABIs, a contract written in one language can call out to any other.

For example, existing Solidity DEXs can — without modifications — list Rust ERC20 tokens, which might call out to C programs to do cryptography. Everything is fully interoperable, so users never have to care about the specific language or implementation details of the contracts they call.

Stylus is an upgrade to Arbitrum Nitro, the tech stack powering Arbitrum One, Arbitrum Nova, and Arbitrum Orbit chains. This upgrade adds a second, coequal virtual machine to the EVM, where EVM contracts continue to behave exactly as they would in Ethereum. We call this paradigm EVM+ since everything is entirely additive and is not replacing the Ethereum Virtual Machine (EVM).

This second virtual machine executes WebAssembly (WASM) rather than EVM bytecode. WASM is a modern binary format popularized by its use in major web standards, browsers, and companies to speed up computation. WASM is built to be fast, portable, and human-readable, and has sandboxed execution environments for security and simplicity. Working with WASM is nothing new for Arbitrum chains. Since the Nitro upgrade, WASM has been a fundamental component of Arbitrum’s fully functioning fraud proofs.

With a WASM VM, any programming language that can compile down to WASM is within the bounds of Stylus. While many popular programming languages can be compiled into WASM, some compilers are more suitable for smart contract development than others, like Rust, C, and C++. Other languages like Go, Sway, Move, and Cairo can also be supported. Languages that include their own runtimes, like Python and Javascript, are harder for Stylus to support, although not impossible. Third-party contribution in the form of libraries for new and existing languages is welcomed!

Compared to using Solidity, WASM programs are much more efficient. There are many reasons for this, including the decades of compiler development for Rust and C. WASM also has a faster runtime than the EVM, resulting in faster execution. Generally, a 10x improvement has been seen for contracts using WASM languages compared to contracts using Solidity.

How is this possible?

Stylus is only possible because of Arbitrum Nitro’s unique fraud-proving technology. When there’s a dispute on an Arbitrum network, Nitro replays the execution of the chain in WASM. Honest Arbitrum validators will then bisect what is disputed until a single invalid step is identified and checked on-chain via a “one-step proof.”

This means Nitro can prove arbitrary WASM deterministically.

If WASM can be proven in general, then the correctness of any program that compiles down to WASM can be proven. This is the key technological leap that makes Stylus possible.

For a detailed overview of Nitro’s technical architecture, see the documentation or the Nitro whitepaper.

Why is Stylus a game-changer?

Traditionally, smart contracts on Ethereum and other blockchains are written in Solidity, a language specifically designed for the EVM. While Solidity has served its purpose well, it comes with limitations. It can be verbose, have security vulnerabilities, and lack the performance of more modern languages.

Arbitrum Stylus addresses these limitations by offering several key advantages:

  • Wider developer pool: By supporting WASM, Stylus opens the door to a vast pool of developers already familiar with popular languages like Rust. This can significantly increase the developer talent pool available for building blockchain applications.
  • Faster and more efficient contracts: WASM programs are generally more efficient than Solidity code, leading to faster transaction execution and lower gas fees. This can be crucial for high-performance applications like decentralized exchanges and gaming platforms.
  • Enhanced security: Rust, in particular, is known for its memory safety features, which can help to prevent certain types of security vulnerabilities in smart contracts.

Gas Price (key feature)

Stylus introduces new pricing models for WASM programs. Intended for high-compute applications, Stylus makes the following more affordable:

  • Compute, which is generally 10–100x cheaper depending on the program. This is primarily due to the efficiency of the WASM runtime relative to the EVM, and the quality of the code produced by Rust, C, and C++ compilers. Another factor that matters is the quality of the code itself. For example, highly optimized and audited C libraries that implement a particular cryptographic operation are usually deployable without modification and perform exceptionally well. The fee reduction may be smaller for highly optimized Solidity that makes heavy use of native precompiles vs an unoptimized Stylus equivalent that doesn’t do the same.
  • Memory, which is 100–500x cheaper due to Stylus’s novel exponential pricing mechanism intended to address Vitalik’s concerns with the EVM’s per-call, quadratic memory pricing policy. For the first time ever, high-memory applications are possible on an EVM-equivalent chain.
  • Storage, for which the Rust SDK promotes better access patterns and type choices. Note that while the underlying SLOAD and SSTORE operations cost as they do in the EVM, the Rust SDK implements an optimal caching policy that minimizes their use. Exact savings depends on the program.
  • VM affordances, including common operations like keccak and reentrancy detection. No longer is it expensive to make safety the default.

There are, however, minor overheads to using Stylus that may matter to your application:

  • The first time a WASM is deployed, it must be activated. This is generally a few million gas, though to avoid testnet DoS, we’ve set it to a fixed 14 million. Note that you do not have to activate future copies of the same program. For example, the same NFT template can be deployed many times without paying this cost more than once. We will soon make the fees paid depend on the program, so that the gas used is based on the complexity of the WASM instead of this very conservative, worst-case estimate.
  • Calling a Stylus program costs 200–2000 gas. We’re working with Wasmer to improve setup costs, but there will likely always be some amount of gas one pays to jump into WASM execution. This means that if a contract does next to nothing, it may be cheaper in Solidity. However if a contract starts doing interesting work, the dynamic fees will quickly make up for this fixed-cost overhead.

Though conservative bounds have been chosen for testnet, all of this is subject to change as pricing models mature and further optimizations are made. Since gas numbers will vary across updates, it may make more sense to clock the time it takes to perform an operation rather than going solely by the numbers reported in receipts.

How does it work?

There are four main steps for bringing a Stylus program to life — coding, compilation, execution, and proving.

Coding

In principle, developers can write smart contracts in any programming language that can be compiled into WASM. In practice, some high-level languages generate far more performant WASMs than others.

Initially, there will be support for Rust, C, and C++. However, the levels of support will differ at first. Rust has rich language support from day one, with an open-source SDK that makes writing smart contracts in Rust as easy as possible. C and C++ are supported off the bat too, which will enable deploying existing contracts in those languages on-chain with minimal modifications.

The Stylus SDK for Rust contains the smart contract development framework and language features most developers will need to use in Stylus. The SDK also makes it possible to perform all of the EVM-specific functionalities that smart contract developers are used to. Check out the Rust SDK Guide and the Crate Docs.

Compilation

Stylus programs are compiled twice. Once from a high-level language (such as Rust, C, or C++) to WASM, and then once more, in a process called activation, from WASM to a node’s native machine code (such as ARM or x86).

The first stage of compilation happens either using the CLI tool provided in the Stylus SDK for Rust or by using any other compiler, such as Clang for C and C++. Once compiled, the WASM is posted on-chain. While the contract’s behavior is now defined, it still cannot be called until after it’s activated.

Activating a Stylus program requires a new precompile, ArbWasm. This precompile produces efficient binary code tailored to a node’s native assembly. During this step, a series of middlewares ensure user programs can be safely executed and deterministically fraud-proven. Instrumentation includes gas metering, depth-checking, memory charging, and more to guarantee all WASM programs are safe for the chain to execute.

Execution

Stylus programs are executed in a fork of Wasmer, the leading WebAssembly runtime, with minimal changes made to optimize their codebase for blockchain-specific use cases. Wasmer executes native code much faster than Geth executes EVM bytecode, contributing to the significant gas savings that Stylus provides.

EVM contracts continue to execute the same way that they did prior to Stylus. When a contract is called, the difference between an EVM contract and a WASM program can be seen via an EOF-inspired contract header. From there, the contract is executed using its corresponding runtime. Contracts written in Solidity and WASM languages can make cross-contract calls to each other, meaning a developer never has to consider what language the contract was written in. Everything is interoperable.

Proving

Nitro has a happy case and a sad case. Most of the time, it’s in a happy case, compiling execution history to native code. In the sad case where there is a dispute between validators, Nitro compiles execution history to WASM to conduct interactive fraud proofs on Ethereum. Stylus is a natural extension to Nitro’s fraud-proving technology, utilizing it to not only bisect over execution history but also any WASM programs deployed by developers.

What can I do?

The Stylus testnet is open to all. A lot of thought has been given to creating the best programming experience possible. However, the work doesn’t stop here. Feedback gained from developers will help drive Stylus to the next level, improving tooling, documentation, and language features. Becoming an early adopter of Stylus is the best way to get familiar with the opportunities it presents.

Many possibilities are enabled because of Stylus, to name a few:

  • Custom pre compiled for alternative signature schemes, such as secp256r1
  • Generative art libraries that consume a bunch of RAM
  • Bringing existing games written in C++ on-chain
  • Compute-heavy AI models

The most exciting part about Stylus is all of the novel use cases that haven’t even been dreamt of in the EVM. This is because none of this was possible, until today.

While many developers will be drawn to the new use cases, rebuilding existing applications in Stylus will also open the door to innovation. dApps have never been faster, cheaper, or safer.

If you’re a developer interested in Stylus, visit the quickstart, join the Discord channel, and start building!

Road Map

Stylus is currently testnet-only and not recommended for production use. This will change as an audit and add additional features is completed.

Arbitrum Orbit L3s may opt into Stylus at any time. Arbitrum One and Arbitrum Nova will upgrade to Stylus should the DAO vote for it.

The Future of Stylus

The introduction of Stylus marks a significant milestone in the evolution of Arbitrum and the broader blockchain ecosystem. Its potential to attract new developers, improve smart contract performance, and enhance security promises to unlock a new wave of innovation in the blockchain space.

As the Stylus ecosystem matures and more tools and libraries become available, we can expect to see even more exciting applications emerge. From high-frequency trading platforms to decentralized social networks, the possibilities are truly limitless.

In conclusion, Arbitrum Stylus is not just a technological upgrade; it represents a paradigm shift in smart contract development. By empowering developers with the freedom to choose their preferred language and leverage the efficiency of WASM, Stylus paves the way for a future of faster, more secure, and more innovative blockchain applications.

Arbitrum is a suite of scaling solutions providing environments with high-throughput, low-cost smart contracts, backed by industry-leading proving technology rooted in Ethereum. Arbitrum has primarily 2 blockchains called Arbitrum One and Arbitrum Nova. The newest product, Arbitrum Orbit, lets you create your own dedicated chain that settles to one of Arbitrum’s Layer 2 (L2) chains: Arbitrum One, Arbitrum Nova, or Arbitrum Goerli. Learn more about Arbitrum here

Resources links:

[1] Arbitrum Stylus

[2] Abitrum Nitro

[3] Arbitrum Nova

[4] Arbitrum Goerli

[5] Arbitrum One

[6] Arbitrum Sepolia

[7] Stylus Testnet

--

--