# Balancer Rounding Error Bugfix Review

Rounding error in Balancer ERC4626LinearPool 1:1 wrap/unwrap let a flash-swap attacker repeatedly drain 1 wei per swap, draining boosted pools with no capital.

- Payout: $1,000,000
- Severity: critical
- Program: Balancer
- Credited: GothicShanon89238
- Disclosed: 2023-10-12
- Write-up quality: 8/10
- Original: https://immunefi.com/blog/bug-fix-reviews/balancer-rounding-error/
- Library page: https://bugbountylibrary.com/r/blog%3Aimmunefi-com-blog-bug-fix-reviews-balancer-rounding-error
- Tags: domain:web3 impact:funds-loss kind:bounty platform:blog platform:immunefi sev:critical tech:evm tech:solidity technique:chained technique:source-review vuln:accounting-error vuln:business-logic vuln:flash-loan vuln:precision-loss

**Target:** ERC4626LinearPool / ComposableStablePool (bb-a-* boosted pools) via Balancer V2 Vault batchSwap
**Root cause:** When swapping 1 wei of wrapped token for underlying, the pool deducts only 1 wei of underlying due to rounding, so the wrapped token (worth more) is exchanged at a favorable rate, decreasing pool balance without reducing supply and dropping rate=balance/supply below 1.
**Steps:**
1. Flash swap BPT in the Linear Pool to trade for main and wrapped tokens, driving their balances near 0.
2. Loop `batchSwap` GIVEN_OUT steps swapping 1 wei wrapped->underlying (`assetInIndex:1, assetOutIndex:2, amount:1`) to exploit rounding, lowering rate below 1.
3. Repay flash-swapped BPT using underlying token at the now-lower rate, keeping the difference.
4. Repeat `swapDecrease` ~500 times in one tx (PoC: 320,891 DAI stolen, zero starting capital).
**How found:** Researcher examined the 1:1 wrap/unwrap math in ERC4626LinearPools and noticed rounding on 1-wei exchanges deducts only 1 wei of underlying despite wrapped token being worth more; then reasoned that flash swaps + zero-fee balanced swaps + large BPT supply remove the gas/fee barriers that would normally make the leak unprofitable.
**Exploitation:** No capital needed: batchSwap 'settles at the end' acts as a flash swap. Attacker borrows BPT, drains main/wrapped balances, performs many 1-wei GIVEN_OUT swaps exploiting rounding to push rate below 1, then repays BPT cheaply with underlying, extracting the spread. Repeated across boosted pools to drain up to 20% of $1B TVL.
**Escalation:** Chained three conditions: flash swaps (no capital), zero fees when balanced (free repeated swaps), and large initial BPT supply (unlimited borrow) to scale from 1-wei leak to full pool drain.
**Insight:** In AMM/linear-pool math, check rounding direction on the smallest possible trade (1 wei) between assets of unequal value; then check whether flash swaps, zero-fee windows, and large minted BPT supply remove the economic barriers that normally make tiny leaks unprofitable.
