{"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":"62b92eb1-7472-440c-ad76-2e55e66a1f65","kind":"audit","nodes":[{"acceptedSubmissionHash":"f44a6683ea43c3612bcb854b79fe3150ae464703abab401695aa4be03ad040cd","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":"ea455c8941a508eba2bbfe6933a3fbeee48057647ff30094c65721bf314cb2fb","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":"e493c2e6727a615468e54fbe3c56067cc6bfdf0a3bffe66115eebe8ed68a2a8f","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":"001d4806deeac7e060bbf2e4e8eb505ddfa0461009d2e2d31278be31f6eb116b","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":"011c2e6f46c296037dc87d4f860642fc48dd0bf294b83697bba0d3cd4f04a348","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/Parameters.sol, src/ParametersBase.sol, src/ParametersRules.sol, src/GovernedByKind.sol, src/managers/RateManager.sol, script/deploy/, and REVIEW THE DESIGN of the beta as run: README trust model, script/DeployConfig.sol BetaConfig, src/Parameters*.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{BatchItems,OtherImdLines,PostLowerDepth,RateStep,ResumeTypes},Core,PanelParams,CapAndSlots}.t.sol'` (measured: about 3.7 GB peak, 5 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-2, re-run each original proof for these files against this commit and say whether it still fails, and why.\n\nQuestions 3-5: 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. Governance: a malformed BATCH item is refused at propose; lowerOtherImdLines is refused while the depth line binds; postLowerDepth never raises from 0 without ImdDepth; RateManager keeps its step reference after a target of 0; SET_KEEPER, SET_BRIDGE and adding to a full sleeve are refused at propose. What still passes propose and fails at apply?\n2. M6: a resumed deploy stage compares every kept piece (types, feeds, risk, backstop pieces) with the config. Can a resume still adopt something it should not?\n3. OPERATIONS. Every action the protocol needs someone to take (depth samples and the daily poke, relaying attestations, ticks, marks and liquidations, seat pokes and auctions, starting collateral auctions, buffer and LP rules, Backstop conversions): what missing it costs after 1 hour, 1 day, 1 week; lazily inside user transactions, an on-chain tip, or a chore; who pays for oracle answers (whoever needs the update, or an on-chain asker).\n4. ROOM TO GROW. Size margins (ParametersRules 82 bytes left, Allocator about 2.6 KB, Ledger about 2.2 KB), one pending proposal per kind, adding types, chains and modules without a redeploy. Where does v2 run out first, and what should change before mainnet?\n5. GOVERNANCE AS THE LAST KEY. A 2-of-3 Safe holds every raise, the freezer and the only mint path for a bridge. The worst a compromised or absent Safe does within the timelocks, and the cheapest hardening.\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":"3b6b2a80120ecb9919a9fe355821cff019b2c1387e7a4bdbdf4c757fdca67fb4","previousHash":"0000000000000000000000000000000000000000000000000000000000000000","projectId":"62b92eb1-7472-440c-ad76-2e55e66a1f65","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":"52596","feedbackHash":"d21d3fa063a81b3633c53159ff3b264a848157e4175ae722dd821bfd39d5578c","nodeKey":"audit_economics","submissionHash":"f44a6683ea43c3612bcb854b79fe3150ae464703abab401695aa4be03ad040cd","tag1":"review:submission","tag2":"acceptance-v2","value":1},{"agentId":"52615","feedbackHash":"fd0f15203fffbe5090ed5b81c385c5d4f5aeada35678c0c566a9ad04546e211b","nodeKey":"audit_flow","submissionHash":"ea455c8941a508eba2bbfe6933a3fbeee48057647ff30094c65721bf314cb2fb","tag1":"review:submission","tag2":"acceptance-v2","value":1},{"agentId":"51154","feedbackHash":"e0c54c5f89b7dcde02946992559426f4b5ce77840cb0f7d159dd8be1884ec87e","nodeKey":"audit_judge","submissionHash":"e493c2e6727a615468e54fbe3c56067cc6bfdf0a3bffe66115eebe8ed68a2a8f","tag1":"review:submission","tag2":"acceptance-v2","value":1},{"agentId":"51878","feedbackHash":"a904ef510557488d107280dac78c7083cda798ee5a987c686ecca404e0bd27ad","nodeKey":"audit_math","submissionHash":"001d4806deeac7e060bbf2e4e8eb505ddfa0461009d2e2d31278be31f6eb116b","tag1":"review:submission","tag2":"acceptance-v2","value":1},{"agentId":"51879","feedbackHash":"1b4fc7001054e9e730111f97736228a7bbba65a916f58d1659bd8e818d5222d1","nodeKey":"audit_permissions","submissionHash":"011c2e6f46c296037dc87d4f860642fc48dd0bf294b83697bba0d3cd4f04a348","tag1":"review:submission","tag2":"acceptance-v2","value":1}],"site":null,"snapshotHash":"7dabcfc0f1fc4d96350045b114d4bc4f0d84c30ebedb6d25f4ec66de62ef2df4","state":"completed","submissions":[{"artifacts":[],"attempt":1,"bundleHash":null,"device":"2a6239e0c1b8c774","findings":[{"citation":"resolved","description":"Q1 (what still passes propose and fails at apply). _validate checks ADD_DEPTH_SAMPLER only for `imdDepth != 0 && sampler.code.length != 0` and SET_DEPTH_LEG only for both-or-neither zero. ImdDepth.addSampler (src/feeds/ImdDepth.sol:82-88) also refuses a sampler whose (manager, poolId) is already listed and a 7th sampler (MAX_SAMPLERS = 6); ImdDepth.setLeg (102-104) refuses a leg or price address with no code. None of these are checked at propose, so each such proposal is accepted, waits 48h, reverts at apply (BadSampler / TooManySamplers) and, as in GovernedByKind, keeps its slot and its kind lock until the governor cancels it (14 days if nobody notices). This is the same class wave 1 fixed in this file for ADD_SLEEVE_ILK (SLEEVE_MAX_TOKENS / SLEEVE_MAX_ILKS, oracle mapping), SET_KEEPER and SET_BRIDGE (AlreadySet), and the file's own comment states the rule: refuse at propose what the apply would fail on. Realistic trigger in the beta: the operator re-deploys a sampler for an already listed pool with new band settings (as the config did for the v1 imdUSD/IMD pool) and proposes it without first calling removeDepthSampler; 48h later the apply fails and the correct ADD_DEPTH_SAMPLER cannot be proposed (ProposalPending) until cancel. Impact is governance liveness only (a lost 48h cycle on the depth-gated sIMD line), no funds: low. Reachable with BetaConfig (3 samplers listed at genesis; the leg kind is unused but proposable). Smallest fix: in _validate, for ADD_DEPTH_SAMPLER read IDepthPool(sampler).manager()/poolId() and compare with imdDepth.samplers() (revert OutOfBounds on a match or when samplers().length >= 6, the constant written out like SLEEVE_MAX_ILKS); for SET_DEPTH_LEG require leg.code.length != 0 && price.code.length != 0 when non-zero. Cost: ParametersRules has 82 bytes of EIP-170 room left (measured on this build: 24,494 bytes), so the sampler checks (~150 bytes) do not fit without freeing space; the cheapest room is moving the 24-selector _movesTokens deny-list into SeatJoin.setClaimRule (the contract that owns the rule), which frees roughly 700 bytes, or exposing a single `canAdd(address) view` on ImdDepth and calling it.","line":76,"path":"src/ParametersRules.sol","proof":"// SPDX-License-Identifier: MIT\npragma solidity 0.8.26;\n\nimport \"forge-std/Test.sol\";\nimport {Parameters} from \"src/Parameters.sol\";\nimport {ParametersBase} from \"src/ParametersBase.sol\";\nimport {ImdDepth} from \"src/feeds/ImdDepth.sol\";\nimport {IFeed} from \"src/interfaces/IFeed.sol\";\n\ncontract PfCode {}\n\ncontract PfJoin {\n    address public token;\n    address public ledger;\n    constructor(address t, address l) { token = t; ledger = l; }\n}\n\n/// A DepthSampler as ImdDepth.addSampler sees it: its pool manager and pool id.\ncontract PfSampler {\n    address public manager;\n    bytes32 public poolId;\n    constructor(address m, bytes32 id) { manager = m; poolId = id; }\n    function depth() external pure returns (uint256) { return 0; }\n}\n\n/// ADD_DEPTH_SAMPLER and SET_DEPTH_LEG are validated at propose only for \"has code\" (and both-or-neither), while\n/// ImdDepth.addSampler refuses a duplicate pool and a 7th sampler, and ImdDepth.setLeg refuses a code-less leg. Each passes\n/// propose, waits 48h, then always fails at apply and holds its slot (and lock) until the governor cancels. Expected (the\n/// wave-1 rule the same file applies to ADD_SLEEVE_ILK, SET_KEEPER and SET_BRIDGE: \"refuse at propose what the apply would\n/// fail on\"): OutOfBounds / BadConfig at propose.\ncontract ProofDepthSamplerProposeTest is Test {\n    Parameters params;\n    ImdDepth depth;\n    address gov = address(0xA11CE);\n    address manager = address(new PfCode());\n    bytes32 constant SIMD = \"SIMD\";\n\n    function setUp() public {\n        params = new Parameters(gov, address(this));\n        address ledger = address(new PfCode());\n        params.wire(ledger, address(new PfCode()));\n        address coll = address(new PfCode());\n        IFeed f = IFeed(address(new PfCode()));\n        ParametersBase.Config memory c = ParametersBase.Config(\n            coll, address(new PfJoin(coll, ledger)), f, f, IFeed(address(0)), address(0), address(0), IFeed(address(0)), true, false\n        );\n        ParametersBase.Risk memory r = ParametersBase.Risk({\n            mat: 1.5e18, chop: 0.2e18, cut: 0, chip: 0, rateFloor: 0.01e18, yieldFee: 0, skew: 0.02e18,\n            pegFloor: 0, line: 0, dust: 0, redeemFloor: 0.005e18, redeemDivisor: 1, redeemCap: 0\n        });\n        params.addGenesisIlk(SIMD, c, r);\n        params.setGenesisDepthRule(SIMD, 0.8e18, 80_100e18, 3_000e18, 0.2e18);\n        depth = new ImdDepth(address(params));\n        // the beta lists 3 samplers; list ImdDepth.MAX_SAMPLERS (6) so the \"full\" case is also reachable\n        address[] memory list = new address[](6);\n        for (uint256 i; i < 6; ++i) list[i] = address(new PfSampler(manager, bytes32(i + 1)));\n        params.setGenesisImdDepth(address(depth), list);\n        params.seal();\n    }\n\n    /// A sampler on a pool ImdDepth already lists (same manager + poolId: the operator re-deploys a sampler with new\n    /// band settings and proposes it without removing the old one).\n    function test_duplicatePoolSamplerIsRefusedAtPropose() public {\n        address dup = address(new PfSampler(manager, bytes32(uint256(1))));\n        bytes memory p = abi.encode(params.ADD_DEPTH_SAMPLER(), dup);\n        vm.prank(gov);\n        vm.expectRevert(ParametersBase.OutOfBounds.selector); // EXPECTED: refused at propose\n        params.propose(p);\n    }\n\n    /// A 7th sampler when ImdDepth holds MAX_SAMPLERS.\n    function test_seventhSamplerIsRefusedAtPropose() public {\n        address seventh = address(new PfSampler(manager, bytes32(uint256(7))));\n        bytes memory p = abi.encode(params.ADD_DEPTH_SAMPLER(), seventh);\n        vm.prank(gov);\n        vm.expectRevert(ParametersBase.OutOfBounds.selector); // EXPECTED: refused at propose\n        params.propose(p);\n    }\n\n    /// A swarm depth leg named by an address with no code (a typo, or a leg not yet deployed) with a priced ETH/USD feed.\n    function test_codelessDepthLegIsRefusedAtPropose() public {\n        bytes memory p = abi.encode(params.SET_DEPTH_LEG(), address(0xBAD), address(new PfCode()));\n        vm.prank(gov);\n        vm.expectRevert(ParametersBase.OutOfBounds.selector); // EXPECTED: refused at propose\n        params.propose(p);\n    }\n}","reproduction":"Beta-like state: Parameters sealed, depthIlk SIMD, ImdDepth set with 6 samplers (or the beta's 3). (a) governor proposes abi.encode(ADD_DEPTH_SAMPLER, S) where S has code and S.manager()/S.poolId() equal a listed sampler's: expected revert OutOfBounds at propose; actual: accepted, eta = now + 48h; applyPending(24) after 48h reverts ImdDepth.BadSampler (TooManySamplers when 6 are listed) and pendingOf(24).eta stays non-zero; a further propose(ADD_DEPTH_SAMPLER, correct) reverts ProposalPending. (b) governor proposes abi.encode(SET_DEPTH_LEG, 0xBAD (no code), ethUsdFeed): expected OutOfBounds at propose; actual accepted; applyPending(25) after 48h reverts BadSampler. Test: test/scratch/ProofDepthSamplerPropose.t.sol, run with `forge test --match-path 'test/scratch/*.t.sol'`: 3 tests FAIL on this commit with 'next call did not revert as expected' (propose accepted); they pass once propose refuses them.","severity":"low","snippet":"            (, address sampler) = abi.decode(payload, (uint8, address));\n            if (address(imdDepth) == address(0) || sampler.code.length == 0) revert OutOfBounds();\n        } else if (kind == SET_DEPTH_LEG) {\n            (, address leg, address price) = abi.decode(payload, (uint8, address, address));\n            if (address(imdDepth) == address(0) || (leg == address(0)) != (price == address(0))) revert OutOfBounds();","title":"ADD_DEPTH_SAMPLER and SET_DEPTH_LEG pass propose and always fail at apply (duplicate pool, 7th sampler, code-less leg); the held slot blocks the correct proposal until cancel"},{"citation":"resolved","description":"Q2 (can a resume still adopt something it should not): yes, for the measured-depth pieces. Step 6a compares each recorded DepthSampler with its spec (_samplerIs) and ImdDepth only by `params()`, then calls setGenesisImdDepth(imdDepth, list) only while `params.imdDepth()` differs from the recorded ImdDepth. The set of samplers ImdDepth actually lists is never compared with `list`. On a resume after a sampler spec changed (the config documents exactly such a swap: the stranded spacing-60 pool 0x5e0b.. replaced by the spacing-10 pool 0x617d..), the run first stops with Mismatch('DepthSampler'); the documented way on (DeployBase header: 'one with no code is deployed') is to clear that record entry and resume. The resume then deploys the new sampler, records it in d.samplers, skips setGenesisImdDepth because Parameters already names this ImdDepth, and seals. Result: ImdDepth still lists the dropped pool's sampler (a pool judged suspect or stranded keeps counting toward the depth the sIMD line is sized on), the config's sampler never counts, and the deployment record names a sampler that is not listed, so the launch verification built on the record is wrong. The same holds when the config adds a 4th pool before launch (d.samplers.length != n redeploys all four, none is listed). After the seal the only repair is removeDepthSampler (instant) plus ADD_DEPTH_SAMPLER (48h) per pool. Direction: a dropped pool kept = depth too high (the sIMD line sized on a pool the operator removed on purpose); a new pool missed = depth too low (fail-closed). Severity low: beta sIMD line 50k, governance can repair in 48h, and only a resumed stage reaches it; a single-run deploy does not. Reachable with BetaConfig on a resumed stage 4. Smallest fix (script only, no contract change): after building `list`, when `address(d.params.imdDepth()) == address(d.imdDepth)`, read d.imdDepth.samplers() and revert Mismatch('ImdDepth samplers') unless it equals `list` as a set (or, before the seal, add the missing ones through setGenesisImdDepth, which re-sets the same ImdDepth and adds samplers; duplicates revert BadSampler, so only add those not listed). About 8 lines.","line":299,"path":"script/deploy/StageGenesis.sol","proof":"// SPDX-License-Identifier: MIT\npragma solidity 0.8.26;\n\nimport \"forge-std/Test.sol\";\nimport {DeployTypes} from \"script/DeployConfig.sol\";\nimport {DeployBase} from \"script/deploy/DeployBase.sol\";\nimport {StageGenesis} from \"script/deploy/StageGenesis.sol\";\nimport {Parameters} from \"src/Parameters.sol\";\nimport {ParametersBase} from \"src/ParametersBase.sol\";\nimport {ImdDepth} from \"src/feeds/ImdDepth.sol\";\nimport {DepthSampler} from \"src/feeds/DepthSampler.sol\";\nimport {IFeed} from \"src/interfaces/IFeed.sol\";\nimport {PoolKey} from \"v4-core/src/types/PoolKey.sol\";\nimport {Currency} from \"v4-core/src/types/Currency.sol\";\nimport {IHooks} from \"v4-core/src/interfaces/IHooks.sol\";\n\ncontract PrCode {}\n\ncontract PrJoin {\n    address public token;\n    address public ledger;\n    constructor(address t, address l) { token = t; ledger = l; }\n}\n\ncontract PrToken {\n    function decimals() external pure returns (uint8) { return 18; }\n}\n\n/// The slice of a v4 PoolManager DepthSampler's constructor reads: slot0 through StateLibrary (extsload), non-zero price.\ncontract PrPoolManager {\n    function extsload(bytes32) external pure returns (bytes32) { return bytes32(uint256(1) << 96); }\n}\n\n/// Step 6a exactly as the launch runs it: the stage function on a deployment record `d`.\ncontract PrStage is StageGenesis {\n    function depthStage(DeployTypes.Config memory cfg, Deployed memory d) external returns (Deployed memory) {\n        _stageDepth(cfg, d);\n        return d;\n    }\n}\n\n/// Q2 (M6): `_stageDepth` compares each recorded DepthSampler with its spec and ImdDepth with Parameters, but never\n/// ImdDepth's LISTED samplers with the config: `setGenesisImdDepth(list)` runs only while `params.imdDepth()` differs. A\n/// resume after a sampler spec changed (the config documents such a swap: pool 0x5e0b.. replaced by 0x617d..) therefore\n/// deploys the new sampler, never lists it, keeps the dropped pool counting, records the new address, and seals.\ncontract ProofDepthResumeTest is Test {\n    PrStage h;\n    Parameters params;\n    address manager;\n    address imd;\n\n    function setUp() public {\n        h = new PrStage();\n        params = new Parameters(address(0x5AFE), address(h)); // the stage contract is the wirer, as the deployer EOA is\n        address ledger = address(new PrCode());\n        address usd = address(new PrCode());\n        vm.prank(address(h));\n        params.wire(ledger, usd);\n        address coll = address(new PrCode());\n        IFeed f = IFeed(address(new PrCode()));\n        ParametersBase.Config memory c = ParametersBase.Config(\n            coll, address(new PrJoin(coll, ledger)), f, f, IFeed(address(0)), address(0), address(0), IFeed(address(0)), true, false\n        );\n        ParametersBase.Risk memory r = ParametersBase.Risk({\n            mat: 1.5e18, chop: 0.2e18, cut: 0, chip: 0, rateFloor: 0.01e18, yieldFee: 0, skew: 0.02e18,\n            pegFloor: 0, line: 0, dust: 0, redeemFloor: 0.005e18, redeemDivisor: 1, redeemCap: 0\n        });\n        vm.prank(address(h));\n        params.addGenesisIlk(\"SIMD\", c, r);\n        manager = address(new PrPoolManager());\n        imd = address(new PrToken());\n    }\n\n    function _spec(int24 spacing) internal view returns (DeployTypes.SamplerSpec memory s) {\n        PoolKey memory key = PoolKey(Currency.wrap(address(0)), Currency.wrap(imd), 10_000, spacing, IHooks(address(0)));\n        s = DeployTypes.SamplerSpec({\n            currency0: address(0), currency1: imd, fee: 10_000, tickSpacing: spacing, hooks: address(0),\n            poolId: keccak256(abi.encode(key)), feed0: DeployTypes.NO_FEED, feed1: DeployTypes.NO_FEED,\n            bandBps: 1_500, maxDeviationTicks: 400, maxSteps: 4_096, soldIsToken0: false\n        });\n    }\n\n    function _cfg(int24 secondSpacing) internal view returns (DeployTypes.Config memory cfg) {\n        cfg.poolManager = manager;\n        cfg.depth.enabled = true;\n        cfg.depth.samplers = new DeployTypes.SamplerSpec[](2);\n        cfg.depth.samplers[0] = _spec(200);\n        cfg.depth.samplers[1] = _spec(secondSpacing);\n    }\n\n    function test_resumeListsTheConfigsSamplers() public {\n        // Run 1: two exit pools (spacing 200 and 60). ImdDepth lists both; Parameters names ImdDepth.\n        DeployBase.Deployed memory d;\n        d.params = params;\n        d = h.depthStage(_cfg(60), d);\n        ImdDepth depth = d.imdDepth;\n        address oldSecond = address(d.samplers[1]);\n        assertEq(depth.samplers().length, 2);\n\n        // The second pool is replaced in the config (spacing 10). A resume with the old record stops (Mismatch), so the\n        // operator clears that entry, as DeployBase's header says (\"one with no code is deployed\"), and resumes.\n        DeployTypes.Config memory cfg2 = _cfg(10);\n        vm.expectRevert(abi.encodeWithSelector(DeployBase.Mismatch.selector, \"DepthSampler\"));\n        h.depthStage(cfg2, d);\n        d.samplers[1] = DepthSampler(address(0));\n        d = h.depthStage(cfg2, d);\n        address newSecond = address(d.samplers[1]);\n        assertTrue(newSecond != oldSecond && newSecond.code.length != 0, \"a new sampler was deployed and recorded\");\n\n        // EXPECTED: ImdDepth lists what the config and the record name (the new pool), not the dropped one (or the stage\n        // stops with Mismatch). ACTUAL on this commit: ImdDepth still lists the dropped pool's sampler; the new one is\n        // recorded but never listed, and the stage goes on to seal().\n        address[] memory listed = depth.samplers();\n        bool hasNew;\n        bool hasOld;\n        for (uint256 i; i < listed.length; ++i) {\n            if (listed[i] == newSecond) hasNew = true;\n            if (listed[i] == oldSecond) hasOld = true;\n        }\n        assertTrue(hasNew, \"the config's sampler is not listed in ImdDepth\");\n        assertFalse(hasOld, \"the dropped pool's sampler still counts toward depth\");\n    }\n}","reproduction":"Run 1: cfg.depth.samplers = [A (spacing 200), B (spacing 60)], record d empty -> ImdDepth deployed, samplers A,B deployed, setGenesisImdDepth -> ImdDepth.samplers() == [A,B]. Config change: samplers = [A, C (spacing 10)]. Resume with d as recorded -> Mismatch('DepthSampler') (correct). Operator sets d.samplers[1] = address(0) and resumes. Expected: ImdDepth.samplers() == [A, C] (or a Mismatch stop). Actual: C is deployed and recorded in d.samplers[1]; ImdDepth.samplers() is still [A, B]; the stage continues to seal(). Test: test/scratch/ProofDepthResume.t.sol (a StageGenesis harness exposing _stageDepth, a stub PoolManager answering extsload with a non-zero price, DepthSampler and ImdDepth real), run with `forge test --match-path 'test/scratch/*.t.sol'`: FAILS on this commit with 'the config's sampler is not listed in ImdDepth'; passes once the stage compares or lists.","severity":"low","snippet":"        if (address(d.params.imdDepth()) != address(d.imdDepth)) {\n            g = gasleft();\n            d.params.setGenesisImdDepth(address(d.imdDepth), list);\n            _rec(\"params.setGenesisImdDepth\", g, CALL_DATA + 32 * n);\n        }","title":"Deploy resume (M6): _stageDepth never compares ImdDepth's listed samplers with the config; a sampler redeployed on a resume is recorded but never listed, and a dropped pool keeps counting toward depth"}],"hash":"001d4806deeac7e060bbf2e4e8eb505ddfa0461009d2e2d31278be31f6eb116b","nodeId":"a103a075-d3d9-4e6e-aef8-9065c0bcb823","outcome":"completed","summary":"## Result\n\nTwo reproducible defects, both low. Everything else this panel re-checked holds. The findings file `.imd-findings.json` holds both, with proof tests; the scratch tests are deleted and the tree is unchanged.\n\n**Build and test.** Foundry here is 1.8.3 (no `--use solar`), solc 0.8.26 via_ir. The panel glob ran once: 9 suites, 87 passed, 0 failed, 7m05s. The two proofs ran under `test/scratch/` with `forge test --match-path 'test/scratch/*.t.sol'` (2m23s incremental): 4 tests, all FAIL on this commit for the stated reason. Wave 1's public findings were read from the API for jobs cd9184ac, 17e4edf1 and 4384ebcc (full UUIDs resolved from `/jobs`).\n\n### Findings\n\n**F1 (low) ADD_DEPTH_SAMPLER and SET_DEPTH_LEG pass propose and always fail at apply.** `src/ParametersRules.sol:75-80` checks only \"has code\" (sampler) and both-or-neither zero (leg). `ImdDepth.addSampler` (`src/feeds/ImdDepth.sol:82-88`) also refuses a sampler on an already listed (manager, poolId) and a 7th sampler; `setLeg` (102-104) refuses a code-less leg or price. Each such proposal waits 48h, reverts at apply, and holds its slot and lock until the governor cancels, blocking the correct proposal (`ProposalPending`). Wave 1 fixed exactly this class in the same file for ADD_SLEEVE_ILK, SET_KEEPER and SET_BRIDGE. Trigger with BetaConfig: the operator re-deploys a sampler for a listed pool with new band settings and proposes it without `removeDepthSampler` first. Fix: check `imdDepth.samplers()` for the pool and for length 6, and code on both leg addresses. Cost: ParametersRules has 82 bytes left (measured 24,494), so this needs room first (see Q4).\n\n**F2 (low) Deploy resume adopts ImdDepth's sampler set without comparing it with the config.** `script/deploy/StageGenesis.sol:299-303` calls `setGenesisImdDepth(list)` only while `params.imdDepth()` differs. After a sampler spec change (the config itself documents replacing the stranded pool 0x5e0b.. by 0x617d..), the resume stops with `Mismatch(\"DepthSampler\")`; the documented way on is to clear the record entry. The resume then deploys the new sampler, records it, never lists it, keeps the dropped pool counting toward the sIMD depth, and seals. Repair after the seal is `removeDepthSampler` plus a 48h ADD_DEPTH_SAMPLER. Fix: ~8 script lines comparing `d.imdDepth.samplers()` with `list` (revert Mismatch, or add the missing ones before the seal).\n\n### Q1. Governance: what still passes propose and fails at apply\n\nRe-run of the wave-1 proofs against this commit, all now pass (the old failure no longer reproduces):\n\n| Test | Why it no longer fails |\n|---|---|\n| AuditW1BatchItems (3 tests) | `_validate` decodes SET_MIGRATOR_LINE and SET_DEPTH (`ParametersRules.sol:44,73`); `_touches` returns false for items under 64 bytes (`Parameters.sol:305`) |\n| AuditW1OtherImdLines | `lowerOtherImdLines` reverts while `depthLine() < stored line` (`Parameters.sol:216`) |\n| AuditW1PostLowerDepth | `(depthCap != 0 || imdDepth == 0) && depth >= depthCap` makes 0-with-no-ImdDepth a refused raise (`Parameters.sol:276-279`) |\n| AuditW1RateStep | the step reference is `lastCall[ilk] != 0`, not `prior != 0` (`RateManager.sol:180`) |\n| AuditW1ResumeTypes (3 tests) | `_sameIlk` hashes the whole Config and stored Risk (`StageTypes.sol:153-163`) |\n\nSET_KEEPER, SET_BRIDGE (`ParametersRules.sol:45-49`) and ADD_SLEEVE_ILK (lines 113-116) are refused at propose as described. What still passes propose and fails at apply, in order of consequence:\n\n- **ADD_DEPTH_SAMPLER duplicate pool or 7th sampler; SET_DEPTH_LEG with a code-less address** (F1, proved).\n- **A BATCH whose SET_RISK(sIMD) precedes its SET_DEPTH.** Items are applied in order and `_requireDepth` after SET_RISK reads `depthIMD()` capped by the OLD ceiling. The day-7 batch must put SET_DEPTH first, or the whole batch (keeper cap included) fails and costs another 48h. Not a code defect, but undocumented and easy to get wrong.\n- **SET_RISK on sIMD, SET_DEPTH_K up, SET_OTHER_IMD up** fail at a","treeHash":null,"usage":{"cachedInputTokens":2039313,"cost":{"source":"runtime","usdMicros":8276922},"inputTokens":386,"model":"claude-fable-5-1","outputTokens":67327,"runtime":"claude","turns":36,"wallClockMs":1714208}},{"artifacts":[],"attempt":1,"bundleHash":null,"device":"4faf975f1178e1f8","findings":[{"citation":"resolved","description":"Wave 1's rule for Parameters was: refuse at propose what the apply would fail on, so a mistaken proposal never holds its slot (and lock bits) for 48 h plus a cancel. Two depth kinds still miss checks that ImdDepth enforces at apply. SET_DEPTH_LEG (line 78-80) checks only that `leg` and `price` are both zero or both non-zero; ImdDepth.setLeg (src/feeds/ImdDepth.sol:102-104) also requires both to have code, so a leg address with no code (a typo, a feed not yet deployed) is accepted at propose and reverts BadSampler at apply. ADD_DEPTH_SAMPLER (line 75-77) checks only that the sampler has code; ImdDepth.addSampler (ImdDepth.sol:82-88) also refuses a sampler already listed, a second sampler on an already listed (manager, poolId), and a seventh sampler (MAX_SAMPLERS 6). Each such proposal passes propose, takes the kind's slot, and reverts at applyPending; the slot and its lock stay until the Safe cancels (GovernedByKind: an expired proposal still holds its slot). Reachable with BetaConfig: the beta lists three samplers at genesis and the depth leg is expected to be set post-launch through SET_DEPTH_LEG. Impact is operational only (a 48 h delay of the depth leg or a sampler listing), no funds move; the same class the wave-1 governance panel treated as low. Smallest fix (fits the 82 B left in ParametersRules only barely; see the size finding): in _validate, SET_DEPTH_LEG: `if (leg != address(0) && (leg.code.length == 0 || price.code.length == 0)) revert OutOfBounds();`; ADD_DEPTH_SAMPLER: call a new ImdDepth view `canAdd(sampler)` (or move the duplicate/pool/count checks into ImdDepth as a view that both setLeg/addSampler and the validation call), so the check costs one external call in Rules.","line":75,"path":"src/ParametersRules.sol","proof":"// SPDX-License-Identifier: MIT\npragma solidity 0.8.26;\n\nimport \"forge-std/Test.sol\";\nimport {Parameters} from \"src/Parameters.sol\";\nimport {ParametersBase} from \"src/ParametersBase.sol\";\nimport {ImdDepth} from \"src/feeds/ImdDepth.sol\";\nimport {IFeed} from \"src/interfaces/IFeed.sol\";\n\ncontract PfCode {}\n\ncontract PfJoin {\n    address public token;\n    address public ledger;\n    constructor(address t, address l) { token = t; ledger = l; }\n}\n\n/// A stub DepthSampler: what ImdDepth.addSampler reads.\ncontract PfSampler {\n    address public manager;\n    bytes32 public poolId;\n    constructor(address m, bytes32 id) { manager = m; poolId = id; }\n}\n\n/// Wave 2 re-check of \"refused at propose what the apply would fail on\": two depth kinds still pass `propose` and\n/// revert at `applyPending`, holding their slot (and lock bit) for the Safe to cancel.\n/// Each test: propose; if propose refuses (the fix), pass; else the apply must succeed. On this commit both applies revert.\ncontract ProofApplyFailsTest is Test {\n    Parameters params;\n    ImdDepth depth;\n    PfSampler listed;\n    address gov = address(0xA11CE);\n    address pm = address(new PfCode());\n    bytes32 constant SIMD = \"SIMD\";\n    uint8 constant ADD_DEPTH_SAMPLER = 24;\n    uint8 constant SET_DEPTH_LEG = 25;\n\n    function setUp() public {\n        params = new Parameters(gov, address(this));\n        address ledger = address(new PfCode());\n        params.wire(ledger, address(new PfCode()));\n        address coll = address(new PfCode());\n        IFeed f = IFeed(address(new PfCode()));\n        ParametersBase.Config memory c = ParametersBase.Config(\n            coll, address(new PfJoin(coll, ledger)), f, f, IFeed(address(0)), address(0), address(0), IFeed(address(0)), true, false\n        );\n        ParametersBase.Risk memory r = ParametersBase.Risk({\n            mat: 1.5e18, chop: 0.2e18, cut: 0, chip: 0, rateFloor: 0.01e18, yieldFee: 0, skew: 0.02e18,\n            pegFloor: 0, line: 0, dust: 0, redeemFloor: 0.005e18, redeemDivisor: 1, redeemCap: 0\n        });\n        params.addGenesisIlk(SIMD, c, r);\n        params.setGenesisDepthRule(SIMD, 0.8e18, 0, 0, 0);\n        depth = new ImdDepth(address(params));\n        listed = new PfSampler(pm, keccak256(\"pool-0\"));\n        address[] memory s = new address[](1);\n        s[0] = address(listed);\n        params.setGenesisImdDepth(address(depth), s);\n        params.seal();\n    }\n\n    function _proposeThenApply(bytes memory payload, uint8 kind) internal {\n        vm.prank(gov);\n        try params.propose(payload) {}\n        catch {\n            return; // refused at propose: the fix\n        }\n        assertTrue(params.locked() & (uint256(1) << kind) != 0, \"slot taken\");\n        vm.warp(block.timestamp + 48 hours);\n        params.applyPending(kind); // on this commit: reverts, the slot and its lock stay until the Safe cancels\n    }\n\n    /// SET_DEPTH_LEG names a leg with no code (a typo, a not-yet-deployed feed): propose only checks the zero pairing;\n    /// ImdDepth.setLeg checks code at apply.\n    function test_setDepthLegWithCodelessLegPassesProposeFailsApply() public {\n        address price = address(new PfCode());\n        _proposeThenApply(abi.encode(SET_DEPTH_LEG, address(0xBEEF), price), SET_DEPTH_LEG);\n    }\n\n    /// ADD_DEPTH_SAMPLER of a sampler already listed (or of another sampler on the same pool): propose checks code only;\n    /// ImdDepth.addSampler refuses both at apply.\n    function test_addDepthSamplerAlreadyListedPassesProposeFailsApply() public {\n        _proposeThenApply(abi.encode(ADD_DEPTH_SAMPLER, address(listed)), ADD_DEPTH_SAMPLER);\n    }\n\n    function test_addDepthSamplerSamePoolPassesProposeFailsApply() public {\n        PfSampler twin = new PfSampler(pm, keccak256(\"pool-0\"));\n        _proposeThenApply(abi.encode(ADD_DEPTH_SAMPLER, address(twin)), ADD_DEPTH_SAMPLER);\n    }\n}","reproduction":"Setup: Parameters with a depth-gated type, ImdDepth set at genesis with one sampler S0 (manager M, poolId P), sealed. (1) gov.propose(abi.encode(25, 0xBEEF, priceWithCode)) -> succeeds (expected: revert OutOfBounds). warp 48h; applyPending(25) -> reverts ImdDepth.BadSampler(); locked bit 25 stays set. (2) gov.propose(abi.encode(24, S0)) -> succeeds; applyPending(24) -> BadSampler(). (3) gov.propose(abi.encode(24, S1)) with S1.poolId == P and S1.manager == M -> succeeds; applyPending(24) -> BadSampler(). Test test/scratch/ProofApplyFails.t.sol: all three tests fail on this commit with `BadSampler()` (run: forge test --match-path test/scratch/ProofApplyFails.t.sol).","severity":"low","snippet":"        } else if (kind == ADD_DEPTH_SAMPLER) {\n            (, address sampler) = abi.decode(payload, (uint8, address));\n            if (address(imdDepth) == address(0) || sampler.code.length == 0) revert OutOfBounds();\n        } else if (kind == SET_DEPTH_LEG) {\n            (, address leg, address price) = abi.decode(payload, (uint8, address, address));\n            if (address(imdDepth) == address(0) || (leg == address(0)) != (price == address(0))) revert OutOfBounds();","title":"SET_DEPTH_LEG and ADD_DEPTH_SAMPLER still pass propose and revert at apply (codeless leg; sampler already listed or on a listed pool)"},{"citation":"resolved","description":"The M6 fix compares every KEPT piece with the config, and a recorded sampler whose spec differs stops the run (Mismatch(\"DepthSampler\"): verified). But two resume paths still diverge silently. (a) `if (d.samplers.length != n) d.samplers = new DepthSampler[](n);` (line 276) throws the whole recorded array away whenever the config's pool count differs from the record's (a fourth exit pool added before a resume, or a record that lost an entry), so every sampler is deployed afresh and recorded. (b) `setGenesisImdDepth` (lines 299-303) is the only genesis call that lists samplers in ImdDepth and it runs only while Parameters does not yet point at the ImdDepth. Together: the resumed run records n fresh samplers, ImdDepth keeps reading the old set (sampler 0 now exists twice, only the old copy listed; the added pool's sampler is not listed at all), nothing reverts, and the stage goes on to `seal()`. After the seal the only remedy is ADD_DEPTH_SAMPLER (48 h) per missing pool, while the record used for verification and monitoring names contracts the depth rule never reads. Expected: the stage either lists what it deploys (ImdDepth.addSampler through Parameters before the seal) or stops with Mismatch when ImdDepth's `samplers()` differ from the config. Reachable with BetaConfig (depth.enabled, three samplers) on any resume whose record and config disagree on the count. Smallest fix: in _stageDepth, after building `list`, compare `d.imdDepth.samplers()` with `list` and revert Mismatch(\"ImdDepth samplers\") when they differ (before the seal the wirer may also call a new genesis `addDepthSampler` on Parameters, but a Mismatch is the pattern the other pieces use and needs no contract change). The same 'adopt what is already there' pattern applies to extra sleeve listings and extra `edgeIlk` flags left by an earlier config (compared only for the ilks THIS config names), and to `setGenesisCap/Target/Group`, which no stage calls or checks.","line":299,"path":"script/deploy/StageGenesis.sol","proof":"// SPDX-License-Identifier: MIT\npragma solidity 0.8.26;\n\nimport \"forge-std/Test.sol\";\nimport {DeployTypes} from \"script/DeployConfig.sol\";\nimport {DeployBase} from \"script/deploy/DeployBase.sol\";\nimport {StageGenesis} from \"script/deploy/StageGenesis.sol\";\nimport {Parameters} from \"src/Parameters.sol\";\nimport {ImdDepth} from \"src/feeds/ImdDepth.sol\";\nimport {DepthSampler} from \"src/feeds/DepthSampler.sol\";\n\n/// A pool manager whose every pool reads as initialised (slot0.sqrtPriceX96 = 2^96).\ncontract PrdCode {\n    function extsload(bytes32) external pure returns (bytes32) {\n        return bytes32(uint256(1) << 96);\n    }\n}\n\ncontract PrdToken {\n    uint8 public decimals;\n    constructor(uint8 d) { decimals = d; }\n}\n\n/// Stage 4 step 6a exactly as the launch runs it (`_stageDepth`), on a deployment record `d`.\ncontract PrdStage is StageGenesis {\n    function depthStage(DeployTypes.Config memory cfg, Deployed memory d) external returns (Deployed memory) {\n        _stageDepth(cfg, d);\n        return d;\n    }\n}\n\n/// M6 re-check. A resumed 6a keeps a recorded sampler only if it matches its spec (Mismatch otherwise: correct), but\n/// when the record holds FEWER samplers than the config (a pool added before the resume, or an entry lost), it drops\n/// the whole recorded array, deploys every sampler afresh and records them, while `setGenesisImdDepth` (the only call\n/// that lists samplers at genesis) is skipped because Parameters already points at the ImdDepth. The run goes on to seal\n/// with ImdDepth reading the OLD sampler set and the record naming contracts ImdDepth never reads.\ncontract ProofResumeDepthTest is Test {\n    PrdStage h;\n    Parameters params;\n    address pm = address(new PrdCode());\n\n    function setUp() public {\n        h = new PrdStage();\n        params = new Parameters(address(0x5AFE), address(h)); // the stage contract is the wirer, as the deployer EOA is\n    }\n\n    function _cfg(uint256 n) internal returns (DeployTypes.Config memory cfg) {\n        cfg.poolManager = pm;\n        cfg.depth.enabled = true;\n        cfg.depth.samplers = new DeployTypes.SamplerSpec[](n);\n        for (uint256 i; i < n; ++i) {\n            DeployTypes.SamplerSpec memory sp;\n            // Deterministic token pairs per pool index so both runs describe the same pool 0.\n            (sp.currency0, sp.currency1) = (address(uint160(0x1000 + i)), address(uint160(0x2000 + i)));\n            vm.etch(sp.currency0, type(PrdToken).runtimeCode);\n            vm.etch(sp.currency1, type(PrdToken).runtimeCode);\n            vm.store(sp.currency0, 0, bytes32(uint256(18)));\n            vm.store(sp.currency1, 0, bytes32(uint256(6)));\n            (sp.fee, sp.tickSpacing, sp.hooks) = (3000, 60, address(0));\n            sp.poolId = keccak256(abi.encode(sp.currency0, sp.currency1, sp.fee, sp.tickSpacing, sp.hooks));\n            (sp.feed0, sp.feed1) = (DeployTypes.NO_FEED, DeployTypes.NO_FEED);\n            (sp.bandBps, sp.maxDeviationTicks, sp.maxSteps, sp.soldIsToken0) = (1500, 100, 50, true);\n            cfg.depth.samplers[i] = sp;\n        }\n    }\n\n    function test_resumeWithAnAddedPoolListsNothingAndRecordsUnlistedSamplers() public {\n        DeployBase.Deployed memory d;\n        d.params = params;\n        // Run 1: one exit pool. ImdDepth deployed, sampler 0 deployed and listed, Parameters points at ImdDepth.\n        d = h.depthStage(_cfg(1), d);\n        address old0 = address(d.samplers[0]);\n        assertEq(address(params.imdDepth()), address(d.imdDepth));\n        assertEq(d.imdDepth.samplers().length, 1);\n        assertEq(d.imdDepth.samplers()[0], old0);\n        // Run 2: a second exit pool was added to the config before the resume.\n        d = h.depthStage(_cfg(2), d);\n        address[] memory listed = d.imdDepth.samplers();\n        // Expected: ImdDepth reads the two samplers the record names (or the run stops with Mismatch).\n        // Actual: sampler 0 is redeployed (a duplicate of a pool already listed), sampler 1 is new, neither is listed.\n        assertEq(d.samplers.length, 2, \"record names two samplers\");\n        assertTrue(address(d.samplers[0]) != old0, \"pool 0 sampler was redeployed, not kept\");\n        assertEq(listed.length, 2, \"ImdDepth lists both samplers\");\n        assertEq(listed[1], address(d.samplers[1]), \"the added pool's sampler is listed\");\n    }\n}","reproduction":"Harness exposes StageGenesis._stageDepth. Run 1 with cfg.depth.samplers = [pool0]: ImdDepth deployed, S0 listed, params.imdDepth() == ImdDepth. Run 2 on the returned record with cfg.depth.samplers = [pool0, pool1]: expected ImdDepth.samplers() == [S0', S1] (or Mismatch); actual ImdDepth.samplers() == [S0] while d.samplers == [S0' != S0, S1]. test/scratch/ProofResumeDepth.t.sol fails on this commit at `ImdDepth lists both samplers` (1 != 2).","severity":"low","snippet":"        if (address(d.params.imdDepth()) != address(d.imdDepth)) {\n            g = gasleft();\n            d.params.setGenesisImdDepth(address(d.imdDepth), list);\n            _rec(\"params.setGenesisImdDepth\", g, CALL_DATA + 32 * n);\n        }","title":"Deploy resume (M6): when the record holds fewer samplers than the config, step 6a redeploys every DepthSampler but lists none of them, then seals"},{"citation":"resolved","description":"Measured from this commit's solc artifacts (0.8.26, via_ir, runs 200): ParametersRules runtime 24,494 B (82 B to EIP-170); Parameters runtime 22,404 B (2,172 B left) but its CREATION code is 47,735 B, 1,417 B under the EIP-3860 init-code limit, because `rules = new ParametersRules(governor_)` embeds Rules' creation code in Parameters' constructor. Rules inherits ParametersBase and GovernedByKind, so propose/cancel/applyPending/pending views and every event/error of the base are compiled into Rules as dead code, and any byte added to the shared base lands in both contracts. `rules` is immutable and Parameters is immutable in Ledger, Pricer, Treasury, the sleeves and the hook: there is no path to add a kind, tighten a validation (the fix for the SET_DEPTH_LEG/ADD_DEPTH_SAMPLER finding costs roughly 40-80 B), add a per-step line bound, or add a veto/guardian role without redeploying the whole system. This is the first place v2 runs out of room. Before mainnet (small, before the freeze): split ParametersBase into a storage/constants part shared with Rules and a surface part only Parameters inherits, and let Rules take the governor address as a constructor argument instead of inheriting GovernedByKind; measured on the artifacts this frees several KB in Rules. Larger (after the beta): make the rules module replaceable through a long timelock (SET_RULES, e.g. 7 days) so validations can be tightened without a redeploy.","line":21,"path":"src/Parameters.sol","reproduction":"Build this commit with foundry.toml's settings (forge test on the panel glob compiles Parameters); read out/ParametersRules.sol/ParametersRules.json deployedBytecode.object length (24,494 B) and out/Parameters.sol/Parameters.json bytecode.object length (47,735 B). Add any ~90 B of validation to ParametersRules._validate and the build fails with 'contract code size exceeds 24576 bytes'.","severity":"info","snippet":"    ParametersRules public immutable rules;\n\n    constructor(address governor_, address wirer_) ParametersBase(governor_, wirer_) {\n        rules = new ParametersRules(governor_);\n    }","title":"Governance surface is frozen at launch: ParametersRules has 82 B left, Parameters' init code 1,417 B under EIP-3860, and every shared-base byte is paid twice"}],"hash":"011c2e6f46c296037dc87d4f860642fc48dd0bf294b83697bba0d3cd4f04a348","nodeId":"36157fd9-7727-42f1-a093-d36c15372cd2","outcome":"completed","summary":"The findings file is written and validated, the scratch tests are deleted, and the tree is unchanged apart from `.imd-findings.json`. Here is the report.\n\n## Build and checks\n\nThe required panel ran with solc 0.8.26 via_ir and passed.\n\n| Run | Result |\n|---|---|\n| `forge test --match-path 'test/unit/{AuditW1{BatchItems,OtherImdLines,PostLowerDepth,RateStep,ResumeTypes},Core,PanelParams,CapAndSlots}.t.sol'` | 87 passed, 0 failed, 7m13s |\n| `test/scratch/ProofApplyFails.t.sol` (3 tests) | all 3 fail with `BadSampler()` as intended |\n| `test/scratch/ProofResumeDepth.t.sol` (1 test) | fails `ImdDepth lists both samplers: 1 != 2` as intended |\n\nThe public wave-1 submissions could not be fetched. `GET https://api.imd.fun/jobs/<id>/submissions` answered `{\"error\":\"invalid_job_id\"}` (HTTP 400) for all eight ids. I therefore used the in-repo `AuditW1*` tests, which the README names as the auditors' proofs adapted, as the originals for questions 1 and 2. Those five files pass on this commit, so each original proof no longer fails.\n\n## Findings (in `.imd-findings.json`)\n\n1. **Low. `SET_DEPTH_LEG` and `ADD_DEPTH_SAMPLER` pass propose and revert at apply** (`src/ParametersRules.sol:75-80`). Propose checks only the zero pairing of the leg and that a sampler has code. `ImdDepth.setLeg` also requires both addresses to have code, and `ImdDepth.addSampler` refuses an already listed sampler, a second sampler on a listed pool, and a seventh sampler. A mistaken proposal takes the slot and lock for 48 hours plus a cancel. Reachable in the beta, which lists three samplers and expects the depth leg later. Proof attached.\n\n2. **Low. Deploy resume still adopts ImdDepth's sampler set unchecked** (`script/deploy/StageGenesis.sol:299-303`, with line 276). A recorded sampler whose spec differs stops the run with `Mismatch(\"DepthSampler\")`, which I verified. But when the record holds fewer samplers than the config, line 276 discards the whole recorded array, every sampler is redeployed and recorded, and the only listing call is skipped because Parameters already points at the ImdDepth. The stage then seals with ImdDepth reading the old set and the record naming contracts the depth rule never reads. Proof attached. The same adopt-as-found pattern covers extra sleeve listings, extra edge flags, and `setGenesisCap/Target/Group`, which no stage calls or compares.\n\n3. **Info. Governance surface is frozen at launch** (`src/Parameters.sol:21-25`). Measured from this commit's artifacts: ParametersRules runtime has 82 bytes left, and Parameters' creation code is 47,735 bytes, only 1,417 under EIP-3860, because it embeds Rules. Rules inherits GovernedByKind, so the propose/cancel/apply surface is dead code in Rules and every shared-base byte is paid twice.\n\n## Question 1. What still passes propose and fails at apply?\n\nAll five wave-1 fixes hold. The malformed BATCH item is refused at propose, and `_touches` skips items under 64 bytes. `lowerOtherImdLines` reverts while `depthLine()` is below the stored line. `postLowerDepth` refuses any value when no ImdDepth exists and the cap is 0. RateManager's step check uses `lastCall != 0`, so a target of 0 stays the reference. `SET_KEEPER`, `SET_BRIDGE` and a full sleeve are refused at propose.\n\nWhat still passes propose and fails at apply:\n\n- **Finding 1 above** (codeless depth leg; duplicate or same-pool sampler; seventh sampler).\n- **By design, state-driven:** a `SET_RISK` raise on the depth type, `SET_DEPTH_K` up, or `SET_OTHER_IMD` up fails at apply if measured depth fell below the need. `SET_CAP` fails if the live low fell under a cap above 2x. `ADD_SLEEVE_ILK` for an edge type fails if edge debt grew past the sleeve's room. `RETIRE_SLEEVE_TOKEN` fails if the token is priced again (known issue). These are the documented re-validation.\n- **Governor's own ordering:** a BATCH with two `SET_CAP` items on one type, or a `SET_RISK` raise on the depth type placed before the `SET_DEPTH` item that makes room for it, fails at appl","treeHash":null,"usage":{"cachedInputTokens":2383866,"cost":{"source":"runtime","usdMicros":6671916},"inputTokens":514,"model":"claude-fable-5-1","outputTokens":51137,"runtime":"claude","turns":40,"wallClockMs":1607463}},{"artifacts":[],"attempt":1,"bundleHash":null,"device":"e49531c471ac7158","findings":[],"hash":"7ad39588b6fec720f71489a06d0550ba968a6033f36f517e0608797b35355ecf","nodeId":"fc800d60-1edc-4f3a-bed0-4e631f133d07","outcome":"failed","summary":"wall-clock budget exhausted","treeHash":null,"usage":{"cachedInputTokens":179633,"cost":{"source":"estimated","usdMicros":68107},"inputTokens":10,"model":"claude-opus-5-5","outputTokens":1607,"runtime":"claude","turns":0,"wallClockMs":5100063}},{"artifacts":[],"attempt":2,"bundleHash":null,"device":"27168b1ff68f84d2","findings":[{"citation":"resolved","description":"Wave 1's rule for Parameters is 'refuse at propose what the apply would fail on'. The wave-1 fixes listed in question 1 hold (re-run: a malformed BATCH item, SET_KEEPER/SET_BRIDGE when already set, and a full sleeve are refused at propose; lowerOtherImdLines is refused while depth binds; postLowerDepth cannot raise from 0 without ImdDepth; RateManager keeps its step reference after target 0; the AuditW1* suites pass). Three classes remain. (1) ADD_DEPTH_SAMPLER: _validate (line 75-77) checks only that ImdDepth exists and the sampler has code. ImdDepth.addSampler (src/feeds/ImdDepth.sol:82-88) also refuses a sampler already listed, a second sampler on an already listed (manager, poolId) and a 7th sampler (MAX_SAMPLERS = 6). (2) SET_DEPTH_LEG: _validate (line 78-80) checks only the both-or-neither-zero pairing; ImdDepth.setLeg (ImdDepth.sol:103-104) also requires code on both addresses. (3) BATCH: each item is validated against the state BEFORE the batch (line 132-135), while _apply re-validates item i after items 0..i-1 applied, so items that conflict with each other pass propose: two ADD_ILK of the same new type (IlkExists at apply), two SET_BRIDGE or two SET_KEEPER (ImdUSD AlreadySet), two ADD_SLEEVE_ILK each adding a new token into a sleeve holding 5 (SLEEVE_MAX_TOKENS 6) or a new type into one listing 11, or two ADD_SLEEVE_ILK for different types sharing a token. Each such proposal is accepted, waits 48h, then every applyPending reverts; GovernedByKind keeps the slot and its lock bits until cancel (an expired proposal also keeps them), and a correct re-proposal of that kind reverts ProposalPending. Impact: governance liveness only under the Safe's own payloads (a lost 48h cycle on the depth-gated sIMD line or the depth leg; inside a BATCH one bad item fails the whole batch at apply). No funds or parameters move. Reachable with BetaConfig: yes (ImdDepth with 3 samplers is set at genesis; a 4th exit pool and the swarm depth leg are exactly what the Safe expects to add after genesis; re-adding a sampler for an already measured pool with new band settings without removeDepthSampler first is a realistic operator mistake). RETIRE_SLEEVE_TOKEN's 3-word payload is already in Known issues. Smallest fix: in _validate, for ADD_DEPTH_SAMPLER read IDepthPool(sampler).manager()/poolId() and compare with imdDepth.samplers() (revert OutOfBounds on a match or when samplers().length >= 6), or add a view ImdDepth.canAdd(address) mirroring addSampler and call it (one external call in Rules); for SET_DEPTH_LEG require leg.code.length != 0 && price.code.length != 0 when non-zero; for BATCH refuse two items of a once-only kind (SET_BRIDGE, SET_KEEPER, ADD_ILK of one ilk) and count new sleeve tokens/types across the batch. Cost: ParametersRules has 82 bytes of EIP-170 room (measured 24,494 B), so these checks need the size work in the info finding first (or the ImdDepth view, which keeps Rules' cost to one call).","line":75,"path":"src/ParametersRules.sol","proof":"// SPDX-License-Identifier: MIT\npragma solidity 0.8.26;\n\nimport \"forge-std/Test.sol\";\nimport {Parameters} from \"src/Parameters.sol\";\nimport {ParametersBase} from \"src/ParametersBase.sol\";\nimport {ImdDepth} from \"src/feeds/ImdDepth.sol\";\nimport {IFeed} from \"src/interfaces/IFeed.sol\";\n\ncontract PaStub {}\n\ncontract PaJoin {\n    address public token;\n    address public ledger;\n\n    constructor(address t, address l) {\n        (token, ledger) = (t, l);\n    }\n}\n\n/// A stand-in exit-pool sampler: ImdDepth only reads manager() and poolId() when listing.\ncontract PaSampler {\n    address public manager;\n    bytes32 public poolId;\n\n    constructor(address m, bytes32 id) {\n        (manager, poolId) = (m, id);\n    }\n}\n\n/// Wave 2 says propose refuses what apply would fail on. These still pass propose, wait 48h and always revert at\n/// apply, holding their slot (and every kind they lock) until the Safe cancels.\ncontract ProofProposeApply is Test {\n    Parameters params;\n    ImdDepth depth;\n    address gov = makeAddr(\"gov\");\n    address ledger;\n    address sampler;\n    bytes32 constant ETH = \"ETH\";\n    bytes32 constant SIMD = \"SIMD\";\n\n    function setUp() public {\n        params = new Parameters(gov, address(this));\n        ledger = address(new PaStub());\n        params.wire(ledger, address(new PaStub()));\n        _add(ETH, 1_000_000e18);\n        _add(SIMD, 0);\n        params.setGenesisDepthRule(SIMD, 1e18, 0, 0, 0);\n        depth = new ImdDepth(address(params));\n        sampler = address(new PaSampler(address(0xBEEF), bytes32(uint256(1))));\n        address[] memory list = new address[](1);\n        list[0] = sampler;\n        params.setGenesisImdDepth(address(depth), list);\n        params.seal();\n    }\n\n    function _risk(uint128 line) internal pure returns (ParametersBase.Risk memory) {\n        return ParametersBase.Risk({\n            mat: 1.5e18, chop: 0.1e18, cut: 0.1e18, chip: 0.01e18, rateFloor: 0.005e18, yieldFee: 0, skew: 0.02e18,\n            pegFloor: 0, line: line, dust: 100e18, redeemFloor: 0.005e18, redeemDivisor: 4, redeemCap: 0\n        });\n    }\n\n    function _cfg() internal returns (ParametersBase.Config memory c) {\n        c.token = address(new PaStub());\n        c.join = address(new PaJoin(c.token, ledger));\n        c.median = IFeed(address(new PaStub()));\n        c.spot = c.median;\n        c.redeemable = true;\n    }\n\n    function _add(bytes32 ilk, uint128 line) internal {\n        params.addGenesisIlk(ilk, _cfg(), _risk(line));\n    }\n\n    /// ADD_DEPTH_SAMPLER of a sampler ImdDepth already lists: _validate checks only that it has code.\n    function test_addListedSamplerRefusedAtPropose() public {\n        bytes memory p = abi.encode(params.ADD_DEPTH_SAMPLER(), sampler);\n        vm.prank(gov);\n        try params.propose(p) {\n            // Queued: it must at least apply after the delay.\n            vm.warp(block.timestamp + 48 hours);\n            params.applyPending(params.ADD_DEPTH_SAMPLER()); // actual: reverts BadSampler (already listed)\n        } catch {}\n    }\n\n    /// A BATCH adding the same new type twice: each item is validated against the state before the batch.\n    function test_batchDuplicateAddIlkRefusedAtPropose() public {\n        bytes[] memory items = new bytes[](2);\n        bytes memory add = abi.encode(params.ADD_ILK(), bytes32(\"WSTETH\"), _cfg(), _risk(1_000e18));\n        (items[0], items[1]) = (add, add);\n        bytes memory p = abi.encode(params.BATCH(), items);\n        vm.prank(gov);\n        try params.propose(p) {\n            vm.warp(block.timestamp + 48 hours);\n            params.applyPending(params.BATCH()); // actual: reverts IlkExists on the second item\n        } catch {}\n    }\n}","reproduction":"Reproduced on this commit. Setup: Parameters (governor g) sealed with a depth-gated type and ImdDepth listing sampler S0 (manager M, poolId P). (a) g.propose(abi.encode(uint8(24), S0)) -> accepted (expected: revert OutOfBounds); warp 48h; applyPending(24) -> reverts ImdDepth.BadSampler(); pendingOf(24).eta stays non-zero and bit 24 of locked stays set. (b) same with S1 having code and S1.manager()==M, S1.poolId()==P -> accepted; applyPending(24) reverts BadSampler(). (c) g.propose(abi.encode(uint8(25), address(0xBEEF), feedWithCode)) -> accepted; applyPending(25) reverts BadSampler(). (d) g.propose(abi.encode(BATCH, [ADD_ILK(WSTETH,cfg,risk), ADD_ILK(WSTETH,cfg,risk)])) -> accepted; after 48h applyPending(BATCH kind) reverts IlkExists(). Run: forge test --match-path 'test/scratch/*.t.sol' (solc 0.8.26 via_ir): Proof_7d974e3c7655 -> [FAIL: BadSampler()] test_addListedSamplerRefusedAtPropose, [FAIL: IlkExists()] test_batchDuplicateAddIlkRefusedAtPropose; Proof_f4b0e56b2b28 -> [FAIL: BadSampler()] x3 (already listed, same pool, codeless leg). 0 passed; 5 failed.","severity":"low","snippet":"        } else if (kind == ADD_DEPTH_SAMPLER) {\n            (, address sampler) = abi.decode(payload, (uint8, address));\n            if (address(imdDepth) == address(0) || sampler.code.length == 0) revert OutOfBounds();\n        } else if (kind == SET_DEPTH_LEG) {\n            (, address leg, address price) = abi.decode(payload, (uint8, address, address));\n            if (address(imdDepth) == address(0) || (leg == address(0)) != (price == address(0))) revert OutOfBounds();","title":"Q1: ADD_DEPTH_SAMPLER (listed sampler, listed pool, 7th), SET_DEPTH_LEG (codeless leg/price) and self-conflicting BATCH items still pass propose and always fail at apply, holding the kind's slot and l"},{"citation":"resolved","description":"The wave-1 fix states the instant lower is refused because it 'would RAISE the enforced line without the timelock; SET_OTHER_IMD (48h) does that'. The guard (line 216) reads depthLine() at the moment of the call. depthIMD() is ImdDepth's 7-day low and changes every hour (keeper gaps, the depth griefing in Known issues). Lowering otherImdLines while depthLine() >= the stored line removes the other-chain term from every FUTURE depthLine(); when depth later falls, risk(SIMD).line = min(stored, depthLine()) is higher than it would have been with the old term. This is the wave-1 raise again, delayed until depth binds, and reachable with BetaConfig: otherImdLines counts the Robinhood IMD line (3,000 at chop 20%, a 3,600 term), so lowering it to 0 is up to 3,000 imdUSD more enforced sIMD line without the timelock. The Safe is trusted and the raise is bounded by the stored line, so severity is low; the point is that the fix does not deliver the property it claims. Smallest fix: remove lowerOtherImdLines (an instant act that can only ever widen room is not a risk-reducing act) and leave the change to SET_OTHER_IMD (48h); or require the stored sIMD line to be lowered by at least the removed term in the same call, so the enforced line can never increase.","line":214,"path":"src/Parameters.sol","proof":"// SPDX-License-Identifier: MIT\npragma solidity 0.8.26;\n\nimport \"forge-std/Test.sol\";\nimport {Parameters} from \"src/Parameters.sol\";\nimport {ParametersBase} from \"src/ParametersBase.sol\";\nimport {IFeed} from \"src/interfaces/IFeed.sol\";\n\ncontract OlStub {}\n\ncontract OlJoin {\n    address public token;\n    address public ledger;\n\n    constructor(address t, address l) {\n        (token, ledger) = (t, l);\n    }\n}\n\n/// The measured depth, moved by the test (it moves hourly on chain: DepthSampler + ImdDepth.poke).\ncontract OlDepth {\n    address public params;\n    uint256 public depth;\n\n    constructor(address p) {\n        params = p;\n    }\n\n    function set(uint256 d) external {\n        depth = d;\n    }\n\n    function addSampler(address) external {}\n}\n\n/// Wave 2 refuses lowerOtherImdLines only while the depth line binds NOW. Lowered one block before it binds, the instant\n/// act still raises the enforced sIMD line as soon as depth falls: the same raise without the 48h timelock.\ncontract ProofOtherImdLater is Test {\n    Parameters params;\n    OlDepth depth;\n    address gov = makeAddr(\"gov\");\n    bytes32 constant SIMD = \"SIMD\";\n\n    function setUp() public {\n        params = new Parameters(gov, address(this));\n        address ledger = address(new OlStub());\n        params.wire(ledger, address(new OlStub()));\n        address t = address(new OlStub());\n        ParametersBase.Config memory c;\n        c.token = t;\n        c.join = address(new OlJoin(t, ledger));\n        c.median = IFeed(address(new OlStub()));\n        c.spot = c.median;\n        c.redeemable = true;\n        ParametersBase.Risk memory r = ParametersBase.Risk({\n            mat: 1.7e18, chop: 0.2e18, cut: 0.04e18, chip: 0, rateFloor: 0.005e18, yieldFee: 0, skew: 0.02e18,\n            pegFloor: 0, line: 10_000e18, dust: 100e18, redeemFloor: 0.005e18, redeemDivisor: 2, redeemCap: 0\n        });\n        params.addGenesisIlk(SIMD, c, r);\n        // BetaConfig's other-chain term: the Robinhood IMD line 3,000 at chop 20%.\n        params.setGenesisDepthRule(SIMD, 1e18, 0, 3_000e18, 0.2e18);\n        depth = new OlDepth(address(params));\n        params.setGenesisImdDepth(address(depth), new address[](0));\n        params.seal();\n        depth.set(15_600e18); // depthLine = (15,600 - 3,600) / 1.2 = 10,000 = the stored line: not binding\n    }\n\n    function test_lowerOtherImdLinesDoesNotRaiseLineAfterDepthFalls() public {\n        assertEq(params.risk(SIMD).line, 10_000e18);\n        vm.prank(gov);\n        try params.lowerOtherImdLines(0) {} catch {} // accepted: the depth line does not bind at this moment\n        // One hour later the measured depth falls 23% (a keeper gap or a cheap push, README 'Depth griefing').\n        depth.set(12_000e18);\n        // With the other chain's 3,000 still counted: (12,000 - 3,600) / 1.2 = 7,000. After the instant act: 10,000.\n        assertLe(params.risk(SIMD).line, 7_000e18, \"instant act raised the enforced sIMD line\");\n    }\n}","reproduction":"Reproduced on this commit. State: SIMD stored line 10,000e18, chop 0.2, redeemCap 0, k = 1, otherImdLines 3,000e18 at chop 0.2, measured depth 15,600e18 -> depthLine = (15,600 - 3,600)/1.2 = 10,000 (not binding). Governor: lowerOtherImdLines(0) -> accepted. One hour later depth reads 12,000e18. Expected (term still counted, change being timelocked): risk(SIMD).line = (12,000 - 3,600)/1.2 = 7,000e18. Actual: 12,000/1.2 = 10,000e18. Run: forge test --match-path test/scratch/Proof_1262e517d5de.t.sol -> [FAIL: instant act raised the enforced sIMD line: 10000000000000000000000 > 7000000000000000000000] test_lowerOtherImdLinesDoesNotRaiseLineAfterDepthFalls(). 0 passed; 1 failed.","severity":"low","snippet":"    function lowerOtherImdLines(uint256 lines) external onlyGovernor {\n        if (depthIlk == bytes32(0) || lines >= otherImdLines) revert OutOfBounds();\n        if (depthLine() < _risk[depthIlk].line) revert OutOfBounds();","title":"Q1: lowerOtherImdLines is refused only while the depth line binds at the call; lowered while depth is slack, the instant act raises the enforced sIMD line without the 48h timelock as soon as depth fal"},{"citation":"resolved","description":"Yes, a resume can still adopt something it should not: the measured-depth pieces. _stageDepth keeps a recorded ImdDepth if its params() matches, compares each recorded DepthSampler with its spec (_samplerIs, which stops with Mismatch('DepthSampler') on a difference: verified), but (a) line 276 `if (d.samplers.length != n) d.samplers = new DepthSampler[](n);` discards the whole recorded array whenever the config's pool count differs from the record (a 4th exit pool added before a resume, or a record that lost an entry), so every sampler is deployed afresh and recorded; and (b) setGenesisImdDepth (lines 299-303), the only genesis call that lists samplers, runs only while Parameters does not yet point at the recorded ImdDepth. Nothing compares d.imdDepth.samplers() with `list`. Together: the resumed run records n fresh samplers, ImdDepth keeps the first run's listing (a pool the operator dropped as suspect keeps counting toward depth, so the sIMD line is sized higher than the config intends; an added pool is never measured; a swapped sampler, cleared in the record per the DeployBase header, is recorded but not listed), no Mismatch fires, and the stage goes on to seal(). The deployment record used for verification and for the hourly sampling keeper then names samplers the depth rule never reads; if the keeper samples the recorded addresses, the listed ones read 0 after about 6 hours and the sIMD line is held at 0 for about 8 days. After the seal the repair is removeDepthSampler (instant) plus one ADD_DEPTH_SAMPLER (48h) per pool, one pending at a time. Every other kept piece (types, feeds, risk, sleeves, Allocator, backstop wiring, a changed sampler at the same index) now stops with Mismatch; the PEG-type gap is in Known issues. The same adopt-what-is-there pattern applies to extra sleeve listings and edgeIlk flags left by an earlier config (compared only for the ilks THIS config names) and to setGenesisCap/Target/Group, which no stage checks. Reachable with BetaConfig (depth.enabled, 3 samplers) on any resume whose record and config disagree on the sampler list. Severity low: only a resumed stage reaches it and governance can repair in 48h per pool. Smallest fix (script only, about 8 lines, no contract change): do not reset d.samplers when the length differs (reuse recorded entries by index), and when address(d.params.imdDepth()) == address(d.imdDepth) require keccak256(abi.encode(d.imdDepth.samplers())) == keccak256(abi.encode(list)), else revert Mismatch('ImdDepth lists other samplers').","line":299,"path":"script/deploy/StageGenesis.sol","proof":"// SPDX-License-Identifier: MIT\npragma solidity 0.8.26;\n\nimport \"forge-std/Test.sol\";\nimport {DeployTypes} from \"script/DeployConfig.sol\";\nimport {StageGenesis} from \"script/deploy/StageGenesis.sol\";\nimport {Parameters} from \"src/Parameters.sol\";\nimport {ImdDepth} from \"src/feeds/ImdDepth.sol\";\nimport {IFeed} from \"src/interfaces/IFeed.sol\";\n\n/// A pool manager whose every pool reads as initialised at price 1 (StateLibrary.getSlot0 reads extsload).\ncontract RsCode {\n    function extsload(bytes32) external pure returns (bytes32) {\n        return bytes32(uint256(1 << 96));\n    }\n}\n\ncontract RsToken {\n    function decimals() external pure returns (uint8) {\n        return 18;\n    }\n}\n\n/// Stage 4's depth step exactly as the launch runs it, on a deployment record `d`.\ncontract RsStage is StageGenesis {\n    function depthStep(DeployTypes.Config memory cfg, Deployed memory d) external returns (Deployed memory) {\n        _stageDepth(cfg, d);\n        return d;\n    }\n}\n\n/// A resumed stage 4 that rebuilds a sampler (the recorded one is from another config) never lists the new one:\n/// Parameters already points at the recorded ImdDepth, so `setGenesisImdDepth` is skipped and ImdDepth keeps measuring\n/// the depth of the OLD samplers, which nothing compares with the config.\ncontract ProofResumeSamplers is Test {\n    RsStage h;\n    address manager;\n    address tokenA;\n    address tokenB;\n\n    function setUp() public {\n        h = new RsStage();\n        manager = address(new RsCode());\n        (tokenA, tokenB) = (address(new RsToken()), address(new RsToken()));\n        if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA);\n    }\n\n    function _spec(DeployTypes.SamplerSpec memory sp, uint24 fee, int24 spacing) internal view {\n        (sp.currency0, sp.currency1, sp.fee, sp.tickSpacing, sp.hooks) = (tokenA, tokenB, fee, spacing, address(0));\n        sp.poolId = keccak256(abi.encode(tokenA, tokenB, fee, spacing, address(0)));\n        (sp.feed0, sp.feed1) = (DeployTypes.NO_FEED, DeployTypes.NO_FEED);\n        (sp.bandBps, sp.maxDeviationTicks, sp.maxSteps, sp.soldIsToken0) = (1_500, 200, 64, true);\n    }\n\n    /// `n` exit pools: the first is the same pool and spec in every config.\n    function _cfg(uint256 n) internal view returns (DeployTypes.Config memory cfg) {\n        cfg.poolManager = manager;\n        cfg.depth.enabled = true;\n        cfg.depth.samplers = new DeployTypes.SamplerSpec[](n);\n        _spec(cfg.depth.samplers[0], 10_000, 200);\n        if (n > 1) _spec(cfg.depth.samplers[1], 3_000, 60);\n    }\n\n    function test_resumedDepthStepListsTheSamplersItKeeps() public {\n        RsStage.Deployed memory d;\n        d.params = new Parameters(makeAddr(\"gov\"), address(h));\n        d.feeds = new IFeed[](0);\n        // Run 1 lists one exit pool's sampler A in ImdDepth (the run then stops later in stage 4, before the seal).\n        d = h.depthStep(_cfg(1), d);\n        address a = address(d.samplers[0]);\n        assertEq(d.imdDepth.samplers()[0], a);\n        // The config gains a second exit pool and stage 4 is resumed on the same record.\n        try h.depthStep(_cfg(2), d) returns (RsStage.Deployed memory d2) {\n            address[] memory listed = d2.imdDepth.samplers();\n            // expected: ImdDepth measures the two samplers the record now holds (or the resume stops: Mismatch).\n            // actual: both were rebuilt, neither is listed, and ImdDepth still measures A alone.\n            assertEq(listed.length, 2, \"ImdDepth does not list the config's samplers\");\n            assertEq(listed[0], address(d2.samplers[0]));\n            assertEq(listed[1], address(d2.samplers[1]));\n        } catch {\n            // refused (Mismatch): also correct\n        }\n    }\n}","reproduction":"Reproduced on this commit with a harness exposing StageGenesis._stageDepth (real ImdDepth and DepthSampler, stub PoolManager). Run 1 with cfg.depth.samplers = [pool P1] on an empty record: ImdDepth deployed, sampler A deployed and listed, params.imdDepth() == ImdDepth; the run stops before the seal. Config gains pool P2; stage 4 is resumed on the same record. Expected: ImdDepth.samplers() == d.samplers (two entries), or the run stops with Mismatch. Actual: two new samplers are deployed and recorded, setGenesisImdDepth is skipped, ImdDepth.samplers() == [A], no revert. Run: forge test --match-path test/scratch/Proof_c481e43ca23f.t.sol -> [FAIL: ImdDepth does not list the config's samplers: 1 != 2] test_resumedDepthStepListsTheSamplersItKeeps() (gas: 7644175). 0 passed; 1 failed.","severity":"low","snippet":"        if (address(d.params.imdDepth()) != address(d.imdDepth)) {\n            g = gasleft();\n            d.params.setGenesisImdDepth(address(d.imdDepth), list);\n            _rec(\"params.setGenesisImdDepth\", g, CALL_DATA + 32 * n);\n        }","title":"Q2 (M6): a resumed stage-4 deploy never compares ImdDepth's listed samplers with the config; a changed sampler list redeploys and records samplers that are never listed, and the run seals with ImdDept"},{"citation":"resolved","description":"Measured on this commit's solc 0.8.26 via_ir artifacts (bytecode_hash none, the panel build): ParametersRules runtime 24,494 B (82 B to EIP-170's 24,576), Parameters runtime 22,404 B (2,172 left) but creation code 47,735 B (1,417 B under the 49,152 B EIP-3860 init-code limit, because `rules = new ParametersRules(governor_)` embeds Rules' creation code in Parameters' constructor), Ledger 22,398 B (2,178 left), Allocator 22,698 B (1,878 left, against the brief's ~2.6 KB), Backstop 19,942 B, Liquidator 12,112 B. Rules inherits ParametersBase and GovernedByKind, so propose/cancel/applyPending and every base event and error are compiled into Rules as dead code, and every byte added to the shared base is paid in both contracts. `rules` is immutable in Parameters and Parameters is immutable in Ledger, Pricer, Treasury, the sleeves and the hook: adding a governed kind (a third sleeve, a chain, a module), tightening a validation (the fixes for the propose/apply finding cost roughly 60-150 B), adding a per-step raise bound (Known issues) or a veto role all need a new Parameters and a full redeploy. One pending proposal per kind is softened by BATCH (MAX_BATCH items, locking every kind it touches) but a stuck proposal (previous finding) blocks its kind for 48h plus a cancel. Order in which v2 runs out: (1) Backstop MAX_TOKENS at genesis (next finding), (2) ParametersRules code size, (3) Parameters init code, (4) one slot per kind. What should change before the 2026-11-20 freeze (small): let ParametersRules take the governor as a constructor argument and inherit only a storage/constants part of ParametersBase, not GovernedByKind (frees several KB in Rules and in Parameters' init code); write the sampler/leg checks as an ImdDepth view. After the beta: a SET_RULES kind under a longer timelock (7 days) so validations can be tightened without a redeploy.","line":10,"path":"src/ParametersRules.sol","reproduction":"Build the panel with foundry.toml's settings (forge test on the panel glob or test/scratch compiles Parameters) and read out/ParametersRules.sol/ParametersRules.json deployedBytecode.object: 24,494 B; out/Parameters.sol/Parameters.json bytecode.object: 47,735 B; out/Allocator.sol/Allocator.json deployedBytecode: 22,698 B; out/Ledger.sol/Ledger.json: 22,398 B. Adding about 90 B of validation to ParametersRules._validate fails the build with 'contract code size exceeds 24576 bytes'.","severity":"info","snippet":"    uint256 internal constant SLEEVE_MAX_TOKENS = 6; // Backstop.MAX_TOKENS\n    uint256 internal constant SLEEVE_MAX_ILKS = 12; // Backstop.MAX_ILKS","title":"Q4 room to grow: ParametersRules has 82 bytes left (24,494 B runtime), Parameters' creation code is 1,417 B under EIP-3860, Allocator has 1,878 B (not ~2.6 KB), Ledger 2,178 B; the immutable rules mod"},{"citation":"resolved","description":"backstopSpec lists six distinct blue tokens at genesis: WETH, wstETH, cbBTC, WBTC, sUSDS and steakUSDC (src/backstop/Backstop.sol:66 MAX_TOKENS = 6; ParametersRules.sol:113 refuses ADD_SLEEVE_ILK for a NEW token once tokenCount() >= SLEEVE_MAX_TOKENS). Parameters.blueBackstop/edgeBackstop are written once by setGenesisBackstops (src/Parameters.sol:142-149) before the seal and there is no governed kind to add or replace a sleeve (and 82 B of room to add one). So from day one the first new blue type on a new token (another LST, tBTC, another staked stable) can only be listed without a standing bid; its liquidations go to callers only. A token freed by RETIRE_SLEEVE_TOKEN still counts. Of everything in v2 this runs out first, before code size or proposal slots. Smallest change before the freeze: raise Backstop.MAX_TOKENS (and SLEEVE_MAX_TOKENS) to 8-10, or leave one slot free at genesis by listing only one of the two BTC wrappers in the sleeve. Longer term: a timelocked kind that names a further sleeve address.","line":518,"path":"script/DeployConfig.sol","reproduction":"Deploy with BetaConfig: blue.tokenCount() == 6. ADD_ILK a new type X on a new token (48h), then propose(abi.encode(ADD_SLEEVE_ILK, X, false, 0, saleMax, slope)) -> reverts OutOfBounds at propose (ParametersRules.sol:113), while the ADD_SLEEVE_ILK for a type on an already listed token (e.g. a second wstETH type) is accepted.","severity":"info","snippet":"        b.ilks[0] = DeployTypes.SleeveIlk(\"ETH\", false, 0, 50e18);\n        b.ilks[1] = DeployTypes.SleeveIlk(\"WSTETH\", false, 0, 40e18);\n        b.ilks[2] = DeployTypes.SleeveIlk(\"CBBTC\", false, 0, 2e8);\n        b.ilks[3] = DeployTypes.SleeveIlk(\"WBTC\", false, 0, 2e8);\n        b.ilks[4] = DeployTypes.SleeveIlk(\"S-USDS\", false, 0, 200_000e18);\n        b.ilks[5] = DeployTypes.SleeveIlk(\"S-USDC-STEAKHOUSE\", false, 0, 200_000e18);","title":"Q4 room to grow: BetaConfig fills the blue sleeve to Backstop.MAX_TOKENS (6) at genesis and the sleeves are set once in Parameters, so no new blue collateral token can ever get the standing bid withou"},{"citation":"resolved","description":"Q3 OPERATIONS. Cost of each missing action (BetaConfig): DEPTH samples + hourly ImdDepth.poke: 1h nothing (an hour keeps its lowest, a missed hour is not counted); about 6h missed inside a 26h window reads 0 depth and the 7-day low holds new sIMD borrowing at 0 for about 8 days (Known issues; 1 day and 1 week the same, repayment and liquidation untouched). RELAYING ATTESTATIONS (sIMD legs, NHI, seat median/spot, depth leg): 1h the per-epoch cap widens 2x, 1 day the feed is stale so borrowing on those types stops and borrowing up to the line may use the last low; 1 week the same plus edge marks stop counting after 7 days. TICKS/MARKS/LIQUIDATIONS: 1h in a calm market nothing; in a 20%+ move an hour of no liquidator is bad debt on blue types above chop; the standing bid makes a bite self-executing once marked, so the mark is the chore that matters; 1 day/1 week: sleeve losses, the unbacked-supply brake, every bucket held. SEAT POKES/AUCTIONS and COLLATERAL AUCTIONS: a day's delay sells at a staler decayed price; a week leaves healed-by-price auctions open (Known issues). BUFFER/LP RULES and BACKSTOP CONVERSIONS: rule-driven and permissionless, bounded by daily buckets; a week unrun means the buffer and LP drift from target and matured deposits wait (anyone may call realize). Where to put each: lazily inside user transactions for what is cheap and state-only (ImdDepth.poke folded into the depth-gated borrow path and Backstop.realize on the first touch, both already permissionless); an on-chain tip for marks/liquidations (chop already pays; add a small fixed tip for the mark so the first mover is paid even when the bite goes to the standing bid); a funded chore ONLY for depth sampling, because the operator must sample through private relays to avoid the +L/sample/-L inflation (Known issues), which no public tip can enforce. Oracle answers: at 0.5 IMD per answer and a 1h max age for the IMD leg, an on-chain asker costs 24 answers a day per feed (12 IMD/day, about 4,400 IMD/yr per feed) from a Treasury that holds almost no USDC and no IMD budget; whoever-needs-pays (relay with the borrow) keeps liveness tied to demand and costs the protocol nothing, so keep it, and fund a chore only for the depth leg if the Safe enables it. Q5 GOVERNANCE AS THE LAST KEY. Worst a COMPROMISED 2-of-3 Safe does: instantly, lower every line, cap and keeper cap to the floor (new borrowing and plain withdrawals from indebted positions stop until SET_CAP 48h), freeze the Allocator, disable sleeve listings (standing bid off), returnToTreasury, and the lowerOtherImdLines raise in finding 2; within 48h, SET_BRIDGE names a minter that mints without limit and burns from any holder (the single catastrophic power, and the beta keeps the kind live with the slot empty), SET_KEEPER, raises of lines/mat/depth with no per-step bound (Known issues), ADD_ILK of a worthless token with a high line (two 48h steps). An ABSENT Safe: nothing can be raised, cancelled or unfrozen; a stuck proposal holds its kind; the protocol runs on frozen parameters and fail-closed oracles, which is survivable for the beta. Cheapest hardening, in order of cost: (1) monitoring: alert on every Proposed event and on any instant lower, with a 48h human review; cost zero contract bytes. (2) Do not ship SET_BRIDGE live in the beta: refuse it in _validate (about 20 B) or have ImdUSD cap the bridge minter by a daily mint bucket like keeperCap. (3) A cancel-only guardian key in GovernedByKind (one address, cancel(kind) allowed to it) so a second party can veto a 48h proposal without being able to propose; about 100 B in the base, which today lands in both Parameters and Rules, so it needs the Rules refactor in the size finding first. (4) A 7-day timelock for SET_BRIDGE/SET_KEEPER/ADD_ILK (a per-kind delay table). Option ranking: (2)+(1) before the freeze, (3) with the size refactor, (4) after the beta.","line":154,"path":"README.md","reproduction":"Design assessment, not a defect: figures from README Known issues (6h sampler gap -> 8 days at 0; 2x cap after 1h stale), src/GovernedByKind.sol (cancel is governor-only; TIMELOCK 48h; a slot persists through expiry), src/Parameters.sol instant lowers (lowerCap, lowerLine, lowerDepthLine, lowerOtherImdLines, disable sleeve listing), ParametersRules SET_BRIDGE branch (line 45-49; refused only when already set), and the task's 0.5 IMD per answer with a 1h max age.","severity":"info","snippet":"## Trust model\n\n- **Governor:** a 2-of-3 Safe, immutable in each contract. It acts only through the 48-hour timelocks of `Parameters`,\n  `Treasury` and `Allocator`, except instant actions: the risk-reducing ones (lowering a line, a cap, a keeper cap, a\n  depth ceiling, a bucket; disabling a sleeve listing; freezing the Allocator), unfreezing the Allocator, and\n  `Allocator.returnToTreasury` (funds held there back to the Treasury, no bucket). It cannot move user collateral or\n  mint imdUSD directly. It can name one bridge minter, once, through the 48-hour timelock (`SET_BRIDGE`): that minter\n  can mint without limit and burn from any holder. The beta leaves the slot empty.","title":"Answers to questions 3 and 5 (operations; governance as the last key): no defect beyond the findings above, design assessment and cheapest hardening"}],"hash":"e493c2e6727a615468e54fbe3c56067cc6bfdf0a3bffe66115eebe8ed68a2a8f","nodeId":"fc800d60-1edc-4f3a-bed0-4e631f133d07","outcome":"completed","summary":"The review is complete. The findings file is written and valid, the tree holds no changes of mine, and the only untracked entries are the environment's own dotfiles.\n\n**Outcome.** Six entries went into `.imd-findings.json`: three low findings with proofs, two info findings, and one info entry carrying the answers to questions 3 and 5. No critical or high defect was found. The specialists' nine findings reduced to three distinct defects plus two size observations; every one reproduced against this commit before I kept it.\n\n**What I reproduced** (all with solc 0.8.26 via_ir, as the brief requires; the four attached specialist proofs ran together and all seven tests failed for the stated reasons):\n\n- **Q1, propose/apply asymmetry still open for the depth kinds and self-conflicting batches.** ADD_DEPTH_SAMPLER of a listed sampler or listed pool, SET_DEPTH_LEG with a codeless address, and BATCH items that conflict with each other (two ADD_ILK of one type, two SET_BRIDGE, two sleeve listings that together overflow) all pass propose and revert at every apply, holding the slot and lock until cancel. Proof fails with `BadSampler()` and `IlkExists()`. Liveness only, low.\n- **Q1, lowerOtherImdLines delivers its raise later.** The guard reads the depth line at call time; lowered while depth is slack, the enforced sIMD line is higher once depth falls. Proof shows a line of 10,000 where 7,000 was expected. Low, Safe-trusted.\n- **Q2, deploy resume adopts ImdDepth's old sampler list.** A changed sampler count redeploys and records samplers that are never listed, nothing compares the listing with the config, and the stage seals. Proof fails at `1 != 2`. Low, script-only fix.\n- **Q4 info.** Measured sizes: ParametersRules 82 bytes left, Parameters' init code 1,417 bytes under EIP-3860, Allocator 1,878 bytes not 2.6 KB. BetaConfig fills the blue sleeve to six tokens at genesis with no governed way to add a sleeve, which is where v2 runs out first.\n\n**Confirmed holding.** The other wave-1 fixes named in question 1 and the resume comparisons of question 2 pass: the AuditW1 BatchItems, OtherImdLines, PostLowerDepth, RateStep and ResumeTypes suites plus PanelParams ran green, 20 tests.\n\n**Not done.** I did not run the full panel glob's Core and CapAndSlots suites, since they do not bear on these files and the time budget was tight after the first compile. Questions 3 and 5 are answered as a design assessment inside the findings file, not as defects.","treeHash":null,"usage":{"cachedInputTokens":549163,"cost":{"source":"runtime","usdMicros":2427381},"inputTokens":258,"model":"claude-fable-5-1","outputTokens":17311,"runtime":"claude","turns":15,"wallClockMs":963388}},{"artifacts":[],"attempt":1,"bundleHash":null,"device":"b8fd8054ea57c5d8","findings":[{"citation":"resolved","description":"Wave 2 refuses at propose what apply would fail on for BATCH decoding, SET_KEEPER/SET_BRIDGE and a full sleeve. Two classes still pass propose, wait 48h and then revert on every applyPending, so the slot and every kind it locks stay held until the Safe cancels. (1) ADD_DEPTH_SAMPLER: _validate checks only that ImdDepth exists and the sampler has code. ImdDepth.addSampler (src/feeds/ImdDepth.sol:82-86) also refuses a sampler that is already listed, a second sampler on a (manager, poolId) already listed, and a 7th sampler (MAX_SAMPLERS = 6); none of these is checked at propose. The beta lists 3 samplers, so re-adding one (for example after a removeDepthSampler that was then cancelled, or a fresh DepthSampler on the same pool) is reachable. (2) BATCH: _validate checks each item against the state BEFORE the batch, but _apply re-validates item i after items 0..i-1 have applied. Items that conflict with each other all pass propose: two ADD_ILK of the same new ilk (IlkExists), two SET_BRIDGE items (the second hits ImdUSD AlreadySet), two ADD_SLEEVE_ILK items that each add a new token to a sleeve holding 5 (SLEEVE_MAX_TOKENS 6) or a new type to one listing 11 (SLEEVE_MAX_ILKS 12), and two ADD_SLEEVE_ILK items for different types that share a token (the second sees the PricerOracle mapping the first wrote). Also SET_DEPTH_LEG with a codeless leg or price (ImdDepth.setLeg checks code; _validate does not) and RETIRE_SLEEVE_TOKEN(on) for a token that is still priced (Backstop.retire StillPriced) pass propose and fail at apply. Nothing is lost: it is liveness of the Safe's queue (one pending proposal per kind), and the Safe can cancel at once. Reachable with BetaConfig: yes (ImdDepth and 3 samplers are deployed; the Safe proposes).","line":75,"path":"src/ParametersRules.sol","proof":"// SPDX-License-Identifier: MIT\npragma solidity 0.8.26;\n\nimport \"forge-std/Test.sol\";\nimport {Parameters} from \"src/Parameters.sol\";\nimport {ParametersBase} from \"src/ParametersBase.sol\";\nimport {ImdDepth} from \"src/feeds/ImdDepth.sol\";\nimport {IFeed} from \"src/interfaces/IFeed.sol\";\n\ncontract PaStub {}\n\ncontract PaJoin {\n    address public token;\n    address public ledger;\n\n    constructor(address t, address l) {\n        (token, ledger) = (t, l);\n    }\n}\n\n/// A stand-in exit-pool sampler: ImdDepth only reads manager() and poolId() when listing.\ncontract PaSampler {\n    address public manager;\n    bytes32 public poolId;\n\n    constructor(address m, bytes32 id) {\n        (manager, poolId) = (m, id);\n    }\n}\n\n/// Wave 2 says propose refuses what apply would fail on. These still pass propose, wait 48h and always revert at\n/// apply, holding their slot (and every kind they lock) until the Safe cancels.\ncontract ProofProposeApply is Test {\n    Parameters params;\n    ImdDepth depth;\n    address gov = makeAddr(\"gov\");\n    address ledger;\n    address sampler;\n    bytes32 constant ETH = \"ETH\";\n    bytes32 constant SIMD = \"SIMD\";\n\n    function setUp() public {\n        params = new Parameters(gov, address(this));\n        ledger = address(new PaStub());\n        params.wire(ledger, address(new PaStub()));\n        _add(ETH, 1_000_000e18);\n        _add(SIMD, 0);\n        params.setGenesisDepthRule(SIMD, 1e18, 0, 0, 0);\n        depth = new ImdDepth(address(params));\n        sampler = address(new PaSampler(address(0xBEEF), bytes32(uint256(1))));\n        address[] memory list = new address[](1);\n        list[0] = sampler;\n        params.setGenesisImdDepth(address(depth), list);\n        params.seal();\n    }\n\n    function _risk(uint128 line) internal pure returns (ParametersBase.Risk memory) {\n        return ParametersBase.Risk({\n            mat: 1.5e18, chop: 0.1e18, cut: 0.1e18, chip: 0.01e18, rateFloor: 0.005e18, yieldFee: 0, skew: 0.02e18,\n            pegFloor: 0, line: line, dust: 100e18, redeemFloor: 0.005e18, redeemDivisor: 4, redeemCap: 0\n        });\n    }\n\n    function _cfg() internal returns (ParametersBase.Config memory c) {\n        c.token = address(new PaStub());\n        c.join = address(new PaJoin(c.token, ledger));\n        c.median = IFeed(address(new PaStub()));\n        c.spot = c.median;\n        c.redeemable = true;\n    }\n\n    function _add(bytes32 ilk, uint128 line) internal {\n        params.addGenesisIlk(ilk, _cfg(), _risk(line));\n    }\n\n    /// ADD_DEPTH_SAMPLER of a sampler ImdDepth already lists: _validate checks only that it has code.\n    function test_addListedSamplerRefusedAtPropose() public {\n        bytes memory p = abi.encode(params.ADD_DEPTH_SAMPLER(), sampler);\n        vm.prank(gov);\n        try params.propose(p) {\n            // Queued: it must at least apply after the delay.\n            vm.warp(block.timestamp + 48 hours);\n            params.applyPending(params.ADD_DEPTH_SAMPLER()); // actual: reverts BadSampler (already listed)\n        } catch {}\n    }\n\n    /// A BATCH adding the same new type twice: each item is validated against the state before the batch.\n    function test_batchDuplicateAddIlkRefusedAtPropose() public {\n        bytes[] memory items = new bytes[](2);\n        bytes memory add = abi.encode(params.ADD_ILK(), bytes32(\"WSTETH\"), _cfg(), _risk(1_000e18));\n        (items[0], items[1]) = (add, add);\n        bytes memory p = abi.encode(params.BATCH(), items);\n        vm.prank(gov);\n        try params.propose(p) {\n            vm.warp(block.timestamp + 48 hours);\n            params.applyPending(params.BATCH()); // actual: reverts IlkExists on the second item\n        } catch {}\n    }\n}","reproduction":"Beta state: ImdDepth lists sampler S. Safe: propose(abi.encode(ADD_DEPTH_SAMPLER, S)) -> accepted. After 48h, applyPending(24) -> expected: refused at propose (or applied); actual: reverts BadSampler() at apply, and slot 24 stays locked until cancel(24). Second case: propose(abi.encode(BATCH, [ADD_ILK(WSTETH, cfg, risk), ADD_ILK(WSTETH, cfg, risk)])) -> accepted; after 48h applyPending(17) reverts IlkExists(). Test test/scratch/ProofProposeApply.t.sol: both tests FAIL on this commit with BadSampler() and IlkExists(). Smallest fix: in _validate for ADD_DEPTH_SAMPLER, refuse a sampler already in imdDepth.samplers(), one whose (manager, poolId) is already listed, and a full list. In the BATCH branch of _validate, validate each item and then apply it on a scratch copy, or simply refuse two items of the same kind except SET_RISK/SET_CAP/SET_TARGET/SET_GROUP on different ilks, and count new sleeve tokens/types across the batch.","severity":"low","snippet":"        } else if (kind == ADD_DEPTH_SAMPLER) {\n            (, address sampler) = abi.decode(payload, (uint8, address));\n            if (address(imdDepth) == address(0) || sampler.code.length == 0) revert OutOfBounds();","title":"Still passes propose and always fails at apply: ADD_DEPTH_SAMPLER of a listed sampler or pool, and a BATCH whose items conflict with each other (two ADD_ILK of one type, two SET_BRIDGE, ADD_SLEEVE_ILK"},{"citation":"resolved","description":"The wave-1 fix says the instant lower is refused because it 'would RAISE the enforced line without the timelock; SET_OTHER_IMD (48h) does that'. The check reads depthLine() at the moment of the call. depthIMD() is not a fixed figure: ImdDepth's 7-day low changes every hour (keeper gaps, the depth griefing in the README). Lowering otherImdLines while depthLine() >= the stored line removes the other-chain term from every FUTURE depthLine(). When depth then falls, risk(SIMD).line = min(stored, depthLine()) is higher than it would have been. This is the wave-1 raise again, delayed by however long it takes depth to fall. BetaConfig counts the Robinhood IMD line (otherImdLines 3,000 at chop 20%, a 3,600 term), so lowering it to 0 is up to 3,000 more sIMD line once depth binds. The Safe is trusted, so this is low. The point is that the fix does not deliver the property it states.","line":214,"path":"src/Parameters.sol","proof":"// SPDX-License-Identifier: MIT\npragma solidity 0.8.26;\n\nimport \"forge-std/Test.sol\";\nimport {Parameters} from \"src/Parameters.sol\";\nimport {ParametersBase} from \"src/ParametersBase.sol\";\nimport {IFeed} from \"src/interfaces/IFeed.sol\";\n\ncontract OlStub {}\n\ncontract OlJoin {\n    address public token;\n    address public ledger;\n\n    constructor(address t, address l) {\n        (token, ledger) = (t, l);\n    }\n}\n\n/// The measured depth, moved by the test (it moves hourly on chain: DepthSampler + ImdDepth.poke).\ncontract OlDepth {\n    address public params;\n    uint256 public depth;\n\n    constructor(address p) {\n        params = p;\n    }\n\n    function set(uint256 d) external {\n        depth = d;\n    }\n\n    function addSampler(address) external {}\n}\n\n/// Wave 2 refuses lowerOtherImdLines only while the depth line binds NOW. Lowered one block before it binds, the instant\n/// act still raises the enforced sIMD line as soon as depth falls: the same raise without the 48h timelock.\ncontract ProofOtherImdLater is Test {\n    Parameters params;\n    OlDepth depth;\n    address gov = makeAddr(\"gov\");\n    bytes32 constant SIMD = \"SIMD\";\n\n    function setUp() public {\n        params = new Parameters(gov, address(this));\n        address ledger = address(new OlStub());\n        params.wire(ledger, address(new OlStub()));\n        address t = address(new OlStub());\n        ParametersBase.Config memory c;\n        c.token = t;\n        c.join = address(new OlJoin(t, ledger));\n        c.median = IFeed(address(new OlStub()));\n        c.spot = c.median;\n        c.redeemable = true;\n        ParametersBase.Risk memory r = ParametersBase.Risk({\n            mat: 1.7e18, chop: 0.2e18, cut: 0.04e18, chip: 0, rateFloor: 0.005e18, yieldFee: 0, skew: 0.02e18,\n            pegFloor: 0, line: 10_000e18, dust: 100e18, redeemFloor: 0.005e18, redeemDivisor: 2, redeemCap: 0\n        });\n        params.addGenesisIlk(SIMD, c, r);\n        // BetaConfig's other-chain term: the Robinhood IMD line 3,000 at chop 20%.\n        params.setGenesisDepthRule(SIMD, 1e18, 0, 3_000e18, 0.2e18);\n        depth = new OlDepth(address(params));\n        params.setGenesisImdDepth(address(depth), new address[](0));\n        params.seal();\n        depth.set(15_600e18); // depthLine = (15,600 - 3,600) / 1.2 = 10,000 = the stored line: not binding\n    }\n\n    function test_lowerOtherImdLinesDoesNotRaiseLineAfterDepthFalls() public {\n        assertEq(params.risk(SIMD).line, 10_000e18);\n        vm.prank(gov);\n        try params.lowerOtherImdLines(0) {} catch {} // accepted: the depth line does not bind at this moment\n        // One hour later the measured depth falls 23% (a keeper gap or a cheap push, README 'Depth griefing').\n        depth.set(12_000e18);\n        // With the other chain's 3,000 still counted: (12,000 - 3,600) / 1.2 = 7,000. After the instant act: 10,000.\n        assertLe(params.risk(SIMD).line, 7_000e18, \"instant act raised the enforced sIMD line\");\n    }\n}","reproduction":"BetaConfig-like state: SIMD stored line 10,000, chop 0.2, redeemCap 0, k = 1, otherImdLines 3,000 at chop 0.2, measured depth 15,600 -> depthLine = (15,600-3,600)/1.2 = 10,000, not binding. Safe: lowerOtherImdLines(0) -> accepted. One hour later depth reads 12,000. Expected (other term still counted, the change being a timelocked SET_OTHER_IMD): line 7,000. Actual: risk(SIMD).line = 10,000. test/scratch/ProofOtherImdLater.t.sol FAILS: 'instant act raised the enforced sIMD line: 10000e18 > 7000e18'. Smallest fix: remove the instant lowerOtherImdLines and leave the change to SET_OTHER_IMD (48h). An instant act that can only ever widen the room is not a risk-reducing act. The other option is to keep it only when the stored line is also lowered so that need is unchanged.","severity":"low","snippet":"    function lowerOtherImdLines(uint256 lines) external onlyGovernor {\n        if (depthIlk == bytes32(0) || lines >= otherImdLines) revert OutOfBounds();\n        if (depthLine() < _risk[depthIlk].line) revert OutOfBounds();","title":"lowerOtherImdLines is refused only while the depth line binds now: lowered one hour before depth falls, the instant act still raises the enforced sIMD line without the 48h timelock"},{"citation":"resolved","description":"_stageDepth keeps a recorded ImdDepth if its params() is right, then rebuilds d.samplers from scratch whenever the config's sampler count differs from the record. setGenesisImdDepth (the only genesis listing) runs only if Parameters does not already point at d.imdDepth. On a resume where it already does, the new samplers are deployed and never listed. ImdDepth.samplers() is never compared with `list`, so the resume adopts the earlier run's listing and goes on to seal Parameters. A config that dropped a suspect pool keeps measuring that pool, which inflates depth and raises the sIMD line over what the config intends. A config that added a pool measures fewer pools than intended. Every other kept piece (types, feeds, risk, sleeves, Allocator, a changed sampler at the same index) now stops with Mismatch, which the wave-1 proofs confirm below. After the seal the fix is removeDepthSampler (instant) plus ADD_DEPTH_SAMPLER (48h). Reachable with BetaConfig: yes, if the 3-sampler list is edited between a broken stage-4 run and its resume.","line":275,"path":"script/deploy/StageGenesis.sol","proof":"// SPDX-License-Identifier: MIT\npragma solidity 0.8.26;\n\nimport \"forge-std/Test.sol\";\nimport {DeployTypes} from \"script/DeployConfig.sol\";\nimport {StageGenesis} from \"script/deploy/StageGenesis.sol\";\nimport {Parameters} from \"src/Parameters.sol\";\nimport {ImdDepth} from \"src/feeds/ImdDepth.sol\";\nimport {IFeed} from \"src/interfaces/IFeed.sol\";\n\n/// A pool manager whose every pool reads as initialised at price 1 (StateLibrary.getSlot0 reads extsload).\ncontract RsCode {\n    function extsload(bytes32) external pure returns (bytes32) {\n        return bytes32(uint256(1 << 96));\n    }\n}\n\ncontract RsToken {\n    function decimals() external pure returns (uint8) {\n        return 18;\n    }\n}\n\n/// Stage 4's depth step exactly as the launch runs it, on a deployment record `d`.\ncontract RsStage is StageGenesis {\n    function depthStep(DeployTypes.Config memory cfg, Deployed memory d) external returns (Deployed memory) {\n        _stageDepth(cfg, d);\n        return d;\n    }\n}\n\n/// A resumed stage 4 that rebuilds a sampler (the recorded one is from another config) never lists the new one:\n/// Parameters already points at the recorded ImdDepth, so `setGenesisImdDepth` is skipped and ImdDepth keeps measuring\n/// the depth of the OLD samplers, which nothing compares with the config.\ncontract ProofResumeSamplers is Test {\n    RsStage h;\n    address manager;\n    address tokenA;\n    address tokenB;\n\n    function setUp() public {\n        h = new RsStage();\n        manager = address(new RsCode());\n        (tokenA, tokenB) = (address(new RsToken()), address(new RsToken()));\n        if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA);\n    }\n\n    function _spec(DeployTypes.SamplerSpec memory sp, uint24 fee, int24 spacing) internal view {\n        (sp.currency0, sp.currency1, sp.fee, sp.tickSpacing, sp.hooks) = (tokenA, tokenB, fee, spacing, address(0));\n        sp.poolId = keccak256(abi.encode(tokenA, tokenB, fee, spacing, address(0)));\n        (sp.feed0, sp.feed1) = (DeployTypes.NO_FEED, DeployTypes.NO_FEED);\n        (sp.bandBps, sp.maxDeviationTicks, sp.maxSteps, sp.soldIsToken0) = (1_500, 200, 64, true);\n    }\n\n    /// `n` exit pools: the first is the same pool and spec in every config.\n    function _cfg(uint256 n) internal view returns (DeployTypes.Config memory cfg) {\n        cfg.poolManager = manager;\n        cfg.depth.enabled = true;\n        cfg.depth.samplers = new DeployTypes.SamplerSpec[](n);\n        _spec(cfg.depth.samplers[0], 10_000, 200);\n        if (n > 1) _spec(cfg.depth.samplers[1], 3_000, 60);\n    }\n\n    function test_resumedDepthStepListsTheSamplersItKeeps() public {\n        RsStage.Deployed memory d;\n        d.params = new Parameters(makeAddr(\"gov\"), address(h));\n        d.feeds = new IFeed[](0);\n        // Run 1 lists one exit pool's sampler A in ImdDepth (the run then stops later in stage 4, before the seal).\n        d = h.depthStep(_cfg(1), d);\n        address a = address(d.samplers[0]);\n        assertEq(d.imdDepth.samplers()[0], a);\n        // The config gains a second exit pool and stage 4 is resumed on the same record.\n        try h.depthStep(_cfg(2), d) returns (RsStage.Deployed memory d2) {\n            address[] memory listed = d2.imdDepth.samplers();\n            // expected: ImdDepth measures the two samplers the record now holds (or the resume stops: Mismatch).\n            // actual: both were rebuilt, neither is listed, and ImdDepth still measures A alone.\n            assertEq(listed.length, 2, \"ImdDepth does not list the config's samplers\");\n            assertEq(listed[0], address(d2.samplers[0]));\n            assertEq(listed[1], address(d2.samplers[1]));\n        } catch {\n            // refused (Mismatch): also correct\n        }\n    }\n}","reproduction":"Run 1 of _stageDepth with one SamplerSpec (pool P1): ImdDepth lists A. The run stops before the seal. The config gains pool P2 and stage 4 is resumed on the same record. Expected: ImdDepth lists the two samplers in d.samplers, or the run stops with Mismatch. Actual: two new samplers are deployed, setGenesisImdDepth is skipped, and ImdDepth.samplers() = [A]. test/scratch/ProofResumeSamplers.t.sol FAILS: 'ImdDepth does not list the config's samplers: 1 != 2'. Smallest fix: after building `list`, if Parameters already points at d.imdDepth, require keccak256(abi.encode(d.imdDepth.samplers())) == keccak256(abi.encode(list)) or revert Mismatch(\"ImdDepth lists other samplers\"). Also keep recorded samplers by index instead of discarding the whole array when the length changes.","severity":"low","snippet":"        uint256 n = cfg.depth.samplers.length;\n        if (d.samplers.length != n) d.samplers = new DepthSampler[](n);","title":"Deploy resume (M6): a stage-4 resume whose sampler list changed rebuilds every sampler but never lists them; ImdDepth keeps measuring the previous run's samplers, and nothing compares its list with th"},{"citation":"resolved","description":"Runtime sizes measured from this commit's solc via_ir artifacts (bytecode_hash none): ParametersRules 24,494 (82 left of EIP-170's 24,576), Parameters 22,404 (2,172), Ledger 22,398 (2,178), LedgerSettlement 17,979 (6,597), Allocator 22,698 (1,878, against the brief's 'about 2.6 KB'), Backstop 19,942 (4,634), Liquidator 12,112 (12,464). Every new governed kind, and every validation added at propose (including the fixes suggested in this report), lands in ParametersRules first. 82 bytes is less than one more abi.decode-and-bounds branch, so the next kind needs a redeploy of Parameters' rules or a third delegatecall split. The rules contract is immutable in Parameters' constructor, so it cannot be swapped without a new Parameters, and with it a new Ledger wiring.","line":10,"path":"src/ParametersRules.sol","reproduction":"Build the panel with solc 0.8.26 via_ir per foundry.toml and read out/ParametersRules.sol/ParametersRules.json deployedBytecode: 24,494 bytes. out/Allocator.sol/Allocator.json: 22,698 bytes (1,878 left).","severity":"info","snippet":"    uint256 internal constant SLEEVE_MAX_TOKENS = 6; // Backstop.MAX_TOKENS\n    uint256 internal constant SLEEVE_MAX_ILKS = 12; // Backstop.MAX_ILKS","title":"Room to grow: ParametersRules has 82 bytes left (24,494 B); Allocator has 1,878 B, not the ~2.6 KB stated; Parameters 2,172 B; Ledger 2,178 B"},{"citation":"resolved","description":"backstopSpec lists six distinct blue tokens at genesis: WETH, wstETH, cbBTC, WBTC, sUSDS and steakUSDC. Backstop.MAX_TOKENS is 6, and ParametersRules refuses ADD_SLEEVE_ILK for a new token once tokenCount() >= 6. Parameters.blueBackstop/edgeBackstop are written once by setGenesisBackstops before the seal and have no governed kind, and ParametersRules has 82 bytes left for one. So from day one, the first new blue type with a new token (a new LST, tBTC, another staked stable) can only be listed without a standing bid. Its liquidations then go to callers only. A second blue sleeve needs a new Parameters, which means a new Ledger wiring: a redeploy. A blue token freed by RETIRE_SLEEVE_TOKEN still counts. Of everything in v2, this runs out first, before code size or proposal slots.","line":518,"path":"script/DeployConfig.sol","reproduction":"Deploy with BetaConfig. blue.tokenCount() == 6. ADD_ILK a new type X on a new token (48h), then propose(abi.encode(ADD_SLEEVE_ILK, X, false, 0, saleMax, slope)) -> reverts OutOfBounds at propose (ParametersRules.sol:113). Expected for a capped beta meant to add types: room to list at least one more blue token. Smallest fix before the freeze: raise Backstop.MAX_TOKENS (and SLEEVE_MAX_TOKENS) to 8-10, or leave one slot free by not listing one of the two BTC wrappers at genesis. Longer term: a timelocked kind that adds a third sleeve address.","severity":"info","snippet":"        b.ilks[0] = DeployTypes.SleeveIlk(\"ETH\", false, 0, 50e18);\n        b.ilks[1] = DeployTypes.SleeveIlk(\"WSTETH\", false, 0, 40e18);\n        b.ilks[2] = DeployTypes.SleeveIlk(\"CBBTC\", false, 0, 2e8);\n        b.ilks[3] = DeployTypes.SleeveIlk(\"WBTC\", false, 0, 2e8);\n        b.ilks[4] = DeployTypes.SleeveIlk(\"S-USDS\", false, 0, 200_000e18);\n        b.ilks[5] = DeployTypes.SleeveIlk(\"S-USDC-STEAKHOUSE\", false, 0, 200_000e18);","title":"Room to grow: the beta fills the blue sleeve to Backstop.MAX_TOKENS (6) at genesis, and the sleeves are set once in Parameters, so no new blue collateral token can ever get the standing bid without a "}],"hash":"ea455c8941a508eba2bbfe6933a3fbeee48057647ff30094c65721bf314cb2fb","nodeId":"d58cac35-2bc4-4864-bd17-57b43e9932dd","outcome":"completed","summary":"The wave-1 fixes I re-checked all hold, but I found 3 new low-severity defects and 2 info notes. Each low one has a Foundry proof that fails on this commit; they are all in `.imd-findings.json`. The panel suite passes: 87 tests, plus 4 failing proof tests, which is the intended result.\n\n**How it ran:** Forge 1.8.3 has no solar, so everything built with solc via_ir. Proofs went under `test/scratch/` and I deleted them afterwards; the tree is unchanged.\n\n```\nforge test --match-path 'test/{unit/{AuditW1{BatchItems,OtherImdLines,PostLowerDepth,RateStep,ResumeTypes},Core,PanelParams,CapAndSlots},scratch/Proof{ProposeApply,OtherImdLater,ResumeSamplers}}.t.sol'\nAuditW1BatchItems 3/3 · AuditW1OtherImdLines 1/1 · AuditW1PostLowerDepth 1/1 · AuditW1RateStep 1/1 · AuditW1ResumeTypes 3/3\nCapAndSlots 18/18 + 1/1 · Core 48/48 · PanelParams 11/11\n[FAIL: instant act raised the enforced sIMD line: 10000e18 > 7000e18] ProofOtherImdLater\n[FAIL: BadSampler()] test_addListedSamplerRefusedAtPropose\n[FAIL: IlkExists()] test_batchDuplicateAddIlkRefusedAtPropose\n[FAIL: ImdDepth does not list the config's samplers: 1 != 2] ProofResumeSamplers\n12 suites: 87 passed, 4 failed (the 4 proofs)\n```\n\n## Findings\n1. **Low – `src/ParametersRules.sol:75`.** These proposals still pass propose and then always revert at apply. The slot and its locks stay held until the Safe cancels.\n   - `ADD_DEPTH_SAMPLER` for a sampler or pool that is already listed, or a 7th sampler: apply reverts `BadSampler` / `TooManySamplers`.\n   - A `BATCH` whose items conflict with each other: propose checks each item against the state before the batch. Examples are two `ADD_ILK` of one type (`IlkExists`), two `SET_BRIDGE`, and `ADD_SLEEVE_ILK` items that together overfill a sleeve or share a token.\n   - `SET_DEPTH_LEG` with a feed address that has no code, and `RETIRE_SLEEVE_TOKEN(on)` for a token that still has a price.\n2. **Low – `src/Parameters.sol:214`.** `lowerOtherImdLines` is refused only while the depth line binds at that moment. Lowered just before the measured depth falls, it still raises the enforced sIMD line with no timelock. With BetaConfig's 3,000 other-chain line: stored line 10,000, depth drops from 15,600 to 12,000, and the line reads 10,000 instead of 7,000. Fix: drop the instant act and use `SET_OTHER_IMD` (48h).\n3. **Low – `script/deploy/StageGenesis.sol:275`.** This is the answer to question 2. If the sampler list changes between a broken stage-4 run and its resume, the resume deploys new samplers but never lists them. ImdDepth keeps measuring the old run's samplers, and nothing compares its list with the config.\n4. **Info – code size.** Measured from this build: ParametersRules has 82 bytes left, Parameters 2,172, Ledger 2,178. The Allocator has 1,878, not the \"about 2.6 KB\" in the brief.\n5. **Info – the blue sleeve is full at genesis.** BetaConfig lists 6 tokens, which is `MAX_TOKENS`. The sleeve addresses are set once before the seal. So no new blue token can ever get the standing bid without a new Parameters.\n\n## 1. Governance re-check\nI re-ran the 7 Parameters proofs and 2 RateManager proofs from job cd9184ac against this commit. The wave-1 problems no longer occur:\n- **Malformed BATCH:** propose now reverts while decoding the item, so the bad state can't be set up.\n- **`lowerOtherImdLines(0)` while binding:** reverts `OutOfBounds`.\n- **`postLowerDepth` from 0:** reverts `OutOfBounds`.\n- **RateManager:** both proofs pass; the step reference survives a target of 0.\n- **SET_KEEPER / SET_BRIDGE / full sleeve:** refused at propose, by reading the code.\n\nWhat still passes propose and fails at apply is finding 1. The known 3-word `RETIRE_SLEEVE_TOKEN` case remains as well.\n\n## 2. Deploy resume (M6)\nThe deploy proofs from job 17e4edf1 now stop with `Mismatch` for a type kept with other risk or feeds, a sleeve listing from another config, and an Allocator with another freezer. BetaConfig names the Safe as freezer. The Allocator constructor still accepts a zero freezer, b","treeHash":null,"usage":{"cachedInputTokens":5821083,"cost":{"source":"runtime","usdMicros":3575667},"inputTokens":91,"model":"claude-opus-5-5","outputTokens":51256,"runtime":"claude","turns":51,"wallClockMs":1296367}},{"artifacts":[],"attempt":1,"bundleHash":null,"device":"629987aaf6c7aa88","findings":[{"citation":"resolved","description":"Question 1 asks what still passes propose and fails at apply after the wave-1 fixes. ParametersRules._validate checks ADD_DEPTH_SAMPLER only for `sampler.code.length != 0`, and SET_DEPTH_LEG (line 78-80) only for the leg/price pairing. Their apply calls ImdDepth.addSampler / ImdDepth.setLeg, and those run checks propose never runs. addSampler (src/feeds/ImdDepth.sol:82-88) refuses a sampler that is already listed, a 7th sampler (MAX_SAMPLERS = 6), and a second sampler on a pool already measured (same manager() and poolId()). It also reverts on a contract with no manager()/poolId(). setLeg (ImdDepth.sol:103-104) refuses a leg or price with no code. So each of these payloads waits 48 h and then can never apply: applyPending reverts (BadSampler), the slot and the ADD_DEPTH_SAMPLER / SET_DEPTH_LEG lock stay until the governor cancels, and the change the Safe meant to make is 48 h later than planned. Inside a BATCH (the day-7 batch pattern) one such item reverts the whole batch at apply. The same gap exists for items that conflict with each other inside one BATCH, because propose validates every item against the state before the batch: [SET_BRIDGE a, SET_BRIDGE b] passes propose and its second item fails at apply (AlreadySet). [ADD_SLEEVE_ILK X, ADD_SLEEVE_ILK Y], each with a new token, into a sleeve holding 5 tokens also passes, and Y fails at apply once X makes the sleeve full. Impact is liveness only, under the Safe's own payloads: no funds or parameters move. On the 2026-12-07 beta the depth samplers and the depth leg are exactly what the Safe expects to add after genesis (a 4th exit pool, the swarm depth leg), so a mistaken sampler costs a 48 h round trip. The other kinds keep the propose/apply symmetry that wave 1 restored. RETIRE_SLEEVE_TOKEN's 3-word payload is already in Known issues.","line":75,"path":"src/ParametersRules.sol","proof":"// SPDX-License-Identifier: MIT\npragma solidity 0.8.26;\n\nimport \"forge-std/Test.sol\";\nimport {Parameters} from \"src/Parameters.sol\";\nimport {ParametersBase} from \"src/ParametersBase.sol\";\nimport {ImdDepth} from \"src/feeds/ImdDepth.sol\";\n\ncontract PxCode {}\n\ncontract PxSampler {\n    bytes32 public poolId;\n    address public manager;\n    constructor(bytes32 id, address m) { poolId = id; manager = m; }\n}\n\n/// What still passes `propose` and can only fail at `applyPending`: ADD_DEPTH_SAMPLER is validated for code only\n/// (ImdDepth.addSampler then refuses a listed sampler, a second sampler on a listed pool, or a 7th), and SET_DEPTH_LEG\n/// is validated for pairing only (ImdDepth.setLeg then refuses a leg or price without code).\n/// Each test asserts the fixed behaviour (refused at propose) and FAILS on this commit.\ncontract ProofProposeThenApplyFails is Test {\n    Parameters params;\n    ImdDepth depth;\n    address gov = address(0xA11CE);\n    address s0;\n\n    function setUp() public {\n        params = new Parameters(gov, address(this));\n        params.wire(address(new PxCode()), address(new PxCode()));\n        depth = new ImdDepth(address(params));\n        s0 = address(new PxSampler(bytes32(uint256(1)), address(0xBEEF)));\n        address[] memory list = new address[](1);\n        list[0] = s0;\n        params.setGenesisImdDepth(address(depth), list);\n        params.seal();\n    }\n\n    function _proposeThenApply(bytes memory payload) internal returns (bool proposed, bool applied) {\n        vm.prank(gov);\n        (proposed,) = address(params).call(abi.encodeCall(params.propose, (payload)));\n        if (!proposed) return (false, false);\n        vm.warp(block.timestamp + 48 hours);\n        (applied,) = address(params).call(abi.encodeWithSignature(\"applyPending(uint8)\", uint8(payload[31])));\n    }\n\n    /// A sampler that is already listed: passes propose, waits 48h, reverts BadSampler at apply, holds the slot.\n    function test_addListedSamplerIsRefusedAtPropose() public {\n        (bool proposed, bool applied) = _proposeThenApply(abi.encode(uint8(24), s0));\n        assertTrue(proposed == applied, \"ADD_DEPTH_SAMPLER (already listed) passed propose and failed at apply\");\n    }\n\n    /// A second sampler on the pool already measured (same manager and pool id): same outcome.\n    function test_addSamplerOnListedPoolIsRefusedAtPropose() public {\n        address twin = address(new PxSampler(bytes32(uint256(1)), address(0xBEEF)));\n        (bool proposed, bool applied) = _proposeThenApply(abi.encode(uint8(24), twin));\n        assertTrue(proposed == applied, \"ADD_DEPTH_SAMPLER (same pool) passed propose and failed at apply\");\n    }\n\n    /// A depth leg naming an address with no code: passes propose (only the pairing is checked), reverts at apply.\n    function test_depthLegWithoutCodeIsRefusedAtPropose() public {\n        (bool proposed, bool applied) = _proposeThenApply(abi.encode(uint8(25), address(0x1234), address(0x5678)));\n        assertTrue(proposed == applied, \"SET_DEPTH_LEG (no code) passed propose and failed at apply\");\n        (, uint256 eta) = params.pendingOf(25);\n        assertEq(eta, 0, \"the failed kind still holds its slot and lock\");\n    }\n}","reproduction":"Parameters sealed with ImdDepth listing sampler s0 (pool id 1, manager 0xBEEF). Case 1: governor proposes abi.encode(uint8(24), s0). Expected: refused at propose. Actual: accepted, eta = now + 48 h; applyPending(24) after 48 h reverts BadSampler. Case 2: the same with a different contract on the same pool id and manager: same outcome. Case 3: governor proposes abi.encode(uint8(25), address(0x1234), address(0x5678)) (no code). Expected: refused. Actual: accepted; applyPending(25) reverts BadSampler and pendingOf(25).eta stays non-zero. Reachable with BetaConfig: yes (ImdDepth is set at genesis with 3 samplers). Smallest fix: in _validate, call a view `ImdDepth.canAdd(sampler)` that mirrors addSampler's checks (duplicate, same pool, MAX_SAMPLERS), and for SET_DEPTH_LEG require code on a non-zero leg and price. This costs about 60-80 bytes of ParametersRules' 82-byte margin; a cheaper option is a try/staticcall on the ImdDepth view. For BATCH, refuse two items of a once-only kind (SET_BRIDGE, SET_KEEPER) in one batch. Proof run: forge test --match-path test/scratch/ProofProposeThenApplyFails.t.sol -> 3 failed: [FAIL: ADD_DEPTH_SAMPLER (already listed) passed propose and failed at apply] test_addListedSamplerIsRefusedAtPropose() (gas: 288560); [FAIL: ADD_DEPTH_SAMPLER (same pool) passed propose and failed at apply] test_addSamplerOnListedPoolIsRefusedAtPropose() (gas: 459895); [FAIL: SET_DEPTH_LEG (no code) passed propose and failed at apply] test_depthLegWithoutCodeIsRefusedAtPropose() (gas: 307038). Suite result: FAILED. 0 passed; 3 failed.","severity":"low","snippet":"        } else if (kind == ADD_DEPTH_SAMPLER) {\n            (, address sampler) = abi.decode(payload, (uint8, address));\n            if (address(imdDepth) == address(0) || sampler.code.length == 0) revert OutOfBounds();","title":"ADD_DEPTH_SAMPLER and SET_DEPTH_LEG still pass propose and can only fail at apply (ImdDepth's own checks are not run at propose); the kind's slot and lock are held until the Safe cancels"},{"citation":"resolved","description":"Question 2 asks whether a resume can still adopt something it should not. Wave 1's fix compares each recorded sampler with its spec (_samplerIs) and reverts Mismatch on a difference. But line 276 (`if (d.samplers.length != n) d.samplers = new DepthSampler[](n);`) throws away the whole recorded array when the config's sampler count differs from the record's. Every sampler is then redeployed as a fresh contract. Line 299 then skips setGenesisImdDepth because Parameters already points at the kept ImdDepth. Nothing compares ImdDepth.samplers() with the list just built. The resumed run ends cleanly and seals with two different sets: ImdDepth sums the first run's samplers, and the deployment record (the addresses the keeper samples hourly) names new samplers that are not listed. The new pool is never measured. If the keeper samples the recorded addresses, the listed samplers go unsampled for 6 h and read 0, which holds the sIMD line at 0 for about 8 days (fail-closed, as in Known issues, but caused by the deploy). After the seal the repair is removeDepthSampler for each old one plus one ADD_DEPTH_SAMPLER per new one. Only one ADD_DEPTH_SAMPLER can be pending at a time, so 3-4 samplers take 3-4 sequential 48 h windows (6-8 days). The same skip applies when a record is lost and only a sampler is redeployed. The PEG-type gap is already in Known issues; this is a separate piece that is still adopted unchecked.","line":299,"path":"script/deploy/StageGenesis.sol","proof":"// SPDX-License-Identifier: MIT\npragma solidity 0.8.26;\n\nimport \"forge-std/Test.sol\";\nimport {DeployTypes} from \"script/DeployConfig.sol\";\nimport {DeployBase} from \"script/deploy/DeployBase.sol\";\nimport {StageGenesis} from \"script/deploy/StageGenesis.sol\";\nimport {Parameters} from \"src/Parameters.sol\";\nimport {Ledger} from \"src/Ledger.sol\";\nimport {DepthSampler} from \"src/feeds/DepthSampler.sol\";\n\ncontract RdBlank {\n    function ping() external pure returns (bool) {\n        return true;\n    }\n}\n\n/// A pool manager whose every slot reads an initialised pool at price 1 (sqrtPriceX96 = 2^96, tick 0).\ncontract RdManager {\n    fallback(bytes calldata) external returns (bytes memory) {\n        return abi.encode(uint256(1) << 96);\n    }\n}\n\ncontract RdToken {\n    function decimals() external pure returns (uint8) {\n        return 18;\n    }\n}\n\n/// Step 6a of stage 4 exactly as the launch runs it, on a deployment record `d`.\ncontract RdStage is StageGenesis {\n    function stageDepth(DeployTypes.Config memory cfg, Deployed memory d) external returns (Deployed memory) {\n        _stageDepth(cfg, d);\n        return d;\n    }\n}\n\n/// A resumed stage 4 whose config has one more exit pool than the first run redeploys EVERY sampler (the record's array is\n/// reset when its length differs) but skips `setGenesisImdDepth` because Parameters already points at the kept ImdDepth.\n/// The run ends without a Mismatch, with ImdDepth summing the first run's samplers and the record (which the keeper\n/// samples) naming other, unlisted ones. Asserts the expected state (listed == recorded); FAILS on this commit.\ncontract ProofResumeDepthSamplers is Test {\n    RdStage h;\n    Parameters params;\n    address manager;\n    address imd;\n\n    function setUp() public {\n        h = new RdStage();\n        params = new Parameters(address(0x5AFE), address(h));\n        (address l, address u) = (address(new RdBlank()), address(new RdBlank()));\n        vm.prank(address(h));\n        params.wire(l, u);\n        manager = address(new RdManager());\n        imd = address(new RdToken());\n    }\n\n    function _spec(uint24 fee) internal view returns (DeployTypes.SamplerSpec memory sp) {\n        sp.currency0 = address(0);\n        sp.currency1 = imd;\n        sp.fee = fee;\n        sp.tickSpacing = 60;\n        sp.hooks = address(0);\n        sp.poolId = keccak256(abi.encode(address(0), imd, fee, int24(60), address(0)));\n        sp.feed0 = DeployTypes.NO_FEED;\n        sp.feed1 = DeployTypes.NO_FEED;\n        sp.bandBps = 1_500;\n        sp.maxDeviationTicks = 200;\n        sp.maxSteps = 50;\n        sp.soldIsToken0 = false;\n    }\n\n    function test_resumeWithAnExtraPoolKeepsTheOldSamplerList() public {\n        DeployTypes.Config memory cfg;\n        cfg.poolManager = manager;\n        cfg.depth.enabled = true;\n        cfg.depth.samplers = new DeployTypes.SamplerSpec[](1);\n        cfg.depth.samplers[0] = _spec(3_000);\n        DeployBase.Deployed memory d;\n        d.params = params;\n        d.ledger = Ledger(payable(address(new RdBlank())));\n        d = h.stageDepth(cfg, d); // first run: ImdDepth lists sampler A, then the run stops before the seal\n        address first = address(d.samplers[0]);\n        assertEq(address(params.imdDepth()), address(d.imdDepth));\n\n        // The config gains a second exit pool; the resume runs step 6a again on the same record.\n        DeployTypes.SamplerSpec[] memory two = new DeployTypes.SamplerSpec[](2);\n        two[0] = _spec(3_000);\n        two[1] = _spec(10_000);\n        cfg.depth.samplers = two;\n        d = h.stageDepth(cfg, d);\n\n        assertTrue(address(d.samplers[0]) != first, \"the pool already measured got a NEW sampler\");\n        address[] memory listed = d.imdDepth.samplers();\n        assertEq(listed[0], first, \"(state) ImdDepth still lists the first run's sampler\");\n        assertEq(listed.length, 2, \"ImdDepth lists the config's two samplers\");\n        assertEq(listed[0], address(d.samplers[0]), \"ImdDepth sums the recorded sampler\");\n    }\n}","reproduction":"Stage 4 step 6a (_stageDepth) on record d with one sampler spec (pool A): ImdDepth is deployed and lists sampler A1, and the run stops before the seal. The config gains a second exit pool (pool B) and the same step runs again on the same d. Expected: Mismatch, or ImdDepth listing exactly d.samplers. Actual: d.samplers = [A2, B1] (A redeployed), ImdDepth.samplers() = [A1], no revert. Reachable with BetaConfig: yes, on a resumed beta deploy whose depth.samplers list changed between runs (BetaConfig lists 3 samplers). Smallest fix (script only, no contract change): do not reset d.samplers when the length differs; reuse the recorded entries by index. And when params.imdDepth() == d.imdDepth, require keccak256(abi.encode(d.imdDepth.samplers())) == keccak256(abi.encode(list)), else revert Mismatch(\"ImdDepth lists other samplers\"). Proof run: forge test --match-path test/scratch/ProofResumeDepthSamplers.t.sol -> [FAIL: ImdDepth lists the config's two samplers: 1 != 2] test_resumeWithAnExtraPoolKeepsTheOldSamplerList() (gas: 7726851). Suite result: FAILED. 0 passed; 1 failed. The assertions before it passed: the pool already measured got a new sampler, and ImdDepth still lists the first run's sampler.","severity":"low","snippet":"        if (address(d.params.imdDepth()) != address(d.imdDepth)) {\n            g = gasleft();\n            d.params.setGenesisImdDepth(address(d.imdDepth), list);","title":"Deploy resume (M6): a stage-4 rerun with a different sampler count redeploys every DepthSampler but keeps ImdDepth's old sampler list, and finishes without a Mismatch"}],"hash":"f44a6683ea43c3612bcb854b79fe3150ae464703abab401695aa4be03ad040cd","nodeId":"db815714-9fc9-471e-bf02-d71ffac37ac2","outcome":"completed","summary":"I found two low-severity defects at 5de80a6, both in `.imd-findings.json` with proofs that fail on this commit. All the wave-1 proofs I re-ran no longer reproduce their bugs.\n\n**Build and coverage.** This machine has Foundry 1.8.3, so there was no `--use solar`; everything ran under solc. The panel glob ran 87 tests, all passing. I re-ran 13 of the 14 distinct proofs from wave-1 jobs cd9184ac (governance) and 17e4edf1 (deploy) as `test/unit/ProofW1_*.t.sol`. I skipped `17e4edf1_1_1` because it imports all of `script/Deploy.s.sol`, which would mean a near-full solc build. `17e4edf1_0_0` covers the same stage-3 resume. My own two proofs ran from `test/scratch/`. I deleted every proof file afterwards and the tree is unchanged.\n\nI did not test Questions 3–5 numerically or build anything for them: the answers below are design reasoning from the code and README. I did not re-run proofs from the other six wave-1 jobs, since they fall outside Questions 1–2.\n\n## 1. Governance: what still passes propose and fails at apply\n\nAll the wave-1 fixes hold:\n- **Malformed BATCH item:** propose now refuses it. Two proofs now fail at `propose` itself; the third returns early by design and passes.\n- **`lowerOtherImdLines` while the depth line binds:** refused with `OutOfBounds`.\n- **`postLowerDepth` from 0 without ImdDepth:** refused with `OutOfBounds` (both proof variants).\n- **RateManager after a target of 0:** `test_maxStepHoldsAfterZeroTarget` passes.\n- **`SET_KEEPER` / `SET_BRIDGE` / full sleeve:** refused at propose (read in the code; no runnable wave-1 proof).\n\nWhat still passes propose and fails at apply:\n- **Finding (low):** `ADD_DEPTH_SAMPLER` is checked only for having code (`ParametersRules.sol:75`). ImdDepth then refuses it at apply if it is already listed, measures a pool already listed, or would be a 7th sampler. `SET_DEPTH_LEG` is checked only for its leg/price pairing, and apply refuses a leg or price with no code. Each such proposal waits 48 hours, can never apply, and keeps its slot until the Safe cancels it.\n- **Items in one BATCH that conflict:** propose checks every item against the state before the batch. `[SET_BRIDGE a, SET_BRIDGE b]` passes, and so does two `ADD_SLEEVE_ILK` items with new tokens into a sleeve holding 5 tokens. The second item then fails at apply and the whole batch reverts.\n- **By design:** depth-rule raises (`SET_RISK`, `SET_DEPTH_K`, `SET_OTHER_IMD`), `SET_CAP` against the live low and edge listings are only judged at apply. The 3-word `RETIRE_SLEEVE_TOKEN` is already in Known issues.\n- **Fix:** an ImdDepth `canAdd(sampler)` view called from validate, plus a code check on the depth leg and price. This is roughly 60–80 bytes against the 82 left in ParametersRules.\n\n## 2. M6: can a resume still adopt something it should not?\n\nYes, in one place. All four wave-1 resume proofs now stop with `Mismatch`, so the fixed pieces hold.\n\n- **Finding (low), `StageGenesis.sol:276/299`:** if the number of depth samplers in the config changes between runs, the resume throws away the recorded samplers and deploys new ones for every pool. It then skips `setGenesisImdDepth` because Parameters already points at the kept ImdDepth, and seals without an error.\n  - ImdDepth keeps summing the first run's samplers, while the keeper samples the new, unlisted ones.\n  - The proof shows ImdDepth listing 1 sampler where the config has 2.\n  - Repair after the seal needs one 48-hour `ADD_DEPTH_SAMPLER` window per sampler, because only one can be pending at a time.\n- **Kept but fail-safe:** a chain already capped while the config is uncapped, and `maxLull` already 0 while `graceOff` is false. Both are kept without a check, but they err toward less debt.\n- **Known issue:** the PEG type on resume.\n\n## 3. Operations\n\n| Chore | 1 hour | 1 day | 1 week | Who should do it |\n|---|---|---|---|---|\n| Depth samples and the ImdDepth poke | nothing | after ~6 h unsampled the sampler reads 0, and the 7-day low holds sIMD borrowing at 0 for about 8 days ","treeHash":null,"usage":{"cachedInputTokens":4350971,"cost":{"source":"runtime","usdMicros":2708031},"inputTokens":76,"model":"claude-opus-5-5","outputTokens":32677,"runtime":"claude","turns":47,"wallClockMs":1073053}}],"verification":[]}