Skip to content
Business logic Audit finding Advanced

State-price mismatch in liquidation

The liquidation function values a user's collateral using a stale stored interest figure while valuing their debt with interest calculated up to the current block, so the user's net worth is underestimated. This can cause the protocol to overstate its loss and revoke premiums from sellers, and can underpay liquidators.

devdragon Follow with merlinboii

Originally disclosed on Code4rena

Submitted by devdragon, also found by merlinboii

In PanopticPool._liquidate, the protocol evaluates the liquidatee’s collateral and debt to determine the liquidation bonus and potential protocol loss. However, there is a fundamental accounting mismatch in how these values are calculated:

1. Stale asset valuation:

When a liquidator calls PanopticPool._liquidate, the protocol immediately checks the liquidatee’s margin.

contracts/PanopticPool.sol

1482:    function _liquidate(
...
1503:            (tokenData0, tokenData1, ) = riskEngine().getMargin(
...
1510:                collateralToken0(),
1511:                collateralToken1()
1512:            );

Inside getMargin, the RiskEngine calls assetsAndInterest(user) on the CollateralTracker.

contracts/CollateralTracker.sol

1091:    function assetsAndInterest(address owner) external view returns (uint256, uint256) {
1092:        return (convertToAssets(balanceOf[owner]), _owedInterest(owner));
1093:    }

CollateralTracker.assetsAndInterest calculates the user’s collateral balance using convertToAssets. This function relies on totalAssets(), which is defined as:

    return uint256(s_depositedAssets) + s_assetsInAMM + s_marketState.unrealizedInterest();

The unrealizedInterest here is a stored value that is only updated during state-modifying _accrueInterest calls. If several blocks have passed since the last interaction, this value is significantly lower than the actual interest accrued by the pool.

2. Fresh Debt Valuation:

In the same call, assetsAndInterest retrieves the user’s debt via _owedInterest. Unlike the asset calculation, this function simulates the global borrow index up to the current block timestamp:

(uint128 currentBorrowIndex, , ) = _calculateCurrentInterestState(
    s_assetsInAMM,
    _interestRateView(_poolUtilizationWadView())
);

This ensures the debt is “Price-Fresh.”

3. The Mismatch:

Because the debt is updated to the current second but the pool’s assets (which include that debt) are not, the user’s share of the pool is undervalued. Essentially, the user is charged the full interest for the elapsed time, but they do not receive their proportional “credit” as a pool participant for that same interest in their collateral valuation.

Impact

This mismatch systematically underestimates the liquidatee’s net worth. In a liquidation:

  • Overestimated protocol loss: The protocol will believe the liquidatee is deeper in debt than they truly are. This directly triggers haircutPremia, where the protocol revokes premiums from honest sellers to cover a “loss” that doesn’t actually exist.
  • Systemic disincentive: Liquidators receive bonuses based on the available collateral. If the collateral is undervalued, liquidators are underpaid, which can lead to delayed liquidations during high-volatility events.

Recommended mitigation steps

Call accrueInterest(liquidatee) at the beginning of the _liquidate function in PanopticPool.sol. This ensures that both the global pool assets and the liquidatee’s specific balance are updated and synchronized before any valuation occurs.

Proof of Concept

Create PoC test file test/foundry/audit/LiquidationMismatch.t.sol and run forge test --match-path test/foundry/audit/LiquidationMismatch.t.sol -vvv:

View detailed Proof of Concept

Console output:

Logs:
  Valuation BEFORE Accrual:
    Assets (Stale Price): 50000000000000000000
    Interest (Fresh Debt): 1434795130794140900
    Net Position Value:   48565204869205859100

Valuation AFTER Accrual:
    Assets (Fresh Price): 48612850467710481715
    Interest (Fresh Debt): 0
    Net Position Value:   48612850467710481715

[!] BUG CONFIRMED: Mismatch hidden value of: 47645598504622615
  This discrepancy leads to overstated protocol losses and underpaid liquidators.

Panoptic commented:

We made the decision to maintain that protocol design choice (ie. the liquidator needs to call collateralToken.accrueInterest() manually to get the max possible bonus) and did not fix it.


The original report as published on Code4rena, by devdragon. 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

Impact

The protocol may overstate its loss and revoke premiums from honest sellers, and liquidators may be underpaid, which could delay liquidations during volatile periods; the project stated it chose not to fix this.

What the attacker needed

A position eligible for liquidation; several blocks since last interest accrual

The fix

The project decided to keep the design and did not fix it, so the suggested change is to accrue interest for the liquidatee at the start of the liquidation function.

How it was found

  1. Let several blocks pass since the last interest accrual so the stored interest figure is out of date.
  2. Call the liquidation function on a user whose position is being evaluated.
  3. Observe that the collateral is valued with the stale stored interest while the debt is valued with interest up to the current block.
  4. Compare the net position value before and after an explicit interest accrual to see the discrepancy.

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 lending pool, people deposit money and earn interest, while borrowers owe interest that grows over time. This report says that when checking whether a borrower should be liquidated, the system used an old, out-of-date figure for what the borrower's collateral was worth, but a fresh figure for what they owed. That made the borrower look poorer than they really were, which could cause the protocol to take fees from other users to cover a loss that did not exist.

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 from Panoptic: Next Core

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.