Skip to content
Business logic Audit finding Advanced

Commission share-burn distribution is JIT-capturable when builderCode == 0 (default)

When builderCode is zero, commission fees are burned as shares from the option owner without removing assets, which instantly raises the share price for all current shareholders. An attacker can deposit just before such a burn to capture most of the value, or a fee payer can recapture their own fee.

fuzious Follow with kind0dev and Valves

Originally disclosed on Code4rena

Submitted by fuzious, also found by kind0dev and Valves

Summary

When builderCode == 0 (i.e., feeRecipient == address(0)), commissions in CollateralTracker.settleMint() / CollateralTracker.settleBurn() are implemented as a share burn from the option owner without removing assets. This reduces totalSupply() while keeping totalAssets() roughly constant, immediately increasing assetsPerShare for whoever holds shares at that instant (including same-block entrants). MEV searchers can JIT-deposit immediately before these commission-burn events to capture the majority of the value.

A stronger implication than “LP yield leakage” also exists: fee self-rebating / fee bypass. If a fee payer (or flash-funded actor in an active-trigger flow) can temporarily dominate the share supply at the moment their commission is burned, they can reclaim most of the fee back via the share-price uplift, undermining the commission’s intended economic purpose.

Finding description and impact

Panoptic distributes some value to shareholders by burning shares (reducing totalSupply() without removing assets), which increases assetsPerShare immediately for whoever holds shares at that moment. This is inherently Just-In-Time (JIT) liquidity-capturable: an MEV searcher can temporarily deposit to become a dominant shareholder right before a burn event, then unwind after, capturing most of the distribution that was economically intended for incumbent LPs.

Root cause mechanics

The share price is defined by ERC4626-style conversions:

  • assetsPerShare ≈ totalAssets() / totalSupply()
  • totalAssets() includes tracked pool assets, assets in AMM, and unrealized interest
  • totalSupply() is _internalSupply + s_creditedShares

Any event that burns shares but does not remove assets causes:

  • totalSupply() ↓ (burn)
  • totalAssets() ≈ constant
  • assetsPerShare ↑ instantly

That instant uplift is captured pro-rata by whoever is a shareholder at that exact moment.

Why builderCode == 0 is not “rare misconfiguration”:

In CollateralTracker.settleMint():

// CollateralTracker.sol:1558-1561
if (riskParameters.feeRecipient() == 0) {
    _burn(optionOwner, sharesToBurn);
    emit CommissionPaid(optionOwner, address(0), commissionFee, 0);
}

Critically, feeRecipient == 0 is produced by the DEFAULT builder flow:

  • RiskEngine.getRiskParameters() computes feeRecipient from builderCode
  • _computeBuilderWallet(builderCode) returns address(0) if builderCode == 0

More importantly, several critical protocol maintenance paths HARDCODE getRiskParameters(0):

  • _burnAllOptionsFrom(...) (used by liquidations): (RiskParameters riskParameters, ) = getRiskParameters(0); (Line 839)
  • _forceExercise(...): (RiskParameters riskParameters, ) = getRiskParameters(0); (Line 1634)

This means an attacker can actively trigger commission-burn distributions by initiating liquidation/forced-exercise flows when a target account is eligible, rather than passively waiting to sandwich a victim’s optional builderCode==0 transaction.

Attack flow

Passive MEV Sandwich (around user transaction with builderCode = 0):

  1. Victim tx pending: a user submits an option interaction via PanopticPool.dispatch(...) with builderCode = 0.
  2. Attacker front-runs: attacker calls CollateralTracker.deposit(...) to mint a very large share balance right before the victim tx executes.
  3. Victim tx executes: PanopticPool calls CollateralTracker.settleMint/settleBurn and the commission path burns sharesToBurn from the option owner (supply decreases, assets do not).
  4. Attacker back-runs: attacker unwinds, capturing the share price uplift.

