Skip to content

Commit

Permalink
Merge pull request #2 from dsrvlabs/welldone-migrate
Browse files Browse the repository at this point in the history
feat: apply 0.4.2 version
  • Loading branch information
markjung96 authored Aug 20, 2024
2 parents d99b733 + a2c6039 commit 74e9fb4
Show file tree
Hide file tree
Showing 24 changed files with 1,815 additions and 986 deletions.
1,172 changes: 628 additions & 544 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ resolver = "2"

[workspace.package]
authors = ["Offchain Labs"]
version = "0.4.0"
version = "0.4.2"
edition = "2021"
homepage = "https://arbitrum.io"
license = "MIT OR Apache-2.0"
repository = "https://github.com/OffchainLabs/cargo-stylus"

[workspace.dependencies]
alloy-primitives = "0.7.2"
alloy-json-abi = "0.7.2"
alloy-sol-macro = "0.7.2"
alloy-sol-types = "0.7.2"
alloy-primitives = "0.7.6"
alloy-json-abi = "0.7.6"
alloy-sol-macro = "0.7.6"
alloy-sol-types = "0.7.6"
alloy-ethers-typecast = "0.2.0"
clap = { version = "4.5.4", features = [ "derive", "color" ] }
ethers = "2.0.10"
Expand All @@ -34,4 +34,4 @@ parking_lot = "0.12.1"
sneks = "0.1.2"

# members
cargo-stylus-util = { path = "util", version = "0.4.0" }
cargo-stylus-util = { path = "util", version = "0.4.2" }
69 changes: 28 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Cargo Stylus
# Cargo Stylus

