
upgrade-stellar-contracts
Upgrade Stellar/Soroban smart contracts using OpenZeppelin's upgradeable module. Use when users need to: (1) make Soroban contracts upgradeable via native WASM replacement, (2) use Upgradeable or UpgradeableMigratable derive macros, (3) implement atomic upgrade-and-migrate patterns with an Upgrader contract, (4) ensure storage key compatibility across upgrades, or (5) test upgrade paths for Soroban contracts.
- Installs
- 257
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/openzeppelin/openzeppelin-skills --skill upgrade-stellar-contracts- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads upgrade-stellar-contracts automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
Stellar Upgrades
Contents
Soroban Upgrade Model
Soroban contracts are mutable by default. Mutability refers to the ability of a smart contract to modify its own WASM bytecode, altering its function interface, execution logic, or metadata. Soroban provides a built-in, protocol-level mechanism for contract upgrades — no proxy pattern is needed.
A contract can upgrade itself if it is explicitly designed to do so. Conversely, a contract becomes immutable simply by not provisioning any upgrade function. This is fundamentally different from EVM proxy patterns:
| Soroban | EVM (proxy pattern) | Starknet | |
|---|---|---|---|
| Mechanism | Native WASM bytecode replacement | Proxy delegatecalls to implementation contract | replace_class_syscall swaps class hash in-place |
| Proxy contract needed | No — the contract upgrades itself | Yes — a proxy sits in front of the implementation | No — the contract upgrades itself |
| Storage location | Belongs to the contract directly | Lives in the proxy, accessed via delegatecall | Belongs to the contract directly |
| Opt-in to immutability | Don't expose an upgrade function | Don't deploy a proxy | Don't call the syscall |
One advantage of protocol-level upgradeability is a significantly reduced risk surface compared to platforms that require proxy contracts and delegatecall forwarding.
The new implementation only becomes effective after the current invocation completes. This means if migration logic is defined in the new implementation, it cannot execute within the same call as the upgrade. An auxiliary Upgrader contract can wrap both calls to achieve atomicity (see below).
Using the OpenZeppelin Upgradeable Module
OpenZeppelin Stellar Soroban Contracts provides an upgradeable module in the contract-utils package with two main components:
| Component | Use when |
|---|---|
Upgradeable | Only the WASM binary needs to be updated — no storage migration required |
UpgradeableMigratable | The WASM binary and specific storage entries need to be modified during the upgrade |
The recommended way to use these is through derive macros: #[derive(Upgradeable)] and #[derive(UpgradeableMigratable)]. These macros handle the implementation of necessary functions and set the crate version from Cargo.toml as the binary version in WASM metadata, aligning with SEP-49 guidelines.
Upgrade only
Derive Upgradeable on the contract struct, then implement UpgradeableInternal with a single required method:
_require_auth(e: &Env, operator: &Address)— verify the operator is authorized to perform the upgrade (e.g., check against a stored owner address)
The operator parameter is the invoker of the upgrade function and can be used for role-based access control.
Upgrade and migrate
Derive UpgradeableMigratable on the contract struct, then implement UpgradeableMigratableInternal with:
- An associated
MigrationDatatype defining the data passed to the migration function _require_auth(e, operator)— same authorization check as above_migrate(e: &Env, data: &Self::MigrationData)— perform storage modifications using the provided migration data
The derive macro ensures that migration can only be invoked after a successful upgrade, preventing state inconsistencies and storage corruption.
Atomic upgrade and migration
Because the new implementation only takes effect after the current invocation completes, migration logic in the new contract cannot run in the same call as the upgrade. An auxiliary Upgrader contract wraps both calls atomically:
use soroban_sdk::{contract, contractimpl, symbol_short, Address, BytesN, Env, Val};
use stellar_contract_utils::upgradeable::UpgradeableClient;
#[contract]
pub struct Upgrader;
#[contractimpl]
impl Upgrader {
pub fn upgrade_and_migrate(
env: Env,
contract_address: Address,
operator: Address,
wasm_hash: BytesN<32>,
migration_data: soroban_sdk::Vec<Val>,
) {
operator.require_auth();
let contract_client = UpgradeableClient::new(&env, &contract_address);
contract_client.upgrade(&wasm_hash, &operator);
env.invoke_contract::<()>(
&contract_address,
&symbol_short!("migrate"),
migration_data,
);
}
}
Guard upgrade_and_migrate with proper access control (e.g., Ownable from the access package with #[only_owner]).
If a rollback is required, the contract can be upgraded to a newer version where rollback-specific logic is defined and performed as a migration.
Examples: See the
examples/directory of the stellar-contracts repository for full working integration examples of bothUpgradeableandUpgradeableMigratable, including theUpgraderpattern.
Access Control
The upgradeable module deliberately does not embed access control itself. You must define authorization in the _require_auth method of UpgradeableInternal or UpgradeableMigratableInternal. Forgetting this allows anyone to replace your contract's code.
Common access control options:
- Ownable — single owner, simplest pattern (available in the
accesspackage) - AccessControl / RBAC — role-based, finer granularity (available in the
accesspackage) - Multisig or governance — for production contracts managing significant value
Upgrade Safety
Caveats
The framework structures the upgrade flow but does not perform deeper checks:
- The new contract's constructor will not be invoked — any initialization must happen via migration or a separate call
- There is no automatic check that the new contract includes an upgrade mechanism — an upgrade to a contract without one permanently loses upgradeability
- Storage consistency is not verified — the new contract may inadvertently introduce storage mismatches
Storage compatibility
When replacing the WASM binary, existing storage is reinterpreted by the new code. Incompatible changes corrupt state:
- Do not remove or rename existing storage keys
- Do not change the type of values stored under existing keys
- Adding new storage keys is safe
- Soroban storage uses explicit string keys (e.g.,
symbol_short!("OWNER")), so key naming is critical — unlike EVM sequential slots, there is no ordering dependency
Version tracking
The derive macros automatically extract the crate version from Cargo.toml and embed it as the binary version in the WASM metadata, following SEP-49. This enables on-chain version tracking and can be used to coordinate upgrade paths.
Testing upgrade paths
Before upgrading a production contract:
- Deploy V1 on a local Soroban testnet (e.g.,
stellar-cliwith local network) - Write state with V1, upgrade to V2, and verify that all existing state reads correctly
- Verify new functionality works as expected after the upgrade
- Confirm access control — only authorized callers can invoke
upgrade - Check that V2 includes an upgrade mechanism — otherwise upgradeability is permanently lost
- Verify storage key compatibility — ensure no removals, renames, or type changes to existing keys
- Test atomic upgrade-and-migrate using the
Upgraderpattern if migration is needed - Manual review — there is no automated storage compatibility validation for Soroban; use the derive macros for safe upgrade scaffolding and rely on testnet testing
FAQ
What does the upgrade-stellar-contracts skill do?
Upgrade Stellar/Soroban smart contracts using OpenZeppelin's upgradeable module. Use when users need to: (1) make Soroban contracts upgradeable via native WASM replacement, (2) use Upgradeable or UpgradeableMigratable derive macros, (3) implement atomic upgrade-and-migrate patterns with an Upgrader contract, (4) ensure storage key compatibility across upgrades, or (5) test upgrade paths for Soroban contracts.
How do I install upgrade-stellar-contracts?
Run npx skills add https://github.com/openzeppelin/openzeppelin-skills --skill upgrade-stellar-contracts in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/upgrade-stellar-contracts/ (personal) or .claude/skills/upgrade-stellar-contracts/ (project).
Which AI agents can use upgrade-stellar-contracts?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is upgrade-stellar-contracts safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains upgrade-stellar-contracts?
It is published by openzeppelin in openzeppelin/openzeppelin-skills. It has 257 recorded installs.
More from openzeppelin/openzeppelin-skills
setup-solidity-contracts
openzeppelin/openzeppelin-skills
Set up a Solidity smart contract project with OpenZeppelin Contracts. Use when users need to: (1) create a new Hardhat or Foundry project, (2) install OpenZeppelin Contracts dependencies for Solidity, (3) configure remappings for Foundry, or (4) understand Solidity import conventions for OpenZeppelin.
develop-secure-contracts
openzeppelin/openzeppelin-skills
Develop secure smart contracts using OpenZeppelin Contracts libraries. Use when users need to integrate OpenZeppelin library components — including token standards (ERC20, ERC721, ERC1155), access control (Ownable, AccessControl, AccessManager), security primitives (Pausable, ReentrancyGuard), governance (Governor, timelocks), or accounts (multisig, account abstraction) — into existing or new contracts. Covers pattern discovery from library source, CLI contract generators, and library-first integration. Supports Solidity, Cairo, Stylus, Stellar, and Sui Move.
upgrade-solidity-contracts
openzeppelin/openzeppelin-skills
Open the skill to read its SKILL.md instructions.
setup-stellar-contracts
openzeppelin/openzeppelin-skills
Set up a Stellar/Soroban smart contract project with OpenZeppelin Contracts for Stellar. Use when users need to: (1) install Stellar CLI and Rust toolchain for Soroban, (2) create a new Soroban project, (3) add OpenZeppelin Stellar dependencies to Cargo.toml, or (4) understand Soroban import conventions and contract patterns for OpenZeppelin.
setup-stylus-contracts
openzeppelin/openzeppelin-skills
Open the skill to read its SKILL.md instructions.
upgrade-stylus-contracts
openzeppelin/openzeppelin-skills
Open the skill to read its SKILL.md instructions.
Popular testing & qa skills
tdd
mattpocock/skills
Test-driven development. Use when the user wants to build features or fix bugs test-first, mentions "red-green-refactor", or wants integration tests.
grilling
mattpocock/skills
Grill the user relentlessly about a plan, decision, or idea. Use when the user wants to stress-test their thinking, or uses any 'grill' trigger phrases.
migrate-to-shoehorn
mattpocock/skills
Migrate test files from as type assertions to @total-typescript/shoehorn. Use when user mentions shoehorn, wants to replace as in tests, or needs partial test data.
run-train
lllllllama/rigorpilot-skills
Rigor Train skill for deep learning research repositories. Use when a documented or selected training command should be run conservatively for startup verification, short-run verification, full kickoff, or resume, with command, config, seed, log, checkpoint, status, and metric evidence written to standardized trainoutputs/. Do not use for environment setup, exploratory sweeps, speculative idea implementation, or end-to-end orchestration.
test-driven-development
obra/superpowers
Use when implementing any feature or bugfix, before writing implementation code
finishing-a-development-branch
obra/superpowers
Use when implementation is complete, all tests pass, and you need to decide how to integrate the work