{
 "item": "gov-timelock-pending",
 "commit": "ff1c192b3798542997f600091f2dc73ff05e4c40",
 "forge": "forge Version: 1.9.0 (6056c5845d34205a83cf7108042adb137325c9df); every run: forge test --use solar (Solar 0.8.38) --match-path 'test/scratch/*'",
 "verdict": "findings",
 "findings": [
  {
   "id": "GTP-1",
   "severity": "info",
   "title": "ImdBridge BATCH: every item is validated against the state before the batch, then the items are applied one by one, so a BATCH that passes propose and the apply-time re-validation can revert in _apply",
   "property": "P1 (a payload passing propose applies, alone and in a BATCH)",
   "claim": "C1",
   "files": [
    "src/bridge/ImdBridge.sol:899",
    "src/bridge/ImdBridge.sol:916",
    "src/bridge/ImdBridge.sol:981",
    "src/bridge/ImdBridge.sol:1130",
    "src/bridge/ImdBridge.sol:1173"
   ],
   "sequence": "Safe pause(HOME); propose BATCH[ENDPOINT_SKIP(HOME,s,1), ENDPOINT_SKIP(HOME,s,1)]. _validate checks each item with _check(items[i], items) against the endpoint's state before the batch, so nonce 1 == inboundNonce+1 passes for both items. After 48 h anyone calls applyPending(): the item validation passes again, the first skip moves lazyInboundNonce to 1, and the second endpoint.skip reverts LZ_InvalidNonce(1). The whole proposal fails and the 48 h is lost. By reading (NOT RUN): duplicate ENDPOINT_NILIFY/ENDPOINT_BURN items behave the same way. The reverse also holds: two consecutive SKIPs (n, n+1) in one BATCH are refused at propose, because n+1 is checked against the state before the batch.",
   "expected": "A BATCH that passes _validate at propose and again at apply applies. Otherwise _validate should refuse it: the items should be checked in sequence, or duplicate endpoint acts refused as SET_PATH/library duplicates are (ImdBridge.sol:906-914).",
   "actual": "applyPending() reverts LZ_InvalidNonce(1) in the second item. No money moves. The endpoint clean-up for a paused path is delayed by at least one more 48 h proposal, and the path stays paused that long (it holds honest inbound transfers for longer). This is self-inflicted by the Safe's encoding, so it is info.",
   "reachableAtDeploy": true,
   "fix": "In ImdBridge._validate, refuse two items of kind ENDPOINT_SKIP/NILIFY/BURN with the same (eid, sender, nonce), as is already done for SET_PATH and library pins. Alternatively, validate a BATCH by simulating its items in order.",
   "test": {
    "source": "// test/scratch/GovBridge.t.sol (is W5Bridge from test/utils/W5Bridge.sol; setUp: _setUpW5())\nfunction _batch(bytes memory a, bytes memory b) internal pure returns (bytes memory) {\n    bytes[] memory items = new bytes[](2);\n    (items[0], items[1]) = (a, b);\n    return abi.encode(uint8(6), items);\n}\nfunction test_C1_batchPassesProposeFailsAtApply() public {\n    vm.prank(safe);\n    rh.pause(HOME);\n    bytes memory skip = abi.encode(uint8(8), HOME, bytes32(uint256(0xbeef)), uint64(1));\n    _proposeRh(_batch(skip, skip)); // accepted by _validate\n    _warp(48 hours);\n    vm.prank(attacker);\n    rh.applyPending(); // expected: applies (re-validated OK); actual: reverts\n}\nfunction test_C1_control_singleSkipApplies() public {\n    vm.prank(safe);\n    rh.pause(HOME);\n    _governRh(abi.encode(uint8(8), HOME, bytes32(uint256(0xbeef)), uint64(1)));\n}",
    "ran": true,
    "result": "[FAIL: LZ_InvalidNonce(1)] test_C1_batchPassesProposeFailsAtApply() (gas: 635066); trace: MockLzEndpoint.skip <- ImdBridge.applyPending. [PASS] test_C1_control_singleSkipApplies() (gas: 299726). MockLzEndpoint.skip has the EndpointV2 rule n == inboundNonce+1."
   }
  },
  {
   "id": "GTP-2",
   "severity": "info",
   "title": "C3 does not describe the code: a tighten failing a multi-path SET_DELAY is not the only liveness loss of the one-slot contracts. pause(eid) and closeDay(day) drop a whole multi-item proposal, including items for other paths and days",
   "property": "P2 / C3",
   "claim": "C3",
   "files": [
    "src/bridge/ImdBridge.sol:694",
    "src/bridge/ImdBridge.sol:751",
    "src/stocks/MarketCalendar2.sol:233",
    "src/stocks/MarketCalendar2.sol:242"
   ],
   "sequence": "(a) The bridge has BATCH[SET_FEE(30184,5), UNPAUSE(HOME)] pending. The Safe calls pause(HOME), and _drop(UNPAUSE, HOME) cancels the whole BATCH, so path 30184's change is lost. voidPayload(h) and cancelClaim(eid) drop a BATCH holding UNVOID(h) or UNCANCEL(eid) the same way (ImdBridge.sol:741-751, read, not run). (b) MarketCalendar2 has SET_DAYS(EARLY_CLOSE,[d, d+14]) pending. closeDay(d) cancels it, so day d+14's early close is lost too.",
   "expected": "Per C3, only a tighten fails a queued multi-path change. README:1104 covers only that case: '- One pending proposal slot is shared by every path (a `tighten` fails a multi-path `SET_DELAY` BATCH).'",
   "actual": "applyPending reverts NothingPending: the other path's fee and the other day's status are never applied. This is liveness only. The drops are the intended conservative side, and they are documented in code comments, not in the README. No money is lost or minted.",
   "reachableAtDeploy": true,
   "fix": "Document these routes in the README known issues, or drop only the matching item. The latter is not possible with one slot, so the doc fix is enough.",
   "test": {
    "source": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.38;\nimport {W5Bridge} from \"../utils/W5Bridge.sol\";\nimport {MarketCalendar2} from \"../../src/stocks/MarketCalendar2.sol\";\n\ncontract GovC3Test is W5Bridge {\n    function setUp() public { _setUpW5(); }\n\n    /// C3 as written: only a tighten fails a queued multi-path change. pause(HOME) also drops a BATCH that changes OTHER.\n    function test_C3_pauseDropsOtherPathsChange() public {\n        vm.prank(safe);\n        rh.pause(HOME);\n        bytes[] memory items = new bytes[](2);\n        items[0] = abi.encode(uint8(7), uint32(30184), uint256(5)); // SET_FEE on another path\n        items[1] = abi.encode(uint8(5), HOME); // UNPAUSE(HOME)\n        _proposeRh(abi.encode(uint8(6), items));\n        _warp(48 hours);\n        vm.prank(safe);\n        rh.pause(HOME); // the Safe re-pauses HOME (no tighten anywhere)\n        vm.prank(attacker);\n        rh.applyPending(); // claim says the queued change to path 30184 survives: reverts NothingPending\n        assertEq(rh.feeBps(30184), 5);\n    }\n\n    /// Same on MarketCalendar2: closeDay(d) drops a 2-day SET_DAYS; the other day's change is lost.\n    function test_C3_closeDayDropsOtherDays() public {\n        MarketCalendar2 cal = new MarketCalendar2(safe, new uint32[](0), new uint32[](0));\n        uint256 d = block.timestamp / 1 days + 3;\n        while ((d + 4) % 7 == 0 || (d + 4) % 7 == 6) ++d;\n        uint32[] memory l = new uint32[](2);\n        (l[0], l[1]) = (uint32(d), uint32(d + 14));\n        vm.prank(safe);\n        cal.propose(abi.encode(uint8(1), uint8(2), l)); // EARLY_CLOSE on two days\n        _warp(48 hours);\n        vm.prank(safe);\n        cal.closeDay(uint32(d));\n        vm.prank(attacker);\n        cal.applyPending(); // reverts NothingPending: day d + 14's early close is gone too\n        assertEq(cal.dayStatus(d + 14), 2);\n    }\n}\n",
    "ran": true,
    "result": "[FAIL: NothingPending()] test_C3_closeDayDropsOtherDays() (gas: 1852307); [FAIL: NothingPending()] test_C3_pauseDropsOtherPathsChange() (gas: 534374)"
   }
  }
 ],
 "claims": [
  {
   "id": "C1",
   "result": "refuted",
   "evidence": "Fuzzed propose->apply (256 runs each, apply by a stranger at a random time in [eta, eta+14d]) over every kind of FixedLoans (SET_LEND_PRICE, SET_TERMS, SET_LIMITS incl. uint128-max limits, UNPAUSE), StableModule (SET_CAPS, SET_CURVE, SET_BAND; ADD_LEG/SET_YIELD/REOPEN by reading: the same tuple is decoded in _validate and _apply, StableModule.sol:912-1002), MorphoLender (RAISE_CAP, SET_ALLOCATOR; APPROVE via LenderBase setUp) and MarketCalendar2 (SET_DAYS, SET_OFFSETS). Every accepted payload applied, and available()/configHash() did not overflow 30 days later. No decode mismatch or narrowing overflow: the bridge bounds (MAX_LIMIT, windows<=7d, fee<=25, cap/breaker<=uint64*1e12) fit their storage types. Refuted only for an ImdBridge BATCH, whose items are validated against the state before the batch: GTP-1."
  },
  {
   "id": "C2",
   "result": "holds",
   "evidence": "Each instant act only tightens what it changes, and drops the pending proposal that would loosen it: FixedLoans lowerLendPrice/lowerDailyLimit/lowerSurgeLimit/pause (FixedLoans.sol:521-560), StableModule lowerCaps/lowerYield/close/abandonVault/_pull cut (StableModule.sol:376-430,785), MorphoLender lowerCap/revokeAllocator (MorphoLender.sol:241-258), bridge tighten (min cap/breaker, max delay, earlier cutoff, version bump), pause/voidPayload/cancelClaim (_drop), tripBreaker (trip number), MarketCalendar2.closeDay. Fuzzed for every field it names. One instant act re-opens risk by design: FixedLoans affirm/lowerAndAffirm resets issuedSinceAffirm and re-opens lending. That is documented at FixedLoans.sol:69 ('`affirm` is the one instant act that keeps risk open'), in a code comment and not in the README. 48 h kinds that change several fields (SET_LIMITS minDebt/affirmEvery, SET_DELAY cutoff lift) all wait 48 h and are re-validated."
  },
  {
   "id": "C3",
   "result": "refuted",
   "evidence": "The one-slot contracts are ImdBridge.sol:177, MarketCalendar2.sol:34, Treasury.sol:46 and house/Treasury.sol:56 (also house/feeds/MarketCalendar.sol:19, which the sheet does not name). GovernedByKind contracts hold one slot per kind, plus locks. Other liveness losses besides a tighten failing a multi-path SET_DELAY: pause(eid)/voidPayload/cancelClaim drop a whole BATCH, and closeDay drops a whole multi-day SET_DAYS (GTP-2). A single pending proposal also blocks every other one until it is cancelled (Governed.propose ProposalPending). The Safe's cancel() never reverts, so it can always free the slot. Tests: test_C3_pauseDropsOtherPathsChange and test_C3_closeDayDropsOtherDays fail."
  },
  {
   "id": "C4",
   "result": "holds",
   "evidence": "A cancel and a stranger's apply in the same block, in both orders, on FixedLoans (testFuzz_P3_expiryAndCancel) and ImdBridge/Governed (testFuzz_P3_bridgeExpiryCancel): exactly one takes effect. If the apply comes first, the cancel is a no-op without a revert. If the cancel comes first, the apply reverts NothingPending. Same for StockOracle cancelForce vs forceRelease (testFuzz_forceWindowAndCancel). 256 runs each, all pass."
  },
  {
   "id": "C5",
   "result": "refuted",
   "evidence": "No setGenesis* function exists in any family-2 file (GovernedByKind, Governed, StableModule, FixedLoans, ImdBridge, MorphoLender, MarketCalendar2, StockOracle). The only setGenesis* functions are in src/Parameters.sol:51-118 (core Parameters, family 1; not tested here). The genesis values of this family go through constructors, which apply the governed kinds' checks: StableModule.sol:187-190 (_checkLeg per launch leg, MAX_LEGS), FixedLoans.sol:212-214 (_checkTerms, _checkLimits, lendPrice != 0). MorphoLender's constructor (MorphoLender.sol:128-140) has no APPROVE, and its allocator_ is unchecked (0 allowed = none). MarketCalendar2's constructor seeds days with _set (weekday check only, any date, including past dates) — deployer-only, not a timelocked route. By reading."
  }
 ],
 "holds": [
  {
   "property": "P1 (GovernedByKind contracts: StableModule, FixedLoans, MorphoLender; MarketCalendar2; bridge non-batch kinds)",
   "tried": "Fuzz propose->apply per kind, as in C1: testFuzz_C1_everyKindApplies, testFuzz_C1_stableKinds, testFuzz_lenderRaceAndApply, testFuzz_C1_calendarKinds, test_C1_control_singleSkipApplies. All pass. These GovernedByKind contracts have no BATCH kind, so P1 for a BATCH concerns only ImdBridge, which fails (GTP-1)."
  },
  {
   "property": "P2 (loosening waits 48 h and is re-validated at apply; tightening lands in its own tx, no looser than named or stood, drops the pending loosening)",
   "tried": "Same-block races with a matured loosening applied by a stranger in front of, or after, the Safe's instant act, with random values and random apply times in [eta, eta+14d]: FixedLoans lowerLendPrice/lowerDailyLimit/pause vs SET_LEND_PRICE+SET_LIMITS; StableModule lowerCaps vs SET_CAPS and close vs REOPEN; MorphoLender lowerCap+revokeAllocator vs RAISE_CAP+SET_ALLOCATOR; bridge tighten vs SET_DELAY and pause vs BATCH[SET_FEE x2, UNPAUSE]; MarketCalendar2 closeDay vs SET_DAYS(OPEN|EARLY_CLOSE). In every ordering the result is at the tighter value and the loosening cannot be applied afterwards (256 runs each, all pass). Re-validation at apply was read for every kind: GovernedByKind.sol:95-97 and Governed.sol:77-78 call _validate after _take. MorphoLender skips only the dead-deposit check, by design (MorphoLender.sol:265-268). Bridge BATCH ordering checked by reading: BATCH[UNPAUSE(e), SET_DELAY shorter(e)] or [UNPAUSE, NILIFY] apply in the same transaction as the permitted order, so no gap. Two SET_DELAY or a SET_DELAY+RESET_BREAKER on one eid only end tighter or reset what the Safe proposed."
  },
  {
   "property": "P3 (expiry 14 d past ETA; no apply after expiry or cancel)",
   "tried": "testFuzz_P3_expiryAndCancel (FixedLoans/GovernedByKind) and testFuzz_P3_bridgeExpiryCancel (Governed): dt fuzzed over 0..40 d. The apply succeeds iff 48h <= dt <= 48h+14d, and never after cancel. StockOracle forced release: testFuzz_forceWindowAndCancel, dt over 0..20 d. It succeeds iff eta <= t <= eta+14d and there was no cancelForce (StockOracle.sol:292). The existing test_O8_force_onlyWhilePending_cancellable_expires_boundToOneFreeze passes and covers a re-freeze that voids the force. All pass."
  }
 ],
 "notRun": [
  "[fork]/[data]: none in this sheet; no RPC used",
  "duplicate ENDPOINT_NILIFY/BURN items in a BATCH (reasoned, same mechanism as GTP-1)",
  "StableModule ADD_LEG/SET_YIELD/REOPEN fuzzed apply (read only; REOPEN race run)",
  "MorphoLender APPROVE fuzz (covered only by LenderBase setUp applying it)",
  "src/Parameters.sol setGenesis* bounds (family 1)",
  "Treasury.sol governance kinds (named as one-slot only)"
 ]
}