erc4626-inflation

Solid

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`.

AI & Automation 38 stars 5 forks Updated 2 days ago MIT

Install

View on GitHub

Quality Score: 82/100

Stars 20%
53
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# 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...

Details

Author
iktok90-design
Repository
iktok90-design/ai-smart-contract-auditor
Created
1 weeks ago
Last Updated
2 days ago
Language
JavaScript
License
MIT

Bundled in these plugins

Similar Skills

Semantically similar based on skill content — not just same category