[![linux](https://github.com/OffchainLabs/cargo-stylus/actions/workflows/linux.yml/badge.svg)](https://github.com/OffchainLabs/cargo-stylus/actions/workflows/linux.yml) [![mac](https://github.com/OffchainLabs/cargo-stylus/actions/workflows/mac.yml/badge.svg)](https://github.com/OffchainLabs/cargo-stylus/actions/workflows/mac.yml) [![windows](https://github.com/OffchainLabs/cargo-stylus/actions/workflows/windows.yml/badge.svg)](https://github.com/OffchainLabs/cargo-stylus/actions/workflows/windows.yml) [![lint](https://github.com/OffchainLabs/cargo-stylus/actions/workflows/check.yml/badge.svg)](https://github.com/OffchainLabs/cargo-stylus/actions/workflows/check.yml)

A cargo subcommand for building, verifying, and deploying Arbitrum Stylus WASM programs in Rust.
A cargo subcommand for building, verifying, and deploying Arbitrum Stylus WASM contracts in Rust.

## Quick Start

Expand All @@ -29,16 +29,16 @@ cargo stylus --help
Cargo command for developing Arbitrum Stylus projects
Usage:
Usage:
cargo stylus new
cargo stylus export-abi
cargo stylus check
cargo stylus check
cargo stylus deploy
```

### Overview

The cargo stylus command comes with useful commands such as `new`, `check` and `deploy`, and `export-abi` for developing and deploying Stylus programs to Arbitrum chains. Here's a common workflow:
The cargo stylus command comes with useful commands such as `new`, `check` and `deploy`, and `export-abi` for developing and deploying Stylus contracts to Arbitrum chains. Here's a common workflow:

Start a new Stylus project with

Expand All @@ -54,24 +54,23 @@ You can also use `cargo stylus new --minimal <YOUR_PROJECT_NAME>` to create a mo

All testnet information, including faucets and RPC endpoints can be found [here](https://docs.arbitrum.io/stylus/reference/testnet-information).


### Developing With Stylus

Then, develop your Rust program normally and take advantage of all the features the [stylus-sdk](https://github.com/OffchainLabs/stylus-sdk-rs) has to offer. To check whether or not your program will successfully deploy and activate onchain, use the `cargo stylus check` subcommand:
Then, develop your Rust contract normally and take advantage of all the features the [stylus-sdk](https://github.com/OffchainLabs/stylus-sdk-rs) has to offer. To check whether or not your contract will successfully deploy and activate onchain, use the `cargo stylus check` subcommand:

```
cargo stylus check
```

This command will attempt to verify that your program can be deployed and activated onchain without requiring a transaction by specifying a JSON-RPC endpoint. By default, it will use the public URL of the Stylus testnet as its endpoint. See [here](https://docs.arbitrum.io/stylus/reference/testnet-information) for available testnet RPC URLs. See `cargo stylus check --help` for more options.
This command will attempt to verify that your contract can be deployed and activated onchain without requiring a transaction by specifying a JSON-RPC endpoint. By default, it will use the public URL of the Stylus testnet as its endpoint. See [here](https://docs.arbitrum.io/stylus/reference/testnet-information) for available testnet RPC URLs. See `cargo stylus check --help` for more options.

If the command above fails, you'll see detailed information about why your WASM will be rejected:

```
Reading WASM file at bad-export.wat
Compressed WASM size: 55 B
Stylus checks failed: program predeployment check failed when checking against
ARB_WASM_ADDRESS 0x0000…0071: (code: -32000, message: program activation failed: failed to parse program)
Stylus checks failed: contract predeployment check failed when checking against
ARB_WASM_ADDRESS 0x0000…0071: (code: -32000, message: contract activation failed: failed to parse contract)
Caused by:
binary exports reserved symbol stylus_ink_left
Expand All @@ -80,18 +79,18 @@ Location:
prover/src/binary.rs:493:9, data: None)
```

To read more about what counts as valid vs. invalid user WASM programs, see [VALID_WASM](./check/VALID_WASM.md).
To read more about what counts as valid vs. invalid user WASM contracts, see [VALID_WASM](./check/VALID_WASM.md).

If your program succeeds, you'll see the following message:
If your contract succeeds, you'll see the following message:

```
Finished release [optimized] target(s) in 1.88s
Reading WASM file at hello-stylus/target/wasm32-unknown-unknown/release/hello-stylus.wasm
Compressed WASM size: 3 KB
Program succeeded Stylus onchain activation checks with Stylus version: 1
Contract succeeded Stylus onchain activation checks with Stylus version: 1
```

Once you're ready to deploy your program onchain, you can use the `cargo stylus deploy` subcommand as follows:
Once you're ready to deploy your contract onchain, you can use the `cargo stylus deploy` subcommand as follows:

First, we can estimate the gas required to perform our deployment and activation with:

Expand All @@ -105,7 +104,7 @@ and see:

```
Compressed WASM size: 3 KB
Deploying program to address 0x457b1ba688e9854bdbed2f473f7510c476a3da09
Deploying contract to address 0x457b1ba688e9854bdbed2f473f7510c476a3da09
Estimated gas: 12756792
```

Expand All @@ -120,60 +119,43 @@ and see:

```
Compressed WASM size: 3 KB
Deploying program to address 0x457b1ba688e9854bdbed2f473f7510c476a3da09
Deploying contract to address 0x457b1ba688e9854bdbed2f473f7510c476a3da09
Estimated gas: 12756792
Submitting tx...
Confirmed tx 0x42db…7311, gas used 11657164
Activating program at address 0x457b1ba688e9854bdbed2f473f7510c476a3da09
Activating contract at address 0x457b1ba688e9854bdbed2f473f7510c476a3da09
Estimated gas: 14251759
Submitting tx...
Confirmed tx 0x0bdb…3307, gas used 14204908
```

## Compiling and Checking Stylus Programs
## Compiling and Checking Stylus Contracts

**cargo stylus check**

Instruments a Rust project using Stylus. This command runs compiled WASM code through Stylus instrumentation checks and reports any failures. It **verifies the program can compile onchain** by making an eth_call to a Arbitrum chain RPC endpoint.
Instruments a Rust project using Stylus. This command runs compiled WASM code through Stylus instrumentation checks and reports any failures. It **verifies the contract can compile onchain** by making an eth_call to a Arbitrum chain RPC endpoint.

```
Usage: cargo stylus check [OPTIONS]
```

See `--help` for all available flags and default values.

## Deploying Stylus Programs
## Deploying Stylus Contracts

**cargo stylus deploy**

Instruments a Rust project using Stylus and by outputting its brotli-compressed WASM code. Then, it submits **two transactions** by default: the first **deploys** the WASM program code to an address and the second triggers an **activation onchain**. Developers can choose to split up the deploy and activate steps via this command as desired.
Instruments a Rust project using Stylus and by outputting its brotli-compressed WASM code. Then, it submits **two transactions** by default: the first **deploys** the WASM contract code to an address and the second triggers an **activation onchain**. Developers can choose to split up the deploy and activate steps via this command as desired.

```
Usage: cargo stylus deploy [OPTIONS]
```

See `--help` for all available flags and default values.

## Verifying Stylus Programs

**cargo stylus verify**

Verifies that a deployed smart contract is identical to that produced by the
current project. Since Stylus smart contracts include a hash of all project
files, this additionally verifies that code comments and other files are
identical. To ensure build reproducibility, if a program is to be verified,
it should be both deployed and verified using `cargo stylus reproducible`.

See `--help` for all available flags and default values.

## Reproducibly Deploying and Verifying

**cargo stylus reproducible**
## Verifying Stylus Contracts

Runs a `cargo stylus` command in a Docker container to ensure build
reproducibility.

See `--help` for all available flags and default values.
See [here](https://hackmd.io/bpeMnrzbSvO4mohhvkrKqw)

## Deploying Non-Rust WASM Projects

Expand Down Expand Up @@ -209,9 +191,14 @@ cargo stylus export-abi
## Optimizing Binary Sizes
<<<<<<< HEAD
Brotli-compressed, Stylus program WASM binaries must fit within the **24Kb** [code-size limit](https://ethereum.org/en/developers/tutorials/downsizing-contracts-to-fight-the-contract-size-limit/) of Ethereum smart contracts. By default, the `cargo stylus check` will attempt to compile a Rust program into WASM with reasonable optimizations and verify its compressed size fits within the limit. However, there are additional options available in case a program exceeds the 24Kb limit from using default settings. Deploying smaller binaries onchain is cheaper and better for the overall network, as deployed WASM programs will exist on the Arbitrum chain's storage forever.
=======
Brotli-compressed, Stylus contract WASM binaries must fit within the **24Kb** [code-size limit](https://ethereum.org/en/developers/tutorials/downsizing-contracts-to-fight-the-contract-size-limit/) of Ethereum smart contracts. By default, the `cargo stylus check` will attempt to compile a Rust contract into WASM with reasonable optimizations and verify its compressed size fits within the limit. However, there are additional options available in case a contract exceeds the 24Kb limit from using default settings. Deploying smaller binaries onchain is cheaper and better for the overall network, as deployed WASM contracts will exist on the Arbitrum chain's storage forever.
> > > > > > > main
We recommend optimizing your Stylus program's sizes to smaller sizes, but keep in mind the safety tradeoffs of using some of the more advanced optimizations. However, some small programs when compiled to much smaller sizes can suffer performance penalties.
We recommend optimizing your Stylus contract's sizes to smaller sizes, but keep in mind the safety tradeoffs of using some of the more advanced optimizations. However, some small contracts when compiled to much smaller sizes can suffer performance penalties.
For a deep-dive into the different options for optimizing binary sizes using cargo stylus, see [OPTIMIZING_BINARIES.md](./check/OPTIMIZING_BINARIES.md).
Expand Down
5 changes: 5 additions & 0 deletions check/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ tokio.workspace = true
wasmer = "3.1.0"
glob = "0.3.1"
tempfile = "3.10.1"
wasmparser = "0.213.0"
wasm-encoder = "0.213.0"
wasm-gen = "0.1.4"
toml = "0.8.14"
sys-info = "0.9.1"
7 changes: 0 additions & 7 deletions check/Dockerfile

This file was deleted.

4 changes: 2 additions & 2 deletions check/OPTIMIZING_BINARIES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Optimizing Stylus Program WASM Binaries
# Optimizing Stylus Contract WASM Binaries

WASM programs need to be small to be deployed onchain. Stylus applies [brotli compression](https://github.com/google/brotli), which empirically reduces the footprint of common Rust WASMs by over 50%, the Stylus runtime obeys the EVM contract size limit of 24KB. This means that, after compression, **all WASMs must not exceed 24KB**.
WASM contracts need to be small to be deployed onchain. Stylus applies [brotli compression](https://github.com/google/brotli), which empirically reduces the footprint of common Rust WASMs by over 50%, the Stylus runtime obeys the EVM contract size limit of 24KB. This means that, after compression, **all WASMs must not exceed 24KB**.

**Uncompressed WASM** files also have an enforced limit of **128Kb**.

Expand Down
8 changes: 4 additions & 4 deletions check/VALID_WASM.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Invalid Stylus WASM Programs
# Invalid Stylus WASM Contracts

This document explains the limitations of Stylus WASM programs and why certain programs might fail `cargo stylus check`. Stylus programs are bound by similar rules to Ethereum smart contracts when it comes to bounded execution, bounded memory use, and determinism.
This document explains the limitations of Stylus WASM contracts and why certain contracts might fail `cargo stylus check`. Stylus contracts are bound by similar rules to Ethereum smart contracts when it comes to bounded execution, bounded memory use, and determinism.

WASM programs must fit within the **24Kb** code size limit of Arbitrum chains _after_ compression. Uncompressed WASMs must have a size less than **128Kb**.
WASM contracts must fit within the **24Kb** code size limit of Arbitrum chains _after_ compression. Uncompressed WASMs must have a size less than **128Kb**.

While Stylus includes a large portion of available WASM opcodes, not all of them are supported. To see the set of allowed / disallowed opcodes, see [here](https://github.com/OffchainLabs/stylus/blob/stylus/arbitrator/prover/src/wavm.rs#L731).

Expand All @@ -15,4 +15,4 @@ When a user WASM gets "activated" on chain, it goes through a series of checks t
5. Check for **disallowed opcodes**, such as SIMD or other features
6. Disallow WASMs with an enormous amount of **functions and exports**

Stylus programs should use `#[no_std]` to avoid including the Rust standard library and keep code small. Many crates that build without the standard library make for great dependencies to use in Stylus programs, as long as the total, compressed WASM size is within the 24Kb code size limit.
Stylus contracts should use `#[no_std]` to avoid including the Rust standard library and keep code small. Many crates that build without the standard library make for great dependencies to use in Stylus contracts, as long as the total, compressed WASM size is within the 24Kb code size limit.
Loading

0 comments on commit 74e9fb4

Please sign in to comment.