{
 "item": "house-pricer-liquidation",
 "commit": "ff1c192b3798542997f600091f2dc73ff05e4c40",
 "forge": "forge 1.8.3 (older than 1.9: no --use solar; solc 0.8.38 from svm). Repo profile (via_ir + full optimizer) did not finish compiling in 580 s here, so tests ran with an extra profile in the throwaway clone only: FOUNDRY_PROFILE=fast = same via_ir/optimizer, yul optimizer_steps 'u:'. Command: FOUNDRY_PROFILE=fast forge test --offline --match-path test/goal/HPL.t.sol -vv",
 "verdict": "findings",
 "findings": [
  {
   "id": "HPL-F1",
   "severity": "low",
   "title": "NHI leaf (mat) moves two caps in one direction inside one maxAge: 0.85 -> 0.5667, mat 1.7 -> 2.0 between reads 86,399 s apart",
   "property": "P4 (and the SwarmNhiFeed's own 'ONE CAP PER WINDOW OF TIME, NOT PER EPOCH' rule, src/house/feeds/SwarmFeeds.sol:97-100)",
   "claim": "C3",
   "files": [
    "src/house/feeds/SwarmFeed.sol:584",
    "src/house/feeds/SwarmFeed.sol:739",
    "src/house/feeds/SwarmFeed.sol:740",
    "src/house/feeds/SwarmFeeds.sol:97",
    "src/house/Pricer.sol:93"
   ],
   "sequence": "NHI held at v0=0.590278 for >1 day. T: attest 1e24 -> epoch E1 opens, stored v0*1.2, _movedAt=T. T+1d (exactly maxAge after the move, so _carryNow()=0 at SwarmFeed.sol:584 because it uses >=): attest 1e24 -> E2 opens at v0*1.2, no carry, stored v0*1.44=0.8500003 (mat 1.7). T+1d+2: attest 1 -> inside E2 the range rule lets it fall to hi*0.8=0.68. T+2d: attest 1 -> E3 opens at 0.68 with carry = E2's anchor v0*1.2=0.7083, lower edge max(0.68*0.8, 0.7083*0.8)=0.5667 (mat 2.0). The value 0.85 was held at T+1d+1; 0.5667 at T+2d: 86,399 s apart, < maxAge. Every single epoch moves at most one cap from the value held (P4 as worded per epoch holds), but per time NHI fell 33.3% (0.5667/0.85 = 0.667 = 0.8 x 0.8333) and mat went 1.7 -> 2.0, the very move (0.85 -> 0.68 -> 0.544, mat 1.7 -> 2.0) the carry fix says it stops; it now takes 86,399 s instead of 1 s. Mirror image upward (testFuzz_P4 counterexample): 0.576 -> 0.82944 (+44%) in 86,399 s, which lowers mat and shelters unhealthy positions.",
   "expected": "Per SwarmFeeds.sol:97 'ONE CAP PER WINDOW OF TIME': any two NHI values held less than maxAge apart are within one cap (20%) of each other, so mat moves at most one cap's worth inside a day.",
   "actual": "Two values held 86,399 s apart differ by -33.3% (and +44% upward). The code bounds each window to one cap around SOME earlier value X (spread X*0.8..X*1.2), i.e. two caps pairwise, and the carry is skipped for an epoch opened exactly maxAge after the last move (>= at SwarmFeed.sol:584). Who can do it: the swarm attester key (or a wrong majority) signing within each per-epoch cap; README:1186 bounds a wrong NHI 'by its feed's per-epoch cap and lifetime', and this is within per-epoch caps, so the excess is only against the per-time rule the leaf states.",
   "reachableAtDeploy": true,
   "fix": "Bound against the whole previous window, not one anchor: keep the min and max of values held in the last maxAge (or the previous epoch's range) and clamp a new value into [max_prev*(1-c), min_prev*(1+c)]; and make the carry condition `block.timestamp - _movedAt <= maxAge` (include the edge). Or state the true bound ((1-c)^2 down / (1+c)^2 up per window of maxAge) in SwarmFeeds.sol:97 and the W5 test header.",
   "test": {
    "source": "// test/goal/HPL.t.sol (contract HPLTest is System, test/house/utils/System.sol harness; sIMD = MockFeed median=spot, NHI = DoorNhiLeaf from test/house/unit/PricerTwin.t.sol (SwarmNhiPolicy, maxAge 1 day, cap 2000 bps))\n    function setUp() public {\n        vm.chainId(1);\n        vm.warp(1_800_000_000);\n        vm.roll(26_000_000);\n        nhi = new DoorNhiLeaf();\n        nhi.set(0.98e18);\n        price = new MockFeed(100e18);\n        price.setMaxAge(type(uint64).max);\n        med = new MockFeed(100e18);\n        med.setMaxAge(type(uint64).max);\n        prov = new MockProven(100e18);\n        prov.setMaxAge(type(uint64).max);\n        _deploySystem(IERC20(address(new MockERC20(\"imdUSDv1\", 18))));\n        simd = new MockERC20(\"sIMD\", 18);\n        ParametersBase.Risk memory r = _risk(1.7e18, 10_000_000e18);\n        r.skew = 0.05e18;\n        _addIlk(SIMD, address(simd), IFeed(address(price)), IFeed(address(price)), IFeed(address(nhi)), address(0), address(0), true, r);\n        _addIlk(TWIN, address(new MockERC20(\"t\", 18)), IFeed(address(med)), IFeed(address(prov)), IFeed(address(0)), address(0), address(0), true, r);\n        simd.mint(alice, 1_000_000e18);\n        vm.startPrank(alice);\n        simd.approve(address(ledger), type(uint256).max);\n        usd.approve(address(ledger), type(uint256).max);\n        vm.stopPrank();\n        simd.mint(keeper, 10e18);\n        vm.prank(keeper);\n        simd.approve(address(ledger), type(uint256).max);\n        _fund(keeper, 1_000_000e18);\n        vm.prank(keeper);\n        usd.approve(address(ledger), type(uint256).max);\n    }\n    function _stored() internal view returns (uint256 v) {\n        (v,) = nhi.latestValue();\n    }\n    function _settleAt(uint256 v) internal {\n        for (uint256 i; i < 40 && (_stored() != v || !nhi.converged()); ++i) {\n            vm.warp(vm.getBlockTimestamp() + 1 days);\n            nhi.set(v);\n        }\n        vm.warp(vm.getBlockTimestamp() + 1 days + 1);\n    }\n    function test_F1_twoCapsDownInsideMaxAge() public {\n        uint256 v0 = 0.590278e18; // x 1.44 = 0.8500003\n        _settleAt(v0);\n        nhi.set(_stored());\n        vm.warp(vm.getBlockTimestamp() + 1 days + 1);\n        uint256 T = vm.getBlockTimestamp();\n        nhi.set(1e24); // E1 opens: v0 x 1.2, movedAt = T\n        vm.warp(T + 1 days); // E2 opens exactly maxAge after the move: no carry\n        nhi.set(1e24); // v0 x 1.44 = 0.85\n        uint256 hi = _stored();\n        assertEq(pricer.quote(SIMD).mat, 1.7e18);\n        vm.warp(T + 1 days + 2);\n        uint256 tHi = vm.getBlockTimestamp() - 1; // hi still held at T + 1d + 1\n        nhi.set(1); // inside E2: hi x 0.8 (range rule)\n        vm.warp(T + 2 days); // E3: anchor hi x 0.8, carry = E2's anchor (v0 x 1.2)\n        nhi.set(1);\n        uint256 lo = _stored();\n        assertEq(pricer.quote(SIMD).mat, 2e18, \"mat 1.7 -> 2.0\");\n        assertLt(vm.getBlockTimestamp() - tHi, 1 days);\n        assertGe(lo, hi * 8_000 / 10_000, \"moved more than one cap inside one maxAge\");\n    }\n    function testFuzz_P4_pairwiseWithinOneCapUnderMaxAge(uint256 s0Seed, uint256 seed) public {\n        _settleAt(bound(s0Seed, 0.3e18, 1.2e18));\n        uint256 n = 12;\n        uint256[] memory ts = new uint256[](n + 1);\n        uint256[] memory vs = new uint256[](n + 1);\n        ts[0] = vm.getBlockTimestamp();\n        vs[0] = _stored();\n        for (uint256 i = 1; i <= n; ++i) {\n            uint256 r = uint256(keccak256(abi.encode(seed, i)));\n            uint256 k = r % 6;\n            uint256 dt = k == 0 ? 1 : k == 1 ? 1 days - 1 : k == 2 ? 1 days : k == 3 ? 1 days + 1 : k == 4 ? 0 : bound(r >> 16, 1, 2 days);\n            vm.warp(vm.getBlockTimestamp() + dt);\n            uint256 t = (r >> 64) % 3;\n            nhi.set(t == 0 ? 1 : t == 1 ? 1e24 : bound(r >> 96, 1, 2e18));\n            ts[i] = vm.getBlockTimestamp();\n            vs[i] = _stored();\n        }\n        for (uint256 i; i <= n; ++i) {\n            for (uint256 j = i + 1; j <= n; ++j) {\n                if (ts[j] - ts[i] >= 1 days) continue;\n                uint256 hi = Math.max(vs[i], vs[j]);\n                uint256 lo = Math.min(vs[i], vs[j]);\n                assertGe(lo + 1, hi * 8_000 / 10_000, \"two values < maxAge apart more than one cap apart\");\n            }\n        }\n    }",
    "ran": true,
    "result": "[FAIL: moved more than one cap inside one maxAge: 566666880000000000 < 680000256000000000] test_F1_twoCapsDownInsideMaxAge() (gas: 669982) -- both mat asserts (1.7e18 then 2e18) passed before it. [FAIL: two values < maxAge apart more than one cap apart: 576000000000320002 < 663552000000368640; counterexample: args=[500000, 15866]] testFuzz_P4_pairwiseWithinOneCapUnderMaxAge."
   }
  },
  {
   "id": "HPL-F2",
   "severity": "info",
   "title": "setGenesisDepthRule bounds otherLines but not the posted depth: with no ImdDepth a large depth makes depthLine()/depthRule() panic, so risk(depthIlk), lowerLine/lowerDepthLine/lowerDepthK revert until postLowerDepth",
   "property": "P2 / C2",
   "claim": "C2",
   "files": [
    "src/house/Parameters.sol:99",
    "src/house/Parameters.sol:100",
    "src/house/ParametersBase.sol:477",
    "src/house/ParametersBase.sol:480",
    "src/house/ParametersRules.sol:317"
   ],
   "sequence": "Deployer (an attacker until sealed) calls setGenesisDepthRule(SIMD, k=1e18, depth=2**200, 0, 0) before setGenesisImdDepth (or on a chain with no ImdDepth). depthIMD() returns depthCap; room = depthK * depthIMD() overflows -> Panic in depthLine(), depthRule(), Parameters.risk(SIMD) (every line check), and in _flagDepth inside lowerLine(SIMD,..)/lowerDepthLine/lowerDepthK. The same unbounded value can arrive by SET_DEPTH (validate only decodes it, ParametersRules.sol:317 stores any value; then its own _flagDepth panics so that apply is dead).",
   "expected": "The FR5 comment at Parameters.sol:97-98 says a wrong genesis value cannot make depthLine() and the applies panic.",
   "actual": "otherLines is bounded, depth is not; depthLine() panics (test). Only borrowing on the depth type and the instant lowers fail (no funds move; liquidation reads storedRisk). The governor's postLowerDepth restores it at once. In the shipped house order (_stageDepth before setGenesisDepthRule, StageHouse.sol:105-107) depthIMD = min(measured, cap), so not reachable with the shipped script.",
   "reachableAtDeploy": false,
   "fix": "In setGenesisDepthRule and SET_DEPTH validate depth <= type(uint128).max (as otherLines).",
   "test": {
    "source": "// test/goal/HPL.t.sol (contract HPLTest is System, test/house/utils/System.sol harness; sIMD = MockFeed median=spot, NHI = DoorNhiLeaf from test/house/unit/PricerTwin.t.sol (SwarmNhiPolicy, maxAge 1 day, cap 2000 bps))\n    function test_C2_genesisDepthUnbounded() public {\n        vm.expectRevert(ParametersBase.OutOfBounds.selector);\n        params.setGenesisDepthRule(SIMD, 1e18, 1e24, uint256(type(uint128).max) + 1, 0);\n        params.setGenesisDepthRule(SIMD, 1e18, 2 ** 200, 0, 0); // accepted\n        vm.expectRevert(); // panic 0x11\n        params.depthLine();\n        vm.expectRevert();\n        params.risk(SIMD);\n        vm.prank(params.governor());\n        vm.expectRevert();\n        params.lowerLine(SIMD, 0);\n        vm.prank(params.governor());\n        params.postLowerDepth(1e24); // the instant way out\n        params.depthLine();\n    }",
    "ran": true,
    "result": "[PASS] test_C2_genesisDepthUnbounded() (gas: 346481): the OutOfBounds on otherLines=2^128, then the depthLine()/risk()/lowerLine panics, then recovery by postLowerDepth, all as asserted."
   }
  }
 ],
 "claims": [
  {
   "id": "C1",
   "result": "holds",
   "evidence": "Code-level bound tested: testFuzz_P1_conservativeLegs (256 runs, median m and proven spot s in [1e15,1e24], cap in [0,1e24]): when borrowable, borrow <= min(m,s) and <= cap; low <= max(m,s); a spot under the median moves low at most TWIN_STEP (20%) below m (Pricer.sol:111-118). A pushed proven spot alone cannot lift borrow: borrowable needs agree (|m-s|<=skew), and agree takes min(m,s). The only lift is moving the MEDIAN, by attested reads of a pool held pushed: 20% per 1 h epoch (DeployConfig NHI/price caps 20%, price maxAge 1 h). The house config sets NO cap for sIMD (no setGenesisCap in script/house; Parameters.cap = 0 = none, Pricer.sol:128-129), so 'min(line, cap)' is the line alone: loss <= line - collateral value at market = line x (1 - mat x P_true / P_pushed) for a position at mat, i.e. at most the sIMD line (0 at genesis; <= 50k target and the D1 depth rule after day 7) less the collateral's market value. Not measured economically (cost of holding the pool pushed across >=1 epoch against arbitrage, which the D1 depth rule is meant to price). NOT RUN on a fork."
  },
  {
   "id": "C2",
   "result": "refuted",
   "evidence": "otherLines bound matches SET_OTHER_IMD (Parameters.sol:99 vs ParametersRules.sol:75-78) and the apply arithmetic cannot overflow (testFuzz_C2_setOtherImdNoPanic: 256 runs, lines<=2^128-1, chop<=1e18, apply never Panics, depthLine() readable after). But setGenesisDepthRule leaves `depth` unbounded and depthLine() panics on it (HPL-F2, info)."
  },
  {
   "id": "C3",
   "result": "refuted",
   "evidence": "Two steps between one consumer's reads < maxAge apart: shown (HPL-F1). test_C3_twoCapsAcrossMaxAgePlusOne also passes: 0.85 -> 0.68 at t0+1 and -> 0.544 at t0+1+1d (carry ends at movedAt + maxAge, SwarmFeed.sol:584 uses >=). The leaf bounds each epoch from the value held, but per time NHI moves up to (1-c)^2 / (1+c)^2 inside one maxAge."
  },
  {
   "id": "C4",
   "result": "holds",
   "evidence": "Day 1 (house: HouseConfig.graceOff = BetaConfig's true, script/house/DeployConfig.sol:1295, 732) sets maxLull 0 via StageTypes.sol:69-72, not in StageHouse itself as the claim says (StageHouse reuses _stageTypes, StageHouse.sol:54). Parameters' default is maxLull = MAX_LULL = 6h (ParametersBase.sol:281): any deploy without graceOff ships the 6h lull (tested). test_C4_lullDefaultAndSetMaxLullOrdering: a mark set at lull 0, then a stranger applies a matured SET_MAX_LULL(6h) in the same block in front of the bite: the bite still succeeds (Liquidator.sol:143 takes min(graces.end, m.at+lull)); a fresh mark after it waits exactly 6h (InGrace(now+6h)). No stranger can reset an existing grace: a new mark within MARK_TTL of the last inherits its end (Liquidator.sol:121)."
  },
  {
   "id": "C5",
   "result": "holds",
   "evidence": "testFuzz_C5_biteGasAtomic (256 runs, gas 30k..3M): every bite either fully applies (mark deleted, debt reduced) or fully reverts (mark kept, debt unchanged). bite deletes the mark and seizes in one frame; the standing bid try-call reverts BidGasShort if starved (Liquidator.sol:181) and the cover requires COVER_MIN_GAS (Liquidator.sol:215). Seize price: q.low on both the standing-bid and caller legs (Liquidator.sol:165,185,201); auction (seat) types settle at the taker's Dutch-auction price instead (Liquidator.sol:234), by design."
  },
  {
   "id": "C6",
   "result": "not-checked",
   "evidence": "Proposed invariant (not run as an invariant campaign): for every t, mat(t) = Pricer._mat(NHI_stored(t)) and lull(t) = min(_lull(NHI_stored(t)), maxLull), and for every pair of reads t1<t2 with t2-t1 < maxAge: |ln NHI(t2) - ln NHI(t1)| <= ln(1/(1-c)). Routes: SwarmFeed._follow (only writer of the NHI value), Pricer.quote (only mat/lull producer; Parameters.liqRisk returns mat 0 on NHI types, LedgerBase._liq uses the live q.mat), Liquidator.bark/bite (lull readers), Ledger._adjust/_liqView, LedgerSettlement.liquidatePosition/setRate (mat readers). HPL-F1 shows the pairwise form fails today; smallest replacement: clamp each new value into the intersection of +-c bands of the min and max held over the trailing maxAge."
  }
 ],
 "holds": [
  {
   "property": "P1",
   "tried": "testFuzz_P1_conservativeLegs (256 runs over median, proven spot, cap); code review of the twin rule (Pricer.sol:105-120), live leg (_applyLive only raises payout / clears agree), health = q.low uncapped, borrow = min(low, cap) (Ledger._adjust uses q.borrow). A pushed proven spot ABOVE the median sets low = s with no bound (Pricer.sol:118) but only shelters until anyone proves a newer block (ProvenPoolPrice: only a newer block replaces); it cannot lift borrowing (no agreement) and cannot force a healthy liquidation. Pushed DOWN within skew: README:1338-1342 (known)."
  },
  {
   "property": "P2",
   "tried": "Code review only (no v4 pool harness in time): DepthSampler hourly buckets keep minima, a sample only lowers its hour, depth = 4th-lowest of >=20 buckets in 26 h, rises capped 2x, reference from ProvenPoolPrice (cannot move inside the sampling tx), sample() refused inside a v4 unlock; ImdDepth takes the 7-day min of daily robust figures and fails closed on a missing day. JIT liquidity raises nothing while the keeper samples privately each hour (stated dependency). Not tested: MAX_RISE is off while depth()==0 (<20 buckets), so after a keeper outage of >=7 h a lone sampler sets buckets uncapped until 20 are filled (bounded by the 7-day ImdDepth min and the Safe's postLowerDepth). otherLines bounds: testFuzz_C2_setOtherImdNoPanic; depth bound gap: HPL-F2."
  },
  {
   "property": "P3",
   "tried": "testFuzz_P3_markAndSeize (256 runs, price 40..120 on CR 250%, NHI 0.5..1.0, maxLull 0): after a stranger's 1-wei addFor and a front-running bark in the same block, a healthy position cannot be barked (Healthy) and an unhealthy one is liquidated at once by another caller (liquidate skips bark when marked). test_C4 covers a SET_MAX_LULL applied by a stranger in front of a bite. The 1-wei addFor one-block sIMD redeem hold (Join.sol:33-40) blocks only atomic flash unwinds, documented there."
  },
  {
   "property": "P4",
   "tried": "Per epoch from the value held: holds (each epoch in F1 moves one cap). Per window of time: fails (HPL-F1, testFuzz_P4 counterexample, test_F1)."
  }
 ],
 "notRun": [
  "[fork] none of the claims are [fork]/[data]; no fork test run (NOT RUN)",
  "Economic cost of C1's pool push across an epoch (no pool model)",
  "DepthSampler/ImdDepth JIT tests on a v4 pool (P2 by code review only)",
  "Invariant campaign for C6",
  "Earlier submissions (ad4f75ab-..., 4d56c477-...) were not fetched"
 ]
}