Skip to content

[FEAT] Implement Emergency Pause (Circuit Breaker) Functionality #24

Description

@Queenode

🟡 Priority: High
Difficulty: Hard
Estimated Effort: 2-3 days
Relevant Files: contracts/src/lib.rs
Labels: enhancement, priority:high, security

Requirements

  1. Pausable State

    • Add DataKey::IsPaused to instance storage (boolean, defaults to false).
    • Add pub fn pause(env: Env) and pub fn unpause(env: Env) functions.
    • Only the Admin can call pause or unpause.
  2. Function Modifiers

    • In contribute(), payout(), add_member(), and reset_cycle(), check IsPaused.
    • If true, panic with "Contract is paused for emergency".
  3. Emergency Withdraw (Escape Hatch)

    • Add pub fn emergency_withdraw(env: Env) callable ONLY when the contract is paused.
    • Only members can call it.
    • It allows a member to withdraw exactly what they have contributed in the current active cycle.
    • This provides a trustless exit if the admin abandons the group or a bug is discovered.
    • It must update their Contributions state and clear HasContributedThisCycle.
  4. State Integrity during Pause

    • The escape hatch must not allow draining more funds than the member put in.
    • If a member uses emergency_withdraw, the CycleMemberCount or CurrentCycleContributions counters must be decremented to keep the pool math valid if the contract is ever unpaused.
  5. Testing

    • Unit test: Admin pauses, contributions fail.
    • Unit test: Admin unpauses, contributions succeed.
    • Unit test: Non-admin tries to pause (panics).
    • Integration test: Pause -> Member executes emergency withdraw -> Verify balance -> Unpause -> Contract math still works for remaining members.
    • Target: >90% coverage on pausable flows.

Metadata

Metadata

Assignees

No one assigned

    Labels

    GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial Campaign | FWC26Campaign: Official Campaign | FWC26

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions