Skip to content
Business logic Write-up Advanced

Balancer V2

Balancer V2's modified SafeERC20 library omitted a check that the token address has code, so calling safeTransferFrom on a not-yet-deployed ERC20 returned success. An attacker could front-run a token deployment, create a pool or internal balance for the non-existent token, and later withdraw real funds deposited by users.

mirror.xyz

Published on mirror.xyz

Two years ago I submitted a bug in Balancer V2 that let attackers create infinite token balances by front-running ERC20 deployments. I was paid $250k for this critical bug and it was made public recently.

The author, on mirror.xyz

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

Root cause

Likely the protocol's modified SafeERC20 library removed the check that the token address contains code, so a call to a non-existent token returned success and was treated as a real transfer.

Impact

An attacker could potentially extract up to $120M in the worst case, though this was unlikely as someone might detect the infinite balance; the bug was classified as critical and paid $250K.

What the attacker needed

Attacker can front-run token deployment; permissionless pool creation; victim deposits into affected pool

How it was found

  1. The attacker front-runs a token deployment transaction in the mempool to predict the token's address.
  2. The attacker creates a Balancer pool or internal balance for the not-yet-deployed ERC20.
  3. The deposit function calls safeTransferFrom on the non-existent ERC20, which succeeds without moving tokens.
  4. The protocol records an infinite balance for the attacker.
  5. Once the ERC20 is deployed and real users deposit funds, the attacker withdraws the phantom balance.

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 smart contract can call another address even if no code exists there, and the call may still report success. Balancer's code assumed a successful token transfer meant real tokens moved, but for a token not yet deployed, no tokens moved while the protocol recorded a deposit. An attacker could exploit this to get a large fake balance and later take real money from other users.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.