Skip to content
Smart contracts Write-up Advanced

Balancer Rounding Error

A rounding error in Balancer's ERC4626LinearPools allowed an attacker to repeatedly swap 1 wei of wrapped token for 1 wei of underlying token, extracting value because the wrapped token is worth more. Combined with flash swaps and zero fees when balanced, an attacker could drain all value from Boosted Pools.

immunefi.com

Published on immunefi.com

On August 11, 2023, whitehat GothicShanon89238 submitted a critical vulnerability to Balancer via Immunefi, which consisted of a rounding error of ERC4626LinearPools combined with flashSwap. At the time of the submission, all value in Boosted Pools could be drained by the attack, which was 20% of Balancer’s $1 billion…

The author, on immunefi.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Impact

An attacker could drain all value in Boosted Pools, which was 20% of Balancer's $1 billion TVL at the time, but mitigation reduced the total TVL at risk from $242 million to $40 million.

What the attacker needed

No initial capital required; flash swap functionality; zero fees when balanced

How it was found

  1. Execute a flash swap in a Linear Pool using BPT to trade for the main and wrapped tokens, significantly reducing the total supply of each to near 0.
  2. Perform multiple swaps with GivenOut between the underlying and wrapped, which takes advantage of the rounding error to decrease the total balance without affecting the supply.
  3. Repay the flash swapped BPT by trading the underlying token at a lower rate than when it was borrowed.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

A rounding error in a smart contract meant that when someone swapped a tiny amount of a valuable token for a less valuable one, the pool gave out slightly more value than it should. By repeating this many times in one transaction, an attacker could steal funds from the pool. The bug was in how the pool calculated exchange rates when dealing with very small numbers.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.