{
 "item": "stable-relist-band-gov",
 "commit": "ff1c192b3798542997f600091f2dc73ff05e4c40",
 "forge": "forge 1.8.3 (older than 1.9: no --use solar); solc 0.8.38 via_ir (installed), forge test --offline --match-path test/scratch/RelistBandGov.t.sol",
 "verdict": "findings",
 "findings": [
  {
   "id": "SRBG-1",
   "severity": "info",
   "title": "SET_BAND to a new feed drops the old feed's round history: a matured apply (anyone) opens minting in the same block over a <=0 / out-of-band round the old feed printed inside the reopen delay that no poke recorded",
   "property": "P3, P4 (and C1: a third route that opens minting)",
   "claim": "C1, C3",
   "files": [
    "src/peg/StableModule.sol:988",
    "src/peg/StableModule.sol:991",
    "src/peg/StableModule.sol:627",
    "src/peg/StableModule.sol:633",
    "src/peg/StableModule.sol:690"
   ],
   "sequence": "1) Safe proposes SET_BAND|1 to a new feed nf (48 h). 2) The leg's current feed prints answer 0 (or 0.97), then 1.00 an hour later; nobody pokes, so bandClosed stays false. mint reverts OutOfBand (the walk sees the 0 round). 3) Anyone applies SET_BAND|1 in front of a mint: _apply writes l.feed = nf and leaves bandClosed/goodSince untouched; _price(l,true) now walks only nf's rounds, so mintOpen is true and mint succeeds in that block, 1 h after the 0 round with reopenDelay 6 h.",
   "expected": "A round answer <= 0 (or out of band) of the leg's feed inside the reopen delay keeps minting closed whatever kind is applied in front (P3/P4).",
   "actual": "mintOpen(USDS) == true right after the apply; the old feed's history is no longer read and nothing (bandClosed) carried it. A poke before the apply would have closed the band and SET_BAND keeps bandClosed (C3 holds), so the gap is only when no one poked. Money at risk only if the new feed does not show the same event (minting at min($1, new answer)) up to the daily bucket.",
   "reachableAtDeploy": false,
   "fix": "In SET_BAND's apply, when the feed changes, set (bandClosed, goodSince) = (true, 0) (or require the old feed's walk to pass at apply), so minting reopens only after poke sees the new feed good for reopenDelay.",
   "test": {
    "source": "// test/scratch/RelistBandGov.t.sol, contract RelistBandGovTest is StableBase (test/utils/StableKit.sol), setUp(){ _setUpStable(); USDS = address(usds); }\n    /// minting in the same block: the old feed's history is no longer read and nothing recorded it.\n    function test_P3_setBandToANewFeedDropsTheOldFeedsZeroRound() public {\n        MockLiveAggregator nf = new MockLiveAggregator(8, 1e8);\n        _propose(abi.encode(SET_BAND | 1, address(nf), uint32(25 hours), uint16(100), uint32(6 hours), bytes4(0)));\n        _pass(40 hours);\n        nf.push(1e8);\n        usdsFeed.push(1e8);\n        _pass(7 hours);\n        usdsFeed.push(0); // the leg's feed answers 0\n        _pass(1 hours);\n        usdsFeed.push(1e8);\n        assertFalse(mod.mintOpen(USDS), \"held on the old feed\");\n        vm.prank(stranger);\n        mod.applyPending(SET_BAND | 1);\n        assertFalse(mod.mintOpen(USDS), \"P3: a <=0 round 1 h ago (delay 6 h) no longer holds minting\");\n    }",
    "ran": true,
    "result": "[FAIL: P3: a <=0 round 1 h ago (delay 6 h) no longer holds minting] test_P3_setBandToANewFeedDropsTheOldFeedsZeroRound() (gas: 1142726). Same route with an out-of-band 0.97 old round: test_C1_otherRoutesOpenMinting asserts mintOpen true after the apply [PASS]."
   }
  }
 ],
 "claims": [
  {
   "id": "C1",
   "result": "refuted",
   "evidence": "The flags halted / bandClosed are cleared only by REOPEN's apply (StableModule.sol:999, after _settle()==0 at :998) and poke (:302-303). But minting also opens with neither: (a) SET_BAND applied by anyone over an unpoked out-of-band or <=0 old feed (SRBG-1; test_C1_otherRoutesOpenMinting PASS asserting the open, test_P3_setBandToANewFeedDropsTheOldFeedsZeroRound FAIL); (b) state checks that clear themselves: a donation lifting R >= minted after an unpoked vault fall (_sound, :704; same test, by design: real backing), a freeze lifting, an unreadable vault reading again, ADD_LEG of a never-listed stable (starts open, :907 halts only relistings). Only (a) bypasses the reopen delay."
  },
  {
   "id": "C2",
   "result": "holds",
   "evidence": "Other single vault reads: poke's _snap at a one-block dip books a loss and halts (known README:867 'A one-block dip of a listed vault (latent)'); _harvest at a spike books at most maxYieldBps x booked x dt / year (rate cap, :808); REOPEN's _validate _snap dip only reverts BadConfig (slot kept, retried later); mint's liquid read only moves the fee curve (round trip >= feeMin). SET_YIELD's apply does not check what withdraw(all) paid (:981): test_C2_setYieldApplyAgainstAShortPayingVault [PASS] shows a vault paying 100 short is not halted at apply, minting closes on R<minted and the next poke books exactly that loss and halts (same end state as _pull's short pay). Not reachable at deploy (sUSDS)."
  },
  {
   "id": "C3",
   "result": "holds",
   "evidence": "SET_BAND's apply (:988-993) writes feed/maxAge/band/delay/feedDec only. test_C3_setBandKeepsTheCloseAndWalksTheNewFeed [PASS]: bandClosed and goodSince identical across the apply; poke reopens 6 h after the old-feed goodSince; mint still refused by the NEW feed's 0.98 round inside the delay and opens 6 h later. The converse gap (nothing recorded before the apply) is SRBG-1."
  },
  {
   "id": "C4",
   "result": "not-checked",
   "evidence": "[data] NOT RUN: no archive RPC used in this run. From code: _price closes at a 25th round inside reopenDelay (MAX_ROUNDS 24, :635) and at age > maxAge (deploy 1 days + 1 hours, DeployConfig.sol:230/233); a heartbeat late by > 1 h closes minting while the peg holds (liveness only, mint refuses; redeem reads no feed). Early reopen: only an unreadable round (new phase, README:1067) or SRBG-1."
  },
  {
   "id": "C5",
   "result": "holds",
   "evidence": "_price (:634-642) ends as good only at a round with at == 0 (call failed / short returndata / no time, :640) or at the first round at or before cut (the round in force at the window start, itself band-checked); id == 0 and k == MAX_ROUNDS end as OUT of band. test_C5_walkStops [PASS]: the round in force at the cut is checked, exactly at the cut it drops out. A gas-starved getRoundData (staticcall(gas()), :659) cannot fake at == 0: the caller keeps 1/64 (< ~300 gas for a ~15k-gas proxy read), far below what the rest of mint needs."
  },
  {
   "id": "C6",
   "result": "holds",
   "evidence": "Known as written (README:861). Bound: test_C6_sequencerGapBound [PASS]: a pre-halt answer 20 h old mints at ~$1 up to the leg's dailyCap (bucket full after the gap, :746), then only the refill dailyCap/24 per hour, and stops at maxAge (25 h). At deploy: USDC (Eth) 25,000/day, USDS 12,500, USDG (4663) 12,500, Base USDC 12,500 (DeployConfig.sol:230,233,576,775); loss <= minted x depeg, <= dailyCap x (1 + h/24) x depeg until the feed prints or maxAge. Not worse than written."
  }
 ],
 "holds": [
  {
   "property": "P1",
   "tried": "testFuzz_P1_relistOrderings (256 runs x 24 random steps): after reportLoss(0,all), ADD_LEG relisting, REOPEN|0, SET_BAND|0, SET_CAPS|0, SET_CURVE|0, SET_YIELD|0 all queued BEFORE the relisting, applied by a stranger in any order interleaved with exits (held imdUSD), pokes (settle), mints and 0-3 h steps; invariants: every successful REOPEN left owed==0; every USDC mint was on a leg with a successful REOPEN; once relisted, old leg minted 0 / adapter 0, new leg halted and mintOpen false; sum of legs' minted == hub outstanding. test_P1_bothOrders: REOPEN|0 refused while owed, reopened after the row is settled, then the relisting refused (BadConfig); relisting first: REOPEN|0 refused UnknownKind, new leg MintClosed. halted=false is written only at :999; legIndex only at :908; _validate re-runs at apply (GovernedByKind.applyPending). All PASS."
  },
  {
   "property": "P2",
   "tried": "test_P2_nothingReentersDuringSetYieldApply: an adapter whose withdraw re-enters mint, redeem, poke, rebalance, harvest, recover, applyPending(SET_CAPS|1, SET_CURVE|1, SET_YIELD|1, SET_BAND|1, REOPEN|1, ADD_LEG) and applyPending() with matured proposals queued: 13 tries, 0 succeeded; the whole 30,000 came home. Lock taken at :980 around the only mutating external call (:981); assets()/harvest reads are staticcalls; _apply refuses inside a guarded call (:945). PASS."
  },
  {
   "property": "P3",
   "tried": "testFuzz_P3_nonPositiveRoundHolds (256 runs): 0-10 in-band rounds at random 1 s-3 h gaps, a round answering any value <= 0, 1-12 later in-band rounds at random gaps, optionally a matured SET_BAND (same feed) applied by a stranger in front; whenever the bad round is still in force after now - reopenDelay, mintOpen false and mint reverts OutOfBand. PASS. Fails only when the feed itself is replaced (SRBG-1)."
  },
  {
   "property": "P4",
   "tried": "Same fuzzes with every kind applied in front (P1 fuzz: six kinds in random order; P3 fuzz: SET_BAND in front; C3 test: SET_BAND over a closed band), from an empty relisted leg and a fresh one. Holds except SET_BAND to a new feed (SRBG-1)."
  }
 ],
 "notRun": [
  "C4 [data]: the four stable feeds' round histories (no archive RPC run)",
  "--use solar (forge 1.8.3 has no solar; compiled with solc 0.8.38)"
 ]
}