Virtual Shares

Phantom shares and assets added to ERC-4626 conversion math to make the empty-vault exchange rate well-defined and inflation attacks uneconomical.

Virtual shares are a defensive accounting technique used in ERC-4626 vaults to neutralize the inflation attack. Instead of computing the share/asset exchange rate from the vault's real balances alone, the implementation adds a fixed number of non-existent ("virtual") shares and assets to both sides of the conversion. OpenZeppelin's reference implementation adds +1 virtual asset and +10**offset virtual shares to every convertToShares and convertToAssets calculation.

Why they work

The inflation attack relies on a first depositor being able to hold a tiny totalSupply (often a single share) while donating a large amount of the underlying asset to skew the exchange rate. Virtual shares mean the vault behaves as if a well-capitalized "virtual" depositor were always present, so the empty-vault state can never be driven to an extreme ratio by one attacker. To move the rate meaningfully, an attacker would have to donate an amount scaled by 10**offset, which quickly costs far more than the attack can return.

Limitations

Virtual shares reduce the profitability of an inflation attack rather than mathematically eliminating it. With only the +1 virtual asset and no decimal offset, a determined attacker can still dilute victims (see OpenZeppelin issue #5223). The technique also skims a small amount of yield toward the virtual position and can distort withdrawals when the vault is operating at a loss. The recommended posture is to combine a sufficient virtual offset with internal balance tracking and a zero-share deposit revert.

Need expert guidance on Virtual Shares?

Our team at Zealynx has deep expertise in blockchain security and DeFi protocols. Whether you need an audit or consultation, we're here to help.

Get a Quote