CfdEngine: a hedged pair's winning close latches degraded mode, and a zero-carry losing leg keeps all LP settlement frozen until the owner pays
A profitable close on the smaller side of a hedged pair can push the pool's effective assets below its maximum liability, latching a degraded mode that blocks all LP settlement, deposits and opens. The attacker then tops up the losing leg's margin so it pays no carry and cannot be liquidated, leaving the pool frozen until the owner donates the shortfall.
- Disclosed after under an hour
#99123 [SC-High] CfdEngine: a hedged pair's winning close latches degraded mode, and a zero-carry losing leg keeps all LP settlement frozen until the owner pays
Submitted on Nov 12th 2026 at 00:30:47 UTC by @vesko210 for Audit Competition | Plether
- Report ID: #99123
- Report Type: Smart Contract
- Report severity: High
- Target: https://github.com/immunefi-team/audit-comp-plether/tree/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src
- Impacts:
- Temporary freezing of funds for at least 24 hours
Description
Brief/Intro
Plether admits a new position only while the pool's effective assets E cover the larger side's maximum profit L plus a 25 bps buffer B. A close has no such limit. A profitable close on the smaller side is paid from pool cash and leaves L unchanged, so it can push E below L. CfdEngine then latches degraded mode. While the latch is set, every LP epoch settlement reverts: no redemption is funded and no deposit activates, in either tranche. Every open is refused, and no trader with an open position can withdraw. Only the owner can clear the latch, and only once E ≥ L again. An attacker with a hedged LONG/SHORT pair that fills the pool to its admission limit can set the latch with one winning close after a basket move of about 0.75%. It then tops up the losing leg to full margin, so that leg pays no carry and cannot be liquidated. From then on nothing in the protocol brings E back up to L. The whole pool stays frozen until the owner donates the gap from its own wallet; the PoC shows it unchanged after 7 days. On a 10,002,000 USDG pool the PoC attack costs 39,321-62,671 USDG, and the pool keeps most of that as VPI and fees.
Vulnerability Details
Opens need headroom B above L. Closes do not.
Every open or increase must leave E ≥ L + B. Here E is pool assets minus trader claims, L = max(longMaxProfit, shortMaxProfit), and B = ceil(L × 25 / 10,000):
// CfdEnginePlanLib.sol, _applyOpenSettlementBufferAfterPlan
satisfied = SolvencyAccountingLib.hasRequiredSettlementBuffer(
result.effectiveAssetsAfterAssets, result.maxLiabilityAfterAssets, snap.settlementBufferBps
);
A close is never rejected for solvency. The NatSpec of planClose says so: "A valid close may project degraded mode; solvency is reported rather than rejected". The close's price gain is paid at once whenever pool cash net of trader claims covers it. L and B play no part in that test:
// CfdEnginePlanLib.sol, _planIsolatedCloseSettlement
uint256 freePoolCashAssets =
CashPriorityLib.reserveFreshPayouts(poolCashAfterCollectionsAssets, claimsAfterPriceNettingAssets)
.freeCashAssets;
if (delta.pricePayoutAssets > 0) {
delta.pricePayoutIsImmediate = freePoolCashAssets >= delta.pricePayoutAssets;
A close lowers only its own side's envelope. When the closing side is not the larger one, L stays the same while E falls by the payout.
One close sets a latch that only the owner can lift.
After every close and liquidation, the engine compares E with L:
// CfdEngine.sol, _enterDegradedModeIfInsolvent
uint256 maxLiabilityAssets = _maxLiability();
if (effectiveAssetsAfter < maxLiabilityAssets) {
degradedMode = true;
emit DegradedModeEntered(effectiveAssetsAfter, maxLiabilityAssets, account);
}
While degradedMode is set:
HousePool._settleLpEpochreverts withHousePool__DegradedModebefore it does anything. No redemption is funded and no deposit activates, in either tranche. A matured Junior deposit cannot be cancelled (DepositEpochAlreadyActive). A Senior deposit is committed when requested and cannot be cancelled either (SeniorDepositCommitted). A matured redemption cannot be cancelled (RedeemCancellationUnavailable). New deposit requests revert (DepositsUnavailable).- Every open fails:
OrderRouter__DegradedModeat commit,DEGRADED_MODEat execution. validateWithdrawreverts withCfdEngine__DegradedModefor every account that holds a position. Such a trader can get its free settlement out only by closing first.
The flag is cleared in exactly one place, the owner-only clearDegradedMode, and only when E ≥ L:
// CfdEngine.sol
function clearDegradedMode() external onlyOwner {
if (!degradedMode) {
revert CfdEngine__NotDegraded();
}
if (_availableCashForFreshPoolPayouts() < _maxLiability()) {
revert CfdEngine__StillInsolvent();
}
degradedMode = false;
emit DegradedModeCleared();
}
The attack.
- The attacker uses two accounts. At a basket price of 1.00, account A opens LONG and account B opens SHORT, in alternating chunks of up to 2,000,000 USDG, so skew stays under the 0.4 × depth cap. It stops when one more open would break
E ≥ L + B. In the PoC, E = 10,002,002 USDG and an unrelated trader already holds a 10,000 LONG. A ends at 9,966,900 LONG and B at 9,976,900 SHORT. Both envelopes then equal L: a LONG's maximum profit is its entry cost, and a SHORT's is lots × 2.00 minus its entry cost, so both are 9,976,900 at 1.00. B is 24,942 USDG, and E − L − B is 159 USDG. The price PnL of the two legs cancels. The open fees are 7,977 USDG in total. Each increase must post new margin for its 10 bps liquidation reserve. The PoC posts 150,000 USDG on the first chunk of each leg and 0.5% of each later chunk. - The attacker waits for the basket to move by about 0.75% or more. The direction does not matter.
- It closes the winning leg. The pool pays the gain minus the close VPI and the 4 bps execution fee. The fee also stays in the pool: the treasury top-up is paid only from free cash above
L + B, and there is none at the edge. After a 1% move, a full close has a gain of 99,769, close VPI of about 50,759 and a fee of about 4,031. The PoC measures a pool payout of 44,978 USDG, and the treasury receives nothing. That is 20,036 more than B. With the 159 USDG of slack, E falls to L − 19,876, and degraded mode latches. - It calls
addMarginon the losing leg until the margin covers the leg's maximum profit (9,966,900 USDG in the PoC, which adds 9,800,972 USDG). The carry basemax(maxProfit − margin, 0)is then zero, so the leg pays no carry. With margin equal to its notional, the leg cannot be liquidated. The PoC shows it is still solvent after a 50% adverse move to 1.50.addMarginhas no degraded-mode gate.
From then on L cannot fall: the leg stays open, and a LONG's maximum profit is fixed at its entry cost. E rises only when new cash enters the pool. The latch blocks deposits and opens. A direct USDG transfer is not counted, because totalAssets() is min(balance, accountedAssets), and only the owner can admit it. Losses and carry paid by other traders would help, but here the attacker's pair is almost the whole book. In practice, the only way out is owner money.
Threshold, recomputed with close VPI.
Closing x of the winning leg after a move m pays out x·m − 0.005·(x·(1+m))²/D − 0.0004·x·(1+m). Close VPI is C(post) − C(pre) with C(S) = 0.005·S²/D, and the skew goes from 0 to x. With the PoC's state (D = E = 10,002,002 USDG, L = 9,976,900 USDG, B = 24,942 USDG, E − L − B = 159 USDG) and release parameters:
| Move | Close size | Gain | Close VPI | Fee | Pool outflow | L − E after close | Latch |
|---|---|---|---|---|---|---|---|
| 0.70% | full | 69,838 | 50,458 | 4,019 | 15,361 | below 0 (E − L = 9,740) | no |
| 0.80% | 7,478,100 (best) | 59,825 | 28,404 | 3,015 | 28,405 | 3,304 | yes |
| 1.00% | full | 99,769 | 50,759 | 4,031 | 44,979 | 19,878 | yes |
| 1.50% | full | 149,654 | 51,263 | 4,051 | 94,340 | 69,239 | yes |
The PoC runs the first three rows. It measures a pool outflow of 15,361 and E − L = 9,740 with no latch at 0.70%, L − E = 3,303 with a latch at 0.80%, and a pool outflow of 44,978 with L − E = 19,876 and a latch at 1.00%.
The latch needs a move of at least 0.75% with the best partial close, or 0.80% with a full close. Our tool's original example used 0.35% and left out the close VPI, so it was wrong. Section 8.3 of the whitepaper gives a median daily basket move of 22.67 bps and a 95th percentile of 83 bps. A cumulative move of 0.75% in either direction therefore typically arrives within days.
The pool can also reach the edge without the attacker filling it. LP epoch funding pays redemptions until free cash is zero, which leaves pool cash at C + L + B, so E = L + B. From there any profitable close on the smaller side that pays out more than B latches the pool, with no attacker at all. The attacker in this report only chooses the moment and keeps the latch set.
Why this is not intended.
- The repo test models real insolvency, not this.
test_ProfitableCloseLatchesDegradedModeWhenBackingFallsBelowLiabilityopens a 999,000 SHORT and a 500,000 LONG on a 1,000,000 pool with VPI turned off. It then closes the LONG after an 80% basket fall, from 1.00 to 0.20. The remaining SHORT is then 799,000 under water on 50,000 of margin, so the pool really cannot cover its book. The test's own message reads "Profitable close should latch degraded mode when it reveals insolvency". The whitepaper says the same: "valid terminal exits can complete even when they reveal insolvency; and a degraded-mode latch then prevents further risk expansion". In this report nothing is insolvent. The held leg's loss is fully collateralized. The pool's NAV has gone up by the fees and VPI the attacker paid. E is below L only against a basket move to zero. The cash that left was paid to the attacker's own winning leg, and its own losing leg owes it back. - The docs expect the latch to clear when solvency is "genuinely restored". ACCOUNTING_SPEC.md allows "owner action to clear the mode after solvency is genuinely restored". The whitepaper says the owner may clear it "after genuine restoration to A_eff ≥ L_max". Here the latch itself blocks every inflow that could restore E (deposits and opens), and the attacker's leg pays no carry. The only route left is a gift from the owner. No document accepts that an untrusted trader can choose when the latch fires, for about 39,000 USDG, and then keep it set for free.
- The buffer rules do not cover this. SECURITY.md says closes "may consume" B, and that
L <= E < L + B"is solvent but unavailable for new risk and LP redemption funding". That state is only a liquidity pause. Deposits still activate, new LP money can fund exits, and the pause ends when cash arrives or positions close. The PoC controls show this: at the edge without the latch, the first settlement funds only 3 bps of the matured Senior redemption, but the queued 500,000 USDG deposit activates and funds that redemption in full one epoch later. The latch is a different state: settlement reverts as a whole, and the latch outlives the positions that caused it. - Not a known issue. The program's known-issue list has no item on how degraded mode is triggered. The documents quoted above are design notes, not accepted risks. Cecuro LOW-73 covers only creating stop-loss protection while degraded.
Impact Details
Selected impact: Temporary freezing of funds for at least 24 hours (High).
- What is frozen. All LP capital in the pool: no Junior or Senior redemption is funded, and matured requests cannot be cancelled. Every queued LP deposit: it cannot activate, and neither a matured Junior deposit nor a Senior deposit can be cancelled. The free settlement of every trader with an open position, unless that trader closes. New deposits and all opens are refused.
- How long. The code sets no limit. While the attacker holds its fully margined leg, nothing raises E or lowers L. The latch ends only when the owner adds
L − Eof its own money and then callsclearDegradedMode.recapitalizePoolmints no shares, so the owner gets nothing back. The gap is 19,876 USDG after a 1% move in the PoC and about 69,239 USDG after a 1.5% move, and the attacker picks the move it waits for. To reopen trading and LP redemption funding at the same time, the owner must addL + B − E(44,818 USDG after a 1% move). In the PoC,recapitalizePool(L − E)is enough to clear the latch, but the payment stays queued inpendingRecapitalizationAssets. A pending claimant bucket keeps deposit activation closed (HousePoolTrancheGateLib.trancheDepositsAllowed), no redemption has free cash, and the nextsettleLpEpochreverts withHousePool__NoLpEpochProgress. Settlement resumed only when the owner instead transferredL − Eto the pool and admitted it with the owner-onlyaccountExcess. One atom less still leftclearDegradedModereverting. The project's emergency guide answers an unexpected degraded latch with diagnosis and risk-off or full containment, not with an immediate gift. The PoC shows the state unchanged after 7 days. The code never ends the freeze. It ends only when the owner decides to donate. - Cost against harm. The PoC measures the attacker's mark-to-market cost at the moment of the latch: 39,321 USDG after a 0.8% move with the best partial close, and 62,671 USDG after a 1% move with a full close. Of this, 7,977 USDG is open fees paid to the treasury and 2 USDG is keeper bounties. The rest stays in the pool as VPI and fees. That rest includes 9,952 USDG of the held LONG's open VPI, which comes back to the attacker when it finally closes that leg. For this spend, the attacker freezes the whole pool: 10,002,000 USDG of LP principal plus a 500,000 USDG queued deposit in the PoC, 159 to 254 times what it paid. LPs lose no principal. The harm is that their capital and any queued deposits cannot move.
- Preconditions. Two accounts. Each leg needs enough margin to survive the move, and more than the 3% weekend FAD requirement (about 300,000 USDG) if the pair is held over a weekend. Making the held leg carry-free needs about 9.97M USDG of margin (9,966,900 USDG in the PoC), all returned when the attacker closes. The pool must be at its admission edge, which the attacker can produce itself, and the basket must move at least 0.75%. If the winning leg is not fully margined while the attacker waits, its carry is paid into the pool when it closes, which raises the required move by about 0.013% per day of waiting.
References
- Open admission requires
E ≥ L + B: https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/libraries/CfdEnginePlanLib.sol#L770-L777 hasRequiredSettlementBuffer: https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/libraries/SolvencyAccountingLib.sol#L93-L104- Closes report solvency instead of rejecting: https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/libraries/CfdEnginePlanLib.sol#L795-L796
- Close payout checks only cash net of claims: https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/libraries/CfdEnginePlanLib.sol#L953-L966
- Close fee top-up only from free cash above
L + B: https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/libraries/CfdEnginePlanLib.sol#L984-L987 - Engine payout rule: https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/CfdEngine.sol#L840-L871
_applyCloseruns the latch check: https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/CfdEngine.sol#L1306-L1322- The latch: https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/CfdEngine.sol#L1351-L1369
_maxLiability: https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/CfdEngine.sol#L1044-L1050- Owner-only clear: https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/CfdEngine.sol#L655-L667
- Recapitalization mints no shares: https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/CfdEngine.sol#L627-L653
- LP epoch settlement reverts while degraded: https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/HousePool.sol#L832 and https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/HousePool.sol#L1864-L1870
- Deposit entry blocked while degraded: https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/HousePool.sol#L1139-L1145
- Matured Junior deposits and committed Senior deposits cannot be cancelled: https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/TrancheVault.sol#L851-L860
- Matured redemptions cannot be cancelled: https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/TrancheVault.sol#L894-L897
- Withdrawals blocked for position holders: https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/CfdEngineSettlementSidecar.sol#L274-L276
- Opens blocked: https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/libraries/CfdEnginePlanLib.sol#L318-L321 and https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/router/OrderLiquidationBatchLogic.sol#L328-L330
addMarginhas no degraded gate: https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/CfdEngine.sol#L501-L529- Carry base is zero when margin covers maximum profit: https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/libraries/PositionRiskAccountingLib.sol#L48-L53
- Maximum profit per side: https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/CfdMath.sol#L76-L90
- VPI curve: https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src/CfdMath.sol#L118-L140
- The repo test (80% move, real shortfall): https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/test/perps/accounting/close/DegradedSettlementBehavior.t.sol#L32-L44
- ACCOUNTING_SPEC.md, clear "after solvency is genuinely restored": https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/ACCOUNTING_SPEC.md#L1201-L1233
- WHITEPAPER.md, latch when exits "reveal insolvency": https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/WHITEPAPER.md#L41-L44 and https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/WHITEPAPER.md#L1322-L1342
- SECURITY.md, buffer and latch design: https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/SECURITY.md#L340 and https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/SECURITY.md#L936-L943
- Emergency guide response to
EngineDegraded: https://github.com/immunefi-team/audit-comp-plether/blob/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/EMERGENCY_RESPONSE_GUIDE.md#L178
Recommendation
- Latch on real insolvency, not on raw
E < L. Count the collectible price losses of open positions, up to their pledged margin, as backing in the latch test, as terminal NAV already does. A gain paid out of a hedged book is then backed by the matching loss and does not latch. - Let anyone clear the latch once
E ≥ L, so it cannot outlive the positions that caused it. Keep the owner-only clear for anything else. - Consider charging carry on the part of L that a position occupies even when it is fully margined, so the losing leg cannot hold the pool at the edge for free.
Proof of Concept
Proof of Concept
Test file: packages/perps/test/perps/poc/HedgedCloseLatchesDegradedModePoC.t.sol (create it with the code below)
Run (from the repository root): forge test --root packages/perps --match-path test/perps/poc/HedgedCloseLatchesDegradedModePoC.t.sol -vv
The test uses the project's own Foundry setup (BasePerpTest) with the release risk parameters and Senior caps, and does not change any in-scope contract. Only Pyth prices and USDG are mocked. Every trader, keeper and LP step goes through a public entry point from the actor's own address: the order router's commit, execute, updateMarkPrice, settleLpEpoch and executeLiquidation, CfdEngine.addMargin, MarginClearinghouse.withdrawMargin, and the TrancheVault request and cancel functions. The owner (the test contract) acts only in the final cure step, with recapitalizePool, a direct USDG transfer plus accountExcess, and clearDegradedMode.
Steps
Step 1. A Junior LP deposits 8,000,000 USDG and a Senior LP deposits 2,000,000 USDG. With the two 1,000 USDG seeds of the test base, E is 10,002,002 USDG. An unrelated trader (the bystander) opens a 10,000 LONG with 1,000 USDG of margin.
Step 2. At the start of a fresh LP epoch, a new LP queues a 500,000 USDG Junior deposit. The Junior LP requests to redeem 1,000,000 USDG worth of shares, and the Senior LP 500,000 USDG worth. All three requests mature at the next epoch boundary.
Step 3. The attacker builds the hedged pair at 1.00 from two accounts, alternating LONG (A) and SHORT (B) chunks of at most 2,000,000 so skew stays under 0.4 × depth. Each LONG chunk is the largest that keeps E ≥ L + B. A ends with 9,966,900 LONG and B with 9,976,900 SHORT. Both side envelopes equal L = 9,976,900 USDG, the buffer B is 24,942 USDG, and E − L − B is 159 USDG. The test asserts the pool is at its admission edge and not degraded.
Step 4 (attack). The basket moves to 1.01 and B closes its whole SHORT through the router. The gain is 99,769 USDG. The pool pays 44,978 USDG, and the treasury receives no close fee. E falls to 9,957,023 USDG while L stays at 9,976,900, so L − E = 19,876 USDG and degradedMode is set by this close. The attacker's mark-to-market cost at this point is 62,671 USDG: 7,977 of open fees to the treasury, 2 of keeper bounties, and 54,692 kept by the pool. 9,952 of that is the LONG's open VPI, which the attacker gets back when it closes the LONG. The frozen LP principal is 10,002,000 USDG, 159 times the cost.
Step 5. A calls addMargin with 9,800,972 USDG. Its carry base becomes 0. A liquidation attempt after a 50% adverse move to 1.50 reverts with CfdEngine__PositionIsSolvent.
Step 6. The test checks the freeze right after the latch, at the maturity boundary, 24 hours later and 7 days later. It measures the elapsed time with vm.getBlockTimestamp() (24 h and 168 h). Each time:
router.settleLpEpochreverts withHousePool__DegradedMode. The queued deposit is not activated, and neither redemption is funded.- Once the requests have matured, cancelling them reverts:
TrancheVault__DepositEpochAlreadyActivefor the deposit, andTrancheVault__RedeemCancellationUnavailablefor both redemptions. - With a fresh mark, the bystander's
withdrawMarginreverts withCfdEngine__DegradedMode. - A new trader's commit, even a skew-reducing SHORT, reverts with
OrderRouter__DegradedMode. - A new Junior deposit request reverts with
TrancheVault__DepositsUnavailable. - Liquidating A reverts with
CfdEngine__PositionIsSolvent. clearDegradedModereverts for a keeper (not the owner), and for the owner withCfdEngine__StillInsolvent.
After 7 days E and L are unchanged, and A has accrued no carry.
Step 7 (owner cure). From the same state, two owner paths are tried:
- (a)
recapitalizePool(L − E)lets the owner clear the latch, but the 19,876 USDG stays inpendingRecapitalizationAssets, andsettleLpEpochstill reverts, now withHousePool__NoLpEpochProgress. - (b) The owner transfers USDG to the pool and admits it with
accountExcess. With one atom less than L − E,clearDegradedModestill reverts. With exactly L − E it succeeds, settlement activates the 500,000 USDG deposit, and the bystander can withdraw again.
Step 8 (threshold). From the edge, a 0.80% move and a partial close of 7,478,100 of the SHORT already latch, with L − E = 3,303 USDG. The mark-to-market cost is 39,321 USDG, and the frozen LP principal is 254 times that.
Step 9 (controls). Each control starts from the same edge state.
- (A) The same full close with no price move does not latch (E − L = 74,861 USDG).
- (B) The same 1% move with no close does not latch.
- In A and B, A tops up its LONG the same way. At the boundary the settlement succeeds and the queued deposit activates. The bystander can withdraw, and a new open and a new deposit request are accepted. One epoch later the Senior redemption is fully funded (10,000 bps; only 3 bps in control B's first epoch, because the pool is at its edge).
- (C) A full close after a 0.70% move pays 15,361 USDG, less than the 24,942 USDG buffer, and does not latch (E − L = 9,740 USDG).
Code
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.35;
import {BasePerpTest} from "../BasePerpTest.sol";
import {CfdTypes} from "@plether/perps/CfdTypes.sol";
import {OrderV3Types} from "@plether/perps/OrderV3Types.sol";
import {TrancheVault} from "@plether/perps/TrancheVault.sol";
import {ICfdEngineTypes} from "@plether/perps/interfaces/ICfdEngineTypes.sol";
import {IHousePool} from "@plether/perps/interfaces/IHousePool.sol";
import {IOrderRouterErrors} from "@plether/perps/interfaces/IOrderRouterErrors.sol";
import {console2} from "forge-std/console2.sol";
/// @notice Opens must leave E >= L + B (E = pool assets net of trader claims, L = larger side's maximum profit,
/// B = 25 bps of L). Closes are never rejected for solvency, and a winning close on the side that is not the
/// larger one pays out of pool cash while L stays the same. CfdEngine._enterDegradedModeIfInsolvent then
/// latches degraded mode as soon as E < L. While latched, every LP epoch settlement reverts
/// (HousePool__DegradedMode), every open is refused, and position holders cannot withdraw. Only the owner can
/// clear the latch, and only once E >= L again.
///
/// The attacker holds a hedged LONG/SHORT pair that fills the pool to its admission edge, waits for a 1%
/// basket move, closes the winning SHORT, and tops the losing LONG up to full margin so it pays no carry and
/// cannot be liquidated. Nothing permissionless brings E back to L: LP settlement stays frozen until the owner
/// puts L - E of its own money into the pool.
///
/// Only Pyth prices (MockPyth) and USDG (MockSettlementToken) are mocked. Every trader and LP step goes
/// through a public entry point from the actor's own address: OrderRouter commit/execute, updateMarkPrice,
/// settleLpEpoch and executeLiquidation; CfdEngine.addMargin; MarginClearinghouse.withdrawMargin; TrancheVault
/// requests and cancellations. The test contract (owner) acts only in the final cure step, through
/// recapitalizePool, accountExcess and clearDegradedMode.
contract HedgedCloseLatchesDegradedModePoC is BasePerpTest {
address internal constant KEEPER = address(0xBEEF);
address internal constant JUNIOR_LP = address(0x1E01);
address internal constant SENIOR_LP = address(0x5E01);
address internal constant NEW_LP = address(0x1E02);
address internal constant LATE_LP = address(0x1E03);
address internal constant BYSTANDER = address(0xB0B0);
address internal constant FRESH_TRADER = address(0xF4E5);
address internal constant ATTACKER_LONG = address(0xA77A);
address internal constant ATTACKER_SHORT = address(0xA77B);
uint256 internal constant ENTRY_PRICE = 1e8;
uint256 internal constant MOVED_PRICE = 1.01e8;
uint256 internal constant CHUNK_ASSETS = 2_000_000e6;
uint256 internal constant QUANTUM_ASSETS = 100e6; // SIZE_QUANTUM (100 units) at 1.00
uint256 internal constant ATTACKER_LONG_FUNDS = 10_200_000e6;
uint256 internal constant ATTACKER_SHORT_FUNDS = 400_000e6;
uint256 internal constant QUEUED_DEPOSIT = 500_000e6;
uint256 internal depositId;
uint256 internal juniorRedeemId;
uint256 internal seniorRedeemId;
uint256 internal juniorRedeemShares;
uint256 internal seniorRedeemShares;
uint256 internal edgeEffectiveAssets;
uint256 internal edgeMaxLiability;
uint256 internal edgeBuffer;
uint256 internal treasuryBeforeBuild;
uint256 internal keeperBeforeBuild;
/// @dev Release risk parameters from packages/perps/DEPLOYMENT.md ("Initial release parameters").
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
});
}
function _initialJuniorDeposit() internal pure override returns (uint256) {
return 0;
}
function _initialSeniorDeposit() internal pure override returns (uint256) {
return 0;
}
function setUp() publi
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 degraded-mode check compares raw effective assets with maximum liability without counting the collectible losses of open positions as backing, so a payout on a hedged book latches the mode even though the book is fully collateralised.
Impact
All LP redemptions and deposits, trader withdrawals and new opens are frozen with no code-set end, and the PoC shows the state unchanged after 7 days until the owner donates the gap.
What the attacker needed
Two accounts; pool at its admission edge; basket moves at least 0.75%; about 9.97M USDG margin for the held leg
The fix
The latch should count collectible losses of open positions up to their margin as backing, and anyone should be able to clear it once effective assets cover liability.
How it was found
- Two accounts build a hedged LONG/SHORT pair in alternating chunks until the pool sits at its admission edge.
- The basket price moves by about 0.75% or more in either direction.
- The winning leg is closed, paying out pool cash and pushing effective assets below maximum liability, which sets degraded mode.
- The losing leg is topped up with margin until its carry base is zero and it cannot be liquidated.
- The freeze is checked immediately, at maturity, after 24 hours and after 7 days, with settlement, cancellation, withdrawal and new orders all reverting.
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.
The pool only lets people open new bets while it holds enough spare cash to cover the biggest possible payout. Closing a winning bet pays out real cash but does not shrink that biggest possible payout, so a cleverly balanced pair of opposite bets can be closed to drain the spare cash. The system then enters a safety mode that stops all money moving, and only the owner can switch it off by putting in their own funds.
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.