Booked senior principal is paid to junior when the recap mark is replaced
The empty-book recapitalisation branch of the pool overwrites the high-water mark on each settle, so repeated settles shrink the recovery target down to the senior principal. Queued revenue then has no gap to restore and is credited to junior, letting a junior holder redeem cash that had been booked as senior principal.
- Disclosed after under an hour
#98667 [SC-High] Booked senior principal is paid to junior when the recap mark is replaced
Submitted on Nov 9th 2026 at 11:36:57 UTC by @Omisanin0 for Audit Competition | Plether
- Report ID: #98667
- Report Type: Smart Contract
- Report severity: High
- 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
An empty senior book is supposed to take a recapitalization once. The first settle books the cash as senior principal and sets the high-water mark to the whole queued recap. That mark is the recovery target the waterfall tests keep. The next settle reserves the residual recap against the same cash. The reserve eats the distributable balance, absorbLoss zeros the senior principal, and the empty-book branch runs again. It writes the mark down to the residual recap. One settle later the last recap slice and the queued revenue are reserved together. The mark is replaced again, down to that last slice, so the gap above senior principal is gone. The revenue is credited to junior, and the junior redeem in that epoch is paid from the cash. On this fork the senior principal booked at 340,000.385469 USDG falls by 220,000.156407 USDG. Bob, whose junior shares were worth nothing after the wipe, is paid 73,382.034131 USDG. The rest of the drop stays as junior principal. Alice's share of the booked senior was 226,593.732378 USDG. Her later redeem pays 79,975.781200 USDG.
Vulnerability Details
HousePoolPendingPreviewLib.applyClaimantRecapitalizationIntent is the empty-book branch. It runs only when senior supply is nonzero and both stored principals are zero (lines 117-122). It sets senior principal to the settleable recap amount and the high-water mark to max(full outstanding recap, that amount). Recap never goes to junior in this function. The waterfall test expects the first use of that branch: senior principal equals the settleable slice, and the mark stays on the gross recap so the residual can restore senior later (HousePoolWaterfall.t.sol line 201).
HousePool._reconcile (line 1555) does not apply the pending buckets to the stored principals. It plans the waterfall first. _settleablePendingClaimantBuckets (line 1829) caps the buckets to distributable assets, recap first. HousePoolReconcilePlanLib.planReconcile (lines 68-71) then subtracts that settleable total from distributable before it compares what is left with claimed principal. When the reserved pending is the whole cash balance, the waterfall sees a loss equal to the stored senior principal. absorbLoss (lines 167-184) zeros junior, then senior, and leaves the high-water mark where it was. The comment on that function says the mark is kept so later revenue can restore the impairment.
_reconcile writes that zeroed waterfall (line 1584) and then calls _applyPendingClaimantBucketsLive (line 1759). That function reads the waterfall it just wrote. Both principals are now zero, senior shares are still outstanding, and the empty-book branch runs on a book that had senior principal at the start of the call. The mark argument is the full outstanding recap, not the gross amount from the first settle. The branch overwrites the mark with max(residual recap, settleable slice).
The third settle is the one that pays. allowRevenueContinuation is sampled at line 1567, while senior principal is still nonzero, and line 1577 keeps it true after absorbLoss has zeroed the plan. Revenue is therefore allowed into the waterfall the empty-book branch just re-seeded. On this run the new mark equals the new senior principal, so the restoration gap is zero. applyRevenueIntent (lines 180-182) adds the revenue to junior principal. _settleLpEpoch has already reconciled (line 835). The junior phase prices the matured redeem on that principal, safeTransfers the settlement token into the vault (line 1007), and line 886 subtracts the funded amount from junior principal.
payOut (lines 604-613) decreases accountedAssets and transfers. It does not touch either pending bucket. A winning close can remove cash while a queued recap and a queued revenue balance stay at the old amounts. recordClaimantInflow always queues recap (line 644). It queues revenue only when both stored principals are already zero (lines 646-648). CfdEngineSettlementSidecar._executeClose sends a losing trader's pledge in through that function (lines 604-612). recapitalizePool (lines 632-652) transfers the owner's tokens into the pool and queues the same amount. It does not set the mark.
The cash has to sit in a band or the second replace never lines up with a junior credit. Let R be the queued recap and C the pool cash, with both principals still zero and the book flat.
- The first settle is the documented bootstrap. Settleable recap is
C, because recap is capped to distributable and takes priority over revenue. Senior principal becomesC. The mark becomesR. Pending recap left isR - C. Bob is paid nothing, because junior principal is still zero and the vault refunds the shares. - The second settle reserves
min(R - C, C). That equalsCwhenR > 2C. The waterfall loss is the senior principal just booked.absorbLosszeros it and keeps the mark atR. The empty-book branch then books senior principalCagain and replaces the mark withR - C. Pending recap left isR - 2C. Bob is paid nothing again. - The third settle reserves the last recap slice
R - 2Cand then revenue, up to the same cash cap. The revenue slice isC - (R - 2C) = 3C - R, providedR < 3Cand the queued revenue is at least that large. Reserving both spends the whole distributable balance, soabsorbLosszeros senior principal once more. The empty-book branch books senior principal atR - 2Cand sets the mark to the same number. The revenue has no gap left to fill and is credited to junior. The drop in senior principal isC - (R - 2C) = 3C - R.
A few atoms of senior principal left after absorbLoss skip the branch. The revenue requirement is what drives the loss all the way to zero. The test checks the band directly: residual recap greater than cash, recap under three times cash, and revenue large enough to fill 3C - R.
This run uses R = 800,001 USDG and C = 340,000.385469 USDG. 3C - R = 220,000.156407 USDG. The printed window is (266,667.000001, 400,000.499999), which is (R/3, R/2) in atoms. After the second settle the stored senior principal is still C and the mark is 460,000.614531, the residual recap. TrancheVault.convertToAssets reads getPendingTrancheState (HousePool line 1295), so it already shows the third settle: Alice 79,974.320476, Bob 73,382.034131. Neither wallet has been paid. The third settle commits that preview. Bob receives 73,382.034131. Junior principal left in the same settle is 146,618.122276. Those two add to the senior drop.
The path into that band is ordinary pool flow. Alice and Bob deposit through requestDeposit, settleLpEpoch, and claimDeposit. Short closes then pay the cash out through the engine. A short opened while the pool is large stores a max profit that a later fresh open cannot reach: the launch skew cap is 0.4e18, the helper stops a new short at 39% of depth, the minimum notional is 1,000 USDG, and _maxAdditionalProfit leaves the configured settlement buffer (launch value 25 bps). An 80 lot long, opened beside the 400 lot sweeper, has a smaller max profit than the short, so it does not raise the larger-side liability. After the fresh drains stop, the sweeper is closed at the cap for its stored max profit and the long is closed down to the last atom of cash. Claims stay zero. The cash leaves through HousePool.payOut, which the engine calls on the close.
The close that spends the last cash latches degraded mode while that long is still open for the last lot. Once the lot is gone, both side max profits are zero and pool cash is zero. CfdEngine.clearDegradedMode (lines 658-666) is the owner's recovery for that state: it requires cash, net of trader claims, to cover the larger side's max profit, and here both sides are zero. HousePool._requireWithdrawalsLive (line 1867) reverts HousePool__DegradedMode until that call. The three settles that move the senior cash are Bob's redeems. They go through pool.settleLpEpoch as the deployed router. The owner calls are the recap queue and the flat-book clear. Neither call takes a mark.
Bob's redeem on the empty book is refunded. absorbLoss zeros both principals and leaves the high-water mark. Alice's senior shares stay, and convertToAssets on them is zero. The owner then calls recapitalizePool(800_001e6). Principals are still zero, so the 2,800 lot losing long, filled at one quarter of the cap and closed at the cap, queues its loss as revenue. Winning shorts shave the cash into the band. The pending buckets are unchanged by those payouts.
F-580 is the first apply. It treats the gross mark of 800,001 as the bug. The waterfall test at line 201 says that mark is the recovery target, and revenue after it restores senior up to the mark before junior is credited. The payment here is the second apply and the third. They replace that mark. With the mark pulled down to the senior principal the third settle just wrote, the queued revenue is junior principal, and the redeem transfers it out of the cash the previous settle had booked to senior.
Impact Details
Impact: Direct theft of any user funds, whether at-rest or in-motion, other than unclaimed yield. Critical.
The senior principal was booked, and the shares were still outstanding. The paying settle reduces that principal and credits junior. Bob's shares are burned for USDG. The junior principal left in the same settle belongs to the junior shares that remain.
Settlement token is the deployment's USDG, 6 decimals. The protocol prices 1 USDG at $1, so the figures below are the dollar amounts of this fork. Perps is not on mainnet. This is the measured loss for this recap and this cash level.
| Account | Before the paying settle (USDG) | After that settle (USDG) |
|---|---|---|
| Senior principal | 340,000.385469 | 120,000.229062 |
| Junior principal | 0 | 146,618.122276 |
| Bob wallet | 0 | 73,382.034131 |
Bob's wallet plus the junior principal left is 220,000.156407. The senior drop is 220,000.156407. The test requires those two integers to be equal. Senior principal of 120,000.229062 is still on the books after the settle.
Alice's shares times the senior principal from the second settle, divided by senior supply, is 226,593.732378. That is her claim on the booked cash. Her redeem, after the owner's later junior exit, pays 79,975.781200. The test requires that payout to be more than 1,000 USDG under the booked share.
The owner's later junior redeem pays 116,616.695145. The vault's seed floor is why the requested shares and the claimable shares differ: 1,000,008.000056000 requested, 795,390.191563960 claimable. That redeem, and Alice's, settle the revenue still pending after the theft (200,475.153302). The books move again. juniorPrincipalLeft in the final log line is that later balance, 10,006.659914. The equality uses 146,618.122276, the junior principal still stored when the third settle returned.
Bob's junior shares were refunded on the wipe, so the shares that receive the credit were not bought at a positive NAV. The drain, the losing long, and the shave are engine fills. Their margin is the token's own mint on this testnet deployment. The closes in the log leave the trader wallet unchanged because the payout sits in the clearinghouse. The USDG that leaves the pool for Bob is the 73,382.034131 on the third settle.
The same band scales with the queued recap. Any cash strictly between R/3 and R/2, with queued revenue of at least 3C - R, gives up 3C - R of already booked senior principal on the third settle. This demonstration is 220,000.156407 USDG, about $220,000.16.
References
packages/perps/src/libraries/HousePoolPendingPreviewLib.sol:applyClaimantRecapitalizationIntent(line 111), empty-book write (lines 117-122).applyRevenueIntent(line 158) credits junior at lines 180-182.capClaimantBuckets(line 72) gives recap priority over revenue.packages/perps/src/libraries/HousePoolReconcilePlanLib.sol:planReconcile(line 47) subtracts settleable pending at lines 68-71, thenabsorbLossat lines 102-104.packages/perps/src/libraries/HousePoolWaterfallAccountingLib.sol:absorbLoss(line 167) zeros principal and does not write the high-water mark.planReconcile(line 98).packages/perps/src/HousePool.sol:_reconcile(line 1555),allowRevenueContinuation(lines 1567 and 1577),_applyPendingClaimantBucketsLive(line 1759),_settleablePendingClaimantBuckets(line 1829),_settleLpEpoch(line 824) reconciles at line 835, junior funding subtracts principal at line 886,safeTransferat line 1007,payOut(line 604),recordClaimantInflow(line 624),getPendingTrancheState(line 1295), degraded-mode revert (line 1867).packages/perps/src/CfdEngine.sol:recapitalizePool(line 632),clearDegradedMode(line 658),_payOrRecordTraderClaim(line 840),_availableCashForFreshPoolPayouts(line 865).packages/perps/src/CfdEngineSettlementSidecar.sol:_executeCloserecords revenue at lines 604-612 and records the trader payout at line 618.packages/perps/src/TrancheVault.sol:convertToAssets(line 521) prices offgetPendingTrancheState.packages/perps/test/perps/accounting/waterfall/HousePoolWaterfall.t.solline 201. The gross recap mark is the recovery target of the first empty-book apply.packages/perps/DEPLOYMENT.md. LaunchmaxSkewRatio0.4e18,settlementBufferBps25,executionFeeBps4.- Source pin
a82d4fefb02768e5b3bddcc97dee371eee24fea8.
Proof of Concept
Proof of Concept
The in-scope deployment is Arbitrum Sepolia v2.0.0. The test forks that chain at block 324500000 and talks to the contracts already there. It deploys nothing. Chain id is 421614. HousePool 0xeB5604c393843B2f3c347Ec24Fa9dDaD6Ab2131e must have codehash 0x5e684cc82bfc5b697a24c80ef26910cfbe25efbe6fb2ca184c421808b5ced957 or the test stops. Junior vault 0x4A8b67184a1E3224c11A191cc69F22C50EEf734e. Senior vault 0x5Dc42Ba5a1E8DD3E1B6868D10f66A9bf8Fb5B83d. Engine 0xcA18a6783D7542F9D2F28F4f259772b74C4D6bAA. Clearinghouse 0xB5B851f627d6Df3CF3F096E23e20a58884D7b89A. Settlement token 0x3d051DbBf5Ff427a4aE8Ad09746902666Af8FB9D.
No in-scope contract is mocked. The test does not call vm.etch, vm.mockCall, vm.deal, or vm.store. There is no Pyth mock. mint is that token's own public mint. It funds the two deposits, the trader margin, and the owner recap. It is not called on the payment. Opens and closes call processOrderTyped as the deployed router, with pool.totalAssets() as the depth argument. Marks call updateMarkPrice as that same router. A rejected open or close is reverted with the snapshot. The call that is kept is not reverted. The price on the way in is one quarter of the cap. The prices on the way out are the closes the search accepts. clearDegradedMode runs only after cash is zero and both side max profits are zero. The impact asserts run on the third settle, before the later owner and Alice redeems. USDG totalSupply does not change across the three settles.
Run from the Foundry project at audit-comp-plether/packages/perps/foundry.toml (solc 0.8.35, via IR, optimizer runs 200). Forge from the repo root compiles nothing. Foundry is the only dependency. No API key, no private key, no --ffi. If ARB_SEPOLIA_RPC_URL is unset, the test uses https://arbitrum-sepolia.gateway.tenderly.co.
cd audit-comp-plether/packages/perps
forge test --match-contract F534EmptyBookRecapFork --threads 1 -vv
One run of that command passed. Exit status 0. Suite result: 1 passed, 0 failed. Gas 17,869,418. Finished in 576.56ms on a warm cache. The test asserts chain id 421614 and the HousePool codehash above. The log prints forkChainId 421614 and forkBlock 324500000.
Steps:
- Fork Arbitrum Sepolia at block 324500000. Warp to timestamp 1793572200, Sunday 2026-11-01 22:30:00 UTC, after the 17:00 New York open, so the oracle is not frozen. Refresh the stored mark. Long and short open interest are both 0. The pool already holds the seed: cash 2,000,002.000000, senior principal 1,000,001.000017, junior principal 1,000,000.999983.
- Alice deposits 2,000,000 USDG into senior. Request 498215, shares 1,998,031.868256533. Bob deposits 500,000 USDG into junior. Request 498216, shares 500,502.212373974. Each deposit is
requestDeposit, thensettleLpEpoch, thenclaimDeposit. Pool cash is 4,500,002.000000. Senior principal is 3,000,996.425866. Junior principal is 1,499,005.574134. Alice'sconvertToAssetsis 2,000,018.264839. Bob's is 499,999.999999. - Open a 400 lot short for the sweeper at one quarter of the cap. Stored max profit is 60,000. Open an 80 lot long for the finisher. Stored max profit is 4,000. Two fresh short drains then pay the pool down: 29,525 lots, cash 73,614.284444, then 89 lots, cash 60,271.404444. The next pass has room for 0 lots. Close the sweeper at the cap. Cash left 302.960000, claims 0. Partial-close 79 lots of the long at price 46,289,062. Cash left 11.416632. Close the last lot at price 38,574,218. Cash 0, claims 0.
degradedOnFlatBookis true. Both side max profits are 0.engine.owner()callsclearDegradedMode. The latch clears. - Bob redeems the junior shares. The vault refunds all 500,502.212373974 shares.
absorbLosszeros both principals. Alice's senior share balance is unchanged. HerconvertToAssetsis 0. The high-water mark left behind is 3,001,051.238586. - The engine owner calls
recapitalizePoolwith 800,001 USDG. Pending recap is 800,001. Both principals stay 0. A 2,800 lot long, same entry, closes at the cap and queues 420,122.499846 of revenue. Cash is 1,220,123.499846. Four winning short closes shave cash to 340,000.385469. Pending recap is still 800,001. Pending revenue is 420,475.309709, the loss plus the open and close fees that also queued. The window is 266,667.000001 to 400,000.499999. Principals are still 0. Alice's preview, which already includes the pending buckets, reads 226,593.732378. Bob's preview is 0. - Bob requests a full junior redeem. The first settle refunds the shares. Senior principal becomes 340,000.385469. The mark becomes 800,001. Pending recap left is 460,000.614531. Junior principal is 0. Bob is paid 0. Cash does not move.
- Bob requests again. The second settle refunds the shares. Senior principal stays 340,000.385469. The mark is replaced with 460,000.614531. Pending recap left is 120,000.229062. Bob is paid 0. Cash does not move.
convertToAssetsnow prices Alice at 79,974.320476 and Bob at 73,382.034131. Both wallets are still 0. - Bob requests a third time. The settle pays 73,382.034131 into his wallet. Senior principal falls to 120,000.229062. Junior principal left in that settle is 146,618.122276. The mark is 120,000.229062. Pending recap is 0. Pending revenue left is 200,475.153302. Cash falls by Bob's payment, from 340,000.385469 to 266,618.351338. Before any later redeem, the test checks that this wallet gain equals the pool cash drop, that the wallet gain plus the junior principal left equals the senior drop of 220,000.156407, and that USDG
totalSupplyis unchanged. pool.owner()(0x5a71a4094Ec81165Ada48AA4c27dA48ec27E0d6B) then redeems junior and is paid 116,616.695145. Alice redeems senior and is paid 79,975.781200. Those two redeems are after the snapshot. The equality does not include them.
The lines below are the snapshots and the checks. The command also prints each open, each close, and the drain passes.
forkChainId 421614
forkBlock 324500000
housePool 0xeB5604c393843B2f3c347Ec24Fa9dDaD6Ab2131e
pin
cash 2000002000000
seniorP 1000001000017
juniorP 1000000999983
hwm 1000001000017
longOi 0
shortOi 0
depositAccount 0x328809Bc894f92807417D2dAD6b7C998c1aFdac6
depositAssets 2000000000000
depositRequest 498215
depositShares 1998031868256533
depositAccount 0x1D96F2f6BeF1202E4Ce1Ff6Dad0c2CB002861d3e
depositAssets 500000000000
depositRequest 498216
depositShares 500502212373974
deposited
cash 4500002000000
seniorP 3000996425866
juniorP 1499005574134
aliceAssets 2000018264839
bobAssets 499999999999
sweeperLots 400
sweeperMaxProfit 60000000000
finisherLots 80
finisherMaxProfit 4000000000
drainPass 0
drainCash 4500002284444
drainLots 29525
drainPass 1
drainCash 73614284444
drainLots 89
drainPass 2
drainCash 60271404444
drainLots 0
sweeperClosePayout 60000000000
cashAfterSweeperMax 302960000
claimsAfterSweeperMax 0
partialExit 46289062
cashAfterPartial 11416632
finalExit 38574218
cashAfterExactClose 0
claimsAfterExactClose 0
degradedOnFlatBook true
longMaxOnFlatBook 0
shortMaxOnFlatBook 0
wiped
cash 0
seniorP 0
juniorP 0
hwm 3001051238586
aliceAssets 0
bobRefundOnWipe 0
recapQueued 800001000000
queuedRevenue 420122499846
cashAfterShave 340000385469
armed
cash 340000385469
seniorP 0
juniorP 0
hwm 3001051238586
pendRecap 800001000000
pendRev 420475309709
aliceAssets 226593732378
bobAssets 0
windowLow 266667000001
windowHigh 400000499999
settle1
cash 340000385469
seniorP 340000385469
juniorP 0
hwm 800001000000
pendRecap 460000614531
pendRev 420475309709
bobPaidThisSettle 0
settle2
cash 340000385469
seniorP 340000385469
juniorP 0
hwm 460000614531
pendRecap 120000229062
pendRev 420475309709
aliceAssets 79974320476
bobAssets 73382034131
bobPaidThisSettle 0
settle3
cash 266618351338
seniorP 120000229062
juniorP 146618122276
hwm 120000229062
pendRecap 0
pendRev 200475153302
bobUsdg 73382034131
bobPaidThisSettle 73382034131
IMPACT seniorPrincipalBefore 340000385469
IMPACT seniorPrincipalAfter 120000229062
IMPACT seniorPrincipalDrop 220000156407
IMPACT bobWalletBefore 0
IMPACT bobWalletAfter 73382034131
IMPACT bobWalletGain 73382034131
IMPACT juniorPrincipalLeft 146618122276
IMPACT juniorReceived 220000156407
IMPACT poolCashBefore 340000385469
IMPACT poolCashAfter 266618351338
IMPACT poolCashDrop 73382034131
IMPACT tokenSupplyBeforeSettles 11316731409009
IMPACT tokenSupplyAfterSettles 11316731409009
fundsAtRiskUsdg 220000
juniorReceivedAtTheft 220000156407
seniorPrincipalDrop 220000156407
redeemAccount 0x5a71a4094Ec81165Ada48AA4c27dA48ec27E0d6B
redeemShares 1000008000056000
claimableShares 795390191563960
redeemedAssets 116616695145
redeemAccount 0x328809Bc894f92807417D2dAD6b7C998c1aFdac6
redeemShares 1998031868256533
redeemedAssets 79975781200
bobPaid 73382034131
ownerJuniorPaid 116616695145
alicePaid 79975781200
aliceAssetsAfterTheft 79974320476
aliceShareOfBookedSenior 226593732378
juniorPrincipalLeft 10006659914
poolCashLeft 50033299570
tokenSupplyIncrease 9316729409009
The IMPACT lines are printed before the owner and Alice redeems. IMPACT juniorReceived equals IMPACT seniorPrincipalDrop. IMPACT poolCashDrop equals IMPACT bobWalletGain. IMPACT tokenSupplyBeforeSettles equals IMPACT tokenSupplyAfterSettles. The later juniorPrincipalLeft is the balance after those redeems.
Full test, audit-comp-plether/packages/perps/test/perps/fork/F534EmptyBookRecapFork.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";
/// @notice Fork PoC for the empty-book recap overwrite. Local Anvil fork only. Do not broadcast.
/// @dev Run from `packages/perps` with that directory's foundry.toml
/// (solc 0.8.35, via_ir, optimizer runs 200):
///
/// forge test --match-contract F534EmptyBookRecapFork --threads 1 -vv
///
/// Optional env: ARB_SEPOLIA_RPC_URL. If unset, the test forks
/// https://arbitrum-sepolia.gateway.tenderly.co at block 324500000.
/// The file forks the deployed HousePool, vaults, engine, clearinghouse, router, and USDG.
/// It does not deploy over those addresses and does not call vm.etch, vm.mockCall, vm.deal,
/// or vm.store. There is no Pyth mock. `mint` is the deployed token's own mint. It funds
/// deposits, the owner recap, and trader margin. It is not called on the payment below.
/// Opens, closes, and marks are `processOrderTyped` and `updateMarkPrice` as
/// `engine.orderRouter()`, with `pool.totalAssets()` as the depth. A rejected open or close
/// is reverted with the snapshot. The call that is kept is not reverted.
/// The impact is checked on the third settle, before the later owner and Alice redeems.
/// Senior principal drop equals Bob's wallet gain plus the junior principal left in that
/// settle. Pool USDG falls by the same wallet gain. USDG totalSupply does not change
/// across the three settles.
contract F534EmptyBookRecapForkTest 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 (standard time).
uint256 constant LIVE_TS = 1_793_572_200;
uint256 constant ALICE_SENIOR = 2_000_000e6;
uint256 constant BOB_JUNIOR = 500_000e6;
uint256 constant RECAP = 800_001e6;
uint256 constant MIN_NOTIONAL = 1_000e6;
address constant POOL = 0xeB5604c393843B2f3c347Ec24Fa9dDaD6Ab2131e;
address constant JUNIOR = 0x4A8b67184a1E3224c11A191cc69F22C50EEf734e;
address constant SENIOR = 0x5Dc42Ba5a1E8DD3E1B6868D10f66A9bf8Fb5B83d;
address constant ENGINE = 0xcA18a6783D7542F9D2F28F4f259772b74C4D6bAA;
address constant CLEARINGHOUSE = 0xB5B851f627d6Df3CF3F096E23e20a58884D7b89A;
address constant TOKEN = 0x3d051DbBf5Ff427a4aE8Ad09746902666Af8FB9D;
bytes32 constant POOL_CODEHASH = 0x5e684cc82bfc5b697a24c80ef26910cfbe25efbe6fb2ca184c421808b5ced957;
IUsdG internal token;
IPool internal pool;
IVault internal junior;
IVault internal senior;
IEngine internal engine;
address internal owner;
address internal router;
address internal alice;
address internal bob;
address internal drainer;
address internal sweeper;
address internal finisher;
address internal loser;
address internal winner;
function setUp() public {
string memory rpc = vm.envOr("ARB_SEPOLIA_RPC_URL", string("https://arbitrum-sepolia.gateway.tenderly.co"));
vm.createSelectFork(rpc, FORK_BLOCK);
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);
owner = pool.owner();
router = engine.orderRouter();
alice = makeAddr("alice");
bob = makeAddr("bob");
drainer = makeAddr("drainer");
sweeper = makeAddr("sweeper");
finisher = makeAddr("finisher");
loser = makeAddr("loser");
winner = makeAddr("winner");
}
function test_Fork_EmptyBookReplacePaysSeniorPrincipalToJunior() public {
uint256 supplyBefore = token.totalSupply();
console2.log("forkChainId", block.chainid);
// createSelectFork pins the L2 block. On this chain block.number is the L1 block.
console2.log("forkBlock", FORK_BLOCK);
console2.log("housePool", POOL);
_warpUntilOracleLive();
_refreshMark(engine.lastMarkPrice());
_log("pin");
(uint256 longOi,,,) = engine.sides(0);
(uint256 shortOi,,,) = engine.sides(1);
console2.log("longOi", longOi);
console2.log("shortOi", shortOi);
require(longOi == 0 && shortOi == 0, "fork book is not flat");
// Step 1. Real senior and junior deposits. Alice is the senior victim. Bob holds
// junior shares that are worth nothing after the wipe and later receive the cash.
_deposit(senior, alice, ALICE_SENIOR);
_deposit(junior, bob, BOB_JUNIOR);
_log("deposited");
uint256 aliceShares = senior.balanceOf(alice);
uint256 bobShares = junior.balanceOf(bob);
require(aliceShares > 0 && bobShares > 0, "deposits minted no shares");
// Step 2. Real short closes pay the pool cash out. A sweeper short is opened while the
// pool is large enough to store its max profit, then closed after the geometric drains
// for the tail a new open can no longer take. The flat settle then absorbs the loss
// and both stored principals become 0. Shares stay.
uint256 entry = _lowEntry();
_refreshMark(entry);
_drainToZero(entry);
_log("drained");
require(token.balanceOf(POOL) == 0, "drain left pool cash");
require(engine.totalTraderClaimBalanceAssets() == 0, "drain left a trader claim");
uint256 bobRefund = _redeemAndCollect(junior, bob);
_log("wiped");
console2.log("bobRefundOnWipe", bobRefund);
require(pool.seniorPrincipal() == 0 && pool.juniorPrincipal() == 0, "wipe did not zero both principals");
require(senior.balanceOf(alice) == aliceShares, "wipe burned alice");
require(junior.balanceOf(bob) > 0, "wipe burned bob");
require(senior.convertToAssets(aliceShares) == 0, "alice still has senior assets after the wipe");
// Step 3. While both principals stay 0, the owner recap only queues. A losing long
// close then queues revenue through the settlement sidecar. A winning short close
// pays most of that cash out. payOut does not shrink either pending bucket.
_mi
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 empty-book recapitalisation branch rewrites the high-water mark from the outstanding recap on every settle instead of keeping the gross mark, so after absorbLoss zeroes the principals the mark is repeatedly pulled down to the newly booked senior principal.
Impact
A junior holder could be paid cash that had been booked as senior principal, with the senior principal dropping by about 220,000 USDG in this fork, though the figures are specific to this recap and cash level and perps is not on mainnet.
What the attacker needed
Fork of the deployed testnet contracts; owner recapitalisation call; cash between R/3 and R/2; queued revenue of at least 3C - R
The fix
The empty-book branch should preserve the gross recapitalisation mark rather than replacing it with the residual recap, so revenue restores senior principal before junior is credited.
How it was found
- Fork Arbitrum Sepolia at the stated block and warp past the oracle open so the stored mark can be refreshed.
- Alice deposits into senior and Bob into junior via request, settle and claim.
- Open a sweeper short and a finisher long, drain cash with fresh shorts, then close positions until pool cash and both side max profits are zero, and clear degraded mode.
- Bob redeems junior; the vault refunds the shares and absorbLoss zeros both principals while the mark stays.
- The owner recapitalises the pool and a losing long plus winning shorts shave cash into the band between a third and a half of the queued recap.
- Bob requests a junior redeem three times; the first two refund, the third pays out and senior principal drops.
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 splits money between a senior part (safer, paid first) and a junior part (riskier, absorbs losses first). A 'high-water mark' is a remembered target the pool uses to decide when senior losses have been repaid before junior gets anything. Here, each time the pool settled, it quietly lowered that target, so incoming revenue was handed to the junior side instead of repaying senior, and a junior holder could withdraw cash that belonged to senior depositors.
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.