Skip to content
DoS Audit finding Advanced

Division-by-zero in long-leg collateral requirement can block solvency checks and dispatchFrom (liquidation/force-exercise) for tickSpacing==1 pools

For pools with tickSpacing equal to one, a long position with a one-tick-wide leg evaluated at a tick equal to its strike causes a division-by-zero revert in the risk engine's margin calculation. Because dispatchFrom always includes the current tick, liquidation, force-exercise and settlement actions can hard-revert when the current tick equals the strike, potentially blocking third-party resolution at those prices.

niffylord Follow with 0xnija, Agontuk and 7 others

Originally disclosed on Code4rena

Submitted by niffylord, also found by 0xnija, Agontuk, Blackdruid, Diavolo, edoscoba, Ituba, legat, LimeiBBQ, and VulSight

For pools with tickSpacing == 1, a 1-tick-wide long leg (width == 1) evaluated at atTick == strike triggers a division-by-zero revert inside RiskEngine margin computation. Because PanopticPool.dispatchFrom(...) always includes currentTick in its tick set, any liquidation/force-exercise/settle action that hits currentTick == strike can hard-revert, potentially blocking third-party resolution actions at specific prices.

Exploit narrative (attack steps)

Assumptions:

  • Target pool has tickSpacing == 1.
  • Attacker can obtain/hold a long position with a 1-tick-wide leg and strike T.

Steps:

  1. Ensure the position exists with width == 1, tickSpacing == 1, strike == T.
  2. When dispatchFrom(...) evaluates solvency at ticks including currentTick, and currentTick == T, margin evaluation calls into RiskEngine and reverts (division-by-zero), blocking the action.

Affected components/code references (GitHub links)

  • Division-by-zero source (long-leg branch): RiskEngine.sol L1508 and RiskEngine.sol L1541
  • dispatchFrom includes currentTick in tick set: PanopticPool.sol L1360 and PanopticPool.sol L1392

Proof of Concept

This PoC uses the existing V3 harness and demonstrates liquidation reverting with a division-by-zero error.

Put this function inside PanopticPoolTest in: test/foundry/coreV3/PanopticPool.t.sol

Run:

FOUNDRY_PROFILE=ci_test FOUNDRY_ETH_RPC_URL=https://ethereum.publicnode.com \
  forge test \
  --match-path test/foundry/coreV3/PanopticPool.t.sol \
  --match-test test_poc_WidthOneLongAtStrike_DivisionByZero_BlocksLiquidation

View detailed Proof of Concept

  • When tickSpacing == 1 and width == 1, the code path sets positionWidth = tickUpper - tickLower = 1.
  • In the long-leg branch, distanceFromStrike = max(positionWidth / 2, abs(atTick - strike)) becomes max(0, 0) = 0 when atTick == strike.
  • The subsequent computation divides by (distanceFromStrike * expValue), which becomes a division-by-zero revert. The PoC triggers this exact state and asserts stdError.divisionError during liquidation.

Recommended mitigation steps

Add a distanceFromStrike == 0 guard in the long-leg branch (e.g., clamp to 1), and/or disallow width==1 longs for tickSpacing==1 pools if that’s an acceptable constraint.

Panoptic mitigated:

No more division-by-zero in long-leg collateral requirement.

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


The original report as published on Code4rena, by niffylord. 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 long-leg margin formula divides by a distanceFromStrike term that can be zero when the position width is one and the evaluated tick equals the strike, with no guard against that case.

Impact

Liquidation, force-exercise and settlement actions could hard-revert when the current tick equals the strike of such a position, potentially blocking third-party resolution at those prices.

What the attacker needed

Pool with tickSpacing equal to one; long position with a one-tick-wide leg; current tick equals the strike

The fix

The project added a guard so the long-leg collateral requirement no longer divides by zero, and the mitigation was confirmed.

How it was found

  1. Have a pool where tickSpacing equals one.
  2. Hold a long position with a one-tick-wide leg and strike T.
  3. Trigger dispatchFrom so that the current tick equals T.
  4. Observe the margin evaluation revert with a division-by-zero error, blocking the action.

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 smart contract calculates how much collateral a position needs by dividing by a distance value. When a position is exactly one tick wide and the current price sits exactly on its strike, that distance becomes zero, and dividing by zero makes the transaction fail. The result is that actions like liquidation cannot run at that particular price.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by niffylord

View all

7 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.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.