Skip to content

feat: add sliding-window rate limiting to wallet transaction execution #31

Description

@Cjay-Cyber-2

Description — what to implement and the why/impact.

Implement a sliding-window rate limiting policy in the wallet contract (contracts/wallet). Autonomous AI agents executing transactions via wallets need protection against sudden anomalous spikes or runaway loops that could drain funds within a short interval. Adding a sliding-window rate limiter directly into the wallet execution path provides on-chain velocity checks.

Context & Requirements — background, constraints, design references, edge cases;

  • Grounded in contracts/wallet using Soroban ledger timestamps (env.ledger().timestamp()).
  • Must track transaction counts or cumulative values over configured time windows.
  • Must return a deterministic error such as RATE_LIMIT_EXCEEDED when transactions exceed the threshold within the active window.
  • Must optimize storage writes to prune expired window entries and avoid state bloat.

Acceptance Criteria — a checklist ("- [ ] ...") of specific, testable conditions that define "done".

  • Define rate-limit configuration and history storage structures in contracts/wallet.
  • Implement window validation logic that inspects recent ledger timestamps prior to permitting wallet execution.
  • Define and export the RATE_LIMIT_EXCEEDED error constant.
  • Add unit tests simulating rapid transaction attempts and verifying rate-limit enforcement across window boundaries.

Implementation Guidance — likely files/modules to touch and a suggested approach

  • Likely files: contracts/wallet/src/lib.rs, contracts/wallet/src/policy.rs (or wallet transaction handler).
  • Approach: Store timestamps of recent successful transactions in a bounded vector or state map. On each execute call, filter out timestamps older than the window duration and check the count or total against configured limits.

Testing & Validation — how the contributor should prove it works

  • Run cargo test --package astroid-wallet to validate rate-limiting edge cases under simulated ledger time increments.
  • Verify formatting and clippy checks pass cleanly across the workspace.

Submission Guidelines — must open a PR that includes "Closes #"; assignment is required before starting; follow the repo's existing style and conventions.


Wave complexity: Medium

Activity

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions