{
 "item": "stock-multiplier-freeze",
 "commit": "ff1c192b3798542997f600091f2dc73ff05e4c40",
 "forge": "forge Version: 1.9.0 (--use solar, Solar 0.8.38)",
 "verdict": "findings",
 "findings": [
  {
   "id": "SMF-1",
   "severity": "low",
   "title": "The step base moves after STEP_SETTLE (24 h) without the feed having printed, while MAX_AGE prices a 49 h-old answer: under a stalled feed, chained small steps misprice by up to ~3x SMALL_STEP",
   "property": "P2 (no step chain / stale leg misprices past SMALL_STEP from the base)",
   "claim": "StockOracle NatSpec at src/stocks/StockOracle.sol:73-76: the base moves to the last change once it is older than STEP_SETTLE because 'the feed's 24 h heartbeat runs in open-market time, so by then it has printed under the change'. The code never checks that the feed printed: sync() (line 253) moves baseMultiplier on open-market time alone, and price() (line 214) still accepts a latest round up to MAX_AGE = 49 h old (line 85; STEP_SETTLE = 24 h, line 87). A Chainlink stall (in the threat model) inside MAX_AGE therefore lets 2-3 small steps be released, each measured from a base the priced answer was never printed under.",
   "files": [
    "src/stocks/StockOracle.sol:253",
    "src/stocks/StockOracle.sol:85",
    "src/stocks/StockOracle.sol:87",
    "src/stocks/StockOracle.sol:214",
    "src/stocks/StockOracle.sol:262"
   ],
   "sequence": "Mon 09:32 NY feed prints P (two rounds), then stalls. Mon 09:40 issuer step m0 -> m1 = +1%; stranger sync() (released, base m0). Tue 09:41 (24 h 1 min open-market time later) step m1 -> m2 = +1%; sync(): openTime >= STEP_SETTLE so base = m1, step 1% <= SMALL_STEP, released. Wed 09:42 step +1% again, released the same way. price() at Wed 09:42 returns P (answer 48 h 10 min old < MAX_AGE) while the token is worth P x 1.0303.",
   "expected": "price within SMALL_STEP (1%) of the token's value (the answer was printed under a multiplier within SMALL_STEP of the current one), or Frozen",
   "actual": "priced 2.9% under the value after three 1% steps (1.76% after two steps in the fuzz counterexample s1=0.889%, s2=0.888%..1%): borrowers can be liquidated on a price 3x SMALL_STEP low (a falling multiplier: priced high, borrows against value that is not there). Bounded by the steps that fit in MAX_AGE (49 h) at one per STEP_SETTLE (24 h): 3 steps; never split-sized.",
   "reachableAtDeploy": "yes: SMALL_STEP 0.01e18 (script/DeployConfig.sol:866), MAX_AGE/STEP_SETTLE are constants; needs a feed stall of 24-49 h of open-market time with two or three multiplier steps (dividend steps) inside it",
   "fix": "Move the base only once the feed has printed under the recorded change: in sync(), replace the openTime(syncedAt) >= STEP_SETTLE test by 'the feed's round before its latest (t1, both priced legs) is newer than syncedAt' (or keep a syncedAt-indexed check in price(): if t1 <= syncedAt measure the step from the multiplier in force at t1). Alternatively STEP_SETTLE >= MAX_AGE + one heartbeat.",
   "test": {
    "source": "// test/scratch/MultFreeze.t.sol (contract MultFreezeTest is StockOracleBase; setUp: _deploy(); _print(monOpen + 1 minutes, P); _print(monOpen + 2 minutes, P);)\n// helpers: _schedule(m, lead) = token.scheduleMultiplier(m, now + lead); _stepOf(a, b) = ceil(|a - b| * 1e18 / b)\n    // ---------------------------------------------------------------- FINDING 1 (P2): stale leg + STEP_SETTLE < MAX_AGE\n    /// The feed stalls (prints nothing, still inside MAX_AGE = 49 h). Two small steps, each recorded after STEP_SETTLE (24 h\n    /// open-market time) of the one before, move the base without the feed ever printing under them: the priced answer is\n    /// still the one printed under the multiplier before both, so the price is off by s1 + s2 > SMALL_STEP.\n    function testFuzz_F1_stalledFeed_stepChainMispricesPastSmallStep(uint256 s1, uint256 s2) public {\n        s1 = bound(s1, 0.006e18, 0.01e18);\n        s2 = bound(s2, 0.006e18, 0.01e18);\n        _at(monOpen + 10 minutes);\n        uint256 m1 = 1e18 + s1;\n        _schedule(m1, 0);\n        vm.prank(stranger);\n        o.sync();\n        assertFalse(o.pendingRelease());\n        _at(tueOpen + 11 minutes); // 24 h 1 min of open-market time after the first sync; no round since monOpen + 2 min\n        uint256 m2 = m1 * (1e18 + s2) / 1e18;\n        _schedule(m2, 0);\n        vm.prank(stranger);\n        o.sync();\n        assertFalse(o.pendingRelease(), \"second small step released\");\n        assertEq(o.baseMultiplier(), m1);\n        uint256 v = _priced(o); // the answer printed under 1e18, 24 h old (< MAX_AGE)\n        uint256 truth = uint256(P) * m2 / 1e18;\n        assertLe(_stepOf(v, truth), o.SMALL_STEP(), \"P2: price within SMALL_STEP of the value\");\n    }\n\n    /// Three steps of 1% inside one MAX_AGE: about 3% off.\n    function test_F1_threeStepsInsideMaxAge() public {\n        uint256 m = 1e18;\n        uint256[3] memory at = [monOpen + 10 minutes, tueOpen + 11 minutes, wedStart + 13 hours + 30 minutes + 12 minutes];\n        for (uint256 i; i < 3; ++i) {\n            _at(at[i]);\n            m = m * 1.01e18 / 1e18;\n            _schedule(m, 0);\n            o.sync();\n            assertFalse(o.pendingRelease());\n        }\n        uint256 v = _priced(o);\n        uint256 truth = uint256(P) * m / 1e18;\n        emit log_named_uint(\"price (feed units)\", v);\n        emit log_named_uint(\"value (feed units)\", truth);\n        assertLe(_stepOf(v, truth), o.SMALL_STEP(), \"P2: price within SMALL_STEP of the value\");\n    }\n\n",
    "ran": "forge test --use solar --match-path test/scratch/MultFreeze.t.sol (fuzz 2000 runs)",
    "result": "[FAIL: P2: price within SMALL_STEP of the value: 17550270640344108 > 10000000000000000; counterexample: args=[8890937385923030 [8.89e15], 33445492662212280090674059326658851473 [3.344e37]]] testFuzz_F1_stalledFeed_stepChainMispricesPastSmallStep(uint256,uint256) (runs: 0)\n[FAIL: P2: price within SMALL_STEP of the value: 29409852072355555 > 10000000000000000] test_F1_threeStepsInsideMaxAge() (gas: 438635)"
   }
  },
  {
   "id": "SMF-2",
   "severity": "info",
   "title": "sync() reverts (checked-math overflow) on a multiplier more than ~1e41x the base, contradicting its 'never a revert' comment: the market is frozen with no Safe exit",
   "property": "P3 (sync never reverts in a way that leaves the market frozen with no exit)",
   "claim": "src/stocks/StockOracle.sol:257-261 comment: 'never a revert: a sync that cannot run would leave the market frozen with no exit'. The step '(|current - base|) * WAD + base - 1' overflows when |current - base| > ~1.16e59 (or base close to 2^256), so sync() panics (0x11); pendingRelease is never set, so proposeForce reverts NotPending (line 274) and forceRelease cannot run. Only the issuer writing the multiplier back exits.",
   "files": [
    "src/stocks/StockOracle.sol:259-261",
    "src/stocks/StockOracle.sol:274",
    "src/stocks/StockOracle.sol:233"
   ],
   "sequence": "issuer schedules uiMultiplier = 2^256/1e17 effective now -> frozen() true (current != seen) -> sync() reverts Panic(0x11) -> governor proposeForce() reverts NotPending.",
   "expected": "sync() records the change and freezes it (pendingRelease) so the Safe's forced release is the exit",
   "actual": "sync() reverts; no route the Safe or anyone can take releases the market until the issuer changes the multiplier again",
   "reachableAtDeploy": "yes, but only by the issuer writing an absurd multiplier (an issuer can freeze the market by pause anyway); hence info",
   "fix": "compute the step saturating: if (diff > type(uint256).max / WAD) step = type(uint256).max / WAD; else step = (diff * WAD + base - 1) / base (or use Math.mulDiv rounding up).",
   "test": {
    "source": "// test/scratch/MultFreeze.t.sol (contract MultFreezeTest is StockOracleBase; setUp: _deploy(); _print(monOpen + 1 minutes, P); _print(monOpen + 2 minutes, P);)\n// helpers: _schedule(m, lead) = token.scheduleMultiplier(m, now + lead); _stepOf(a, b) = ceil(|a - b| * 1e18 / b)\n    // ---------------------------------------------------------------- FINDING 2 (P3): sync reverts on overflow\n    function test_F2_syncRevertsOnHugeMultiplier_noExit() public {\n        _at(monOpen + 10 minutes);\n        _schedule(type(uint256).max / 1e17, 0); // issuer writes a garbage multiplier\n        assertTrue(o.frozen());\n        (bool ok,) = address(o).call(abi.encodeCall(StockOracle.sync, ()));\n        vm.prank(governor);\n        (bool okP,) = address(o).call(abi.encodeCall(StockOracle.proposeForce, ()));\n        assertFalse(okP, \"no forced release: NotPending\");\n        assertTrue(ok, \"P3: sync never reverts\");\n    }\n\n",
    "ran": "forge test --use solar --match-path test/scratch/MultFreeze.t.sol",
    "result": "[FAIL: P3: sync never reverts] test_F2_syncRevertsOnHugeMultiplier_noExit() (gas: 186629)"
   }
  }
 ],
 "claims": [
  {
   "id": "C1",
   "result": "holds",
   "evidence": "For a split-sized step: sync() sets pendingRelease (step > SMALL_STEP, src/stocks/StockOracle.sol:262-267) and frozen() is true while pendingRelease (src/stocks/StockOracle.sol:231), so price() reverts Frozen whatever the feed prints until forceRelease (testFuzz_C1C2_splitOrQuickChainNeverPricesBeforeRelease, 2000 runs: split x2 after up to 8 quick steps, feed printing P twice, Frozen until 48 h - 1 s after proposeForce, TooEarly). The first print after sync() IS trusted for a released small step (error up to the step, README:821 known) and, with a stalled feed, up to ~3 steps (SMF-1), never split-sized: no route prices a split before the Safe's forceRelease. After forceRelease nothing checks the feed has printed under the new multiplier (Safe accepted)."
  },
  {
   "id": "C2",
   "result": "holds",
   "evidence": "Steps synced within STEP_SETTLE of open-market time of the last recorded change are measured from the same base (line 253): fuzz over 1-8 steps of up to 1% each spaced 0-3 h, scheduled now or 5 min ahead: every total > SMALL_STEP froze (pendingRelease) and was Frozen (2000 runs). The base moves when the last change is 24 h old (STEP_SETTLE), without a print: see SMF-1 for the stalled-feed case."
  },
  {
   "id": "C3",
   "result": "holds",
   "evidence": "forceRelease requires forceId == freezeId (src/stocks/StockOracle.sol:291) and every large or pending-time sync does ++freezeId (line 267), cancelForce zeroes forceEta, and the multiplier must equal seenMultiplier and be settled (line 294). testFuzz_C3C5_randomOrderings (2000 seeds x 40 ops: small/large/back-to-base schedules now or 12-24 s ahead, stranger sync, governor propose/cancel, stranger forceRelease, warps of 0 s, 12 s, 1 h, 12 h, 24 h, 49 h, 3 d, 15 d): every successful forceRelease was for the freezeId of the live proposal, inside [eta, eta + 14 d], with the multiplier recorded."
  },
  {
   "id": "C4",
   "result": "holds",
   "evidence": "_settled returns ok=false on a revert or a return shorter than 32 bytes (lines 324-328, 336-339) and frozen() returns true when !ok (line 233); sync() reverts MultiplierPending (line 249). test_C4_unreadableMultiplierIsFrozen (mockCallRevert / 1-byte return on uiMultiplier and newUIMultiplier, 2000 runs): frozen, price Frozen, sync reverts, priced again once readable. Exit while unreadable is the issuer's (an issuer action, accepted)."
  },
  {
   "id": "C5",
   "result": "refuted",
   "evidence": "The invariant the code keeps, checked over random orderings (testFuzz_C3C5_randomOrderings, 2000 x 40 ops, passes): (I) !pendingRelease => |seen - base| <= SMALL_STEP x base, and (II) uiMultiplier != newUIMultiplier || uiMultiplier != seen || pendingRelease => frozen. Routes that move the base: constructor (203-204), sync line 253 (time-based), forceRelease line 297; release: sync 262 and forceRelease 295. (I)+(II) are not sufficient for soundness because the base can move on time alone (SMF-1). ONE invariant that covers every route: 'whenever price() succeeds, every multiplier recorded since the older priced round (t1) is within SMALL_STEP of the current one' = the base is never newer than t1. Smallest replacement: record the base only when the feed has printed both priced legs after syncedAt (t1 > syncedAt) instead of STEP_SETTLE, and keep forceRelease (Safe) as the only other base writer; then (I) with base <= multiplier at t1 implies the property."
  }
 ],
 "holds": [
  {
   "property": "P1 (frozen from the block a change is scheduled until sync records it; <= SMALL_STEP released by sync; larger frozen until the Safe's 48 h forced release, expiry 14 d, same freeze only)",
   "tried": "testFuzz_C3C5_randomOrderings (2000 seeds x 40 ops incl. several ops in one block (0 s warp), consecutive blocks (12 s), schedules now/12 s/24 s ahead, back-to-base changes while pending, forceRelease by a stranger in front of/after sync): invariant (II) frozen while scheduled/unrecorded/pending never failed; P3-style sync-revert while settled never seen. testFuzz_C1C2 (2000 runs) for split and chained steps; C4 test. Existing suite test/unit/StockOracleMultiplier.t.sol covers 1% strict bound, weekend not settling, expiry and cancel. Holds except the stale-leg mispricing reported under P2 (SMF-1)."
  },
  {
   "property": "P2",
   "tried": "see SMF-1 (fails under a feed stall inside MAX_AGE). With the feed printing within STEP_SETTLE the fuzz C1C2 and the existing testFuzz_O8_smallStepMispricesByAtMostTheStep hold."
  },
  {
   "property": "P3 (sync never reverts leaving no exit)",
   "tried": "random orderings: sync never reverted while settled across random small steps, doublings, halvings and back-to-base changes; openTime(0, now) returns max (MarketCalendar2.sol:138, MAX_SPAN 14 days) so the first sync cannot revert; base 0 handled (line 259). Fails only on overflow (SMF-2, info)."
  },
  {
   "property": "Writers/readers of pendingRelease, freezeId, forceId, forceEta, syncedAt, seenMultiplier, baseMultiplier (grep src/ and script/)",
   "tried": "All writers are in src/stocks/StockOracle.sol (constructor 203-204, sync 253-267, proposeForce 275-276, cancelForce 282, forceRelease 295-297); readers: frozen() 231-233 -> price() 211 (Morpho). No other src/script contract writes or calls sync/frozen/forceRelease (MarketHoursFeed.sol has its own separate seenMultiplier, not this mechanism). governor = cfg.governor (script/deploy/StageChain.sol:57), no deployer power in StockOracle."
  }
 ],
 "notRun": [
  "[fork]/[data]: whether the 4663 feeds actually print under a multiplier change within 24 h of open-market time, and the stall frequency: NOT RUN (no RPC read made). SGOV step data quoted only from the earlier submission ec9fe0d5 (not re-read)."
 ]
}