This implementation addresses the "Circuit Breaker: Mass Milestone Dispute Trigger" issue to protect the DAO treasury from Sybil-Dispute attacks designed to overwhelm the arbitration panel.
If more than 15% of active grants are placed into "Dispute" status within 24 hours, the protocol should halt new grant initializations to prevent coordinated attacks on the arbitration system.
Added new storage keys in circuit_breakers.rs:
DisputeWindowStart: Timestamp when the current 24-hour monitoring window startedDisputeAccumulator: Number of disputes in the current windowActiveGrantsSnapshot: Number of active grants at window startGrantInitializationHalted: Flag indicating if new grant creation is halted
DISPUTE_WINDOW_SECS: 24 hours (86,400 seconds)DISPUTE_THRESHOLD_BPS: 15% (1,500 basis points)
- Records a new dispute in the monitoring window
- Automatically resets the window after 24 hours
- Calculates dispute percentage relative to active grants
- Returns
falseif the 15% threshold is breached (trips the circuit breaker) - Returns
trueif the dispute is recorded normally
- Returns whether the circuit breaker is currently active
- Used to block new grant creation
- Admin-only function to resume grant initialization
- Resets all monitoring counters
- Should only be called after manual investigation
- Returns current monitoring statistics for transparency
- Tuple: (window_start, dispute_count, active_grants_snapshot, halted)
Added check at the beginning of create_grant():
if circuit_breakers::is_grant_initialization_halted(&env) {
return Err(Error::GrantInitializationHalted);
}New function to be called when a grant enters dispute status:
- Verifies the grant exists
- Counts current active grants
- Records the dispute and checks threshold
- Emits events for transparency
Added new error type: GrantInitializationHalted = 19
- Grant is created normally
- Grant enters dispute status through arbitration process
trigger_grant_dispute()is called- Dispute is recorded, threshold checked
- If below 15%, operation continues normally
- Multiple grants rapidly enter dispute status
- When disputes exceed 15% of active grants in 24 hours:
- Circuit breaker trips
GrantInitializationHaltedflag is set- New grant creation is blocked
- Event is emitted for transparency
- Admin investigates the dispute pattern
- If determined to be a false alarm or resolved:
- Admin calls
resume_grant_initialization() - Monitoring window is reset
- Grant creation resumes
- Admin calls
- Monitoring window automatically resets after 24 hours
- Prevents permanent lockout
- Only admin can resume operations
- Requires manual investigation
- Prevents automatic recovery from genuine attacks
- All actions emit events
- Statistics are publicly readable
- Enables community monitoring
- Existing grants continue to function
- Only new grant creation is halted
- Minimizes disruption to legitimate users
Created comprehensive test suite in test_dispute_circuit_breaker.rs:
-
Basic Functionality Test
- Creates grants, triggers disputes
- Verifies threshold detection
- Tests grant creation blocking
-
Interface Integration Test
- Tests through main contract interface
- Verifies statistics reporting
-
Window Reset Test
- Tests automatic window reset after 24 hours
- Verifies counter reset functionality
The dispute monitoring should be integrated with the existing arbitration contract:
// In arbitration contract when dispute is created
pub fn raise_dispute(env: Env, grant_id: u32, ...) -> u32 {
// ... existing dispute logic ...
// Trigger monitoring in grant stream contract
grant_stream_contract.trigger_grant_dispute(grant_id as u64);
// ... rest of dispute logic ...
}The threshold and window duration can be adjusted by modifying the constants:
const DISPUTE_WINDOW_SECS: u64 = 24 * 60 * 60; // 24 hours
const DISPUTE_THRESHOLD_BPS: i128 = 1_500; // 15%Contract events provide real-time monitoring:
dispute_cb: Emitted when threshold is breachedresume_grants: Emitted when admin resumes operations
Off-chain systems should monitor these events for alerting and governance response.
- Dynamic Thresholds: Allow DAO to adjust thresholds via governance
- Graduated Response: Implement graduated restrictions based on dispute percentage
- Whitelist Mechanism: Allow certain trusted creators to bypass restrictions
- Historical Analysis: Store dispute history for pattern analysis
This implementation provides robust protection against Sybil-Dispute attacks while maintaining system transparency and allowing for legitimate dispute resolution. The circuit breaker approach ensures rapid response to potential attacks while minimizing disruption to normal operations.