{
 "item": "house-ledger-spoke",
 "commit": "ff1c192b3798542997f600091f2dc73ff05e4c40",
 "forge": "forge Version: 1.8.3 (cae51ad458f6abb64852b7709eb784352429825d); older than 1.9, so --use solar was not available; tests compiled with the installed solc 0.8.38 (via_ir) and run, only the one test file (--match-path).",
 "verdict": "holds",
 "findings": [],
 "claims": [
  {
   "id": "C1",
   "result": "holds",
   "evidence": "grep of src/ and script/: the only hub calls from the house are in Ledger/LedgerBase: hub.mint only in the borrow branch of _adjust (src/house/Ledger.sol:294, reached by open/adjust/execute); hub.burn in _collect (src/house/LedgerBase.sol:343: repay in _adjust, liquidatePosition) and _burnAgainst (src/house/Ledger.sol:456: cover, retire); hub.payReserve in _collect (LedgerBase.sol:355); hub.reportLoss in _report (Ledger.sol:433); lossOf/usedOf/indexOf/reserveShare are reads. No other house contract (Liquidator, Treasury, Backstop, Join, PositionNFT, Parameters*) calls the hub. Fuzz testFuzz_P1_P4_orderings counts any rise of hub.usedOf(houseRow) outside a borrow (brokeMint == 0 over 1000x24 random steps)."
  },
  {
   "id": "C2",
   "result": "holds",
   "evidence": "ImdUSD.isMinter is ledger|bridge|hub, each set once (src/ImdUSD.sol:101-138); the house deploy never calls usd.wire (script/house/deploy/StageHouse.sol:30 'The house is NOT usd.wire'd and has no hub row'); house SET_BRIDGE is refused (src/house/ParametersRules.sol:47-52, tested as kind 4). The house reaches core state only via hub.reportLoss (hub.unbacked/exoticUnbacked through bad_s), hub.payReserve (reserve it pays), the reserve burned by _coverFromReserve on its report (reserve it spends), and hub.mint/burn (total supply). Reasoned from code; covered by the fuzz for mint/burn."
  },
  {
   "id": "C3",
   "result": "holds",
   "evidence": "`forge inspect` storageLayout of src/house/Ledger.sol:Ledger and src/house/LedgerSettlement.sol:LedgerSettlement: identical (name, slot, offset, bytes): liquidator 0, _positions 1, _ilkList 2, _ilkIndex 3, ilkState 4, reserveBacked 5, totalBadDebt 6, worthlessSince 7, worthlessLast 8, bookedEdge 9, bookedTreasury 10; both inherit LedgerBase and add only immutables (settlement / ledger)."
  },
  {
   "id": "C4",
   "result": "not-checked",
   "evidence": "[fork] NOT RUN (needs the renounced StakedIMD at 0x9Efa934D9fAd4AE28c998a40195646b965a97247 on an Ethereum fork; no RPC used). From code: the hold acts on redeem (maxRedeem 0; test/house/fork/Mainnet.t.sol:279), not on transfer, and no house liquidation or repay path redeems sIMD: the only redeem is Join.unwrap (src/house/Join.sol:63) on a viaAsset withdrawal (README:1076, known). Liquidation pays out via Join.exit (safeTransfer) and _exitMarker try/catch, repay pulls imdUSD only; a caller-path liquidator that unwinds atomically reverts as a whole (Join.sol:40-46 NatSpec, README:739). No in-protocol liquidation or repay revert was found, so nothing worse than the known lines is shown."
  },
  {
   "id": "C5",
   "result": "holds",
   "evidence": "test_C5_coverAboveCollectableChargesOnlyCollectable: 10,000 at 50% for 365 days then a full bad-debt liquidation (bad > collectable()); a stranger's cover(ETH, max) is charged exactly collectable(), totalBadDebt -> 0, identity B6 (_checkB6) holds after, and the house lends and a later full repay lands. Fuzz also asserts payer charge <= collectable() on every random cover and retire (brokeCover == 0). Algebra: with B6 at rest, amount - min(amount, outstanding) <= bookedEdge + bookedTreasury, so _cancel never saturates and the identity is kept."
  }
 ],
 "holds": [
  {
   "property": "P1 (mints only by borrow via hub.mint; interest booked; B6 identity; no burn above outstanding)",
   "tried": "testFuzz_P1_P4_orderings: 1000 runs x 24 random steps over ETH (plain) and SIMD (edge type with sleeve): borrow (random rate/amount), full and partial repayFor, 0 / 1 h / 37 d time steps (several txs per block included), liquidatePosition at random price incl. reserve=true, reportLoss, stranger cover, Treasury.coverBadDebt, retire, lift, hub states (cap 0, freeze, Safe mark, total cap 0) and a stranger's hub.cover; after each step B6 (sum debt + sum bad + reserveBacked == usedOf(row) - lossOf.bad + bookedEdge + bookedTreasury, and supply == hub used); at the end every position repays in full (no OverBurn). Only reverts seen on funded repays were DustDebt (partial repay leaving < dust, by design)."
  },
  {
   "property": "P2 (cap 0, frozen, braked: repay+withdraw, liquidation, cover need no hub.mint)",
   "tried": "testFuzz_P2_exitsAtCapZeroFrozenBraked (1000 runs): unreported bad debt booked (brake on), hub state fuzzed over none/cap 0/frozen/Safe mark/total cap 0/others full, plus freeze and lowerCap(0); then a full repay + full withdrawal, a Liquidator.liquidate at a lower price, a stranger cover and reportLoss all succeed, B6 holds, and a new borrow reverts. hub.burn/payReserve/reportLoss read no cap or freeze (src/hub/MinterHub.sol:185-206,236)."
  },
  {
   "property": "P3 (non-redeemable; collateral leaves only by owner or liquidation; kinds 3,6,7 retired and 4,14,19 refused alone and in BATCH)",
   "tried": "test_P3_retiredAndNotHouseKindsRefusedAloneAndInBatch: each of 3,6,7,4,14,19 refused UnknownKind at propose alone and inside a BATCH as first or second item (ParametersRules.sol:47-52,130,158). Redeemable types refused at ADD_ILK (src/house/ParametersBase.sol:412); the house Ledger/LedgerSettlement have no redeem entry and no Redeemer is wired (Ledger.wire takes only the liquidator). Collateral exits: _adjust (owner/operator rights, holder-bound to owner), liquidatePosition (Liquidator only, which checks health). Note on wording, not a loss: two more exits exist by design and the property does not name them: _harvest moves pure-yield shares to the Treasury against debt (src/house/LedgerBase.sol:439) and writeOff seizes a custody that reads worthless() (src/house/LedgerSettlement.sol:190-224). Deployer: Ledger.wire(liquidator) is one-shot (Ledger.sol:107-112); the deploy rechecks ledger.liquidator() (script/house/deploy/StageCore.sol:109-113) and no debt (so no liquidation) exists before the house row is added by a 48 h hub proposal."
  },
  {
   "property": "P4 (lends nothing new while owing the hub or holding unreported bad debt)",
   "tried": "_checkBrake (src/house/LedgerBase.sol:383) reverts on lossOf.bad (bad_s + covered_s), the Safe's mark, or totalBadDebt, and runs before hub.mint in every borrow and in setRate's charged premium. Fuzz counts any borrow that succeeded while braked (brokeP4 == 0 over 1000x24 steps, incl. reserve-paid (covered) losses and stranger hub.cover); P2 test shows a borrow refused after report+cover while covered loss remains."
  },
  {
   "property": "P5 (lift adds no debt, changes no health)",
   "tried": "testFuzz_P5_liftAddsNoDebtChangesNoHealth (1000 runs): positions at 0.01 and 0.6, 0-400 days, a floor raise (SET_RISK) proposed and applied by a stranger after 48 h, then lift x2 and lift on the above-floor position in one block: debtOf, healthy(), ilkDebt and hub used unchanged, rate == floor, above-floor untouched, B6 holds, full repays in the next block land. Also lift in random order inside the P1 fuzz."
  }
 ],
 "notRun": [
  "C4 [fork]: sIMD one-block hold on a mainnet fork (StakedIMD 0x9Efa934D9fAd4AE28c998a40195646b965a97247): NOT RUN, no RPC used",
  "Earlier submissions ad4f75ab-8d61-4951-bc65-214951e52ac1 and 4d56c477-4266-4883-bf12-a7783bc8b0c8 (api.imd.fun) not fetched: no finding here to de-duplicate",
  "forge 1.9 --use solar: not available (forge 1.8.3 installed); tests ran with solc 0.8.38"
 ],
 "test": {
  "source": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.38;\n\nimport {HouseRig} from \"../utils/HouseRig.sol\";\nimport {LedgerBase} from \"../../../src/house/LedgerBase.sol\";\nimport {ParametersBase} from \"../../../src/house/ParametersBase.sol\";\nimport {Adjust} from \"../../../src/house/interfaces/IPositions.sol\";\n\n/// house-ledger-spoke goal item: property tests (scratch).\ncontract ScratchHouseSpokeTest is HouseRig {\n    uint256[] ids;\n    address[3] who;\n    uint256 brokeP4;\n    uint256 brokeMint;\n    uint256 brokeCover;\n    bytes4 lastErr;\n\n    function setUp() public {\n        _setUpHouse();\n        _approveCommonActors();\n        who = [alice, bob, carol];\n        address[5] memory fs = [alice, bob, carol, dave, stranger];\n        for (uint256 i; i < 5; ++i) _fund(fs[i], 5_000_000e18);\n    }\n\n    // ---------------------------------------------------------------- P5: lift\n    function _raiseFloor(bytes32 ilk, uint64 floor) internal {\n        ParametersBase.Risk memory r = params.storedRisk(ilk);\n        r.rateFloor = floor;\n        vm.prank(governor);\n        params.propose(abi.encode(uint8(1), ilk, r));\n        _skip(48 hours + 1);\n        vm.prank(stranger);\n        params.applyPending(uint8(1)); // a matured proposal applied by anyone\n    }\n\n    function testFuzz_P5_liftAddsNoDebtChangesNoHealth(uint64 floorSeed, uint32 dt, uint96 debtSeed) public {\n        uint256 debt = bound(debtSeed, 200e18, 12_000e18);\n        uint256 id = _open(alice, ETH, 10e18, debt, 0.01e18);\n        uint256 id2 = _open(bob, ETH, 10e18, 5_000e18, 0.6e18);\n        _skip(bound(dt, 0, 400 days));\n        uint64 floor = uint64(bound(floorSeed, 0.01e18 + 1, 0.5e18));\n        _raiseFloor(ETH, floor);\n        // several transactions in one block: lift, lift again, then other actions\n        uint256 d0 = ledger.debtOf(id);\n        (bool h0,) = ledger.healthy(id);\n        uint256 ilkD0 = ledger.ilkDebt(ETH);\n        uint256 used0 = hub.usedOf(houseRow);\n        vm.prank(stranger);\n        ledger.lift(id);\n        vm.prank(stranger);\n        ledger.lift(id); // idempotent\n        vm.prank(stranger);\n        ledger.lift(id2); // above the floor: no-op\n        assertEq(ledger.debtOf(id), d0, \"lift adds no debt\");\n        (bool h1,) = ledger.healthy(id);\n        assertEq(h1, h0, \"lift changes no health\");\n        assertLe(ledger.ilkDebt(ETH), ilkD0 + 1, \"type debt unchanged\");\n        assertEq(hub.usedOf(houseRow), used0, \"lift mints nothing\");\n        assertEq(ledger.rateOf(id), floor, \"raised to the floor\");\n        assertEq(ledger.rateOf(id2), 0.6e18, \"above floor untouched\");\n        _checkB6();\n        // consecutive block: full repay of both still lands (no burn over outstanding)\n        _skip(1 days);\n        vm.prank(alice);\n        ledger.repayFor(id, type(uint256).max);\n        vm.prank(bob);\n        ledger.repayFor(id2, type(uint256).max);\n        assertEq(ledger.debtOf(id) + ledger.debtOf(id2), 0);\n        _checkB6();\n    }\n\n    // ---------------------------------------------------------------- P3: kinds\n    function test_P3_retiredAndNotHouseKindsRefusedAloneAndInBatch() public {\n        uint8[6] memory ks = [3, 6, 7, 4, 14, 19];\n        ParametersBase.Risk memory r = params.storedRisk(ETH);\n        bytes memory ok = abi.encode(uint8(1), ETH, r);\n        for (uint256 i; i < ks.length; ++i) {\n            bytes memory p = ks[i] == 4 ? abi.encode(ks[i], address(this)) : abi.encode(ks[i], uint256(1));\n            vm.prank(governor);\n            vm.expectRevert(ParametersBase.UnknownKind.selector);\n            params.propose(p);\n            bytes[] memory items = new bytes[](2);\n            items[0] = ok;\n            items[1] = p;\n            vm.prank(governor);\n            vm.expectRevert(ParametersBase.UnknownKind.selector);\n            params.propose(abi.encode(uint8(17), items));\n            items[0] = p;\n            items[1] = ok;\n            vm.prank(governor);\n            vm.expectRevert(ParametersBase.UnknownKind.selector);\n            params.propose(abi.encode(uint8(17), items));\n        }\n    }\n\n    // ---------------------------------------------------------------- C5: cover / retire above collectable\n    function test_C5_coverAboveCollectableChargesOnlyCollectable() public {\n        uint256 id = _open(alice, ETH, 10e18, 10_000e18, 0.5e18);\n        _skip(365 days); // ~5000 of booked interest\n        uint256 bad = _bookBad(id, 1e18, dave); // price 1: everything is bad debt\n        assertGt(bad, ledger.collectable(), \"bad debt above the hub outstanding\");\n        uint256 coll = ledger.collectable();\n        uint256 b0 = usd.balanceOf(stranger);\n        vm.prank(stranger);\n        ledger.cover(ETH, type(uint256).max);\n        assertEq(b0 - usd.balanceOf(stranger), coll, \"payer charged only collectable\");\n        assertEq(ledger.totalBadDebt(), 0);\n        _checkB6();\n        // the house lends again (P4 released) and a full repay lands\n        uint256 id2 = _open(bob, ETH, 10e18, 2_000e18, 0.05e18);\n        _skip(30 days);\n        vm.prank(bob);\n        ledger.repayFor(id2, type(uint256).max);\n        _checkB6();\n    }\n\n    // ---------------------------------------------------------------- P2: cap 0, frozen, braked\n    function testFuzz_P2_exitsAtCapZeroFrozenBraked(uint8 state, uint32 dt) public {\n        uint256 ia = _open(alice, ETH, 10e18, 10_000e18, 0.05e18);\n        uint256 ib = _open(bob, ETH, 10e18, 10_000e18, 0.05e18);\n        uint256 ic = _open(carol, ETH, 10e18, 5_000e18, 0.05e18);\n        _skip(bound(dt, 0, 200 days));\n        _bookBad(ia, 1e18, dave); // braked: unreported bad debt\n        _hubState(state);\n        if (state % 3 == 0) {\n            vm.prank(governor);\n            hub.freeze(houseRow);\n        }\n        vm.prank(governor);\n        hub.lowerCap(houseRow, 0);\n        // a borrower repays and withdraws\n        vm.prank(carol);\n        ledger.adjust(ic, Adjust(-10e18, -type(int256).max, 0, 0, 0, false, 0, address(0)));\n        // a liquidation settles\n        ethFeed.set(1100e18);\n        vm.prank(dave);\n        liquidator.liquidate(ib);\n        // anyone covers, and the report lands\n        vm.prank(stranger);\n        ledger.cover(ETH, 1_000e18);\n        ledger.reportLoss(ETH);\n        _checkB6();\n        // still braked: no new debt\n        ethFeed.set(2000e18);\n        vm.prank(dave);\n        vm.expectRevert();\n        ledger.open(ETH, 7, Adjust(10e18, 1_000e18, 0.05e18, 0, 0, false, type(uint256).max, address(0)));\n    }\n\n    // ---------------------------------------------------------------- P1/P4: random orderings\n    function _used() internal view returns (uint256) {\n        return hub.usedOf(houseRow);\n    }\n\n    function _braked() internal view returns (bool) {\n        (uint256 b, uint256 m) = hub.lossOf(address(ledger));\n        return b != 0 || m != 0 || ledger.totalBadDebt() != 0;\n    }\n\n    function _step(uint256 r) internal {\n        uint256 a = r % 11;\n        address u = who[(r >> 8) % 3];\n        uint256 amt = bound(r >> 16, 100e18, 9_000e18);\n        uint256 u0 = _used();\n        bytes32 K = (r >> 120) % 2 == 0 ? ETH : SIMD;\n        if (a == 0 || a == 1) {\n            bool braked = _braked();\n            vm.prank(u);\n            try ledger.open(K, ids.length, Adjust(K == ETH ? int256(10e18) : int256(5000e18), int256(amt), uint64(0.01e18 + (r >> 40) % 0.3e18), 0, 0, false, type(uint256).max, address(0))) returns (uint256 id) {\n                ids.push(id);\n                if (braked) ++brokeP4;\n                if (_used() != u0 + amt) ++brokeMint;\n            } catch {}\n            return;\n        }\n        if (ids.length == 0) return;\n        uint256 id = ids[(r >> 24) % ids.length];\n        if (a == 2) {\n            vm.prank(u);\n            try ledger.repayFor(id, (r >> 50) % 2 == 0 ? type(uint256).max : amt) {} catch (bytes memory e) { if (bytes4(e) != LedgerBase.DustDebt.selector) { brokeCover += 1 << (8 * a); lastErr = bytes4(e); } }\n        } else if (a == 3) {\n            _skip((r >> 30) % 3 == 0 ? 0 : ((r >> 30) % 3 == 1 ? 1 hours : 37 days));\n        } else if (a == 4) {\n            if (ledger.debtOf(id) != 0) {\n                vm.prank(address(liquidator));\n                try ledger.liquidatePosition(id, ledger.ilkOf(id) == ETH ? bound(r >> 60, 1e18, 2500e18) : bound(r >> 60, 1e15, 6e18), dave, dave, (r >> 90) % 4 == 0) {} catch {}\n            }\n        } else if (a == 5) {\n            try ledger.reportLoss(K) {} catch { brokeCover += 1 << (8 * a); }\n        } else if (a == 6) {\n            uint256 c = ledger.collectable();\n            uint256 b0 = usd.balanceOf(stranger);\n            vm.prank(stranger);\n            try ledger.cover(K, amt) {} catch { brokeCover += 1 << (8 * a); }\n            if (b0 - usd.balanceOf(stranger) > c) brokeCover += 1 << (8 * a + 4);\n        } else if (a == 7) {\n            vm.prank(stranger);\n            ledger.lift(id);\n        } else if (a == 8) {\n            vm.prank(stranger);\n            usd.transfer(address(treasury), amt);\n            try treasury.coverBadDebt(K) {} catch { brokeCover += 1 << (8 * a); }\n        } else if (a == 9) {\n            uint256 c = ledger.collectable();\n            uint256 b0 = usd.balanceOf(stranger);\n            vm.prank(stranger);\n            try ledger.retire(amt) {} catch { brokeCover += 1 << (8 * a); }\n            if (b0 - usd.balanceOf(stranger) > c) brokeCover += 1 << (8 * a + 4);\n        } else {\n            _hubState(uint8((r >> 100) % 5));\n            vm.prank(stranger);\n            usd.approve(address(hub), type(uint256).max);\n            vm.prank(stranger);\n            hub.cover(houseRow, amt);\n        }\n        if (_used() > u0) ++brokeMint;\n    }\n\n    function testFuzz_P1_P4_orderings(uint256 seed) public {\n        for (uint256 i; i < 24; ++i) {\n            _step(uint256(keccak256(abi.encode(seed, i))));\n            _checkB6();\n        }\n        assertEq(brokeP4, 0, \"P4: lent while owing\");\n        assertEq(brokeMint, 0, \"P1: used rose outside a borrow\");\n        assertEq(lastErr, bytes4(0), \"err\");\n        assertEq(brokeCover, 0, \"P1/P2: a funded repay/cover/report reverted or overcharged\");\n        // every position repays in full (no burn over outstanding), then the identity still holds\n        for (uint256 i; i < ids.length; ++i) {\n            vm.prank(dave);\n            ledger.repayFor(ids[i], type(uint256).max);\n        }\n        _checkB6();\n    }\n}\n",
  "ran": "forge 1.8.3 (cae51ad), solc 0.8.38 via_ir, `forge test --offline --match-path test/house/unit/ScratchHouseSpoke.t.sol --fuzz-runs 1000` (no --use solar: forge 1.8.3 predates it), file placed in test/house/unit/ to reuse the repo's HouseRig (real Ledger, LedgerSettlement, Liquidator, Treasury, edge Backstop, MinterHub, ImdUSD; mock collateral/feeds).",
  "result": "[PASS] testFuzz_P1_P4_orderings(uint256) (runs: 1000); [PASS] testFuzz_P2_exitsAtCapZeroFrozenBraked(uint8,uint32) (runs: 1000); [PASS] testFuzz_P5_liftAddsNoDebtChangesNoHealth(uint64,uint32,uint96) (runs: 1000); [PASS] test_C5_coverAboveCollectableChargesOnlyCollectable(); [PASS] test_P3_retiredAndNotHouseKindsRefusedAloneAndInBatch(). Suite result: ok. 5 passed; 0 failed."
 }
}