Skip to content
Business logic Audit finding Advanced

ApplyClaimantRecapitalizationIntent overwrites the Senior high-water mark when one owner recapitalization meets exactly zero LP equity, so the revenue owed to Senior is paid to Junior

When a pool loss leaves both Senior and Junior principal at exactly zero, the recapitalization routine overwrites the Senior high-water mark with the recapitalization amount instead of preserving it. Revenue that should restore the impaired Senior tranche is then credited to Junior holders, who can redeem it.

emanueldlvg Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#99887 [SC-Low] applyClaimantRecapitalizationIntent overwrites the Senior high-water mark when one owner recapitalization meets exactly zero LP equity, so the revenue owed to Senior is paid to Junior

Submitted on Nov 15th 2026 at 16:27:54 UTC by @emanueldlvg for Audit Competition | Plether

Description

Affected contracts (in-scope commit a82d4fef; live on Arbitrum Sepolia v2.0.0)

The program states that the v2.0.0 Arbitrum Sepolia release is built from a commit whose packages/perps/src is identical to a82d4fef. The defect is in HousePoolPendingPreviewLib.applyClaimantRecapitalizationIntent, which HousePool inlines and runs in _reconcile after HousePoolReconcilePlanLib.planReconcile. The proof of concept runs in the repository's Foundry suite at the in-scope commit, with the release parameters, Pyth mocked by the suite's MockPyth and USDG by the suite's mock settlement token. No in-scope contract is modified.

Contract Arbitrum Sepolia v2.0.0 address Role in the issue
HousePool 0xeb5604c393843b2f3c347ec24fa9ddad6ab2131e Root cause. _reconcile first absorbs the loss (Senior high-water mark kept), then _applyPendingClaimantBucketsLive runs the inlined applyClaimantRecapitalizationIntent, which assigns seniorHighWaterMark = max(target, amount) when Senior and Junior principal are both zero
CfdEngine 0xca18a6783d7542f9d2f28f4f259772b74c4d6baa recapitalizePool and clearDegradedMode, the owner's documented recovery actions
TrancheVault (Senior) 0x5dc42ba5a1e8dd3e1b6868d10f66a9bf8fb5b83d Senior LP redemption, which loses the restoration revenue
TrancheVault (Junior) 0x4a8b67184a1e3224c11a191cc69f22c50eef734e Junior redemption, which receives it
OrderRouter 0x918663d6da8cb33b325a04c4a5e8c51d42f3b444 Public commitOrder / executeOrder / updateMarkPrice used for the market path and the later trading revenue

