ERC-4626 Vault Security Checklist
Short answer: most ERC-4626 vault bugs fall into six groups:
- share inflation through a first deposit or a donation;
- rounding in the wrong direction;
totalAssets()that can be moved by anyone;- preview and max functions that disagree with what actually happens;
- tokens that don't behave like plain ERC-20s;
- privileged roles over strategies and fees.
The checklist below covers each group, with what the EIP-4626 standard requires and what auditors check.
The checklist
- First depositor cannot inflate the share price (virtual shares, a decimals offset or seeded liquidity)
- Every conversion rounds in the vault's favour, as EIP-4626 requires
-
totalAssets()can't be moved in one transaction by donations, flash loans or a spot price -
preview*functions match what the action actually does, fees included -
max*functions return 0 when an action would revert (paused, capped, locked) - Fee-on-transfer, rebasing and callback tokens are handled or explicitly rejected
- Deposits and withdrawals follow checks-effects-interactions or are reentrancy-guarded
- Users have slippage protection (a router, or minimum-out parameters)
- Strategy, fee and pause roles are limited, time-locked where possible, and documented
- Withdrawals still work, or fail clearly, when a strategy is illiquid or paused
1. Share inflation (first deposit and donation)
What goes wrong. When a vault is empty, the first depositor can mint one share and then send assets straight to the vault. That raises the price of a share. The next depositor's assets then convert to zero shares after rounding down, and the attacker redeems their one share for both deposits.
The fix. Make inflation unprofitable:
- Virtual shares and assets. OpenZeppelin's ERC4626 adds an offset, through
_decimalsOffset(), so the attacker's donation mostly goes to virtual shares. See OpenZeppelin's notes on inflation attacks. - Seed the vault at deployment with a deposit that is never withdrawn.
- Require a minimum number of shares out on deposit.
A vault that tracks assets internally instead of reading its token balance is not exposed to donations at all. Say so in your spec so auditors can confirm it.
2. Rounding direction
EIP-4626 says rounding must favour the vault, so existing holders never lose value to a new action:
| Function | Rounds |
|---|---|
deposit / previewDeposit, convertToShares | Shares down |
mint / previewMint | Assets up |
withdraw / previewWithdraw | Shares up |
redeem / previewRedeem, convertToAssets | Assets down |
Check every custom path, not only the four main functions: fee calculations, partial withdrawals, reward or yield accrual, and any function that converts between shares and assets. A single path that rounds the other way can be repeated in a loop to drain value.
3. A totalAssets() anyone can move
The share price is totalAssets() divided by total supply. If totalAssets() reads a token balance, a spot price from a DEX or an external vault, anyone who can move that number in one transaction can move the share price, then deposit or redeem at the wrong price.
Use internally tracked balances where you can, time-weighted or oracle prices instead of spot prices, and limits on how fast the reported value can change.
4. Preview and max functions that disagree with reality
Integrators and routers rely on these functions:
previewDeposit,previewMint,previewWithdrawandpreviewRedeemmust include fees and return what the action would do in the same transaction.maxDeposit,maxMint,maxWithdrawandmaxRedeemmust return 0 or the real limit when the vault is paused, capped or locked, never an amount that would revert.
Write tests that call each preview function and then the real action, and assert they match.
5. Tokens that don't behave like plain ERC-20s
- Fee-on-transfer tokens: the vault receives less than
amount. Measure the balance before and after, or reject such tokens. - Rebasing tokens: balances change without transfers, which breaks internal accounting.
- Tokens with callbacks (ERC-777 style hooks) can re-enter the vault mid-deposit. Update state before external calls, or use a reentrancy guard.
- Decimals: don't assume 18. Make the share decimals and any offset match the asset.
State which tokens the vault supports and reject the rest at deployment.
6. Privileged roles, strategies and withdrawals
Immunefi reports that DeFi losses increasingly come from keys and privileged access rather than contract maths (The Block). For each role, write down what it can do:
- Strategy changes: can a new strategy take all assets? Is the change time-locked?
- Fees: are they capped in code? Can a fee change apply to deposits already made?
- Pause: what does it stop? Can users still withdraw while deposits are paused?
- Recovery functions: can an admin sweep the underlying asset, or only stray tokens?
Plan for illiquid strategies too. If assets are locked in a strategy, withdraw should fail clearly or queue the request, as the asynchronous ERC-7540 extension does. It should never pay early users at the expense of later ones.
Slippage protection
EIP-4626 functions have no minimum-out parameter, so a user calling a vault directly can be front-run or hit by a price change. Route deposits and redemptions through a router that checks minimum shares or assets out, or add minimum-out variants for users who call the vault directly.
Frequently asked questions
What is an ERC-4626 inflation attack?
An attacker makes the first deposit into an empty vault, mints one share, then sends assets directly to the vault to raise the price per share. The next depositor's assets round down to zero shares, and the attacker redeems their single share for both deposits. Virtual shares, a decimals offset or a seeded first deposit make the attack unprofitable.
Which way should an ERC-4626 vault round?
Always in the vault's favour. Deposit and redeem round down (fewer shares minted, fewer assets paid out), while mint and withdraw round up (more assets taken, more shares burned). This stops anyone extracting value from existing holders through rounding.
Does using OpenZeppelin's ERC4626 make a vault secure?
It handles rounding and adds inflation protection through virtual shares, but most vault bugs sit in the custom parts: totalAssets(), fees, strategies, roles, and how the vault handles unusual tokens. Those still need tests and review.
What should be audited in an ERC-4626 vault?
The share maths and its rounding, inflation protection, how totalAssets() is calculated and whether it can be manipulated, and preview and max functions against real behaviour. Then token compatibility, reentrancy, slippage protection, and every privileged role over strategies, fees, pausing and recovery.