{
  "item": "morpho-lender",
  "commit": "ff1c192b3798542997f600091f2dc73ff05e4c40",
  "forge": "forge 1.9.0 (Commit SHA 6056c5845d34205a83cf7108042adb137325c9df); --use solar unavailable (solar not installed, no network write to ~/.svm for it in this sandbox); solc 0.8.38 as pinned by foundry.toml was not pre-installed either, so it was downloaded from solidity's GitHub release to a local writable path and used via --use ./.solcbin/solc-0.8.38 (no change to foundry.toml). All runs below used this solc 0.8.38.",
  "verdict": "holds",
  "findings": [],
  "claims": [
    {
      "id": "C1",
      "result": "holds",
      "evidence": "Only 3 functions write r.principal: supply() (+=amount, L1), _exit() (-=t, called from withdraw/pull), _report() (-=loss, called from _settle/_trueUp on a Morpho shortfall). grep of src/morpho/MorphoLender.sol confirms no other assignment to .principal. All imdUSD leaving the lender goes through: morpho.supply (supply()), hub.burn (_exit()), hub.restore+hub.burn then token.approve/hub.payReserve and token.transfer(treasury,...) (_distribute(), called only from _settle/_exit/_trueUp paths). test_L2_suppliesOnlyStoredParams_holdsNothing_allowancesSpent (existing suite, re-run below, PASS) shows the lender's own balance and every allowance are 0 after every call and only the hub/Treasury gain."
    },
    {
      "id": "C2",
      "result": "holds",
      "evidence": "Morpho Blue's own liquidate/accrueInterest/settle route are permissionless by design (not lender code); MorphoLender.settle(index) has no access modifier (anyone). The gated float (StockLiquidator.liquidate, operator-only) is unaffected by that: it only tries lender.settle in a try/catch after its own liquidate call (StockLiquidator.sol:93-97) and never reverts the liquidation just because settle fails on its own (test_liquidator_settleCannotBlock, existing suite, PASS, market 1 not supplied into when the liquidation runs)."
    },
    {
      "id": "C3",
      "result": "holds",
      "evidence": "Wrote and ran 2 new tests (test/scratch/MorphoLenderGoal.t.sol, MorphoLenderSettleDoubleCountTest): test_C3_repeatedSettleSameBlock_reportsExactlyOnce calls settle 3x in the same block, by 3 different callers, after one liquidation realised bad debt; the loss is reported on the first call only, bad unchanged on the 2nd/3rd. testFuzz_C3_settleOrderNeverDoubleCounts(uint8 n in [1,6]) repeats settle n times (3 rotating callers) and asserts the reported loss never moves after the first call. Both PASS (256 fuzz runs). This follows from _settle's own invariant: after a report, r.principal is set to exactly v (Morpho's current claim), so a second call in the same state sees v==pr and reports nothing further; nothing in supply/withdraw/pull bypasses _settle first (every entry point calls _settle(index,...) before touching principal)."
    },
    {
      "id": "C4",
      "result": "holds",
      "evidence": "StockLiquidator.sol:91-97: liquidate() measures gasleft() before try lender.settle(n-1); on a catch it reverts SettleGasShort only if the remaining gas is under g/32 (i.e. the settle call was starved, not a clean revert on its own logic), matching the documented 1/32 rule (comment at StockLiquidator.sol:26-28, modelled on Liquidator.BidGasShort). A settle that reverts for its own reason (not gas) is left unreported but does not block the liquidation, exactly as the CLAIM states ('a settle that reverts by itself is still only tried'). Reasoned from code; not independently re-fuzzed with an artificial gas stipend in this session (would need a wrapper forcing gasleft() under g/32 at the exact call site) -- NOT RUN as a dedicated gas-griefing test, only re-derived from the existing code and the passing test_liquidator_settleCannotBlock, which exercises the try/catch path (clean revert, not gas-short) and confirms liquidation proceeds either way."
    },
    {
      "id": "C5",
      "result": "holds",
      "evidence": "MAX_MARKETS = 24 (MorphoLender.sol:66); _check's APPROVE branch reverts BadConfig if _rows.length >= MAX_MARKETS (MorphoLender.sol:275); _rows only grows via _rows.push in _apply's APPROVE branch (MorphoLender.sol:318) -- there is no function that removes or resets a row, so 24 is for the contract's life, matching the CLAIM. Dead supply/borrow (MIN_DEAD_SHARES/MIN_DEAD_BORROW) are checked only `if (atPropose)` (MorphoLender.sol:295-299), never in _validateAtApply's re-run of _check (atPropose=false); the dev comment at MorphoLender.sol:265-266 says this is deliberate ('anyone may repay the dead borrow on its behalf, so a re-check would let a stranger block a matured approval'). This exactly matches the KNOWN line (README 'Lender: ... dead supply / borrow checked at propose only'); not worse than written: the dead SUPPLY side (shares held by 0x...dEaD) can never be moved by anyone (DEAD has no key), only the dead BORROW can be repaid down, which is the scenario the known line and the code comment both already describe."
    },
    {
      "id": "C6",
      "result": "holds",
      "evidence": "Every value _check's STOCK_ORACLES branch reads (o.VERSION(), o.token(), o.loanToken(), o.morpho(), o.governor(), o.calendar(), o.JUMP()) is an `immutable` on StockOracle (src/stocks/StockOracle.sol: token/loanToken/morpho/governor/JUMP/calendar all declared `immutable`), and p.lltv is fixed in the proposal payload; _validateAtApply re-runs the identical STOCK_ORACLES checks (only the propose-only dead-supply/dead-borrow checks are skipped, C5 above). Since none of the re-checked values can change between propose and apply, there is no reachable oracle that passes APPROVE's checks at propose and fails at apply, or the reverse (other than the documented dead-borrow case, not part of this check). The 'different governor forces a release' sub-claim is refuted: APPROVE requires o.governor()==governor (the lender's own, immutable Safe address), and StockOracle.governor is itself immutable, so an approved market's oracle is permanently bound to the SAME Safe as the lender; no other governor can ever call its proposeForce/forceRelease (StockOracle.sol:271-288, onlyGovernor-gated proposeForce, 48h, then forceRelease by anyone once matured -- same single Safe throughout)."
    },
    {
      "id": "C7",
      "result": "holds",
      "evidence": "script/DeployConfig.sol:828 'lenderCap stays 0: the blue-chip lender gets no hub row on day 1 (file H3 is refused)' for BaseConfig; script/launch/SafeBatch.s.sol:178-183 h3() hard-requires config().launch.lenderCap != 0 to even propose the hub's ADD_SPOKE row for the lender, so on Base this step is never run. Wrote and ran test_C7_noHubRow_supplyAndWithdrawRevertAtTheHub_noMintNoMorphoSupply (test/scratch/MorphoLenderGoal.t.sol): a second MorphoLender sharing the SAME hub but never added as a spoke (the Base shape) has its own APPROVE/cap machinery work fine (it can propose+apply an APPROVE), but supply() reverts MinterHub.NotSpoke at hub.mint before ever calling morpho.supply or minting anything; because supply always reverts, principal stays 0 forever, so withdraw/pull/settle are permanent no-ops (never reach hub.burn or Morpho.supply either). PASS. This matches IMinterHub._spoke() reverting NotSpoke() when indexOf[msg.sender]==0 (MinterHub.sol:558-563), which every lender entry point that touches the hub depends on."
    },
    {
      "id": "C8",
      "result": "holds",
      "evidence": "supply/withdraw are `onlyOps` (msg.sender==allocator || msg.sender==governor, MorphoLender.sol:143-146,151,166); supply's only imdUSD moves are hub.mint(address(this), amount) then morpho.supply(r.params, amount, ...) with the exact stored MarketParams (never caller-supplied); withdraw only ever calls hub.burn via _exit with the row's own params, after a cap-respecting check (p > r.cap in pull / cap in supply). Re-ran existing test_L2_onlyAllocatorOrSafeMovesMoney and test_L1_capBoundsEverySupply/testFuzz_L1_principalNeverAboveCap (PASS): a stranger's supply/withdraw revert NotOps, and supply past a row's cap reverts OverCap in every case tried (fixed and fuzzed amounts, a lowered cap mid-sequence, the hub's own cap on top)."
    }
  ],
  "holds": [
    {"property": "P1 principal_m <= cap_m after every supply; sum principal == hub outstanding; assets() counts claims only", "tried": "existing test_L1_capBoundsEverySupply, testFuzz_L1_principalNeverAboveCap (256 fuzz runs incl. a mid-sequence lowered cap), test_L1_onlyASupplyRaisesPrincipal (donation + settle + pull), test_P6_aDonationDoesNotHideAnUnreportedLoss (a plain-transfer donation is never counted by assets()); testFuzz_L5_lossBound cross-checks bad+outstanding==supplied over 3 markets and a crash+liquidation. All PASS with solc 0.8.38."},
    {"property": "P2 anyone pulls principal over the cap; allocator/Safe withdraws to 0 as far as idle; no exit mints or reads the oracle", "tried": "existing test_L3_pullByAnyone_inEveryHubAndOracleState (hub row frozen, hub caps 0, oracle unpriced, lender cap 0 -> stranger's pull still works, vm.expectCall(hub.mint, 0) over the call), test_L3_withdrawToZeroByAllocator_andPullNeedsAnExcess, testFuzz_L3_pullNeverRevertsWhenIdleAndExcessExist (256 fuzz runs over debt, elapsed time, a lowered cap and a mid-run freeze). All PASS."},
    {"property": "P3 every entry settles first; interest pays bad then covered before the reserve share; settle pays principal before interest", "tried": "existing test_L4_reserveCoveredLoss_restoredByInterest_coveredBackToZero (covered_s drained to 0 by harvested interest before any reserve/Treasury split), test_D8_reserveShare (50%/20% bootstrap-vs-tail split, hub's own floor respected), and the new C3 tests above confirming _settle always runs first and never double-reports. All PASS; code reading of _settle's `owed = max(pr-cap, exitWant)` idle carve-out (wave-7 panel 4 judge L3) confirms principal an exit is owed is protected before interest is harvested."},
    {"property": "P4 APPROVE admits only a conforming market/oracle", "tried": "existing test_L2_approveRefusesEveryBadMarket (7 distinct bad-market shapes: uncreated, no dead legs, wrong loan token incl. a lying oracle, no IRM, oracle for a different token, already approved) plus a passing market; and the C6 analysis above (immutability of every oracle value re-checked at apply). All PASS / holds."}
  ],
  "notRun": [
    "[fork] test/fork/MorphoLender.fork.t.sol (checks MorphoMath's accounting against live Morpho Blue) -- NOT RUN: no RPC endpoint was used in this session, only MockMorpho via the unit suite.",
    "A dedicated gas-griefing test for StockLiquidator's SettleGasShort threshold (forcing gasleft() under g/32 exactly at the lender.settle call site) -- NOT RUN; C4 answered by code reasoning plus the existing clean-revert test only."
  ]
}
