{
 "item": "gov-instant-acts",
 "commit": "ff1c192b3798542997f600091f2dc73ff05e4c40",
 "forge": "forge 1.9.0 (6056c58), compiled with solar 0.3.0-dev (0.8.38) via --use /path/to/solar (the bare word 'solar' is read as a solc version by this forge); only test/scratch/* compiled",
 "verdict": "findings",
 "findings": [
  {
   "id": "GIA-1",
   "severity": "low",
   "title": "Parameters.lowerCap (core and house) reverts OutOfBounds whenever the live low price is above 100x the cap the Safe asks: a Chainlink spike blocks the instant cap at the true price, and the pending SET_CAP raise it would have dropped survives and can be applied by anyone",
   "property": "P1 (lands at once in any state; no outsider's action makes it revert) and P2 (drops its kind's pending loosening)",
   "claim": "C1 (instant act under oracle spike), C4",
   "files": [
    "src/Parameters.sol:137",
    "src/Parameters.sol:139",
    "src/Parameters.sol:140",
    "src/house/Parameters.sol:195",
    "src/house/Parameters.sol:197",
    "src/ParametersBase.sol:312",
    "src/ParametersBase.sol:316"
   ],
   "sequence": "1) The Safe has a cap of 3,000 on ETH and a pending SET_CAP(ETH, 3,500). 2) The ETH median feed (in the threat model: a Chainlink spike) prints more than 100x the true 2,000. _liveLow returns the median: it falls back to the median when spot is not lower within skew, and here median = spot. 3) The Safe calls lowerCap(ETH, 2,000), the true price, to stop borrowing at the spiked price: it reverts OutOfBounds, because the bound check at :139 runs BEFORE _cancelPending at :140. 4) 48 h later a stranger applies the SET_CAP raise to 3,500.",
   "expected": "lowerCap(ETH, x) lands at min(cap, x) and drops the pending SET_CAP of ETH in any oracle state. A cap is a ceiling, so a low cap is always the safe direction.",
   "actual": "It reverts for every x < liveLow/100. At a k-fold spike (k > 100) the Safe can only cap at liveLow/100 = (k/100) x the true price or more. The pending raise is not dropped. The fuzz test with spike factors 101..1e6 shows the revert on all 256 runs. In the P1 property tests, factor 1e6 fails for core and a random large factor fails for house.",
   "reachableAtDeploy": "yes: every type with a live feed. Mitigation available to the Safe: lowerLine(ilk, 0) still lands (it reads no price) and stops new draws, so the loss is bounded to a cap the Safe cannot set, not to unbounded minting. Hence low.",
   "fix": "Run _cancelPending(SET_CAP, ilk) first, and make the unit-error guard independent of the live price, e.g. refuse only cap_ == 0 or compare against a stored reference (the cap or the price at the last SET_CAP/genesis), or skip the guard when the cap already stands. Never let a price the act defends against gate the act.",
   "test": {
    "source": "/// >100x on the median makes the Safe's instant cap at the true price revert, and the pending SET_CAP raise survives.\ncontract ScratchParamsSpike is System {\n    bytes32 constant ETH = \"ETH\";\n    MockFeed feed;\n\n    function setUp() public {\n        vm.warp(1_800_000_000);\n        feed = new MockFeed(2000e18);\n        _deploySystem(IERC20(address(new MockERC20(\"imdUSDv1\", 18))));\n        _addIlk(ETH, address(new MockERC20(\"WETH\", 18)), feed, feed, address(0), address(0), true, _risk(1.4e18, 10_000_000e18));\n        params.seal();\n    }\n\n    function testFuzz_lowerCapRevertsUnderASpike(uint256 mult) public {\n        mult = bound(mult, 101, 1_000_000);\n        vm.prank(governor);\n        params.lowerCap(ETH, 3000e18); // a cap the Safe set earlier\n        vm.prank(governor);\n        params.propose(abi.encode(uint8(21), ETH, uint256(3500e18))); // a pending SET_CAP raise\n        feed.set(2000e18 * mult); // the feed spikes (median = spot here)\n        vm.prank(governor);\n        vm.expectRevert(bytes4(keccak256(\"OutOfBounds()\")));\n        params.lowerCap(ETH, 2000e18); // the instant act at the true price: refused\n        assertEq(params.cap(ETH), 3000e18);\n        vm.warp(block.timestamp + 48 hours);\n        vm.prank(makeAddr(\"stranger\"));\n        params.applyPending(21); // the raise the act would have dropped lands\n        assertEq(params.cap(ETH), 3500e18);\n    }\n}\n\n/// P1 as a property (fails): the Safe's instant cap at the true price lands whatever the feed prints.\ncontract ScratchParamsSpikeProperty is ScratchParamsSpike {\n    function testFuzz_P1_lowerCapLandsInAnyState(uint256 mult) public {\n        mult = bound(mult, 1, 1_000_000);\n        vm.prank(governor);\n        params.propose(abi.encode(uint8(21), ETH, uint256(3500e18)));\n        feed.set(2000e18 * mult);\n        vm.prank(governor);\n        params.lowerCap(ETH, 2000e18);\n        assertLe(params.cap(ETH), 2000e18);\n    }\n}\n\n/// The house Parameters carries the same rule (src/house/Parameters.sol:197).\n\n/// The house Parameters carries the same rule (src/house/Parameters.sol:197).\ncontract ScratchHouseSpike is CapAndSlotsTest {\n    function testFuzz_P1_houseLowerCapLandsInAnyState(uint256 mult) public {\n        mult = bound(mult, 1, 1_000_000);\n        ethMedian.set(2000e18 * mult);\n        ethSpot.set(2000e18 * mult);\n        vm.prank(governor);\n        params.lowerCap(ETH, 2000e18);\n        assertLe(params.cap(ETH), 2000e18);\n    }\n}",
    "ran": "forge 1.9.0 + solar 0.3.0-dev (Solidity 0.8.38), forge test --use <solar> --match-path test/scratch/<file> --fuzz-runs 256, local (no fork); file InstantActs.t.sol + InstantActs2.t.sol",
    "result": "[PASS] ScratchParamsSpike.testFuzz_lowerCapRevertsUnderASpike(uint256) (runs: 256) shows the revert and the surviving raise for every spike factor 101..1e6. [FAIL: OutOfBounds(); counterexample: args=[340282366920938463463374607431768211455]] ScratchParamsSpikeProperty.testFuzz_P1_lowerCapLandsInAnyState(uint256), where the bound gives factor 1e6. [FAIL: OutOfBounds(); counterexample: args=[810881428472137372093908858482910792464230400225625968390001765509283514085]] ScratchHouseSpike.testFuzz_P1_houseLowerCapLandsInAnyState(uint256) (house Parameters)."
   }
  },
  {
   "id": "GIA-2",
   "severity": "low",
   "title": "Before seal, the deployer key (wirer) re-opens the Safe's instant lowers with the genesis setters: setGenesisCap (including 0 = no ceiling) and setGenesisExoticMargin overwrite a lowerCap / lowerExoticMargin at once, without a 48 h proposal",
   "property": "P2 (nothing re-opens what an instant act closed except a new 48 h proposal), against 'the deployer until sealed'",
   "claim": "C4",
   "files": [
    "src/Parameters.sol:85",
    "src/Parameters.sol:94",
    "src/Parameters.sol:137",
    "src/Parameters.sol:165",
    "src/house/Parameters.sol:125",
    "src/house/Parameters.sol:82",
    "src/house/Parameters.sol:93",
    "script/deploy/StageGenesis.sol:79"
   ],
   "sequence": "Stages 1-3 add the genesis types and caps. The Parameters governor is the Safe, and its instant acts are live before seal. The Safe calls lowerCap(ETH, x) and lowerExoticMargin(m). In the same block, or in any block before Stage 4's params.seal() (StageGenesis.sol:79), the wirer calls setGenesisCap(ETH, 0) and setGenesisExoticMargin(1,000,000e18), then seals.",
   "expected": "The Safe's lower stands until a 48 h proposal raises it, or the genesis setters cannot raise a value the Safe lowered.",
   "actual": "The cap is removed (cap 0 = none) and the margin is raised to its maximum after the Safe lowered them, with no proposal. The house setters setGenesisCap, setGenesisDepthRule and setGenesisChainLine have the same pattern against lowerCap / lowerDepthK / postLowerDepth (read from the code, not tested).",
   "reachableAtDeploy": "only in the deploy window between the first genesis setter and seal(). The wirer is a one-shot key in the threat model ('the deployer until sealed').",
   "fix": "Have every genesis setter only lower what an instant act already lowered: take min with the current value once the governor has acted, or keep a per-field flag set by the instant act. Or refuse instant acts before seal, and say so.",
   "test": {
    "source": "/// P2 against \"the deployer until sealed\": before `seal`, the wirer's genesis setters re-open what the Safe's instant\n/// lowers closed, with no 48 h proposal.\ncontract ScratchDeployerUndo is System {\n    bytes32 constant ETH = \"ETH\";\n\n    function setUp() public {\n        vm.warp(1_800_000_000);\n        MockFeed feed = new MockFeed(2000e18);\n        _deploySystem(IERC20(address(new MockERC20(\"imdUSDv1\", 18))));\n        _addIlk(ETH, address(new MockERC20(\"WETH\", 18)), feed, feed, address(0), address(0), true, _risk(1.4e18, 10_000_000e18));\n        params.setGenesisExoticMargin(1_000e18); // not sealed yet: this contract is the wirer\n    }\n\n    function testFuzz_P2_wirerUndoesInstantLowersBeforeSeal(uint256 cap, uint256 margin) public {\n        cap = bound(cap, 20e18, 1_000_000e18);\n        margin = bound(margin, 0, 999e18);\n        vm.startPrank(governor);\n        params.lowerCap(ETH, cap);\n        params.lowerExoticMargin(margin);\n        vm.stopPrank();\n        // the deployer key, same block, no proposal\n        params.setGenesisCap(ETH, 0); // 0 = no ceiling\n        params.setGenesisExoticMargin(1_000_000e18);\n        params.seal();\n        assertLe(params.cap(ETH) == 0 ? type(uint256).max : params.cap(ETH), cap, \"cap re-opened\");\n        assertLe(params.exoticMargin(), margin, \"margin re-opened\");\n    }\n}",
    "ran": "forge 1.9.0 + solar 0.3.0-dev (Solidity 0.8.38), forge test --use <solar> --match-path test/scratch/<file> --fuzz-runs 256, local (no fork); file InstantActs3.t.sol",
    "result": "[FAIL: cap re-opened: 115792089237316195423570985008687907853269984665640564039457584007913129639935 > 999980000944728738879523; counterexample: args=[944728738879522, 1157...9932]] ScratchDeployerUndo.testFuzz_P2_wirerUndoesInstantLowersBeforeSeal(uint256,uint256) (runs: 0)"
   }
  }
 ],
 "claims": [
  {
   "id": "C1",
   "result": "refuted",
   "evidence": "Instant acts in src/ and the state they read. MinterHub: lowerCap:359 (rows[i].cap, slot SET_CAP|i), lowerTotalCap:368, lowerExoticCap:376, freeze:387 (UNFREEZE|i, RELEASE_COVERED|i), markLoss:399 (LOWER_MARK|i, RELEASE_COVERED|i, marks). StableModule: close:376, lowerCaps:381, lowerYield:395, reportLoss:406, abandonVault:418 (stable balance, hub.reportLoss, which loops <=16 rows in _coverFromReserve), _report:842 (REOPEN|i). MorphoLender: lowerCap:241, revokeAllocator:251. FixedLoans: lowerLendPrice:518, lowerDailyLimit:531, lowerSurgeLimit:540, pause:549, lowerAndAffirm:584. Core Parameters: disableSleeveIlk:122, lowerCap:137 (reads the live feeds via _liveLow, ParametersBase.sol:312), lowerLine:149, lowerExoticMargin:165, lowerUnbackedBrake:173. House Parameters: removeDepthSampler:117, lowerEdgePremium:164, disableSleeveIlk:176, lowerCap:195 (live feeds), lowerDepthLine:212, lowerLine:220, lowerDepthK:236, postLowerDepth:247. MarketCalendar2.closeDay:230 (block time, offsetOf, the single pending slot). StockOracle.cancelForce:280. ImdBridge: cancelClaim:618, tripBreaker:631, tighten:654, pause:693, hold:702 (endpoint.inboundPayloadHash), voidPayload:732. house Allocator unfreeze/clearFreezer/lowerLimit/removeTarget/lowerSlippage:456-494 and house MarketCalendar.closeDay:73 are outside this sheet's files (not tested). Tested with matured proposals applied by a stranger in front, in the same block, in any subset and order: hub, stable module, lender, fixed loans, calendar, oracle; all hold. The core and house Parameters lowerCap FAILS under an oracle spike (GIA-1). The only state-dependent revert among the acts is that one, because it reads a price. Donation: no instant act reads a balance a donation can move except abandonVault, where a donation only lowers the loss it reports. NIL: the bridge's hold binds NIL (README 'hold binds NIL', fixed); not re-tested here."
  },
  {
   "id": "C2",
   "result": "refuted",
   "evidence": "Wording: MorphoLender has no cancelForce. cancelForce is src/stocks/StockOracle.sol:280. MorphoLender's instant acts are lowerCap:241, revokeAllocator:251 and GovernedByKind.cancel(kind):77. The behaviour itself holds. ScratchLenderInstant.testFuzz_lenderActsLandAndStay (256 runs, PASS): matured RAISE_CAP(0) and SET_ALLOCATOR, applied in front or not, any delay inside expiry; lowerCap(0,c) gives cap <= c, revokeAllocator gives allocator 0, cancel(kind) on an empty slot is a no-op, and nothing applies after. ScratchOracleInstant.testFuzz_cancelForce (256 runs, PASS): never reverts with nothing proposed, proposed, matured or expired; forceRelease then reverts NoForce and the market stays frozen. _row (MorphoLender.sol:335) reverts only on index >= markets; markets are never removed."
  },
  {
   "id": "C3",
   "result": "holds",
   "evidence": "StableModule: lowerCaps clears SET_CAPS|i (:383); lowerYield (:397) and abandonVault (:420) clear SET_YIELD|i; close, reportLoss and abandonVault clear REOPEN|i through _report (:843). ScratchStableInstant.testFuzz_stableActsLandAndStay (256 runs, PASS): matured SET_CAPS(0), SET_YIELD(1), REOPEN(0), REOPEN(1), any subset applied in front, then lowerCaps/lowerYield/close/reportLoss(1,0); caps and yield are <= asked, both legs halted, and nothing applies after. Hub: freeze and markLoss clear RELEASE_COVERED|i (MinterHub.sol:390,402) as well as UNFREEZE|i and LOWER_MARK|i. ScratchHubInstant.testFuzz_hubActsLandAndStay (1000 runs, PASS) covers SET_CAP, SET_TOTAL_CAP, SET_EXOTIC_CAP, LOWER_MARK, RELEASE_COVERED and UNFREEZE in any subset applied in front; covered stays and nothing applies after. MarketCalendar2.closeDay drops a pending SET_DAYS that lists the day with status OPEN or EARLY_CLOSE (:233-247) and is refused at or after the open (:232). ScratchCalendarInstant.testFuzz_closeDay (256 runs, PASS): any status, matured or not, applied in front or not, closeDay 1-3 days ahead; the day stays CLOSED_DAY after any apply, and closeDay at the open reverts. A pending SET_OFFSETS cannot move today's open, because its days must be > today at apply (:273)."
  },
  {
   "id": "C4",
   "result": "refuted",
   "evidence": "ONE invariant for every route. For each instant act A that tightens field F[key], after A in any state: (a) A reverts only on onlyGovernor or an index out of range, never on a value an outsider or an oracle moves; (b) F[key] <= asked (or >= for marks); (c) every pending slot, alone or in a BATCH, whose apply could write F[key] looser is gone, or its apply re-validates against a counter A bumped (bridge SET_DELAY version, RESET_BREAKER trip number); (d) the only writers of F after A are A-type lowers and _apply of a slot proposed AFTER A. (a) fails for Parameters.lowerCap (GIA-1) and (d) fails for the genesis setters before seal (GIA-2); everything else tested holds. Smallest replacement design: a per-field epoch. Every instant lower does epoch[F,key]++; propose stores the epochs of the fields its payload writes; apply refuses a payload whose epoch changed. Instant acts check nothing but the caller and the index. Genesis setters also bump or are disabled once the governor has acted. This one rule covers the version/trip-number special cases, _clear, _drop and _cancelPending."
  }
 ],
 "holds": [
  {
   "property": "P1 (hub, stable module, lender, fixed loans, calendar, oracle, bridge)",
   "tried": "Fuzz over subsets of matured proposals applied by a stranger in front in the same block, delay 48h..48h+14d, any act arguments (uint128 caps/marks, uint16 yield); 256-1000 runs per contract; every act landed. Bridge (read only, ImdBridge.sol:618-740): the acts revert only on onlyGovernor; tighten on a never-set path is documented (NotTighter, :660); the counters are uint32 (README 'Counters', known)."
  },
  {
   "property": "P2 (kind's pending loosening dropped; nothing re-opens except a new 48h proposal)",
   "tried": "After each act, every slot a stranger applies fails (NothingPending or re-validation). Hub ADD_SPOKE and SET_RESERVE_RULE are not dropped by lowerTotalCap/lowerExoticCap, but ADD_SPOKE is re-validated against the lowered caps at apply (MinterHub.sol:_check); RELEASE_RESERVE is refused at apply while marks != 0. FixedLoans pause drops UNPAUSE, SET_LEND_PRICE, SET_LIMITS and SET_TERMS (:549-553). Bridge: SET_DELAY and RESET_BREAKER are not dropped by tighten/tripBreaker but are bound to version/trip (:1022,:1031). A pending DROP is not dropped by hold, which is the README known 'DROP on a never-held nonce' as written. FAILS for the genesis setters before seal (GIA-2)."
  },
  {
   "property": "P3 (bounded gas)",
   "tried": "Loops reached by an instant act: hub _coverFromReserve <= MAX_SPOKES 16 rows (stable reportLoss/abandonVault); closeDay <= MAX_DAYS 64 listed days; Parameters _touches <= MAX_BATCH 8 items, one level deep; bridge _names over the pending BATCH items; GovernedByKind._clear O(1). Measured: whole fuzz cases including setup averaged 0.6M-2.4M gas (mean, forge). No act loops over anything a stranger can grow."
  }
 ],
 "notRun": [
  "[fork]/[data]: none in this sheet; no fork tests RAN (no RPC used).",
  "house Allocator instant acts and house MarketCalendar.closeDay (outside the sheet's FILES): read, not tested.",
  "Bridge instant acts: reviewed from the code only; earlier submissions (dc9419af..., 439d66ba...) cover hold/DROP/UNCANCEL/UNPAUSE orderings.",
  "house setGenesisDepthRule/ChainLine vs lowerDepthK/postLowerDepth (GIA-2 extension): read, not tested."
 ]
}