Skip to content
Business logic Audit finding Advanced

Near-Zero Claim-Net Depth in Close VPI Pricing Lets a Losing Close Freeze Other Traders' Margin in Degraded Mode

Close orders price virtual price impact on HousePool assets net of trader claims, and the zero-depth exemption only applies at exactly zero, so a tiny positive depth makes a skew-increasing close cost many times its notional. A trader can realise part of a losing position to park the depth just above zero, after which a minority-side trader's bounded close is refused and, in degraded mode, its whole clearinghouse balance cannot be withdrawn.

zer0luck_xint Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#99374 [SC-High] Near-Zero Claim-Net Depth in Close VPI Pricing Lets a Losing Close Freeze Other Traders' Margin in Degraded Mode

Submitted on Nov 13th 2026 at 12:05:51 UTC by @zer0luck_xint for Audit Competition | Plether

Description

Brief/Intro

Close orders pay virtual price impact (VPI) priced on the depth of HousePool assets P net of outstanding trader claims C, max(P - C, 0), and the close flow skips fresh VPI only when that depth is exactly zero. The VPI curve divides the squared skew by depth, so at a small positive depth a close that increases skew can be charged several times its own notional.

After trader claims reach HousePool assets and degraded mode has latched, a trader on the dominant side (the side with the larger open size) can realize part of a losing position so that pool assets end just above trader claims. A close by a trader on the minority side that increases the absolute skew is then refused when its maxActionChargeAssets is near its depth-0 quote. Degraded mode blocks every withdrawal from an account with an open position, so that trader's whole clearinghouse balance stays frozen while the depth stays there, unless it accepts a VPI charge of thousands of USDG to exit.

Vulnerability Details

Close VPI is priced on claim-net depth. The close plan passes HousePool assets net of outstanding trader claims to CloseAccountingLib.buildCloseState as the VPI depth:

https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/libraries/CfdEnginePlanLib.sol#L1339-L1341

Solidity
                poolDepthAssets: PositionRiskAccountingLib.computeNetPoolDepthAssets(
                    snap.poolAssets, snap.totalTraderClaimBalanceAssets
                ),

https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/libraries/PositionRiskAccountingLib.sol#L21-L26

Solidity
        return physicalAssets > traderClaimsAssets ? physicalAssets - traderClaimsAssets : 0;

Fresh VPI is skipped only at exactly zero depth. buildCloseState computes fresh VPI for every nonzero depth:

https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/libraries/CloseAccountingLib.sol#L105-L111

Solidity
        // With no economic depth, keep protective exits live without creating a fresh charge or rebate.
        // The lifetime clamp below still recovers any previously received negative VPI.
        if (inputs.poolDepthAssets != 0) {
            state.vpiDeltaAssets = CfdMath.calculateVPI(
                inputs.preSkewAssets, inputs.postSkewAssets, inputs.poolDepthAssets, inputs.vpiFactor
            );
        }

The VPI of a trade is the change in the skew cost cost(S) = 0.5 * k * S^2 / D at depth D and VPI factor k (CfdMath.sol:96-139, :164-180). A close that raises the absolute skew from S_pre to S_post is charged 0.5 * k * (S_post^2 - S_pre^2) / D. The charge is 0 at D = 0 and grows without limit as D approaches 0 from above.

The trader's charge bound refuses the close. The close action charge is the VPI plus the execution fee, the frozen close spread and carry (CfdEnginePlanLib.sol:1041-1047). The policy evaluator rejects the order when that charge exceeds the trader's maxActionChargeAssets:

https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/CfdOrderPolicyEvaluatorBase.sol#L509-L513

Solidity
        _requireMaximum(
            OrderV3Types.ConstraintKind.ActionCharge,
            assessment.actionChargeAssessedAssets,
            bounds.maxActionChargeAssets
        );

OrderRouter classifies this policy rejection as terminal (OrderRouterExecutionSidecar.sol:879-893), so each refused close is final and the trader has to commit a new one. By design, the position-protection builders require explicit close limits, including maxActionChargeAssets, and reserve an unlimited value for intentionally unlimited authority (packages/perps-aa-client/README.md:208-214).

Degraded mode blocks every withdrawal while the position is open. MarginClearinghouse.withdrawMargin calls the engine's withdrawal check (MarginClearinghouse.sol:463-465, CfdEngine.sol:730-748), which reverts in degraded mode for any account with an open position:

