← ClaudeAtlas

erc4626-inflationlisted

Detect ERC-4626 inflation/donation attacks — first depositor share-price manipulation, naive convertToShares math, missing virtual-shares defense. Activate on any ERC-4626 vault implementation, share/asset math, `convertToShares`, `convertToAssets`, `previewDeposit`, `previewMint`, `totalAssets`, `_decimalsOffset`.
iktok90-design/ai-smart-contract-auditor · ★ 36 · AI & Automation · score 80
Install: claude install-skill iktok90-design/ai-smart-contract-auditor
# ERC-4626 inflation attack detection ## Background The classic "donation" or "inflation" attack on share-based vaults. First depositor mints 1 wei share for 1 wei of asset → share price = 1. Attacker then donates large amount directly to the vault (bypassing deposit) → totalAssets balloons → share price massively inflated → next depositor rounds shares to 0. Has caused real, public losses across many forks of naive ERC-4626. ## When this applies - Any contract inheriting ERC-4626 - Custom vaults with share/asset math - Yield aggregators - Lending markets that mint share-tokens ## Detection patterns ### Naive convertToShares math (CRITICAL) ```solidity function convertToShares(uint256 assets) public view returns (uint256) { if (totalSupply() == 0) return assets; return assets * totalSupply() / totalAssets(); } ``` First deposit: 1 share for 1 asset. Donation: totalAssets += 1e30. Next depositor's 1 asset → `1 * 1 / 1e30 = 0` shares. Funds lost. ### No virtual-shares defense (HIGH) Defense: OZ ERC4626 v4.9+ uses `_decimalsOffset()` to mint "virtual" shares: ```solidity function _convertToShares(uint256 assets, Math.Rounding rounding) internal view virtual override returns (uint256) { return assets.mulDiv(totalSupply() + 10 ** _decimalsOffset(), totalAssets() + 1, rounding); } ``` This adds N virtual shares (typically 10**6 — 6 decimals offset) that nobody owns. Donations have far less leverage. ### Dead-shares pattern not used (HIGH) Alternative defense: m