Skip to content

Reconcile contract token balance with funded_amount to bound sweep_terminal_dust blast radius #267

@mikewheeleer

Description

@mikewheeleer

Description

sweep_terminal_dust can move up to MAX_DUST_SWEEP_AMOUNT of the funding token to the treasury in terminal states, and the rustdoc warns integrations must keep token balances reconciled with funded_amount so the sweep cannot pull user principal. Add an on-chain invariant check that the sweep never reduces the contract balance below outstanding investor liabilities.

Requirements and context

  • Scoped to the LiquiFact escrow Soroban contract.
  • Before transferring, compute outstanding = funded_amount - (already-distributed) and assert balance - sweep_amt >= outstanding; otherwise trap.
  • Track distributed principal explicitly (new storage key) so the invariant is computable on-chain.
  • Invariant: a dust sweep can never reduce the balance below funds owed to unredeemed investors.
  • Reference ADR-006 and docs/escrow-security-checklist.md.
  • Must be secure, tested, and documented.

Suggested execution

  • Fork the repo and create a branch:
    • git checkout -b security/dust-sweep-liability-floor
  • Implement changes:
    • escrow/src/lib.rs
    • Tests: escrow/src/tests/external_calls.rs
    • Docs: docs/adr/ADR-006-dust-sweep-and-token-safety.md
    • Include rustdoc/NatSpec-style doc comments on public functions
    • Validate security assumptions (auth, overflow, storage TTL, double-spend)

Test and commit

  • Run tests: cargo test
  • Cover edge cases (zero amounts, overflow, unauthorized callers, double-spend, state-machine misuse)
  • Include test output and security notes in the PR

Example commit message

feat(escrow): enforce liability floor on terminal dust sweep

Guidelines

  • Minimum 95% test coverage on new/changed code
  • Clear documentation
  • Timeframe: 96 hours from assignment

Metadata

Metadata

Type

No fields configured for Task.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions