Skip to content
Business logic Audit finding Advanced

Re-reserved recapitalization residual in HousePool lowers the Senior high-water mark and lets Junior take Senior's recovery

A residual from a recapitalization that was only partly absorbed by a terminal deficit stays pending and is reserved again on later reconciles, even though that value already backs Senior principal. This lets a Junior holder trigger reconciles that drop the Senior high-water mark and divert recovery revenue to Junior, taking about 8,493 USDG from the Senior LP.

zer0luck_xint Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#99115 [SC-High] Re-reserved recapitalization residual in HousePool lowers the Senior high-water mark and lets Junior take Senior's recovery

Submitted on Nov 11th 2026 at 23:39:16 UTC by @zer0luck_xint for Audit Competition | Plether

Description

Brief/Intro

After a terminal deficit, the owner recovers the pool with CfdEngine.recapitalizePool and clearDegradedMode. The part of the recapitalization that the deficit absorbs stays in pendingRecapitalizationAssets, and each later mark-fresh reconcile reserves it from distributable value even though the same value already backs the Senior principal assigned from this recapitalization. When the residual is at least the distributable value, the reservation empties Senior principal and the empty-waterfall bootstrap restarts Senior with only the residual as its high-water mark, so Senior's recovery target falls with no loss and no new inflow. A holder of Junior shares can trigger these reconciles through permissionless LP epoch settlement, and when the basket recovers, the revenue that should restore Senior principal to its high-water mark is paid to Junior holders instead: in the release configuration the attacker withdraws 8,493.18 USDG and the Senior LP withdraws 8,493.23 USDG less than without the attack.

Vulnerability Details

Let R be the recapitalization and D the terminal deficit at the current mark price. After the recapitalization, distributable value is R - D.

1. The first reconcile after the recapitalization. _settleablePendingClaimantBuckets caps the pending recapitalization at the whole distributable value:

https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/HousePool.sol#L1829-L1834

Solidity
        return HousePoolPendingPreviewLib.capClaimantBuckets(claimantBuckets, reconcileSnapshot.distributable);

planReconcile reserves the capped R - D, so the waterfall sees zero equity and both tranches are wiped. _applyPendingClaimantBucketsLive then applies R - D through the empty-waterfall bootstrap. The bootstrap target is meant to be the full recapitalization intent (HousePoolPendingPreviewLib.sol:110), and on this first reconcile the caller passes the whole pending amount R. Senior principal becomes R - D and the high-water mark becomes R:

https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/libraries/HousePoolPendingPreviewLib.sol#L46-L49

https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/libraries/HousePoolPendingPreviewLib.sol#L103-L122

The residual D stays pending. The project's regression test for this state requires the residual to keep Senior's recovery target and to settle into Senior principal once backing returns (HousePoolWaterfall.t.sol:201, :217):

https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/test/perps/accounting/waterfall/HousePoolWaterfall.t.sol#L177-L219

2. The next reconcile counts the same value twice. At an unchanged mark price, distributable value is still R - D, and all of it backs Senior principal R - D. _settleablePendingClaimantBuckets caps the residual D at that same distributable value, so for R <= 2D it reserves all of R - D, and planReconcile subtracts it:

https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/libraries/HousePoolReconcilePlanLib.sol#L68-L71

By design, the reserved amount is value already represented in snapshot.distributable that ordinary reconciliation must not assign a second time (HousePoolReconcilePlanLib.sol:41-42, ACCOUNTING_SPEC.md:336-340). Here that value is Senior's principal, so the reservation creates a shortfall equal to Senior principal and the waterfall charges it to Senior:

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

The bootstrap runs whenever Senior shares exist and both principals are zero (HousePoolPendingPreviewLib.sol:117-122). At this reconcile no loss has occurred: pool assets, trader claims and Senior principal are unchanged since the first reconcile, so the zero principal comes only from the reservation. With Senior principal at zero, _applyPendingClaimantBucketsLive takes the bootstrap again. This time the caller passes the residual D as the recapitalization intent, which gives a high-water mark of max(D, R - D) = D. Senior principal returns to R - D, the high-water mark falls from R to D, and pendingRecapitalizationAssets drops to 2D - R. The next reconcile applies that remainder through the ordinary restore step.

3. Recovery pays Junior. Revenue restores Senior principal up to its high-water mark and then pays Junior (ACCOUNTING_SPEC.md:338). With the high-water mark at D instead of R, Junior receives the recovered value between D and R.

