Skip to content
Business logic Audit finding Intermediate

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.

nemveer Follow with 0xBeirao, Hama and 2 others

Originally disclosed on Code4rena

Submitted by nemveer, also found by 0xBeirao, Hama, n33k, and Madalad

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.

GeVault.deposit#L271-L278

    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;
    }

GeVault.getTVL#L392-L398

  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.

  1. 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.
  2. Withdraw all except one wei of shares.
  3. 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

  1. Almost 1/4th of first deposit can be frontrun and stolen.
  2. Let’s assume there is a first user trying to deposit with z dollars worth of tokens
  3. An attacker can see this transaction in mempool and carry out the above-described attack with x = (z/2 + 1).
  4. This means the user gets 1 Wei of share which is only worth ~ 3x/4 of tokens.
  5. 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.
  6. 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


The original report as published on Code4rena, by nemveer. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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.

More by nemveer

View all

19 more disclosed reports, best first.

More from Good Entry

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.