First depositor can break minting of liquidity shares in GeVault
The vault's share minting uses the contract's token balance, so the first depositor can inflate the share price by donating tokens directly. An attacker can front-run a victim's deposit to steal most of their funds or cause a denial of service for small deposits.
Submitted by nemveer, also found by 0xBeirao, Hama, n33k, and Madalad
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.
Proof of Concept
When totalSupply is zero, an attacker can go ahead and execute following steps.
- Calls deposit function with 1 wei amount of underlying as argument. To that, he will be minted some amount of liquidity share depending on the price of underlying.
- Withdraw all except one wei of shares.
- Transfer some X amount of underlying directly to pool contract address.
So, now 1 wei of share worths X underlying tokens. Attacker won’t have any problem making this X as big as possible. Because he’ll always be able to redeem it with 1 wei of share.
Impact
- Almost 1/4th of first deposit can be frontrun and stolen.
- Let’s assume there is a first user trying to deposit with z dollars worth of tokens
- An attacker can see this transaction in mempool and carry out the above-described attack with x = (z/2 + 1).
- This means the user gets 1 Wei of share which is only worth ~ 3x/4 of tokens.
- Here, the percentage of the user funds lost depends on how much capital the attacker has. let’s say a attacker keeps 2 wei in the share initially instead of 1 (this makes doubles capital requirement), they can get away with 33% of the user’s funds.
- DOS to users who tries to deposit less than X because of this check
require(liquidity > 0, "GEV: No Liquidity Added");
Recommended Mitigation Steps
Burn some MINIMUM_LIQUIDITY during first deposit.
Keref (Judge) confirmed, but disagreed with severity and commented:
Issue is medium severity as easily preventable and only affects GE team when deploying a new vault.
gzeon (Judge) decreased severity to Medium
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Impact
An attacker can front-run a victim's first deposit to steal up to about a quarter of the funds, or cause a denial of service for deposits smaller than the inflated share price.
What the attacker needed
Vault has no existing shares; attacker has capital to donate; attacker can front-run victim's deposit
The fix
Burn a minimum amount of liquidity shares during the first deposit.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When you put money into a shared vault, you get shares representing your portion. The vault calculates share value from its total token balance, which an attacker can inflate by sending tokens directly to the vault before anyone else deposits. This makes each share very expensive, so a victim's deposit buys almost no shares, and the attacker can later withdraw the inflated value.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.