{
 "item": "x-supply-identity",
 "commit": "ff1c192b3798542997f600091f2dc73ff05e4c40",
 "forge": "forge 1.8.3 (pre-1.9); tests compiled with solc 0.8.30 on a pragma-only port because 0.8.38 is not installed here; --use solar not available in 1.8.3",
 "verdict": "holds",
 "findings": [],
 "claims": [
  {
   "id": "C1",
   "result": "holds",
   "evidence": "grep of _mint/.mint( in src/ (non-vendored). imdUSD mint sites: ImdUSD.sol:144 (mint, gated by isMinter = ledger|hub|bridge, ImdUSD.sol:136-139) and :281 (flashLoan, burned at :286 in the same call). Callers of token.mint: Ledger.sol:272 (borrow), LedgerBase.sol:292,298 (_mintInterest -> SavingsVault/Treasury; also reached from LedgerSettlement.sol:245 rate-change premium), MinterHub.sol:179 (mint) and :232 (restore mint-back, fc <= covered_s, 0 while frozen), ImdBridge.sol:523 (send fee re-mint to Treasury), :590 (lzReceive), :611 (claim). Every spoke reaches supply only through hub.mint/burn/restore: StableModule.sol:221,325,835; FixedLoans.sol:268; MorphoLender.sol:158,425-428; Migrator.sol:52; house/Ledger.sol:294 (house interest is booked, never minted: house/LedgerBase.sol:318-326). Only other direct imdUSD mint call: src/house/peg/PegHook.sol:494 IMintBurn(stable).mint, in src/house/peg which README:409 lists as not deployed on day 1; it is not a minter (ImdUSD.isMinter) so the call would revert. No other mint route exists; the list in P3 is complete."
  },
  {
   "id": "C2",
   "result": "holds",
   "evidence": "RAN locally: forge 1.8.3 (older than 1.9: no --use solar; solc 0.8.38 not installed). Ran on a scratch copy of the commit with ONLY `pragma solidity 0.8.38` -> 0.8.30 and foundry.toml solc 0.8.30 (installed), via_ir/optimizer unchanged. No other source edited. (a) test/invariant/HubInvariants.t.sol (core Ledger + hub with 4 rows incl. a hostile spoke and the real Migrator, flash borrower, Safe acts, stranger applies; invariant_I3_supplyIdentity = P1 without bridge): PASS runs 128, calls 8192. (b) test/invariant/BridgeInvariants.t.sol (two real deploys, core+hub+ImdBridge on a mock endpoint, fee path exercised): invariant_supplyPerChain (supply == ledger terms + received - sent) and invariant_supplyAcrossChains PASS runs 128, calls 8192. (c) own scratch fuzz testFuzz_P1_P2_anyOrder: core Ledger + hub (mod non-exotic, house/evil exotic, Migrator) over 60-step random orderings of spoke mint/burn/report/payReserve/restore, coverFromReserve, repayReserve, cover by anyone, flash loans, RELEASE_COVERED proposed and applied by a stranger, freeze, warps up to 3 days, odd wei tails; P1 asserted (after ledger.accrue) after every step: PASS 500 runs. Morpho lender, stable module, fixed loans and house by case from code: they move supply only through hub.mint/burn/restore whose counters move by the exact token amount."
  },
  {
   "id": "C3",
   "result": "holds",
   "evidence": "Code: coverFromReserve/_coverFromReserve (MinterHub.sol:619-648) moves bad->covered by p and burns p from the hub's own balance: supply -p, (used-covered) -p. restore (MinterHub.sol:213-233) moves covered->outstanding by fc and mints fc: +fc both sides. repayReserve and RELEASE_COVERED (_uncover) drop covered and used together with no supply change; cover() burns the payer's bad with used. The exotic branch covers NON-exotic rows' bad first (:628-636) by the same _toCovered. Test test_C3_coverRestoreRelease (scratch): non-exotic report covered from reserve, partial dry reserve, repayReserve refill, exotic report covering the non-exotic row's bad, restore minting back (asserted supply rises), frozen-row restore minting nothing (asserted), RELEASE_COVERED applied by a stranger; P1 after each step: PASS."
  },
  {
   "id": "C4",
   "result": "refuted",
   "evidence": "The hub's counters move by exactly the token amount of each hub mint/burn/restore (MinterHub.sol:174-179,187-191,224-232); no division or rounding exists in the hub, and the hub never reads totalSupply. A spoke's own rounding (e.g. MorphoLender share math, StableModule decimals) can only change WHAT it asks the hub to mint/burn, never make sum(used - covered) differ from the hub's share of supply. Fuzz with odd wei tails (scratch testFuzz_P1_P2_anyOrder, 500 runs) kept P1 exact (assertEq, zero drift). sum(used) itself differs from supply by exactly totalCovered by design (sheet P1), not by rounding."
  }
 ],
 "holds": [
  {
   "property": "P1",
   "tried": "Exact equality, after accrue, over: HubInvariants (128x64 calls incl. hostile spoke reentry from flash callbacks), BridgeInvariants per-chain and cross-chain identity with real deploys (128x64), own 60-step any-order fuzz over every hub route and time (500 runs) and a by-case C3 sequence. Code check of the core side: borrow (Ledger.sol:255-272) adds amount and premium to s.debt and mints the same; repay burns what it subtracts (:274-278); _accrue adds ceil interest to s.debt and _mintInterest mints exactly amount (savings + treasury split sums to amount, LedgerBase.sol:274-300); harvest moves credit s.debt -> reserveBacked (LedgerBase.sol:399-400); liquidation subtracts debt-left, adds bad, burns repaid = debt-left-bad (LedgerSettlement.sol:162-176); redemption subtracts taken per position and the Redeemer burns sum(taken) once (Redeemer.sol:121-133); cover/retire burn what they subtract (Ledger.sol:354-368). Bridge: send burns amount, re-mints amount-delivered to Treasury, sent += delivered (ImdBridge.sol:519-524); receipt/claim mint exactly what received counts (:588-590, :610-611); queued claims are not counted until claimed."
  },
  {
   "property": "P2",
   "tried": "Scratch fuzz asserts, around every flash loan (random size up to maxFlashLoan), totalSupply, totalUsed, totalCovered and totalBad unchanged: PASS 500 runs. HubInvariants exercises flash loans with hostile spoke calls inside the callback (okFlash>2 in test_handlerActionsSucceed): PASS. Code: flashLoan mints value and burns value+fee(0) from the receiver in the same call (ImdUSD.sol:271-288); the hub reads only its own counters and balanceOf(hub) (MinterHub.sol:38-40); imdUSD flash-minted and parked in the hub can only be burned (coverFromReserve) or sent to the Treasury, so it is the receiver's donation and the loan's end-burn needs the receiver's own imdUSD."
  },
  {
   "property": "P3",
   "tried": "Complete grep of mint call sites (C1); isMinter gate ImdUSD.sol:136-139 with three fixed minters (wire once, setBridge once via timelocked Parameters, checkBridge); hub mint refuses minting into itself (MinterHub.sol:165) and ADD_SPOKE refuses token, hub, ledger and bridge as spokes (re-checked at apply); HubInvariants invariant_I7_minterSet PASS. Restore mint-back <= covered_s and 0 for a frozen row: asserted in test_C3_coverRestoreRelease."
  }
 ],
 "notRun": [
  "Fetching earlier findings from https://api.imd.fun/jobs/<id>/submissions: NOT RUN (time); this result reports no finding so nothing duplicates.",
  "No [fork]/[data] claim in this sheet; no RPC used.",
  "Real StableModule / FixedLoans / MorphoLender / house Ledger were not wired into the scratch P1 fuzz (mock TestSpoke rows stand in); argued by case from their hub call sites listed in C1.",
  "test/invariant/Invariants.t.sol invariant_supplyEquation not run (compile time)."
 ],
 "tests": [
  {
   "name": "test/scratch/SupplyIdentity.t.sol (scratch, not submitted)",
   "source": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.30;\n\nimport {HubBase} from \"../utils/HubBase.sol\";\nimport {MinterHub} from \"../../src/hub/MinterHub.sol\";\nimport {IERC3156FlashBorrower} from \"@openzeppelin/contracts/interfaces/IERC3156FlashBorrower.sol\";\n\ncontract FlashR is IERC3156FlashBorrower {\n    function onFlashLoan(address, address t, uint256 v, uint256, bytes calldata d) external returns (bytes32) {\n        (address target, bytes memory data) = abi.decode(d, (address, bytes));\n        if (target != address(0)) { (bool ok,) = target.call(data); ok; }\n        MinterHub(msg.sender == t ? address(0) : address(0)); // no-op\n        (bool a,) = t.call(abi.encodeWithSignature(\"approve(address,uint256)\", t, v)); a;\n        return keccak256(\"ERC3156FlashBorrower.onFlashLoan\");\n    }\n}\n\n/// x-supply-identity: P1 (core + hub, every hub route incl. exotic cover of other rows, restore, release-covered, freeze)\n/// and P2 (flash mints move no hub counter, supply back at the tx end), fuzzed over orderings, odd amounts and time.\ncontract SupplyIdentityScratch is HubBase {\n    FlashR fr;\n    function setUp() public {\n        _setUpHub();\n        fr = new FlashR();\n        address[3] memory us = [alice, bob, carol];\n        for (uint256 i; i < 3; ++i) { vm.prank(us[i]); usd.approve(address(hub), type(uint256).max); }\n        _borrow(alice, 100e18, 50_000e18);\n    }\n\n    function _ids() internal view returns (uint256 u, uint256 c, uint256 b) { return (hub.totalUsed(), hub.totalCovered(), hub.totalBad()); }\n\n    function _spoke(uint256 r) internal view returns (address) { return r % 3 == 0 ? address(mod) : r % 3 == 1 ? address(house) : address(evil); }\n\n    function testFuzz_P1_P2_anyOrder(uint256 seed) public {\n        for (uint256 k; k < 60; ++k) {\n            uint256 r = uint256(keccak256(abi.encode(seed, k)));\n            uint256 x = (r >> 16) % 50_000e18 + (r >> 200) % 7; // odd wei tails (C4: rounding)\n            address sp = _spoke(r >> 8);\n            uint256 act = r % 14;\n            if (act == 0) { (bool o,) = sp.call(abi.encodeWithSignature(\"mint(address,uint256)\", bob, x)); o; }\n            else if (act == 1) { (bool o,) = sp.call(abi.encodeWithSignature(\"mint(address,uint256)\", sp, x)); o; }\n            else if (act == 2) { (bool o,) = sp.call(abi.encodeWithSignature(\"burn(uint256)\", x % (usd.balanceOf(sp) + 1))); o; }\n            else if (act == 3) { (bool o,) = sp.call(abi.encodeWithSignature(\"report(uint256)\", x)); o; }\n            else if (act == 4) { vm.prank(stranger); try hub.coverFromReserve((r >> 30) % 4) {} catch {} }\n            else if (act == 5) { (bool o,) = sp.call(abi.encodeWithSignature(\"pay(uint256)\", x % (usd.balanceOf(sp) + 1))); o; }\n            else if (act == 6) { (bool o,) = sp.call(abi.encodeWithSignature(\"restore(uint256)\", x)); o; }\n            else if (act == 7) { vm.prank(bob); try hub.repayReserve((r >> 30) % 4, x % (usd.balanceOf(bob) + 1)) {} catch {} }\n            else if (act == 8) { vm.prank(bob); try hub.cover((r >> 30) % 4, x % (usd.balanceOf(bob) + 1)) {} catch {} }\n            else if (act == 9) {\n                (uint256 u0, uint256 c0, uint256 b0) = _ids();\n                uint256 s0 = usd.totalSupply();\n                // inside the loan: a spoke mint+burn round trip and a Ledger repay with flash-minted imdUSD are left out; P2 is the loan itself\n                bytes memory d = abi.encode(address(0), \"\");\n                try usd.flashLoan(fr, address(usd), x % (usd.maxFlashLoan(address(usd)) + 1), d) {} catch {}\n                (uint256 u1, uint256 c1, uint256 b1) = _ids();\n                assertEq(usd.totalSupply(), s0, \"P2 supply\");\n                assertTrue(u0 == u1 && c0 == c1 && b0 == b1, \"P2 hub counters\");\n            } else if (act == 10) { _pass((r >> 40) % 3 days + 1); }\n            else if (act == 11) {\n                uint256 i = (r >> 30) % 4;\n                vm.prank(governor);\n                try hub.propose(abi.encode(uint8(0x60 | i), uint128(x))) {\n                    _pass(48 hours + 1);\n                    vm.prank(stranger); try hub.applyPending(uint8(0x60 | i)) {} catch {}\n                } catch {}\n            } else if (act == 12) { vm.prank(governor); hub.freeze((r >> 30) % 4); }\n            else { // core: repay part of alice's debt, or borrow more\n                vm.prank(bob); try usd.transfer(alice, x % (usd.balanceOf(bob) + 1)) {} catch {}\n            }\n            _assertSupply();\n        }\n    }\n}\n\ncontract SupplyIdentityReach is HubBase {\n    function setUp() public { _setUpHub(); _borrow(alice, 100e18, 50_000e18); }\n\n    /// C3 by case: an EXOTIC row's loss report covers a NON-exotic row's bad from the reserve; that row restores (mint-back);\n    /// a frozen row's restore mints nothing back; RELEASE_COVERED applied by a stranger; flash in between. P1 after each step.\n    function test_C3_coverRestoreRelease() public {\n        mod.mint(address(mod), 10_000e18 + 3);\n        house.mint(address(house), 10_000e18 + 1);\n        mod.pay(4_000e18 + 1); _assertSupply();\n        mod.report(1_000e18 + 7); _assertSupply();          // reserve covers mod's own bad at once\n        (,,,,,, uint128 bad,, uint128 cov) = hub.rows(MOD);\n        assertEq(bad, 0); assertEq(cov, 1_000e18 + 7);\n        mod.report(5_000e18 + 5); _assertSupply();          // reserve (3000e18-6) runs dry: rest stays bad\n        house.report(2_000e18 + 9); _assertSupply();        // exotic: covers non-exotic bad first (reserve empty: no-op)\n        vm.prank(bob); usd.approve(address(hub), type(uint256).max);\n        mod.mint(bob, 3_000e18);\n        vm.prank(bob); hub.repayReserve(MOD, 500e18); _assertSupply(); // covered falls, reserve refilled\n        house.report(1); _assertSupply();                   // exotic cover takes mod's bad out of the reserve first\n        uint256 s0 = usd.totalSupply();\n        uint256 got = mod.restore(type(uint128).max); _assertSupply();\n        assertGt(got, 0); assertGt(usd.totalSupply(), s0, \"restore minted back covered\");\n        house.restore(type(uint128).max); _assertSupply();\n        vm.prank(governor); hub.freeze(HOUSE);\n        house.report(1_000e18); hub.coverFromReserve(HOUSE); _assertSupply();\n        s0 = usd.totalSupply();\n        house.restore(type(uint128).max); _assertSupply();\n        assertEq(usd.totalSupply(), s0, \"frozen restore mints nothing\");\n        (,,,,,,,, cov) = hub.rows(HOUSE);\n        if (cov != 0) {\n            _gov(abi.encode(uint8(0x60 | HOUSE), uint128(cov)));\n            _pass(48 hours + 1);\n            _apply(uint8(0x60 | HOUSE)); _assertSupply();\n            assertEq(hub.totalCovered(), 0 + _cov(MOD) + _cov(EVIL) + _cov(MIG));\n        }\n        _pass(5 days); _assertSupply();\n    }\n\n    function _cov(uint256 i) internal view returns (uint256 c) { (,,,,,,,, c) = hub.rows(i); }\n}\n",
   "ran": true,
   "result": "[PASS] test_C3_coverRestoreRelease() (gas: 2921582); [PASS] testFuzz_P1_P2_anyOrder(uint256) (runs: 500). Also existing: HubInvariantsTest 5 invariants PASS (runs 128, calls 8192); BridgeInvariantsTest invariants PASS (runs 128, calls 8192) incl. invariant_supplyPerChain and invariant_supplyAcrossChains. RAN locally: forge 1.8.3 (older than 1.9: no --use solar; solc 0.8.38 not installed). Ran on a scratch copy of the commit with ONLY `pragma solidity 0.8.38` -> 0.8.30 and foundry.toml solc 0.8.30 (installed), via_ir/optimizer unchanged. No other source edited."
  }
 ]
}