# Whole-balance sweep drains shared deposits

Functions that move the contract's entire token balance instead of a tracked per-user or per-proposal amount

_Area: DeFi accounting and math bugs. Seen in 2 disclosed reports; latest 2026-06-22. Updated 2026-11-09._

## How it works
A contract holds tokens on behalf of many users or proposals, but a downstream call moves the contract's *whole* balance rather than the amount attributable to the caller. The assumption that breaks is "the contract only holds what this operation is about." In reality the contract custodies everyone's deposits at once, so any path that pulls `balanceOf(this)` or an untracked total sweeps other users' funds into one operation. The same shape appears when a token balance sitting in a contract is redeemable by anyone: the balance itself becomes the entitlement, not a recorded share.

## Where it shows up
- Sweep, buyout, burn, commit, or redeem paths that read the contract's full token balance instead of a per-user/per-proposal tracked amount.
- Shared custody contracts (migration, escrow, router, staking) where multiple deposits coexist before settlement.
- Calls to `transfer(address(0), ...)` or `burn()` on tokens the contract merely holds.
- DEX pair contracts holding LP tokens sent to them directly.
- Any function where the recipient or amount is derived from `balanceOf(address(this))`.

## How to review
For every function that moves tokens out of a shared contract, find the exact quantity it moves and confirm it equals the caller's tracked share, not the contract balance. The invariant: *a caller can only move funds they are recorded as owning; the contract's total balance is never the unit of transfer.* Check that per-proposal/per-user amounts are stored and passed explicitly. For burn/redeem paths, confirm the recipient is a real redeemer and the amount is the tracked holding, not `balanceOf(this)`. Treat any stray balance in a contract as claimable by whoever calls next unless the code proves otherwise.

## How finders spotted it
- Read `Buyout.start` and `Migration.commit` together and noticed the buyout pulled all fractions the Migration contract held, not the proposal-specific deposit [E1](https://bugbountylibrary.com/r/c4%3A2022-07-fractional%3AH-06.md).
- Noticed `sweepInterest` transferred cNote to `address(0)` instead of redeeming — an unconditional asset-destruction mistake visible on code reading [E3](https://bugbountylibrary.com/r/c4%3A2022-06-canto%3AH-03.md).
- Likely watched pair LP balances and saw LP tokens sitting in the pair contract, then recognized `burn()` redeems them [E2](https://bugbountylibrary.com/r/dhl%3A20260622-atm-lp-burn.md).

## Variants seen
- Buyout/commit path sweeping all custodied fractions across proposals [E1](https://bugbountylibrary.com/r/c4%3A2022-07-fractional%3AH-06.md).
- DEX pair `burn()` redeeming LP tokens mistakenly sent to the pair [E2](https://bugbountylibrary.com/r/dhl%3A20260622-atm-lp-burn.md).
- Interest sweep transferring collateral to `address(0)`, destroying it [E3](https://bugbountylibrary.com/r/c4%3A2022-06-canto%3AH-03.md).

## Impact and severity
Funds stolen at zero cost by a competing proposal [E1](https://bugbountylibrary.com/r/c4%3A2022-07-fractional%3AH-06.md); 1,603 WBNB and 99M tokens redeemed from a victim's misplaced LP [E2](https://bugbountylibrary.com/r/dhl%3A20260622-atm-lp-burn.md); interest-bearing collateral destroyed and repayments blocked [E3](https://bugbountylibrary.com/r/c4%3A2022-06-canto%3AH-03.md). Severity is high because the sweep reaches every depositor sharing the contract, and in E1 a zero-cost competing proposal scales the theft to all pending deposits.

## Evidence
- E1: https://bugbountylibrary.com/r/c4%3A2022-07-fractional%3AH-06.md
- E2: https://bugbountylibrary.com/r/dhl%3A20260622-atm-lp-burn.md
- E3: https://bugbountylibrary.com/r/c4%3A2022-06-canto%3AH-03.md
