|
| 1 | +# Multi-Sig Administration Control |
| 2 | + |
| 3 | +> Implements issue **#73 — [Smart Contracts] Implement Multi-Sig administration control for platform upgrades** |
| 4 | +
|
| 5 | +Rare, high-impact protocol configuration changes — whitelisting collateral |
| 6 | +assets ("adding pools"), changing fee tables, linking governance/oracle, and |
| 7 | +moving insurance-fund balances ("withdrawing protocol fees") — used to be a |
| 8 | +single admin key away from being changed. They now require **N-of-M approval** |
| 9 | +from authorised admin wallets via a new `MultiSigAdminContract`. |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +## 1. Located administrative operations (Task 1) |
| 14 | + |
| 15 | +| Contract | Function | Why it's in scope | |
| 16 | +|---|---|---| |
| 17 | +| Lending | `whitelist_asset` | "Adding pools" — this codebase's collateral-asset whitelist | |
| 18 | +| Lending | `set_flash_loan_fee_bps` | "Setting interest rate tables" | |
| 19 | +| Lending | `set_governance` | Linking the DAO — rare, high-impact config | |
| 20 | +| Reputation | `set_oracle` | Authorising who can write credit-score data | |
| 21 | +| Default Mgmt | `add_to_insurance` / `trigger_insurance_payout` | "Withdrawing protocol fees" — literal fund movement | |
| 22 | + |
| 23 | +**Deliberately NOT gated:** `activate_loan`, `record_payment`, `mark_defaulted`, |
| 24 | +`confirm_disbursement`, `record_default`, `add_reputation_event`, |
| 25 | +`freeze_account`/`unfreeze_account`. These are high-frequency, backend-automated |
| 26 | +loan-lifecycle operations (issue #23's cron, #72's liquidation keeper) — gating |
| 27 | +them behind async multi-party approval would break automation entirely, and |
| 28 | +they aren't the kind of operation the issue's examples point at. |
| 29 | + |
| 30 | +## 2. Multi-sig approval before configuration shifts (Task 2) |
| 31 | + |
| 32 | +New [`contracts/multisig_admin`](contracts/multisig_admin/src/lib.rs) contract: |
| 33 | + |
| 34 | +``` |
| 35 | +propose(signer, action) -> id — any signer opens a proposal (counts as their own approval) |
| 36 | +approve(signer, id) — a DISTINCT signer approves, in a SEPARATE transaction |
| 37 | +revoke_approval(signer, id) — withdraw an approval before execution |
| 38 | +cancel(proposer, id) — proposer withdraws their own proposal |
| 39 | +execute(id) — permissionless once approvals >= threshold |
| 40 | +``` |
| 41 | + |
| 42 | +`AdminAction` is a closed, typed enum (not a generic "any call") — every |
| 43 | +protected operation is explicit and independently reviewable: |
| 44 | + |
| 45 | +```rust |
| 46 | +pub enum AdminAction { |
| 47 | + WhitelistAsset(Address, Address), // target, asset |
| 48 | + SetFlashLoanFeeBps(Address, u32), // target, new_fee_bps |
| 49 | + SetGovernance(Address, Address), // target, governance |
| 50 | + SetOracle(Address, Address), // target, oracle |
| 51 | + AddToInsurance(Address, i128), // target, amount |
| 52 | + TriggerInsurancePayout(Address, u32, Address, i128), // target, loan_id, lender, amount |
| 53 | + AddSigner(Address), RemoveSigner(Address), SetThreshold(u32), // self-governance |
| 54 | +} |
| 55 | +``` |
| 56 | + |
| 57 | +`execute` cross-calls the target contract (`whitelist_asset`, etc.) with the |
| 58 | +MultiSigAdmin contract's own address as caller — the same pattern already used |
| 59 | +by the Governance contract (issue #22) to call `set_platform_fee_bps`. |
| 60 | + |
| 61 | +**The bypass is genuinely closed, not just supplemented.** Each target contract |
| 62 | +gains a one-time `set_multisig_admin(admin, multisig)` bootstrap. Once called: |
| 63 | +- The gated functions check `caller == multisig` — **not** `caller == admin`. |
| 64 | +- `set_multisig_admin` panics if called again — the original admin can never |
| 65 | + quietly repoint it at a different multisig they solely control. |
| 66 | +- The only way forward is the multisig's own signer governance |
| 67 | + (`AddSigner`/`RemoveSigner`/`SetThreshold`, themselves propose→approve→execute). |
| 68 | + |
| 69 | +## 3. Integration tests (Task 3) |
| 70 | + |
| 71 | +[`contracts/multisig_admin/src/test.rs`](contracts/multisig_admin/src/test.rs) — |
| 72 | +**27 tests**, using the *real* Lending, Default-Management, and Reputation |
| 73 | +contracts (dev-dependencies), not mocks: |
| 74 | + |
| 75 | +- **The core sequence**: distinct wallets Alice → propose, Bob → approve (separate |
| 76 | + transactions) → anyone executes → asset whitelisted on-chain. |
| 77 | +- **The security property this issue is about**: even the *original* admin can |
| 78 | + no longer call `whitelist_asset` directly once multisig is linked, and can |
| 79 | + never re-link a different multisig. |
| 80 | +- All six protected actions exercised end-to-end (fee change, governance link, |
| 81 | + oracle link, insurance fund add + payout). |
| 82 | +- Approval bookkeeping: non-signers rejected, double-approval rejected, revoke, |
| 83 | + cancel (proposer-only), no double-execute. |
| 84 | +- Signer self-governance: add/remove signer, threshold change, removing a |
| 85 | + signer below the threshold is rejected, and a *raised* threshold correctly |
| 86 | + requires more approvals for subsequent proposals. |
| 87 | + |
| 88 | +```bash |
| 89 | +cd contracts && cargo test -p multisig-admin |
| 90 | +``` |
| 91 | + |
| 92 | +## 4. Automation impact |
| 93 | + |
| 94 | +`trigger_insurance_payout` is now multisig-gated, so the default-management |
| 95 | +cron (issue #23) can no longer execute payouts unattended — it now |
| 96 | +**proposes** the payout (its key must be a registered signer) and a human |
| 97 | +completes the remaining approvals + `execute`. See |
| 98 | +[`lib/scheduler/default-management.ts`](lib/scheduler/default-management.ts). |
| 99 | + |
| 100 | +## 5. Verification |
| 101 | + |
| 102 | +Full workspace: **89/89 tests passing** (13+7+12+30+27, unchanged pre-existing |
| 103 | +suites + 27 new). Clippy clean (`-D warnings`). Both `wasm32-unknown-unknown` |
| 104 | +(CI) and `wasm32v1-none` (deploy) release builds succeed for all 6 contracts. |
| 105 | +Frontend: `tsc --noEmit`, ESLint, and the full vitest suite (80 tests) all pass |
| 106 | +after the TS client + cron updates. |
0 commit comments