Fee receiver does not get paid when collateral is enough to cover the funding fee, during liquidation
When a position is liquidated and the remaining collateral is enough to cover the funding fee, the fee receiver's portion of position fees is not paid. Instead, all remaining collateral is given to the pool, so the fee receiver loses its share.
Source: https://github.com/sherlock-audit/2023-02-gmx-judging/issues/146
Found by
IllIllI
Summary
When a position is liquidated, and there is enough collateral to cover the outstanding funding fee, the fee receiver does not get paid its fee
Vulnerability Detail
All of the remaining collateral is given to the pool, rather than paying the portion of position fees owed to the fee receiver
Impact
Fee receiver does not get paid its share, which is instead given to the pool
Code Snippet
The PnL funds are all given to the pool, and the _fees variable, which contains the fee receiver portion remains uninitialized.
// File: gmx-synthetics/contracts/position/DecreasePositionCollateralUtils.sol : DecreasePositionCollateralUtils.getLiquidationValues() #1
346 } else {
347 @> values.pnlAmountForPool = (params.position.collateralAmount() - fees.funding.fundingFeeAmount).toInt256();
348 }
349
350 @> PositionPricingUtils.PositionFees memory _fees;
351
352 PositionUtils.DecreasePositionCollateralValues memory _values = PositionUtils.DecreasePositionCollateralValues(
353 values.pnlTokenForPool,
354 values.executionPrice, // executionPrice
355 0, // remainingCollateralAmount
356 values.positionPnlUsd, // positionPnlUsd
357 @> values.pnlAmountForPool, // pnlAmountForPool
358 0, // pnlAmountForUser
359 values.sizeDeltaInTokens, // sizeDeltaInTokens
360 values.priceImpactAmount, // priceImpactAmount
361 0, // priceImpactDiffUsd
362 0, // priceImpactDiffAmount
363 PositionUtils.DecreasePositionCollateralValuesOutput(
364 address(0),
365 0,
366 address(0),
367 0
368 )
369 );
370
371 @> return (_values, _fees);
372: }
The empty fees are returned, and the function exits, skipping the paying of the fee receiver's portion of the position fees that are owed.
Tool used
Manual Review
Recommendation
Split the fees properly in getLiquidationValues() and don't return early after the call to getLiquidationValues()
Discussion
xvi10
this is a valid concern, but we do not think that the contracts should be changed for it, for simplicity the fee receiver does not receive a fee for this case
IllIllI000
I'm leaving this open since the fees are not paid
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 liquidation function returns early with an uninitialized fee structure, so the fee receiver's portion is never calculated or paid.
Impact
The fee receiver does not receive its share of the fees; the amount is instead added to the pool.
What the attacker needed
Position is liquidated; collateral covers funding fee
The fix
The code should split the fees properly in the liquidation calculation and not return early after that calculation.
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.
In a trading system, when a trader's position is closed out because it lost too much money (liquidation), any leftover collateral is supposed to be split between the pool and a fee receiver. Here, the code skips paying the fee receiver and sends everything to the pool, so the fee receiver gets nothing.
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.