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: 164/169
Findings: 1
Award: $14.28
🌟 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
https://github.com/code-423n4/2023-01-popcorn/blob/main/src/vault/Vault.sol#L134-L158
The first depositor may not receive shares in exchange for their assets if their transaction is front-run and the total asset amount has been manipulated.
The amount of shares to mint in exchange for a given number of assets is calculated by:
uint256 supply = totalSupply(); return (supply == 0 ? assets : assets.mulDiv(supply, totalAssets(), Math.Rounding.Down) );
An attacker can exploit this by front-running the first depositor's transaction, depositing 1 wei of an asset and transferring a large number of tokens on behalf of the vault. This will cause the share price to be greatly inflated which can lead to rounding down of the victim's share calculation.
Example exploit steps:
AdapterBase::mint
with the vault contract as the receiver, transferring 100 WETHManual Review
As stated in other similar reports, one solution to this problem is to burn the first 1000 shares thereby increasing the cost to perform this attack by the same factor. Additionally, ensure the number of shares is non-zero to prevent an attacker from stealing all the funds in the case where subsequent deposits are less than Vault::totalAssets
:
require(shares != 0, "No shares minted");
#0 - c4-judge
2023-02-16T03:30:41Z
dmvt marked the issue as duplicate of #15
#1 - c4-sponsor
2023-02-18T11:54:45Z
RedVeil marked the issue as sponsor confirmed
#2 - c4-judge
2023-02-23T00:39:37Z
dmvt marked the issue as partial-50
#3 - c4-judge
2023-03-01T00:33:41Z
dmvt marked the issue as full credit
#4 - c4-judge
2023-03-01T00:42:59Z
dmvt marked the issue as satisfactory