Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stylus V2 New IA #1804

Open
wants to merge 49 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
73bb2eb
[wip] Added new file for concepts, moved content over from gentle int…
srinjoyc Oct 30, 2024
b7b13fb
Final proposed changes to the introduction and addition of How It Wor…
srinjoyc Nov 4, 2024
2f9eef9
removed concepts section for now, will keep concept page to a single one
srinjoyc Nov 5, 2024
417df46
fixed sidebar and removed (rust) from quickstart label
srinjoyc Nov 5, 2024
0fe43f1
fixed tg link
srinjoyc Nov 5, 2024
236765e
[wip] scaffold new sidebar
srinjoyc Nov 7, 2024
2d37ea3
[wip] scaffold new sidebar
srinjoyc Nov 7, 2024
69d8708
Modified SBE script handler to include applications and added these t…
srinjoyc Nov 15, 2024
446af3f
updated to proper casing for sidebar titles
srinjoyc Nov 15, 2024
c592997
added concepts section and a missed concepts section on gas
srinjoyc Nov 15, 2024
505abef
fix: format
anegg0 Nov 6, 2024
f077a33
Update arbitrum-docs/stylus/stylus-gentle-introduction.md
srinjoyc Nov 6, 2024
511e0c4
Update arbitrum-docs/stylus/stylus-gentle-introduction.md
srinjoyc Nov 6, 2024
a534610
Update arbitrum-docs/stylus/concepts/how-it-works.md
srinjoyc Nov 6, 2024
ac498a8
fix: edit fontmatter: "id" value
anegg0 Nov 6, 2024
aa4fc65
Merge branch 'master' into Stylus-V2
srinjoyc Nov 15, 2024
8af2ca9
formatted the SBE script
srinjoyc Nov 15, 2024
7ed8fdd
small updates to gentle intro + link fixes
srinjoyc Nov 15, 2024
780d8c4
formatted with prettier
srinjoyc Nov 15, 2024
cffe9e7
fix: re-add stylus/how-it-works.md
anegg0 Nov 20, 2024
d49b1de
re-adding Srinjoy content
anegg0 Nov 20, 2024
43deda2
Merge branch 'sync-stylus-v2-with-master' into Stylus-V2
anegg0 Nov 20, 2024
2528e93
fix: format
anegg0 Nov 20, 2024
d612cbb
Update arbitrum-docs/stylus/concepts/how-it-works.md
anegg0 Nov 26, 2024
4fb9f5b
Update arbitrum-docs/stylus/concepts/how-it-works.md
anegg0 Nov 26, 2024
b1055e1
Update arbitrum-docs/stylus/concepts/how-it-works.md
anegg0 Nov 26, 2024
7bafac6
Update arbitrum-docs/stylus/concepts/how-it-works.md
anegg0 Nov 26, 2024
99879c1
Update arbitrum-docs/stylus/concepts/how-it-works.md
anegg0 Nov 26, 2024
a77450a
Update arbitrum-docs/stylus/concepts/how-it-works.md
anegg0 Nov 26, 2024
7cfe020
Update arbitrum-docs/stylus/concepts/how-it-works.md
anegg0 Nov 26, 2024
5939d54
Update arbitrum-docs/stylus/concepts/how-it-works.md
anegg0 Nov 26, 2024
dec2d4f
Update arbitrum-docs/stylus/concepts/how-it-works.md
anegg0 Nov 26, 2024
9c8ee99
Update arbitrum-docs/stylus/concepts/how-it-works.md
anegg0 Nov 26, 2024
5ea85c3
Update arbitrum-docs/stylus/stylus-gentle-introduction.md
anegg0 Nov 26, 2024
43e927b
Update arbitrum-docs/stylus/concepts/how-it-works.md
anegg0 Nov 26, 2024
8fdc52d
Update arbitrum-docs/stylus/concepts/how-it-works.md
anegg0 Nov 26, 2024
d972ba8
Update arbitrum-docs/stylus/concepts/how-it-works.md
anegg0 Nov 26, 2024
d3d3442
Update arbitrum-docs/stylus/concepts/how-it-works.md
anegg0 Nov 26, 2024
6cf2eea
Update arbitrum-docs/stylus/concepts/how-it-works.md
anegg0 Nov 26, 2024
2205e7c
Update arbitrum-docs/stylus/concepts/how-it-works.md
anegg0 Nov 26, 2024
86c0641
Update arbitrum-docs/stylus/concepts/how-it-works.md
anegg0 Nov 26, 2024
4eda897
Update arbitrum-docs/stylus/concepts/how-it-works.md
anegg0 Nov 26, 2024
1e2f902
Update arbitrum-docs/stylus/concepts/how-it-works.md
anegg0 Nov 26, 2024
c8f9a97
Update arbitrum-docs/stylus/concepts/how-it-works.md
anegg0 Nov 26, 2024
7b3feb6
Update arbitrum-docs/stylus/concepts/how-it-works.md
anegg0 Nov 26, 2024
e9356b0
Update arbitrum-docs/stylus/concepts/how-it-works.md
anegg0 Nov 26, 2024
6bb3956
Update arbitrum-docs/stylus/stylus-gentle-introduction.md
anegg0 Nov 26, 2024
3eb4498
Update arbitrum-docs/stylus/stylus-gentle-introduction.md
anegg0 Nov 26, 2024
eadda87
updated sidebar to remove tutorials
srinjoyc Nov 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions arbitrum-docs/stylus/concepts/how-it-works.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
id: how-it-works
title: 'How Stylus works'
sidebar_label: 'How Stylus works'
description: 'Learn what powers Stylus'
author: srinjoyc
SME: srinjoyc
user_story: As an Ethereum developer/project owner, I need to vet the Stylus.
content_type: concept
---

