Skip to content

Add Rate Limiting and Throttle Checks #40

@Just-Bamford

Description

@Just-Bamford

��# Issue 23: Add Rate Limiting and Throttle Checks

Problem

No protection against spam. Malicious actor could repeatedly call operations to exhaust resources.

Solution

  • Implement RateLimit { calls_per_minute: u32, calls_per_hour: u32 } config
  • Track call counts per caller in contract state
  • Return RateLimitExceeded error when limit violated
  • Add configurable rate limit policy per operation type

Implementation Tasks

  • Define RateLimit struct
  • Add call count tracking per (caller, operation) pair
  • Implement set_rate_limit(operation, limit) (admin only)
  • Add rate limit check at start of operations
  • Use timestamp bucketing for per-minute and per-hour limits
  • Unit tests: rate limits enforced correctly
  • Test: calls within limit succeed, over limit fail

Note for Contributors

This is a spam and resource protection feature for production robustness. Implement per-caller rate limits to prevent any single address from exhausting contract resources. Support multiple limit types: calls per minute, calls per hour, calls per day. Use timestamp-based bucketing (e.g., bucket = timestamp / 60 for per-minute). Store call counts per caller per bucket. Check limits at the start of expensive operations: record_token, record_vote, record_ballot. Admin can configure rate limits per operation. Default limits should be generous (e.g., 100 calls/minute) to avoid blocking legitimate usage. Return RateLimitExceeded error with cooldown info. Consider gradual backoff instead of hard blocking (out of scope for MVP). Emit rate limit events for monitoring. Ensure rate limit logic is efficient to avoid gas exhaustion in the check itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    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