November 28, 2026 Free pentesting academy for Web2 & Web3
ERC-4626 Vault Inflation Attacks: How First-Depositor Exploits Work and How to Stop Them
Share

ERC-4626 is the standard for tokenized yield-bearing vaults. Its share accounting introduced a now-famous class of bug: the “inflation” or “first-depositor” attack, where an attacker manipulates the share price so the next depositor’s shares round down to almost nothing. This article explains the mechanism, the math, how to prove it with Foundry, and the mitigations auditors expect.

Chart showing the ERC-4626 inflation attack with and without protection
Share price under an inflation attack. Source: OpenZeppelin ERC-4626 documentation.

How vault shares work

A vault mints “shares” representing a claim on the underlying assets. The conversion is:

shares minted = assets_deposited * totalSupply / totalAssets

When the vault is empty (totalSupply == 0) the first depositor typically gets shares 1:1. The problem lives in the interaction between an empty vault and Solidity’s integer rounding.

The attack, step by step

  1. The attacker is the first depositor and deposits the smallest unit — 1 wei of the asset — receiving 1 share. Now totalSupply == 1.
  2. The attacker donates a large amount of the asset directly to the vault (a plain transfer, not a deposit). Now totalAssets is large but totalSupply is still 1. One share is now “worth” the whole balance.
  3. A victim deposits, say, 10 tokens. Their shares are 10 * 1 / totalAssets, which rounds down to 0 when the donation made totalAssets bigger than the victim’s deposit.
  4. The victim receives 0 (or near-0) shares but their assets are now in the vault. The attacker redeems their single share and walks away with most of the victim’s deposit.

The root cause is a rounding-down conversion combined with an attacker’s ability to inflate totalAssets without minting shares. Any custom vault that converts assets to shares with integer division is a candidate.

Proving it with Foundry

A proof of concept outline (run against a copy of the target in a test environment you control):

function test_inflation() public {
    // Attacker seeds the empty vault with 1 wei
    vm.prank(attacker);
    vault.deposit(1, attacker);

    // Attacker donates directly to inflate the share price
    vm.prank(attacker);
    asset.transfer(address(vault), 10_000e18);

    // Victim deposits — observe shares rounding to zero
    vm.prank(victim);
    uint256 shares = vault.deposit(10e18, victim);
    assertEq(shares, 0); // victim got nothing for 10 tokens
}

Mitigations

1. Virtual shares and assets (decimals offset)

OpenZeppelin’s ERC4626 implementation (since v4.9) adds a virtual offset so the vault behaves as if it already holds a tiny amount of shares and assets. This makes the rounding error negligible and the donation attack unprofitable. You configure it by overriding _decimalsOffset().

function _decimalsOffset() internal view virtual override returns (uint8) {
    return 6; // larger offset => stronger protection
}

2. Seed the vault on deployment

Deposit a non-trivial initial amount (and optionally burn those shares to a dead address) so the vault is never in the empty state an attacker needs.

3. Internal balance accounting

Track deposited assets in a storage variable rather than reading asset.balanceOf(this), so a direct donation does not change totalAssets.

4. Slippage protection for users

Expose mint/deposit variants with a minimum-shares-out parameter, and have front ends enforce it so a user never silently receives zero shares.

Auditor’s checklist

  • What happens when totalSupply == 0? Is the first deposit special-cased safely?
  • Rounding direction of every conversion — does it ever favour the protocol over the user in a way an attacker can exploit?
  • Does a direct token transfer to the vault change totalAssets?
  • Is there a decimals offset or virtual-shares protection?
  • Is there slippage protection on deposit and mint?

Key takeaways

  • The inflation attack abuses rounding-down in an empty vault plus a direct donation to inflate share price.
  • OpenZeppelin’s virtual shares / decimals offset makes it unprofitable; custom vaults must add equivalent protection.
  • Seeding the vault and using internal accounting both remove the preconditions.
  • Always give users slippage protection so a deposit can never silently return zero shares.

Frequently asked questions

What is an ERC-4626 inflation attack?

An attacker deposits a tiny amount into an empty vault, then donates assets directly to it to inflate the share price so that the next depositor’s shares round down to zero or near zero, letting the attacker redeem most of the victim’s deposit.

Does OpenZeppelin’s ERC4626 prevent it?

Since version 4.9 the OpenZeppelin implementation uses virtual shares and assets with a configurable decimals offset, which makes the attack unprofitable. Custom vaults must implement an equivalent protection.

What should auditors check in a vault?

Rounding direction in every conversion, behaviour when totalSupply is zero, donation handling, decimals offset, slippage protection for users and whether the deployer seeds the vault with an initial deposit.

Was this tutorial useful?
Share

The pentestwiki.org editorial team: practising penetration testers, red teamers and smart contract auditors who write, test and peer-review every tutorial before publication.

Need a professional assessment? Our team performs authorized penetration tests and smart contract audits.
See services

Get new tutorials in your inbox

One email when a new guide, cheat sheet or Web3 security write-up is published. No spam, unsubscribe in one click.

By subscribing you accept our Privacy Policy. Unsubscribe anytime.