Active Trigger (Liquidation-style):

  1. Attacker identifies a margin-called account eligible for liquidation.
  2. Attacker deposits large liquidity into the relevant CollateralTracker(s) to dominate share supply.
  3. Attacker calls dispatchFrom, which routes into _liquidate(...) and burns all positions via _burnAllOptionsFrom(...) using hardcoded getRiskParameters(0).
  4. CollateralTracker.settleBurn(...) charges commission; if feeRecipient==0, it burns shares.
  5. Attacker exits when liquidity permits; the economic transfer happens at burn time.

How the attacker finds margin-called accounts (practically):

  • Off-chain: call PanopticPool.getAccumulatedFeesAndPositionsData(...) + RiskEngine.isAccountSolvent(...) / RiskEngine.getMargin(...) to evaluate solvency at relevant ticks.
  • On-chain: simply attempt dispatchFrom(...) for a candidate account; the call reverts unless the account is fully margin-called, so failed attempts are self-pruning.

The attacker’s captured value is approximately:

$$captured \approx donationValue \times \frac{attackerShares}{totalSharesAfterAttackerDeposit}$$

With sufficient capital, the attacker can make the ratio arbitrarily close to 1 and capture almost all of the distribution.

Capital requirements (Passive JIT capture):

For a pool with incumbent TVL T (in assets) and an attacker deposit A, the attacker’s capture fraction at the instant of the burn is approximately:

$$captureFraction \approx \frac{A}{T + A}$$

So to capture p of a burn event, the attacker needs roughly:

$$A \approx \frac{p}{1-p}\,T$$

Examples: p=90% → A≈9×T; p=99% → A≈99×T. The PoC uses large deposits to make the capture fraction very close to 1 and show the asymptote clearly.

Flash loan severity multiplier:

Flash loans are not a universal multiplier for a passive mempool sandwich (the attacker must hold shares across a separate victim transaction). However, when the attacker can actively trigger the commission-burn event (e.g., via liquidation / force exercise paths that hardcode getRiskParameters(0)), they can wrap “enter → trigger burn → exit” in a single transaction, making flash-loan-funded entry feasible.

Practical constraints:

  • Realized, in-tx profit is bounded by withdrawable liquidity: maxWithdraw/maxRedeem are capped by s_depositedAssets (not totalAssets(), which includes s_assetsInAMM and unrealized interest), and withdrawals are blocked when numberOfLegs(owner) != 0.
  • In liquidation / force-exercise flows, the protocol delegates virtual shares to the distressed account; any “burn” that only consumes phantom shares is compensated on revoke() (i.e., it does not persist as a net totalSupply() decrease). The extractable “donation size” depends on how many real shares are actually burned.

Impact

  • Systematic MEV capture of commission distributions: value intended for longer-term LPs can be captured by JIT entrants.
  • Fee self-rebating / fee bypass: large or flash-funded actors can materially reduce effective commission paid, undermining the fee model.
  • LP incentive degradation: Passive LP returns become MEV-farmable, reducing the attractiveness of providing liquidity.
  • MEV arms race: Sophisticated searchers can bundle entry/exit around high-value option interactions.
  • MEV around risk events: forced-exercise/liquidation flows can become predictable “donation” farming opportunities when they route through getRiskParameters(0).

Recommended Mitigation Steps

There is no free lunch here: “burn-based instant distribution to current shareholders” is fundamentally JIT-capturable. Mitigations are about making the distribution not instantaneous or not purely share-price based.

  1. Disallow burn-based distribution for commissions (Strongest, Simplest):

    • Treat builderCode == 0 as “protocol receives fees” rather than “burn to LPs”.
    • Enforce feeRecipient != 0 for all dispatch paths, or route builderCode == 0 to a non-zero treasury recipient, then distribute via a separate time-weighted mechanism.
  2. Stream/Vest distributions instead of instantaneous uplift:

    • Accumulate commissions in a buffer and drip them into totalAssets() over a window (e.g., X blocks).
    • This makes same-block JIT capture unprofitable because the “uplift” is smeared over time.
  3. Cooldown / Time-weighting (Partial mitigation):

    • A 1-block withdrawal cooldown reduces risk-free atomic sandwiches but does not remove the economic issue (attackers can hold across blocks).
    • If implemented, it must also cover transfers (otherwise deposit→transfer→withdraw bypass exists).

