Vault Security

Vault security covers the patterns and testing strategies for protecting ERC-4626 tokenized vaults and custom vault implementations against share inflation and rounding exploits.

In Depth

Vaults are one of DeFi's most common building blocks. Users deposit tokens and receive shares representing their proportional claim on the vault's assets. The ERC-4626 standard defines a common interface, but getting the math right is surprisingly hard. Share inflation attacks exploit the first-depositor problem. An attacker can donate assets directly to the vault to inflate the share price, causing subsequent depositors to receive zero shares due to rounding. Rounding direction matters for every conversion between shares and assets. Deposits should round down (fewer shares), and withdrawals should round up (more assets required). Custom vaults that don't follow ERC-4626 often have even more accounting pitfalls. Invariant testing is the strongest defense — properties like 'total shares times price per share always equals total assets' catch rounding and inflation bugs that unit tests miss. For a deeper dive, see smart contract security and Recon's approach to testing vault implementations.

Frequently Asked Questions

What is vault security?

Vault security is the discipline of protecting token vaults — contracts where users deposit assets and receive shares — from accounting bugs, share manipulation, and rounding exploits. It applies to ERC-4626 vaults, yield aggregators, and any contract that manages pooled deposits.

What are common vault vulnerabilities?

The most common vault vulnerabilities are share inflation attacks (first-depositor manipulation) and incorrect rounding direction on deposit and withdrawal conversions. Donation attacks can skew the share-to-asset ratio, and accounting drift between tracked and actual token balances is another risk. Invariant testing can catch these by verifying that share accounting stays consistent across all deposit and withdraw sequences.

Related Terms

Need expert help with vault security?