{
 "item": "fixed-forfeit-take",
 "commit": "ff1c192b3798542997f600091f2dc73ff05e4c40",
 "forge": "forge 1.8.3 (older than 1.9): `--use solar` answers `solc \"solar\" does not exist`; solc 0.8.38 is not installed, and installing a newer forge was declined on this machine. So the tests ran under solc 0.8.30 on a scratch copy of src/spokes/FixedLoans.sol, src/hub/{MinterHub,IMinterHub}.sol, src/ImdUSD.sol, src/GovernedByKind.sol, src/TransientReentrancyGuard.sol, src/interfaces/IFeed.sol and test/utils/{FixedBase,Mocks,MockStakedImd,HubKit}.sol, with only `pragma solidity 0.8.38` rewritten to 0.8.30 (via_ir, optimizer 200, cancun, isolate). As a check, the repo's own test/unit/FixedLoansP8.t.sol passed 8/8 on that copy. Caveat: these results are not from the pinned compiler.",
 "verdict": "holds",
 "findings": [],
 "claims": [
  {
   "id": "C1",
   "result": "holds",
   "evidence": "Confirmed as framed; no unrepaid path beyond what is designed. close (src/spokes/FixedLoans.sol:415-424) sets saleDebt -= debt, sends l.shares to the Treasury and calls _end -> hub.reportLoss(debt) (src/spokes/FixedLoans.sol:703-706). MinterHub.reportLoss (src/hub/MinterHub.sol:197-205) moves min(debt, outstanding) = debt (P4 holds) to bad_s. _coverFromReserve (MinterHub.sol:619-647) burns reserve first against non-exotic rows' bad (FL is exotic: script/launch/SafeBatch.s.sol:129), then up to the FL loss. Bound: the reserve pays at most min(available reserve, unpaid debt), and the unpaid debt is <= the FL row outstanding <= the row cap (3,000e18 PLACEHOLDER, script/DeployConfig.sol:481). The unsold shares went unsold at the floor price floorBps x lotDebt (50% at deploy), so they are likely worth < floor. The reserve then pays at least (1 - floorBps) x debt that the shares cannot repay, which is the designed loss. The shares can be sold: Treasury._apply pays any asset out after its 48 h timelock (src/Treasury.sol: `else IERC20(asset).safeTransfer(to, amount);`), and repayReserve is open to anyone (MinterHub.sol:260-268). Paths not repaid by shares: (a) a lot sold out below its debt reports debt - paid in take (src/spokes/FixedLoans.sol:394-395, 408-409) and sends the Treasury no shares; (b) the operator duty (README:1095, \"Operator duty (the operator runbook, not public): the Safe sells the unsold shares a lot sends to the Treasury and repays the reserve with `repayReserve`\") is off-chain; (c) any excess of share value over debt at close stays with the Treasury, not the borrower (a P2 design choice; floor <= debt, so this needs no buyer at a profitable floor). test_C1_reserveVsLot: debt 450e18, reserve 4.5e18 all burned at close, floor 225e18 unsold; sold-out path paid 225e18, loss 225e18 reported, Treasury got 0 shares. RAN: forge 1.8.3, solc 0.8.30 (pragma-patched scratch copy, via_ir, cancun), --fuzz-runs 2000; harness = repo test/utils/FixedBase.sol (real ImdUSD + MinterHub, FL row 1 exotic cap 10,000, deploy terms 8x/6h/72h/floor 50%).\n    // ---- C1: what the reserve pays at close vs the lot; the sold-out-below-debt path leaves no shares\n function test_C1_reserveVsLot() public {\n uint256 id = _open(alice, 450e18);\n uint256 id2 = _open(carol, 450e18);\n _toForfeit(id);\n fl.forfeit(id);\n FixedLoans.Loan memory l = fl.loan(id);\n uint256 r0 = hub.reserve();\n _pass(l.saleLength);\n // floor price of the WHOLE lot = floorBps x debt: nobody bought there\n uint256 floorPrice = Math.mulDiv(l.lotDebt, l.floorBps, 10_000, Math.Rounding.Ceil);\n fl.close(id);\n uint256 paidByReserve = r0 - hub.reserve();\n emit log_named_uint(\"reserve before\", r0);\n emit log_named_uint(\"reserve paid\", paidByReserve);\n emit log_named_uint(\"debt\", l.debt);\n emit log_named_uint(\"lot floor price (unsold)\", floorPrice);\n assertEq(paidByReserve, Math.min(r0, l.debt));\n // path 2: sold out below the debt, nothing reaches the Treasury\n fl.forfeit(id2);\n _pass(l.saleLength - 1);\n uint256 t0 = simd.balanceOf(treasury);\n (uint256 bad0, uint256 cov0) = (_row().bad, _row().covered);\n vm.prank(bob);\n (, uint256 p) = fl.take(id2, type(uint256).max, type(uint256).max);\n emit log_named_uint(\"sold out for\", p);\n emit log_named_uint(\"loss reported\", _row().bad + _row().covered - bad0 - cov0);\n assertEq(simd.balanceOf(treasury), t0, \"no shares to repay the reserve with\");\n _assertBooks();\n }"
  },
  {
   "id": "C2",
   "result": "holds",
   "evidence": "Gas grief only, as README:725 says (\"a 1-share take in front reverts a partial take sized to the 10% rest (take-all always runs);\"). The rule is at src/spokes/FixedLoans.sol:396-397. Take-all is clamped at src/spokes/FixedLoans.sol:689 and lands in paysOff or rest==0, so it always runs. The griefer pays ceil(p/lotShares) >= 1 wei per raw share at the lot price, which a partial take cannot change (P3). The victim can take a slightly smaller partial or take-all. Nothing locks the lot or mis-prices it. testFuzz_C2_oneShareInFront (2000 runs, any debt 50-900e18, any time from 3 half-lives to the end, 1-3 shares in front): the exact-rest partial reverts TooSmall, take-all lands, matches quoteTake and ends the lot DONE with the books equal. RAN: forge 1.8.3, solc 0.8.30 (pragma-patched scratch copy, via_ir, cancun), --fuzz-runs 2000; harness = repo test/utils/FixedBase.sol (real ImdUSD + MinterHub, FL row 1 exotic cap 10,000, deploy terms 8x/6h/72h/floor 50%).\n    // ---- C2: a 1-share take in front reverts a partial sized to the 10% rest; take-all always runs, at any time\n function testFuzz_C2_oneShareInFront(uint256 d, uint256 dt, uint256 pre) public {\n uint256 id = _forfeited(alice, bound(d, 50e18, 900e18));\n FixedLoans.Loan memory l = fl.loan(id);\n _pass(bound(dt, 3 * l.halfLife, l.saleLength - 1)); // price at or under the debt: partials do not pay off\n uint256 exact = l.shares - (uint256(l.lotShares) * 1000 + 9_999) / 10_000; // leaves exactly the 10% rest\n (,, bool off) = fl.quoteTake(id, exact);\n vm.assume(!off);\n vm.prank(stranger);\n fl.take(id, bound(pre, 1, 3), type(uint256).max);\n vm.prank(bob);\n vm.expectRevert(FixedLoans.TooSmall.selector);\n fl.take(id, exact, type(uint256).max);\n (uint256 qt, uint256 qp,) = fl.quoteTake(id, type(uint256).max);\n vm.prank(bob);\n (uint256 t, uint256 p) = fl.take(id, type(uint256).max, type(uint256).max);\n assertEq(t, qt);\n assertEq(p, qp);\n assertEq(fl.loan(id).state, 3);\n _assertBooks();\n }"
  },
  {
   "id": "C3",
   "result": "holds",
   "evidence": "repay needs state OPEN (src/spokes/FixedLoans.sol:278). forfeit flips OPEN->SALE (src/spokes/FixedLoans.sol:366-369). take needs SALE (src/spokes/FixedLoans.sol:384). Exactly one of them lands. test_C3_repayVsForfeit(bool), both orders in the forfeit second (expiry+grace+1, one block): repay-first makes forfeit revert NotOpen and take revert NotInSale; forfeit-first makes the stranger's full repay revert NotOpen and take pays exactly the debt. The FL row outstanding ends at 0 with bad+covered 0 (no double count). RAN: forge 1.8.3, solc 0.8.30 (pragma-patched scratch copy, via_ir, cancun), --fuzz-runs 2000; harness = repo test/utils/FixedBase.sol (real ImdUSD + MinterHub, FL row 1 exotic cap 10,000, deploy terms 8x/6h/72h/floor 50%).\n    // ---- C3: a stranger's full repay vs forfeit/take in the forfeit block, both orders\n function test_C3_repayVsForfeit(bool repayFirst) public {\n uint256 id = _open(alice, 300e18);\n _toForfeit(id);\n FixedLoans.Loan memory l = fl.loan(id);\n if (repayFirst) {\n vm.prank(stranger);\n fl.repay(id, type(uint256).max);\n vm.expectRevert(FixedLoans.NotOpen.selector);\n fl.forfeit(id);\n vm.expectRevert(FixedLoans.NotInSale.selector);\n fl.take(id, type(uint256).max, type(uint256).max);\n } else {\n fl.forfeit(id);\n vm.prank(stranger);\n vm.expectRevert(FixedLoans.NotOpen.selector);\n fl.repay(id, type(uint256).max);\n vm.prank(bob);\n (, uint256 p) = fl.take(id, type(uint256).max, type(uint256).max);\n assertEq(p, l.debt);\n }\n assertEq(_row().outstanding, 0, \"burned once\");\n assertEq(_row().bad + _row().covered, 0, \"no loss\");\n _assertBooks();\n }"
  },
  {
   "id": "C4",
   "result": "holds",
   "evidence": "forfeit (src/spokes/FixedLoans.sol:364-374) reads only the loan. take/close read only loan fields (_lotPrice src/spokes/FixedLoans.sol:715-732 uses lotDebt, floorBps, halfLife, saleStart, startMultipleBps, all copied into the loan) and call hub.burn/reportLoss. Neither function reads affirmedAt, _terms, _limits, paused or lendPrice. MinterHub.burn (MinterHub.sol:185-193) checks only indexOf and outstanding >= amount (true by P4). reportLoss clamps. ADD_SPOKE refuses a re-added spoke (MinterHub.sol `indexOf[a.spoke] != 0` in _check), so no hub act removes or resets the row. ImdUSD.burn has no pause or blocklist (src/ImdUSD.sol:152-156). test_C4_noBrakeBlocksExits: with hub.freeze(1), markLoss(1,900e18), lowerCap(1,0), lowerExoticCap(0), lowerTotalCap(0), fl.pause(), fl.lowerLendPrice(0) all on, three forfeits, a pay-off take, a partial take and two closes all run, the books stay equal and outstanding ends at 0. RAN: forge 1.8.3, solc 0.8.30 (pragma-patched scratch copy, via_ir, cancun), --fuzz-runs 2000; harness = repo test/utils/FixedBase.sol (real ImdUSD + MinterHub, FL row 1 exotic cap 10,000, deploy terms 8x/6h/72h/floor 50%).\n    // ---- C4: every hub / governance brake on, exits still run\n function test_C4_noBrakeBlocksExits() public {\n uint256 a = _open(alice, 300e18);\n uint256 b = _open(alice, 300e18);\n uint256 c = _open(alice, 300e18);\n _toForfeit(a);\n vm.startPrank(governor);\n hub.freeze(1);\n hub.markLoss(1, 900e18);\n hub.lowerCap(1, 0);\n hub.lowerExoticCap(0);\n hub.lowerTotalCap(0);\n fl.pause();\n fl.lowerLendPrice(0);\n vm.stopPrank();\n fl.forfeit(a);\n fl.forfeit(b);\n fl.forfeit(c);\n vm.prank(bob);\n fl.take(a, type(uint256).max, type(uint256).max); // pays off\n uint256 half = fl.loan(b).shares / 10;\n vm.prank(bob);\n fl.take(b, half, type(uint256).max);\n _pass(fl.loan(c).saleLength);\n fl.close(b);\n fl.close(c);\n _assertBooks();\n assertEq(_row().outstanding, 0);\n }"
  }
 ],
 "holds": [
  {
   "property": "P1 A lot brings at most its debt; rest to the borrower in that tx; DONE",
   "tried": "Code: _quoteTake (src/spokes/FixedLoans.sol:688-699) clamps paid to debt when ceil(p*want/lotShares) >= debt and gives k = floor(debt*lotShares/p) (at least 1, at most want) shares. take (src/spokes/FixedLoans.sol:392-407) sets DONE, zeros the loan, saleDebt -= debt, burns debt, and sends the rest to l.borrower. l.shares >= 1 for every loan: a partial repay releases floor(shares*amount/debt) < shares. testFuzz_P1_P3_twoTakes (2000 runs): any debt, any second of the sale, any first take, then a second take in the same or the next block. Checked: paid <= debt over both takes; a pay-off pays exactly the debt; borrower balance gain == shares - taken; spoke holds 0 shares; take == quoteTake; only TooSmall refuses. testFuzz_P4_sequence also checks P1 on each of 40 random ops. RAN: forge 1.8.3, solc 0.8.30 (pragma-patched scratch copy, via_ir, cancun), --fuzz-runs 2000; harness = repo test/utils/FixedBase.sol (real ImdUSD + MinterHub, FL row 1 exotic cap 10,000, deploy terms 8x/6h/72h/floor 50%).\n    // ---- P1 + P3 + P4(quote): any two takes in one block, any time in the sale\n function testFuzz_P1_P3_twoTakes(uint256 d, uint256 dt, uint256 s1, uint256 s2, bool sameBlock) public {\n uint256 id = _forfeited(alice, bound(d, 50e18, 900e18));\n FixedLoans.Loan memory l0 = fl.loan(id);\n _pass(bound(dt, 0, l0.saleLength - 2));\n s1 = bound(s1, 1, l0.shares);\n (uint256 qt, uint256 qp, bool qo) = fl.quoteTake(id, s1);\n // P3: what x shares cost after a partial take == before it (same block), unless the debt clamp bites\n uint256 x = bound(s2, 1, l0.shares);\n (, uint256 px0, bool o0) = fl.quoteTake(id, x);\n uint256 aliceS = simd.balanceOf(alice);\n vm.prank(bob);\n try fl.take(id, s1, type(uint256).max) returns (uint256 t, uint256 p) {\n assertEq(t, qt, \"quote taken\");\n assertEq(p, qp, \"quote paid\");\n FixedLoans.Loan memory l = fl.loan(id);\n assertLe(p, l0.debt, \"P1: never more than the debt\");\n if (qo) {\n assertEq(p, l0.debt, \"pays exactly the debt\");\n assertEq(l.state, 3, \"DONE\");\n assertEq(simd.balanceOf(alice) - aliceS, l0.shares - t, \"P1: rest to borrower\");\n assertEq(simd.balanceOf(address(fl)), 0);\n } else if (l.state == 2) {\n if (!sameBlock) _pass(1);\n if (sameBlock && x <= l.shares) {\n (, uint256 px1, bool o1) = fl.quoteTake(id, x);\n if (!o0 && !o1) assertEq(px1, px0, \"P3: per-share price unchanged by a partial take\");\n }\n uint256 y = bound(s2, 1, l.shares);\n (uint256 qt2, uint256 qp2, bool qo2) = fl.quoteTake(id, y);\n vm.prank(carol);\n try fl.take(id, y, type(uint256).max) returns (uint256 t2, uint256 p2) {\n assertEq(t2, qt2);\n assertEq(p2, qp2);\n assertLe(p + p2, l0.debt, \"P1 over two takes\");\n if (qo2) assertEq(p + p2, l0.debt);\n } catch (bytes memory e) {\n assertEq(bytes4(e), FixedLoans.TooSmall.selector);\n }\n }\n } catch (bytes memory e) {\n assertEq(bytes4(e), FixedLoans.TooSmall.selector, \"only the 10% rest rule refuses\");\n assertFalse(qo);\n }\n _assertBooks();\n }"
  },
  {
   "property": "P2 forfeit only after expiry+grace; no take before forfeit; no close before sale end; close (anyone) sends unsold shares to Treasury and reports the whole unpaid debt once",
   "tried": "Code: src/spokes/FixedLoans.sol:367 (strict >), 384-385 (take while ts < saleStart+saleLength), 418 (close while ts >= that end), so there is no gap and no overlap; 420-423 (DONE before the external calls; nonReentrant). testFuzz_P2_edges (2000 runs, 0-3 floor-price takes of 10% each): forfeit at expiry+grace reverts NotExpired and at +1 succeeds; a second forfeit reverts NotOpen; take before forfeit reverts NotInSale; close at end-1 reverts SaleNotOver; take at end reverts SaleOver; the stranger's close adds exactly loan.debt to the row's bad+covered and l.shares to the Treasury; a second close reverts NotInSale. RAN: forge 1.8.3, solc 0.8.30 (pragma-patched scratch copy, via_ir, cancun), --fuzz-runs 2000; harness = repo test/utils/FixedBase.sol (real ImdUSD + MinterHub, FL row 1 exotic cap 10,000, deploy terms 8x/6h/72h/floor 50%).\n    // ---- P2: the clock edges, close once, the whole debt reported\n function testFuzz_P2_edges(uint256 d, uint256 nTakes) public {\n uint256 id = _open(alice, bound(d, 50e18, 900e18));\n FixedLoans.Loan memory l = fl.loan(id);\n vm.expectRevert(FixedLoans.NotInSale.selector);\n fl.take(id, 1, type(uint256).max);\n vm.warp(uint256(l.expiry) + l.grace);\n vm.expectRevert(FixedLoans.NotExpired.selector);\n fl.forfeit(id);\n vm.warp(uint256(l.expiry) + l.grace + 1);\n vm.prank(stranger);\n fl.forfeit(id);\n vm.expectRevert(FixedLoans.NotOpen.selector);\n fl.forfeit(id);\n // small takes at the floor (leave >= 10%), then the sale ends\n vm.warp(uint256(l.expiry) + l.grace + 1 + l.saleLength - 1);\n nTakes = bound(nTakes, 0, 3);\n for (uint256 i; i < nTakes; ++i) {\n vm.prank(bob);\n fl.take(id, l.shares / 10, type(uint256).max);\n }\n vm.expectRevert(FixedLoans.SaleNotOver.selector);\n fl.close(id);\n vm.warp(uint256(l.expiry) + l.grace + 1 + l.saleLength);\n vm.expectRevert(FixedLoans.SaleOver.selector);\n fl.take(id, 1, type(uint256).max);\n FixedLoans.Loan memory s = fl.loan(id);\n uint256 rowBad = _row().bad + _row().covered;\n uint256 tre = simd.balanceOf(treasury);\n vm.prank(stranger);\n fl.close(id);\n assertEq(_row().bad + _row().covered - rowBad, s.debt, \"P2: the WHOLE unpaid debt is the hub loss\");\n assertEq(simd.balanceOf(treasury) - tre, s.shares, \"P2: unsold shares to the Treasury\");\n vm.expectRevert(FixedLoans.NotInSale.selector);\n fl.close(id);\n _assertBooks();\n }"
  },
  {
   "property": "P3 lot price per share is a function of time only; a partial take never changes what the next buyer pays per share",
   "tried": "Code: _lotPrice reads only lotDebt, floorBps, halfLife, startMultipleBps and saleStart, all fixed at forfeit or at open/extend (src/spokes/FixedLoans.sol:369-370, 669-673). extend needs OPEN, so no governance act after forfeit reaches a lot. Pro-rata cost is ceil(p*taken/lotShares) with lotShares fixed. testFuzz_P1_P3_twoTakes, same-block branch: quoteTake(x) after a partial take == quoteTake(x) before it whenever neither hits the debt clamp. Per-call ceil rounding (1 wei per take) is README:725 as written."
  },
  {
   "property": "P4 Sum of open and lot debts == hub outstanding at all times; quoteTake equals what take charges",
   "tried": "Writers (src/ and script/ grep: only FixedLoans touches openDebt, saleDebt or lot fields, and no script calls forfeit/take/close). open +debt (hub.mint +debt), repay -amount (burn), extend -over (burn), forfeit moves openDebt->saleDebt, take -paid (burn) or -debt (burn debt, or burn paid + reportLoss loss), close -debt (reportLoss debt). The hub FL row outstanding changes only via mint/burn/reportLoss/restore with msg.sender = the spoke, and FL never calls restore. quoteTake and take share _quoteTake; quoteTake reverts outside the sale exactly where take does. testFuzz_P4_sequence (2000 runs x 40 ops: open x4, warp 0 (same block) or up to 2 days, forfeit, random/1-share/take-all takes, close, stranger full repay) asserts FixedBase._assertBooks after every op: sum == outstanding, per-state sums, spoke holds exactly the loans' shares. Plus take == quoteTake in the P1, C2 tests. RAN: forge 1.8.3, solc 0.8.30 (pragma-patched scratch copy, via_ir, cancun), --fuzz-runs 2000; harness = repo test/utils/FixedBase.sol (real ImdUSD + MinterHub, FL row 1 exotic cap 10,000, deploy terms 8x/6h/72h/floor 50%).\n    // ---- P4 + everything: random sequences of open/repay/forfeit/take/close/warp(0 = same block)\n function testFuzz_P4_sequence(uint256 seed) public {\n uint256[] memory ids = new uint256[](4);\n for (uint256 i; i < 4; ++i) ids[i] = _open(i % 2 == 0 ? alice : carol, 60e18 + (uint256(keccak256(abi.encode(seed, i))) % 180e18));\n for (uint256 k; k < 40; ++k) {\n uint256 r = uint256(keccak256(abi.encode(seed, k, \"op\")));\n uint256 id = ids[r % 4];\n uint256 op = (r >> 8) % 6;\n uint256 amt = r >> 16;\n if (op == 0) _pass(amt % 3 == 0 ? 0 : amt % 2 days);\n else if (op == 1) { vm.prank(stranger); try fl.forfeit(id) {} catch {} }\n else if (op == 2) {\n FixedLoans.Loan memory l = fl.loan(id);\n uint256 want = l.shares == 0 ? 1 : 1 + amt % l.shares;\n if (amt % 5 == 0) want = type(uint256).max;\n uint256 debt = l.debt;\n uint256 bs = simd.balanceOf(l.borrower);\n vm.prank(bob);\n try fl.take(id, want, type(uint256).max) returns (uint256 t, uint256 p) {\n assertLe(p, debt, \"P1\");\n FixedLoans.Loan memory n = fl.loan(id);\n if (p == debt) {\n assertEq(n.state, 3);\n assertEq(simd.balanceOf(l.borrower) - bs, l.shares - t, \"rest back\");\n }\n } catch {}\n } else if (op == 3) { try fl.close(id) {} catch {} }\n else if (op == 4) { vm.prank(stranger); try fl.repay(id, type(uint256).max) {} catch {} }\n else { vm.prank(bob); try fl.take(id, 1, type(uint256).max) {} catch {} }\n _assertBooks();\n }\n }"
  }
 ],
 "notRun": [
  "No [fork]/[data] claims in this sheet: none RUN.",
  "Not run under solc 0.8.38 or `--use solar` (forge 1.8.3 here; see forge field).",
  "Earlier findings fetched from api.imd.fun/jobs/{157d860f-dc22-4fa5-9ce4-a1683d3da28c,4d56c477-4266-4883-bf12-a7783bc8b0c8}/submissions (base commits 5719b27, ab136ba). None of them targets forfeit/take/close beyond the C2 info (the 1-share take in front, take-all immune), which is now README:725."
 ]
}