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

Merged
merged 83 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 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
a313bc0
Feat: add "Using Stylus CLI" draft
anegg0 Nov 20, 2024
3de1c1b
feat: add command table
anegg0 Nov 20, 2024
1a8023a
feat: Draft CLI article
anegg0 Nov 21, 2024
39b80e1
fix: reformat
anegg0 Nov 22, 2024
5e6c3a1
fix: content re-shuffle
anegg0 Nov 22, 2024
a1e6143
fix: re-format + simplify
anegg0 Nov 22, 2024
fc20392
fix: re-format
anegg0 Nov 22, 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
4d8d51a
fix: re-construct the command table based on code and dog fooding
anegg0 Nov 28, 2024
731b06e
fix: integrated examples in command table
anegg0 Nov 28, 2024
c665e24
Merge branch 'Stylus-V2' into stylus-cargo-stylus
anegg0 Nov 28, 2024
5f5cd78
Update arbitrum-docs/stylus/using-stylus-cli.mdx
anegg0 Nov 28, 2024
43c6031
fix: fix sidebar error
anegg0 Nov 28, 2024
264d7eb
fix: reformat
anegg0 Dec 4, 2024
b5b62bd
Update arbitrum-docs/stylus/using-stylus-cli.mdx
anegg0 Dec 4, 2024
c18a514
Update arbitrum-docs/stylus/using-stylus-cli.mdx
anegg0 Dec 4, 2024
e4c74f0
Update arbitrum-docs/stylus/using-stylus-cli.mdx
anegg0 Dec 4, 2024
520666e
Update arbitrum-docs/stylus/using-stylus-cli.mdx
anegg0 Dec 4, 2024
21a3a5a
Update arbitrum-docs/stylus/using-stylus-cli.mdx
anegg0 Dec 4, 2024
562f0cc
Update arbitrum-docs/stylus/using-stylus-cli.mdx
anegg0 Dec 4, 2024
3ec7e5f
Update arbitrum-docs/stylus/using-stylus-cli.mdx
anegg0 Dec 4, 2024
203a5de
fix: reformat + remove some prereqs + reword intro
anegg0 Dec 4, 2024
fa1efa1
Merge pull request #1846 from OffchainLabs/stylus-cargo-stylus
anegg0 Dec 4, 2024
a38dc6f
updated sidebar to include CLI dropdown + fixes to SBE load script to…
srinjoyc Dec 4, 2024
627c0f3
Update arbitrum-docs/stylus/concepts/how-it-works.md
srinjoyc Dec 4, 2024
b2e91bd
Update arbitrum-docs/stylus/concepts/how-it-works.md
srinjoyc Dec 4, 2024
d577a97
fixed table formatting in CLI overview
srinjoyc Dec 4, 2024
70042df
Fix sidebar generation
hkalodner Dec 4, 2024
cbddd8a
Fix broken links
hkalodner Dec 4, 2024
5ba8cf7
Fix arrow direction for run a dev node
hkalodner Dec 4, 2024
4417c1f
Update arbitrum-docs/stylus/using-stylus-cli.mdx
anegg0 Dec 9, 2024
5ad06ad
Update arbitrum-docs/stylus/concepts/how-it-works.md
srinjoyc Dec 9, 2024
a8b249e
standardized up arrow html element in sidebar for other section links…
srinjoyc Dec 9, 2024
7a2e753
Merge branch 'master' into Stylus-V2
srinjoyc Dec 9, 2024
9791c03
Merge branch 'master' into Stylus-V2
srinjoyc Dec 9, 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
70 changes: 70 additions & 0 deletions arbitrum-docs/stylus/concepts/how-it-works.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
id: how-it-works
title: 'Architecture overview'
sidebar_label: 'Architecture overview'
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: **coding, activation, execution, and proving**.

## Coding

Developers can now write smart contracts in any programming language that compiles to WASM.

:::note
Some high-level languages generate far more performant WASMs than others.
:::

Currently, there is support for Rust, C, and C++. However, the levels of support vary. 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, enabling the deployment of 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 EVM-specific functionalities that smart contract developers use. 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).

## Activation

Starting from a high-level language (such as Rust, C, or C++), the first compilation stage happens 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 an activation process, WASM gets lowered to a node's native machine code (such as ARM or x86).

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 that user programs execute safely and are 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 activation.

