Skip to content
Business logic Audit finding Intermediate

GTELaunchpadV2Pair::burn over-estimates distribution amounts when there are non-zero accrued launchpad fees

The burn function in GTELaunchpadV2Pair calculates token distribution amounts using the contract's total balances, which include accrued launchpad fees owed to the distributor. An attacker can repeatedly mint and burn LP tokens to claim a portion of these fees, potentially draining almost all liquidity from the pair.

hgrano Follow with 0rpse, 0xnija and 11 others

Originally disclosed on Code4rena

Submitted by hgrano, also found by 0rpse, 0xnija, AasifUsmani, AvantGard, codegpt, IvanAlexandur, KuwaTakushi, nachin, saraswati, serial-coder, Web3Vikings, Willi-I-Am, and ZeroEx

launchpad/uniswap/GTELaunchpadV2Pair.sol #L217-L218

When burning LP tokens, the GTELaunchpadV2Pair contract calculates the amounts of base/quote tokens to distribute based on the current balances (lines 217-218):

        amount0 = liquidity.mul(balance0) / _totalSupply; // using balances ensures pro-rata distribution
        amount1 = liquidity.mul(balance1) / _totalSupply; // using balances ensures pro-rata distribution

This seems ok but the problem is that the balances will also include accrued launchpad fees, which are owed to the distributor, so liquidity providers should have no claim over these fees. Furthermore, when minting, the amount of liquidity to mint is calculated based on reserves, not balances - and reserves will always have accrued launchpad fees deducted from them.

We see this on GTELaunchpadV2Pair.sol:196:

            liquidity = Math.min(amount0.mul(_totalSupply) / _reserve0, amount1.mul(_totalSupply) / _reserve1);

An attacker can do the following in a single transaction:

  1. Perform swap(s) to ensure the accrued launchpad fees are non-zero.
  2. Mint LP tokens.
  3. Burn their LP tokens and capture a profit due to the fact they have a claim on a portion of the contract balances not contract reserves.
  4. Repeat steps 2-3 many times to increase their profit.

Impact: theft of funds from the pair contract. Given it can be repeated at will by the attacker, this could lead to theft of almost all liquidity from the pair.

Recommended mitigation steps

When calculating the amounts to distribute when burning LP tokens, make sure to deduct any accrued launchpad fees from the balances as shown:

--- a/contracts/launchpad/uniswap/GTELaunchpadV2Pair.sol
+++ b/contracts/launchpad/uniswap/GTELaunchpadV2Pair.sol
@@ -214,8 +214,8 @@ contract GTELaunchpadV2Pair is IUniswapV2Pair, IGTELaunchpadV2Pair, UniswapV2ERC

         bool feeOn = _mintFee(_reserve0, _reserve1);
         uint256 _totalSupply = totalSupply; // gas savings, must be defined here since totalSupply can update in _mintFee
-        amount0 = liquidity.mul(balance0) / _totalSupply; // using balances ensures pro-rata distribution
-        amount1 = liquidity.mul(balance1) / _totalSupply; // using balances ensures pro-rata distribution
+        amount0 = liquidity.mul(balance0 - accruedLaunchpadFee0) / _totalSupply; // using balances ensures pro-rata distribution
+        amount1 = liquidity.mul(balance1 - accruedLaunchpadFee1) / _totalSupply; // using balances ensures pro-rata distribution

View detailed Proof of Concept


The original report as published on Code4rena, by hgrano. 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

Root cause

The burn function uses the contract's total balances (which include accrued launchpad fees) instead of the reserves (which exclude those fees) to calculate pro-rata distribution amounts.

Impact

The attacker can steal funds from the pair contract, and by repeating the attack could steal almost all liquidity from the pair.

What the attacker needed

Accrued launchpad fees are non-zero; attacker can mint and burn LP tokens

The fix

The burn function should deduct accrued launchpad fees from the balances before calculating distribution amounts.

How it was found

  1. Perform swap(s) to ensure the accrued launchpad fees are non-zero.
  2. Mint LP tokens.
  3. Burn their LP tokens and capture a profit due to the fact they have a claim on a portion of the contract balances not contract reserves.
  4. Repeat steps 2-3 many times to increase their profit.

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.

This is a smart contract bug in a liquidity pool. When you remove your money (burn LP tokens), the contract gives you a share based on the total money in the pool, but that total includes fees that belong to someone else. So you get more than you should, and by repeating the process you can steal funds from the pool.

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 hgrano

View all

10 more disclosed reports, best first.

More from GTE Perps and Launchpad

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.