{
 "item": "core-redeemer",
 "commit": "ff1c192b3798542997f600091f2dc73ff05e4c40",
 "forge": "forge 1.9.0 (--use solar, solc 0.8.38)",
 "verdict": "findings",
 "findings": [
  {
   "id": "core-redeemer-F1",
   "severity": "info",
   "title": "An issuer pause of the collateral token makes redeem revert with the token's error, not NothingRedeemed/NotRedeemable, so P3's closed list of reverts does not hold",
   "property": "P3",
   "claim": "P3: for a caller whose maxFee and minCollateralOut fit it reverts otherwise only when no visited position can pay (NothingRedeemed) or the type is not redeemable (NotRedeemable)",
   "files": [
    "src/LedgerSettlement.sol:97",
    "src/Redeemer.sol:123",
    "src/Redeemer.sol:128"
   ],
   "sequence": "1) A borrower opens a healthy position on a redeemable, priced type. 2) The collateral's issuer pauses transfers (the threat model lists issuers that pause). 3) A holder calls redeem(ilk, amt, maxFee=1e18, maxPositions=10, minOut=0).",
   "expected": "Under P3 as written, the redemption either fills or reverts with NothingRedeemed or NotRedeemable.",
   "actual": "redeemPosition sends the redeemer's collateral with a plain Join(c.join).exit(to, collateralOut) (LedgerSettlement.sol:97). Only the Treasury's share is wrapped in try/catch (_toTreasury). The token's revert ('paused') unwinds the whole redemption. Test result: [FAIL: P3: other revert] at the first fuzz input. No money is lost: positions, fee and base rate are unchanged. But the type's peg floor is closed for as long as the pause lasts, and the property's list of reverts is incomplete. A redeemer the issuer blocklisted fails the same way, since redeem pays only msg.sender.",
   "reachableAtDeploy": true,
   "fix": "Either state the issuer-pause or blocklist revert in P3 and the README known issues, or make the payout non-blocking: try the exit, and on failure skip the position (taken = 0) so that NothingRedeemed is the revert.",
   "test": {
    "source": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.38;\n\nimport {IERC20} from \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport {System} from \"../utils/System.sol\";\nimport {MockERC20, MockFeed} from \"../utils/Mocks.sol\";\nimport {ParametersBase} from \"../../src/ParametersBase.sol\";\nimport {Redeemer} from \"../../src/Redeemer.sol\";\nimport {Adjust} from \"../../src/interfaces/IPositions.sol\";\n\ncontract PausableToken is MockERC20 {\n    bool public paused;\n    constructor() MockERC20(\"P\", 18) {}\n    function setPaused(bool p) external { paused = p; }\n    function _update(address f, address t, uint256 v) internal override {\n        require(!paused || f == address(0) || t == address(0), \"paused\");\n        super._update(f, t, v);\n    }\n}\n\n/// P3: a caller whose maxFee and minCollateralOut fit, on a priced redeemable type with a position that can pay,\n/// reverts with neither NothingRedeemed nor NotRedeemable while the collateral's issuer pauses transfers.\ncontract RedeemPauseTest is System {\n    bytes32 constant T = \"PT\";\n    PausableToken tok;\n    MockFeed feed;\n    address b = makeAddr(\"b\");\n    address dave = makeAddr(\"dave\");\n\n    function setUp() public {\n        vm.warp(1_800_000_000);\n        tok = new PausableToken();\n        feed = new MockFeed(2000e18);\n        feed.setMaxAge(3650 days);\n        _deploySystem(IERC20(address(new MockERC20(\"v1\", 18))));\n        _addIlk(T, address(tok), feed, feed, address(0), address(0), true, _risk(1.4e18, 1e30));\n        params.seal();\n        tok.mint(b, 1000e18);\n        vm.prank(b);\n        tok.approve(address(ledger), type(uint256).max);\n        vm.prank(b);\n        ledger.open(T, 0, Adjust(int256(100e18), int256(50_000e18), 0.05e18, 0, 0, false, type(uint256).max, address(0)));\n        vm.prank(b);\n        usd.transfer(dave, 10_000e18);\n        vm.warp(block.timestamp + 3 hours);\n    }\n\n    function testFuzz_issuerPauseRevertsRedemption(uint256 amt) public {\n        amt = bound(amt, 1e18, 10_000e18);\n        tok.setPaused(true);\n        (bool priced,) = (pricer.quote(T).priced, 0);\n        assertTrue(priced);\n        vm.prank(dave);\n        try redeemer.redeem(T, amt, 1e18, 10, 0) {\n            emit log(\"redeemed\");\n        } catch (bytes memory err) {\n            bytes4 sel = bytes4(err);\n            assertTrue(sel == Redeemer.NothingRedeemed.selector || sel == Redeemer.NotRedeemable.selector, \"P3: other revert\");\n        }\n    }\n}\n",
    "ran": true,
    "result": "forge test --use solar --match-path test/scratch/RedeemPause.t.sol: [FAIL: P3: other revert; counterexample: args=[210994037]] testFuzz_issuerPauseRevertsRedemption(uint256) (runs: 0). Suite result: FAILED. 0 passed; 1 failed"
   }
  }
 ],
 "claims": [
  {
   "id": "C1",
   "result": "holds",
   "evidence": "[data] NOT RUN: the recorded Chainlink rounds were not replayed, so the sheet's step figures (README:874-878) are taken as given and not re-verified. Code bound (Redeemer.sol:135,142): the fee is floor + decayedBase + amount/feeBase/d, and each redemption raises the base by redeemed/feeBase/d. Both divide by feeBase(), which a mint from an earlier transaction cannot raise (testFuzz_feeBaseNotDiluted: mint up to 50M, then redeem in the same block or up to 3599 s later; fee and base rise are never below their values on the pre-mint supply). One actor's take on a step of net gain g' (step - 0.5% floor - 0.1% sale): one redemption gives at most g'^2*S*d/4. Splitting into many redemptions in one transaction gives at most g'^2*S*d/2, which is Liquity's split bound and still the base-rate bound. testFuzz_splitVsWhole (2-20 parts) shows a split never beats the whole by more than half the ramp. With g = 2.16% (the sheet's largest ETH step) and the beta divisor 16 (script/DeployConfig.sol BLUE_REDEEM_DIVISOR), R* = 0.25*S, which exceeds the ETH line (50k of a 300k chain line). So in the beta the binding limit is the type's redeemable debt, not the base rate: about 50k*(1.56% - 0.52%), roughly $520 per type per step. The base then rises by about 1% and halves every ~12 h. Per-type base rates (Redeemer natspec) let correlated types (ETH, wstETH) each be taken on the same step. No route found that avoids the fee or the base-rate rise: self-redemption pays it, splitting pays it, and a mint-dilution is blocked by feeBase except in the launch window README:629-631 states."
  },
  {
   "id": "C2",
   "result": "holds",
   "evidence": "testFuzz_walkMatchesModel and testFuzz_walkYieldLiq: 8 positions with tied rates, then 10 random ops (setRate in and out of cooldown with random or wrong hints, partial and full repay, reopen at a new rate, permissionless harvest, partial liquidation to a target buffer, accrual over 0-3 days, several transactions per block). After every op: the list is ascending by recorded rate and a position is listed iff its recorded debt != 0. Then a random-price redemption is compared to an exact model of the walk (per-position taken, collateral out, Treasury fee); 1000 runs each, PASS. Every writer of p.rate/p.debt (_record) is followed by _relist (Ledger.sol:172,305; LedgerSettlement.sol:96,173,257), except partial liquidation, which keeps rate and listing. Hints only select between _valid and _walk (SortedPositions.sol:126,135), and redeem takes none."
  },
  {
   "id": "C3",
   "result": "holds",
   "evidence": "Redeemer.sol:141-142 (fee) and :132,135 (base rise) read only ImdUSD.feeBase(). feeBase is constant inside one transaction, including after the interest mint inside redeemPosition (_noteStart runs once per transaction), so the fee read before the loop and supplyBefore read after it are the same figure."
  },
  {
   "id": "C4",
   "result": "holds",
   "evidence": "LedgerSettlement.sol:76-82: a position is skipped only when debt==0 after harvest (nothing to pay), when collateral*payout < debt, or when its debt is at or under dust AND the remaining amount is below that debt. A dust-sized position is fully redeemed when the amount covers it, so 'skips a position at or under dust' is conditional. A position above dust whose remainder would fall under dust is cut to debt-dust, not skipped. maxPositions counts visited positions, skipped ones included. The walk model reproduces every pass-over; no other reason found in 2000 runs."
  },
  {
   "id": "C5",
   "result": "holds",
   "evidence": "LedgerSettlement.sol:93-98: the position loses gross = taken/payout (rounded down). The redeemer gets gross*(1-fee) (rounded down) and the remainder goes to _toTreasury (owedToTreasury when the Treasury is refused). testFuzz_selfRedeemPaysFee: a borrower redeeming their own first position for any amount from 1 wei to debt-dust sends at least gross*fee to the Treasury and the base rate does not fall. Rounding favours the borrower (gross rounds down) and the Treasury (out rounds down). Tiny redemptions with gross=0 burn imdUSD for nothing, which is equal to a repay and adds no fee-free base-rate pinning."
  }
 ],
 "holds": [
  {
   "property": "P1",
   "tried": "Walk model (both walk tests): out*payout <= redeemed, out = \u03a3 floor(floor(taken/payout)*(1-fee)), positions taken strictly in list order, nothing taken beyond maxPositions or after the amount is filled, and only from the type's own list (redeemable is fixed at addIlk; no setter in Parameters). testFuzz_newestFirst: three equal-rate opens with arbitrary hints are redeemed newest first; a same-rate setRate after the cooldown moves the position to the front; a partial redemption keeps its place. Payout is Pricer.sol:72/79 (max of agreeing legs, or the fresh higher spot past skew; a stale spot is ignored and the median used). test/scratch/RedeemerProps.t.sol (7 fuzz tests, FOUNDRY_FUZZ_RUNS=1000, all PASS: testFuzz_walkMatchesModel, testFuzz_walkYieldLiq, testFuzz_newestFirst, testFuzz_feeBaseNotDiluted, testFuzz_pulseGrace, testFuzz_selfRedeemPaysFee, testFuzz_splitVsWhole). Mutation check: removing the underwater skip (LedgerSettlement.sol:76) or the reinsert on a rate change (LedgerBase.sol _relist) makes both walk tests FAIL, so the model really constrains the code."
  },
  {
   "property": "P2",
   "tried": "testFuzz_feeBaseNotDiluted (1000 runs): borrow 1e18..50M in one transaction, then feeFor and redeem from 0 to 3599 s later. The fee is >= floor+base+amount/S0/d and the stored base >= base+redeemed/S0/d, where S0 is the supply before the borrow. Exception, known and quoted: README:629-631 'A record of 0 reads as no record: with no genesis mint (seed 0), for the first 1-2 h of each chain's launch ... feeBase() equals circulating(), so a fresh mint counts at once.' Two-transaction round trips through fee-free routes lower the base (more fee), as README:620-628 states."
  },
  {
   "property": "P3",
   "tried": "testFuzz_pulseGrace (1000 runs; silences 0-3 h, with or without a poke in between): redeem reverts SequencerGrace exactly when Pulse.inGrace() (Pulse.sol:58), and a passing redemption never leaves a grace open. The check (Redeemer.sol:112) comes before the Ledger's poke. Unpriced or zero payout: Redeemer.sol:115. Exception: F1 (issuer pause or blocklist reverts with the token's error)."
  },
  {
   "property": "P4",
   "tried": "Walk model with random prices (80-120%), dust 100e18, yield harvests and partial liquidations: every touched position ends with debt 0 or >= dust, and with debt > 0 it keeps collateral > 0 (algebra: collateral*payout >= debt*1e18 before, so the remaining collateral times payout is >= (debt-taken)*1e18). Collateral drop is exactly floor(taken*1e18/payout) (whole on principal; rounding favours the borrower)."
  }
 ],
 "notRun": [
  "C1 [data]: the Chainlink round replay (Ethereum block 26552986) was not re-run; the figures are the sheet's/README's",
  "Fork tests: none needed for this item; all tests are local (test/utils/System.sol rig)"
 ]
}