Proof of Concept

Setup instructions:

  1. Create the PoC file at test/foundry/poc/CollateralTrackerCommissionBurnJITPoC.t.sol
  2. Apply the diff below (or copy the full file content)
  3. Run the tests via forge test --match-path test/foundry/poc/CollateralTrackerCommissionBurnJITPoC.t.sol -vvv

Note: This PoC uses a minimal mock PanopticPool solely to satisfy onlyPanopticPool and to simulate the liquidation-style delegate() → settleBurn() → revoke() sequence that the real PanopticPool uses during dispatchFrom liquidations/forced exercises. A full dispatchFrom end-to-end liquidation PoC would require spinning up real option positions + solvency/oracle plumbing (typically via a forked environment) and is orthogonal to demonstrating the JIT-capturable share-burn mechanism inside CollateralTracker.

PoC diff:

View detailed Proof of Concept

Expected test output:

All 10 tests pass, demonstrating:

  1. test_PoC_CommissionBurn_JITCapture_WhenFeeRecipientIsZero - JIT attacker captures >99% of commission burn distribution.
  2. test_PoC_SettleBurn_NoRealizedPremium_NoCommissionBurn - Confirms settleBurn gating on realizedPremium != 0.
  3. test_PoC_ActiveCapture_SettleBurn_CommissionBurn_JITCapture - Active attacker-initiated burn capture.
  4. test_PoC_FeeSelfRebating_PreDepositReducesEffectiveFee - Fee payer can recapture >99% of their own fee.
  5. test_PoC_FeeSelfRebating_CostDecreases_WithShareFraction - Effective fee decreases as the fee payer’s share fraction increases.
  6. test_PoC_FlashLoan_ActiveCapture_IsAtomic_WhenLiquidityAllows - Atomic flash loan attack variant.
  7. test_PoC_LiquidationStyle_DelegateRevoke_PhantomBurnIsRestored_WhenNoRealShares - Phantom burn is restored on revoke (no persistent supply decrease).
  8. test_PoC_LiquidationStyle_DelegateRevoke_RealBurnPersists_WhenVictimHasRealShares - Persistent supply decrease requires burning real shares.
  9. test_PoC_UpliftMayBeNonWithdrawable_WhenAssetsInAMMHigh - Shows maxWithdraw/maxRedeem are capped by s_depositedAssets (not totalAssets()).
  10. test_PoC_RiskEngine_builderCode0_feeRecipient0 - Confirms builderCode == 0 → feeRecipient == address(0).

Panoptic marked as informative.


The original report as published on Code4rena, by fuzious. 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 commission is implemented as a share burn that reduces totalSupply without reducing totalAssets, so the resulting share-price increase is captured by whoever holds shares at that moment.

Impact

Value intended for longer-term liquidity providers can be captured by just-in-time entrants, and large or flash-funded actors can materially reduce the effective commission they pay, though realised profit is bounded by withdrawable liquidity and withdrawals are blocked when the owner has open legs.

What the attacker needed

BuilderCode is zero (default); attacker has large capital or a flash loan; for active trigger: a margin-called account

The fix

The commission should not be distributed by an instantaneous share burn; instead, builderCode zero should route fees to a non-zero treasury or the fees should be streamed over time.

How it was found

  1. Victim submits an option interaction with builderCode set to zero.
  2. Attacker deposits a large amount to become a dominant shareholder before the victim's transaction.
  3. Victim's transaction executes and the commission path burns shares from the option owner.
  4. Attacker withdraws, capturing the share price uplift.

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 shared pool, each person's share of the pool is their number of shares divided by the total number of shares. If the pool burns some shares without taking out any money, the remaining shares are each worth more. An attacker can buy shares just before the burn and sell them just after, pocketing most of that increase.

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 fuzious

View all

1 more disclosed report, 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.

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.