feat: Add emergency pause with owner override and unpause timelock (#195) - #525
Open
xion-19 wants to merge 2 commits into
Open
feat: Add emergency pause with owner override and unpause timelock (#195)#525xion-19 wants to merge 2 commits into
xion-19 wants to merge 2 commits into
Conversation
…romptMintLabs#195) Implement emergency pause functionality that allows the contract owner to immediately halt all purchases and transfers in case of vulnerability discovery. Includes a timelock for unpause to prevent instant re-enabling. New functions: - emergency_pause: owner-only, instantly pauses the contract - propose_unpause: owner-only, starts a 24h cooldown before unpause - confirm_unpause: owner-only, confirms unpause after cooldown - cancel_unpause: owner-only, cancels a pending unpause proposal - get_pending_unpause: read-only, returns pending unpause timestamp New error variants: EmergencyAlreadyActive, UnpauseNotProposed, UnpauseCooldownNotElapsed New events: EmergencyPaused, UnpauseProposed, UnpauseConfirmed, UnpauseCancelled Co-Authored-By: Codebuff <noreply@codebuff.com> 🤖 Generated with Codebuff
|
@xion-19 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! 🚀 |
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
Implements emergency pause functionality that allows the contract owner to halt all purchases and transfers in case of vulnerability discovery, with a timelock for unpause.
Resolves #195
Changes
emergency_pause()— Owner-only (#[only_owner]), instantly pauses the contract without requiring multisig approval. This enables fast response during vulnerability discovery.propose_unpause()— Owner-only, starts a 24-hour cooldown before unpause takes effect.confirm_unpause()— Owner-only, executes the unpapse after the cooldown has elapsed.cancel_unpause()— Owner-only, cancels a pending unpause proposal.get_pending_unpause()— Read-only, returns the pending unpapse timestamp (if any).Design
EMERGENCY_UNPAUSE_COOLDOWN_SECS = 86400)set_pause_statusstill worksemergency_pauseclears any pending unpause proposalNew Error Variants
EmergencyAlreadyActive(55) — contract is already pausedUnpauseNotProposed(56) — no pending unpause to confirm/cancelUnpauseCooldownNotElapsed(57) — 24h cooldown has not yet passedNew Events
EmergencyPaused— emitted when owner triggers emergency pauseUnpauseProposed— emitted when unpause is proposed with timestampUnpauseConfirmed— emitted when unpapse is confirmed after cooldownUnpauseCancelled— emitted when a pending unpapse is cancelledTests (11 new tests)
test_emergency_pause_owner_can_pause— owner can pause immediatelytest_emergency_pause_rejects_already_paused— rejects double-pausetest_emergency_pause_blocks_operations— create_prompt blocked when pausedtest_emergency_pause_clears_pending_unpause— re-pause clears pending unpausetest_propose_unpause_requires_paused_state— propose fails when not pausedtest_propose_and_confirm_unpause_with_cooldown— full propose/confirm flow with 24h checktest_confirm_unpause_requires_proposal— confirm fails without proposaltest_cancel_unpause— cancel removes proposal, contract stays pausedtest_cancel_unpause_requires_proposal— cancel fails without proposaltest_emergency_pause_multisig_still_works— existing multisig pause/unpause preservedtest_emergency_pause_get_pending_unpause_none_when_no_proposal— query returns None initiallyFrontend Tests
Frontend tests (vitest) show 35 failures / 74 passed — same results before and after this change. All failures are pre-existing and unrelated to the smart contract changes.
Files Changed
contracts/prompt-hash/src/contract.rs— 5 new methods + 1 constant (+52 lines)contracts/prompt-hash/src/types.rs— 3 Error variants, 1 DataKey, 5 trait declarations (+29 lines)contracts/prompt-hash/src/storage.rs— 3 storage methods for unpapse timelock (+22 lines)contracts/prompt-hash/src/events.rs— 4 new events and emitters (+36 lines)contracts/prompt-hash/src/test.rs— 11 new tests (+220 lines)Total: +359 lines across 5 files