Release configuration used (packages/perps/DEPLOYMENT.md): vpiFactor 0.01, maxSkewRatio 0.4, maintenance margin 0.1 %, initial margin 0.2 %, frozen-market margin 3 %, base carry 5 %, liquidation bounty 10 bps (minimum 1 USDG, 50 % keeper share), execution fee 0.04 % (asserted), Senior cap 40,000,000 USDG and 80 % of the pool (applied through the owner's timelocked setter and asserted), Senior coupon 800 bps and frozen LP fees 25/75 bps (pool defaults, asserted), Junior maintenance fee 0, 1 USDG seed in each tranche. The release Router configuration is applied through the owner's 72-hour timelocked path: maxExecutionWindowSeconds 60, orderExecutionStalenessLimit 60, liquidationStalenessLimit 15, basketMaxConfidenceRatioBps 10, orderSettlementWindow 15, maxComponentPublishTimeDivergence 5, adverseConfidenceMultiplierBps 2500, minOpenNotionalAssets 1,000 USDG, open-order bounty 1 bp (0.01–0.2 USDG), protection trigger bounty 0.2 USDG, maxPendingOrders 5, minEngineGas 600,000, maxPruneOrdersPerCall 64. Every Pyth mark moves at most 1 % and passes the oracle's ordering and freshness checks.

Brief/Intro

The Senior high-water mark H is the Senior entitlement that later revenue must restore before Junior receives anything. Losses never lower it: absorbLoss leaves H "deliberately unchanged so future revenue continues to restore senior impairment", and the specification and whitepaper repeat that a loss does not reduce H.

HousePoolPendingPreviewLib.applyClaimantRecapitalizationIntent breaks this for a single owner recapitalization. In _reconcile, the loss is absorbed first. If that leaves Senior and Junior principal both exactly zero, the recapitalization takes a bootstrap branch that assigns seniorHighWaterMark = max(recapitalization target, amount) and discards the H that absorbLoss just preserved. If the loss leaves even one atom of principal, the gap branch runs instead and H survives. The same Senior shares remain outstanding in both cases, and no new Senior shares are minted.

The proof of concept drives the pool through a public market path to the price unit where terminal LP equity crosses zero. It then runs the owner's documented recovery (recapitalizePool(200,000 USDG), clearDegradedMode()) and one public settlement. The two runs differ only by one 1e-8 price unit in the last crisis close:

  • terminal LP equity 0.000000 USDG: the stored H of 300,001.001552 USDG becomes 200,000.000000 USDG;
  • terminal LP equity 0.011001 USDG: H is kept and, with the Senior coupon checkpointed in the same reconcile, stands at 312,233.926714 USDG.

The following ordinary LP revenue of 71,970.345220 USDG then goes entirely to Junior in the first run and entirely to Senior in the second. The Senior LP redeems 71,966.456737 USDG less (200,002.985257 instead of 271,969.441994), and the main Junior holder redeems 70,527.270000 USDG instead of 0. 0.011001 USDG of LP equity decides 112,233.926714 USDG of Senior entitlement.

Impact: High — Theft of unclaimed yield. Revenue that the protocol owes to the impaired Senior tranche until it reaches its high-water mark is paid to Junior holders instead.

Vulnerability Details

Losses keep the Senior high-water mark

HousePoolWaterfallAccountingLib.sol, lines 161–184:

Solidity
/// @notice Absorbs loss against junior principal first and senior principal second.
/// @dev Principal subtraction saturates at zero if loss exceeds all claimed equity. The senior high-water mark is
///      deliberately unchanged so future revenue continues to restore senior impairment.
/// @param state Waterfall state before loss.
/// @param lossAssets Loss to absorb in 6-decimal settlement token.
/// @return nextState State after the junior-first loss waterfall.
function absorbLoss(
    WaterfallState memory state,
    uint256 lossAssets
) internal pure returns (WaterfallState memory nextState) {
    nextState = state;
    if (lossAssets <= nextState.juniorPrincipal) {
        nextState.juniorPrincipal -= lossAssets;
        return nextState;
    }

    uint256 seniorLoss = lossAssets - nextState.juniorPrincipal;
    nextState.juniorPrincipal = 0;
    if (nextState.seniorPrincipal > seniorLoss) {
        nextState.seniorPrincipal -= seniorLoss;
    } else {
        nextState.seniorPrincipal = 0;
    }
}

ACCOUNTING_SPEC.md, line 337: "Charge a shortfall to Junior first, then Senior. Losses do not reduce the Senior high-water mark." WHITEPAPER.md, lines 627–636: "Let (H) be the senior high-water mark: the unimpaired senior entitlement that future revenue must restore before junior receives residual value … 3. Loss does not reduce (H). 4. Later revenue first restores (S) to (H)." SECURITY.md, line 394, lists the invariant "High-water-mark protection | Senior impairment must be restored before junior extracts surplus".

The loss is absorbed first, and the recapitalization is applied afterwards

_reconcile reserves the pending recapitalization out of distributable value (it is "settleable" up to distributable value, HousePool.sol lines 1829–1834). It plans the waterfall against the remaining, non-pending equity, stores that plan, and only then applies the recapitalization to the stored state:

HousePool.sol, lines 1564–1598 (abridged):

Solidity
HousePoolPendingPreviewLib.ClaimantPendingBuckets memory claimantBuckets = _getPendingClaimantBuckets();
HousePoolPendingPreviewLib.ClaimantPendingBuckets memory settleableClaimantBuckets =
    _settleablePendingClaimantBuckets(reconcileSnapshot, claimantBuckets);
...
HousePoolReconcilePlanLib.ReconcilePlan memory plan = HousePoolReconcilePlanLib.planReconcile(
    _currentPendingAccountingState(),
    reconcileSnapshot,
    _pendingClaimantBucketAssets(settleableClaimantBuckets),
    poolConfig.seniorRateBps,
    couponElapsed,
    markFresh
);
...
_setWaterfallState(plan.state.waterfall);
unassignedAssets = plan.state.unassignedAssets;
...
_applyPendingClaimantBucketsLive(settleableClaimantBuckets, claimantBuckets, allowRevenueContinuation);

In planReconcile the stored principal is compared with distributable - pending and the shortfall goes through absorbLoss (HousePoolReconcilePlanLib.sol, lines 84–105). With non-pending equity e, that leaves Junior at 0 and Senior at exactly e, with H unchanged.

A recapitalization that meets zero principal assigns a new high-water mark

_applyPendingClaimantBucketsLive (HousePool.sol, lines 1759–1776) then calls:

HousePoolPendingPreviewLib.sol, lines 103–137:

Solidity
/// @notice Routes recapitalization to senior restoration or to unassigned assets.
/// @dev With senior owners and zero claimed principal, all `amount` bootstraps senior principal and sets the
///      high-water mark to `max(recapitalizationTargetAssets, amount)`. Otherwise, senior principal is restored only
///      up to its high-water mark. Any remainder, including all value when there are no senior owners, becomes
///      unassigned; recapitalization never accrues to junior principal. Mutates `state` in place.
/// @param state In-memory accounting state to update.
/// @param amount Settleable recapitalization assets to apply.
/// @param recapitalizationTargetAssets Full recapitalization intent used as the high-water mark on an empty bootstrap.
function applyClaimantRecapitalizationIntent(
    PendingAccountingState memory state,
    uint256 amount,
    uint256 recapitalizationTargetAssets
) internal pure {
    uint256 remaining = amount;
    if (state.seniorSupply > 0) {
        if (state.waterfall.seniorPrincipal == 0 && state.waterfall.juniorPrincipal == 0) {
            state.waterfall.seniorPrincipal += remaining;
            state.waterfall.seniorHighWaterMark =
                recapitalizationTargetAssets > remaining ? recapitalizationTargetAssets : remaining;
            remaining = 0;
        } else {
            uint256 gap = state.waterfall.seniorHighWaterMark > state.waterfall.seniorPrincipal
                ? state.waterfall.seniorHighWaterMark - state.waterfall.seniorPrincipal
                : 0;
            if (gap > 0) {
                uint256 seniorAssignedAssets = remaining > gap ? gap : remaining;
                state.waterfall.seniorPrincipal += seniorAssignedAssets;
                remaining -= seniorAssignedAssets;
            }
        }
    }
    if (remaining > 0) {
        state.unassignedAssets += remaining;
    }
}
  • e == 0: lines 118–122 run. Senior principal becomes the recapitalization amount X, and H is overwritten with max(target, X). With a single recapitalization, target and amount are both X. The H that absorbLoss preserved is lost.
  • e >= 1 atom: lines 123–131 run. Senior principal becomes e + min(X, H - e) and H is untouched.

The same outstanding Senior shares, the same owner action and the same recapitalization amount end with two different Senior entitlements. The only difference is whether one atom of LP equity remained when the reconcile ran. In the proof of concept the whole recapitalization is applied in that first reconcile in both runs (pending residual 0), and one more ordinary settlement before any revenue leaves H unchanged in both runs.

The overwritten mark sends the next revenue to Junior

On the next reconcile with revenue, distributeRevenue restores Senior only up to H and credits the remainder to Junior (HousePoolWaterfallAccountingLib.sol, lines 140–159). After the overwrite, Senior already sits at its new H = X, so the whole 71,970.345220 USDG of revenue becomes Junior principal. With H intact, the same revenue restores Senior toward 312,233.926714 USDG and Junior receives nothing.

Documented behavior and the repository tests

The NatSpec above (lines 104–107) documents the bootstrap branch, and two repository tests assert it:

  • test/perps/accounting/waterfall/TrancheRecoveryBehavior.t.sol, lines 24–55, test_PostWipeoutRequiresExplicitRecapForHwmReset: a 50,000 USDG Senior seed, all pool tokens burned, a 10,000 USDG recapitalization, then assertEq(pool.seniorHighWaterMark(), recapAmount, "Explicit recapitalization should reset the HWM").
  • the same file, lines 577–610, test_SeniorRequiresExplicitRecapAfterFullWipeout: "Recapitalization should seed a fresh HWM".

These tests describe the intended treatment of a tranche whose value is gone. They do not make the cliff in this report intended:

  1. Both tests create the wipe by removing every pool token directly (settlementToken.burn(address(pool), pool.totalAssets()), or a transfer of the whole balance to 0xdead by the pool itself). Equity is exactly zero by construction, so neither test ever looks at a pool with a residual atom. Under real trading losses, equity lands at an arbitrary value, and the branch depends on whether it rounds to exactly zero.
  2. The same file asserts the opposite principle: lines 65–77, test_SeniorHighWaterMarkMustSurviveFullWipeout, assert "Senior recovery rights should survive wipeout". The public documents all state the survival rule: ACCOUNTING_SPEC.md line 337, WHITEPAPER.md lines 627–636 and SECURITY.md line 394. None of them mentions an exception for recapitalization.
  3. ACCOUNTING_SPEC.md lines 450–452 describe recapitalization as restoring the existing entitlement: "claimant recapitalization recorded through recordClaimantInflow(amount, Recapitalization, cashMode) may restore an existing protected senior entitlement above a reduced limit; it mints no new senior LP shares". In the zero-equity run, the existing entitlement is not restored. It is replaced by the recapitalization size, while the same Senior shares remain outstanding.
  4. The rule is discontinuous in a way no design would choose. In the proof of concept, 0.011001 USDG of remaining LP equity decides between keeping and erasing 112,233.926714 USDG of Senior entitlement. Within the same crisis, that difference comes from one 1e-8 price unit in the last close. The supplementary library test shows that the threshold is exactly one atom (S = 10M, J = 2.5M, H = 10M, recapitalization 1M: D = R gives H = 1M, D = R + 1 wei gives H = 10M).

Who triggers it and who benefits

The trigger is the owner's documented recovery runbook (SECURITY.md "Explicit terminal-deficit cascade": recapitalize, then clear degraded mode once E >= L), followed by any public settleLpEpoch. The program puts "a legitimate, documented action by a trusted role that triggers a bug harming users" in scope. The owner's recapitalization amount is an ordinary choice. It is meant to restore solvency and to restore Senior toward its entitlement. Nothing in the documentation tells the owner that the amount will also become Senior's new, lower entitlement.

The branch is decided by terminal LP equity at the first post-recapitalization reconcile. In the proof of concept that is set by the last crisis close, and no unprivileged actor steers it. The beneficiaries are the Junior holders at the time of the next revenue. They receive Senior's restoration revenue through ordinary Junior redemptions: the 980,000 USDG Junior holder redeems 70,527.270000 USDG that it would not otherwise receive. The losers are the Senior LPs, whose shares were never redeemed or diluted.

Exploitation

All steps are in test_SingleRecapErasesSeniorHighWaterMark_RevenueRedirectedToJunior. LP capital, trades and settlements go through the public TrancheVault, HousePool and OrderRouter entry points. Pyth marks are pushed with OrderRouter.updateMarkPrice, one mark of at most 1 % per trading day.

  1. LPs. Through the public request/settle/claim path, Junior receives 980,000 USDG from the main Junior holder and 4 × 5,000 USDG from four small Junior wallets. Senior receives 300,000 USDG from the Senior LP. Each tranche also holds its 1 USDG seed.
  2. Crisis (public market path). A fully margined hedge is opened at 1.00, interleaved: three SHORT orders of 430,000 units and two LONG orders of 400,000 units (1 unit = 1 USDG notional at 1.00; the proof asserts that no position has a carry borrow base). The price rises 60 % in 48 daily marks (66 calendar days). A second LONG account opens 300,000 units at the top (1.60), and the winning SHORT closes, which latches degraded mode (asserted). The price then falls in daily 1 % marks (87 trading-day marks), until closing both LONG accounts would leave no LP equity.
  3. Crossing. Inside the last 1 % move, the close price of both LONGs is bisected to adjacent 1e-8 price units: 0.67178025 (terminal LP equity 0.000000 USDG) and 0.67178026 (terminal LP equity 0.011001 USDG). Both runs start from one EVM snapshot. After the close, every step is identical.
  4. Owner (documented recovery). CfdEngine.recapitalizePool(200,000 USDG) once, then CfdEngine.clearDegradedMode(). The stored H before the reconcile is 300,001.001552 USDG.
  5. First public settlement. One small Junior wallet exits through settleLpEpoch, the first reconcile after the recapitalization. Zero-equity run: Senior principal 200,000.000000, H 200,000.000000. Positive-equity run: Senior principal 200,000.011001, H 312,233.926714. The increase over the stored 300,001.001552 is the Senior coupon accrued over the crisis and checkpointed in that reconcile. No recapitalization remains pending in either run.
  6. A second ordinary settlement (another small Junior wallet) leaves H unchanged in both runs.
  7. Revenue. A trader runs 20 identical losing LONG round trips of 70,000 USDG notional (five 1 % marks up, close, five back). LP revenue: 71,970.345220 USDG (zero-equity run) and 71,970.338965 USDG (positive-equity run).
  8. A settlement (the third small wallet's exit) reconciles the revenue. Zero-equity run: Senior 200,000.000000, Junior 71,970.345220. Positive-equity run: Senior 271,970.349966, Junior 0.
  9. The Senior LP and the main Junior holder request full redemptions, and a settlement funds them. Senior LP: 200,002.985257 USDG vs 271,969.441994 USDG. Junior holder: 70,527.270000 USDG vs 0.

test_Control_OneAtomOfEquityKeepsHighWaterMark runs the positive-equity run on its own. test_LibraryOrder_OneWeiDecidesHighWaterMark calls the real libraries in _reconcile order to show that the threshold is a single wei.

Impact Details

High — Theft of unclaimed yield.

  • Senior LP: −71,966.456737 USDG in redemption value (200,002.985257 vs 271,969.441994). Under the stored entitlement min(H, S + J + U), Senior's shortfall is 71,970.345220 USDG. That is the whole revenue that should have restored it.
  • Junior holders: +71,970.345220 USDG of Junior principal. The main Junior holder redeems 70,527.270000 USDG. The remaining small Junior wallets and the seed share the rest.
  • Entitlement erased: 112,233.926714 USDG of Senior high-water mark (312,233.926714 → 200,000.000000). Every later dollar of revenue up to that amount goes to Junior instead of Senior. The proof of concept realizes 71,970 USDG of it.
  • Preconditions: a pool loss that consumes all LP equity, which is the case the recapitalization runbook exists for, and the owner's documented recapitalization. All other steps are public. The cliff is at exactly zero: a recapitalization that meets any positive equity keeps H, and one that meets exactly zero erases it.

Recommendation

Do not let a recapitalization lower the high-water mark of Senior shares that still exist. Remove the special case for existing Senior supply, so the zero-principal state follows the same gap logic as every other state:

Solidity
if (state.seniorSupply > 0) {
    uint256 gap = state.waterfall.seniorHighWaterMark > state.waterfall.seniorPrincipal
        ? state.waterfall.seniorHighWaterMark - state.waterfall.seniorPrincipal
        : 0;
    uint256 seniorAssignedAssets = remaining > gap ? gap : remaining;
    state.waterfall.seniorPrincipal += seniorAssignedAssets;
    remaining -= seniorAssignedAssets;
}

If a fresh entitlement is wanted after a real wipeout, make it an explicit, separately documented owner decision (for example, a dedicated reset that emits an event), not a side effect of whether one atom of equity remained. At minimum, keep seniorHighWaterMark = max(storedHighWaterMark, target, amount) in the bootstrap branch.

Add a continuity test: for terminal LP equity e in {0, 1 wei, 1 USDG} and the same recapitalization, the Senior high-water mark after the first reconcile and the Senior/Junior split of later revenue must be the same, apart from e itself.

Proof of Concept

Save the test below as packages/perps/test/perps/poc/SeniorHighWaterMarkRecapReset.t.sol and run from the repository root:

Bash
forge test --root packages/perps --match-contract RecapitalizationHighWaterMarkResetPoC -vv

The file contains three tests:

  • test_SingleRecapErasesSeniorHighWaterMark_RevenueRedirectedToJunior: the zero-equity run and the positive-equity run from one snapshot, with the full comparison;
  • test_Control_OneAtomOfEquityKeepsHighWaterMark: the positive-equity (control) run alone;
  • test_LibraryOrder_OneWeiDecidesHighWaterMark: a supplementary illustration that calls the real libraries in _reconcile order. It is not an attack path.

It uses the repository's BasePerpTest, the suite's MockPyth and mock settlement token, and only public entry points apart from the owner's recapitalizePool and clearDegradedMode. There is no vm.store, etch or mockCall on in-scope contracts.

Complete test:

<details> <summary>Complete test </summary>
Solidity
// SPDX-License-Identifier: AGPL-3.0
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 {TrancheVault} from "@plether/perps/TrancheVault.sol";
import {IHousePool} from "@plether/perps/interfaces/IHousePool.sol";
import {IOrderRouterAdminHost} from "@plether/perps/interfaces/IOrderRouterAdminHost.sol";
import {HousePoolAccountingLib} from "@plether/perps/libraries/HousePoolAccountingLib.sol";
import {HousePoolPendingPreviewLib} from "@plether/perps/libraries/HousePoolPendingPreviewLib.sol";
import {HousePoolReconcilePlanLib} from "@plether/perps/libraries/HousePoolReconcilePlanLib.sol";
import {HousePoolWaterfallAccountingLib} from "@plether/perps/libraries/HousePoolWaterfallAccountingLib.sol";
import {MockPyth} from "@plether/test-utils/MockPyth.sol";

/// @title One owner recapitalization of a just-wiped pool overwrites the Senior high-water mark
/// @notice Claimed impact: High - Theft of unclaimed yield (the revenue that must restore Senior to its high-water mark
///         is credited to Junior instead).
///
///         HousePoolPendingPreviewLib.applyClaimantRecapitalizationIntent (lines 118-121): when the reconcile leaves
///         S == J == 0, a recapitalization ASSIGNS seniorHighWaterMark = max(recapitalization target, amount), discarding
///         the stored high-water mark that absorbLoss deliberately preserves ("Losses do not reduce the Senior
///         high-water mark", ACCOUNTING_SPEC.md line 337). If the same reconcile leaves even one atom of equity, the gap
///         branch (lines 123-131) runs instead and the stored high-water mark survives.
///
///         Scenario (public calls only apart from the owner's documented recovery; release parameters; MockPyth and
///         mock USDG are the only mocks):
///           1. LP capital enters through the public request/settle/claim path (Senior 300k, Junior 1M).
///           2. A fully margined hedge, a +60% leg and a -32..33% leg at one <=1% Pyth mark per trading day wipe the LP
///              tranches (trader claims ~= pool cash). The final close price is bisected to the 1e-8 price unit at
///              which terminal LP equity crosses zero, so the two branches below differ by ONE price unit at the
///              close (about 0.011 USDG of equity).
///           3. The owner's documented runbook: CfdEngine.recapitalizePool(X) once, then clearDegradedMode().
///           4. A public settleLpEpoch (any LP's ordinary exit). This is the FIRST reconcile after the single recap.
///           5. Ordinary losing trades bring revenue B; one more public settlement; both LPs redeem.
///
///         ZERO-EQUITY branch (terminal equity exactly 0 before the recap): step 4 overwrites the high-water mark
///         ~312k -> X. Revenue B then goes to Junior because Senior already sits at its new high-water mark X.
///         POSITIVE-EQUITY branch (terminal equity +0.011001 USDG): step 4 keeps the high-water mark ~312k, and revenue B
///         restores Senior. No recapitalization stays pending in either branch, and one extra ordinary settlement before
///         the revenue is asserted not to move the high-water mark.
contract RecapitalizationHighWaterMarkResetPoC is BasePerpTest {

    // --- actors ---
    address internal constant SHORT_ACCOUNT = address(0xA770C2);
    address internal constant LONG_A = address(0xA770A1);
    address internal constant LONG_B = address(0xA770B1);
    address internal constant REV_TRADER = address(0x5EE0A1);
    address internal constant SENIOR_LP = address(0x5E1105);
    address internal constant JUNIOR_LP = address(0x1D1105);
    address internal constant LP_EXIT_A = address(0x1D2001);
    address internal constant LP_EXIT_B = address(0x1D2002);
    address internal constant LP_EXIT_C = address(0x1D2003);
    address internal constant LP_EXIT_D = address(0x1D2004);
    address internal constant KEEPER = address(0xE0EC);

    // --- scenario constants ---
    uint256 internal constant ENTRY_PRICE = 1e8;
    uint256 internal constant TOP_PRICE = 160_000_000; // +60% in 1% daily marks
    uint256 internal constant CROSSING_SEARCH_START = 72_000_000; // start evaluating the zero-equity crossing here
    uint256 internal constant TICK_INTERVAL = 2 minutes;
    uint256 internal constant JUNIOR_MAIN = 980_000e6;
    uint256 internal constant EXIT_WALLET_DEPOSIT = 5_000e6;
    uint256 internal constant SENIOR_DEPOSIT = 300_000e6;
    uint256 internal constant RECAP = 200_000e6; // owner's single documented recapitalization
    uint256 internal constant BACKING_ROUNDS = 20;
    uint256 internal constant ROUND_NOTIONAL = 70_000e6; // < 40% skew cap of ~200k depth

    uint256 internal curPrice;
    uint256 internal orderNonce;

    struct Branch {
        uint256 closePrice;
        int256 equityBeforeRecap;
        uint256 hStoredBefore;
        uint256 sFirst;
        uint256 jFirst;
        uint256 hFirst;
        uint256 uFirst;
        uint256 pendingFirst;
        uint256 sExtra;
        uint256 hExtra;
        uint256 revenue;
        uint256 sFin;
        uint256 jFin;
        uint256 uFin;
        uint256 hFin;
        uint256 seniorUsdg;
        uint256 juniorUsdg;
    }

    // ------------------------------------------------------------------ configuration (release values)

    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 _initialJuniorDeposit() internal pure override returns (uint256) {
        return 0;
    }

    function _initialJuniorSeedDeposit() internal pure override returns (uint256) {
        return 1e6;
    }

    function _initialSeniorSeedDeposit() internal pure override returns (uint256) {
        return 1e6;
    }

    function setUp() public override {
        super.setUp();
        _applyReleaseRouterConfig();
        _setSeniorCapacity(40_000_000e6, 8_000);
        assertEq(pool.maxSeniorShareBps(), 8_000, "release Senior share cap");
        assertEq(pool.maxSeniorExposureAssets(), 40_000_000e6, "release Senior exposure cap");
        assertEq(engine.executionFeeBps(), 4, "release execution fee");
        assertEq(pool.seniorFrozenLpFeeBps(), 25, "release Senior frozen fee");
        assertEq(pool.juniorFrozenLpFeeBps(), 75, "release Junior frozen fee");
        assertEq(pool.seniorRateBps(), 800, "release Senior coupon");
        vm.warp(SETUP_TIMESTAMP + 7 days);
        curPrice = ENTRY_PRICE;
        _refreshMark(curPrice);

        uint256 jr = _requestDeposit(juniorVault, JUNIOR_LP, JUNIOR_MAIN);
        uint256 e1 = _requestDeposit(juniorVault, LP_EXIT_A, EXIT_WALLET_DEPOSIT);
        uint256 e2 = _requestDeposit(juniorVault, LP_EXIT_B, EXIT_WALLET_DEPOSIT);
        uint256 e3 = _requestDeposit(juniorVault, LP_EXIT_C, EXIT_WALLET_DEPOSIT);
        uint256 e4 = _requestDeposit(juniorVault, LP_EXIT_D, EXIT_WALLET_DEPOSIT);
        _warpTo(juniorVault.depositEpochStart(jr));
        _refreshMark(curPrice);
        pool.settleLpEpoch(0, 0);
        _claimDeposit(juniorVault, JUNIOR_LP, jr);
        _claimDeposit(juniorVault, LP_EXIT_A, e1);
        _claimDeposit(juniorVault, LP_EXIT_B, e2);
        _claimDeposit(juniorVault, LP_EXIT_C, e3);
        _claimDeposit(juniorVault, LP_EXIT_D, e4);
        uint256 sr = _requestDeposit(seniorVault, SENIOR_LP, SENIOR_DEPOSIT);
        _warpTo(seniorVault.depositEpochStart(sr));
        _refreshMark(curPrice);
        pool.settleLpEpoch(0, 0);
        _claimDeposit(seniorVault, SENIOR_LP, sr);
        _refreshMark(curPrice);
    }

    // ----------

The original report as published on Immunefi, by emanueldlvg. 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 bootstrap branch in applyClaimantRecapitalizationIntent assigns a new high-water mark when both principals are zero, instead of keeping the stored mark and only filling the gap.

Impact

Revenue owed to the impaired Senior tranche, about 71,970 USDG in the proof of concept, is paid to Junior holders instead, and the Senior LP redeems roughly 71,966 USDG less; the trigger requires a total loss of LP equity plus the owner's documented recapitalization.

What the attacker needed

Pool loss consumes all LP equity; owner runs documented recapitalization; public settlement follows

The fix

The report recommends removing the zero-principal special case so recapitalization only fills the gap up to the stored high-water mark, or at minimum keeping the maximum of the stored mark, target and amount.

How it was found

  1. LPs deposit through the public request, settle and claim path: 300,000 USDG to Senior and 1,000,000 USDG to Junior.
  2. A public market path of hedged orders and daily price marks drives the pool until closing the long positions would leave no LP equity.
  3. The final close price is bisected to adjacent price units, giving one run with zero terminal LP equity and one with a tiny positive amount.
  4. The owner runs the documented recovery: recapitalize the pool with 200,000 USDG, then clear degraded mode.
  5. A public settlement reconciles the pool; in the zero-equity run the Senior high-water mark drops to 200,000 USDG, in the other it stays above 312,000 USDG.
  6. A trader generates about 71,970 USDG of LP revenue, and a further settlement shows it all going to Junior in the zero-equity run and all to Senior in the other.

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 high-water mark is a record of how much money a group of investors is owed before anyone else gets paid. Normally a trading loss does not lower that record, so later profits go back to the investors who lost money. Here, if a loss wipes the pool down to exactly nothing and the owner then tops it up, the code replaces that record with the smaller top-up amount, so later profits go to the other investor group instead.

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 emanueldlvg

View all

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