Skip to content
Business logic Audit finding Intermediate

Liquidation shouldn't be used to close positions that were fully-collateralized prior to collateral requirement changes

A position that was fully collateralised before a change to the minimum collateral requirement can become liquidatable if the minimum is increased, even if the position is in profit. Liquidation then gives all remaining funds to the pool and nothing to the user.

IllIllI Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-02-gmx-judging/issues/179

Found by

IllIllI

Summary

There are various factors associated with minimum collateral requirements, and if a position falls below them, the position is liquidated.

Vulnerability Detail

If the position was over-collateralized and in profit prior to the change in the minimums, and the minimum is increased, the position is liquidated.

Impact

Liquidation gives all funds to the pool, giving nothing back to the user

Code Snippet

A position becomes liquidatable once it falls below the changeable collateral requirements:

Solidity
// File: gmx-synthetics/contracts/position/PositionUtils.sol : PositionUtils.isPositionLiquidatable()   #1

377            if (shouldValidateMinCollateralUsd) {
378 @>             cache.minCollateralUsd = dataStore.getUint(Keys.MIN_COLLATERAL_USD).toInt256();
379                if (cache.remainingCollateralUsd < cache.minCollateralUsd) {
380                    return true;
381                }
382            }
383    
384            if (cache.remainingCollateralUsd <= 0) {
385                return true;
386            }
387    
388:           // validate if (remaining collateral) / position.size is less than the min collateral factor (max leverage exceeded)

https://github.com/sherlock-audit/2023-02-gmx/blob/main/gmx-synthetics/contracts/position/PositionUtils.sol#L368-L388

Liquidations give everything to the pool, and nothing to the position's account

Tool used

Manual Review

Recommendation

Close the position with a market order, rather than liquidating it, if the user was previously above the minimum with the old factor

Discussion

xvi10

the min collateral requirements should not be changed unless it is an emergency requirement

this setting should eventually be removed from the Config contract

IllIllI000

@xvi10, while it may be for emergency use, if it does end up being used, isn’t the current behavior incorrect? Should this be a no-fix?

xvi10

yes, updated to confirmed

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

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

A user with a healthy, profitable position could lose all their remaining collateral to the pool if the minimum collateral requirement is increased.

What the attacker needed

Minimum collateral requirement is increased; position was fully collateralised before change

The fix

The position should be closed with a market order rather than liquidated if the user was previously above the minimum with the old factor.

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, a position is like a bet that needs a certain amount of money set aside as a safety buffer. If the rules for that buffer change and the required amount goes up, a position that was previously safe can suddenly be considered unsafe and get closed out. The problem is that when this happens, the system takes all the remaining money for itself instead of giving it back to the trader.

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 IllIllI

View all

119 more disclosed reports, best first.

More from GMX Update

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.