Skip to content

Commit

Permalink
Merge pull request #69 from OffchainLabs/standardize-term-to-contract
Browse files Browse the repository at this point in the history
Standardize Terminology to Contract
  • Loading branch information
joshuacolvin0 authored Aug 12, 2024
2 parents 794221e + f18c28e commit aa05d8f
Show file tree
Hide file tree
Showing 15 changed files with 125 additions and 117 deletions.
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![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 Down Expand Up @@ -38,7 +38,7 @@ Usage:

### 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 @@ -57,21 +57,21 @@ All testnet information, including faucets and RPC endpoints can be found [here]

### 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 +80,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 +105,7 @@ and see:

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

Expand All @@ -120,48 +120,48 @@ 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
## Verifying Stylus Contracts

**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,
identical. To ensure build reproducibility, if a contract is to be verified,
it should be both deployed and verified using `cargo stylus reproducible`.

See `--help` for all available flags and default values.
Expand Down Expand Up @@ -209,9 +209,9 @@ cargo stylus export-abi
## Optimizing Binary Sizes
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.
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
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.
12 changes: 6 additions & 6 deletions check/src/activate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ sol! {
}
}

/// Activates an already deployed Stylus program by address.
pub async fn activate_program(cfg: &ActivateConfig) -> Result<()> {
/// Activates an already deployed Stylus contract by address.
pub async fn activate_contract(cfg: &ActivateConfig) -> Result<()> {
let provider = sys::new_provider(&cfg.common_cfg.endpoint)?;
let chain_id = provider
.get_chainid()
Expand All @@ -54,8 +54,8 @@ pub async fn activate_program(cfg: &ActivateConfig) -> Result<()> {
);
data_fee = bump_data_fee(data_fee, cfg.data_fee_bump_percent);

let program: Address = cfg.address.to_fixed_bytes().into();
let data = ArbWasm::activateProgramCall { program }.abi_encode();
let contract: Address = cfg.address.to_fixed_bytes().into();
let data = ArbWasm::activateProgramCall { program: contract }.abi_encode();
let tx = Eip1559TransactionRequest::new()
.from(client.address())
.to(*ARB_WASM_H160)
Expand All @@ -66,14 +66,14 @@ pub async fn activate_program(cfg: &ActivateConfig) -> Result<()> {
match tx.await? {
Some(receipt) => {
greyln!(
"successfully activated program 0x{} with tx {}",
"successfully activated contract 0x{} with tx {}",
hex::encode(cfg.address),
hex::encode(receipt.transaction_hash).debug_lavender()
);
}
None => {
bail!(
"failed to fetch receipt for program activation {}",
"failed to fetch receipt for contract activation {}",
cfg.address
);
}
Expand Down
18 changes: 9 additions & 9 deletions check/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ sol! {
}
}

pub async fn cache_program(cfg: &CacheConfig) -> Result<()> {
pub async fn cache_contract(cfg: &CacheConfig) -> Result<()> {
let provider = sys::new_provider(&cfg.common_cfg.endpoint)?;
let chain_id = provider
.get_chainid()
Expand All @@ -59,8 +59,8 @@ pub async fn cache_program(cfg: &CacheConfig) -> Result<()> {
let cache_manager = *cache_manager_addrs.last().unwrap();
let cache_manager = H160::from_slice(cache_manager.as_slice());

let program: Address = cfg.address.to_fixed_bytes().into();
let data = CacheManager::placeBidCall { program }.abi_encode();
let contract: Address = cfg.address.to_fixed_bytes().into();
let data = CacheManager::placeBidCall { program: contract }.abi_encode();
let mut tx = Eip1559TransactionRequest::new()
.to(cache_manager)
.data(data);
Expand All @@ -80,13 +80,13 @@ pub async fn cache_program(cfg: &CacheConfig) -> Result<()> {
};
use CacheManager::CacheManagerErrors as C;
match error {
C::AsmTooLarge(_) => bail!("program too large"),
C::AlreadyCached(_) => bail!("program already cached"),
C::AsmTooLarge(_) => bail!("Stylus contract was too large to cache"),
C::AlreadyCached(_) => bail!("Stylus contract is already cached"),
C::BidsArePaused(_) => {
bail!("bidding is currently paused for the Stylus cache manager")
bail!("Bidding is currently paused for the Stylus cache manager")
}
C::BidTooSmall(_) => {
bail!("bid amount {} (wei) too small", cfg.bid.unwrap_or_default())
bail!("Bid amount {} (wei) too small", cfg.bid.unwrap_or_default())
}
}
}
Expand All @@ -106,11 +106,11 @@ pub async fn cache_program(cfg: &CacheConfig) -> Result<()> {
if verbose {
let gas = format_gas(receipt.gas_used.unwrap_or_default());
greyln!(
"Successfully cached program at address: {address} {} {gas}",
"Successfully cached contract at address: {address} {} {gas}",
"with".grey()
);
} else {
greyln!("Successfully cached program at address: {address}");
greyln!("Successfully cached contract at address: {address}");
}
let tx_hash = receipt.transaction_hash.debug_lavender();
greyln!("Sent Stylus cache tx with hash: {tx_hash}");
Expand Down
Loading

0 comments on commit aa05d8f

Please sign in to comment.