Overview & Background
Soroban smart contracts support in-place contract code upgrades via the native system call:
env.deployer().update_current_contract_wasm(new_wasm_hash)
Currently, FlowFi's stream_contract contains no upgrade entrypoint or storage migration mechanism. If a critical protocol vulnerability, security patch, or state schema update is needed, the current contract cannot be upgraded in place. Without an upgrade path, migrating active streams would require manual contract deprecation, fund extraction, and redeployment—disrupting ongoing vesting schedules.
Detailed Problem Statement
- Inability to Patch Bugs:
- Discovered edge cases, arithmetic quirks, or Soroban SDK protocol bumps cannot be applied to the existing contract address.
- Permanent Address Invariance:
- Deploying a new contract changes the contract address, breaking all existing integrations, indexers, frontends, and external smart contract integrations.
- Lack of Migration Framework:
- No standardized schema versioning exists in instance storage to handle data schema changes between contract revisions.
Technical Specification & Architecture
1. Upgrade Entrypoint & Access Control
Implement in contracts/stream_contract/src/lib.rs:
pub fn upgrade(env: Env, new_wasm_hash: BytesN<32>) -> Result<(), StreamError> {
let config = storage::load_config(&env).ok_or(StreamError::NotInitialized)?;
config.admin.require_auth();
env.deployer().update_current_contract_wasm(new_wasm_hash.clone());
events::emit_contract_upgraded(&env, &new_wasm_hash);
Ok(())
}
2. State Schema Versioning
Add contract version tracking to instance storage:
#[contracttype]
pub enum DataKey {
// ...
ContractVersion,
}
pub fn get_contract_version(env: Env) -> u32;
pub fn migrate(env: Env, target_version: u32) -> Result<(), StreamError>;
3. Events
Emit ContractUpgraded event containing old_wasm_hash, new_wasm_hash, and ledger timestamp.
Target Files
contracts/stream_contract/src/lib.rs
contracts/stream_contract/src/storage.rs
contracts/stream_contract/src/events.rs
contracts/stream_contract/src/test.rs
Acceptance Criteria
Overview & Background
Soroban smart contracts support in-place contract code upgrades via the native system call:
Currently, FlowFi's
stream_contractcontains no upgrade entrypoint or storage migration mechanism. If a critical protocol vulnerability, security patch, or state schema update is needed, the current contract cannot be upgraded in place. Without an upgrade path, migrating active streams would require manual contract deprecation, fund extraction, and redeployment—disrupting ongoing vesting schedules.Detailed Problem Statement
Technical Specification & Architecture
1. Upgrade Entrypoint & Access Control
Implement in
contracts/stream_contract/src/lib.rs:2. State Schema Versioning
Add contract version tracking to instance storage:
3. Events
Emit
ContractUpgradedevent containingold_wasm_hash,new_wasm_hash, and ledger timestamp.Target Files
contracts/stream_contract/src/lib.rscontracts/stream_contract/src/storage.rscontracts/stream_contract/src/events.rscontracts/stream_contract/src/test.rsAcceptance Criteria
upgradeentrypoint updates the contract WASM hash on the ledger.upgradeormigratestrictly fail with authorization errors.