# ERC-4626 inflation attack: how it works and how to prevent it

URL: https://shield.quillaudits.com/learn/vulnerabilities/erc4626-inflation-attack/

An ERC-4626 inflation attack is when the first depositor in an empty vault donates assets to inflate the share price, so later deposits round down to 0 shares. The attacker then redeems a single share for the victim's deposit. Virtual shares and assets, a seeded first deposit and a revert on 0 shares stop it, and anything that prices the vault's shares can break the same way.

Last updated 24 November 2026. 6 minute read. By the QuillShield team.

## How does an ERC-4626 inflation attack work?

An ERC-4626 vault mints shares in proportion to the assets it holds. The usual formula is `assets * totalSupply / totalAssets`, and Solidity rounds the division down. When `totalAssets` reads the vault's token balance, anyone can raise it with a plain transfer that mints no shares.

1. The vault is new, so it has no shares and no assets.
2. The attacker deposits 1 wei and gets 1 share.
3. The attacker transfers 10,000 tokens straight to the vault. No shares are minted, so that single share is now worth the whole balance.
4. A user deposits 5,000 tokens. With 10,000 tokens behind 1 share, the formula gives 5,000 × 1 / 10,000, which rounds down to 0 shares, and the deposit still goes through.
5. The attacker redeems the one share for everything in the vault: 15,000 tokens, 5,000 of them the user's.

The attacker only needs to see the first real deposit coming and put the donation in front of it. The same state also hurts contracts that never deposit: a lending market that prices the shares as collateral sees a share price that one transfer moved.

## What does vulnerable code look like?

This vault reads its live token balance and accepts any deposit, even one that mints nothing.

```
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

interface IERC20 {
    function balanceOf(address account) external view returns (uint256);
    function transferFrom(address from, address to, uint256 amount) external returns (bool);
}

contract NaiveVault {
    IERC20 public immutable asset;
    uint256 public totalSupply;
    mapping(address => uint256) public balanceOf;

    constructor(IERC20 asset_) {
        asset = asset_;
    }

    function totalAssets() public view returns (uint256) {
        // A plain transfer to the vault raises this without minting shares.
        return asset.balanceOf(address(this));
    }

    function deposit(uint256 assets) external returns (uint256 shares) {
        uint256 supply = totalSupply;
        // Rounds down: after a large donation, a normal deposit mints 0 shares.
        shares = supply == 0 ? assets : (assets * supply) / totalAssets();
        require(asset.transferFrom(msg.sender, address(this), assets), "transfer failed");
        totalSupply = supply + shares;
        balanceOf[msg.sender] += shares;
    }
}
```

Two lines do the damage. `totalAssets()` counts donations, and `deposit` never checks that `shares` is above 0.

## How do you fix it?

```
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

interface IERC20 {
    function balanceOf(address account) external view returns (uint256);
    function transferFrom(address from, address to, uint256 amount) external returns (bool);
}

contract OffsetVault {
    IERC20 public immutable asset;
    uint256 public totalSupply;
    mapping(address => uint256) public balanceOf;

    // The vault acts as if a million shares and 1 unit of assets were always there,
    // so a donation has to be about a million times a deposit to round it to 0.
    uint256 private constant VIRTUAL_SHARES = 1e6;
    uint256 private constant VIRTUAL_ASSETS = 1;

    constructor(IERC20 asset_) {
        asset = asset_;
    }

    function totalAssets() public view returns (uint256) {
        return asset.balanceOf(address(this));
    }

    function previewDeposit(uint256 assets) public view returns (uint256) {
        return (assets * (totalSupply + VIRTUAL_SHARES)) / (totalAssets() + VIRTUAL_ASSETS);
    }

    function deposit(uint256 assets) external returns (uint256 shares) {
        shares = previewDeposit(assets);
        require(shares > 0, "zero shares"); // never take assets for nothing
        require(asset.transferFrom(msg.sender, address(this), assets), "transfer failed");
        totalSupply += shares;
        balanceOf[msg.sender] += shares;
    }
}
```

- **Virtual shares and assets.** The fixed vault acts as if a million shares and 1 unit of assets were always there, so a donation has to be about a million times a deposit to round it to 0. OpenZeppelin's ERC4626 has done this since version 4.9, through `_decimalsOffset()`. Its docs show that even with the default offset of 0 the attack loses the attacker money, and a larger offset makes any attack on users far more wasteful.
- **Revert on 0 shares.** A deposit that mints nothing should fail, and callers should be able to pass the fewest shares they will accept.
- **Seed the vault when you deploy it.** Make a first deposit in the deployment transaction and send those shares to an address nobody controls, so the vault is never empty.
- **Don't trust a young vault's price.** If your protocol prices another vault's shares, wait for real deposits, limit how fast the rate can move, or set a floor.

