{
 "item": "fixed-limits-fees",
 "commit": "ff1c192b3798542997f600091f2dc73ff05e4c40",
 "forge": "forge 1.9.0 (--use solar, solc 0.8.38)",
 "verdict": "holds",
 "findings": [],
 "claims": [
  {
   "id": "C1",
   "result": "holds",
   "evidence": "issuedSinceAffirm is written only at src/spokes/FixedLoans.sol:253 (open) and src/spokes/FixedLoans.sol:572 (_affirm, also via lowerAndAffirm :591); SET_LIMITS apply (:642-643) does not reset it, and lowerSurgeLimit below it makes the next open revert Surge (:250). Any apply sets affirmedAt=0 (:633), so after a raise opens are closed (PriceStale, :656) until the Safe affirms. Test testFuzz_walk (3000 runs x 160 steps; open greedy at openRoom, warps of 0/1/12 s/1 day-1/1 day/7 days/random, stranger applyPending, lowerDaily/lowerSurge/lowerLendPrice, affirm and lowerAndAffirm up to many times in one block, full repay by a stranger) plus invariant_bucket_surge_price_fee (500 runs x 150 depth): for every affirm period, sum of debt opened <= the largest surgeLimit in force in that period, and over many affirms the total stays under the leaky-bucket bound (resetting the surge count opens no room the bucket has not refilled). PASS. A stranger's apply forces a re-affirm (new surge period), but only the Safe's affirm resets the count (accepted; NatSpec :64 'only `affirm` resets the surge count')."
  },
  {
   "id": "C2",
   "result": "holds",
   "evidence": "_allowance/_allowanceAt written only at src/spokes/FixedLoans.sol:221 (ctor, empty), :252 (open, a-debt at now) and :642 (SET_LIMITS apply: checkpointed with available() at the OLD limit before the new limits are written, :643). lowerDailyLimit (:531) does not checkpoint, so time since the last checkpoint accrues at the lower rate and available() caps at the new limit (:469): conservative. A raise is validated again at apply against the limits then in force (:614) and every lower drops a pending SET_LIMITS (:532,:541). testFuzz_C2_raiseInFrontNoTopUp (5000 runs: wait 48h..10d, new limit 1e3..1e12 imdUSD/day, stranger applies in front, affirm in the same block, then 0..2 days): available() unchanged by apply and affirm, then refills exactly min(newD, before + newD*dt/1 day). PASS. The walk/invariant check every pair of opens i<=j: sum debt <= Dmax*(1 + (tj-ti)/1 day), Dmax the largest dailyLimit in force in [ti,tj]; PASS, tightest slack 0-1 wei (the bound is reached, never exceeded). Per-open flooring of D*dt/1 day loses < 1 wei per open, against the borrower."
  },
  {
   "id": "C3",
   "result": "holds",
   "evidence": "open lends at lendPrice (_lendable src/spokes/FixedLoans.sol:661); lendPrice can exceed the affirmed price only through a SET_LEND_PRICE apply, which zeroes affirmedAt (:633) so open reverts PriceStale (:656) until affirm copies the price (:574); lowerLendPrice/lowerAndAffirm only lower it (:524). So the open price is always min(now, affirmed). extend uses min(lendPrice, _affirmedPrice) explicitly (:444, :329), minimums checked on both sets (:326-328). Walk/invariant asserted on every successful open debt == floor(assets*lendPrice/1e18) and lendPrice <= the last affirmed price: PASS."
  },
  {
   "id": "C4",
   "result": "holds",
   "evidence": "[data] RAN locally (no RPC needed; fixture test/fixtures/fixed-loans/replay.json at this commit): forge test --use solar --match-path test/unit/FixedLoansReplay.t.sol: 4/4 PASS (f04, f05 no loss; f06 ~21,200 ppm, f07 ~79,100 ppm within tolerance). Could not show a loss at f04: scratch test_f04_everyHour opens the real contract at EVERY recorded hour with lend = 0.4 x the trailing 30-day low 2 days old (1121 loans, same terms/buyer model as the fixture test): walked away 0, losses 0, worst 0 ppm. Over 2026-08-17..11-21 IMD never fell to 0.4x its trailing 30-day low within a loan's 15 days. This is a statement about that recorded window only."
  }
 ],
 "holds": [
  {
   "property": "P1 leaky bucket (new debt in any closed window T <= largest dailyLimit in force x (1 + T/1 day))",
   "tried": "invariant_bucket_surge_price_fee (500 runs x depth 150, 10 actions incl. stranger applyPending of SET_LIMITS/SET_LEND_PRICE in front of any act) and testFuzz_walk (3000 seeds x 160 steps, greedy drains at openRoom, several opens per block, 1 s / 1 day-1 / 1 day edges): all pairs of opens checked; PASS, slack down to 0-1 wei. Writers of the state: _allowance/_allowanceAt src/spokes/FixedLoans.sol:221,:252,:642; _limits :219,:534,:543,:643; readers available() :466, openRoom :473. No writer in script/ (script/deploy/StageCore.sol:123 constructs; script/launch/SafeBatch.s.sol:251 calls lowerAndAffirm). The bucket is continuous (no UTC-day reset), so hour and day edges add nothing. The deployer holds no power here: the governor is cfg.governor, fixed in the constructor (StageCore.sol:123-126), and the bucket starts empty (:221)."
  },
  {
   "property": "P1 surge limit between two affirms",
   "tried": "Same walk/invariant: per affirm period, issued <= max surgeLimit in force; lowerSurgeLimit below issued (Surge revert :250); SET_LIMITS raise + affirm in one block. PASS."
  },
  {
   "property": "P1 each open pays a fee >= 1 wei",
   "tried": "_checkTerms refuses feeBps == 0 (:736) at ctor and SET_TERMS (:610), minDebt >= 1e18 (:747), fee rounded up (:256), so fee >= 1e14 wei. Asserted on every open in the walk/invariant and in testFuzz_noLoopGain. PASS. (The earlier 157d860f feeBps=0 info is closed by :736.)"
  },
  {
   "property": "P2 fees and rounding favour the protocol on open, extend, repay (no loop gains)",
   "tried": "testFuzz_noLoopGain (3000 runs): open (shares 2e23..1e33), up to 12 random partial repays by the borrower, extends at random points in the window (sometimes after a lowerLendPrice, so part of the debt is paid down with no collateral released), then a full repay. Asserted: collateral per unit of debt never falls (sharesOut floor :291), extend releases no shares, every fee >= 1, the borrower gets exactly her shares back and pays exactly the fees, fees reach treasury + reserve in full (_payFee :676-682 splits fee with no remainder), hub outstanding 0 at the end. PASS. open: debt floored (:661), fee ceiled (:256); extend: fits floored (:329), fee ceiled (:338)."
  },
  {
   "property": "P3 P1 across any rule-abiding SET_LIMITS / lower applied in front, loans live",
   "tried": "The walk and invariant apply matured SET_LIMITS/SET_LEND_PRICE as a stranger at random points between opens and affirms, interleave lowerDaily/lowerSurge/lowerLendPrice/lowerAndAffirm, with live loans and stranger full repays; testFuzz_C2 applies a raise in front and affirms in the same block. extend mints nothing (outstanding never rises in testFuzz_noLoopGain), so live loans cannot draw on the bucket. PASS."
  }
 ],
 "notRun": [
  "No [fork] claim in this sheet; C4 is [data] and RAN against the fixture at the commit (no RPC)."
 ]
}