# Truncating reward and sale math

Rounding or precision loss in reward, sale, or swap math that pays out on repeated small cycles

_Area: DeFi accounting and math bugs. Seen in 2 disclosed reports; one confirmed bounty: $1,000,000; latest 2024-04-10. Updated 2026-10-29._

## How it works
When a contract converts between two assets of unequal value, it computes an output by dividing and truncating. If the truncation favors the user even by 1 wei, that wei is real value leaving the pool. A single trade is negligible, but the operation is repeatable: the same actor can cycle buy/sell, add/remove, or wrap/unwrap many times in one transaction, and each cycle leaks another unit. The broken assumption is that rounding error is too small to matter; it matters when the operation is cheap, repeatable, and the loss accrues to the pool rather than the caller.

## Where it shows up
- Conversion math that divides before multiplying, or truncates the user-favorable side, especially on the smallest possible amount (1 wei).
- 1:1 wrap/unwrap or linear-pool paths between assets of unequal value [E1](https://bugbountylibrary.com/r/blog%3Aimmunefi-com-blog-bug-fix-reviews-balancer-rounding-error.md).
- Reward or "sell" functions converting token to reward with low precision [E4](https://bugbountylibrary.com/r/dhl%3A20240410-bigbangswap.md).
- Caps or limits stored in a state variable that LP add/remove mutates proportionally [E2](https://bugbountylibrary.com/r/c4%3A2023-05-maia%3AH-20.md).
- Dividend or reward balances credited from donations and claimable in the same transaction [E3](https://bugbountylibrary.com/r/dhl%3A20250619-sinstakezombie.md).
- Zero-fee windows, flash swaps, or large minted supply that make cycling free or cheap [E1](https://bugbountylibrary.com/r/blog%3Aimmunefi-com-blog-bug-fix-reviews-balancer-rounding-error.md).

## How to review
The invariant: for any single operation, the value removed from the pool must be at least the value the caller gave up, and rounding must always favor the pool, not the caller. Check the direction of every truncation on the minimum input. Then check repeatability: can the same caller run the operation many times in one transaction at near-zero cost? If both hold, it is a leak. For caps, verify that small repeated add/remove cycles cannot converge the tracked ratio to a favorable value [E2](https://bugbountylibrary.com/r/c4%3A2023-05-maia%3AH-20.md).

## Variants seen
- 1-wei wrap/unwrap rounding in ERC4626LinearPool draining boosted pools [E1](https://bugbountylibrary.com/r/blog%3Aimmunefi-com-blog-bug-fix-reviews-balancer-rounding-error.md).
- Bandwidth cap bypass via repeated small LP add/remove converging diff/weight [E2](https://bugbountylibrary.com/r/c4%3A2023-05-maia%3AH-20.md).
- Donation-funded dividends realized by a same-transaction flash-borrowed buyer/seller [E3](https://bugbountylibrary.com/r/dhl%3A20250619-sinstakezombie.md).
- Precision loss in sellRewardToken enabling repeated profitable sells [E4](https://bugbountylibrary.com/r/dhl%3A20240410-bigbangswap.md).

## Impact and severity
Losses ranged from ~$705 [E3](https://bugbountylibrary.com/r/dhl%3A20250619-sinstakezombie.md) and ~$5K [E4](https://bugbountylibrary.com/r/dhl%3A20240410-bigbangswap.md) to draining entire boosted pools with no capital [E1](https://bugbountylibrary.com/r/blog%3Aimmunefi-com-blog-bug-fix-reviews-balancer-rounding-error.md). Severity is high when the leak is repeatable and capital-free via flash loans; worse when zero fees or large supply remove the cost of cycling [E1](https://bugbountylibrary.com/r/blog%3Aimmunefi-com-blog-bug-fix-reviews-balancer-rounding-error.md).

## Evidence
- E1: https://bugbountylibrary.com/r/blog%3Aimmunefi-com-blog-bug-fix-reviews-balancer-rounding-error.md
- E2: https://bugbountylibrary.com/r/c4%3A2023-05-maia%3AH-20.md
- E3: https://bugbountylibrary.com/r/dhl%3A20250619-sinstakezombie.md
- E4: https://bugbountylibrary.com/r/dhl%3A20240410-bigbangswap.md