## How has it been exploited?

Resupply's post-mortem describes the pattern costing $10M on 26 June 2025. At 00:18 UTC a new crvUSD and wstUSR lending pair went live with a $10M debt limit. It priced its collateral from a CurveLend vault that held no deposits.

At 01:53 UTC an attacker donated 2,000 crvUSD to the vault's controller and deposited 2 crvUSD to mint 1 wei of vault shares. That pushed the price of a single share so high that Resupply's exchange rate, 1e36 divided by the share price, rounded down to 0. With a rate of 0 the loan-to-value of every position worked out to 0, so each borrow passed the solvency check, and the attacker borrowed up to the pair's $10M limit. The guardian paused the pair at 02:53 UTC, leaving $10M of reUSD bad debt.

The post-mortem lists a patch to Resupply's pair contracts as the next step, and Resupply deployed a share burner that anyone can call to protect a pair's vault from the same move.

## What should a reviewer check?

- Can a plain transfer raise `totalAssets()`, and does any formula use it while the vault is new or empty?
- Does the vault use virtual shares and assets, or seed and lock a first deposit when it is deployed?
- Do `deposit` and `mint` revert when they would mint 0 shares, and can callers set a minimum?
- Does every conversion round in the vault's favor, down for shares given out and up for shares taken in?
- If your contract prices another vault's shares, what happens when that vault is empty, brand new or holding a large donation?
- Do your tests cover the first deposit, a donation before it, and a deposit smaller than the donation?

## How does QuillShield check for it?

QuillShield is AI-Powered Code Review for Solidity in Foundry projects. A full audit covers the whole codebase in scope, so a vault's deposit math is reviewed together with the contracts that lend against or price its shares, which is where Resupply's loss came from. QuillShield builds a security graph of the code and tests its findings with proofs of concept. Each finding that holds up comes with the exact lines, the impact, a recommended fix and, on a full audit, the proof of concept result.

After the audit, each pull request is checked against that security graph. A new collateral market or a change to a conversion function is reviewed against the rest of the protocol before it merges.

Full audits start at $49 and are priced from the lines of Solidity in scope, as the [pricing page](https://shield.quillaudits.com/pricing/) shows. The guide to [running your first audit](https://shield.quillaudits.com/guides/run-your-first-audit/) walks through getting a quote for your own code. [Sign up free](https://shield.quillaudits.com/register) and you see the exact price before anything is charged.

## Common questions

### Does OpenZeppelin's ERC4626 stop the inflation attack?

Since version 4.9 it adds virtual shares and assets. OpenZeppelin's docs show that with the default offset of 0 the attack is no longer profitable, and a larger `_decimalsOffset()` makes it far more wasteful. Custom vaults and older versions need their own defense.

### Is a vault safe once it has deposits?

It's safer, but the risk comes back if the vault empties, and a large enough donation can still round small deposits down. Keep the defenses for the vault's whole life.

### Can the attack hurt a protocol that only reads a vault's price?

Yes. Resupply did not run the vault. It priced the vault's shares as collateral, and one donation to an empty vault pushed its exchange rate to 0.

### How do I test for it in Foundry?

Write a test where an attacker deposits 1 wei, transfers a large amount of the asset to the vault, and a second user then deposits less than that amount. Assert that the second user gets shares worth close to the deposit, or that the deposit reverts.

## Sources

- [Resupply crvUSD-wstUSR Market Post Mortem, Resupply, 28 June 2025](https://mirror.xyz/0x521CB9b35514E9c8a8a929C890bf1489F63B2C84/ygJ1kh6satW9l_NDBM47V87CfaQbn2q0tWy_rtp76OI)
- [In-depth analysis and reflections on the Resupply protocol attack incident, BlockSec](https://blocksec.com/blog/in-depth-analysis-and-reflections-on-the-resupply-protocol-attack-incident)
- [ERC-4626, the inflation attack and the virtual offset, OpenZeppelin docs](https://docs.openzeppelin.com/contracts/erc4626)
- [ERC-4626: Tokenized Vaults](https://eips.ethereum.org/EIPS/eip-4626)