Gas metering is essential for certifying that computational resources are paid for. In Stylus, the unit for measuring cost is called **ink**, which is 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 executing thousands of WASM opcodes could be done in the same amount of 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).

## Execution

Stylus programs execute 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.

EVM contracts continue to execute the same way they were before Stylus. When calling a contract, the difference between an EVM contract and a WASM program is visible via an [EOF](https://notes.ethereum.org/@ipsilon/evm-object-format-overview)-inspired contract header. From there, the contract executes 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 which language the contract is in. Everything is interoperable.

## Proving

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?

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

### One chain, many languages

There are 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 can now use their preferred programming language, which is 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.

### A better EVM

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

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. Deploying cryptography libraries can be done permissionlessly as custom application layer precompiles. Use cases that are impractical in the EVM are now possible in Stylus.

### Opt-in reentrancy

Stylus doesn't just improve on cost and speed. WASM programs are also safer. Reentrancy is a common vulnerability 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.

### Fully interoperable

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/concepts/stylus-gas.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: 'Gas and ink in Stylus'
title: 'Gas metering'
description: 'A conceptual overview of gas and ink, the primitives that Stylus uses to measure the cost of WASM activation, compute, memory, and storage.'
author: rachel-bousfield
sme: rachel-bousfield
Expand Down
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
2 changes: 1 addition & 1 deletion arbitrum-docs/stylus/reference/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ The Stylus Rust SDK is built on top of [Alloy](https://www.paradigm.xyz/2023/06/

The Stylus Rust SDK has been audited in August 2024 at [commit #62bd831](https://github.com/OffchainLabs/stylus-sdk-rs/tree/62bd8318c7f3ab5be954cbc264f85bf2ba3f4b06) by Open Zeppelin which can be viewed [on our audits page](audit-reports.mdx).

This section contains a set of pages that describe a certain aspect of the Stylus Rust SDK, like how to work with [variables](/stylus-by-example/variables.mdx), or what ways are there to [send ether](/stylus-by-example/sending_ether.mdx). Additionally, there's also a page that compiles a set of [advanced features](/stylus/reference/rust-sdk-guide.md) that the Stylus Rust SDK provides.
This section contains a set of pages that describe a certain aspect of the Stylus Rust SDK, like how to work with [variables](/stylus-by-example/basic_examples/variables.mdx), or what ways are there to [send ether](/stylus-by-example/basic_examples/sending_ether.mdx). Additionally, there's also a page that compiles a set of [advanced features](/stylus/reference/rust-sdk-guide.md) that the Stylus Rust SDK provides.

Finally, there's also a [Stylus by example](https://stylus-by-example.org) portal available that provides most of the information included in this section, as well as many different example contracts.
4 changes: 2 additions & 2 deletions arbitrum-docs/stylus/reference/rust-sdk-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Many of the affordances use macros. Though this section details what each does,

## Storage

This section provides extra information about how the Stylus Rust SDK handles storage. You can find more information and basic examples in [Variables](/stylus-by-example/variables.mdx).
This section provides extra information about how the Stylus Rust SDK handles storage. You can find more information and basic examples in [Variables](/stylus-by-example/basic_examples/variables.mdx).

Rust smart contracts may use state that persists across transactions. There’s two primary ways to define storage, depending on if you want to use Rust or Solidity definitions. Both are equivalent, and are up to the developer depending on their needs.

Expand Down Expand Up @@ -226,7 +226,7 @@ The above allows consumers of `Erc20` to choose immutable constants via speciali

## Functions

This section provides extra information about how the Stylus Rust SDK handles functions. You can find more information and basic examples in [Functions](/stylus-by-example/function.mdx), [Bytes in, bytes out programming](/stylus-by-example/bytes_in_bytes_out.mdx), [Inheritance](/stylus-by-example/inheritance.mdx) and [Sending ether](/stylus-by-example/sending_ether.mdx).
This section provides extra information about how the Stylus Rust SDK handles functions. You can find more information and basic examples in [Functions](/stylus-by-example/basic_examples/function.mdx), [Bytes in, bytes out programming](/stylus-by-example/basic_examples/bytes_in_bytes_out.mdx), [Inheritance](/stylus-by-example/basic_examples/inheritance.mdx) and [Sending ether](/stylus-by-example/basic_examples/sending_ether.mdx).

### Pure, View, and Write functions

Expand Down
Loading
Loading