What is ERC-4626 in smart contracts?
ERC-4626 is the standard interface for tokenized vaults: a vault takes deposits of one ERC-20 asset and issues shares, themselves ERC-20 tokens, that represent a claim on what the vault holds. Because every vault exposes the same functions, lending markets, aggregators and front ends can integrate any of them without custom code.
What does the standard define?
EIP-4626, created in December 2021, defines the functions below plus asset, totalAssets and the matching max functions. The standard considers it most secure for every calculation to favor the vault over its users, which sets the rounding direction of each one.
| Function | What it does | Rounds |
|---|---|---|
deposit, previewDeposit |
Assets in, shares minted | Shares down |
mint, previewMint |
Shares minted, assets in | Assets up |
withdraw, previewWithdraw |
Assets out, shares burned | Shares up |
redeem, previewRedeem |
Shares burned, assets out | Assets down |
convertToShares, convertToAssets |
Exchange rate without fees | Down |
What does vault-favoring rounding look like?
Preview math that rounds in favor of the vault (illustrative, not audited code) VaultMath.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
abstract contract VaultMath {
uint256 public totalSupply; // shares
function totalAssets() public view virtual returns (uint256);
// Assets in: round shares down.
function previewDeposit(uint256 assets) public view returns (uint256) {
uint256 supply = totalSupply;
return supply == 0 ? assets : (assets * supply) / totalAssets();
}
// Assets out: round shares up.
function previewWithdraw(uint256 assets) public view returns (uint256) {
uint256 supply = totalSupply;
uint256 total = totalAssets();
return supply == 0 ? assets : (assets * supply + total - 1) / total;
}
}
Where do ERC-4626 vaults go wrong?
The share price is assets divided by shares, so whoever can cheaply change either side can move it. The math above still fails on an empty vault: a donation can round the next deposit down to zero shares, which is the ERC-4626 inflation attack. The OpenZeppelin implementation adds virtual shares and assets and an offset in share precision, so an attacker loses more than they could take (OpenZeppelin). The standard itself warns that share prices can be moved by changing on-chain conditions and are not always safe as price oracles (EIP-4626).
FAQ
Do the preview functions include fees?
The preview functions do, since EIP-4626 requires previewDeposit and previewWithdraw to include deposit and withdrawal fees, while convertToShares and convertToAssets must leave fees out.
Sources
- ERC-4626: Tokenized Vaults, Ethereum Improvement Proposals checked 3 December 2026
- ERC-4626, OpenZeppelin docs checked 3 December 2026