Platform: Code4rena
Start Date: 01/08/2023
Pot Size: $91,500 USDC
Total HM: 14
Participants: 80
Period: 6 days
Judge: gzeon
Total Solo HM: 6
Id: 269
League: ETH
Rank: 34/80
Findings: 1
Award: $250.17
🌟 Selected for report: 0
🚀 Solo Findings: 0
250.1744 USDC - $250.17
https://github.com/code-423n4/2023-08-goodentry/blob/main/contracts/GeVault.sol#L273
The smart contract's deposit function is vulnerable to a first depositor exploit, allowing the initial depositor to manipulate the liquidity calculation and potentially steal funds from later depositors. By artificially inflating the valueX8 parameter during the first deposit, the first depositor can receive a disproportionately large number of liquidity tokens. This manipulation can adversely impact the liquidity pool's stability and fairness, leading to a loss of funds for subsequent depositors and potential financial harm to the entire pool.
/// @notice deposit tokens in the pool, convert to WETH if necessary function deposit(address token, uint amount) public payable nonReentrant returns (uint liquidity) { ... // initial liquidity at 1e18 token ~ $1 if (tSupply == 0 || vaultValueX8 == 0) liquidity = valueX8 * 1e10; else { liquidity = tSupply * valueX8 / vaultValueX8; } .. }
By depositing a minimal amount of weth, such as 1 wei, the attacker mints 1 valueX8 token for themselves. Subsequently, the attacker can donate a substantial amount of weth, for example, , to the protocol reserve.However, the contract fails to recalculate the total supply of X8 tokens after the donation, resulting in the total supply remaining at 1 X8 while the reserve amount is significantly inflated. As a result, the attacker's 1 X8 token represents a disproportionately large share in the inflated reserve, potentially diluting the share value of later depositors.
Manual review
Either during creation of the vault or for first depositor, lock a small amount of the deposit to avoid this.
Token-Transfer
#0 - c4-pre-sort
2023-08-09T15:37:23Z
141345 marked the issue as duplicate of #367
#1 - c4-judge
2023-08-19T16:20:43Z
gzeon-c4 changed the severity to 2 (Med Risk)
#2 - c4-judge
2023-08-20T17:14:04Z
gzeon-c4 marked the issue as satisfactory