{
 "item": "house-edge-first-loss",
 "commit": "ff1c192b3798542997f600091f2dc73ff05e4c40",
 "forge": "forge 1.8.3 (cae51ad458f6abb64852b7709eb784352429825d, 2026-09-15); older than 1.9, solc 0.8.38 not installed: no test compiled or ran; every answer below is reasoned from the code at the commit, tests written but NOT RUN",
 "verdict": "findings",
 "findings": [
  {
   "id": "HEFL-1",
   "severity": "low",
   "title": "Any landed report of a type with bad debt (including the liquidation's own same-tx report, when no FirstLossOwed wait ever happened) moves the global owedEndedAt and revives every lapsed withdrawal request for CLAIM_WINDOW",
   "property": "P3 (claim-window gate of the first-loss wait); C3",
   "claim": "C3: 'A zero-loss report no longer extends a claim window: find another call that does.' Found: Liquidator.bite/settle -> _cover -> Ledger.reportLoss -> Treasury.coverBadDebt -> Backstop.coverBadDebt with bad != 0.",
   "files": [
    "src/house/backstop/Backstop.sol:638",
    "src/house/backstop/Backstop.sol:517",
    "src/house/backstop/Backstop.sol:518",
    "src/house/Liquidator.sol:216",
    "src/house/Ledger.sol:402"
   ],
   "sequence": "1) carol requests withdraw of all shares; 2) she lets it lapse (at+QUEUE+CLAIM_WINDOW passes; withdraw reverts Expired); 3) any edge-type liquidation that books bad debt (any size, any type of the sleeve) reports in the same tx: Backstop.coverBadDebt reads bad != 0 on entry and sets owedEndedAt = now although owedBadDebt() was never non-zero at any block; 4) withdraw: ended >= r.at+QUEUE and ended+CLAIM_WINDOW > end, so end = now+2d: carol exits with no new 7-day queue. owedEndedAt is one global slot, so one report revives every lapsed request of every depositor.",
   "expected": "Per the FR1 comment at Backstop.sol:634-637 ('a zero-loss report ... ended no wait, so it never extends a matured request's window or revives a lapsed one') and README:729 ('a request that matured during the wait stays claimable for 2 days after the report lands'): only a request that was blocked by a real FirstLossOwed wait gets a window from the report.",
   "actual": "The gate is 'this type had bad debt booked on entry', not 'a wait happened'. A report that lands in the very transaction that booked the loss ended no wait, yet revives lapsed requests (weeks old) for 2 days: a standing option for lapsed requesters to skip the 7-day queue after any bad-debt liquidation, i.e. exactly when the next loss is likeliest.",
   "reachableAtDeploy": true,
   "fix": "Record when a wait began: e.g. in Backstop.withdraw, on FirstLossOwed revert is not storable, so instead store waitStartedAt = block.timestamp the first time owedBadDebt() != 0 is observed by a liquidation that could not report (Liquidator: when the try reportLoss fails, call backstop.noteWait()), and in withdraw extend only if waitStartedAt != 0 && ended >= waitStartedAt && r.at + QUEUE + CLAIM_WINDOW > waitStartedAt (the request was live when the wait began). Simpler: extend only requests whose own window was still open at the time bad debt was booked (store bookedAt per type in Ledger).",
   "test": {
    "source": "// test/house/unit/ScratchHouseEdgeFL.t.sol (HouseRig, same helpers as test/house/unit/FixReviewW7House.t.sol)\npragma solidity 0.8.38;\nimport \"forge-std/Test.sol\";\nimport {HouseRig} from \"../utils/HouseRig.sol\";\nimport {Backstop} from \"../../../src/house/backstop/Backstop.sol\";\ncontract ScratchHouseEdgeFL is HouseRig {\n    function setUp() public { _setUpHouse(); }\n    /// No FirstLossOwed wait ever happens: the liquidation reports its own bad debt in the same tx (Liquidator._cover),\n    /// yet owedEndedAt moves and a request that LAPSED weeks ago (any delay, fuzzed) becomes claimable at once.\n    function testFuzz_lapsedRequestRevivedByAnyLandedReport(uint256 lapse) public {\n        _fund(dave, 20_000e18); _fund(eve, 20_000e18); _fund(carol, 6_000e18);\n        vm.prank(carol); edge.deposit(6_000e18, carol);\n        _skip(3 days); edge.realize(carol);\n        simdFeed.set(5e18);\n        uint256 ib = _open(bob, SIMD, 3_000e18, 6_000e18, 0.05e18);\n        uint256 sh = edge.balanceOf(carol);\n        vm.prank(carol); edge.requestWithdraw(sh);\n        _skip(7 days + 2 days + bound(lapse, 1, 60 days)); // lapsed, no wait at any time\n        vm.prank(carol); vm.expectRevert(Backstop.Expired.selector); edge.withdraw(carol);\n        simdFeed.set(1.5e18);\n        vm.prank(eve); liquidator.liquidate(ib); // books bad debt AND reports it in the same tx\n        assertEq(ledger.totalBadDebt(), 0, \"report landed in the liquidation\");\n        vm.prank(carol);\n        (bool ok,) = address(edge).call(abi.encodeCall(Backstop.withdraw, (carol)));\n        assertFalse(ok, \"a lapsed request was revived by a report that ended no wait\");\n    }\n}",
    "ran": false,
    "result": "NOT RUN: forge 1.8.3 (cae51ad) on this machine is older than 1.9 (no --use solar); foundry.toml and every source pin solc 0.8.38, not installed (only 0.8.26-0.8.30). Reasoned from code per the brief. Expected by reading: assertFalse fails (withdraw succeeds) because Backstop.sol:638 sets owedEndedAt inside the liquidation's own report and Backstop.sol:518 extends end to owedEndedAt+2d."
   }
  },
  {
   "id": "HEFL-2",
   "severity": "low",
   "title": "A FirstLossOwed wait on a priced held token turns into a permanent skip once its median (or NHI) leg goes stale: the in-kind first loss passes to the Treasury and the hub for good",
   "property": "P1",
   "claim": "C1: show pusher + prover (or a report held until a leg is stale) reach the skip.",
   "files": [
    "src/house/backstop/Backstop.sol:662",
    "src/house/backstop/Backstop.sol:663",
    "src/house/backstop/PricerOracle.sol:55",
    "src/house/Pricer.sol:87",
    "src/house/Pricer.sol:92",
    "src/house/Pricer.sol:96"
   ],
   "sequence": "1) edge-type liquidation books bad debt while a pool pusher + prover holds a proven spot one leg above median*(1+skew): PricerOracle.priceOf -> (low!=0, ok=false), the in-kind loop reverts FirstLossOwed, Treasury reverts EdgeCoverFailed, Liquidator's try swallows it: bad debt stays booked (README:729, as written); 2) the stranger re-pushes to keep the legs apart (README: 'at the manipulation cost each time'); 3) the median leg (ProductFeed of swarm IMD/ETH x Chainlink ETH/USD for sIMD) or the NHI leg turns stale (Chainlink stall, or the swarm attester withholding signatures); Pricer.quote: medianOk=false -> returns q with low=0, priced=false (Pricer.sol:87-96); PricerOracle.priceOf returns (0,0,false) (PricerOracle.sol:55); 4) anyone calls Ledger.reportLoss: Backstop.sol:663 `if (!ok || low == 0) continue;` skips the token, the Treasury and the hub take the rest, bad debt cleared, owedBadDebt()==0, depositors withdraw with the sIMD that owed the loss.",
   "expected": "README:729: for a token whose type is priced 'the first loss is paid or waits, never skipped'; P1: 'never skipped while a HELD token's type is priced'.",
   "actual": "The wait does not keep the obligation: it only defers the moment the price is read. Whoever can hold the wait until a leg stalls converts it into the skip README:738 allows only for tokens 'with no price'. Worse than written: neither README:729 nor README:738 says a priced-and-refused token can be made skippable by holding the wait across a feed stall.",
   "reachableAtDeploy": true,
   "fix": "Make the obligation survive the read: when the in-kind leg cannot pay (refused OR stale/unpriced while the type is configured), record owedInKind += rest instead of skipping or reverting, keep withdrawals/conversions locked on owedInKind != 0, and let anyone settle it later at a good price (see C6). At minimum: treat low==0 from a configured, non-retired type like a refusal (revert FirstLossOwed) and skip only retired tokens (Backstop.retire, 48h timelock).",
   "test": {
    "source": "// same contract as above (imports PricerOracle, IMinterHub as in FixReviewW7House.t.sol)\n    /// A refused priced token makes the report wait (README:729); hold it (re-push) until the median leg goes stale:\n    /// PricerOracle.priceOf then returns (0,0,false) (Pricer.quote returns q unpriced, low 0) and the next report SKIPS it.\n    function testFuzz_waitTurnsIntoSkipWhenMedianStales(uint256 waitLen) public {\n        _fund(dave, 20_000e18); _fund(eve, 20_000e18); _fund(carol, 6_000e18);\n        vm.prank(carol); edge.deposit(6_000e18, carol);\n        _skip(3 days); edge.realize(carol);\n        simdFeed.set(5e18);\n        uint256 ib = _open(bob, SIMD, 3_000e18, 6_000e18, 0.05e18);\n        simdFeed.set(1.5e18);\n        // a pushed proof (one leg above skew): priced, refused -> the in-kind leg reverts FirstLossOwed, report caught\n        vm.mockCall(address(oracle), abi.encodeWithSelector(PricerOracle.priceOf.selector, address(simd)),\n            abi.encode(uint256(1.5e18), uint256(1.9e18), false));\n        vm.prank(eve); liquidator.liquidate(ib);\n        assertGt(ledger.totalBadDebt(), 0, \"report waits\");\n        _skip(bound(waitLen, 1 hours, 30 days));\n        // the median leg is now stale (Chainlink stall / swarm withholding): quote unpriced, low 0\n        vm.mockCall(address(oracle), abi.encodeWithSelector(PricerOracle.priceOf.selector, address(simd)),\n            abi.encode(uint256(0), uint256(0), false));\n        uint256 held = edge.coll(address(simd));\n        ledger.reportLoss(SIMD);\n        vm.clearMockedCalls();\n        assertEq(ledger.totalBadDebt(), 0, \"loss left the books\");\n        assertLt(edge.coll(address(simd)), held, \"held sIMD paid no first loss: skipped for good\");\n    }",
    "ran": false,
    "result": "NOT RUN: forge 1.8.3 (cae51ad) on this machine is older than 1.9 (no --use solar); foundry.toml and every source pin solc 0.8.38, not installed (only 0.8.26-0.8.30). Reasoned from code per the brief. Expected by reading: assertLt fails (coll unchanged) since Backstop.sol:663 continues on low==0 and Ledger._report clears the bad debt."
   }
  }
 ],
 "claims": [
  {
   "id": "C1",
   "result": "holds",
   "evidence": "Code confirms the skip: Backstop.sol:663 `if (!ok || low == 0) continue;` and :666 `if (!_trySend(t, to, give)) continue;` (no record of what was skipped). Pusher+prover alone: a pushed proof gives low!=0, ok=false -> revert FirstLossOwed (:662), not a skip; ProductFeed/RateFeed return 0 on overflow (ProductFeed.sol:28) so a too-large SPOT leg reads spotOk=false and prices at the median (Pricer.sol:120-121), no skip. Reached with a held report + stale median/NHI leg: HEFL-2. Gas starvation: Liquidator._cover requires COVER_MIN_GAS (Liquidator.sol:215); a send or quote starved inside the in-kind loop leaves each frame <=1/64 of its gas (Backstop, Treasury, Ledger) for Ledger.cover/_report/hub.reportLoss, so for any normal token (send < ~1M gas) the report runs out of gas and reverts whole (Treasury: empty revert data -> EdgeCoverFailed, Treasury.sol:133). Not run (forge 1.8.3)."
  },
  {
   "id": "C2",
   "result": "holds",
   "evidence": "Confirmed: the loop (Backstop.sol:645-671) reverts the whole cover at the first refused token it reaches, even if later tokens could pay; only tokens reached before rest==0 matter (loop guard `rest != 0`), so token order in `tokens` decides. Bound: none in time; it lasts while the legs disagree, i.e. until the median catches up (one TWIN_STEP per epoch) or the pusher stops; each re-push costs the pool manipulation. This is README:729 as written ('a stranger can re-push a proof to prolong it at the manipulation cost each time'). Worse-than-written route is HEFL-2 (the wait can end in a skip)."
  },
  {
   "id": "C3",
   "result": "refuted",
   "evidence": "The zero-loss case is fixed (Backstop.sol:638 `if (bad != 0)`), but another call extends/revives: any report of a type with bad debt on entry, including the liquidation's own same-tx report (Liquidator.sol:216) that ended no wait. HEFL-1."
  },
  {
   "id": "C4",
   "result": "holds",
   "evidence": "owedBadDebt (Backstop.sol:325-333) sums the full booked badDebt of live types; netVested (:337-343) nets min(owed, vested-floor). Conversions wait when owed > vested-floor (_lossOverRoom, :785-789, _convert :805). At the report, coverBadDebt takes min(bad, room) but ledger.cover collects only min(amount, collectable()) and cancels the rest (Ledger.sol:452-453); covered is measured by balance (:615-617). So nav at conversion is low by exactly bad - collected = the cancelled booked interest; in kind is capped by collectable too (:641-642), so it adds no further gap. A disabled type is excluded from both owedBadDebt and coverBadDebt (UnknownIlk -> Treasury pays), consistent."
  },
  {
   "id": "C5",
   "result": "holds",
   "evidence": "grep T_REPORTING src/: written only at Ledger.sol:410-411 and :415 (restore `was`); LedgerBase.sol:187/196 and Ledger.sol:423 only read. LedgerSettlement (delegatecall, shared transient storage) only reads it in _notInReport (LedgerSettlement.sol:81, :191). A nested reportLoss restores 1 on exit (was=1). The flag is cleared before _report (Ledger.sol:415-417), so hub.reportLoss runs with it off; nothing reads it there. Nested in-kind is further closed by Backstop nonReentrant (inner sleeve call reverts -> Treasury EdgeCoverFailed) and the listing rule (Backstop.sol:244-247)."
  },
  {
   "id": "C6",
   "result": "holds",
   "evidence": "Smallest replacement: make the in-kind leg a recorded debt, not a same-tx payment. In Backstop.coverBadDebt under reporting(): owed = min(rest, collectable); pay in kind what is priced ok and sendable; add the remainder to a storage `inKindOwed` (imdUSD units) and RETURN (never revert, never skip), so the report always lands (P1 liquidation and report settle) and Ledger clears badDebt once (P2). A permissionless settleInKind() pays inKindOwed from any held token at a good low (rounded up) to the Treasury; Treasury refunds the hub/reserve leg that fronted it. withdraw and _convert require inKindOwed == 0 (P3), nav nets inKindOwed. Only a RETIRED token (Parameters, 48h) may be written off from it. Invariant: \u03a3 firstLossDue == \u03a3 coveredImd + \u03a3 inKindValuePaid + inKindOwed, with inKindOwed > 0 => no withdraw and no conversion. This removes the wait (C2), the skip (C1/HEFL-2) and the need for owedEndedAt (HEFL-1)."
  }
 ],
 "holds": [
  {
   "property": "P1 (liquidation always settles)",
   "tried": "Read Liquidator._cover (Liquidator.sol:213-217): COVER_MIN_GAS check then try ledger.reportLoss {} catch {}; bite and settle call it after liquidatePosition. A refused token, a sleeve mid-bid (EdgeBidOpen) or hub revert reverts only the report. Starved gas below COVER_MIN_GAS reverts the liquidation itself (by design: CoverGasShort). Not run."
  },
  {
   "property": "P1 (in kind never skipped while priced)",
   "tried": "Fails: HEFL-2 (wait -> stale leg -> skip). Unsendable (issuer pause/blocklist of the Treasury) skip is README:738 as written ('skipped, that part never owed again')."
  },
  {
   "property": "P2 (edge bad debt leaves only via Ledger.cover and reportLoss)",
   "tried": "grep badDebt writers in src/house: decrements only Ledger.cover (Ledger.sol:383-385) and Ledger._report (:429-431); increments only LedgerSettlement.liquidatePosition (:144) and writeOff (:220). Ledger.cover burns the caller's imdUSD (a stranger paying is a gift). Order: Backstop.coverBadDebt outside reporting pays imdUSD only (:633), Treasury.coverBadDebt pays nothing for an edge type outside reporting (Treasury.sol:138), so neither can jump ahead of the in-kind leg in any order; inside reportLoss the sleeve's imdUSD, in kind, then Treasury, then hub. Once per loss: _report zeroes badDebt in the same call. Holds (not run)."
  },
  {
   "property": "P2 (in kind only while reporting(); no bad debt booked while reporting())",
   "tried": "In kind is after `if (!ledger.reporting()) return covered;` (Backstop.sol:633). Both bad-debt writers call _notInReport (LedgerSettlement.sol:81, :191) reading the same T_REPORTING slot through delegatecall. Holds (not run)."
  },
  {
   "property": "P3 (no depositor withdraws while edge bad debt is booked)",
   "tried": "withdraw reverts FirstLossOwed on owedBadDebt()!=0 (Backstop.sol:513); claim() pays only collateral already split at a prior withdraw. owedBadDebt skips disabled types (:329): disableIlk is the deployer's until seal (sealed in StageHouse.sol:135 / StageGenesis.sol:189, README known) then Parameters (Safe, accepted); a disabled type's loss is the Treasury's (UnknownIlk caught, Treasury.sol:133). Holds for strangers; the window gate is HEFL-1."
  }
 ],
 "notRun": [
  "Every Foundry test: forge 1.8.3 (< 1.9, no --use solar) and solc 0.8.38 not installed; HEFL-1 and HEFL-2 test sources written against test/utils/HouseRig.sol but not compiled",
  "No [fork] or [data] claim in this sheet; none run"
 ]
}