Skip to content

[Smart Contracts] Protocol-Wide Emergency Pause & Circuit-Breaker Mechanism #1442

Description

@blurbeast

Overview & Background

Currently, FlowFi allows individual stream senders to pause and resume their own streams. However, there is no protocol-level circuit breaker. In the event of an underlying Stellar asset de-peg, a security vulnerability in an integrated bridge or DEX, an identified contract exploit, or abnormal RPC network disruptions, the protocol admin or governance multisig needs the ability to execute a global emergency pause.


Detailed Problem Statement

  1. Lack of Central Circuit Breaker:
    • The protocol administration cannot halt operations globally during an active exploit or emergency.
  2. Fund Safety Guarantee:
    • While deposits and creations should be haltable, recipient withdrawals of already-vested funds must remain protected to prevent censorship or trapping user capital.

Technical Specification & Architecture

1. Protocol Configuration Extension (types.rs)

#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ProtocolConfig {
    pub admin: Address,
    pub treasury: Address,
    pub fee_rate_bps: u32,
    pub is_protocol_paused: bool,
    pub emergency_guardian: Option<Address>,
}

2. Circuit Breaker Controls

pub fn set_protocol_pause(env: Env, paused: bool) -> Result<(), StreamError> {
    let mut config = storage::load_config(&env).ok_or(StreamError::NotInitialized)?;
    // Admin or emergency guardian can pause; only admin can unpause
    if paused {
        if let Some(ref guardian) = config.emergency_guardian {
            if guardian != &config.admin {
                // guardian or admin authorization
            }
        }
        config.admin.require_auth();
    } else {
        config.admin.require_auth();
    }
    config.is_protocol_paused = paused;
    storage::save_config(&env, &config);
    events::emit_protocol_pause_status(&env, paused);
    Ok(())
}

3. Guard Implementation

  • create_stream, batch_create_streams, create_stream_with_cliff, top_up_stream must check config.is_protocol_paused and revert with StreamError::ProtocolPaused.
  • withdraw remains operational so recipients can access already-vested collateral.

Target Files

  • contracts/stream_contract/src/types.rs
  • contracts/stream_contract/src/lib.rs
  • contracts/stream_contract/src/storage.rs
  • contracts/stream_contract/src/events.rs
  • contracts/stream_contract/src/test.rs

Acceptance Criteria

  • Emergency pause halts all stream creations and top-up operations.
  • Recipient withdrawals remain permitted during emergency pause to uphold user self-custody.
  • Only authorized admin / guardian addresses can toggle pause state.
  • Full suite of unit tests verifying all contract entrypoint behaviors in paused vs unpaused state.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions