{
 "item": "hub-reserve-low-water",
 "commit": "ff1c192b3798542997f600091f2dc73ff05e4c40",
 "forge": "forge Version: 1.9.0 (6056c584), --use solar; via_ir per foundry.toml",
 "verdict": "findings",
 "findings": [
  {
   "id": "F1",
   "severity": "low",
   "title": "reserveLow falls by GROSS outflow: a spoke's reportLoss->restore round trip leaves the reserve unchanged but lowers the mark by x each time, so one unfrozen spoke zeroes it in one transaction and locks RELEASE_RESERVE / SET_EXOTIC_CAP at no cost",
   "property": "P1 (judged at apply on the LOWEST reserve since it was proposed)",
   "claim": "C1 (the mark is stale-LOW, not the lowest reserve); README:607-611 'a matured apply may revert after a cover (re-propose)' is worse than written: re-proposing does not help because the spoke repeats the free round trip in every window",
   "files": [
    "src/hub/MinterHub.sol:197",
    "src/hub/MinterHub.sol:213",
    "src/hub/MinterHub.sol:232",
    "src/hub/MinterHub.sol:422",
    "src/hub/MinterHub.sol:645",
    "src/hub/MinterHub.sol:653"
   ],
   "sequence": "Reserve R=100k (paid). Row 0 (non-exotic, unfrozen) has outstanding x. Safe proposes RELEASE_RESERVE(amt <= R-x) -> reserveLow=R. In one tx the spoke loops k=(R-amt)/x+1 times: reportLoss(x) [reserve burns x, _fell(x)], restore(x) [covered x minted back into the reserve: inflow, never counted]. End state: reserve R, totalCovered 0, used_0 x (nothing changed) but reserveLow = R-k*x < amt. After 48 h anyone's applyPending(0x03) reverts BadConfig; same for SET_EXOTIC_CAP. Repeat before every re-propose.",
   "expected": "The reserve never stood below R-x >= amt since the propose, so RELEASE_RESERVE(amt) applies (control test with no round trips applies).",
   "actual": "applyPending(0x03) reverts BadConfig(): reserveLow = R - k*x while reserve() = R. The reserve-to-Treasury release and every exotic-cap raise are blocked for as long as the spoke keeps doing it (gas only); the Safe's only cure is freeze(row) (restore then mints nothing back, MinterHub.sol:224), after which each report burns real reserve bounded by outstanding.",
   "reachableAtDeploy": "Needs a spoke whose code can reportLoss and restore at will (a hostile spoke, in the threat model). Shipped spokes do not loop it for a stranger: StableModule.reportLoss is onlyGovernor (src/peg/StableModule.sol:406), poke reports only a real shortfall and restores only owned value (StableModule.sol:310-325); MorphoLender reports only Morpho value under principal (src/morpho/MorphoLender.sol:391) and restores from harvest (:427). An honest report-then-restore (stable leg blip) does it once: liveness only. No money is lost or mis-minted; the reserve is locked from release.",
   "fix": "Net the round trip: keep coverSince (sum of _coverFromReserve burns since the first reserve-kind propose, reset in _proposed, per row) and in restore, while a reserve kind is pending, raise reserveLow by min(fc, coverSince_s) and lower coverSince_s by it, so a report->restore that returns what it took leaves the mark where it was and fresh inflow still never counts. Or document that any unfrozen spoke can zero the mark for free and the remedy is freeze.",
   "test": {
    "source": "// 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 LwStub {}\n\n/// A spoke whose code is the attacker's (threat model: a hostile spoke).\ncontract LwSpoke {\n    MinterHub public hub;\n\n    constructor(MinterHub h) {\n        hub = h;\n        h.token().approve(address(h), type(uint256).max);\n    }\n\n    function mint(address to, uint256 a) external { hub.mint(to, a); }\n    function pay(uint256 a) external { hub.payReserve(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 burn(uint256 a) external { hub.burn(a); }\n    function give(address to, uint256 a) external { hub.token().transfer(to, a); }\n    function repay(uint256 i, uint256 a) external { hub.repayReserve(i, a); }\n\n    /// k round trips of its own outstanding: reportLoss(x) (the reserve burns x) then restore(x) (the hub mints x back).\n    function roundTrips(uint256 x, uint256 k) external {\n        for (uint256 j; j < k; ++j) {\n            hub.reportLoss(x);\n            hub.restore(x);\n        }\n    }\n\n    /// One transaction: park `a`, try both reserve applies, un-park as a covered loss.\n    function sandwich(uint256 a) external {\n        hub.mint(address(this), a);\n        hub.payReserve(a);\n        try hub.applyPending(0x03) {} catch {}\n        try hub.applyPending(0x01) {} catch {}\n        hub.reportLoss(a);\n    }\n}\n\ncontract LwBase is Test {\n    ImdUSD usd;\n    MinterHub hub;\n    LwSpoke plain; // row 0, non-exotic\n    LwSpoke exo; // row 1, exotic\n    address gov = address(0x5AFE);\n    address treasury = address(0x7EA5);\n    address ledger;\n    uint128 constant FLOOR = 100_000e18;\n    uint32 constant MULT = 3; // the deploy config's reserveMultiple (script/DeployConfig.sol:218)\n    uint256 constant R = 100_000e18;\n    uint128 constant ROOM = 200_000e18;\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, 2_000_000e18, FLOOR, FLOOR, MULT);\n        ledger = address(new LwStub());\n        usd.wire(ledger, address(hub), address(new LwStub()));\n        plain = new LwSpoke(hub);\n        exo = new LwSpoke(hub);\n        MinterHub.NewSpoke[] memory rows = new MinterHub.NewSpoke[](2);\n        rows[0] = MinterHub.NewSpoke(address(plain), ROOM, false, 0);\n        rows[1] = MinterHub.NewSpoke(address(exo), uint128(FLOOR), true, 0);\n        vm.prank(gov);\n        hub.propose(abi.encode(uint8(0x10), rows));\n        vm.warp(block.timestamp + 48 hours);\n        hub.applyPending(0x10);\n        vm.prank(ledger);\n        usd.mint(address(hub), R); // a real, paid reserve of R (a Ledger borrow to the hub)\n    }\n}\n\ncontract HubLowWaterTest is LwBase {\n    function setUp() public {\n        _deploy();\n    }\n\n    /// C3: hub.mint never names the hub.\n    function testFuzz_C3_mintToHubRefused(uint256 a) public {\n        a = bound(a, 0, ROOM);\n        vm.expectRevert(MinterHub.BadConfig.selector);\n        plain.mint(address(hub), a);\n    }\n\n    /// C2 (reserve units): a spoke's own mint parked BEFORE the propose lifts the reserve figure the apply reads by at most its\n    /// room; the exotic CEILING (floor + reserve x multiple) is lifted by that times reserveMultiple.\n    function testFuzz_C2_parkedBeforeProposeBoundedByRoom(uint256 x) public {\n        x = bound(x, 1e18, ROOM);\n        plain.mint(address(plain), x);\n        plain.pay(x); // parked before the propose\n        uint128 cap = uint128(FLOOR + (R + x) * MULT);\n        vm.prank(gov);\n        hub.propose(abi.encode(uint8(0x01), cap));\n        vm.warp(block.timestamp + 48 hours);\n        hub.applyPending(0x01);\n        plain.report(x); // un-park after the apply: the reserve burns it, covered_x stays on the row\n        uint256 honestCeiling = FLOOR + hub.reserve() * MULT;\n        uint256 lift = hub.exoticCap() - honestCeiling;\n        assertLe(lift, uint256(x) * MULT, \"reserve-unit bound (room x multiple)\");\n        assertEq(hub.usedOf(0), x, \"room spent stays spent\");\n    }\n\n    /// C2 as worded in the sheet / README:607 (\"lifts the exotic ceiling ... bounded by the spoke's room\"): FAILS for MULT > 1.\n    function testFuzz_C2_ceilingLiftAtMostRoom(uint256 x) public {\n        x = bound(x, 1e18, ROOM);\n        plain.mint(address(plain), x);\n        plain.pay(x);\n        vm.prank(gov);\n        hub.propose(abi.encode(uint8(0x01), uint128(FLOOR + (R + x) * MULT)));\n        vm.warp(block.timestamp + 48 hours);\n        hub.applyPending(0x01);\n        plain.report(x);\n        uint256 lift = hub.exoticCap() - (FLOOR + hub.reserve() * MULT);\n        assertLe(lift, x, \"exotic ceiling lifted past the spoke's room\");\n    }\n\n    /// P1 as worded: \"judged at apply on the LOWEST RESERVE since it was proposed\". A spoke's reportLoss -> restore round\n    /// trip leaves the reserve where it was (lowest R - x) but lowers the mark by x each time, so k trips in one transaction\n    /// zero it and a RELEASE_RESERVE that the reserve satisfied at every instant since the propose cannot apply. Repeatable\n    /// before every re-propose at no cost while the row is unfrozen.\n    function testFuzz_P1_roundTripsZeroTheMark(uint256 x, uint256 amt) public {\n        amt = bound(amt, 1e18, R / 2);\n        x = bound(x, 1e18, R - amt); // the reserve never goes under R - x >= amt\n        plain.mint(address(plain), x); // ordinary outstanding (lent out or held)\n        vm.prank(gov);\n        hub.propose(abi.encode(uint8(0x03), amt)); // release amt of the R the reserve holds\n        plain.roundTrips(x, (R - amt) / x + 1); // one transaction, any block in the 48 h\n        assertEq(hub.reserve(), R, \"reserve unchanged\");\n        assertEq(hub.totalCovered(), 0, \"nothing left covered\");\n        assertEq(hub.usedOf(0), x, \"row unchanged\");\n        vm.warp(block.timestamp + 48 hours);\n        hub.applyPending(0x03); // P1: lowest reserve since the propose was R - x >= amt\n        assertEq(usd.balanceOf(treasury), amt);\n    }\n\n    function testFuzz_P1_roundTrip_control(uint256 x, uint256 amt) public {\n        amt = bound(amt, 1e18, R / 2);\n        x = bound(x, 1e18, R - amt);\n        plain.mint(address(plain), x);\n        vm.prank(gov);\n        hub.propose(abi.encode(uint8(0x03), amt));\n        vm.warp(block.timestamp + 48 hours);\n        hub.applyPending(0x03);\n        assertEq(usd.balanceOf(treasury), amt);\n    }\n\n    /// The freeze is the Safe's remedy: once frozen, restore mints nothing back, so the round trip is no longer free.\n    function test_P1_freezeEndsFreeRoundTrips() public {\n        plain.mint(address(plain), 10_000e18);\n        vm.prank(gov);\n        hub.freeze(0);\n        plain.report(10_000e18);\n        assertEq(plain.restore(10_000e18), 0);\n        assertEq(hub.reserve(), R - 10_000e18);\n    }\n}\n",
    "ran": "forge test --use solar --match-path test/scratch/HubLowWater.t.sol (fuzz 256 runs, cache cleared, FOUNDRY_FUZZ_SEED=7)",
    "result": "[FAIL: BadConfig(); counterexample: args=[11574074074074 [1.157e13], 700000000000000000 [7e17]]] testFuzz_P1_roundTripsZeroTheMark(uint256,uint256); [PASS] testFuzz_P1_roundTrip_control(uint256,uint256) (runs: 256); [PASS] test_P1_freezeEndsFreeRoundTrips()"
   }
  },
  {
   "id": "F2",
   "severity": "info",
   "title": "C2 / README:608-609 wording: a spoke's own mint parked before the propose lifts the exotic CEILING by room x reserveMultiple (3x at the deploy config), not 'bounded by the spoke's room'",
   "property": "P1",
   "claim": "C2",
   "files": [
    "src/hub/MinterHub.sol:445",
    "src/hub/MinterHub.sol:670",
    "script/DeployConfig.sol:218",
    "README.md:608"
   ],
   "sequence": "Spoke (room x) mints x to itself, payReserve(x); Safe proposes SET_EXOTIC_CAP(floor+(R+x)*3); apply after 48 h; spoke reportLoss(x) burns its park (covered_s x stays on its row).",
   "expected": "README:608-609: 'A spoke's OWN mint ... still lifts the exotic ceiling, bounded by the spoke's room' -> lift <= x.",
   "actual": "exoticCap - (floor + reserve*3) = 3x (599997e18 > 199999e18 in the counterexample). In reserve units the lift is <= room (testFuzz_C2_parkedBeforeProposeBoundedByRoom passes); the exotic cap rises by reserveMultiple times that. Needs the Safe to propose the raise on the visible parked reserve.",
   "reachableAtDeploy": "Yes with a spoke that has room (reserveMultiple 3, script/DeployConfig.sol:218); hostile spoke + Safe propose.",
   "fix": "State the bound as room x reserveMultiple in the exotic cap (README:607 and the C2 wording), or count only paidIn/repayReserve (not a spoke's park) toward the ceiling.",
   "test": {
    "source": "// in test/scratch/HubLowWater.t.sol (LwBase / LwSpoke as in finding F1's source)\n    function testFuzz_C2_ceilingLiftAtMostRoom(uint256 x) public {\n        x = bound(x, 1e18, ROOM);\n        plain.mint(address(plain), x);\n        plain.pay(x);\n        vm.prank(gov);\n        hub.propose(abi.encode(uint8(0x01), uint128(FLOOR + (R + x) * MULT)));\n        vm.warp(block.timestamp + 48 hours);\n        hub.applyPending(0x01);\n        plain.report(x);\n        uint256 lift = hub.exoticCap() - (FLOOR + hub.reserve() * MULT);\n        assertLe(lift, x, \"exotic ceiling lifted past the spoke's room\");\n    }\n",
    "ran": "same run as F1",
    "result": "[FAIL: exotic ceiling lifted past the spoke's room: 599997000034722222222225 > 199999000011574074074075; counterexample: args=[11574074074074 [1.157e13]]] testFuzz_C2_ceilingLiftAtMostRoom(uint256); [PASS] testFuzz_C2_parkedBeforeProposeBoundedByRoom(uint256) (runs: 256)"
   }
  }
 ],
 "claims": [
  {
   "id": "C1",
   "result": "holds",
   "evidence": "Writers of reserveLow: _proposed MinterHub.sol:432 (only when pendingKinds & RESERVE_KINDS == 1<<kind) and _fell :655 (called from RELEASE_RESERVE apply :520 and the cover burn :645). Readers: _validateAtApply :424 and the public getter (no reader in src/ or script/; grep). Reserve outflows: the hub's balance leaves only by token.burn(address(this)) :644 and token.transfer(treasury) :519; every other hub burn/transfer names msg.sender (:191,:251) or pulls in (:240,:267); the hub grants no allowance, has no onFlashLoan / ERC-1271, and ImdUSD burn(from) is minter-only with callers that burn their own caller (Ledger.sol:278 actor, LedgerSettlement.sol:176 payer, Ledger.sol:412 Redeemer's msg.sender, ImdBridge.sol:520). Invariant (test/scratch/HubLowWaterInv.t.sol, 3 seeds x 500 runs x depth 100, every hub writer + propose/cancel/apply of 0x01/0x02/0x03/0x6i, freeze/mark/lowerExoticCap, warps, park-around-apply sandwiches, round trips, full propose->acts->apply cycles in both orders): hub.reserveLow == reserve at the first reserve-kind propose less every outflow, and never above the lowest reserve observed since that propose: PASS. Mutants (cover's _fell removed; every reserve-kind propose restarts the mark) both FAIL the invariant. No stale-HIGH mark found; the mark is stale-LOW by gross outflow (finding F1)."
  },
  {
   "id": "C2",
   "result": "refuted",
   "evidence": "In reserve units it holds: a park from before the propose lifts the figure the apply reads by <= the spoke's room and the room stays spent (testFuzz_C2_parkedBeforeProposeBoundedByRoom PASS, 256 runs); a park after the propose lifts nothing (invariant flag 32/64 never set). As worded ('lifts the exotic ceiling by at most its room') it fails: the ceiling rises by room x reserveMultiple (finding F2)."
  },
  {
   "id": "C3",
   "result": "holds",
   "evidence": "hub.mint reverts BadConfig for to == hub (MinterHub.sol:165; testFuzz_C3_mintToHubRefused PASS 256 runs). Ledger mints to `to` only after the borrower's debt is booked and line/brake checked (Ledger.sol:263-272), so a borrow to the hub is paid by that debt. Bridge credit/claim mints to `to` with no hub exclusion (ImdBridge.sol:590, :611): paid by a source-chain burn while the DVNs are honest; under compromised DVNs a forged credit to the hub is unpaid like any forged credit, bounded by the bridge's path limits (bridge item; not tested here). In the invariant every rise of the reserve came from payReserve, a paid transfer, repayReserve (<= covered_s) or an unfrozen restore (<= covered_s): flag 1 never set."
  },
  {
   "id": "C4",
   "result": "holds",
   "evidence": "One invariant over every route (checked after every hub call in test/scratch/HubLowWaterInv.t.sol, PASS): with S = reserve + totalCovered, (a) S == R_genesis + sum(payReserve) + sum(transfers in) - sum(RELEASE_RESERVE) - sum(RELEASE_COVERED applied) (cover moves reserve->covered, restore/repayReserve covered->reserve, 1:1); (b) while 0x01 or 0x03 is pending, reserveLow == reserve(t_first_propose) - sum(outflows since) <= min reserve since; (c) an applied SET_EXOTIC_CAP has cap <= floor + mult*min(reserveLow, reserve) and an applied RELEASE_RESERVE(a) has a <= min(...) and exoticCap <= floor + mult*(min(...) - a). Source: // 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\";\nimport {LwBase, LwSpoke} from \"./HubLowWater.t.sol\";\n\n/// Every writer of the reserve / covered / the two reserve kinds, in any order, with a model of the mark kept outside the hub.\ncontract LwHandler is Test {\n    MinterHub hub;\n    ImdUSD usd;\n    LwSpoke[2] sp;\n    address gov;\n    address ledger;\n    address stranger = address(0xBEEF);\n    uint256 constant RK = 1 << 1 | 1 << 3;\n\n    uint256 public ghostLow; // reserve at the first reserve-kind propose less every outflow since (the spec)\n    uint256 public lowest; // lowest reserve observed since that propose\n    int256 public ghostS; // reserve + totalCovered predicted from paid inflows and releases\n    uint256 public bad; // bit flags of broken properties\n    uint256 public applies01;\n    uint256 public applies03;\n    uint256 public proposes;\n    uint256 public trips;\n    uint256 last;\n\n    constructor(MinterHub h, ImdUSD u, LwSpoke a, LwSpoke b, address g, address l) {\n        (hub, usd, sp[0], sp[1], gov, ledger) = (h, u, a, b, g, l);\n        last = hub.reserve();\n        ghostS = int256(last);\n        vm.prank(stranger);\n        usd.approve(address(hub), type(uint256).max);\n    }\n\n    /// After every hub call: an outflow lowers the model mark BY it; track the lowest balance; an inflow must be a listed route.\n    function _obs(bool inflowAllowed, uint256 maxIn) internal {\n        uint256 r = hub.reserve();\n        if (r < last) {\n            uint256 out = last - r;\n            ghostLow = ghostLow > out ? ghostLow - out : 0;\n        } else if (r > last) {\n            if (!inflowAllowed || r - last > maxIn) bad |= 1; // P2: an unlisted rise\n        }\n        if (r < lowest) lowest = r;\n        last = r;\n        if (hub.pendingKinds() & RK != 0) {\n            if (hub.reserveLow() != ghostLow) bad |= 2; // C1: the mark is not the spec\n            if (ghostLow > lowest) bad |= 4; // stale-high: above the lowest reserve since the propose\n        }\n        if (int256(hub.reserve() + hub.totalCovered()) != ghostS) bad |= 8; // P2 identity\n    }\n\n    function mint(uint8 w, uint256 a) external {\n        LwSpoke s = sp[w % 2];\n        a = bound(a, 1, 50_000e18);\n        try s.mint(address(s), a) {} catch {}\n        _obs(false, 0);\n    }\n\n    function pay(uint8 w, uint256 a) external {\n        LwSpoke s = sp[w % 2];\n        uint256 bal = usd.balanceOf(address(s));\n        if (bal == 0) return;\n        a = bound(a, 1, bal);\n        s.pay(a);\n        ghostS += int256(a);\n        _obs(true, a);\n    }\n\n    function donate(uint256 a) external {\n        a = bound(a, 1, 50_000e18);\n        vm.prank(ledger);\n        usd.mint(stranger, a); // a paid borrow\n        vm.prank(stranger);\n        usd.transfer(address(hub), a);\n        ghostS += int256(a);\n        _obs(true, a);\n    }\n\n    function report(uint8 w, uint256 a) external {\n        a = bound(a, 0, 60_000e18);\n        sp[w % 2].report(a);\n        _obs(false, 0);\n    }\n\n    function restore(uint8 w, uint256 a) external {\n        uint256 i = w % 2;\n        (,,,,,,,, uint128 cov) = hub.rows(i);\n        a = bound(a, 0, 60_000e18);\n        sp[i].restore(a);\n        (,, bool frozen,,,,,,) = hub.rows(i);\n        _obs(!frozen, cov);\n    }\n\n    function roundTrip(uint8 w, uint256 a, uint8 k) external {\n        uint256 i = w % 2;\n        a = bound(a, 1, 60_000e18);\n        k = uint8(bound(k, 1, 8));\n        for (uint256 j; j < k; ++j) {\n            sp[i].report(a);\n            _obs(false, 0);\n            (,,,,,,,, uint128 cov) = hub.rows(i);\n            (,, bool frozen,,,,,,) = hub.rows(i);\n            sp[i].restore(a);\n            _obs(!frozen, cov);\n        }\n        ++trips;\n    }\n\n    function burn(uint8 w, uint256 a) external {\n        LwSpoke s = sp[w % 2];\n        try s.burn(bound(a, 0, usd.balanceOf(address(s)))) {} catch {}\n        _obs(false, 0);\n    }\n\n    function repay(uint8 w, uint256 a) external {\n        a = bound(a, 1, 60_000e18);\n        vm.prank(ledger);\n        usd.mint(stranger, a);\n        (,,,,,,,, uint128 cov) = hub.rows(w % 2);\n        vm.prank(stranger);\n        uint256 paid = hub.repayReserve(w % 2, a);\n        if (paid > cov) bad |= 16;\n        _obs(true, paid);\n    }\n\n    function coverFromReserve(uint8 w) external {\n        hub.coverFromReserve(w % 2);\n        _obs(false, 0);\n    }\n\n    function coverByStranger(uint8 w, uint256 a) external {\n        a = bound(a, 1, 60_000e18);\n        vm.prank(ledger);\n        usd.mint(stranger, a);\n        vm.prank(stranger);\n        hub.cover(w % 2, a);\n        _obs(false, 0);\n    }\n\n    function propose(uint8 sel, uint256 v) external {\n        bool first = hub.pendingKinds() & RK == 0;\n        uint256 r = hub.reserve();\n        bytes memory p;\n        uint8 kind;\n        sel = sel % 6;\n        if (sel == 0 || sel == 1) {\n            kind = 0x01;\n            p = abi.encode(kind, uint128(bound(v, 100_000e18, hub.exoticFloor() + r * hub.reserveMultiple())));\n        } else if (sel == 2 || sel == 3) {\n            kind = 0x03;\n            p = abi.encode(kind, bound(v, 0, r));\n        } else if (sel == 4) {\n            kind = 0x02;\n            p = abi.encode(kind, uint128(bound(v, 50_000e18, 150_000e18)), uint32(bound(v >> 128, 1, 4)));\n        } else {\n            kind = uint8(0x60 | (v % 2));\n            p = abi.encode(kind, uint128(bound(v >> 8, 1, 60_000e18)));\n        }\n        vm.prank(gov);\n        try hub.propose(p) {\n            ++proposes;\n            if (first && (kind == 0x01 || kind == 0x03)) {\n                ghostLow = r;\n                lowest = r;\n            }\n        } catch {}\n        _obs(false, 0);\n    }\n\n    function cancel(uint8 sel) external {\n        uint8[4] memory ks = [uint8(0x01), 0x03, 0x02, uint8(0x60)];\n        vm.prank(gov);\n        hub.cancel(ks[sel % 4]);\n        _obs(false, 0);\n    }\n\n    function tighten(uint8 sel, uint256 v) external {\n        vm.startPrank(gov);\n        if (sel % 8 < 4) hub.lowerExoticCap(uint128(v));\n        else if (sel % 8 < 7) hub.freeze(v % 2);\n        else hub.markLoss(v % 2, uint128(bound(v, 1, 10_000e18)));\n        vm.stopPrank();\n        _obs(false, 0);\n    }\n\n    function apply_(uint8 sel, bool warp) external {\n        uint8[4] memory ks = [uint8(0x01), 0x03, 0x02, uint8(0x60)];\n        uint8 kind = ks[sel % 4];\n        (bytes memory p, uint256 eta) = hub.pendingOf(kind);\n        if (eta == 0) return;\n        if (warp && block.timestamp < eta) vm.warp(eta);\n        uint256 fig = ghostLow < hub.reserve() ? ghostLow : hub.reserve();\n        uint256 c0 = hub.totalCovered();\n        try hub.applyPending(kind) {\n            if (kind == 0x01) {\n                ++applies01;\n                if (hub.exoticCap() > hub.exoticFloor() + fig * hub.reserveMultiple()) bad |= 32;\n            } else if (kind == 0x03) {\n                ++applies03;\n                (, uint256 amt) = abi.decode(p, (uint8, uint256));\n                if (amt > fig || hub.exoticCap() > hub.exoticFloor() + (fig - amt) * hub.reserveMultiple()) bad |= 64;\n                ghostS -= int256(amt);\n            } else if (kind == 0x60) {\n                ghostS -= int256(c0 - hub.totalCovered());\n            }\n        } catch {}\n        _obs(false, 0);\n    }\n\n    /// Park a fresh mint around both applies in one sequence (the wave-7 L1 shape), then un-park it as a covered loss.\n    function sandwich(uint8 w, uint256 a) external {\n        uint256 i = w % 2;\n        a = bound(a, 1, 50_000e18);\n        try sp[i].mint(address(sp[i]), a) {} catch { return; }\n        _obs(false, 0);\n        sp[i].pay(a);\n        ghostS += int256(a);\n        _obs(true, a);\n        this.apply_(1, true);\n        this.apply_(0, true);\n        sp[i].report(a);\n        _obs(false, 0);\n    }\n\n    /// A whole window: both reserve kinds proposed (either first), stranger / spoke acts between, both applied (either first),\n    /// with acts between and in the apply block.\n    function cycle(uint256 seed) external {\n        if (hub.marks() != 0 || hub.totalBad() != 0) {\n            for (uint256 i; i < 2; ++i) {\n                (,,,,,, uint128 b,,) = hub.rows(i);\n                if (b != 0) try this.coverByStranger(uint8(i), b) {} catch {}\n            }\n        }\n        bool exFirst = seed & 1 == 0;\n        this.propose(exFirst ? 0 : 2, seed >> 8);\n        _act(seed >> 40);\n        this.propose(exFirst ? 2 : 0, seed >> 16);\n        _act(seed >> 60);\n        vm.warp(block.timestamp + 48 hours + (seed >> 80) % 3 days);\n        _act(seed >> 100);\n        bool relFirst = (seed >> 1) & 1 == 0;\n        this.apply_(relFirst ? 1 : 0, true);\n        _act(seed >> 120);\n        this.apply_(relFirst ? 0 : 1, true);\n        _act(seed >> 140);\n    }\n\n    function _act(uint256 s) internal {\n        uint256 op = s % 9;\n        uint8 w = uint8(s >> 4);\n        uint256 a = s >> 8;\n        bytes memory c;\n        if (op == 0) c = abi.encodeCall(this.mint, (w, a));\n        else if (op == 1) c = abi.encodeCall(this.pay, (w, a));\n        else if (op == 2) c = abi.encodeCall(this.donate, (a));\n        else if (op == 3) c = abi.encodeCall(this.report, (w, a));\n        else if (op == 4) c = abi.encodeCall(this.restore, (w, a));\n        else if (op == 5) c = abi.encodeCall(this.roundTrip, (w, a, uint8(s >> 12)));\n        else if (op == 6) c = abi.encodeCall(this.sandwich, (w, a));\n        else if (op == 7) c = abi.encodeCall(this.repay, (w, a));\n        else c = abi.encodeCall(this.coverFromReserve, (w));\n        (bool ok,) = address(this).call(c);\n        ok;\n    }\n\n    function warp(uint256 dt) external {\n        vm.warp(block.timestamp + bound(dt, 1, 20 days));\n    }\n}\n\ncontract HubLowWaterInvariantTest is LwBase {\n    LwHandler h;\n\n    function setUp() public {\n        _deploy();\n        h = new LwHandler(hub, usd, plain, exo, gov, ledger);\n        targetContract(address(h));\n    }\n\n    function invariant_lowWaterAndReserveIdentity() public view {\n        assertEq(h.bad() & 1, 0, \"P2: reserve rose by an unlisted route\");\n        assertEq(h.bad() & 2, 0, \"C1: reserveLow != reserve at propose less outflows\");\n        assertEq(h.bad() & 4, 0, \"C1: stale-high mark\");\n        assertEq(h.bad() & 8, 0, \"P2: reserve + totalCovered off the paid inflows\");\n        assertEq(h.bad() & 16, 0, \"repay over covered\");\n        assertEq(h.bad() & 32, 0, \"P1: SET_EXOTIC_CAP over the low-water ceiling\");\n        assertEq(h.bad() & 64, 0, \"P1: RELEASE_RESERVE over the low-water mark\");\n    }\n\n    function afterInvariant() public {\n        emit log_named_uint(\"applies01\", h.applies01());\n        emit log_named_uint(\"applies03\", h.applies03());\n        emit log_named_uint(\"proposes\", h.proposes());\n        emit log_named_uint(\"roundTrips\", h.trips());\n    }\n}\n"
  }
 ],
 "holds": [
  {
   "property": "P1 (safety direction: no reserve kind applies on imdUSD parked after its propose, in any order)",
   "tried": "Invariant above: 1500 runs x 100 calls, proposals of 0x01/0x03 in either order, second kind proposed while the first pending, cancels and re-proposes, expired slots, applies by any account at maturity or 3 days later in either order, park-mint-around-both-applies sandwich (wave-7 L1 shape), covers and reportLoss/restore between, stranger covers/repays/donations, freezes, marks, lowerExoticCap, rule changes. Every successful apply was within the low-water figure; the mark never exceeded the lowest reserve since propose. Fails only as worded ('lowest reserve'): F1."
  },
  {
   "property": "P2 (reserve rises only by payReserve, repayReserve, restore mint-back <= covered_s never on a frozen row, or a transfer in; reserve + totalCovered rises only by payReserve or a transfer in)",
   "tried": "Invariant flags 1 (any reserve rise checked against the call's route and its covered_s bound, frozen restore allowed 0) and 8 (identity (a) above) never set over 1500 runs x 100 calls; test_P1_freezeEndsFreeRoundTrips: frozen restore returns 0 and mints nothing; hub.mint to hub refused (C3)."
  }
 ],
 "notRun": [
  "No [fork]/[data] claims in this sheet: NOT RUN (no RPC used).",
  "Bridge forged inbound to the hub under compromised DVNs (C3 tail): reasoned from ImdBridge.sol:590/611, no test.",
  "Deployer powers: MinterHub has no owner, wirer or seal (MinterHub.sol:24); ImdUSD.wire is the deployer's one-shot (ImdUSD.sol:101), not exercised here."
 ]
}