Steps 2 and 3 depart from the accounting design. The high-water mark records the Senior entitlement that future revenue must restore, and even a real loss does not reduce it (ACCOUNTING_SPEC.md:332-337); here it falls at a reconcile with no loss at all. Senior impairment is restored before Junior extracts surplus (SECURITY.md:394), and reserved pending claimant inflows are not counted twice (ACCOUNTING_SPEC.md:339-340).

The cap and the bootstrap target were added in commit 31a38bb7 (Plether-Fi/plether-core#29) so that unsettled recapitalization stays pending and reserved until it is backed. The defect reported here is introduced by that change. The residual instead settles against value that is already assigned, and the first such settlement lowers the recovery target. A single additional pool.reconcile() before backing returns makes the project's regression test fail with Residual recap should settle once backing becomes available: 50040000000 != 100000000000.

Trigger. On the release deployment, the permissionless mark-fresh reconcile runs inside OrderRouter.settleLpEpoch(bytes[]). The reconcile runs first, and the whole call reverts unless some request makes progress (HousePool.sol:835, :1183-1185). In the demonstrated depressed-mark state, a refunded Junior redemption provides that progress. Queued tranche deposits do not settle, because the entry check rejects a pending claimant bucket or a Senior principal below its high-water mark (HousePool.sol:908, :1108, HousePoolTrancheGateLib.sol:32-38). A Senior redemption cannot be funded while the pending residual is at least the free cash, because the residual is reserved from free cash (HousePool.sol:1727-1735). A Junior redemption at zero Junior principal quotes zero and is refunded, and the refund counts as progress (HousePool.sol:960-985). The holder claims the refund and requests again in the next eligible LP epoch.

Impact Details

Severity: High, Theft of unclaimed yield.

The misrouted value is pool revenue that arrives after the attack: reconciliation books the rise in distributable value as revenue and distributes it through the waterfall (HousePoolReconcilePlanLib.sol:92-99). No tranche holds it when the high-water mark falls; the waterfall owes it to Senior restoration and instead credits it to Junior. The attacker's settlements leave credited Senior principal unchanged at 24,250.00 USDG; the loss arises only when that revenue arrives. Any holder of Junior shares wiped by the deficit can carry out the attack for gas and the Pyth update fee. When backing returns, Senior LPs lose the misrouted recovery and Junior holders, including the attacker, receive it pro rata.

The owner's recapitalizePool and clearDegradedMode are the protocol's recovery actions (packages/perps/SECURITY.md:155-162, :246) and behave as designed; every harmful step after them is permissionless.

In the release deployment with release parameters, the control and the attack start from the same snapshot after the first post-recapitalization settlement. Both refresh the 0.30 mark at the same 2 follow-up times, then run the same recovery settlement and final cash claims. They differ in the attacker's 2 refunded Junior redemption requests at the depressed mark. In the control nobody queues an LP request while the basket stays depressed, and both settlement attempts revert together with their reconciles because no request makes progress (HousePool.sol:1183-1185). The attacker holds every Junior share apart from the owner's seed position.

Control Attack
Terminal deficit D / recapitalization R 40,495.25 / 64,745.25 same
Senior high-water mark after the first follow-up settlement attempt 64,745.25 40,495.25
Senior principal plus funded redemptions after recovery 49,000.00 40,495.25
Junior principal after recovery 0.00 8,504.75
USDG the Senior LP withdraws 48,987.85 40,494.62
USDG the attacker withdraws for its Junior shares 0.00 8,493.18

Recapitalizing Senior's remaining impairment does not restore the intended state either. If the owner recapitalizes the gap between Senior principal and its high-water mark (40,495.25 USDG) after the first settlement, the next settlement at the depressed mark price reserves it together with the residual, wipes Senior again, and the bootstrap sets the high-water mark to 80,990.50 instead of 64,745.25. Recovery revenue that belongs to Junior once Senior is restored to 64,745.25 therefore goes to Senior up to the 16,245.25 USDG excess of the raised mark, and at recovery Junior principal reaches only 8,504.75 USDG (test_followUpRecapitalization).

Prerequisites:

  • A terminal deficit that wipes both tranches. Risk-increasing opens and LP redemption funding keep signed terminal equity non-negative at any single mark price (SECURITY.md:339, :342; WHITEPAPER.md:218-238), so a deficit needs a profitable close that latches degraded mode (CfdEngine.sol:1351-1369) and then opposite-side profit at a later mark price above the remaining backing (WHITEPAPER.md:268-290). With the pool at the withdrawal firewall and equal LONG and SHORT maximum-profit liabilities, as in the scenario, the 2 profits must together exceed 1.0025 times that liability (1 plus the 25 bps settlement buffer, DEPLOYMENT.md:143). A symmetric move therefore needs a fall of at least 40.1% and then a rise to at least 40.1% above entry from the scenario's entry price of 1.20, and 50.1% each way from an entry price of 1.00. In the scenario, public trades and a Junior redemption to the firewall produce the deficit at mark prices 1.20, 0.30, 1.99 and 0.30 (Proof of Concept steps 2-4). The protocol persists this state on reconcile and blocks LP entry (SECURITY.md:346), contains it with degraded mode, and handles it with the terminal-deficit runbook, whose recovery steps are to recapitalize or clear positions and then clear degraded mode (SECURITY.md:1499-1510).
  • A settlement at which the residual is at least the distributable value, so that the reservation empties Senior principal. At an unchanged mark price this means R <= 2D, which holds in this scenario (64,745.25 <= 80,990.50, with R equal to the clearDegradedMode minimum plus 1,000 USDG). Because clearDegradedMode requires pool assets net of trader claims to cover the larger side's maximum-profit liability (CfdEngine.sol:655-667), R exceeds D by at least the remaining maximum-profit liability less the net profit of the open positions at that mark price, so the deficit must be at least that difference.
  • The basket stays at the depressed mark price through 3 eligible LP epoch settlements after clearDegradedMode. The first creates the residual, the second lowers the high-water mark to D, and the third applies the 2D - R remainder through the restore step (this needs 2D - R < R - D; here 16,245.25 < 24,250.00). The attacker supplies the second and third, 2 hours apart in the PoC.
  • No Senior redemption request is waiting at those settlements. A matured Senior request that free cash cannot fund stops the Junior phase (HousePool.sol:878-879), and the settlement reverts.
  • Revenue after the attack. Revenue first restores Senior principal from R - D to the lowered high-water mark D, so Junior receives only revenue above 2D - R (16,245.25 USDG here), and the amount moved is at most R - D. In the scenario this revenue comes from the basket's return from 0.30 to 1.20.

The high-water mark falls by R - D (24,250.00 USDG here), which bounds the recovery that can move to Junior; in the scenario 8,504.75 USDG of credited principal moves, and after the final cash claims the Senior LP has received 8,493.23 USDG less and the attacker 8,493.18 USDG more. The Senior LP has no remaining wallet or queued redemption shares at that point.

Recommendation

While part of a recapitalization that bootstrapped an empty waterfall is still pending, a later bootstrap from that residual should keep the Senior high-water mark the first bootstrap recorded instead of replacing it with the pending amount. HousePool can track this with a flag that is set when a bootstrap leaves a residual and cleared when pendingRecapitalizationAssets reaches zero. While the flag is set, the live and the preview reconcile both pass the current high-water mark as the bootstrap target to applyPendingClaimantBucketsPreview. The residual then keeps settling and releasing free cash as it does at the audit commit, and a follow-up recapitalization of the gap between Senior principal and its high-water mark restores Senior to its existing target. HousePool's runtime is 24,571 bytes at the audit commit, 5 bytes below the EIP-170 limit of 24,576 bytes, so the added flag and branches need other HousePool code moved into a library or sidecar.

References

  • Audit commit: https://github.com/immunefi-team/audit-comp-plether/tree/a82d4fefb02768e5b3bddcc97dee371eee24fea8
  • Change that added the cap and the bootstrap target: Plether-Fi/plether-core#29 (commit 31a38bb7)
  • Senior high-water mark and reconciliation order: packages/perps/ACCOUNTING_SPEC.md:333-340; recapitalization routing: ACCOUNTING_SPEC.md:634-643
  • Owner recovery: packages/perps/SECURITY.md (Owner-funded recapitalization), CfdEngine.sol:632 (recapitalizePool), CfdEngine.sol:658-667 (clearDegradedMode)
  • Release parameters: packages/perps/DEPLOYMENT.md and script/DeployPerpsArbitrumSepolia.s.sol

Proof of Concept

Proof of Concept

The test deploys the release contracts with script/DeployPerpsArbitrumSepolia.s.sol inside Forge. 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.
  • USDG: the release MockUSDG.
  • The ArbSys block-number precompile.

The PoC is a single file, RecapResidualHwmReset.t.sol, with 2 tests. test_recapResidualResetsSeniorHighWaterMark runs the attack through public entry points; only step 5 uses the owner's recovery functions:

  1. A Junior LP (the attacker) deposits 200,000 USDG and a Senior LP deposits 30,000 USDG.
  2. 5 traders open positions at 1.20 (LONG 70,000 and SHORT 105,000 basket units).
  3. The attacker requests redemption of 95% of its Junior shares; settlement funds it down to the withdrawal firewall.
  4. The basket moves to 0.30, where trader A closes its LONG for cash. It then moves to 1.99, where B and H close and X closes 15,000 of its 27,500 units; B takes the remaining cash, and the unpaid trader claims of H and X total 33,530.41 USDG. Back at 0.30, signed terminal equity is -40,495.25 USDG and degraded mode is latched.
  5. The owner calls recapitalizePool(R) with R equal to the clearDegradedMode minimum plus 1,000 USDG, then calls clearDegradedMode.
  6. The attacker requests a redemption of all its Junior shares, and an arbitrary address (the test's keeper, which holds no role) calls OrderRouter.settleLpEpoch (settlement 1). The test checks that the high-water mark equals R, Junior principal is zero and the pending recapitalization equals D, then takes a snapshot.
  7. Control: the mark is refreshed at 0.30 at 2 follow-up times, 2 hours apart, and nobody queues an LP request. Both settlement attempts at 0.30 revert with HousePool__NoLpEpochProgress, so the high-water mark stays at R. The basket then recovers to 1.20, where a Senior redemption request for 2,000 USDG of shares settles.
  8. Attack: at those same 2 timestamps, the attacker's refunded Junior requests settle at 0.30, with pool assets, trader claims and Senior principal unchanged and the high-water mark lower. Then the same Senior redemption request settles at 1.20.
  9. In both sequences the remaining traders close at 1.20, and both LPs request redemption of their wallet shares in the next settlement and claim funded cash and refunds. The Senior LP has no wallet or queued redemption shares afterward; the reported Junior amount is USDG already claimed at that point.
  10. The test checks equal timestamps and equal total LP equity in both sequences, Junior principal of zero and an impaired Senior in the control, a positive Junior principal in the attack, and that the attacker's withdrawn USDG matches the Senior LP's shortfall within 1 USDG.

test_followUpRecapitalization repeats steps 1-6, then has the owner recapitalize the gap between Senior principal and its high-water mark, and checks that the high-water mark rises above R and that Senior takes recovery revenue up to the raised mark.

On a fresh clone of the audit commit, run git submodule update --init --recursive. Create test/poc/ at the repository root, place RecapResidualHwmReset.t.sol (source 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/RecapResidualHwmReset.t.sol -vv

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

[PASS] test_recapResidualResetsSeniorHighWaterMark() (gas: 35321929)
Logs:
  terminal deficit D at the depressed mark       40495248820
  owner recapitalization R                   64745248820
  unpaid trader claims C at the depressed mark 33530409810
  after settlement #1 at the depressed mark
     seniorPrincipal / juniorPrincipal  24250000000 0
     seniorHighWaterMark / pendingRecap 64745248820 40495248820
  CONTROL after recovery
     seniorPrincipal / juniorPrincipal  48120000000 0
     seniorHighWaterMark / pendingRecap 63582477005 0
  ATTACK after settlement #2 at the depressed mark
     seniorPrincipal / juniorPrincipal  24250000000 0
     seniorHighWaterMark / pendingRecap 40495248820 16245248820
  ATTACK after settlement #3 at the depressed mark
     seniorPrincipal / juniorPrincipal  24250000000 0
     seniorHighWaterMark / pendingRecap 40495248820 0
  ATTACK after recovery
     seniorPrincipal / juniorPrincipal  39615248820 8504751180
     seniorHighWaterMark / pendingRecap 39615248820 0
  --- attack minus control
  Senior tranche (principal + funded escrow) control / attack 49000000000 40495248820
  Junior principal                           control / attack 0 8504751180
  Senior LP share value delta
  -8504467693
  Attacker Junior position value delta
  8504594262
  Owner Junior seed value delta
  156918
  --- final LP settlement and cash claims (traders closed)
  Senior LP USDG received  control / attack 48987854348 40494622539
  Attacker USDG received   control / attack 0 8493177453
  Senior LP USDG delta (attack - control)
  -8493231809
  Attacker USDG delta (attack - control)
  8493177453

Excerpt from the same output for test_followUpRecapitalization, which Forge prints first (deployment lines omitted):

[PASS] test_followUpRecapitalization() (gas: 28611768)
Logs:
  FOLLOW-UP: R / gap recapitalized 64745248820 40495248820
  FOLLOW-UP after the next settlement
     seniorPrincipal / juniorPrincipal  64745248820 0
     seniorHighWaterMark / pendingRecap 80990497640 16245248820
  FOLLOW-UP after one more settlement
     seniorPrincipal / juniorPrincipal  64745248820 0
     seniorHighWaterMark / pendingRecap 80990497640 0
  FOLLOW-UP after recovery
     seniorPrincipal / juniorPrincipal  78990497641 8504751180
     seniorHighWaterMark / pendingRecap 78990497641 0
     unassignedAssets 0
  FOLLOW-UP final cash claims: Senior LP USDG / Junior holder USDG 80989240695 154326210695
Suite result: ok. 2 passed; 0 failed; 0 skipped; finished in 81.06ms (119.29ms CPU time)

For an independent regression in the project's own test suite, add one extra reconcile to test_PendingRecapitalization_CapsAgainstTraderClaimLiabilitiesAndCarriesResidual in packages/perps/test/perps/accounting/waterfall/HousePoolWaterfall.t.sol, immediately before _setTotalTraderClaim(0); makes the backing available. HousePool.reconcile accepts only a vault caller (onlyVault), so the extra call is pranked as the Senior vault, like the test's own reconcile that follows it.

packages/perps is a separate Foundry project. From the repository root, apply the change and run the test in that directory:

Bash
cd packages/perps
git apply <<'EOF'
--- a/test/perps/accounting/waterfall/HousePoolWaterfall.t.sol
+++ b/test/perps/accounting/waterfall/HousePoolWaterfall.t.sol
@@ -210,6 +210,8 @@
         assertEq(viewData.freeAssets, 0, "Residual pending recap should reserve remaining free liquidity");
         assertEq(pool.getMaxSeniorWithdraw(), 0, "Residual pending recap should reserve senior withdrawals");
 
+        vm.prank(address(seniorVault));
+        pool.reconcile(); // one extra reconcile at an unchanged state
         _setTotalTraderClaim(0);
         vm.prank(address(seniorVault));
         pool.reconcile();
EOF
forge test --match-path test/perps/accounting/waterfall/HousePoolWaterfall.t.sol --match-test test_PendingRecapitalization_CapsAgainstTraderClaimLiabilitiesAndCarriesResidual -vv

Result excerpt (compiler output and the suite and failure summaries omitted):

[FAIL: Residual recap should settle once backing becomes available: 50040000000 != 100000000000] test_PendingRecapitalization_CapsAgainstTraderClaimLiabilitiesAndCarriesResidual() (gas: 764203)

Source files

RecapResidualHwmReset.t.sol

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

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";

// Release deployment fixture: deploys the release contracts with script/DeployPerpsArbitrumSepolia.s.sol inside
// the local Forge EVM, as test/scripts/MockUSDGPerpsLifecycle.t.sol does: release wrappers (Senior cap 40M/80%, adverse
// multiplier 2500, minOpenNotional 1000 USDG), release risk parameters, six Pyth feeds with inversions. Only out-of-scope
// components are mocked: Pyth (MockPyth etched at the release Pyth address), USDG (the release MockUSDG), ArbSys (address(100)).

/// @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.getBlockTimestamp());
    }

    function _setBasketPricesAt(
        uint256 basketPrice,
        uint256 publishTime
    ) internal {
        for (uint256 i; i < 6; ++i) {
            _setFeed(i, basketPrice, publishTime);
        }
    }

    /// @dev Sets one component so that it alone would give normalized basket `basketPrice`, at `publishTime`.
    function _setFeed(
        uint256 i,
        uint256 basketPrice,
        uint256 publishTime
    ) internal {
        PletherOracle oracle = _oracle();
        uint256 normalizedPrice = oracle.basePrices(i) * basketPrice / 1e8;
        uint256 feedPrice = oracle.inversions(i) ? 1e16 / normalizedPrice : normalizedPrice;
        MockPyth(RELEASE_PYTH).setPrice(oracle.pythFeedIds(i), int64(uint64(feedPrice)), int32(-8), publishTime);
    }

    /// @dev Same as _setFeed with an explicit confidence (in feed units).
    function _setFeedWithConf(
        uint256 i,
        uint256 basketPrice,
        uint64 conf,
        uint256 publishTime
    ) internal {
        PletherOracle oracle = _oracle();
        uint256 normalizedPrice = oracle.basePrices(i) * basketPrice / 1e8;
        uint256 feedPrice = oracle.inversions(i) ? 1e16 / normalizedPrice : normalizedPrice;
        MockPyth(RELEASE_PYTH).setPrice(oracle.pythFeedIds(i), int64(uint64(feedPrice)), conf, int32(-8), publishTime);
    }

    /// @dev A non-encoded payload makes the MockPyth double use the configured per-feed prices.
    function _updateData() internal pure returns (bytes[] memory data) {
        data = new bytes[](1);
        data[0] = "";
    }

    function _refreshMark(
        uint256 basketPrice
    ) internal {
        _setBasketPrices(basketPrice);
        vm.prank(keeper);
        d.router.updateMarkPrice(_updateData());
    }

    // ---------------------------------------------------------------- time

    function _warp(
        uint256 dt
    ) internal {
        vm.warp(vm.getBlockTimestamp() + dt);
        vm.roll(vm.getBlockNumber() + 1 + dt / 4);
    }

    function _warpTo(
        uint256 t
    ) internal {
        uint256 nowTs = vm.getBlockTimestamp();
        require(t >= nowTs, "warp back");
        vm.roll(vm.getBlockNumber() + 1 + (t - nowTs) / 4);
        vm.warp(t);
    }

    // ---------------------------------------------------------------- USDG and LPs

    function _mint(
        address to,
        uint256 amount
    ) internal {
        d.settlementToken.mint(to, amount);
    }

    function _vault(
        bool senior
    ) internal view returns (TrancheVault) {
        return senior ? d.seniorVault : d.juniorVault;
    }

    function _requestDeposit(
        bool senior,
        address lp,
        uint256 assets
    ) internal returns (uint256 requestId) {
        TrancheVault v = _vault(senior);
        _mint(lp, assets);
        vm.startPrank(lp);
        d.settlementToken.approve(address(v), assets);
        requestId = v.requestDeposit(assets, lp, lp);
        vm.stopPrank();
    }

    /// @dev Warps to the request's epoch start (if not past) and settles through the Router's atomic oracle route.
    function _settleEpoch(
        uint256 requestId,
        uint256 basketPrice
    ) internal {
        uint256 start = d.housePool.lpEpochStart(requestId);
        if (vm.getBlockTimestamp() < start) {
            _warpTo(start);
        }
        _setBasketPrices(basketPrice);
        vm.prank(keeper);
        d.router.settleLpEpoch(_updateData());
    }

    function _claimDeposit(
        bool senior,
        address lp,
        uint256 requestId
    ) internal returns (uint256 shares) {
        TrancheVault v = _vault(senior);
        uint256 claimable = v.claimableDepositRequest(requestId, lp);
        vm.prank(lp);
        shares = v.claimDeposit(requestId, 

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 residual pending recapitalization is reserved from distributable value that already backs Senior principal, and the empty-waterfall bootstrap then replaces the Senior high-water mark with the residual instead of keeping the original target.

Impact

A Junior holder could divert recovery revenue owed to Senior, with the Senior LP receiving 8,493.23 USDG less and the attacker 8,493.18 USDG more in the release configuration; the loss only materialises once revenue arrives after the attack.

What the attacker needed

A terminal deficit that wipes both tranches; residual at least the distributable value; depressed mark held for 3 LP settlements; no waiting Senior redemption request

The fix

While a recapitalization residual is still pending, a later bootstrap should keep the Senior high-water mark recorded by the first bootstrap rather than replacing it with the pending amount, tracked with a flag that is cleared when the pending amount reaches zero.

How it was found

  1. A Junior LP deposits and a Senior LP deposits, then traders open positions.
  2. The attacker requests redemption of most Junior shares, and settlement funds it down to the withdrawal firewall.
  3. The basket moves down and up so that closing positions leaves a terminal deficit and degraded mode is latched.
  4. The owner recapitalizes the pool and clears degraded mode.
  5. The attacker requests redemption of all Junior shares and a permissionless keeper settles the LP epoch, creating the residual.
  6. At the depressed mark the attacker's refunded Junior requests settle twice more, lowering the high-water mark, then the basket recovers and the attacker claims the misrouted value.

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 lending pool has two groups of depositors: Senior, who are meant to be paid back first, and Junior, who take more risk. After a big loss the owner puts money back in to rescue the pool. A leftover slice of that rescue money is counted twice, so the pool forgets how much the Senior depositors are still owed. When the market recovers, the profit that should repay Senior goes to Junior 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 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.