https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/CfdEngineSettlementSidecar.sol#L274-L276

Solidity
        if (engine.degradedMode()) {
            revert ICfdEngineTypes.CfdEngine__DegradedMode();
        }

A trader's own trader claim is settled into the same clearinghouse account (CfdEngine.sol:572-586, :233-244). In degraded mode a trader with an open position therefore recovers its balance only by closing the position, and degraded mode keeps such protective transitions available while it blocks risk expansion (packages/perps/SECURITY.md:340).

The exemption covers only zero depth. By design, VPI depends on HousePool assets net of outstanding trader claims, claim payment alone cannot change that depth, and protective closes create no fresh VPI charge or rebate at zero depth (packages/perps/SECURITY.md:1438-1440). The net-depth basis was added, and the zero-depth close rule made explicit, in commit 6d6622f2 (Plether-Fi/plether-core#118) so that outstanding trader claims no longer count as risk capacity while protective exits stay live. The defect reported here is introduced by that change. Before it, close VPI used gross HousePool assets as depth, which do not approach zero when trader claims approach pool assets. With claim-net depth, a loss realization can leave a small positive P - C, which the zero-depth exemption does not cover. The refusal does not come from missing liquidity: at depth 0 the same close executes, and in degraded mode LP deposits are closed (HousePool.sol:1139-1145). Voluntary closes use the same signed VPI curve in live, FAD-only and oracle-frozen markets (packages/perps/SECURITY.md:1441). The VPI limitations cover the net-depth basis, the shared curve and zero depth; none of them covers this refusal of protective exits at a small positive depth.

Trigger. Once trader claims are at least HousePool assets, depth is 0 and closes execute without fresh VPI. A trader holding a losing position on the dominant side commits a partial close whose realized loss lifts HousePool assets just above trader claims. Order execution is permissionless and processes the global queue in FIFO order (OrderRouter.sol:249-263), so when that close is queued ahead of a victim's close, any executor runs the loss realization first and the victim's close is assessed at the new depth in the same transaction. A retried bounded close is refused for as long as the depth stays there.

Impact Details

Severity: High, Temporary freezing of funds for at least 24 hours.

A trader on the minority side that keeps its close bounded has its whole clearinghouse balance frozen (168 hours in the test). From the depth the attacker's partial close leaves (the parked depth), the exit sequences the test runs leave the victim 5,616.78 USDG (split exit) to 39,815.06 USDG (unlimited bound) below the depth-0 control, in which the same close executes at depth 0.

In the release deployment with release parameters, the victim's full SHORT close of 24,875.00 USDG notional is quoted at 9.95 USDG at depth 0, and the victim sets maxActionChargeAssets to that quote plus 1% of notional, 258.70 USDG. In the control the close executes and the victim withdraws its whole clearinghouse balance of 29,950.01 USDG. In the attack, a partial close of the attacker's losing LONG is queued ahead and executes first in the same transaction, depth becomes 54.77 USDG, and the same close is assessed 124,271.84 USDG, of which 124,261.89 USDG is VPI (the VPI of the fresh quote at that depth). The close is refused, and the victim cannot withdraw its balance or even 1 atom of it.

Control (depth 0) Attack (after the attacker's partial close)
HousePool assets / trader claims 17,785.16 / 33,530.41 33,585.18 / 33,530.41
Claim-net depth 0.00 54.77
Victim's full close: charge assessed against the 258.70 bound 9.95, executed 124,271.84, refused
VPI in that charge (attack: fresh quote at the same depth) 0.00 124,261.89
Withdrawal of the victim's 29,950.01 clearinghouse balance succeeds reverts
Hourly bounded retries over the next 168 hours 168 refused, 0 executed

The freeze persists while the attacker takes no further action and the basket stays fixed. After another trader settles its trader claim, the victim retries every hour for 168 hours with a full close bounded at the fresh quote without its VPI plus 1% of notional. Each hour, addresses with no role refresh the mark, checkpoint carry and attempt LP epoch settlement. Each of the 168 retries is assessed the same 124,261.89 USDG of VPI and refused, no withdrawal succeeds at any hour, and after 168 hours depth is still 54.77 USDG and the victim's 29,950.01 USDG is still locked in its clearinghouse account. In 47 of those hours the oracle market is closed, so the frozen close spread enters both the quote and the bound, and those retries are refused the same way. Close orders carry no execution bounty (packages/perps/DEPLOYMENT.md:150), and no bounty is paid on any refused retry; the first refusal leaves the victim's wealth and the executor's balance unchanged.

Every exit sequence the test starts from the parked depth pays VPI far above 1% of the notional it closes. With an unlimited maxActionChargeAssets the full close executes, is assessed 124,271.84 USDG and collects the victim's whole clearinghouse balance of 29,950.01 USDG. The victim ends 39,815.06 USDG below the depth-0 control, the sum of that balance and the 9,865.05 USDG the control close credits. HousePool assets net of trader claims, together with the USDG held by the Senior and Junior tranche vaults, rise by 29,940.06 USDG (LP equity change in the test output).

The smallest partial close the router accepts at this mark, 1,194.00 USDG notional above the 1,000 USDG minimum (OrderLiquidationBatchLogic.sol:356-364), carries 3,383.54 USDG of VPI and is refused at a bound of its quote without VPI plus 1% of its notional (12.42 USDG). Executed instead with a bound equal to its own quote, that partial close is assessed 3,384.02 USDG, and the 2,910.02 USDG it collects lifts depth to 2,964.79 USDG. The remaining close, bounded at its own quote, is then assessed 2,242.71 USDG and executes. This split exit, the cheapest sequence tested, leaves the victim 5,616.78 USDG below the depth-0 control, 57% of the profit the control close credits.

Settling the victim's own trader claim moves 11,838.06 USDG into the same clearinghouse account, 41,788.07 USDG in total, leaves depth unchanged, and the bounded close is still refused.

Prerequisites:

  • Trader claims at least equal to HousePool assets, with degraded mode latched. A profitable close whose payout exceeds free pool cash creates a trader claim instead of a payment (CfdEnginePlanLib.sol:960-967), and degraded mode latches when a close leaves effective assets below the maximum directional liability (CfdEngine.sol:1355-1368). By design, the maximum directional payout envelope is an endpoint liability bound and not a pathwise reserve, so a profitable close can reduce pool cash while another position still determines the maximum liability (Plether-Fi/plether-core#74). In the test this state follows a Junior redemption of 95% of its shares and a basket move from 1.20 to 0.30 and then to 1.99, below the 2.00 cap price; trader claims are then 33,530.41 USDG against 17,785.16 USDG of HousePool assets. That state comes from realized trader profits on both sides that together exceed the pool left after LP redemptions, which takes large basket moves in both directions; the test compresses them into the moves above.
  • A losing position on the dominant side that its holder partly realizes. In the test the attacker's partial close realizes 15,800.00 USDG of the loss its LONG already carried at the 1.99 mark. The partial close is an ordinary close order, so a trader that realizes a loss of that size for its own reasons leaves the same depth with no attacker involved. A realization that leaves claim-net depth small relative to the skew can produce the same refusal, since the charge scales with 1 / D.
  • A victim with an open position on the minority side, whose close increases the absolute skew.
  • Duration. The attacker holds the depth by keeping the other half of its LONG open. Closing that half also raises the absolute skew at the parked depth: in the test that close is assessed 33,242.16 USDG, collects 8,364.66 USDG of that charge and takes the attacker's clearinghouse balance from 24,164.66 USDG to 0. Depth then rises to 24,203.51 USDG and the victim's bounded close executes with a 16.63 USDG VPI rebate. The refusal also ends when HousePool assets rise far enough above trader claims, for example through another trader's loss realization or an owner recapitalization, and withdrawals resume after clearDegradedMode, which requires raw solvency (CfdEngine.sol:658-667). None of these occurs in the test. The trader can end the freeze at any time by accepting the VPI loss of an executable exit described above; once its position is flat, withdrawals no longer check degraded mode (CfdEngineSettlementSidecar.sol:261-273).
  • Attacker cost and gain. The attacker's clearinghouse balance falls by 15,815.94 USDG at the partial close: the realized loss plus the 15.92 USDG execution fee and carry. The test does not measure Arbitrum gas or Pyth update fees. The attacker then carries price risk on the LONG it keeps open, and it gains nothing from a victim that keeps a bounded close.
  • After the release deployment and its owner setup steps (seed positions and trading activation), no privileged role or unusual configuration is involved, and every call in the scenario is a public function. The basket prices come from the repository's MockPyth at the release Pyth address: all 6 feeds move together from 1.20 to 0.30 and then to 1.99 with zero confidence, which the oracle accepts. The test does not replay authentic signed Pyth updates for these moves, and their size is the main feasibility limit of the claims state.

Recommendation

Extend the zero-depth treatment of protective exits to small positive depths. When CloseAccountingLib.buildCloseState prices fresh VPI at a nonzero claim-net depth, use a depth of at least the post-close absolute skew. The fresh charge on a close is then at most k times the skew it adds (1% of the close notional at release parameters), however small the positive depth is. Alternatively, skip fresh positive VPI on closes whenever claim-net depth is below a floor tied to the close notional or to open interest, keeping the lifetime clamp unchanged. Either change leaves opens on the net-depth basis and keeps rebates on skew-reducing closes no larger than at the audit commit.

References

  • Audit commit: https://github.com/immunefi-team/audit-comp-plether/tree/a82d4fefb02768e5b3bddcc97dee371eee24fea8
  • Change that added the net-depth basis and made the zero-depth close rule explicit: Plether-Fi/plether-core#118 (commit 6d6622f2)
  • VPI limitations and degraded containment: packages/perps/SECURITY.md:1434-1444, packages/perps/SECURITY.md:340
  • Payout envelope as an endpoint liability bound: Plether-Fi/plether-core#74
  • Release parameters: packages/perps/DEPLOYMENT.md (Initial release parameters) and script/DeployPerpsArbitrumSepolia.s.sol

Proof of Concept

Proof of Concept

The test deploys the release contracts with script/DeployPerpsArbitrumSepolia.s.sol inside Forge through ReleaseFixture.sol (source at the end of this section). In-scope contracts are unmodified. Only out-of-scope components are mocked:

  • Pyth: the repository's test/mocks/MockPyth.sol, etched at the release Pyth address. All 6 feeds move together with zero confidence.
  • USDG: the release MockUSDG.
  • The ArbSys block-number precompile.

The victim's commit-time quotes come from CfdClosePreview.previewClose, the close preview deployed by the release script. Every order is executed by an address with no role, on a price published after the commit: through OrderRouter.executeOrder in setUp and through OrderRouter.executeOrderBatch in the test steps. setUp builds the shared claims state for all 3 tests in NearZeroDepthCloseVpiFreeze.t.sol through public entry points:

  1. A Junior LP deposits 200,000 USDG and a Senior LP 30,000 USDG at a 1.20 basket. 5 traders open, with sizes in synthetic tokens (1 lot is 100 synthetic tokens): a LONG of 30,000, a SHORT of 50,000, the attacker's LONG of 40,000, a SHORT of 27,500 for a later claimant, and the victim's SHORT of 27,500.
  2. The Junior LP redeems 95% of its shares at the next LP epoch.
  3. The basket falls to 0.30 and the first LONG closes in profit. The basket rises to 1.99, and the SHORT of 50,000, the claimant's SHORT and 15,000 of the victim's 27,500 close in profit. Payouts above free pool cash become trader claims, and degraded mode is latched in the resulting claims state.

test_nearZeroDepthRefusesBoundedCloseAndLocksBalanceFor168Hours compares the control and attack from that state:

  1. Control, from a snapshot: the victim quotes a full close of its remaining 12,500, sets maxActionChargeAssets to the quote plus 1% of notional, and the close executes. The victim then withdraws its whole clearinghouse balance.
  2. Attack, from the same snapshot: the attacker commits a close of 20,000 of its 40,000 LONG without a charge bound. The victim then quotes (the quote is unchanged) and commits the same bounded full close. One batch executes both in FIFO order, leaving a claim-net depth of 54.77 USDG (the parked depth).
  3. The flat claimant settles its trader claim. Every hour for 168 hours, one address with no role refreshes the mark and a second one checkpoints carry and attempts LP epoch settlement. The victim then reads a fresh quote and commits a full close bounded at the quote without its VPI (execution fee, carry and frozen close spread) plus 1% of notional, and the second address runs the execution batch.
  4. The attacker closes its remaining 20,000 without a charge bound. That close also raises the absolute skew at the parked depth, and its realized loss and charge take the attacker's clearinghouse balance to 0. The victim's bounded full close then executes.

The test checks the exact claims state, the control quote, bound, execution, wealth change and full withdrawal, and the attacker's realized loss, fee and balance change. After the batch it checks the exact depth, the exact refused charge and bound, unchanged victim wealth and executor balance, and failed withdrawals of the whole balance and of 1 atom. For each of the 168 retries it checks the exact fresh VPI, a refused charge equal to the fresh quote, a bound equal to the control bound plus the frozen close spread, and a failed withdrawal. It then checks the elapsed 168 hours, the unchanged depth, degraded mode and balance, and the depth and VPI rebate after the attacker exits.

test_onlyExecutableBoundForfeitsWholeBalance parks the same depth. It checks the refusal of the smallest partial close the router accepts (size 600, 6 lots) with its exact notional, VPI, charge and bound. After the victim settles its own trader claim, it checks that the bounded full close is still refused, that depth is unchanged and that the 41,788.07 USDG balance is locked. With an unlimited maxActionChargeAssets, it checks the executed close with its exact assessed and collected charge and the victim's wealth change against the depth-0 control. It also checks the change in HousePool assets net of trader claims plus the USDG held by the Senior and Junior tranche vaults (LP equity change).

test_splitExitStillLosesThousands parks the same depth and executes the smallest partial close the router accepts (size 600) with maxActionChargeAssets equal to its own quote, checking its charge and the depth after it. It then executes the remaining close bounded at its own quote and checks the victim's wealth against the depth-0 control.

On a fresh clone of the audit commit, run git submodule update --init --recursive. Create test/poc/ at the repository root, place ReleaseFixture.sol and NearZeroDepthCloseVpiFreeze.t.sol (sources at the end of this section) in it, then run from the repository root with Forge 1.5.1:

Bash
forge test --match-path test/poc/NearZeroDepthCloseVpiFreeze.t.sol -vv

Excerpt from the output of the command above for test_nearZeroDepthRefusesBoundedCloseAndLocksBalanceFor168Hours (deployment lines omitted):

[PASS] test_nearZeroDepthRefusesBoundedCloseAndLocksBalanceFor168Hours() (gas: 335731834)
Logs:
  == claims state at basket 1.99
     HousePool assets P 17785.160990 USDG
     trader claims C 33530.409810 USDG
     claim-net depth max(P - C, 0) 0.000000 USDG
     degraded mode true
     victim / attacker size 12500 40000
  victim SHORT close notional 24875.000000 USDG
  victim clearinghouse balance / trader claim 29950.013642 USDG 11838.060000 USDG
  CONTROL quoted close charge 9.950000 USDG
  CONTROL quoted close VPI 0.000000 USDG
  victim bound: quote + 1% of notional 258.700000 USDG
  -- CONTROL victim close
     Executed; charge assessed / collected 9.950000 USDG 0.000000 USDG
     VPI / execution fee 0.000000 USDG 9.950000 USDG
  CONTROL victim wealth change 9865.050000 USDG
  CONTROL victim withdraws its whole clearinghouse balance 29950.013642 USDG
  == after the batch
     HousePool assets P 33585.184625 USDG
     trader claims C 33530.409810 USDG
     claim-net depth max(P - C, 0) 54.774815 USDG
     degraded mode true
     victim / attacker size 12500 20000
  -- ATTACKER partial close (size 20000 of 40000), executed first; status (2 Executed) 2
     realized PnL / execution fee -15800.000000 USDG 15.920000 USDG
     attacker clearinghouse balance change -15815.943635 USDG
  -- ATTACK victim close
     status / reason / constraint (3 Failed, 8 ConstraintViolation, 4 ActionCharge) 3 8 4
     assessed charge / maxActionChargeAssets 124271.837055 USDG 258.700000 USDG
  ATTACK victim wealth change / executor change 0.000000 USDG 0.000000 USDG
  ATTACK victim can withdraw its balance / 1 atom false false
  #### hour 1
     fresh quoted close charge / VPI 124271.837055 USDG 124261.887055 USDG
     claim-net depth 54.774815 USDG
  -- retry
     status / reason / constraint (3 Failed, 8 ConstraintViolation, 4 ActionCharge) 3 8 4
     assessed charge / maxActionChargeAssets 124271.837055 USDG 258.700000 USDG
     victim can withdraw 1 atom false
  #### hour 24
     fresh quoted close charge / VPI 124271.837055 USDG 124261.887055 USDG
     claim-net depth 54.774815 USDG
  -- retry
     status / reason / constraint (3 Failed, 8 ConstraintViolation, 4 ActionCharge) 3 8 4
     assessed charge / maxActionChargeAssets 124271.837055 USDG 258.700000 USDG
     victim can withdraw 1 atom false
  #### hour 168
     fresh quoted close charge / VPI 124271.837055 USDG 124261.887055 USDG
     claim-net depth 54.774815 USDG
  -- retry
     status / reason / constraint (3 Failed, 8 ConstraintViolation, 4 ActionCharge) 3 8 4
     assessed charge / maxActionChargeAssets 124271.837055 USDG 258.700000 USDG
     victim can withdraw 1 atom false
  hourly retries refused 168
     of which with the market closed (frozen close spread in the bound) 47
  hours since the first refusal 168
  victim size / clearinghouse balance 12500 29950.013642 USDG
  == after the attacker closes its residual
     HousePool assets P 36041.571180 USDG
     trader claims C 11838.060000 USDG
     claim-net depth max(P - C, 0) 24203.511180 USDG
     degraded mode true
     victim / attacker size 12500 0
  -- ATTACKER residual close
     Executed; charge assessed / collected 33242.158687 USDG 8364.656365 USDG
     VPI / execution fee 33221.411881 USDG 15.920000 USDG
     attacker clearinghouse balance before / after 24164.656365 USDG 0.000000 USDG
  -- victim close after the attacker exits
     Executed; charge assessed / collected 0.000000 USDG 0.000000 USDG
     VPI / execution fee -16.630163 USDG 9.950000 USDG

Excerpt from the same output for test_onlyExecutableBoundForfeitsWholeBalance (deployment lines omitted):

[PASS] test_onlyExecutableBoundForfeitsWholeBalance() (gas: 8163032)
Logs:
  smallest partial close (size 600): notional / quoted VPI 1194.000000 USDG 3383.538219 USDG
  -- smallest partial close
     status / reason / constraint (3 Failed, 8 ConstraintViolation, 4 ActionCharge) 3 8 4
     assessed charge / maxActionChargeAssets 3384.015819 USDG 12.417600 USDG
  victim settles its own claim; clearinghouse balance 41788.073642 USDG
  claim-net depth 54.774815 USDG
  -- bounded close after the victim settles its own claim
     status / reason / constraint (3 Failed, 8 ConstraintViolation, 4 ActionCharge) 3 8 4
     assessed charge / maxActionChargeAssets 124271.837055 USDG 258.700000 USDG
  -- close with unlimited maxActionChargeAssets
     Executed; charge assessed / collected 124271.837055 USDG 29950.013642 USDG
     VPI / execution fee 124261.887055 USDG 9.950000 USDG
  victim wealth change -29950.013642 USDG
  victim wealth vs the depth-0 control close -39815.063642 USDG
  LP equity change 29940.063642 USDG

Excerpt from the same output for test_splitExitStillLosesThousands (deployment lines omitted) and the suite summary:

[PASS] test_splitExitStillLosesThousands() (gas: 5322767)
Logs:
  -- smallest partial close (size 600) bounded at its own quote
     Executed; charge assessed / collected 3384.015819 USDG 2910.015819 USDG
     VPI / execution fee 3383.538219 USDG 0.477600 USDG
     claim-net depth after 2964.790634 USDG
  -- remaining close (size 11900) bounded at its own quote
     Executed; charge assessed / collected 2242.712454 USDG 0.000000 USDG
     VPI / execution fee 2233.240054 USDG 9.472400 USDG
  victim wealth vs the depth-0 control close -5616.778273 USDG

Suite result: ok. 3 passed; 0 failed; 0 skipped; finished in 1.15s (1.13s CPU time)

Source files

ReleaseFixture.sol

Solidity
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.35;

// Deploys the release contracts with script/DeployPerpsArbitrumSepolia.s.sol inside Forge.
// Pyth, USDG and ArbSys are replaced by local test components; in-scope contracts are unmodified.

import {DeployPerpsArbitrumSepolia} from "../../script/DeployPerpsArbitrumSepolia.s.sol";
import {MockPyth} from "../mocks/MockPyth.sol";
import {CfdTypes} from "@plether/perps/CfdTypes.sol";
import {OrderV3Types} from "@plether/perps/OrderV3Types.sol";
import {PletherOracle} from "@plether/perps/PletherOracle.sol";
import {TrancheVault} from "@plether/perps/TrancheVault.sol";
import {Test, console2} from "forge-std/Test.sol";

/// @dev Mirrors the Arbitrum precompile's block-number view inside the local test EVM.
contract ReleaseFixtureArbSys {

    function arbBlockNumber() external view returns (uint256) {
        return block.number;
    }

}

abstract contract ReleaseFixture is Test {

    address internal constant RELEASE_PYTH = 0x0B73614636C855Bf23F342F307FB981A3e47f42B;
    uint256 internal constant DEPLOYER_KEY = 0xA11CE;
    uint256 internal constant MONDAY_MORNING = 1_709_532_000; // Mon 2024-03-04 06:00 UTC (live market)
    uint256 internal constant BASKET_1_20 = 120_000_000; // normalized basket mark 1.20 (8 decimals)
    uint8 internal constant MODE_LIVE = 1;
    uint8 internal constant MODE_FAD = 2;
    uint8 internal constant MODE_FROZEN = 4;
    uint8 internal constant MODE_ANY = 7;

    DeployPerpsArbitrumSepolia.DeployedContracts internal d;
    address internal owner;
    address internal keeper = makeAddr("keeper");
    uint256 internal clientNonce;

    function setUp() public virtual {
        vm.chainId(421_614);
        vm.warp(MONDAY_MORNING);
        ReleaseFixtureArbSys arbSys = new ReleaseFixtureArbSys();
        vm.etch(address(100), address(arbSys).code);
        MockPyth pyth = new MockPyth();
        vm.etch(RELEASE_PYTH, address(pyth).code);
        vm.setEnv("TEST_PRIVATE_KEY", vm.toString(DEPLOYER_KEY));
        d = DeployPerpsArbitrumSepolia(deployCode("DeployPerpsArbitrumSepolia.s.sol:DeployPerpsArbitrumSepolia")).run();
        owner = vm.addr(DEPLOYER_KEY);

        // Permanent 1 USDG seeds per tranche (release values), then activation.
        d.settlementToken.mint(owner, 2e6);
        vm.startPrank(owner);
        d.settlementToken.approve(address(d.housePool), 2e6);
        d.housePool.initializeSeedPosition(false, 1e6, owner);
        d.housePool.initializeSeedPosition(true, 1e6, owner);
        d.housePool.activateTrading();
        vm.stopPrank();

        _setBasketPrices(BASKET_1_20);
        d.router.updateMarkPrice(_updateData());
    }

    // ---------------------------------------------------------------- prices

    function _oracle() internal view returns (PletherOracle) {
        return PletherOracle(d.pletherOracle);
    }

    /// @dev Sets all six feeds so the normalized basket equals `basketPrice`, published at the current block time.
    function _setBasketPrices(
        uint256 basketPrice
    ) internal {
        _setBasketPricesAt(basketPrice, vm.g

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

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 close VPI depth is claim-net pool assets and the fresh-VPI exemption only triggers at exactly zero depth, so a small positive depth produces a charge that exceeds any reasonable bound.

Impact

A minority-side trader's entire clearinghouse balance could stay frozen for at least 24 hours (168 hours in the test) unless it accepts a VPI charge of thousands of USDG to exit.

What the attacker needed

Trader claims at least equal to pool assets; degraded mode latched; attacker holds a losing dominant-side position; victim has an open minority-side position

The fix

The zero-depth treatment of protective exits should be extended to small positive depths, for example by using a depth of at least the post-close absolute skew or by skipping fresh positive VPI below a floor.

How it was found

  1. Set up a claims state where trader claims equal or exceed HousePool assets and degraded mode is latched.
  2. Control: the victim quotes a full close, bounds the charge at the quote plus 1% of notional, and the close executes at depth 0.
  3. Attack: the attacker commits a partial close of its losing LONG and the victim commits the same bounded close; one batch runs both in FIFO order.
  4. The attacker's loss realisation lifts pool assets just above claims, leaving a small positive depth, and the victim's close is refused on the action-charge constraint.
  5. The victim retries hourly for 168 hours and every retry is refused while withdrawals revert.
  6. The attacker closes its remaining position, depth rises, and the victim's bounded close then executes.

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 trading pool charges a fee based on how much a trade pushes the pool out of balance, and that fee is divided by the pool's spare cash. If the spare cash is almost nothing but not exactly nothing, the fee becomes enormous. Because the system also blocks withdrawals while a position is open, a trader whose close is refused cannot get any money out.

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 zer0luck_xint

View all

6 more disclosed reports, best first.

More from Plether

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.