feat(escrow): add contract upgradability protocol and state migration engine (closes #464) - #467
Open
guptakumarranjeet150 wants to merge 1 commit into
Conversation
… 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
|
@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. |
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)
MigrationError,UpgradeProposal, andmigrate_storage_v1_to_v2routine.pub mod migration;.DataKey::StorageVersionto persistent instance storage.upgrade_and_migrate(env, new_wasm_hash, target_version, signers)gated by 2-of-3 multi-sig threshold check.env.deployer().update_current_contract_wasm()for in-place WASM bytecode upgrades.get_storage_version(env)query.DataKey::StorageVersion.upgrade(env, new_wasm_hash, target_version)callable by the authorized main account.get_storage_version(env).Database Layer
contract_upgrade_proposalstable tracking proposal IDs, target WASM hashes, storage versions, collected signatures, and execution state.contract_upgrade_signaturesfor recording administrative threshold signatures.Backend API & Verification Worker
POST /api/v1/admin/contracts/upgradewith Zod validation, admin authentication (requireAdminApiKeyHeader), and 2-of-3 threshold signature checks.GET /api/v1/admin/contracts/proposalsto inspect audit history.upgradeContractWasmhelper invoking Sorobanupgrade_and_migrate.contractGovernanceRoutesunder/api/v1.Shared & Frontend Portal
ContractUpgradeProposalandContractUpgradeSignaturetypes.3. Verification & Testing
test_contract_upgrade_and_state_migration: locks a trade, verifies storage version1, upgrades contract to version2, 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-> PASStest_migrate_storage_v1_to_v2verifying v1 to v2 schema migration.cargo test -p escrow migration::tests::test_migrate_storage_v1_to_v2-> PASS