Skip to content

Vault: enforce request_id idempotency in deduct to prevent double-metering #350

@greatest0fallt1me

Description

@greatest0fallt1me

Description

CalloraVault::deduct accepts an optional request_id: Symbol and emits it in events, but never persists or checks it, so a backend retry with the same request_id double-charges the consumer. Add a persistent processed-request set so a repeated request_id is rejected, giving safe at-least-once retry semantics.

Requirements and Context

  • Add StorageKey::ProcessedRequest(Symbol) persistent marker set on each successful deduct.
  • Reject deducts whose request_id was already processed (only when request_id is Some).
  • Extend the marker's TTL and document retention; clarify behavior when request_id is None.
  • Must be secure, tested, and documented
  • Should be efficient and easy to review

Suggested Execution

  1. Fork the repo and create a branch
    git checkout -b feature/vault-request-id-idempotency
  2. Implement changes
    • contracts/vault/src/lib.rs — processed-request storage + guard
    • contracts/vault/STORAGE.md — document retention/TTL
  3. Test and commit
    • cargo test -p callora-vault
    • Test duplicate request_id rejected, distinct ids succeed, None unaffected
    • Include test output and notes in the PR

Example commit message

feat: enforce request_id idempotency in vault deduct

Acceptance Criteria

  • Duplicate Some(request_id) deduct rejected
  • Distinct ids and None behave correctly
  • Marker TTL extended and retention documented
  • Tests cover retry semantics

Guidelines

  • .rs under contracts/vault/src/, cargo test, /// docs, minimum 95% line coverage, no unwrap() in prod paths
  • Clear documentation and inline comments
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programenhancementNew feature or improvementsecuritySecurity hardeningsmart-contractSoroban smart-contract worksorobanSoroban SDK / Stellar
No fields configured for Feature.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions