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: 33/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#L271-L282 https://github.com/code-423n4/2023-08-goodentry/blob/main/contracts/GeVault.sol#L392-L398 https://github.com/code-423n4/2023-08-goodentry/blob/main/contracts/GeVault.sol#L423
The deposit function in GeVault is vulnerable to inflation attack. The attacker can inflate the getTVL()
function by donating aTokens to GeVault. This allows the attacker to steal funds from the first depositor.
function deposit(address token, uint amount) public payable nonReentrant returns (uint liquidity) { .... 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; } rebalance(); require(liquidity > 0, "GEV: No Liquidity Added"); _mint(msg.sender, liquidity); emit Deposit(msg.sender, token, amount, liquidity); }
In the deposit
function, the vaultValueX8
variable is determined by the output of the getTVL
function. The vulnerability arises when an attacker uses the following steps:
vaultValueX8
returned from the getTVL
function by calling the underlying TokenisableRange::deposit
to mint aToken and donates it to GeVault.liquidity = tSupply * valueX8 / vaultValueX8
, where tSupply
is 2 wei and valueX8
is a known value, the attacker can inflate the vaultValueX8
to make the result approximately 1.9999 wei. This causes liquidity
to round down to 1 wei, resulting in the user losing the 0.9999 wei equivalent fund to the pool.Note this line won't protect the user,
require(liquidity > 0, "GEV: No Liquidity Added");
Manual review
After the GeVault is depolyed, mint a few liquidity and lock it.
Math
#0 - c4-pre-sort
2023-08-09T10:25:53Z
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:05Z
gzeon-c4 marked the issue as satisfactory