Protocol fails to charge fees from swap amount
The GTE launchpad pair contract's swap function does not actually deduct the swap fee from the transferred amounts, so the fee is never charged. An attacker could perform swaps without paying fees, causing liquidity providers to lose the fees they should earn.
ifex445 Follow with 0rpse, anchabadze and 4 others
Originally disclosed on Code4rena
Submitted by ifex445, also found by 0rpse, anchabadze, dimulski, hezze, IvanAlexandur, and nuthan2x
launchpad/uniswap/GTELaunchpadV2Pair.sol #L231
The GTE uniswap contract fails to charge fee for swaps and update balAdjusted by fees charged. This would allow users execute free swaps making LP providers lose rewards/fees for providing liquidity to the protocol.
function swap(uint256 amount0Out, uint256 amount1Out, address to, bytes calldata data) external lock {
if (amount0Out == 0 && amount1Out == 0) revert("UniswapV2: INSUFFICIENT_OUTPUT_AMOUNT");
(uint112 _reserve0, uint112 _reserve1,) = getReserves(); // gas savings
if (amount0Out >= _reserve0 || amount1Out >= _reserve1) revert("UniswapV2: INSUFFICIENT_LIQUIDITY");
uint256 balance0;
uint256 balance1;
{
// scope for _token{0,1}, avoids stack too deep errors
address _token0 = token0;
address _token1 = token1;
if (to == _token0 || to == _token1) revert("UniswapV2: INVALID_TO");
@> if (amount0Out > 0) _safeTransfer(_token0, to, amount0Out); // optimistically transfer tokens
if (amount1Out > 0) _safeTransfer(_token1, to, amount1Out); // optimistically transfer tokens
if (data.length > 0) IUniswapV2Callee(to).uniswapV2Call(msg.sender, amount0Out, amount1Out, data);
balance0 = IERC20(_token0).balanceOf(address(this));
balance1 = IERC20(_token1).balanceOf(address(this));
}
uint256 amount0In = balance0 > _reserve0 - amount0Out ? balance0 - (_reserve0 - amount0Out) : 0;
uint256 amount1In = balance1 > _reserve1 - amount1Out ? balance1 - (_reserve1 - amount1Out) : 0;
if (amount0In == 0 && amount1In == 0) revert("UniswapV2: INSUFFICIENT_INPUT_AMOUNT");
{
// scope for reserve{0,1}Adjusted and launchpadFee{0,1}, avoids stack too deep errors
@> uint256 balance0Adjusted = balance0.mul(1000).sub(amount0In.mul(3));
@> uint256 balance1Adjusted = balance1.mul(1000).sub(amount1In.mul(3));
As we can see in the pointer neither is the fee charge from the transfer of the swap or balance adjusted, the protocol goes ahead to include launchpad fees without backed transfer. This would break the balance of the pool as protocol assumes the fee was charged so it goes on to update pool variables with unbacked launchpad fees.
Impact
Loss of fees for GTE pool
Recommended mitigation steps
Charge fees for swaps.
View detailed Proof of Concept
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
Likely the swap function computes adjusted balances using a fee formula but never transfers or deducts the fee amount from the swap, so the fee is only assumed rather than collected.
Impact
Liquidity providers lose the swap fees they should receive, and the pool's accounting is updated with fees that were never actually paid.
What the attacker needed
None
The fix
The swap function should actually charge and collect the fee from the swap amount before updating the pool balances.
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.
A liquidity pool is a shared pot of two tokens that people trade against. Normally each trade pays a small fee that goes to the people who put tokens in the pot. Here the code calculates the fee but never actually takes it from the trader, so traders can swap for free and the pool's owners lose that income.
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.