Skip to content
Smart contracts Audit finding Advanced

Cross-contract reentrancy in liquidation enables conversion of phantom shares to real shares, draining CollateralTracker assets

A cross-contract reentrancy flaw in the liquidation process lets a malicious liquidator transfer phantom shares from the liquidatee to themselves before the second collateral tracker revokes them. The attacker can then redeem these shares for real assets, draining the CollateralTracker vault.

ht111111 Follow with edoscoba, fullstop and 4 others

Originally disclosed on Code4rena

Submitted by ht111111, also found by edoscoba, fullstop, johnyfwesh, legat, qed, and VulSight

CollateralTracker.sol L1359-L1360

Impact

A malicious liquidator can exploit a cross-contract reentrancy vulnerability during the liquidation process to steal “phantom shares” (virtual liquidity used for solvency checks) and convert them into real, redeemable shares. This results in the complete drainage of assets from the CollateralTracker (the lending vault), causing a catastrophic loss of funds for liquidity providers.

Root Cause

The vulnerability stems from the interaction between three specific behaviors in the protocol:

  1. Inconsistent Revocation Timing: PanopticPool._liquidate delegates phantom shares (amount 2^248 - 1) to the liquidatee on both token0 and token1 collateral trackers simultaneously, but revokes them sequentially (ct0 first, then ct1).
  2. Unsafe External Call: CollateralTracker.settleLiquidation performs an external ETH refund call (SafeTransferLib.safeTransferETH) to the liquidator before the liquidation process is complete for the other token. This opens a reentrancy window.
  3. Accounting Flaw: The revoke logic in CollateralTracker assumes any missing phantom shares were “consumed” (burned) by the protocol logic and compensates by increasing _internalSupply. It does not account for the possibility that phantom shares were transferred away.

Code Analysis

1. The Trigger: External call in settleLiquidation: In CollateralTracker.sol, when settleLiquidation is called with a non-negative bonus, it refunds any provided msg.value to the caller. This external call passes control to the attacker.

contracts/CollateralTracker.sol:

// In settleLiquidation:
} else {
    // ... (logic to revoke phantom shares for THIS tracker) ...

    // @audit-issue The external call here happens while OTHER trackers might still have active phantom shares
    if (msg.value > 0) SafeTransferLib.safeTransferETH(liquidator, msg.value);
}

2. The Window: Sequential settlement in PanopticPool: In PanopticPool.sol, settlements happen sequentially. When ct0.settleLiquidation is called, ct1’s phantom shares are active (delegated) but not yet revoked.

contracts/PanopticPool.sol:

// In _liquidate:
// ... Phantom shares delegated to liquidatee on both tokens ...

// 1. Settle token0 (Triggers ETH refund -> Reentrancy)
collateralToken0().settleLiquidation{value: msg.value}(...);

// 2. Settle token1 (Has not happened yet when reentrancy occurs)
collateralToken1().settleLiquidation(...);

3. The Exploit: Transferring phantom shares: During the reentrancy callback, the attacker calls ct1.transferFrom. The only check in transferFrom is numberOfLegs == 0. Since _liquidate burns positions before settlement, this check passes.

contracts/CollateralTracker.sol:

function transferFrom(address from, address to, uint256 amount) public override returns (bool) {
    // ...
    // @audit-issue This check passes during liquidation
    if (panopticPool().numberOfLegs(from) != 0) revert Errors.PositionCountNotZero();

    // @audit-issue Standard ERC20 transfer moves phantom shares without checks
    return ERC20Minimal.transferFrom(from, to, amount);
}

4. The Validation: Incorrect supply compensation: When control returns to PanopticPool and ct1.settleLiquidation is finally called, it calls revoke. Since the liquidatee’s balance is now 0 (shares were transferred), the logic assumes they were consumed and validates them by increasing _internalSupply.

contracts/CollateralTracker.sol:

function revoke(address delegatee) external onlyPanopticPool {
    uint256 balance = balanceOf[delegatee];
    if (type(uint248).max > balance) {
        // @audit-issue Logic assumes missing shares were burned, permanently minting them
        _internalSupply += type(uint248).max - balance;
        balanceOf[delegatee] = 0;
    }
    // ...
}

Proof of Concept

A comprehensive Foundry test case demonstrates this vulnerability. The PoC performs the following steps:

  1. Sets up a pool with liquidity in token1.
  2. Creates a malicious liquidator contract.
  3. Triggers liquidation with msg.value = 1 wei to force the ETH refund path.
  4. In the receive() fallback, the liquidator transfers ct1 phantom shares from the liquidatee to itself.
  5. After liquidation completes, the liquidator holds valid shares and redeems them for the underlying assets.

View detailed Proof of Concept

Recommended mitigation steps

Option 1: Reentrancy guard (Recommended): Add a nonReentrant modifier to CollateralTracker.settleLiquidation to prevent re-entering the contract or other trackers during the settlement process.

Option 2: Restrict phantom share transfers: Modify CollateralTracker.transferFrom (and transfer) to explicitly forbid transferring shares if the balance indicates the presence of phantom shares.

function transferFrom(address from, address to, uint256 amount) public override returns (bool) {
+   // Prevent moving phantom shares
+   if (balanceOf[from] > type(uint248).max) revert Errors.PhantomSharesAreNotTransferable();

    _accrueInterest(from, IS_NOT_DEPOSIT);
    if (panopticPool().numberOfLegs(from) != 0) revert Errors.PositionCountNotZero();
    return ERC20Minimal.transferFrom(from, to, amount);
}

Option 3: Move ETH refund: Move the ETH refund logic out of CollateralTracker and into PanopticPool._liquidate (specifically, at the very end of the function), ensuring all settlements and revocations are complete before making external calls.

View detailed Proof of Concept

Panoptic mitigated:

Enhance reentrancy protection and add protocol loss tracking.

Status: Mitigation confirmed. Full details in reports from Valves, edoscoba, and Nyx.


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

Likely the combination of an external ETH refund call made before all phantom shares are revoked, and a revoke function that assumes any missing phantom shares were burned rather than transferred.

Impact

The attacker could drain all assets from the CollateralTracker, causing a catastrophic loss for liquidity providers.

What the attacker needed

Malicious liquidator contract; liquidation with ETH refund

The fix

The protocol mitigated the issue by enhancing reentrancy protection and adding protocol loss tracking.

How it was found

  1. Set up a pool with liquidity in token1.
  2. Create a malicious liquidator contract.
  3. Trigger liquidation with a small ETH value to force the ETH refund path.
  4. In the receive() fallback, transfer ct1 phantom shares from the liquidatee to the liquidator.
  5. After liquidation completes, redeem the shares for underlying assets.

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.

When a position is liquidated, the protocol temporarily gives the liquidatee some virtual shares (called phantom shares) to check solvency. These shares are supposed to be taken back right after. But the code sends an ETH refund to the liquidator before finishing all the take-backs, and during that refund the liquidator can move the still-active phantom shares to themselves. Later, the protocol mistakenly treats the missing shares as if they were burned and mints new real shares, which the attacker redeems for assets.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by ht111111

View all

3 more disclosed reports, best first.

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.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.