RecapitalizePool after a full LP wipe overwrites the Senior high-water mark with the recapitalization amount, so revenue owed to pre-wipe Senior LPs is credited to Junior principal
After a full wipe of both LP tranches, the owner's documented recapitalizePool action overwrites the Senior high-water mark with the recapitalization amount instead of preserving the pre-wipe Senior entitlement. Later trading revenue that should restore Senior LPs is therefore credited to Junior principal, so pre-wipe Senior LPs receive less than they are owed.
Originally disclosed on Immunefi
- Disclosed after under an hour
#99720 [SC-Low] recapitalizePool after a full LP wipe overwrites the Senior high-water mark with the recapitalization amount, so revenue owed to pre-wipe Senior LPs is credited to Junior principal
Submitted on Nov 14th 2026 at 22:59:52 UTC by @Naresh_Kandula for Audit Competition | Plether
- Report ID: #99720
- Report Type: Smart Contract
- Report severity: Low
- Target: https://github.com/immunefi-team/audit-comp-plether/tree/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src
- Impacts:
- Contract fails to deliver promised returns, but doesn't lose value
Description
Severity and impact
- Severity: Low
- Impact (program row): Contract fails to deliver promised returns, but doesn't lose value.
- Asset:
packages/perps/src/libraries/HousePoolPendingPreviewLib.sol(used byHousePool), commita82d4fefb02768e5b3bddcc97dee371eee24fea8. - Trigger:
CfdEngine.recapitalizePool, the owner's documented recovery action (program scope: "a legitimate, documented action by a trusted role that triggers a bug harming users or the protocol"). - Loser: pre-wipe Senior LPs. Their restoration entitlement (
seniorHighWaterMark) is replaced by the recap amount, so later revenue that should restore them accrues to Junior principal.
Description
What the high-water mark promises
seniorHighWaterMark is the Senior entitlement that later revenue must restore after a loss:
packages/perps/ACCOUNTING_SPEC.md:332-333: "seniorHighWaterMarkrecords the Senior entitlement that future revenue must restore after a loss."packages/perps/ACCOUNTING_SPEC.md:337: "Charge a shortfall to Junior first, then Senior. Losses do not reduce the Senior high-water mark."packages/perps/ACCOUNTING_SPEC.md:338: "Route surplus first to restore Senior principal to its high-water mark, then to Junior."packages/perps/src/libraries/HousePoolWaterfallAccountingLib.sol:9-10: "The high-water mark tracks unimpaired senior entitlement: losses do not reduce it".
The loss path implements this. absorbLoss (HousePoolWaterfallAccountingLib.sol:167-184) floors both principals at zero and leaves the mark untouched. Its NatSpec (:162-163) says: "The senior high-water mark is deliberately unchanged so future revenue continues to restore senior impairment." After a loss larger than all claimed equity, the stored state is therefore seniorPrincipal == 0, juniorPrincipal == 0, and seniorHighWaterMark equal to the pre-wipe Senior entitlement. In the PoC this is 21,000.018264 USDG.
How a recapitalization destroys it
CfdEngine.recapitalizePool(packages/perps/src/CfdEngine.sol:632-653) pulls USDG from the owner and records it as aRecapitalizationclaimant inflow (:649-651).ACCOUNTING_SPEC.md:639-643documents this, andSECURITY.md:155-163lists it as the owner-funded recovery action. Step 4 of the terminal-deficit runbook (packages/perps/SECURITY.md:1499-1511) is "Recapitalize or clear positions" (:1509).- At the next reconcile,
HousePool._applyPendingClaimantBucketsLive(packages/perps/src/HousePool.sol:1759-1776) callsHousePoolPendingPreviewLib.applyPendingClaimantBucketsPreview(:1769-1771). It then stores the result through_setWaterfallState(:1774), which writesseniorHighWaterMarkat:1883. Every projection uses the same helper (HousePool.sol:1672-1674): entry/exit previews andisSeniorImpairedAfterPendingDepositReconcile. applyPendingClaimantBucketsPreviewroutes the recap toapplyClaimantRecapitalizationIntent(HousePoolPendingPreviewLib.sol:46-49). Inside it:
// packages/perps/src/libraries/HousePoolPendingPreviewLib.sol:117-132 @ a82d4fef
if (state.seniorSupply > 0) {
if (state.waterfall.seniorPrincipal == 0 && state.waterfall.juniorPrincipal == 0) {
state.waterfall.seniorPrincipal += remaining;
state.waterfall.seniorHighWaterMark =
recapitalizationTargetAssets > remaining ? recapitalizationTargetAssets : remaining; // <-- overwrites
remaining = 0;
} else {
uint256 gap = state.waterfall.seniorHighWaterMark > state.waterfall.seniorPrincipal
? state.waterfall.seniorHighWaterMark - state.waterfall.seniorPrincipal
: 0;
... // restores Senior toward the EXISTING mark
}
}
When both principals are zero, which is exactly the state absorbLoss produces on a full wipe, lines :118-122 assign seniorHighWaterMark = max(recapitalizationTargetAssets, remaining). recapitalizationTargetAssets is the total outstanding recapitalization bucket (:38, :48, :110). It is an amount the owner chose, not the Senior entitlement. The pre-wipe mark is thrown away. With any nonzero principal, the else branch (:123-132) instead restores Senior toward the existing mark.
- Later revenue fills only
seniorHighWaterMark - seniorPrincipalbefore reaching Junior (HousePoolPendingPreviewLib.sol:169-183, andHousePoolWaterfallAccountingLib.distributeRevenueat:147-158). Once the mark has been lowered to the recap amount, the Senior gap is zero (or only the deficit portion, see below). Revenue that the spec routes to Senior restoration (ACCOUNTING_SPEC.md:338) goes tojuniorPrincipal, which is held by the Junior shares that existed before the wipe.
The result: a loss charged to Senior is preserved by design at loss time (absorbLoss) and is then written off as a side effect of the owner adding cash. The write-off is larger when the owner adds less cash.
Documented-path behaviour (test C)
The runbook funds the trader-claim deficit and the restart with recapitalizePool. On that path the bootstrap branch fires on the first recap. The mark then becomes the owner's cumulative recap intent: 8,609.469578 USDG, made of the 3,609.469577 deficit paid out to trader claims plus the 5,000 partial recap. The pre-wipe 21,000.018264 entitlement is gone. Senior principal is 5,000, so Senior stays "impaired" by the deficit amount even though none of that deficit was Senior's loss. The overwrite does not leave the pool in a state matching either Senior's real entitlement or a clean restart.
Attack steps (no attacker needed)
- Senior and Junior LPs deposit (PoC: 20,000 USDG each on top of the 1,000 USDG seeds).
- Real trading and price moves drive the pool into terminal deficit. Both tranches are wiped (
seniorPrincipal == juniorPrincipal == 0), trader claims exceed pool cash, and the engine enters degraded mode.seniorHighWaterMarkstays at 21,000.018264. - The owner follows the runbook: it funds the trader-claim deficit, clears degraded mode, and makes a partial
recapitalizePool(5_000e6). - The first reconcile that applies the recap (here, the epoch that settles an ordinary 10% Senior redemption) stores
seniorHighWaterMark = 5,000(arm A) or8,609.47(arm C, documented path only). The mark is not kept at the pre-wipe level. - New trading revenue arrives. Revenue that the pre-wipe mark would route to Senior goes to Junior principal.
- The Senior LP redeems and receives less USDG than it would if the mark had been preserved.
Impact (measured)
All numbers come from the PoC output below. All values are in USDG (6 decimals).
| Quantity | A: principals exactly 0 (bootstrap branch) | B: control, Senior keeps 1 atom (gap branch) | C: documented path only |
|---|---|---|---|
| Pre-wipe stored Senior HWM | 21,000.018264 | 21,000.018264 | 21,000.018264 |
| Owner USDG spent | 8,609.469576 | 8,609.469577 | 8,609.469577 |
| Senior impaired after the partial recap | no | yes | yes (by the deficit) |
| Stored Senior principal / HWM after the 10% Senior exit | 4,523.809938 / 4,523.809938 | 4,523.809939 / 19,038.191914 | 4,523.809939 / 7,789.520807 |
| Senior HWM erased vs B | 14,514.381976 (76.2%) | 0 | 11,248.671107 (59.1%) |
| Real trading revenue routed to Senior / Junior principal | 0 / 2.263355 | 2.263355 / 0 | not run |
| Senior LP total USDG received | 4,751.186344 | 4,753.325214 | not run |
| Junior LP (ATT) USDG received | 0 | 0 | not run |
| Pool raw USDG after | 251.077011 | 248.938142 | not run |
- Realised loss in the PoC: the Senior LP receives 2.138870 USDG less in A than in B, for the same owner spend (1 atom difference). That is 0.045% of its 4,753.33 USDG exit. In A, 100% of the 2.263355 USDG of real revenue generated after the recap goes to Junior principal; in B it goes to Senior.
- Exposure: the erased mark is 14,514.38 USDG (A) or 11,248.67 USDG (C) after the partial exit, and 16,000.02 / 12,390.55 USDG before it. That much future revenue now goes to Junior principal instead of restoring Senior. The PoC generates only 2.26 USDG of revenue, so the realised figure is far smaller than the exposure. The exposure is realised in proportion to the revenue the pool earns after the restart.
- Value does not leave the protocol. It moves between LP tranches, which is why the impact is "fails to deliver promised returns" rather than theft.
Limitations (disclosed, with their cost)
- Trusted trigger. No unprivileged actor is involved. The trigger is the owner's documented
recapitalizePool, which the program puts in scope when a documented action triggers a bug. The owner can avoid the loss only by recapitalizing at least the full pre-wipe mark. Any partial recap after a full wipe writes off the difference. - Precondition: a full LP wipe with claims above cash. The PoC reaches it with the repo's own handler-driven trading sequence. It uses non-default risk parameters (
maintMarginBps 10,initMarginBps 20,vpiFactor 0.01e18, against base-test defaults of 100 / 150 / 0) and 20k/20k LP deposits, and the price walks run from 20% to 70%. These parameters only serve to reach the wipe. The overwrite itself is a pure function of(seniorPrincipal, juniorPrincipal, seniorHighWaterMark, recap)inHousePoolPendingPreviewLib.sol:111-137and does not depend on risk parameters. The project's own test, run at the base test's default risk parameters (packages/perps/test/perps/spec/lp/HousePoolSeededSetup.t.sol:58-80, wipe simulated by a USDG burn), shows the same thing: after a wipe, a 500 USDG recap clears the stale pre-wipe mark. - Arm B is a control, not the documented path. B admits the deficit +1 atom through the owner-only
HousePool.accountExcess()(HousePool.sol:568-579, documented atACCOUNTING_SPEC.md:637). It exists only to show that the else branch keeps the mark when any principal is nonzero. On the documented path (C), every recap after a full wipe takes the bootstrap branch. - Design intent. The NatSpec at
HousePoolPendingPreviewLib.sol:104-107describes themax(target, amount)formula. The project testHousePoolSeededSetup.t.sol:58-80asserts that a recap after a wipeout "should fully clear projected senior impairment". However, neitherACCOUNTING_SPEC.mdnorSECURITY.mdsays that a recapitalization writes down the Senior entitlement. The spec says losses do not reduce the mark (:337), and it describes the recap as going "to senior restoration or unassigned assets" (:642). On the documented runbook path (test C), the overwrite also fails to clear impairment, because the deficit paid to traders is counted in the new mark. - Related audit item. Cecuro MED-12 (fixed) looked at the same post-wipe recap state. Its subject was revenue continuation being sent to
unassignedAssets. It did not address the overwrite of the pre-wipe mark. - Junior realisation. In the PoC the Junior LP's redemption does not settle within the four epochs run, so ATT receives 0 USDG in both arms. The 2.14 USDG difference stays in the pool attributed to Junior principal (pool raw 251.077011 vs 248.938142).
PoC run command and output
The PoC source (test file plus the handler it imports) is in the Proof of Concept field.
Run
cd packages/perps
forge test --root . --match-path 'test/perps/h27/T6_HwmRecapReset.t.sol' -vv
Expected output (final run, 2026-11-14)
Ran 4 tests for test/perps/h27/T6_HwmRecapReset.t.sol:T6_HwmRecapResetTest
[PASS] test_AB_compare() (gas: 98343682)
Logs:
== A (principals exactly 0)
pre-wipe stored Senior HWM 21000018264
projected S / J before partial recap 0 0
settle right after recap ok (0/1) 0
projected S after recap / impaired 5000000000 0
partial-exit epoch settled (0/1) 1
stored S / HWM after partial exit 4523809938 4523809938
owner USDG spent 8609469576
S / J / HWM after revenue (proj S,J) 4523809938 2263355 4523809938
SLP (Senior LP) total USDG out 4751186344
ATT (Junior LP) total USDG out 0
pool raw USDG after 251077011
== B control (Senior keeps 1 atom)
pre-wipe stored Senior HWM 21000018264
projected S / J before partial recap 1 0
settle right after recap ok (0/1) 0
projected S after recap / impaired 5000000001 1
partial-exit epoch settled (0/1) 1
stored S / HWM after partial exit 4523809939 19038191914
owner USDG spent 8609469577
S / J / HWM after revenue (proj S,J) 4526073294 0 19038191914
SLP (Senior LP) total USDG out 4753325214
ATT (Junior LP) total USDG out 0
pool raw USDG after 248938142
== A/B delta (lever = 1 atom of owner cash)
owner spent A / B 8609469576 8609469577
stored HWM after exit A / B 4523809938 19038191914
Senior HWM erased (B - A) 14514381976
SLP USDG A / B 4751186344 4753325214
ATT USDG A / B 0 0
Senior LP USDG shortfall A vs B 2138870
Junior principal gain A vs B 2263355
[PASS] test_A_exactZero_hwmReset() (gas: 49141463)
Logs:
== A (principals exactly 0)
pre-wipe stored Senior HWM 21000018264
projected S / J before partial recap 0 0
settle right after recap ok (0/1) 0
projected S after recap / impaired 5000000000 0
partial-exit epoch settled (0/1) 1
stored S / HWM after partial exit 4523809938 4523809938
owner USDG spent 8609469576
S / J / HWM after revenue (proj S,J) 4523809938 2263355 4523809938
SLP (Senior LP) total USDG out 4751186344
ATT (Junior LP) total USDG out 0
pool raw USDG after 251077011
[PASS] test_B_control_oneAtom_hwmKept() (gas: 49194505)
Logs:
== B control (Senior keeps 1 atom)
pre-wipe stored Senior HWM 21000018264
projected S / J before partial recap 1 0
settle right after recap ok (0/1) 0
projected S after recap / impaired 5000000001 1
partial-exit epoch settled (0/1) 1
stored S / HWM after partial exit 4523809939 19038191914
owner USDG spent 8609469577
S / J / HWM after revenue (proj S,J) 4526073294 0 19038191914
SLP (Senior LP) total USDG out 4753325214
ATT (Junior LP) total USDG out 0
pool raw USDG after 248938142
[PASS] test_C_documentedPathOnly_hwmDiscarded() (gas: 32554780)
Logs:
== C documented path (recapitalizePool for deficit+1, then 5,000)
pre-wipe stored Senior HWM 21000018264
deficit funded 3609469577
after deficit recap: proj S / J 1 0
after partial recap: proj S / impaired 5000000001 1
partial-exit epoch settled (0/1) 1
stored S / HWM after partial exit 4523809939 7789520807
Suite result: ok. 4 passed; 0 failed; 0 skipped; finished in 140.75ms (311.73ms CPU time)
Ran 1 test suite in 141.89ms (140.75ms CPU time): 4 tests passed, 0 failed, 0 skipped (4 total tests)
Key lines:
- A:
stored S / HWM after partial exit 4523809938 4523809938 - B:
stored S / HWM after partial exit 4523809939 19038191914 - C:
stored S / HWM after partial exit 4523809939 7789520807(pre-wipe21000018264) Senior HWM erased (B - A) 14514381976Senior LP USDG shortfall A vs B 2138870Junior principal gain A vs B 2263355
Recommendation
Do not let a recapitalization overwrite the Senior entitlement. In the bootstrap branch, keep the larger of the existing mark and the newly assigned principal. Do not substitute the recapitalization intent, because that intent also includes cash that was used to pay trader claims:
// HousePoolPendingPreviewLib.applyClaimantRecapitalizationIntent, bootstrap branch
state.waterfall.seniorPrincipal += remaining;
if (state.waterfall.seniorHighWaterMark < state.waterfall.seniorPrincipal) {
state.waterfall.seniorHighWaterMark = state.waterfall.seniorPrincipal;
}
remaining = 0;
If the protocol has to reopen deposits after a partial restart while Senior is still below its pre-wipe mark, make the write-down an explicit governance action instead of a side effect of the recap amount. For example, add an owner-only writeDownSeniorHighWaterMark(newMark) that emits an event, or track the pre-wipe shortfall as a separate Senior recovery claim that revenue repays before Junior but that does not gate deposits. Document whichever choice is made in ACCOUNTING_SPEC.md (waterfall section) and in the terminal-deficit runbook in SECURITY.md.
Proof of Concept
Proof of Concept
Two files under packages/perps/test/perps/:
h27/T6_HwmRecapReset.t.sol: the PoC (below).Hunt_R11b.t.sol: the handler (HuntR11bHandler) that drives traders, keepers and prices against the realBasePerpTeststack (Appendix A). It uses only the repo's ownBasePerpTest,LegacyOrderRouterHarness,MockSettlementToken(USDG) andMockPyth(Pyth). Every protocol contract is the real in-scope code.
Every arm asserts on real USDG balances (settlementToken.balanceOf(SLP)), not only on views. A/B control: the only difference between arms A and B is 1 atom of owner cash, which decides which branch of applyClaimantRecapitalizationIntent runs.
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.35;
// HWM-RECAP-OVERWRITE on the real stack (pin a82d4fef). No USDG is burned out of the pool to fake losses: a real
// deep-insolvency trading sequence wipes both tranches. The owner then funds the trader-claim deficit and makes a
// PARTIAL recapitalization through the documented recovery action CfdEngine.recapitalizePool.
//
// When both waterfall principals are exactly 0, HousePoolPendingPreviewLib.applyClaimantRecapitalizationIntent
// (src/libraries/HousePoolPendingPreviewLib.sol:118-121) ASSIGNS seniorHighWaterMark = max(intent, amount) and
// discards Senior's pre-wipe high-water mark, which absorbLoss (HousePoolWaterfallAccountingLib.sol:161-184)
// deliberately kept so that future revenue restores Senior. With any nonzero principal the gap path (:123-131) keeps it.
//
// test_A / test_B / test_AB_compare: A/B on the branch. Lever = 1 atom of owner cash admitted before the partial recap.
// A (lever) deficit admitted exactly -> principals 0 -> bootstrap branch -> HWM := recap
// B (control) deficit admitted exactly + 1 atom -> Senior 1 atom -> gap branch -> HWM preserved
// The same real trading revenue is then generated in both arms and both pre-wipe LPs redeem via the real vaults.
// test_C: documented path only (recapitalizePool for the deficit, then recapitalizePool for the partial recap).
import {BasePerpTest} from "../BasePerpTest.sol";
import {HuntR11bHandler} from "../Hunt_R11b.t.sol";
import {CfdTypes} from "@plether/perps/CfdTypes.sol";
import {TrancheVault} from "@plether/perps/TrancheVault.sol";
import {IOrderRouterAdminHost} from "@plether/perps/interfaces/IOrderRouterAdminHost.sol";
import {console2} from "forge-std/console2.sol";
contract T6_HwmRecapResetTest is BasePerpTest {
HuntR11bHandler internal handler;
address internal constant SLP = address(0x5E1); // pre-wipe Senior LP
address internal constant ATT = address(0xA77); // pre-wipe Junior LP
uint256 internal constant PARTIAL_RECAP = 5000e6;
struct Out {
uint256 ownerSpent;
uint256 hwmBefore;
uint256 impairedAfterRecap; // 1 = projected Senior still below its HWM after the partial recap
uint256 sAfterRecap;
uint256 storedHwmAfterExit;
uint256 sAfterRevenue;
uint256 jAfterRevenue;
uint256 hwmAfterRevenue;
uint256 slpUsdg;
uint256 attUsdg;
}
function _riskParams() internal pure override returns (CfdTypes.RiskParams memory params) {
params = CfdTypes.RiskParams({
vpiFactor: 0.01e18,
maxSkewRatio: 0.4e18,
maintMarginBps: 10,
initMarginBps: 20,
fadMarginBps: 300,
baseCarryBps: 500,
minBountyAssets: 1e6,
bountyBps: 10,
keeperShareBps: 5000,
protocolShareBps: 0
});
}
function _initialJuniorDeposit() internal pure override returns (uint256) {
return 20_000e6;
}
function _initialSeniorDeposit() internal pure override returns (uint256) {
return 20_000e6;
}
function setUp() public override {
super.setUp();
_setSeniorCapacity(40_000_000e6, 8000);
IOrderRouterAdminHost.RouterConfig memory rc = _routerConfig();
rc.minOpenNotionalAssets = 1000e6;
_setRouterConfig(rc);
uint256 day = block.timestamp / 86_400;
uint256 weekday = (day + 4) % 7;
uint256 add = (8 - weekday) % 7;
if (add == 0) add = 7;
vm.warp((day + add) * 86_400 + 10 hours);
handler = new HuntR11bHandler(
settlementToken, baseMockPyth, engine, clearinghouse, pool, seniorVault, juniorVault, router, routerAdmin, address(this)
);
seniorVault.transfer(SLP, seniorVault.balanceOf(address(this)) - seniorVault.seedShareFloor());
juniorVault.transfer(ATT, juniorVault.balanceOf(address(this)) - juniorVault.seedShareFloor());
}
// Real trading sequence (opens, price stress, liquidations) that leaves both tranches wiped and claims > cash.
function _deepInsolvency() internal {
handler.open(2, true, type(uint256).max - 3, 3_327_982_076_634_955_910, true);
handler.stressCycle(22_836, 40_000_000);
handler.liquidateBatch(5_424_890_403_252_000_409_297_375_161_974_545_563_753_822_129);
handler.stressCycle(
14_138_237_522_377_924_477_279_689_992_028_040_916_067_178_878_552_169_616_822_899_931_020_007_680_005, 1
);
handler.stressCycle(6, 3_784_078_843_179_230_671_230_523_752_236_531_949_277_212_284_759);
}
function _recap(uint256 amt) internal {
settlementToken.mint(address(this), amt);
settlementToken.approve(address(engine), amt);
engine.recapitalizePool(amt);
}
function _settleClaims() internal {
for (uint256 i; i < 5; ++i) {
address a = address(uint160(0xA11 + i));
if (engine.traderClaimBalanceAssets(a) == 0) continue;
vm.prank(a);
engine.settleTraderClaim(a);
}
}
// keeper settleLpEpoch through the router; returns whether THIS call succeeded
function _settleLpOk() internal returns (bool) {
uint256 okBefore = handler.ok("settleLp");
handler.settleLp(150);
return handler.ok("settleLp") > okBefore;
}
function _tradeForRevenue() internal {
for (uint256 r; r < 3; ++r) {
handler.openPair(0, 60, 200);
handler.openPair(2, 60, 200);
handler.warp(8 hours);
for (uint256 i; i < 5; ++i) {
handler.close(i, 4, true);
}
}
}
function _redeemAll(TrancheVault v, address who) internal returns (uint256 rid) {
uint256 sh = v.maxRequestRedeem(who);
if (sh == 0) return 0;
vm.prank(who);
rid = v.requestRedeem(sh, who, who);
}
function _claim(TrancheVault v, uint256 rid, address who) internal {
if (rid == 0) return;
uint256 cl = v.claimableRedeemRequest(rid, who);
if (cl > 0) {
vm.prank(who);
v.claimRedeem(rid, cl, who, who);
}
}
// ordinary 10% Senior exit; its epoch settlement performs the STORED reconcile of the pending recap
function _partialSeniorExit() internal returns (uint256 usdgOut, bool settled) {
vm.warp(block.timestamp + 2 days);
uint256 part = seniorVault.maxRequestRedeem(SLP) / 10;
vm.prank(SLP);
uint256 rid = seniorVault.requestRedeem(part, SLP, SLP);
uint256 b0 = settlementToken.balanceOf(SLP);
settled = _settleLpOk();
_claim(seniorVault, rid, SLP);
usdgOut = settlementToken.balanceOf(SLP) - b0;
}
function _run(bool lever) internal returns (Out memory o) {
_deepInsolvency();
assertTrue(engine.degradedMode(), "precondition: degraded");
assertGt(engine.totalTraderClaimBalanceAssets(), pool.totalAssets(), "precondition: claims > cash");
(uint256 wS, uint256 wJ) = pool.getPendingDepositTrancheState();
assertEq(wS + wJ, 0, "precondition: both tranches wiped (projected)");
o.hwmBefore = pool.seniorHighWaterMark();
// fund the trader-claim deficit so that E == L exactly (A) or E == L + 1 atom (B)
if (routerAdmin.paused()) routerAdmin.unpause();
uint256 fund = engine.totalTraderClaimBalanceAssets() + _maxLiability() - pool.totalAssets() + (lever ? 0 : 1);
settlementToken.mint(address(pool), fund);
pool.accountExcess();
o.ownerSpent = fund;
engine.clearDegradedMode();
_settleClaims();
assertEq(engine.totalTraderClaimBalanceAssets(), 0, "claims paid");
(uint256 ps0, uint256 pj0) = pool.getPendingDepositTrancheState();
console2.log(lever ? "== A (principals exactly 0)" : "== B control (Senior keeps 1 atom)");
console2.log(" pre-wipe stored Senior HWM ", o.hwmBefore);
console2.log(" projected S / J before partial recap", ps0, pj0);
// identical documented partial recapitalization
_recap(PARTIAL_RECAP);
o.ownerSpent += PARTIAL_RECAP;
bool sok = _settleLpOk(); // no LP request queued yet -> NoLpEpochProgress expected
(o.sAfterRecap,) = pool.getPendingDepositTrancheState();
o.impairedAfterRecap = pool.isSeniorImpairedAfterPendingDepositReconcile() ? 1 : 0;
console2.log(" settle right after recap ok (0/1) ", sok ? 1 : 0);
console2.log(" projected S after recap / impaired ", o.sAfterRecap, o.impairedAfterRecap);
// ordinary partial Senior exit -> stored reconcile of the recap
(uint256 exitOut, bool pok) = _partialSeniorExit();
o.slpUsdg += exitOut;
o.storedHwmAfterExit = pool.seniorHighWaterMark();
console2.log(" partial-exit epoch settled (0/1) ", pok ? 1 : 0);
console2.log(" stored S / HWM after partial exit ", pool.seniorPrincipal(), o.storedHwmAfterExit);
// identical real trading revenue
_tradeForRevenue();
(o.sAfterRevenue, o.jAfterRevenue) = pool.getPendingDepositTrancheState();
o.hwmAfterRevenue = pool.seniorHighWaterMark();
// both pre-wipe LPs exit through the real async path
uint256 s0 = settlementToken.balanceOf(SLP);
uint256 a0 = settlementToken.balanceOf(ATT);
vm.warp(block.timestamp + 2 days); // clear any cooldown
uint256 ridS = _redeemAll(seniorVault, SLP);
uint256 ridJ = _redeemAll(juniorVault, ATT);
for (uint256 k; k < 4; ++k) {
_settleLpOk();
_claim(seniorVault, ridS, SLP);
_claim(juniorVault, ridJ, ATT);
}
o.slpUsdg += settlementToken.balanceOf(SLP) - s0;
o.attUsdg = settlementToken.balanceOf(ATT) - a0;
console2.log(" owner USDG spent ", o.ownerSpent);
console2.log(" S / J / HWM after revenue (proj S,J)", o.sAfterRevenue, o.jAfterRevenue, o.hwmAfterRevenue);
console2.log(" SLP (Senior LP) total USDG out ", o.slpUsdg);
console2.log(" ATT (Junior LP) total USDG out ", o.attUsdg);
console2.log(" pool raw USDG after ", pool.rawAssets());
}
function test_A_exactZero_hwmReset() public {
Out memory a = _run(true);
assertEq(a.impairedAfterRecap, 0, "A: partial recap clears Senior impairment => pre-wipe HWM discarded");
assertLt(a.storedHwmAfterExit, a.hwmBefore / 2, "A: stored HWM is far below the pre-wipe HWM");
}
function test_B_control_oneAtom_hwmKept() public {
Out memory b = _run(false);
assertEq(b.impairedAfterRecap, 1, "B: Senior still impaired => HWM kept");
assertGt(b.storedHwmAfterExit, b.sAfterRevenue, "B: stored HWM stays above Senior principal");
}
function test_AB_compare() public {
uint256 snap = vm.snapshotState();
Out memory a = _run(true);
vm.revertToState(snap);
Out memory b = _run(false);
console2.log("== A/B delta (lever = 1 atom of owner cash)");
console2.log(" owner spent A / B ", a.ownerSpent, b.ownerSpent);
console2.log(" stored HWM after exit A / B ", a.storedHwmAfterExit, b.storedHwmAfterExit);
console2.log(" Senior HWM erased (B - A) ", b.storedHwmAfterExit - a.storedHwmAfterExit);
console2.log(" SLP USDG A / B ", a.slpUsdg, b.slpUsdg);
console2.log(" ATT USDG A / B ", a.attUsdg, b.attUsdg);
assertEq(b.ownerSpent, a.ownerSpent + 1, "lever is one atom");
assertEq(a.impairedAfterRecap, 0, "A: Senior not impaired after a partial recap => pre-wipe
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 bootstrap branch of the recapitalization logic assigns the Senior high-water mark from the recapitalization target whenever both principals are zero, discarding the pre-wipe mark that the loss path deliberately preserved.
Impact
Value does not leave the protocol but shifts between tranches: the Senior LP received 2.14 USDG less in the PoC, and up to roughly 14,514 USDG of future revenue exposure is redirected to Junior principal, realised only in proportion to revenue earned after the restart.
What the attacker needed
Owner performs recapitalizePool; full wipe of both LP tranches; trader claims exceed pool cash; partial recap below pre-wipe mark
The fix
The bootstrap branch should keep the larger of the existing high-water mark and the newly assigned principal rather than substituting the recapitalization intent, and any write-down should be an explicit governance action.
How it was found
- Senior and Junior LPs deposit into the pool.
- Trading losses drive the pool into terminal deficit, wiping both tranches to zero while the Senior high-water mark stays at its pre-wipe value.
- The owner funds the trader-claim deficit and makes a partial recapitalization through the documented recovery action.
- The next reconcile that applies the recap stores the Senior high-water mark as the recap amount rather than the pre-wipe value.
- New trading revenue arrives and is credited to Junior principal instead of restoring Senior.
- The Senior LP redeems and receives less than it would have if the mark had been preserved.
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 has two groups of lenders, Senior and Junior. When the pool loses money, the protocol keeps a record of how much the Senior lenders are still owed so that future profits pay them back first. This report shows that when the owner adds fresh cash to restart the pool after a total loss, that record is replaced by the amount of cash added, so the old debt is forgotten and future profits go to the wrong group.
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.