Platform: Code4rena
Start Date: 31/01/2023
Pot Size: $90,500 USDC
Total HM: 47
Participants: 169
Period: 7 days
Judge: LSDan
Total Solo HM: 9
Id: 211
League: ETH
Rank: 97/169
Findings: 2
Award: $49.76
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: 0xNineDec
Also found by: 0xBeirao, 0xNazgul, 0xRajkumar, Blockian, Breeje, CRYP70, Josiah, KIntern_NA, MyFDsYours, Qeew, RaymondFam, Ruhum, UdarTeam, chaduke, giovannidisiena, gjaldon, immeas, koxuan, nadin, peanuts, rbserver, rvi0x, savi0ur
14.2839 USDC - $14.28
Detailed description of the impact of this finding.
The price of ERC4626 vault shares can be maliciously inflated during the first deposit, leading to the loss of assets for next depositors
Provide direct links to all referenced code in GitHub. Add screenshots, logs, or any other relevant proof that illustrates the concept.
Given a vault with DAI as the underlying asset:
Alice (attacker) deposits initial liquidity of 1 wei DAI via deposit() Alice receives 1e18 (1 wei) vault shares Alice transfers 1 ether of DAI via transfer() to the vault to artificially inflate the asset balance without minting new shares. The asset balance is now 1 ether + 1 wei DAI -> vault share price is now very high (= 1000000000000000000001 wei ~ 1000 * 1e18) Bob (victim) deposits 100 ether DAI Bob receives 0 shares Bob receives 0 shares due to a precision issue. His deposited funds are lost.
The shares are calculated as following return supply == 0 ? assets : assets.mulDivDown(supply, totalAssets()); In case of a very high share price, due to totalAssets() > assets * supply, shares will be 0.
Manual Review
This is a well-known issue, Uniswap and other protocols had similar issues when supply == 0.
For the first deposit, mint a fixed amount of shares, e.g. 10**decimals()
if (supply == 0) { return 10**decimals; } else { return assets.mulDivDown(supply, totalAssets()); }
#0 - c4-judge
2023-02-16T03:31:09Z
dmvt marked the issue as duplicate of #15
#1 - c4-sponsor
2023-02-18T11:54:52Z
RedVeil marked the issue as sponsor confirmed
#2 - c4-judge
2023-02-23T00:37:46Z
dmvt marked the issue as partial-50
#3 - c4-judge
2023-02-23T01:05:29Z
dmvt changed the severity to 3 (High Risk)
#4 - c4-judge
2023-03-01T00:40:58Z
dmvt marked the issue as satisfactory