All vulnerabilities
HIGHWeb3exploited in the wild

WEB3-ERC4626-INFLATION-2023

Web3 · Ethereum · ERC-4626 tokenized vault (share-inflation bug class)

Summary

Disclosed publicly by OpenZeppelin on August 15, 2023 and leading the ERC-4626 audit checklists from Trail of Bits and Spearbit, this is the canonical tokenized-vault accounting bug, with real losses such as roughly $200K on early unprotected vaults. The attacker becomes the first depositor into an empty vault and mints 1 share for 1 wei of the underlying. The attacker then transfers (donates) a large amount of the underlying directly to the vault contract, bypassing the mint logic, so totalAssets rises while totalSupply stays at 1. A subsequent depositor's share count, computed as assets * totalSupply / totalAssets, rounds down to zero because their deposit is smaller than the inflated price-per-share. The attacker, still holding the only share, then redeems the entire balance including the victim's captured deposit. The root cause is integer division truncation in share pricing at low totalSupply combined with assets being increased by raw transfers.

How to avoid it in your code

  • Seed new vaults with a dead-shares initial deposit or use OpenZeppelin's virtual shares/assets offset (decimalsOffset) so the first depositor cannot inflate price-per-share.
  • Track assets via an internal accounting variable instead of token.balanceOf, so direct donations cannot move totalAssets.
  • Round share issuance down and asset withdrawal in the vault's favour, and reject deposits that would mint zero shares.
  • Require a protocol-owned initial mint at deployment so the vault never goes live with totalSupply of zero.
  • Enforce a minimum first-deposit amount or burn the initial shares to a dead address.

References

Related vulnerabilities

All Web3 →