Skip to content
Business logic Audit finding Intermediate

Hedging during liquidation is incorrect

During liquidation of a short position, the Exchange contract burns power perp tokens and reduces the short position, but also calls the LiquidityPool's liquidate function, which hedges the pool by the same amount. This causes the LiquidityPool to be over-hedged, leading to an incorrect position and potential loss of funds.

KIntern_NA Follow

Originally disclosed on Code4rena

Submitted by KIntern_NA

Hedging will not work as expected, and LiquidityPool will lose funds without expectation.

Proof of concept

  1. When a short position is liquidated in contract Exchange, function _liquidate will be triggered. It will burn the power perp tokens and reduce the short position amount accordingly.
function _liquidate(uint256 positionId, uint256 debtRepaying) internal {
    ...
    uint256 finalPosition = position.shortAmount - debtRepaying;
    uint256 finalCollateralAmount = position.collateralAmount - totalCollateralReturned;

    shortToken.adjustPosition(positionId, user, position.collateral, finalPosition, finalCollateralAmount);

    pool.liquidate(debtRepaying);
    powerPerp.burn(msg.sender, debtRepaying);
    ...
  1. As you can see, it will decrease the size of short position by debtRepaying, and burn debtRepaying power perp tokens. Because of the same amount, the skew of LiquidityPool will not change.
  2. Howerver, pool.liquidate will be called, and LiquidityPool will be hedged with debtRepaying amount.
function liquidate(uint256 amount) external override onlyExchange nonReentrant {
    (uint256 markPrice, bool isInvalid) = getMarkPrice();
    require(!isInvalid);

    uint256 hedgingFees = _hedge(int256(amount), true);
    usedFunds += int256(hedgingFees);

    emit Liquidate(markPrice, amount);
}
  1. Therefore, LiquidityPool will be hedged more than it needs, and the position of LiquidityPool in the Perp Market will be incorrect (compared with what it should be for hedging).

Recommended Mitigation Steps

Should not hedge the LiquidityPool during liquidation.

mubaris (Polynomial) confirmed


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

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

The liquidation function in the Exchange contract calls the LiquidityPool's liquidate function, which hedges the pool, even though the short position is reduced by the same amount, so the pool's hedge becomes misaligned.

Impact

The LiquidityPool could lose funds because it is over-hedged, leading to an incorrect position in the Perp Market.

What the attacker needed

A short position exists; the short position becomes liquidatable

The fix

The LiquidityPool should not hedge during liquidation.

How it was found

  1. A short position is liquidated in the Exchange contract, triggering the _liquidate function.
  2. The _liquidate function reduces the short position by debtRepaying and burns debtRepaying power perp tokens.
  3. The _liquidate function calls pool.liquidate(debtRepaying), which hedges the LiquidityPool by debtRepaying amount.
  4. As a result, the LiquidityPool is hedged more than necessary, making its position in the Perp Market incorrect.

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 liquidity pool is supposed to hedge its risk by taking an opposite position in a market. When someone's short position is liquidated, the pool also adjusts its hedge, but it does so by the same amount as the liquidation, even though the short position was already reduced. This double-counting makes the pool's hedge too large, which can lose money for the pool.

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 KIntern_NA

View all

21 more disclosed reports, best first.

More from Polynomial Protocol contest

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.