Skip to content

Feat/contract upgradeability#312

Merged
manoahLinks merged 3 commits into
crowdpass-live:mainfrom
Sage-senpai:feat/contract-upgradeability
Apr 28, 2026
Merged

Feat/contract upgradeability#312
manoahLinks merged 3 commits into
crowdpass-live:mainfrom
Sage-senpai:feat/contract-upgradeability

Conversation

@Sage-senpai
Copy link
Copy Markdown
Contributor

feat/contract-upgradeability
Description
Adds a secure, auditable upgrade mechanism to all CrowdPass Soroban contracts, enabling future improvements and bug fixes to land without changing contract addresses or breaking existing storage.

This PR ships two upgrade paths side-by-side:

Fast-path upgrade(new_wasm_hash) — admin-gated, single call, no timelock. Useful for emergency response (live exploit / critical hotfix).
Existing timelocked schedule_upgrade → wait 24h → commit_upgrade — already in the upgradeable lib, untouched and recommended for routine upgrades.
Plus a migrate(target_version) hook for state-shape transformations between versions, with a strict downgrade guard.

The branch carries two commits:

fix(contracts): restore event_manager and resolve SDK v25 build errors — same prerequisite cherry-picked from the #203 branch. The workspace on origin/main doesn't compile because of a botched merge in event_manager plus left-over SDK v22 → v25 migration debt. Without this, no #205 work can be tested.
feat(contracts): implement secure contract upgradeability pattern — the actual #205 work.
If you'd prefer one commit on the merge, squash. If the build-fix lands first via a separate PR (e.g. via the #203 branch), this branch will rebase cleanly onto it.

Type of Change
Bug fix (behavioral)
New feature
Build fix (prerequisite — upstream main was broken before this PR)
Breaking change
Related Issues

What's added
upgradeable lib (contracts/upgradeable/src/lib.rs)
pub fn upgrade(env, new_wasm_hash) — fast-path WASM swap. require_admin() → bump_version() → env.deployer().update_current_contract_wasm(...) → emit UpgradedEvent.
pub fn require_version_increase(env, target_version) — guard that panics with "downgrade not allowed" if target_version <= current_version. Used by every migrate entry point.
pub fn migration_completed(env, target_version) — sets stored version to target_version and emits MigratedEvent. Does not call require_auth() itself — Soroban auth frames forbid double-auth in one call, so the surrounding migrate() does the auth check once.
pub struct MigratedEvent { contract_address, from_version, to_version } — new #[contracttype] event payload for off-chain indexers.
SECURITY NOTE block above upgrade() explicitly flagging the timelock-skip risk so anyone reading the lib understands the trade-off.

Closes #205

The workspace on `origin/main` does not currently compile: a botched
merge replaced `event_manager/src/lib.rs` with a 329-line MultiSig
fragment, and the SDK v22 -> v25 upgrade left several callers using
removed APIs.

- Restore event_manager/src/lib.rs from 097f857 (last-good post-SDK
  version) and add the PoapBadgeMetadata/PoapMintMetadata
  #[contracttype] defs that distribute_poaps references
- ticket_factory + tba_registry: deploy(wasm, args) -> deploy_v2(...)
- ticket_nft: clone Address before storage move so the subsequent
  events.publish still sees `from`/`to`/`owner`
- marketplace: import Symbol; handle the v25 Option return from
  Vec::get; cache recipients.len() before the move into RoyaltyConfig
- dao_governance: drop env.invoker() in favor of admin require_auth();
  cast usize -> u32 for Vec::remove; cast i128 -> u128 for the
  voting-power return type; stub total_supply() (removed in v25)
  returning 0 with a TODO

After this commit `cargo check --workspace` is green; storage
optimization for crowdpass-live#203 follows in a separate commit.
Adds a robust upgrade mechanism to all CrowdPass Soroban contracts,
enabling future improvements and bug fixes without changing contract addresses.

- Add upgrade() function gated behind admin require_auth()
- Implement migrate() hook for state schema transformations
- Store contract version in instance storage for upgrade tracking
- Add version() view function for on-chain version querying
- Include upgrade event emission for transparency and auditability
- Comprehensive tests covering upgrade flow and unauthorized access

Closes crowdpass-live#205
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Apr 28, 2026

@Sage-senpai Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@manoahLinks manoahLinks merged commit 97b6bf8 into crowdpass-live:main Apr 28, 2026
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Soroban Rust: Implement Contract Upgradeability Pattern

2 participants