Skip to content

feat(escrow): add contract upgradability protocol and state migration engine (closes #464) - #467

Open
guptakumarranjeet150 wants to merge 1 commit into
Nullifier-Systems:mainfrom
guptakumarranjeet150:feat/issue-464-contract-upgradability-migration-engine
Open

guptakumarranjeet150 wants to merge 1 commit into
Nullifier-Systems:mainfrom
guptakumarranjeet150:feat/issue-464-contract-upgradability-migration-engine

Conversation

@guptakumarranjeet150

Copy link
Copy Markdown

1. Summary & Overview

This PR implements the Soroban Smart Contract Upgradability Protocol & Storage State Migration Engine for Velo, addressing all requirements outlined in #464.

When contract logic must be upgraded to address security vulnerabilities or protocol evolution, updating contract WASM bytecode without an explicit migration engine risks corrupting or invalidating active locked escrow balances. This feature introduces a multi-sig governed in-place upgrade mechanism with storage versioning and state migration routines.


2. Key Changes & Architecture

Smart Contract Layer (Soroban / Rust)

  • ****: Created state migration engine with MigrationError, UpgradeProposal, and migrate_storage_v1_to_v2 routine.
  • ****:
    • Declared pub mod migration;.
    • Added DataKey::StorageVersion to persistent instance storage.
    • Added upgrade_and_migrate(env, new_wasm_hash, target_version, signers) gated by 2-of-3 multi-sig threshold check.
    • Integrated env.deployer().update_current_contract_wasm() for in-place WASM bytecode upgrades.
    • Added get_storage_version(env) query.
  • ****:
    • Added DataKey::StorageVersion.
    • Added upgrade(env, new_wasm_hash, target_version) callable by the authorized main account.
    • Added get_storage_version(env).

Database Layer

  • ****:
    • Created contract_upgrade_proposals table tracking proposal IDs, target WASM hashes, storage versions, collected signatures, and execution state.
    • Created contract_upgrade_signatures for recording administrative threshold signatures.

Backend API & Verification Worker

  • ****:
    • Registered POST /api/v1/admin/contracts/upgrade with Zod validation, admin authentication (requireAdminApiKeyHeader), and 2-of-3 threshold signature checks.
    • Added GET /api/v1/admin/contracts/proposals to inspect audit history.
  • ****:
    • Added upgradeContractWasm helper invoking Soroban upgrade_and_migrate.
  • ****:
    • Background worker that verifies storage keys and schema versions for active escrows following upgrade execution.
  • ****: Registered contractGovernanceRoutes under /api/v1.

Shared & Frontend Portal

  • ****: Exported ContractUpgradeProposal and ContractUpgradeSignature types.
  • ****: Admin dashboard for proposing WASM code upgrades, reviewing code hash diffs, submitting multi-sig signatures, and monitoring storage migration progress.

3. Verification & Testing

  • Rust Contract Upgrade Test ():
    • Added test_contract_upgrade_and_state_migration: locks a trade, verifies storage version 1, upgrades contract to version 2, verifies trade balance remains intact, and verifies trade is successfully claimable post-upgrade.
    • cargo test -p escrow unit_tests::test_contract_upgrade_and_state_migration -> PASS
  • Storage State Migration Test ():
    • Added test_migrate_storage_v1_to_v2 verifying v1 to v2 schema migration.
    • cargo test -p escrow migration::tests::test_migrate_storage_v1_to_v2 -> PASS
  • API Governance Tests ():
    • Rejection on missing admin key (401).
    • Rejection on insufficient signatures (< 2) (400).
    • Rejection on duplicate signers (400).
    • Successful execution on 2-of-3 signatures (200).
  • Worker Tests ():
    • Verification pass and error handling tests.

… engine (closes Nullifier-Systems#464)

- Implement Soroban Smart Contract Upgradability Protocol in contracts/escrow/src/lib.rs and contracts/session-account/src/lib.rs
- Add DataKey::StorageVersion and upgrade_and_migrate with 2-of-3 multisig admin governance
- Create storage state migration engine in contracts/escrow/src/migration.rs
- Add SQL migration 044_add_contract_upgrade_governance.sql for tracking upgrade proposals
- Add backend routes POST /api/v1/admin/contracts/upgrade with signature validation in apps/api/src/routes/contract-governance.ts
- Add contractMigrationWorker for verifying active escrow storage migration
- Add ContractGovernancePortal frontend dashboard in mobile/frontend/src/pages/ContractGovernancePortal.tsx
- Add tests in test.rs and migration.rs verifying locked balances remain intact post-upgrade
@vercel

vercel Bot commented Sep 9, 2026

Copy link
Copy Markdown

@guptakumarranjeet150 is attempting to deploy a commit to the jotelfootball-tech's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

1 participant