Description:
The _convertToShares() function calculates shares based on the vault's current balance using IERC20(asset()).balanceOf(address(this)). An attacker can manipulate this calculation by directly transferring tokens to the vault before other users deposit, causing subsequent depositors to receive fewer shares than they should.
This is a classic "first depositor" or "donation attack" on ERC4626 vaults. The attacker can:
Deposit a minimal amount (e.g., 1 wei)
Directly transfer a large amount to the vault
This inflates the balanceOfVault while keeping totalShares low
Subsequent depositors get proportionally fewer shares
Impact:
First depositor can steal significant portions of deposits from subsequent users
Users receive far fewer shares than their deposit should entitle them to
Loss of funds for legitimate users
The attack can be frontrun against any deposit transaction
Proof of Concept:
Mitigation:
Implement the "virtual shares" approach recommended by OpenZeppelin:
Or enforce a minimum first deposit:
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.