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
Description
sweep_terminal_dustcan move up toMAX_DUST_SWEEP_AMOUNTof the funding token to the treasury in terminal states, and the rustdoc warns integrations must keep token balances reconciled withfunded_amountso 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
escrowSoroban contract.outstanding = funded_amount - (already-distributed)and assertbalance - sweep_amt >= outstanding; otherwise trap.docs/escrow-security-checklist.md.Suggested execution
git checkout -b security/dust-sweep-liability-floorescrow/src/lib.rsescrow/src/tests/external_calls.rsdocs/adr/ADR-006-dust-sweep-and-token-safety.mdTest and commit
cargo testExample commit message
Guidelines