DeFiFoundry
50,000 USDC
View results
Submission Details
Severity: low
Invalid

Lack of Deleveraging Mechanism Leads to Increased Liquidation Risk Due to GMX's Negative Funding Fees

Summary

The PerpetualVault contract lacks a deleveraging mechanism to handle increasing position leverage caused by GMX's negative funding fees being charged against collateral. As collateral decreases while position size remains constant, the effective leverage increases over time, potentially leading to liquidations if not monitored and adjusted.

Vulnerability Details

The contract allows users to open and maintain a leveraged position on GMX with a specified leverage value set during initialization. However, GMX charges negative funding fees by reducing the collateral amount over time, which creates two key issues:

  1. The effective leverage increases as collateral decreases:

// Example:
Initial State:
Position Size: $1000
Collateral: $100
Leverage = 10x
After Negative Funding Fees:
Position Size: $1000 (unchanged)
Collateral: $80 (reduced)
Effective Leverage = 12.5x
  1. The contract lacks safety mechanisms:

contract PerpetualVault {
uint256 public leverage; // Set once during initialization
// No maximum leverage checks
// No automatic deleveraging
// No safety margin requirements
}

There's currently no way to

  • Partially reduce position size

  • Adjust leverage without closing

  • Gradually deleverage positions

Note that the run and runNextAction responsible for creating GMX orders can only:

  • Open a new position when closed

  • Close an existing position completely

  • Switch position direction (close then reopen)

  • Decrease position size and collateral together

Other Causes

Also, note that the the GMX max leverage constantly decreases as open interest increases, effectively increasing our risks exposure. But unfortunately we have no mechanism to adjust our derisk our Position.

Proof of Concept

  1. User opens a 10x leveraged long position with $100 collateral

  2. GMX charges -$20 in funding fees over time, reducing collateral to $80

  3. Position size remains at $1000

  4. Effective leverage increases to 12.5x

  5. This continues until potential liquidation

  6. No automatic mechanism exists to reduce position size or add only collateral

Impact Details

High risk of user positions being liquidated due to uncontrolled leverage increase leading to loss of user funds.

Tools Used

Manual Review

Recommendations

Implement automatic deleveraging mechanism:

function checkAndDeleverage() internal {
uint256 currentLeverage = getEffectiveLeverage();
uint256 maxAllowedLeverage = leverage + LEVERAGE_BUFFER;
if (currentLeverage > maxAllowedLeverage) {
uint256 excess = currentLeverage - maxAllowedLeverage;
reducePositionSize(excess);
}
}
Updates

Lead Judging Commences

n0kto Lead Judge 7 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Informational or Gas

Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelihood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.