ERC4626 is the tokenized vault standard — it defines a standardized interface for yield-bearing tokens where depositors receive shares representing their proportional claim on underlying assets. The standard is now widely used in DeFi for lending protocols, yield aggregators, and liquid staking wrappers. Its share calculation math introduces non-obvious vulnerabilities that have caused significant losses.
The most critical ERC4626 vulnerability targets the first depositor. The attack works as follows:
deposit)1e18 virtual shares and assets) as an offset, making the inflation attack economically infeasibleaddress(0) at vault creation// OpenZeppelin ERC4626 — virtual offset (recommended)
function _decimalsOffset() internal view virtual override returns (uint8) {
return 6; // 10^6 virtual offset — inflation attack costs 10^6x more
}
ERC4626's previewMint and previewWithdraw must round in favor of the vault (ceiling), while previewDeposit and previewRedeem must round against the depositor (floor). Incorrect rounding direction allows users to extract more assets than they deposited, or enables flash loan attacks to drain the rounding difference repeatedly.
Always use OpenZeppelin's Math.mulDiv with explicit rounding direction:
// Rounding up for vault-favorable operations
Math.mulDiv(assets, totalSupply + 1, totalAssets() + 1, Math.Rounding.Ceil);
Vaults that interact with external protocols (e.g., Aave, Compound) during deposit or withdrawal open reentrancy vectors. Use ReentrancyGuard on all state-changing vault functions. See reentrancy.
Some protocols use ERC4626 share prices as price oracles. If the vault's underlying assets are manipulable via flash loans (e.g., the vault holds AMM LP tokens), the share price can be temporarily inflated to manipulate dependent protocols. See oracle manipulation.
SmartContract.us detects share inflation vulnerability patterns, rounding direction issues, and reentrancy in vault contracts. Analyze a vault contract →