Stylus Upgrades
Contents
Stylus Upgrade Model
Stylus contracts run on Arbitrum as WebAssembly (WASM) programs alongside the EVM. They share the same state trie, storage model, and account system as Solidity contracts. Because of this, EVM proxy patterns work identically for Stylus — a Solidity proxy can delegate to a Stylus implementation and vice versa.
| Stylus | Solidity |
|---|
| Proxy mechanism | Same — to implementation contract | to implementation contract |
| Storage layout | fields map to the same EVM slots as equivalent Solidity structs | Sequential slot allocation per Solidity rules |
| EIP standards | ERC-1967 storage slots, ERC-1822 proxiable UUID | Same |
| Context detection | boolean in a unique storage slot (no support) | stored as |
| Initialization | Two-step: constructor sets , then via proxy | Constructor + initializer via proxy |
| Reactivation | WASM contracts must be reactivated every 365 days or after a Stylus protocol upgrade | Not applicable |
Existing Solidity contracts can upgrade to a Stylus (Rust) implementation via proxy patterns. The
macro lays out fields in the EVM state trie identically to Solidity, so storage slots line up when type definitions match.
Proxy Patterns
OpenZeppelin Contracts for Stylus provides three proxy patterns:
| Pattern | Key types | Best for |
|---|
| UUPS | , , | Most projects — upgrade logic in the implementation, lighter proxy |
| Beacon | , | Multiple proxies sharing one implementation — updating the beacon upgrades all proxies atomically |
| Basic Proxy | , | Low-level building block for custom proxy patterns |
UUPS
The implementation contract composes
in its
struct alongside access control (e.g.,
). Integration requires:
- Add (and access control) as fields in the struct
- Call and initialize access control in the constructor
- Expose calling — invoked via proxy after deployment
- Implement — guarded by access control,
upgrade_interface_version
delegating to
- Implement — delegating to
The proxy contract is a thin
with a constructor that takes the implementation address and initialization data, and a
handler that delegates all calls.
Deploy the proxy with
as the initialization call data. Use
or a deployer contract. The initialization data is the ABI-encoded
call:
rust
let data = MyContractAbi::setVersionCall {}.abi_encode();
// Pass `data` as the proxy constructor's second argument at deployment time.
Beacon
Multiple
contracts point to a single
that stores the current implementation address. Updating the beacon upgrades all proxies in one transaction.
Context detection (Stylus-specific)
Stylus does not support the
keyword. Instead of storing
,
uses a
boolean in a unique storage slot:
- The implementation's constructor sets in its own storage.
- When code runs via a proxy (), the proxy's storage does not contain this flag, so it reads as .
- checks this flag to ensure upgrade functions can only be called through the proxy, not directly on the implementation.
also verifies that the ERC-1967 implementation slot is non-zero and that the proxy-stored version matches the implementation's
.
Examples: See the
directory of the
rust-contracts-stylus repository for full working integration examples of UUPS, Beacon, and related patterns.
Access Control
Upgrade functions must be guarded with access control. OpenZeppelin's Stylus contracts do
not embed access control into the upgrade logic itself — you must add it in
:
rust
fn upgrade_to_and_call(&mut self, new_implementation: Address, data: Bytes) -> Result<(), Vec<u8>> {
self.ownable.only_owner()?; // or any access control check
self.uups.upgrade_to_and_call(new_implementation, data)?;
Ok(())
}
Common options:
- Ownable — single owner, simplest pattern
- AccessControl / RBAC — role-based, finer granularity
- Multisig or governance — for production contracts managing significant value
Upgrade Safety
Storage compatibility
Stylus
fields are laid out in the EVM state trie identically to Solidity. The same storage layout rules apply when upgrading:
- Never reorder, remove, or change the type of existing storage fields
- Never insert new fields before existing ones
- Only append new fields at the end of the struct
- ERC-1967 proxy storage slots are in high, standardized locations — they will not collide with implementation storage
One difference from Solidity: nested structs in Stylus
(e.g., composing
,
,
as fields) are laid out with each nested struct starting at its own deterministic slot. This is consistent with regular struct nesting in Solidity, but not with Solidity's inheritance-based flat layout where all inherited variables share a single sequential slot range.
Initialization safety
- The implementation constructor sets and any implementation-only state. It runs once at implementation deployment.
- must be called via the proxy (during deployment or via ) to write the into the proxy's storage.
- If additional initialization is needed (ownership, token supply), expose a protected initialization function and include in it.
- Failing to initialize properly can result in orphaned contracts with no owner, uninitialized state, or denied future upgrades.
UUPS upgrade checks
The UUPS implementation enforces three safety checks:
- Access control — restrict (e.g.,
self.ownable.only_owner()
)
- Proxy context enforcement — reverts if the call is not via
- Proxiable UUID validation — must return the ERC-1967 implementation slot, confirming UUPS compatibility
Reactivation
Stylus WASM contracts must be
reactivated once per year (365 days) or after any Stylus protocol upgrade. Reactivation can be done using
or the
precompile. If a contract is not reactivated, it becomes uncallable. This is orthogonal to proxy upgrades but must be factored into maintenance planning.
Testing upgrade paths
Before upgrading a production contract: