Skip to content
Business logic Audit finding Advanced

Global position-fee-related state not updated until _after_ liquidation checks are done

In the GMX Synthetics decrease-position flow, the global funding and borrowing state is refreshed only after the liquidation eligibility check runs. A position that should be liquidatable in the current block may therefore pass the check and only become liquidatable in a later block, delaying liquidation and potentially increasing losses.

IllIllI Follow

Originally disclosed on Sherlock

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

Found by

IllIllI

Summary

Global position-fee-related state not updated until after liquidation checks are done

Vulnerability Detail

Checking whether a position is liquidatable occurs before the global state is updated.

Impact

A position that should be liquidated in the current block, won't be liquidated until the next block, when the correct fee multipliers/factors are applied. A delayed liquidation means that a position that should have been liquidated will not be, likely causing a larger loss than should have been incurred.

Code Snippet

State is updated after the liquidation checks:

Solidity
// File: gmx-synthetics/contracts/position/DecreasePositionUtils.sol : DecreasePositionUtils.decreasePosition()   #1

162 @>         if (BaseOrderUtils.isLiquidationOrder(params.order.orderType()) && !PositionUtils.isPositionLiquidatable(
163                params.contracts.dataStore,
164                params.contracts.referralStorage,
165                params.position,
166                params.market,
167                cache.prices,
168                true
169            )) {
170                revert PositionShouldNotBeLiquidated();
171            }
172    
173:@>         PositionUtils.updateFundingAndBorrowingState(params, cache.prices);

https://github.com/sherlock-audit/2023-02-gmx/blob/main/gmx-synthetics/contracts/position/DecreasePositionUtils.sol#L152-L179

Tool used

Manual Review

Recommendation

Call PositionUtils.updateFundingAndBorrowingState() before all checks

Discussion

xvi10

Fix in https://github.com/gmx-io/gmx-synthetics/commit/0821228d2333b5a689d9361bafa806f51c56fbc1

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

Root cause

Likely the liquidation check is performed before the funding and borrowing state is updated, so it evaluates the position against outdated global fee factors.

Impact

A position that should be liquidated in the current block is not liquidated until the next block, which could cause a larger loss than necessary.

What the attacker needed

A position eligible for liquidation; liquidation processed in the same block

The fix

The funding and borrowing state should be updated before all liquidation checks; the report links a fix commit.

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 liquidation check decides whether a trading position has fallen below the safety threshold and should be closed by the protocol. Here that check used slightly stale global fee and borrowing figures, because those figures were refreshed only afterwards. So a position that was actually unsafe could slip through and be closed later, when the loss may be bigger.

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.