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: 162/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#L147 https://github.com/code-423n4/2023-01-popcorn/blob/main/src/vault/Vault.sol#L293-L300
This is a well-known attack vector for contracts that utilize pricePerShare for accounting : users can loss their deposits.
https://github.com/code-423n4/2022-04-pooltogether-findings/issues/44
shares = convertToShares(assets) - feeShares;
/** * @notice Amount of shares the vault would exchange for given amount of assets, in an ideal scenario. * @param assets Exact amount of assets * @return Exact amount of shares */ function convertToShares(uint256 assets) public view returns (uint256) { uint256 supply = totalSupply(); // Saves an extra SLOAD if totalSupply is non-zero. return supply == 0 ? assets : assets.mulDiv(supply, totalAssets(), Math.Rounding.Down); }
A malicious early user can call deposit() with 1 wei as the first depositor of the Vault.sol contract and get 1 wei of shares token.
Then the attacker can send for example (100e18 - 1) directly to the contract without using the deposit function, and inflate the price per share from 1 to an extreme value of 100e18.
if a future user will deposit (100e18-1) token or less he will not receive any shares due to rounding calculation. He will immediately lose his deposit value.
Reading the code
Consider requiring a minimal amount of share tokens to be minted for the first minter, and send a fixed value of the initial mints as a reserve so that the pricePerShare can be more resistant to manipulation.
#0 - c4-judge
2023-02-16T03:30:36Z
dmvt marked the issue as duplicate of #15
#1 - c4-sponsor
2023-02-18T11:54:43Z
RedVeil marked the issue as sponsor confirmed
#2 - c4-judge
2023-02-23T00:39:59Z
dmvt marked the issue as partial-50
#3 - c4-judge
2023-03-01T00:33:02Z
dmvt marked the issue as full credit
#4 - c4-judge
2023-03-01T00:44:05Z
dmvt marked the issue as satisfactory