There are four main steps for bringing a Stylus program to life: <b>coding, activation, execution, and proving.</b>
anegg0 marked this conversation as resolved.
Show resolved Hide resolved

### Coding
anegg0 marked this conversation as resolved.
Show resolved Hide resolved

Developers can now write smart contracts in any programming language that compiles to WASM. Note that some high-level languages generate far more performant WASMs than others.
anegg0 marked this conversation as resolved.
Show resolved Hide resolved

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, enabling the deployment of existing contracts in those languages on-chain with minimal modifications.
anegg0 marked this conversation as resolved.
Show resolved Hide resolved

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](https://docs.arbitrum.io/stylus/rust-sdk-guide) and the [Crate Docs](https://docs.rs/stylus-sdk/latest/stylus_sdk/index.html).
anegg0 marked this conversation as resolved.
Show resolved Hide resolved

### Activation
anegg0 marked this conversation as resolved.
Show resolved Hide resolved

Stylus programs are compiled to WASM and then lowered to assembly. Starting from a high-level language (such as Rust, C, or C++), the first compilation stage happens either using the CLI provided in the Stylus SDK for Rust or any other compiler, such as Clang for C and C++. Once compiled, the WASM is posted onchain. Then, in a process called activation, WASM gets lowered to a node's native machine code (such as ARM or x86).
anegg0 marked this conversation as resolved.
Show resolved Hide resolved

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. Stylus contracts can be called only after they've been activated.
anegg0 marked this conversation as resolved.
Show resolved Hide resolved

Gas metering is essential for certifying that computational resources are paid for. In Stylus, the unit for measuring cost is called “ink,” similar to Ethereum's gas but thousands of times smaller. There are two reasons why a new measurement is used: First, WASM execution is so much faster than the EVM that thousands of WASM opcodes could be executed in the same time it takes the EVM to execute one. Second, the conversion rate of ink to gas can change based on future hardware or VM improvements. For a conceptual introduction to Stylus gas and ink, see [gas and ink (Stylus)](https://docs.arbitrum.io/stylus/concepts/stylus-gas).
anegg0 marked this conversation as resolved.
Show resolved Hide resolved

### Execution
anegg0 marked this conversation as resolved.
Show resolved Hide resolved

Stylus programs are executed in a fork of [Wasmer](https://wasmer.io/), the leading WebAssembly runtime, with minimal changes to optimize their codebase for blockchain-specific use cases. Wasmer executes native code much faster than <a data-quicklook-from="geth">Geth</a> executes EVM bytecode, contributing to the significant gas savings that Stylus provides.
anegg0 marked this conversation as resolved.
Show resolved Hide resolved

EVM contracts continue to execute the same way they did before Stylus. When a contract is called, the difference between an EVM contract and a WASM program can be seen via an [EOF](https://notes.ethereum.org/@ipsilon/evm-object-format-overview)-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.
anegg0 marked this conversation as resolved.
Show resolved Hide resolved

### Proving
anegg0 marked this conversation as resolved.
Show resolved Hide resolved

Nitro operates in two modes: a "happy case" where it compiles execution history to native code, and a "sad case" during validator disputes, where it compiles execution history to WASM for interactive fraud proofs on Ethereum. Stylus builds on Nitro's fraud-proving technology, allowing it to verify both execution history and WASM programs deployed by developers.

Stylus is made possible by Nitro’s ability to replay and verify disputes using WASM. Validators bisect disputes until an invalid step is identified and proven on-chain through a [“one-step proof.”](/how-arbitrum-works/fraud-proofs/challenge-manager.mdx#general-bisection-protocol). This deterministic fraud-proving capability ensures the correctness of any arbitrary program compiled to WASM. The combination of WASM's and Nitro's properties enables this technological leap we call Stylus.

For more details on Nitro’s architecture, refer to the [documentation](/how-arbitrum-works/inside-arbitrum-nitro.mdx) or the [Nitro whitepaper](https://github.com/OffchainLabs/nitro/blob/master/docs/Nitro-whitepaper.pdf).

### Why does this matter?
anegg0 marked this conversation as resolved.
Show resolved Hide resolved

Stylus innovates on many levels, with the key ones described here:

#### One chain, many languages
anegg0 marked this conversation as resolved.
Show resolved Hide resolved

There are estimated to be roughly 20k Solidity developers, compared to 3 million Rust developers or 12 million C developers [[1](https://slashdatahq.medium.com/state-of-the-developer-nation-23rd-edition-the-fall-of-web-frameworks-coding-languages-711525e3df3a)]. Developers are now free to use their preferred programming language, all interoperable on any <a data-quicklook-from="arbitrum-chain">Arbitrum chain</a> with Stylus. By onboarding the next million developers, scaling to the next billion users becomes possible.
anegg0 marked this conversation as resolved.
Show resolved Hide resolved

#### A better EVM
anegg0 marked this conversation as resolved.
Show resolved Hide resolved

Stylus' MultiVM brings the best of both worlds. Developers still get all of the benefits of the EVM, including the ecosystem and liquidity, while getting efficiency improvements and access to existing libraries in Rust, C, and C++, all without changing anything about how the EVM works. EVM equivalence is no longer the ceiling; it's the floor.

#### Cheaper execution
anegg0 marked this conversation as resolved.
Show resolved Hide resolved

Stylus is a more efficient execution environment than the EVM, leading directly to gas savings for complex smart contracts. Computation and memory can be significantly cheaper. Cryptography libraries can be permissionlessly deployed as custom application layer precompiles. Use cases that are impractical in the EVM are now possible in Stylus.
anegg0 marked this conversation as resolved.
Show resolved Hide resolved

#### Opt-in reentrancy
anegg0 marked this conversation as resolved.
Show resolved Hide resolved

Stylus doesn't just improve on cost and speed. WASM programs are also safer. Reentrancy is a common vulnerability that developers can only attempt to mitigate in Solidity. Stylus provides cheap reentrancy detection, and using the Rust SDK, reentrancy is disabled by default unless intentionally overridden.
anegg0 marked this conversation as resolved.
Show resolved Hide resolved

#### Fully interoperable
anegg0 marked this conversation as resolved.
Show resolved Hide resolved

Solidity programs and WASM programs are completely composable. If working in Solidity, a developer can call a Rust program or rely on another dependency in a different language. If working in Rust, all Solidity functionalities are accessible out of the box.
2 changes: 1 addition & 1 deletion arbitrum-docs/stylus/recommended-libraries.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
id: recommended-libraries
title: Recommended Libraries
sidebar_label: Recommended libraries
sidebar_label: Use Rust Crates
---

# Recommended libraries
Expand Down
Loading
Loading