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: 30/80
Findings: 1
Award: $325.23
π Selected for report: 1
π Solo Findings: 0
325.2267 USDC - $325.23
https://github.com/code-423n4/2023-08-goodentry/blob/71c0c0eca8af957202ccdbf5ce2f2a514ffe2e24/contracts/GeVault.sol#L271-L278 https://github.com/code-423n4/2023-08-goodentry/blob/71c0c0eca8af957202ccdbf5ce2f2a514ffe2e24/contracts/GeVault.sol#L420-L424
In GeVault, while depositing tokens in the pool, liquidity tokens are minted to the users.
Calculation of liquidity tokens to mint uses balanceOf(address(this))
which makes it susceptible to first deposit share price manipulation attack.
deposit
calls getTVL
, which calls getTickBalance
uint vaultValueX8 = getTVL(); uint tSupply = totalSupply(); // initial liquidity at 1e18 token ~ $1 if (tSupply == 0 || vaultValueX8 == 0) liquidity = valueX8 * 1e10; else { liquidity = tSupply * valueX8 / vaultValueX8; }
function getTVL() public view returns (uint valueX8){ for(uint k=0; k<ticks.length; k++){ TokenisableRange t = ticks[k]; uint bal = getTickBalance(k); valueX8 += bal * t.latestAnswer() / 1e18; } }
GeVault.getTickBalance#L420-L424
function getTickBalance(uint index) public view returns (uint liquidity) { TokenisableRange t = ticks[index]; address aTokenAddress = lendingPool.getReserveData(address(t)).aTokenAddress; liquidity = ERC20(aTokenAddress).balanceOf(address(this)); }
Although there is a condition on line 281
that liquidity to be minted must be greater than 0, User's funds can be at risk.
When totalSupply is zero, an attacker can go ahead and execute following steps.
Impact
require(liquidity > 0, "GEV: No Liquidity Added");
Manual Review
Math
#0 - c4-pre-sort
2023-08-09T09:47:10Z
141345 marked the issue as primary issue
#1 - 141345
2023-08-09T09:47:56Z
medium might be more appropriate
#2 - c4-sponsor
2023-08-15T00:46:20Z
Keref marked the issue as sponsor disputed
#3 - c4-sponsor
2023-08-15T00:48:05Z
Keref marked the issue as sponsor acknowledged
#4 - c4-sponsor
2023-08-15T00:50:32Z
Keref marked the issue as sponsor confirmed
#5 - c4-sponsor
2023-08-15T00:50:38Z
Keref marked the issue as disagree with severity
#6 - c4-sponsor
2023-08-17T09:31:08Z
Keref marked the issue as sponsor disputed
#7 - c4-sponsor
2023-08-17T09:32:16Z
Keref marked the issue as sponsor confirmed
#8 - Keref
2023-08-17T09:36:01Z
Issue is medium severity as easily preventable and only affects GE team when deploying a new vault
#9 - c4-judge
2023-08-19T16:20:45Z
gzeon-c4 changed the severity to 2 (Med Risk)
#10 - c4-judge
2023-08-19T16:20:50Z
gzeon-c4 marked the issue as satisfactory
#11 - c4-judge
2023-08-19T16:21:56Z
gzeon-c4 marked the issue as selected for report