feat(contracts): add emergency pause mechanism to all four contracts#297
Merged
Leothosine merged 3 commits intoJun 26, 2026
Merged
Conversation
- Add Paused variant to DataKey enum in loyalty_token, payment, order, and restaurant_registry contracts - Add pause_contract() and unpause_contract() admin-only functions to each contract, emitting timestamped ctrl/pause and ctrl/unpause events - Add assert_not_paused_for() guard: non-admin callers are rejected with 'contract is paused'; admin can always operate - Guard all state-mutating public functions in each contract - Add 4 pause-related unit tests per contract (32 total tests all pass) Closes tosirano#288
6 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.
Summary
Implements a circuit-breaker pause mechanism across all four Soroban smart contracts (
loyalty_token,payment,order,restaurant_registry) so that an admin can halt public operations immediately in the event of a discovered vulnerability, without requiring a full contract migration.Implementation Details
The same pattern is applied consistently to all four contracts:
DataKey::Paused— new variant added to each contract'sDataKeyenum, stored as a boolean in instance storage.pause_contract(env, caller)— admin-only function that setsPaused = trueand emits a timestamped(ctrl, pause)event.unpause_contract(env, caller)— admin-only function that setsPaused = falseand emits a timestamped(ctrl, unpause)event.assert_not_paused_for(env, caller)— private guard helper: if the contract is paused and the caller is not the admin, panics with"contract is paused". Admin is always allowed to operate.Guards applied to all state-mutating public functions:
loyalty_token:mint,transfer,approve,transfer_from,burn,burn_frompayment:escrow_payment,release_payment(admin-onlyrefund_paymentis exempt by design)order:place_order,cancel_order(admin-onlyadvance_status,set_statusexempt)restaurant_registry:register_restaurant,update_restaurant,set_activeValidation Results
All 32 tests pass (0 failures):
Each contract has 4 new pause-specific tests covering:
"contract is paused"unpause_contractrestores normal operation for all callersCloses #288