The flaw in PerpetualVault.sol could lead to incorrect redistribution of bad debt during liquidations. If a liquidation event creates bad debt, but the system fails to properly account for and distribute this debt in subsequent liquidation cycles, the remaining debt may not be correctly reallocated.
As a result, instead of ensuring that bad debt is covered efficiently, subsequent liquidations may only partially account for the debt. This leads to smaller amounts of debt being liquidated per event, while cdp (collateralized debt position) owners may receive a disproportionately larger share of collateral. The issue can result in systemic risk where bad debt accumulates over time, potentially affecting the solvency of the protocol.
Function: afterLiquidationExecution()
Location: PerpetualVault.sol
Problem:
This function is called when a liquidation occurs.
If a position has bad debt, it is not explicitly handled here.
Instead, sizeInTokens is checked, but this does not account for uncovered debt remaining after liquidation.
Solution needed: Ensure bad debt is accounted for and redistributed effectively.
Function: _handleReturn()
Location: PerpetualVault.sol
Problem:
This function determines how collateral is returned after liquidation or withdrawal.
However, it does not adjust for bad debt properly.
If the position had insufficient collateral, the remaining debt is not redistributed to future liquidations or covered by the protocol.
Function: afterOrderExecution()
Location: GmxProxy.sol
Problem:
This function processes order execution results, including liquidations.
However, bad debt is not properly addressed.
If liquidation results in a shortfall, the debt is not transferred or compensated by the system.
Scenario:
User A deposits 10,000 USDC into PerpetualVault.sol.
User A opens a long position with 5x leverage.
The market price drops significantly, and User A’s position is liquidated.
Due to price slippage and fees, only 7,000 USDC of collateral is recovered, but the total debt was 9,000 USDC.
Bad debt of 2,000 USDC remains, but is not redistributed.
Subsequent liquidations fail to account for this, leading to:
Liquidators receiving excess collateral.
The protocol accumulating bad debt, risking insolvency.
Severity: HIGH
This issue poses a serious risk to the protocol’s financial stability and should be fixed immediately. If left unresolved, the protocol could become undercollateralized, leading to potential insolvency and loss of user trust.
Manual Review
Modify _handleReturn() in PerpetualVault.sol
Implement _redistributeDebt()
There is no real proof, concrete root cause, specific impact, or enough details in those submissions. Examples include: "It could happen" without specifying when, "If this impossible case happens," "Unexpected behavior," etc. Make a Proof of Concept (PoC) using external functions and realistic parameters. Do not test only the internal function where you think you found something.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.