{
 "item": "hub-rows-frozen-loss",
 "commit": "ff1c192b3798542997f600091f2dc73ff05e4c40",
 "forge": "forge 1.9.0 (6056c584). `--use solar` is refused by this build (`solc \"solar\" does not exist`) and solc 0.8.38 is not installed, so every test was compiled with solar 0.3.1 (Solc-Compatible 0.8.39, release tarball sha256 0a620c9d...8b4a matching its published .sha256) passed as `--use <path-to-solar>`, --match-path test/scratch/HubRows.t.sol only.",
 "verdict": "holds",
 "findings": [],
 "claims": [
  {
   "id": "C1",
   "result": "holds",
   "evidence": "Every gate named exists and reads what the claim says: UNFREEZE src/hub/MinterHub.sol:486 (bad, covered, mark; run at propose and again at apply via _validateAtApply src/hub/MinterHub.sol:422-426); lossOf src/hub/MinterHub.sol:352 = bad + covered; RELEASE_RESERVE src/hub/MinterHub.sol:452 (totalBad, marks; it does not read totalCovered, as the claim says); RELEASE_COVERED src/hub/MinterHub.sol:497 with the clamp at apply src/hub/MinterHub.sol:548-549; the cap via _used src/hub/MinterHub.sol:570-571 = outstanding + bad + covered. covered rises in exactly one place, _toCovered src/hub/MinterHub.sol:597-603, which takes the same amount out of bad (s.bad -= paid), and is reached only from _coverFromReserve src/hub/MinterHub.sol:632/:642 (reportLoss or anyone's coverFromReserve). So a stranger can only turn a bad that already blocked UNFREEZE / lossOf / the cap into a covered that blocks the same three. It does unblock RELEASE_RESERVE's totalBad leg, but the reserve that cover burned also lowers reserveLow (_fell src/hub/MinterHub.sol:653), and RELEASE_RESERVE stays a Safe proposal. Fuzzed in the handler: no non-mint act raises any used_s, UNFREEZE never lands on a row with bad, covered or mark, 500 runs x 200 calls PASS. Planted mutant 'UNFREEZE ignores covered' is caught (FAIL: P3: UNFREEZE landed on an owed row)."
  },
  {
   "id": "C2",
   "result": "holds",
   "evidence": "src/hub/MinterHub.sol:224 sets fc = 0 on a frozen row before the only restore mint (src/hub/MinterHub.sol:232). The handler's restore(i,a) asserts that the hub reserve and token totalSupply are unchanged whenever the row was frozen: 3646 frozen-row restores over 500 runs PASS. Planted mutant deleting :224 is caught (FAIL: C2: frozen restore minted). A restore placed in front of the Safe's freeze still mints back; that is the case README:617-618 covers (\"Once the Safe FREEZES the row, `restore` mints nothing back\")."
  },
  {
   "id": "C3",
   "result": "holds",
   "evidence": "The hub never calls a spoke. Its only external calls go to ImdUSD (mint, burn, transfer, transferFrom, balanceOf), and ImdUSD._update (src/ImdUSD.sol:232-248) makes no external call, so there is no reentry path. Every spoke-callable writer is nonReentrant (src/hub/MinterHub.sol:164,185,197,213,236). A spoke's own acts write only its own row (_spoke() src/hub/MinterHub.sol:558) and the shared totals. The only cross-row writes are the reserve-order loop (src/hub/MinterHub.sol:623-639) and anyone's cover / repayReserve, which spend the caller's own imdUSD (src/hub/MinterHub.sol:251,267). Handler: 4 hostile spokes (rows 0-1 non-exotic, 2-3 exotic) mint, burn, report, restore, report-restore-report in one tx (churn), pay, cover and repay other rows, in any order with dt=0 (same block) or consecutive blocks. Checks: a mint moves no other row's used, a cover changes another row's covered only under the reserve order (non-exotic rows, for an exotic cover), supply == sum(outstanding+bad) == totalUsed - totalCovered. PASS. A variant of README:613 that uses cover(nonExoticRow) instead of payReserve+reportLoss moves a non-exotic loss onto the exotic row, still bounded by the spoke's room (each step needs fresh imdUSD that only mint gives), which is inside the written bound."
  },
  {
   "id": "C4",
   "result": "holds",
   "evidence": "RELEASE_COVERED is clamped at apply (src/hub/MinterHub.sol:548-549). Only covered == 0 refuses it (src/hub/MinterHub.sol:497), and that means the loss was fully repaid. A stranger's coverFromReserve cannot lower the reserve without bad standing, and while bad stands RELEASE_RESERVE is already refused (src/hub/MinterHub.sol:452). testFuzz_C4_repayShortensRelease (stranger repays x in [1, covered-1], then coverFromReserve on a row of its choice, then applies): PASS, runs 256; covered ends at 0. Any refusal leaves the Safe free to re-propose, so nothing blocks for good."
  },
  {
   "id": "C5",
   "result": "holds",
   "evidence": "freeze src/hub/MinterHub.sol:389-390 drops UNFREEZE|i and RELEASE_COVERED|i; markLoss src/hub/MinterHub.sol:401-402 drops LOWER_MARK|i and RELEASE_COVERED|i. Both do it on a no-op too. testFuzz_C5_freezeOrMarkDropsRelease (a release matured 0-14 days, then the Safe's freeze or markLoss(i,1), then a stranger's applyPending(0x60) reverts and covered is unchanged): PASS, runs 256. The handler asserts both pendingOf slots are empty after every freeze and markLoss. The only way a release lands is a stranger applying the matured release BEFORE the freeze in the same block (applyPending is permissionless, src/GovernedByKind.sol:90). That is the general GovernedByKind model the README:860 line sits in; it is not an apply after the freeze."
  }
 ],
 "holds": [
  {
   "property": "P1 Every hub mint leaves used_s <= cap_s, sum used <= totalCap, sum exotic used <= exoticCap; only a mint by s raises used_s.",
   "tried": "mint checks all three on the hub's own counters (src/hub/MinterHub.sol:167-175). Writers of outstanding/bad/covered (mint, burn, reportLoss, restore, cover, coverFromReserve, repayReserve, RELEASE_COVERED apply) all leave used_s the same or lower except mint; ADD_SPOKE starts rows at 0. Handler: after every successful mint, used_i <= cap_i, totalUsed <= totalCap, exoticUsed <= exoticCap, other rows' used unchanged, amount <= room(); every other action wrapped in noRaise (no used_s rises), including Safe lowerCap/freeze/markLoss, matured proposals applied by a stranger (SET_CAP, UNFREEZE, LOWER_MARK, RELEASE_COVERED, RELEASE_RESERVE) warped to maturity in front of the next act. invariant_sums (totalUsed, exoticUsed, totalBad, totalCovered, marks equal the row sums) PASS. Observation (no property here fails): freeze(i) does not drop a pending SET_CAP raise of row i. It cannot apply while the row is frozen (src/hub/MinterHub.sol:480), but once a matured UNFREEZE lands a stranger can apply the pre-freeze raise inside its 14-day window (test_obs_staleSetCapAfterUnfreeze PASS). The Safe can cancel(0x2i) or lowerCap; a raise still passes the cap rule."
  },
  {
   "property": "P2 A spoke can always burn up to outstanding_s of its own balance (any cap, freeze, loss, mark, proposal).",
   "tried": "burn (src/hub/MinterHub.sol:185-193) reads only outstanding. _less cannot underflow because totalUsed and exoticUsed equal the row sums (invariant_sums). Handler: burn(i, min(outstanding, balance)) is asserted never to revert (any revert sets 'P2' and fails), interleaved with freeze, marks, lowerCap to 0, every pending kind, losses, covers, restores and releases: 100000 calls PASS."
  },
  {
   "property": "P3 A row whose loss is owed (bad, covered or a mark) cannot be unfrozen by any apply; once cleared, a matured UNFREEZE lands.",
   "tried": "UNFREEZE is the only writer of frozen=false (src/hub/MinterHub.sol:536), and it is re-checked at apply (src/hub/MinterHub.sol:486). Handler applyAny picks a pending kind, warps to its ETA (sometimes beyond) and applies it as a stranger. Each successful UNFREEZE is checked against the row's pre-state (no bad, covered or mark), and a matured UNFREEZE of a cleared row inside its window is asserted to land: 128 UNFREEZE applies and 602 applies in total over 500 runs PASS; the mutant that drops covered from :486 FAILS. Routes that clear a frozen row's loss: repayReserve and cover (real imdUSD), RELEASE_COVERED and LOWER_MARK (Safe, 48 h), and the spoke's own restore of bad (README:1059, the spoke's word). A stranger cannot raise bad, covered or mark, so a stranger cannot hold an UNFREEZE off. Observation: a pending RELEASE_COVERED is clamped at apply, so it also releases covered loss reported after it was proposed (test_obs_releaseCoversLaterLoss PASS); only freeze and markLoss drop it, a new reportLoss does not."
  },
  {
   "property": "P4 The reserve burns against bad, non-exotic rows first; spoke s leaves at most used_s unbacked whatever its code does.",
   "tried": "_coverFromReserve src/hub/MinterHub.sol:619-647. Handler: after every report or coverFromReserve that raised an exotic row's covered, every non-exotic bad is 0 and reserve >= what non-exotic marks hold (1161 exotic covers PASS; the mutant that skips the non-exotic loop FAILS). After a stranger's coverFromReserve, the core-brake reading max(0, unbacked - min(m, exoticUnbacked)) for m in {0, 30k, 1M} never falls, and stays equal while no mark stands. Supply identity token.totalSupply() == sum(outstanding+bad) <= sum used_s across hostile spokes (invariant_sums PASS), so what a row leaves unbacked is bounded by its used_s; restore's mint-back is at most covered_s (src/hub/MinterHub.sol:219) and keeps used_s."
  },
  {
   "property": "Callers and readers of the row state (src/ and script/)",
   "tried": "Writers: only MinterHub. Spoke callers: StableModule (_settle src/peg/StableModule.sol:831-838 and poke :321-326 restore then burn; _report :849), MorphoLender (_distribute src/morpho/MorphoLender.sol:423-439, reportLoss :391), FixedLoans (reportLoss :704, payReserve :680), house Ledger (reportLoss src/house/Ledger.sol:433, lossOf/usedOf :447-448, payReserve src/house/LedgerBase.sol:355). Readers: LedgerBase brake (src/LedgerBase.sol:224, :329-333). No script calls freeze, markLoss, cover, coverFromReserve or repayReserve. Observation: on a FROZEN row, MorphoLender._distribute's restore returns only the bad part (C2), so harvested imdUSD that would have paid the covered part goes to the reserve share and the Treasury, and covered stays owed until repayReserve or RELEASE_COVERED. Both destinations are protocol-held, so nothing is lost; StableModule._settle keeps the unspent imdUSD."
  },
  {
   "property": "Harness: test/scratch/HubRows.t.sol (source; run: FOUNDRY_INVARIANT_RUNS=500 FOUNDRY_INVARIANT_DEPTH=200 forge test --use <solar> --match-path test/scratch/HubRows.t.sol). Result: invariant_properties PASS, invariant_sums PASS (runs 500, calls 100000, reverts 0); testFuzz_C4 PASS (256); testFuzz_C5 PASS (256); test_obs_staleSetCapAfterUnfreeze PASS; test_obs_releaseCoversLaterLoss PASS. Mutants killed: UNFREEZE without covered, frozen restore mints, no reserve order.",
   "tried": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.38;\n\nimport {Test} from \"forge-std/Test.sol\";\nimport {ImdUSD} from \"../../src/ImdUSD.sol\";\nimport {MinterHub} from \"../../src/hub/MinterHub.sol\";\n\ncontract Stub {}\n\n/// A hostile spoke: does whatever the fuzzer says, in any order.\ncontract HSpoke {\n    MinterHub public hub;\n    ImdUSD public usd;\n\n    constructor(MinterHub h) {\n        hub = h;\n        usd = h.token();\n        usd.approve(address(h), type(uint256).max);\n    }\n\n    function mint(uint256 a) external { hub.mint(address(this), a); }\n    function burn(uint256 a) external { hub.burn(a); }\n    function report(uint256 a) external returns (uint256) { return hub.reportLoss(a); }\n    function restore(uint256 a) external returns (uint256) { return hub.restore(a); }\n    function pay(uint256 a) external { hub.payReserve(a); }\n    function cover(uint256 i, uint256 a) external { hub.cover(i, a); }\n    function repay(uint256 i, uint256 a) external { hub.repayReserve(i, a); }\n    function give(address to, uint256 a) external { usd.transfer(to, a); }\n    /// several hub acts in one transaction: report, restore, report again\n    function churn(uint256 a) external { hub.reportLoss(a); hub.restore(a); hub.reportLoss(a); }\n}\n\ncontract Stranger {\n    function approve(ImdUSD u, address h) external { u.approve(h, type(uint256).max); }\n    function cover(MinterHub h, uint256 i, uint256 a) external { h.cover(i, a); }\n    function repay(MinterHub h, uint256 i, uint256 a) external { h.repayReserve(i, a); }\n    function cfr(MinterHub h, uint256 i) external { h.coverFromReserve(i); }\n    function apply_(MinterHub h, uint8 k) external { h.applyPending(k); }\n}\n\ncontract HubBase is Test {\n    ImdUSD usd;\n    MinterHub hub;\n    address gov = address(0x5AFE);\n    address treasury = address(0x7EA5);\n    HSpoke[4] sp;\n    Stranger st;\n\n    function _deploy() internal {\n        vm.warp(1_800_000_000);\n        usd = new ImdUSD(address(this), 1_000_000e18, address(0));\n        hub = new MinterHub(usd, gov, treasury, 1_000_000e18, 300_000e18, 300_000e18, 2);\n        usd.wire(address(new Stub()), address(hub), address(new Stub()));\n        MinterHub.NewSpoke[] memory rows = new MinterHub.NewSpoke[](4);\n        for (uint256 i; i < 4; ++i) {\n            sp[i] = new HSpoke(hub);\n            // rows 0,1 non-exotic, 2,3 exotic\n            rows[i] = MinterHub.NewSpoke(address(sp[i]), i < 2 ? 300_000e18 : 140_000e18, i >= 2, 0);\n        }\n        vm.prank(gov);\n        hub.propose(abi.encode(uint8(0x10), rows));\n        vm.warp(block.timestamp + 48 hours);\n        hub.applyPending(0x10);\n        st = new Stranger();\n        st.approve(usd, address(hub));\n    }\n\n    function _row(uint256 i)\n        internal\n        view\n        returns (bool exotic, bool frozen, uint128 cap, uint128 out, uint128 bad, uint128 mark, uint128 cov)\n    {\n        (, exotic, frozen,, cap, out, bad, mark, cov) = hub.rows(i);\n    }\n}\n\n/// Handler: hostile spokes, a stranger, the Safe, time; checks P1-P4, C1, C2, C5 at every step.\ncontract Handler is HubBase {\n    bool public broken;\n    string public why;\n    uint256 public applies;\n    uint256 public unfreezes;\n    uint256 public frozenRestores;\n    uint256 public exoticCovers;\n\n    constructor() {\n        _deploy();\n        for (uint256 i; i < 4; ++i) {\n            sp[i].mint(50_000e18);\n            sp[i].pay(10_000e18);\n        }\n    }\n\n    function _fail(string memory w) internal {\n        if (!broken) {\n            broken = true;\n            why = w;\n        }\n    }\n\n    function _useds() internal view returns (uint256[4] memory u) {\n        for (uint256 i; i < 4; ++i) u[i] = hub.usedOf(i);\n    }\n\n    modifier noRaise() {\n        uint256[4] memory a = _useds();\n        _;\n        uint256[4] memory b = _useds();\n        for (uint256 i; i < 4; ++i) if (b[i] > a[i]) _fail(\"P1: used_s rose without a mint by s\");\n    }\n\n    // ---------------------------------------------------------------- spokes\n    function mint(uint256 i, uint256 a) external {\n        i %= 4;\n        uint256 r = hub.room(address(sp[i]));\n        a = _bound(a, 0, r + r / 5 + 1);\n        uint256[4] memory u0 = _useds();\n        try sp[i].mint(a) {\n            (,, uint128 cap,,,,) = _row(i);\n            if (hub.usedOf(i) > cap) _fail(\"P1: used > cap\");\n            if (hub.totalUsed() > hub.totalCap()) _fail(\"P1: totalUsed > totalCap\");\n            if (hub.exoticUsed() > hub.exoticCap()) _fail(\"P1: exoticUsed > exoticCap\");\n            uint256[4] memory u1 = _useds();\n            for (uint256 j; j < 4; ++j) if (j != i && u1[j] != u0[j]) _fail(\"P1: a mint moved another row\");\n            if (a > r) _fail(\"P1: minted past room()\");\n        } catch {}\n    }\n\n    function burn(uint256 i, uint256 a) external noRaise {\n        i %= 4;\n        (,,, uint128 out,,,) = _row(i);\n        uint256 bal = usd.balanceOf(address(sp[i]));\n        a = _bound(a, 0, out < bal ? out : bal);\n        try sp[i].burn(a) {} catch { _fail(\"P2: burn within outstanding and balance reverted\"); }\n    }\n\n    function report(uint256 i, uint256 a) external noRaise {\n        i %= 4;\n        a = _bound(a, 0, 200_000e18);\n        _coverCheck(i, true, a, 0);\n    }\n\n    function churn(uint256 i, uint256 a) external noRaise {\n        i %= 4;\n        a = _bound(a, 0, 100_000e18);\n        try sp[i].churn(a) {} catch {}\n    }\n\n    function restore(uint256 i, uint256 a) external noRaise {\n        i %= 4;\n        a = _bound(a, 0, 300_000e18);\n        (, bool fr,,,,,) = _row(i);\n        uint256 res0 = hub.reserve();\n        uint256 sup0 = usd.totalSupply();\n        uint256 tu0 = hub.totalUsed();\n        uint256 eu0 = hub.exoticUsed();\n        sp[i].restore(a);\n        if (fr) {\n            ++frozenRestores;\n            if (hub.reserve() != res0 || usd.totalSupply() != sup0) _fail(\"C2: frozen restore minted\");\n        }\n        if (hub.totalUsed() != tu0 || hub.exoticUsed() != eu0) _fail(\"restore moved a total\");\n    }\n\n    function pay(uint256 i, uint256 a) external noRaise {\n        i %= 4;\n        a = _bound(a, 0, usd.balanceOf(address(sp[i])));\n        sp[i].pay(a);\n    }\n\n    function spokeCover(uint256 i, uint256 j, uint256 a) external noRaise {\n        (i, j) = (i % 4, j % 4);\n        a = _bound(a, 0, usd.balanceOf(address(sp[i])));\n        sp[i].cover(j, a);\n    }\n\n    function spokeRepay(uint256 i, uint256 j, uint256 a) external noRaise {\n        (i, j) = (i % 4, j % 4);\n        a = _bound(a, 0, usd.balanceOf(address(sp[i])));\n        try sp[i].repay(j, a) {} catch {}\n    }\n\n    function fundStranger(uint256 i, uint256 a) external {\n        i %= 4;\n        a = _bound(a, 0, usd.balanceOf(address(sp[i])));\n        sp[i].give(address(st), a);\n    }\n\n    // ---------------------------------------------------------------- stranger\n    function strangerCfr(uint256 j) external noRaise {\n        j %= 4;\n        _coverCheck(j, false, 0, 0);\n    }\n\n    function strangerCover(uint256 j, uint256 a) external noRaise {\n        j %= 4;\n        a = _bound(a, 0, usd.balanceOf(address(st)));\n        st.cover(hub, j, a);\n    }\n\n    function strangerRepay(uint256 j, uint256 a) external noRaise {\n        j %= 4;\n        a = _bound(a, 0, usd.balanceOf(address(st)));\n        try st.repay(hub, j, a) {} catch {}\n    }\n\n    /// any matured proposal, applied by anyone, in front of anything\n    function applyAny(uint256 sel, uint256 i) external noRaise {\n        i %= 4;\n        uint8 k;\n        {\n            uint256 pk = hub.pendingKinds();\n            uint256 n;\n            for (uint256 b; b < 256; ++b) if (pk >> b & 1 == 1) ++n;\n            if (n == 0) return;\n            uint256 pick = sel % n;\n            for (uint256 b; b < 256; ++b) {\n                if (pk >> b & 1 == 1) {\n                    if (pick == 0) { k = uint8(b); break; }\n                    --pick;\n                }\n            }\n            (, uint256 e) = hub.pendingOf(k);\n            if (block.timestamp < e && sel % 3 != 0) vm.warp(e + (sel >> 8) % 2 days); // matured, in front of anything\n            if (k >= 0x20) i = k & 15;\n        }\n        (, uint256 eta) = hub.pendingOf(k);\n        (, bool fr,,, uint128 bad, uint128 mark, uint128 cov) = _row(i);\n        try st.apply_(hub, k) {\n            ++applies;\n            if (k >> 4 == 3) {\n                ++unfreezes;\n                if (fr && (bad != 0 || cov != 0 || mark != 0)) _fail(\"P3: UNFREEZE landed on an owed row\");\n            }\n        } catch {\n            // P3 second half: a matured UNFREEZE of a cleared row lands\n            if (k >> 4 == 3 && eta != 0 && block.timestamp >= eta && block.timestamp <= eta + 14 days && bad == 0 && cov == 0 && mark == 0) {\n                _fail(\"P3: matured UNFREEZE of a cleared row refused\");\n            }\n        }\n    }\n\n    // ---------------------------------------------------------------- the Safe\n    function freeze(uint256 i) external noRaise {\n        i %= 4;\n        vm.prank(gov);\n        hub.freeze(i);\n        (, uint256 e1) = hub.pendingOf(uint8(0x30 | i));\n        (, uint256 e2) = hub.pendingOf(uint8(0x60 | i));\n        if (e1 != 0 || e2 != 0) _fail(\"C5: freeze left an undo pending\");\n        (, bool fr,,,,,) = _row(i);\n        if (!fr) _fail(\"freeze\");\n    }\n\n    function markLoss(uint256 i, uint128 m) external noRaise {\n        i %= 4;\n        m = uint128(_bound(m, 0, 400_000e18));\n        vm.prank(gov);\n        hub.markLoss(i, m);\n        (, uint256 e1) = hub.pendingOf(uint8(0x50 | i));\n        (, uint256 e2) = hub.pendingOf(uint8(0x60 | i));\n        if (e1 != 0 || e2 != 0) _fail(\"C5: markLoss left an undo pending\");\n    }\n\n    function lowerCap(uint256 i, uint128 c) external noRaise {\n        i %= 4;\n        vm.prank(gov);\n        hub.lowerCap(i, uint128(_bound(c, 0, 300_000e18)));\n    }\n\n    function propose(uint256 sel, uint256 i, uint256 v) external noRaise {\n        i %= 4;\n        uint8 cls = [uint8(0x30), 0x60, 0x50, 0x20, 0x03][sel % 5];\n        bytes memory p;\n        if (cls == 0x30) p = abi.encode(uint8(0x30 | i));\n        else if (cls == 0x60) p = abi.encode(uint8(0x60 | i), uint128(_bound(v, 1, 400_000e18)));\n        else if (cls == 0x50) p = abi.encode(uint8(0x50 | i), uint128(_bound(v, 0, 400_000e18)));\n        else if (cls == 0x20) p = abi.encode(uint8(0x20 | i), uint128(_bound(v, 0, 400_000e18)));\n        else p = abi.encode(uint8(0x03), _bound(v, 0, 100_000e18));\n        vm.prank(gov);\n        try hub.propose(p) {} catch {}\n    }\n\n    function warp(uint256 dt) external {\n        dt = _bound(dt, 0, 3 days);\n        vm.warp(block.timestamp + dt);\n        vm.roll(block.number + (dt == 0 ? 0 : 1));\n    }\n\n    // ---------------------------------------------------------------- the reserve order (P4, C3)\n    function _coverCheck(uint256 i, bool byReport, uint256 a, uint256) internal {\n        (bool ex,,,,,,) = _row(i);\n        uint128[4] memory cov0;\n        for (uint256 j; j < 4; ++j) (,,,,,, cov0[j]) = _row(j);\n        uint256 res0 = hub.reserve();\n        uint256[3] memory b0 = _brakes();\n        bool marked = hub.marks() != 0;\n        if (byReport) sp[i].report(a);\n        else st.cfr(hub, i);\n        if (!byReport) {\n            uint256[3] memory b1 = _brakes();\n            for (uint256 k; k < 3; ++k) {\n                if (b1[k] < b0[k]) _fail(\"P4: a stranger's cover lowered the brake\");\n                if (!marked && b1[k] != b0[k]) _fail(\"P4: a stranger's cover moved the brake (no mark)\");\n            }\n        }\n        (,,,,,, uint128 covI) = _row(i);\n        if (ex && covI > cov0[i]) {\n            ++exoticCovers;\n            // every non-exotic bad was paid first and what non-exotic marks claim stays in the reserve\n            uint256 held;\n            for (uint256 j; j < 2; ++j) {\n                (,,, uint128 out, uint128 bad, uint128 mark,) = _row(j);\n                if (bad != 0) _fail(\"P4: exotic row covered while a non-exotic bad stands\");\n                uint256 m = mark > uint256(out) + bad ? uint256(out) + bad : mark;\n                held += m > bad ? m : bad;\n            }\n            if (hub.reserve() < held) _fail(\"P4: exotic cover spent what a non-exotic mark holds\");\n        }\n        // no other exotic row and no row not in order moves\n        for (uint256 j; j < 4; ++j) {\n            if (j == i) continue;\n            (bool exj,,,,,, uint128 cj) = _row(j);\n            if (cj != cov0[j] && (exj || !ex)) _fail(\"C3: a cover reached a row outside the reserve order\");\n        }\n        res0;\n    }\n\n    /// what the core brake reads of the hub: max(0, unbacked - min(margin, exoticUnbacked)), three margins\n    function _brakes() internal view returns (uint256[3] memory b) {\n        uint256 u = hub.unbacked();\n        uint256 e = hub.exoticUnbacked();\n        uint256[3] memory m = [uint256(0), 30_000e18, 1_000_000e18];\n        for (uint256 k; k < 3; ++k) {\n            uint256 f = m[k] < e ? m[k] : e;\n            b[k] = u > f ? u - f : 0;\n        }\n    }\n\n    // ---------------------------------------------------------------- views for invariants\n    function sums() external view returns (bool ok) {\n        uint256 tu;\n        uint256 eu;\n        uint256 tb;\n        uint256 tc;\n        uint256 mk;\n        uint256 ob;\n        for (uint256 j; j < 4; ++j) {\n            (bool ex,,, uint128 out, uint128 bad, uint128 mark, uint128 cov) = _row(j);\n            uint256 u = uint256(out) + bad + cov;\n            tu += u;\n            if (ex) eu += u;\n            tb += bad;\n            tc += cov;\n            if (mark != 0) ++mk;\n            ob += uint256(out) + bad;\n        }\n        ok = tu == hub.totalUsed() && eu == hub.exoticUsed() && tb == hub.totalBad() && tc == hub.totalCovered()\n            && mk == hub.marks() && usd.totalSupply() == ob;\n    }\n}\n\ncontract HubRowsInvariant is Test {\n    Handler h;\n\n    function setUp() public {\n        h = new Handler();\n        targetContract(address(h));\n    }\n\n    function invariant_properties() public view {\n        assertFalse(h.broken(), h.why());\n    }\n\n    /// supply == Σ(outstanding + bad): what the rows leave unbacked is bounded by their own used\n    function invariant_sums() public view {\n        assertTrue(h.sums());\n    }\n\n    function _acc(string memory k, uint256 v) internal returns (uint256 t) {\n        t = vm.envOr(k, uint256(0)) + v;\n        vm.setEnv(k, vm.toString(t));\n    }\n\n    function afterInvariant() public {\n        emit log_named_uint(\"cum applies\", _acc(\"HR_APPLIES\", h.applies()));\n        emit log_named_uint(\"cum unfreezes\", _acc(\"HR_UNFREEZES\", h.unfreezes()));\n        emit log_named_uint(\"cum frozenRestores\", _acc(\"HR_FR\", h.frozenRestores()));\n        emit log_named_uint(\"cum exoticCovers\", _acc(\"HR_EX\", h.exoticCovers()));\n        emit log_named_uint(\"cum runs\", _acc(\"HR_RUNS\", 1));\n    }\n}\n\n/// Directed tests of C4 and C5.\ncontract HubRowsUnit is HubBase {\n    function setUp() public {\n        _deploy();\n        // row 0 mints, pays reserve, loses: reserve covers part\n        sp[0].mint(100_000e18);\n        sp[0].pay(30_000e18);\n        sp[0].report(50_000e18); // 30k covered, 20k bad\n    }\n\n    /// C5: a release proposed, matured; the Safe freezes (or marks); a stranger's apply finds nothing.\n    function testFuzz_C5_freezeOrMarkDropsRelease(bool byMark, uint256 late) public {\n        vm.prank(gov);\n        hub.propose(abi.encode(uint8(0x60), uint128(30_000e18)));\n        vm.warp(block.timestamp + 48 hours + _bound(late, 0, 14 days));\n        vm.prank(gov);\n        if (byMark) hub.markLoss(0, 1);\n        else hub.freeze(0);\n        vm.expectRevert();\n        st.apply_(hub, 0x60);\n        (,,,,,, uint128 cov) = _row(0);\n        assertEq(cov, 30_000e18);\n    }\n\n    /// C4: a stranger repaying 1 wei (or any part short of all) in the 48 h only shortens the release.\n    function testFuzz_C4_repayShortensRelease(uint256 x, uint256 j) public {\n        sp[0].give(address(st), 40_000e18);\n        x = _bound(x, 1, 30_000e18 - 1);\n        vm.prank(gov);\n        hub.propose(abi.encode(uint8(0x60), uint128(30_000e18)));\n        st.repay(hub, 0, x);\n        st.cfr(hub, _bound(j, 0, 3)); // a stranger picks coverFromReserve's row\n        vm.warp(block.timestamp + 48 hours);\n        st.apply_(hub, 0x60);\n        (,,,,,, uint128 cov) = _row(0);\n        assertEq(cov, 0);\n    }\n\n    /// Observation: freeze(i) does not drop a pending SET_CAP raise of row i; it cannot apply while frozen, but after a\n    /// matured UNFREEZE a stranger applies the pre-freeze raise (inside its 14-day window).\n    function test_obs_staleSetCapAfterUnfreeze() public {\n        HSpoke s1 = sp[1];\n        vm.prank(gov);\n        hub.propose(abi.encode(uint8(0x21), uint128(310_000e18)));\n        vm.prank(gov);\n        hub.lowerTotalCap(1_000_000e18); // no-op\n        vm.prank(gov);\n        hub.freeze(1);\n        vm.prank(gov);\n        hub.propose(abi.encode(uint8(0x31)));\n        vm.warp(block.timestamp + 48 hours);\n        vm.expectRevert();\n        st.apply_(hub, 0x21); // frozen: refused, slot kept\n        st.apply_(hub, 0x31);\n        st.apply_(hub, 0x21);\n        (,, uint128 cap,,,,) = _row(1);\n        assertEq(cap, 310_000e18);\n        s1;\n    }\n\n    /// Observation: a pending RELEASE_COVERED is clamped at apply, so it releases covered loss reported after its proposal\n    /// (a new reportLoss drops nothing).\n    function test_obs_releaseCoversLaterLoss() public {\n        sp[0].give(address(st), 30_000e18);\n        vm.prank(gov);\n        hub.propose(abi.encode(uint8(0x60), uint128(30_000e18)));\n        st.repay(hub, 0, 30_000e18); // reviewed loss repaid by a stranger\n        sp[0].report(30_000e18); // a new loss, reserve-covered\n        (,,,,,, uint128 c0) = _row(0);\n        assertEq(c0, 30_000e18);\n        vm.warp(block.timestamp + 48 hours);\n        st.apply_(hub, 0x60);\n        (,,,,,, uint128 c1) = _row(0);\n        assertEq(c1, 0);\n    }\n}\n"
  }
 ],
 "notRun": [
  "The sheet has no [fork] or [data] claims, so no RPC was used: NOT RUN.",
  "solc 0.8.38 is not installed and `--use solar` is refused by forge 1.9.0. Tests were compiled with solar 0.3.1 given by path; the verifier's solc 0.8.38 build was not reproduced here."
 ]
}