Require a timelock for emergency surplus withdrawal (#968) - #1134
Open
Ada-Girly881 wants to merge 1 commit into
Open
Ada-Girly881 wants to merge 1 commit into
Ada-Girly881 wants to merge 1 commit into
Conversation
|
@Ada-Girly881 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! 🚀 |
Contributor
|
Kindly fix CI |
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.
Summary
withdraw_surpluslet the admin move unallocated surplus funds out of theescrow contract in a single transaction. A compromised admin key could
therefore drain surplus funds instantly, with no observation window — and
the existing two-step admin transfer doesn't help, since the withdrawal
itself was never a multi-step action.
This PR replaces the single-step withdrawal with a propose → execute
timelock flow:
propose_surplus_withdrawal(to, amount, token)— admin-only, validatesthe amount/token/available surplus and records a pending proposal with an
unlock_timeset tonow + delay. Overwrites any existing proposal.execute_surplus_withdrawal()— admin-only, transfers funds to theproposed recipient once
unlock_timehas passed. Re-validates availablesurplus at execution time (not just at proposal time), since balances can
shift while a proposal is pending.
cancel_surplus_withdrawal()— admin-only, discards a pending proposalwithout moving funds.
get_pending_surplus_withdrawal()— returns the outstanding proposal, ifany.
get_surplus_withdrawal_delay()/set_surplus_withdrawal_delay(seconds)— the delay is admin-configurable (defaults to 1 day via
DEFAULT_SURPLUS_WITHDRAWAL_DELAY).New errors
TimelockNotElapsed(26) —execute_surplus_withdrawalcalled beforeunlock_time.NoPendingWithdrawal(27) — cancel/execute called with nothing pending.New events
SurplusWithdrawalProposedSurplusWithdrawalCancelledSurplusWithdrawnEvent(now emitted byexecute_surplus_withdrawalinstead of the removed
withdraw_surplus; payload unchanged)Storage
KEY_SURPLUS_WITHDRAWAL_DELAY— configurable delay in seconds.KEY_PENDING_SURPLUS_WITHDRAWAL— the single outstanding proposal, if any.Acceptance criteria
TimelockNotElapsed)before/exactly at
unlock_time, re-validation of surplus at executiontime, overwrite semantics, and the configurable-delay path)
Files changed
app/onchain/contracts/aid_escrow/src/lib.rs— replaceswithdraw_surpluswith the propose/cancel/execute/delay functions, new error variants, and
new events.
app/onchain/contracts/aid_escrow/src/keys.rs— new storage key constants.app/onchain/contracts/aid_escrow/tests/withdraw_surplus.rs— rewrittenfor the full propose/cancel/execute lifecycle, including boundary timing.
app/onchain/contracts/aid_escrow/tests/events.rs— new event assertionsfor propose/cancel, updated execute-path assertion.
app/onchain/contracts/aid_escrow/tests/pause_controls.rs— pause checksnow exercise
propose_surplus_withdrawal.app/onchain/contracts/aid_escrow/tests/property_based_invariants.rs—fuzz harness collapses propose+execute (zero delay in the fixture) to keep
exercising the same accounting invariants.
app/onchain/contracts/aid_escrow/tests/storage_keys.rs,src/keys.rs(test module) — collision tests cover the two new keys.app/onchain/contracts/aid_escrow/tests/error_codes.rs— pins the two newerror codes (and backfills previously-missing distributor codes for
contiguity).
app/onchain/contracts/aid_escrow/README.md,EVENTS.md,STORAGE_KEYS.md— documentation for the new functions, events, and keys.app/backend/src/onchain/utils/soroban-error.mapper.ts— maps the two newcontract error codes.
Compatibility notes
withdraw_surplusis removed; no other code in this repo (backend adapter,frontend, mobile) called it, so this is not a breaking change for any
in-repo caller. The Testnet contract will need to be redeployed to pick up
the new entrypoints.
Closes #968