Residual recapitalization erases Senior recovery priority and diverts revenue to Junior
A residual slice of a partially applied owner recapitalization is treated as a brand-new recapitalization, so the scaled Senior high-water mark is overwritten with a smaller value. Later trading revenue that should restore Senior first is instead allocated to Junior and paid out to a Junior LP's redemption.
- Disclosed after under an hour
#99371 [SC-High] Residual recapitalization erases Senior recovery priority and diverts revenue to Junior
Submitted on Nov 13th 2026 at 12:01:46 UTC by @viraz for Audit Competition | Plether
- Report ID: #99371
- Report Type: Smart Contract
- Report severity: High
- Target: https://github.com/immunefi-team/audit-comp-plether/tree/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src
- Impacts:
- Theft of unclaimed yield
Description
Description
Plether's Senior high-water mark records the amount that future pool revenue must restore to Senior before any remainder accrues to Junior. The security specification states that Senior impairment must be restored before Junior extracts surplus (packages/perps/SECURITY.md:386-395). HousePoolWaterfallAccountingLib.distributeRevenue implements that priority by filling seniorHighWaterMark - seniorPrincipal before crediting Junior (libraries/HousePoolWaterfallAccountingLib.sol:133-155).
A single owner-funded recapitalization is stored as one pendingRecapitalizationAssets intent (CfdEngine.sol:632-652; HousePool.sol:624-650). During reconciliation, however, HousePool._settleablePendingClaimantBuckets caps that intent to the cash that is currently distributable (HousePool.sol:1555-1599, 1829-1834). HousePoolPendingPreviewLib.capClaimantBuckets permits the recapitalization bucket to be applied in arbitrary slices (libraries/HousePoolPendingPreviewLib.sol:68-82).
The first slice can correctly establish and then scale a Senior recovery entitlement. If both tranche principals subsequently return to zero while a residual slice remains pending, the next reconciliation treats the residual slice as a new bootstrap:
if (state.waterfall.seniorPrincipal == 0 && state.waterfall.juniorPrincipal == 0) {
state.waterfall.seniorPrincipal += remaining;
state.waterfall.seniorHighWaterMark =
recapitalizationTargetAssets > remaining ? recapitalizationTargetAssets : remaining;
remaining = 0;
}
The recapitalizationTargetAssets argument is the currently outstanding bucket, not the original cohort target (libraries/HousePoolPendingPreviewLib.sol:40-49, 111-122). After the first slice has been removed from storage, the residual is therefore interpreted as a fresh target. Assignment replaces the existing scaled high-water mark instead of preserving it.
The replacement is not always adverse. Let R be the original recapitalization, F the first applied slice, Q = R - F the residual, D the Senior redemption funded after that slice, and P = F - D the remaining Senior principal. The next reconciliation uses the ordinary gap branch while P > Q. It reaches the zero-principal bootstrap branch only when P <= Q, equivalently D >= F - Q, and then replaces the scaled high-water mark with Q. That replacement harms Senior only while the correctly scaled mark remains above Q; if the scaled mark is below Q, the replacement instead benefits Senior.
In the demonstrated production path, the shortfall is S, the owner recapitalizes R = 3S, the claims-limited first slice is F = 2S, and the residual is Q = S. The redemption phase derives its budget from free assets after reserving trader claims and pending claimant assets (HousePool.sol:842-855, 1727-1735; libraries/HousePoolAccountingLib.sol:46-55). This leaves a maximum Senior redemption budget of exactly S = F - Q. The adverse bootstrap is therefore reached when the matured Senior redemption consumes the complete available budget. It is a structural full-budget boundary, not a range of below-residual principal states.
Once the adverse overwrite occurs, it permanently removes part of the surviving Senior holders' recovery priority. A later Senior deposit only increments the already-lowered mark (HousePool.sol:1081-1091). Subsequent organic trading revenue sees no Senior gap and can fund Junior redemptions even though the correctly preserved mark would require all of that revenue to restore Senior first.
Production-path sequence
The PoC uses the production OrderRouter, production sidecars, real tranche request/settlement functions, and real trade closes:
- Existing Senior and Junior LPs deposit
100,000 USDGeach. - Production Router trades create
633,563.616365 USDGof trader-claim shortfall and wipe both stored tranche principals while shares survive. - The owner calls the documented
recapitalizePoolrecovery action with3 * shortfall. - Outstanding trader claims reduce currently distributable cash and cap the first application of that recapitalization intent at
2 * shortfall. The redemption does not cause this cap; it runs afterward. - The first slice establishes Senior principal. The matured Senior redemption then consumes the complete
shortfall-sized withdrawal budget and invokesscaleSeniorOnWithdraw. The resulting950,345.424548 USDGhigh-water mark is correct and remains above the surviving633,563.616365 USDGSenior principal. - Trader claimants settle, consuming cash while
633,563.616365 USDGof the original recapitalization remains pending. - At the start of the next LP settlement, reconciliation writes both tranche principals down to zero. This write-down reflects that the remaining cash backs the reserved recapitalization bucket as well as the stored Senior principal; it is an accounting transition, not a second trading loss. The pending-bucket phase then applies the residual against that zero-principal state, so the fresh-bootstrap branch replaces the prior scaled mark with the residual amount.
- A queued
10,000 USDGSenior deposit raises both principal and the overwritten mark to only643,563.616365 USDG. Preserving the scaled entitlement and adding the same deposit would instead produce a960,345.424548 USDGmark. - A later production trade generates
1,040.400040 USDGof organic revenue. This is far below the erased Senior recovery gap, so none of it could reach Junior if the scaled mark had survived. - The protocol nevertheless funds
86.627875 USDGto an ordinary Junior LP's redemption. The Junior LP claims the exact amount into its wallet, while Senior principal receives none of the restoration revenue.
The measured states are:
| State | Amount |
|---|---|
| Organic trader-claim shortfall | 633,563.616365 USDG |
| Correctly scaled Senior high-water mark after the first slice and redemption | 950,345.424548 USDG |
| Expected high-water mark after preserving that entitlement and adding the Senior deposit | 960,345.424548 USDG |
| High-water mark after the residual slice and queued Senior deposit | 643,563.616365 USDG |
| Senior recovery priority erased, compared like for like after the deposit | 316,781.808183 USDG |
| Later organic trading revenue | 1,040.400040 USDG |
| Junior redemption funded and claimed | 86.627875 USDG |
The table reports the exact observed values. It does not claim that the full erased high-water-mark amount is immediately withdrawable or has already been transferred. Before later revenue arrives, the erased amount is an accounting entitlement rather than cash available to Senior. The PoC proves the economic consequence when real revenue does arrive: 86.627875 USDG is allocated and transferred to Junior while the preserved target would allocate the complete revenue amount to Senior.
Causal and reachability controls
The no-Senior-redemption control uses the same claim shortfall, one recapitalization intent applied in two reconciliations, and the same later production trade. Because no Senior redemption lowers principal to the bootstrap boundary, the residual follows the ordinary gap branch. The original 1,900,690.849095 USDG target survives, all 1,039.459356 USDG of measured later revenue restores Senior, and Junior receives zero.
The oversized-redemption control keeps recapitalization fixed at 3 * shortfall and requests 683,563.616365 USDG, which is 50,000 USDG above the available first-pass budget. The production settlement logic funds exactly 633,563.616365 USDG, leaves the remaining redemption shares queued, and therefore lands on the same structural bootstrap boundary without requiring the LP to calculate an exact share request. In the next pass it funds the remaining 50,000 USDG and accepts the queued 10,000 USDG deposit. Preserving the original cohort would leave an 885,345.424548 USDG high-water mark; the actual mark is 593,563.616365 USDG.
That control also rules out the proposed unmatched-residual state for this sequence. The withdrawal budget prevents the first pass from funding more than F - Q, so post-redemption principal cannot fall below the residual. The next reconciliation applies the complete residual, and pendingRecapitalizationAssets ends at zero. The PoC does not claim that this path leaves an underfunded residual or independently freezes deposits.
Why a residual is not a new recapitalization
The protocol intentionally permits one recapitalization intent to settle in slices. test_PendingRecapitalization_CapsAgainstTraderClaimLiabilitiesAndCarriesResidual asserts that the first slice preserves the full target and that the residual settles later. test_PartialMixedInflowsPreserveFullIntentAndSettleResidualLater exercises the same intended split lifecycle. The library NatSpec calls recapitalizationTargetAssets the full recapitalization intent (libraries/HousePoolPendingPreviewLib.sol:103-110).
The protocol also intentionally permits a genuinely new recapitalization after a completed wipeout to establish a fresh target. test_PostWipeoutRequiresExplicitRecapForHwmReset and test_SeniorRequiresExplicitRecapAfterFullWipeout cover that behavior.
These cases are compatible. A new owner inflow after a wipeout is a new recapitalization cohort and may establish a new target. A residual from an already-started cohort is not a new inflow and must preserve that cohort's full target. ACCOUNTING_SPEC.md:331-340 reinforces the distinction: the high-water mark is the Senior entitlement restored by future revenue, ACCOUNTING_SPEC.md:337 expressly says losses do not reduce it, and pending buckets retain their explicit ownership intent.
Why the owner precondition is in scope
CfdEngine.recapitalizePool is the documented immediate recovery action. SECURITY.md:155-163 states that the owner transfers USDG into the HousePool and the pool queues that value for normal claimant reconciliation. The terminal-deficit runbook expressly tells governance to recapitalize or clear positions (SECURITY.md:1499-1511).
The owner is not compromised and does not call an unauthorized path. It supplies recovery capital through the intended API after a real trader-claim shortfall. The competition scope states that a legitimate documented action by a trusted role that triggers a logic bug harming users remains in scope. The Junior holder performs only an ordinary redemption after the accounting priority has been corrupted.
Relationship to MED-11
Cecuro MED-11 reported that Senior withdrawal math itself could understate the remaining high-water mark. Its remediation changed scaleSeniorOnWithdraw so the mark is reduced by the same economic fraction as funded principal.
The PoC proves that withdrawal scaling works: after the first recapitalization slice and Senior redemption, the high-water mark is correctly scaled to 950,345.424548 USDG. The loss occurs later, when a residual recapitalization slice re-enters applyClaimantRecapitalizationIntent and, in the demonstrated adverse state, replaces that correct value with a smaller fresh-bootstrap target.
This is a different root cause from MED-11. MED-11 was an arithmetic error inside withdrawal scaling. This finding begins with the correct scaled result and then loses it through cross-reconciliation recapitalization-cohort state.
Relationship to MED-12
Cecuro MED-12 concerned recapitalization and revenue applied in the same pending-accounting batch. Revenue continuation was computed from the pre-recapitalization principal state, causing already-funded LP revenue to become unassignedAssets. The remediation recomputes continuation after recapitalization and states that partial-settlement residuals remain reserved.
This finding does not send same-batch revenue to unassignedAssets. It uses one recapitalization intent applied in two reconciliations, an intervening redemption and trader-claim payout, and later organic revenue. The residual remains reserved, but it loses the identity of the original recapitalization cohort and is reinterpreted as a new bootstrap target. The later revenue is routed to Junior, not quarantined as ownerless.
This is a different root cause from MED-12. MED-12 was a same-batch continuation flag computed from the wrong pre-recapitalization state. This finding is cross-reconciliation replacement of the full target for a partially settled cohort. It occurs without same-batch revenue and without routing value to unassignedAssets.
Impact
Theft of unclaimed yield through cross-tranche yield misallocation.
The high-water mark is the surviving Senior LPs' on-chain entitlement to priority over future trading revenue. Once the residual slice replaces it, revenue that should increase Senior value is instead allocated pro rata to Junior holders and becomes fundable to Junior redemption claims. The PoC generates revenue through real production-Router trades, funds 86.627875 USDG to a Junior LP, and then transfers that exact amount into the LP's wallet. Under the correctly scaled mark, the entire 1,040.400040 USDG revenue amount is below the remaining Senior recovery gap, so Junior should receive zero from it.
The impact can scale with the portion of the scaled Senior high-water mark that is erased and the later trading revenue generated before Senior principal independently grows back to the corrupted mark. It does not require modifying a price oracle, changing protocol parameters, or calling an inactive feature.
High severity matches the competition impact Theft of unclaimed yield because the value transferred is realized pool revenue that the documented waterfall assigns to Senior recovery before Junior. The report does not claim immediate theft of Senior's deposited principal or that the overwritten target was fully cash-backed before this revenue arrived.
There is a classification risk if the program treats the erased high-water mark only as a promise of future returns rather than an existing yield entitlement. The PoC addresses that distinction by generating the revenue after the overwrite and proving an actual USDG transfer to Junior while the preserved Senior gap would still exceed the complete revenue amount. If the program nevertheless requires yield to have accrued before the corrupting transaction, it may classify the behavior as Low “contract fails to deliver promised returns.”
The in-scope contracts are publicly designated for deployment but are not yet deployed. Under the competition's undeployed-code rule, the impact remains real, while scaling elements such as the 316,781.808183 USDG corrupted target are evaluated at the minimum. The High classification rests on the impact category and the demonstrated misallocation, not on using that large test amount to scale the reward.
Recommendation
Preserve recapitalization cohort identity across partial applications. A residual slice of an already-started cohort must not enter the fresh-bootstrap branch and replace an existing scaled Senior high-water mark.
The robust fix is to store enough cohort state to distinguish:
- the original recapitalization target;
- the amount still pending;
- whether that cohort has already bootstrapped Senior; and
- the high-water-mark entitlement that survived any intervening Senior redemption.
When a residual slice is applied after both principals return to zero, it should restore principal without lowering that surviving cohort entitlement. A truly new recapitalization after a genuine full wipeout can still establish a new target.
Partial settlement must remain supported. It is pinned by test_PendingRecapitalization_CapsAgainstTraderClaimLiabilitiesAndCarriesResidual (test/perps/accounting/waterfall/HousePoolWaterfall.t.sol:177) and test_PartialMixedInflowsPreserveFullIntentAndSettleResidualLater (test/perps/differential/HousePoolSnapshotParity.t.sol:155). The fix should therefore preserve the identity and full target of the original cohort while its residual is carried across reconciliations, not require the complete intent to settle atomically.
The following illustrative patch records whether the current pending recapitalization cohort has already been partially applied. A later residual may then preserve the live high-water mark, while the first slice of a genuinely new cohort retains the existing fresh-bootstrap behavior:
diff --git a/packages/perps/src/HousePool.sol b/packages/perps/src/HousePool.sol
@@
uint256 public pendingRecapitalizationAssets;
+/// @dev True after at least one slice of the current recapitalization cohort
+/// has been applied while a residual remains pending.
+bool private pendingRecapitalizationCohortStarted;
@@
HousePoolPendingPreviewLib.applyPendingClaimantBucketsPreview(
- pendingState, settleableClaimantBuckets, claimantBuckets, allowRevenueContinuation
+ pendingState,
+ settleableClaimantBuckets,
+ claimantBuckets,
+ allowRevenueContinuation,
+ pendingRecapitalizationCohortStarted
);
@@
HousePoolPendingPreviewLib.applyPendingClaimantBucketsPreview(
- state, settleableClaimantBuckets, claimantBuckets, allowRevenueContinuation
+ state,
+ settleableClaimantBuckets,
+ claimantBuckets,
+ allowRevenueContinuation,
+ pendingRecapitalizationCohortStarted
);
_decreasePendingClaimantBuckets(settleableClaimantBuckets);
+
+if (settleableClaimantBuckets.recapitalizationAssets != 0) {
+ // A nonzero remainder belongs to the cohort that was just partially
+ // applied. Clearing the bucket ends that cohort.
+ pendingRecapitalizationCohortStarted = pendingRecapitalizationAssets != 0;
+}
@@
if (kind == IHousePool.ClaimantInflowKind.Recapitalization) {
+ if (pendingRecapitalizationAssets == 0) {
+ pendingRecapitalizationCohortStarted = false;
+ }
pendingRecapitalizationAssets += amount;
}
diff --git a/packages/perps/src/libraries/HousePoolPendingPreviewLib.sol b/packages/perps/src/libraries/HousePoolPendingPreviewLib.sol
@@
function applyPendingClaimantBucketsPreview(
PendingAccountingState memory state,
ClaimantPendingBuckets memory claimantBuckets,
ClaimantPendingBuckets memory claimantIntentBuckets,
- bool allowRevenueContinuation
+ bool allowRevenueContinuation,
+ bool preserveRecapitalizationHwm
) internal pure {
if (claimantBuckets.recapitalizationAssets > 0) {
applyClaimantRecapitalizationIntent(
- state, claimantBuckets.recapitalizationAssets, claimantIntentBuckets.recapitalizationAssets
+ state,
+ claimantBuckets.recapitalizationAssets,
+ claimantIntentBuckets.recapitalizationAssets,
+ preserveRecapitalizationHwm
);
}
@@
function applyClaimantRecapitalizationIntent(
PendingAccountingState memory state,
uint256 amount,
- uint256 recapitalizationTargetAssets
+ uint256 recapitalizationTargetAssets,
+ bool preserveExistingHwm
) internal pure {
uint256 remaining = amount;
if (state.seniorSupply > 0) {
if (state.waterfall.seniorPrincipal == 0 && state.waterfall.juniorPrincipal == 0) {
state.waterfall.seniorPrincipal += remaining;
- state.waterfall.seniorHighWaterMark =
- recapitalizationTargetAssets > remaining ? recapitalizationTargetAssets : remaining;
+ uint256 target =
+ recapitalizationTargetAssets > remaining ? recapitalizationTargetAssets : remaining;
+
+ // Preserve the entitlement that survived any intervening Senior
+ // withdrawal only for a residual from an already-started cohort.
+ if (preserveExistingHwm && state.waterfall.seniorHighWaterMark > target) {
+ target = state.waterfall.seniorHighWaterMark;
+ }
+
+ state.waterfall.seniorHighWaterMark = target;
remaining = 0;
}
This patch is illustrative rather than a drop-in compiled change. Every direct caller of applyPendingClaimantBucketsPreview, including the snapshot-parity test, must receive the new cohort-state argument. The implementation must also preserve preview/live parity and account for storage-layout requirements of the deployed architecture.
The fresh-bootstrap behavior should remain available only for a genuinely new owner inflow after a completed wipeout, as exercised by test_PostWipeoutRequiresExplicitRecapForHwmReset (test/perps/accounting/waterfall/TrancheRecoveryBehavior.t.sol:24) and test_SeniorRequiresExplicitRecapAfterFullWipeout (test/perps/accounting/waterfall/TrancheRecoveryBehavior.t.sol:577). This preserves both intended behaviors: sliced settlement of one cohort retains its full target, while a later independent recapitalization may establish a new target.
Do not globally replace the assignment with max(existingHighWaterMark, target, amount) without a cohort distinction. The test suite contains genuine post-wipeout bootstrap scenarios where stale entitlement is intentionally reset, so an unconditional maximum can preserve protection that no longer has a claimant basis.
Add regression tests for:
- partial application of one recapitalization cohort;
- a correctly scaled Senior redemption after the first slice;
- trader-claim settlement followed by reconciliation that returns both principals to zero;
- application of the residual slice without lowering the surviving high-water mark;
- an oversized Senior redemption being capped without losing the original cohort target or leaving an unmatched residual;
- a later genuinely new recapitalization after a full wipeout;
- future revenue restoring Senior before Junior;
- preview/live parity for the same multi-epoch sequence; and
- deposit and redemption settlement liveness under the chosen fix.
Proof of Concept
Proof of Concept
The dedicated PoC has three production-path tests. Together, they prove the vulnerable sequence, its causal control, and the production withdrawal-budget boundary that makes the sequence reachable without exact request sizing.
test_ResidualRecapitalizationErasesSeniorPriority
- real trades create the deterministic trader-claim shortfall;
- one recapitalization is only partially applied;
- the first Senior withdrawal produces the correct scaled high-water mark;
- claim settlement and the residual slice cause the later overwrite;
- organic trading revenue is smaller than the erased Senior gap;
- Junior receives a funded redemption while Senior receives none of that revenue; and
- the Junior account claims the funded USDG into its wallet.
test_Control_NoSeniorRedemptionPreservesTargetAndRoutesRevenueToSenior
- repeats the same shortfall and sliced recapitalization without a Senior redemption;
- proves the original full target survives the residual reconciliation;
- generates later revenue through the same production trade path;
- proves all measured revenue restores Senior; and
- proves Junior receives zero.
test_OversizedRedemptionIsCappedAtBootstrapBoundary
- keeps recapitalization fixed at
3 * shortfalland requests50,000 USDGmore than the first-pass withdrawal budget; - proves the production path caps first-pass funding at exactly
shortfalland leaves a redemption backlog; - proves the next pass applies the complete residual, funds the remaining redemption shares, and accepts the queued deposit;
- compares the preserved
885,345.424548 USDGtarget with the actual593,563.616365 USDGtarget; and - proves no recapitalization residual remains pending after that pass.
Scope compliance
The test runs at the exact in-scope commit a82d4fefb02768e5b3bddcc97dee371eee24fea8 and does not modify any in-scope contract.
BasePerpTest exposes its Router field through the nominal LegacyOrderRouterHarness type. The PoC overrides the deployment hook and constructs new OrderRouter(...) with production sidecars. It casts the address only to satisfy the fixture field type. No LegacyOrderRouterHarness bytecode is deployed or executed.
The only mocks are the repository's USDG and Pyth test dependencies. The shortfall and later revenue are produced through production Router commitments and executions. No vm.store, mocked in-scope call, snapshot/revert sizing search, or direct mutation of protocol storage is used.
PoC test
Add the following complete file at packages/perps/test/audit/ResidualRecapitalizationPriorityPoC.t.sol:
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.35;
import {BasePerpTest} from "../perps/BasePerpTest.sol";
import {LegacyOrderRouterHarness} from "../utils/LegacyOrderRouterHarness.sol";
import {CfdOrderPolicyEvaluator} from "@plether/perps/CfdOrderPolicyEvaluator.sol";
import {CfdTypes} from "@plether/perps/CfdTypes.sol";
import {OrderLifecycleBook} from "@plether/perps/OrderLifecycleBook.sol";
import {OrderRouter} from "@plether/perps/OrderRouter.sol";
import {OrderRouterExecutionSidecar} from "@plether/perps/OrderRouterExecutionSidecar.sol";
import {OrderRouterLiquidationBatchSidecar} from "@plether/perps/OrderRouterLiquidationBatchSidecar.sol";
import {OrderV3Types} from "@plether/perps/OrderV3Types.sol";
import {IHousePool} from "@plether/perps/interfaces/IHousePool.sol";
import {IOrderRouterAccounting} from "@plether/perps/interfaces/IOrderRouterAccounting.sol";
import {MockPyth} from "@plether/test-utils/MockPyth.sol";
import {console2} from "forge-std/console2.sol";
/// @title PoC: a residual recapitalization slice erases Senior recovery priority
/// @dev Production OrderRouter and production sidecars. Only Pyth and USDG are mocked by BasePerpTest.
contract ResidualRecapitalizationPriorityPoCTest is BasePerpTest {
uint256 internal constant ACTORS = 3;
address internal constant KEEPER = address(0xBEEF01);
address internal constant LP = address(0xFA11);
address internal constant SENIOR_VICTIM = address(0x5151);
address internal constant JUNIOR_LP = address(0xA77A);
address internal constant ENTRY_LP = address(0xE117);
uint256 internal constant SHORTFALL = 633_563_616_365;
address[ACTORS] internal actors;
OrderRouter internal productionRouter;
OrderLifecycleBook internal book;
function setUp() public override {
super.setUp();
productionRouter = OrderRouter(payable(address(router)));
book = OrderLifecycleBook(address(productionRouter.lifecycleBook()));
for (uint256 i; i < ACTORS; ++i) {
actors[i] = address(uint160(0xC0000 + i));
_fundTrader(actors[i], 100_000e6);
}
_refreshMark(1e8);
}
function _riskParams() internal pure override returns (CfdTypes.RiskParams memory) {
return CfdTypes.RiskParams({
vpiFactor: 0.01e18,
maxSkewRatio: 0.4e18,
maintMarginBps: 10,
initMarginBps: 20,
fadMarginBps: 300,
baseCarryBps: 500,
minBountyAssets: 1e6,
bountyBps: 10,
keeperShareBps: 5000,
protocolShareBps: 0
});
}
/// @dev BasePerpTest's field is legacy-typed. This deploys production OrderRouter bytecode and sidecars.
function _deployLegacyOrderRouter(
address engine_,
address engineLens_,
address pool_,
address oracle_
) internal override returns (LegacyOrderRouterHarness deployedRouter) {
policyEvaluator = new CfdOrderPolicyEvaluator();
orderExecutionSidecar = new OrderRouterExecutionSidecar();
address predictedRouter = vm.computeCreateAddress(address(this), vm.getNonce(address(this)) + 2);
OrderLifecycleBook lifecycleBook =
new OrderLifecycleBook(predictedRouter, engine_, address(clearinghouse), pool_);
OrderRouterLiquidationBatchSidecar keeperSidecar = new OrderRouterLiquidationBatchSidecar(predictedRouter);
OrderRouter exactProductionRouter = new OrderRouter(
engine_,
engineLens_,
pool_,
oracle_,
address(keeperSidecar),
address(policyEvaluator),
address(orderExecutionSidecar),
address(lifecycleBook)
);
assertEq(address(exactProductionRouter), predictedRouter);
deployedRouter = LegacyOrderRouterHarness(payable(address(exactProductionRouter)));
}
function test_ResidualRecapitalizationErasesSeniorPriority() public {
_fundSenior(SENIOR_VICTIM, 100_000e6);
_fundJunior(JUNIOR_LP, 100_000e6);
_setupPairAtLimit();
// Deterministic claim shortfall produced by the three production-Router closes below.
uint256 shortfall = SHORTFALL;
uint256 recapitalization = 3 * shortfall;
uint256 firstPrincipal = 2 * shortfall;
(uint256 redeemShares, uint256 quotedAssets) = housePoolRedemptionMathSidecar.maxSharesForNetBudget(
shortfall,
seniorVault.balanceOf(SENIOR_VICTIM),
firstPrincipal,
seniorVault.totalSupply(),
1,
1000,
0
);
assertEq(quotedAssets, shortfall);
uint256 redeemEpoch = _requestSeniorRedeem(SENIOR_VICTIM, redeemShares);
uint256 depositEpoch = _requestSeniorDeposit(ENTRY_LP, 10_000
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 residual slice of an already-started recapitalization cohort is passed as the recapitalization target, so the zero-principal bootstrap branch assigns a fresh high-water mark instead of preserving the surviving scaled entitlement.
Impact
Revenue that the waterfall assigns to Senior recovery is instead allocated to Junior and can be funded to Junior redemptions; the report notes the erased amount is an accounting entitlement rather than immediately withdrawable cash, and the contracts are not yet deployed.
What the attacker needed
Owner recapitalizes after a shortfall; trader claims cap the first slice; Senior redemption uses full budget; later organic trading revenue
The fix
The report recommends storing recapitalization cohort state so a residual slice of an already-started cohort restores principal without lowering the surviving high-water mark, while a genuinely new recapitalization after a full wipeout may still set a fresh target.
How it was found
- Existing Senior and Junior LPs deposit equal amounts and production trades create a trader-claim shortfall that wipes both stored tranche principals.
- The owner calls the documented recapitalizePool recovery action with three times the shortfall.
- Outstanding trader claims cap the first application of the recapitalization at two times the shortfall, and the first slice establishes Senior principal.
- A matured Senior redemption consumes the full shortfall-sized budget and correctly scales the high-water mark.
- Trader claimants settle, then the next reconciliation writes both principals to zero and applies the residual slice, overwriting the scaled mark.
- A later production trade generates revenue that is funded to a Junior LP's redemption while Senior receives none.
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 depositors: Senior, who are promised first claim on future earnings to make up past losses, and Junior, who only get leftovers. The protocol tracks how much Senior is still owed with a number called the high-water mark. A bug lets a later part of a recovery payment reset that number to a smaller value, so new earnings go to Junior instead of paying Senior back first.
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.