{"commit":"bbeda7b27ae80abcf070e0158cb8a31e87bb2286","setup":"Cloned at the commit with submodules. Ran 'forge build src lib/midnight/src/Midnight.sol lib/midnight/src/ratifiers', which compiled successfully. 'forge test --match-path test/MidnightAdapter*.sol' gave 389 passed and 1 failed: the failure is MidnightAdapterGasTest setUp 'vm.getCode: no matching artifact found', caused by the partial build, not by the code. MidnightAdapterTest: 314/314 passed. Test files placed under test/poc/ in that clone; nothing under src/ or lib/ was changed.","untrustedFault":"None found. No note became a fault that an untrusted account can cause with real impact. Every value-moving behaviour shown needs the curator or an allocator (ranks 1, 2, 7, 8), or costs only gas (rank 10).","entries":[{"rank":1,"title":"setMinForceSellPrice is immediate in both directions; the NatSpec says relaxing guardrails is timelocked","class":"Informational","refs":["src/adapters/midnight/MidnightAdapter.sol:54-57","src/adapters/midnight/MidnightAdapter.sol:334-338","src/adapters/midnight/MidnightAdapter.sol:638-639","src/adapters/midnight/README.md:123"],"detail":"After setForceSellable clears its timelock, the curator can lower minForceSellPrice from 0.9e18 to 0 in the same block, with no notice to depositors. The allocator can then sell at any price. In the test a 0.5e18-unit sale at price 0.5 first reverted with ForceSellPriceTooLow, then passed after the floor was set to 0. realAssets fell from 1e18 to 0.5e18 and the vault received 0.25e18, so 0.25e18 was lost at once. The default floor is 0. README:123 states the setter is immediate, but NatSpec 54-55 lists minForceSellPrice among guardrails whose relaxation is timelocked. Only the trusted curator can do this. Fix: make the NatSpec consistent, or timelock decreases.","verified":true,"test":{"path":"test/poc/NotesReview.t.sol:70","source":"    function test_S1_MinForceSellPriceInstant() public {\n        Offer memory held = buy(30 days, 1e18);\n        bytes32 id = _marketId(held.market);\n        setForceSellable(id);\n        vm.prank(curator);\n        adapter.setMinForceSellPrice(id, 0.9e18);\n        console.log(\"minForceSellPrice default for another market\", adapter.marketData(bytes32(uint256(1))).minForceSellPrice);\n        console.log(\"price at MAX_TICK/2 (WAD)\", TickLib.tickToPrice(MAX_TICK / 2));\n        deal(address(loanToken), taker, 1e18);\n        Offer memory s = makeSellOffer(held.market, 0.5e18, MAX_TICK / 2);\n        bytes memory data = ratify([s], signerAllocator);\n        vm.expectRevert(IMidnightAdapterBase.ForceSellPriceTooLow.selector);\n        this.takeWithAccrual(s, data, taker, address(0));\n        console.log(\"sale at MAX_TICK/2 with floor 0.9: reverted ForceSellPriceTooLow\");\n\n        uint256 ra0 = adapter.realAssets();\n        uint256 vb0 = _bal(address(parentVault));\n        vm.prank(curator);\n        adapter.setMinForceSellPrice(id, 0);\n        this.takeWithAccrual(s, data, taker, address(0));\n        console.log(\"same block after curator set floor 0: sale passed\");\n        console.log(\"realAssets before/after\", ra0, adapter.realAssets());\n        console.log(\"vault received\", _bal(address(parentVault)) - vb0);\n    }"},"command":"forge build src lib/midnight/src/Midnight.sol lib/midnight/src/ratifiers && forge test --match-path test/poc/NotesReview.t.sol --match-test 'test_[BS][0-9]' -vv","output":"[PASS] test_S1_MinForceSellPriceInstant()\nminForceSellPrice default for another market 0\nprice at MAX_TICK/2 (WAD) 500000000000000000\nsale at MAX_TICK/2 with floor 0.9: reverted ForceSellPriceTooLow\nsame block after curator set floor 0: sale passed\nrealAssets before/after 1000000000000000000 500000000000000000\nvault received 250000000000000000","known":"README.md:123 ('setMinForceSellPrice is curator-only and immediate in either direction'); contradicted by MidnightAdapter.sol:54-55. Not in either 2026-10-12 draft.","from":"fix-sell"},{"rank":2,"title":"An immediate tightening does not cancel pending relaxations, and any account can execute them once due","class":"Informational","refs":["src/adapters/midnight/MidnightAdapter.sol:191-226","src/adapters/midnight/MidnightAdapter.sol:305-332","src/adapters/midnight/MidnightAdapter.sol:258-270"],"detail":"The curator set maxNetSellRate to 1e9, submitted increaseMaxNetSellRate(5e9) with a 1-day timelock, then cut the rate to 0 at once. One day later a stranger executed the old payload, and maxNetSellRate became 5e9. Likewise, shortfallAllowance went from 0 to 100e18 through a pending increaseShortfallAllowance submitted before an emergency decrease. The increase adds to the remaining allowance. This is the VaultV2 timelock flow (README:33): depositors did see the payload for the full timelock, so no non-custodial guarantee is broken. Operationally, though, an emergency tightening must be paired with revoke() of each pending relaxation. Fix: document this next to the decrease* functions.","verified":true,"test":{"path":"test/poc/NotesReview.t.sol:96","source":"    function test_S2_PendingRelaxationSurvivesTightening() public {\n        address stranger = makeAddr(\"stranger\");\n        vm.prank(curator);\n        adapter.decreaseMaxNetSellRate(1e9);\n        submitTimelock(IMidnightAdapterBase.increaseMaxNetSellRate.selector, 1 days);\n        vm.prank(curator);\n        adapter.submit(abi.encodeCall(IMidnightAdapterBase.increaseMaxNetSellRate, (5e9)));\n        vm.prank(curator);\n        adapter.decreaseMaxNetSellRate(0);\n        console.log(\"maxNetSellRate after emergency decrease\", adapter.maxNetSellRate());\n        skip(1 days);\n        vm.prank(stranger);\n        adapter.increaseMaxNetSellRate(5e9);\n        console.log(\"maxNetSellRate after stranger executes old pending increase\", adapter.maxNetSellRate());\n\n        submitTimelock(IMidnightAdapterBase.increaseShortfallAllowance.selector, 1 days);\n        vm.prank(curator);\n        adapter.decreaseShortfallAllowance(type(uint128).max);\n        vm.prank(curator);\n        adapter.submit(abi.encodeCall(IMidnightAdapterBase.increaseShortfallAllowance, (100e18)));\n        vm.prank(curator);\n        adapter.decreaseShortfallAllowance(type(uint256).max);\n        console.log(\"shortfallAllowance after emergency decrease\", adapter.shortfallAllowance());\n        skip(1 days);\n        vm.prank(stranger);\n        adapter.increaseShortfallAllowance(100e18);\n        console.log(\"shortfallAllowance after stranger executes old pending increase\", adapter.shortfallAllowance());\n    }"},"command":"forge build src lib/midnight/src/Midnight.sol lib/midnight/src/ratifiers && forge test --match-path test/poc/NotesReview.t.sol --match-test 'test_[BS][0-9]' -vv","output":"[PASS] test_S2_PendingRelaxationSurvivesTightening()\nmaxNetSellRate after emergency decrease 0\nmaxNetSellRate after stranger executes old pending increase 5000000000\nshortfallAllowance after emergency decrease 0\nshortfallAllowance after stranger executes old pending increase 100000000000000000000","known":"README.md:33 (same timelock flow as the vault); MidnightAdapter.sol:229 covers only timelock-duration changes. Not in either draft (TRST-R-11 mentions pending actions only for timelock increases).","from":"fix-sell"},{"rank":3,"title":"isRatified returns success for any offer and any caller while inForceDeallocate is set","class":"Informational","refs":["src/adapters/midnight/MidnightAdapter.sol:465-469","src/adapters/midnight/MidnightAdapter.sol:493","src/adapters/midnight/MidnightAdapter.sol:520-526"],"detail":"The early return at 493 checks neither msg.sender nor the offer. The flag is set at 465 and cleared in onBuy (522). In between, Midnight.take calls only the ratifier and, for credit increases, the enter gate (view). test_02 shows that the self-made offer is refused once the flag is off. No reentrancy into the window was shown, so the impact is unproven. Hardening: return early only when msg.sender == midnight and the offer is the adapter's own (maker == this, callback == 0, tick == 0, reduceOnly).","verified":true,"test":{"path":"test/poc/ForceRatifyReview.t.sol:143","source":"    function test_02_SelfOfferNotTakeableOutsideForce() public {\n        testMakerBuy();\n        Market memory market = _market(7 days);\n        bytes32 id = IdLib.toId(market);\n        Offer memory offer = _selfOffer(market);\n        uint256 units = 1000 * oneToken;\n        console.log(\"price of the self-made offer per unit (WAD):\", TickLib.tickToPrice(0));\n        deal(address(underlyingToken), attacker, units);\n        vm.startPrank(attacker);\n        ERC20Mock(address(underlyingToken)).approve(address(midnight), type(uint256).max);\n        (bool ok, bytes memory ret) = address(midnight)\n            .call(abi.encodeCall(IMidnight.take, (offer, hex\"\", units, attacker, address(0), address(0), hex\"\")));\n        console.log(\"take with empty ratifierData succeeded (0 = reverted):\", ok ? 1 : 0);\n        assertFalse(ok);\n        (ok, ret) = address(midnight)\n            .call(\n                abi.encodeCall(\n                    IMidnight.take,\n                    (offer, abi.encode(address(attacker), hex\"\"), units, attacker, address(0), address(0), hex\"\")\n                )\n            );\n        console.log(\"take naming attacker as sub-ratifier succeeded (0 = reverted):\", ok ? 1 : 0);\n        console.logBytes4(_sel(ret));\n        assertFalse(ok);\n        (ok, ret) = address(midnight)\n            .call(\n                abi.encodeCall(\n                    IMidnight.take,\n                    (\n                        offer,\n                        abi.encode(address(priceSubRatifier), abi.encode(bytes32(0), uint256(0), new bytes32[](0), address(0))),\n                        units,\n                        attacker,\n                        address(0),\n                        address(0),\n                        hex\"\"\n                    )\n                )\n            );\n        console.log(\"take naming the real sub-ratifier succeeded (0 = reverted):\", ok ? 1 : 0);\n        console.logBytes4(_sel(ret));\n        assertFalse(ok);\n        vm.stopPrank();\n        assertEq(midnight.credit(id, attacker), 0);\n        assertFalse(_flag(\"inForceDeallocate()\"));\n    }"},"command":"forge build src lib/midnight/src/Midnight.sol lib/midnight/src/ratifiers && forge test --match-path test/poc/ForceRatifyReview.t.sol --match-test 'test_0' -vv","output":"[PASS] test_02_SelfOfferNotTakeableOutsideForce()\nprice of the self-made offer per unit (WAD): 0\ntake with empty ratifierData succeeded (0 = reverted): 0\ntake naming attacker as sub-ratifier succeeded (0 = reverted): 0\n0x30119bd7\ntake naming the real sub-ratifier succeeded (0 = reverted): 0\n0x30119bd7","known":"NatSpec MidnightAdapter.sol:487 ('except while the adapter takes its own offer through forceDeallocate'); not in either draft.","from":"fix-force-ratify"},{"rank":4,"title":"forceRemove irreversibly strands the adapter's Midnight credit, including later repayments","class":"Informational","refs":["src/adapters/midnight/MidnightAdapter.sol:375-391","src/adapters/midnight/MidnightAdapter.sol:435","src/adapters/midnight/MidnightAdapter.sol:631","src/adapters/midnight/MidnightAdapter.sol:726"],"detail":"The test buys 1e18 net credit, calls forceRemove, skips past maturity and has the borrower repay it in full. Midnight then shows withdrawable 1e18 and adapter credit 1e18, but adapter realAssets is 0. withdrawToVault(1e18), withdrawToVault(0) and forceDeallocate all revert with ForceRemoved, and no function clears the flag. The repaid 1e18 can never reach depositors through this adapter. The README and NatSpec document this. Curators should use forceSellable, not forceRemove, for markets that may still recover.","verified":true,"test":{"path":"test/poc/NotesReview.t.sol:143","source":"    function test_S4_ForceRemoveStrandsRecovery() public {\n        Offer memory held = buy(7 days, 1e18);\n        bytes32 id = _marketId(held.market);\n        forceRemove(id);\n        skip(8 days);\n        deal(address(loanToken), taker, 2e18);\n        vm.prank(taker);\n        midnight.repay(held.market, 1e18, taker, address(0), \"\");\n        console.log(\"withdrawable in market after full repay\", midnight.withdrawable(id));\n        console.log(\"adapter credit on Midnight\", midnight.credit(id, address(adapter)));\n        console.log(\"adapter realAssets\", adapter.realAssets());\n        vm.expectRevert(IMidnightAdapterBase.ForceRemoved.selector);\n        withdrawToVault(held.market, 1e18);\n        vm.expectRevert(IMidnightAdapterBase.ForceRemoved.selector);\n        withdrawToVault(held.market, 0);\n        deal(address(loanToken), address(this), 1e18);\n        vm.expectRevert(IMidnightAdapterBase.ForceRemoved.selector);\n        forceDeallocate(held.market, 1e18);\n        console.log(\"withdrawToVault(1e18), withdrawToVault(0), forceDeallocate: all reverted ForceRemoved\");\n    }"},"command":"forge build src lib/midnight/src/Midnight.sol lib/midnight/src/ratifiers && forge test --match-path test/poc/NotesReview.t.sol --match-test 'test_[BS][0-9]' -vv","output":"[PASS] test_S4_ForceRemoveStrandsRecovery()\nwithdrawable in market after full repay 1000000000000000000\nadapter credit on Midnight 1000000000000000000\nadapter realAssets 0\nwithdrawToVault(1e18), withdrawToVault(0), forceDeallocate: all reverted ForceRemoved","known":"README.md:135-138; NatSpec MidnightAdapter.sol:375-376. Not in either draft (forceRemove is new).","from":"fix-sell"},{"rank":5,"title":"The force path relies on tickToPrice(0) == 0 so it never consumes group-0 capacity","class":"Informational","refs":["src/adapters/midnight/MidnightAdapter.sol:436-452","src/adapters/midnight/MidnightAdapter.sol:342-346"],"detail":"The self-made offer uses group 0 with maxAssets = uint128 max. Allocator offers of group 0 share that counter. With the pinned Midnight, tickToPrice(0) = 0, so sellerAssets is 0 and consumed[adapter][0] stays 0 after a 1000-token exit (test_04). An exit still succeeds after setConsumed(0, uint128 max) (test_05). If tick 0 ever priced above 0, setConsumed(0, max) would block every exit. Neither the code nor a comment states this assumption. Fix: pin it in a comment, or use a dedicated group.","verified":true,"test":{"path":"test/poc/ForceRatifyReview.t.sol:252","source":"    function test_05_SetConsumedMaxDoesNotBlockForce() public {\n        testMakerBuy();\n        Market memory market = _market(7 days);\n        bytes32 id = IdLib.toId(market);\n        uint256 units = 1000 * oneToken;\n        _prepareForce(depositor, 2 * units);\n        vm.prank(sentinel);\n        adapter.setConsumed(bytes32(0), type(uint128).max);\n        console.log(\"consumed[adapter][0]:\", midnight.consumed(address(adapter), bytes32(0)));\n        vm.prank(depositor);\n        vault.forceDeallocate(address(adapter), abi.encode(market, depositor), units, depositor);\n        console.log(\"units bought by taker after the cancel:\", midnight.credit(id, depositor));\n        assertEq(midnight.credit(id, depositor), units);\n    }"},"command":"forge build src lib/midnight/src/Midnight.sol lib/midnight/src/ratifiers && forge test --match-path test/poc/ForceRatifyReview.t.sol --match-test 'test_0' -vv","output":"[PASS] test_05_SetConsumedMaxDoesNotBlockForce()\nconsumed[adapter][0]: 340282366920938463463374607431768211455\nunits bought by taker after the cancel: 1000000000000000000000","known":null,"from":"fix-force-ratify"},{"rank":6,"title":"After maturity, a non-forceSellable sale needs proceeds >= face value, so a taker sale at price 1 fails whenever a settlement fee applies","class":"Informational","refs":["src/adapters/midnight/MidnightAdapter.sol:141-144","src/adapters/midnight/MidnightAdapter.sol:641-642"],"detail":"With ttm = 0, line 642 reduces to sellerAssets >= soldNetCredit, whatever maxNetSellRate is (uint64 max in the test). A 1 cbp default settlement fee gave settlementFee(id, 0) = 1e12. A post-maturity allocator take() of an external buy offer at price 1 reverted with NetSellRateTooHigh. The only way to exit a matured position below face is the timelocked setForceSellable. The fix-sell note said 'always fail'. That is correct only when the fee at ttm 0 is non-zero.","verified":true,"test":{"path":"test/poc/NotesReview.t.sol:126","source":"    function test_S3_PostMaturityTakerSaleWithFee() public {\n        for (uint256 i = 0; i <= 6; i++) {\n            midnight.setDefaultSettlementFee(address(loanToken), i, CBP * (i == 0 ? 1 : i));\n        }\n        Offer memory held = buy(30 days, 2e18, MAX_TICK);\n        bytes32 id = _marketId(held.market);\n        skip(31 days);\n        console.log(\"settlementFee at ttm 0 (WAD)\", midnight.settlementFee(id, 0));\n        console.log(\"maxNetSellRate\", adapter.maxNetSellRate());\n        Offer memory buyOffer = makeExternalOffer(held.market, true, 1e18, MAX_TICK);\n        vm.prank(signerAllocator);\n        vm.expectRevert(IMidnightAdapterBase.NetSellRateTooHigh.selector);\n        adapter.take(buyOffer, \"\", 1e18, \"\");\n        console.log(\"post-maturity taker sale at price 1: reverted NetSellRateTooHigh\");\n    }"},"command":"forge build src lib/midnight/src/Midnight.sol lib/midnight/src/ratifiers && forge test --match-path test/poc/NotesReview.t.sol --match-test 'test_[BS][0-9]' -vv","output":"[PASS] test_S3_PostMaturityTakerSaleWithFee()\nsettlementFee at ttm 0 (WAD) 1000000000000\nmaxNetSellRate 18446744073709551615\npost-maturity taker sale at price 1: reverted NetSellRateTooHigh","known":"NatSpec MidnightAdapter.sol:142; README.md:131 ('This permits sales for fewer assets than the sold net credit after maturity' for force-sellable markets); repository test testMaxNetSellRatePostMaturityRequiresFaceValue.","from":"fix-sell"},{"rank":7,"title":"The rate floor recognises up to netCredit*ttm/1e18 wei early per non-empty buy; zero-unit buys are now a fixed point","class":"Informational","refs":["src/adapters/midnight/MidnightAdapter.sol:22","src/adapters/midnight/MidnightAdapter.sol:24","src/adapters/midnight/MidnightAdapter.sol:543-547","src/adapters/midnight/MidnightAdapter.sol:859"],"detail":"The test buys a position of 5.26e23 net credit, waits 1 day, then makes a 1e18 par buy. realAssets rose 540032400388 wei more than the assets paid, under the bound of 1318204296536 (netCredit*ttm/1e18). Three later zero-unit buys left netRate (20140582732) and realAssets unchanged, so the 3.2.8 ratchet is gone. For an 18-decimal token this is about 5.4e-7 tokens per buy, which is not profitable against gas. It matters only for tokens with an expensive smallest unit, which the NatSpec excludes.","verified":true,"test":{"path":"test/poc/NotesReview.t.sol:43","source":"    function test_B2_RateFloorDrift() public {\n        Offer memory held = buy(30 days, 500_000e18, discountTick);\n        bytes32 id = _marketId(held.market);\n        skip(1 days);\n        uint256 ttm = held.market.maturity - block.timestamp;\n        uint256 ra0 = adapter.realAssets();\n        uint256 vb0 = _bal(address(parentVault));\n        uint256 c0 = adapter.marketData(id).netCredit;\n        buyAdditionalCredit(held.market, 1e18);\n        uint256 paid = vb0 - _bal(address(parentVault));\n        uint256 ra1 = adapter.realAssets();\n        console.log(\"net credit before\", c0);\n        console.log(\"paid assets\", paid);\n        console.log(\"realAssets before / after\", ra0, ra1);\n        console.log(\"excess over before+paid (wei)\", ra1 - ra0 - paid);\n        console.log(\"bound netCredit*ttm/1e18\", (c0 + 1e18) * ttm / 1e18);\n\n        for (uint256 k; k < 3; k++) {\n            Offer memory offer = makeBuyOffer(ttm, 1e18, MAX_TICK);\n            bytes memory data = ratify([offer], signerAllocator);\n            vm.prank(taker);\n            midnight.take(offer, data, 0, taker, taker, address(0), \"\");\n            console.log(\"zero-unit buy: netRate / realAssets\", adapter.marketData(id).netRate, adapter.realAssets());\n        }\n    }"},"command":"forge build src lib/midnight/src/Midnight.sol lib/midnight/src/ratifiers && forge test --match-path test/poc/NotesReview.t.sol --match-test 'test_[BS][0-9]' -vv","output":"[PASS] test_B2_RateFloorDrift()\nnet credit before 526102247340447919244567\npaid assets 1000000000000000000\nrealAssets before / after 500828276482402254602509 500829276482942287002897\nexcess over before+paid (wei) 540032400388\nbound netCredit*ttm/1e18 1318204296536\nzero-unit buy: netRate / realAssets 20140582732 500829276482942287002897\nzero-unit buy: netRate / realAssets 20140582732 500829276482942287002897\nzero-unit buy: netRate / realAssets 20140582732 500829276482942287002897","known":"NatSpec MidnightAdapter.sol:22 and :24; prior Cantina 3.2.8 / 3.6.6 and TRST-R-14 (now documented).","from":"fix-buy"},{"rank":8,"title":"A 0-asset buy into a market with no carried value panics with division by zero; into a held market it adds credit and a little early interest","class":"Informational","refs":["src/adapters/midnight/MidnightAdapter.sol:535-547"],"detail":"A first buy at tick 0 passes BuyAtLoss and NetBuyRateTooLow (both 0 >= 0), then reverts with panic 0x12 at line 547. A 0-asset buy of 1e18 units into a held market cost the vault 0. netCredit rose from 1052204494680895838 to 2052204494680895838, and netRate from 20140622947 to 405943092081. realAssets rose by 1224477 wei, within the floor bound. Only allocator-ratified offers at tick 0 reach this path. A named error, or requiring buyerAssets > 0 when units > 0, would give a clearer revert.","verified":true,"test":{"path":"test/poc/NotesReview.t.sol:14","source":"    function test_B1_ZeroAssetBuy() public {\n        Offer memory first = makeBuyOffer(30 days, 1e18, MAX_TICK);\n        first.tick = 0;\n        midnight.supplyCollateral(first.market, 0, first.maxUnits, taker);\n        midnight.supplyCollateral(first.market, 1, first.maxUnits, taker);\n        vm.expectRevert(stdError.divisionError);\n        take(first);\n        console.log(\"first 0-asset buy into empty market: reverted with panic 0x12\");\n\n        Offer memory held = buy(30 days, 1e18, discountTick);\n        bytes32 id = _marketId(held.market);\n        uint256 ra0 = adapter.realAssets();\n        MarketData memory d0 = adapter.marketData(id);\n        Offer memory z = makeBuyOffer(held.market.maturity - block.timestamp, 1e18, MAX_TICK);\n        z.tick = 0;\n        z.maxUnits = 1e18;\n        z.group = bytes32(uint256(123));\n        midnight.supplyCollateral(z.market, 0, 1e18, taker);\n        midnight.supplyCollateral(z.market, 1, 1e18, taker);\n        uint256 vb0 = _bal(address(parentVault));\n        take(z);\n        MarketData memory d1 = adapter.marketData(id);\n        console.log(\"held market 0-asset buy: paid by vault\", vb0 - _bal(address(parentVault)));\n        console.log(\"netCredit before/after\", d0.netCredit, d1.netCredit);\n        console.log(\"netRate before/after\", d0.netRate, d1.netRate);\n        console.log(\"realAssets before/after\", ra0, adapter.realAssets());\n    }"},"command":"forge build src lib/midnight/src/Midnight.sol lib/midnight/src/ratifiers && forge test --match-path test/poc/NotesReview.t.sol --match-test 'test_[BS][0-9]' -vv","output":"[PASS] test_B1_ZeroAssetBuy()\nfirst 0-asset buy into empty market: reverted with panic 0x12\nheld market 0-asset buy: paid by vault 0\nnetCredit before/after 1052204494680895838 2052204494680895838\nnetRate before/after 20140622947 405943092081\nrealAssets before/after 1000000000002159122 1000000000003383599","known":"Inline comment MidnightAdapter.sol:546; NatSpec :24 ('0-asset buys can accrue significant interest too early'); repository test testFirstBuyAtZeroPriceReverts; Cantina 3.4 remark on Q = p = 0.","from":"fix-buy"},{"rank":9,"title":"The factory registers adapters for any parentVault, and IKRCompatibleEnterGate.admit trusts isCreated","class":"Informational","refs":["src/adapters/midnight/MidnightAdapterFactory.sol:29-41","src/adapters/midnight/MidnightAdapter.sol:429-431","src/adapters/midnight/MidnightAdapter.sol:457-464","src/adapters/midnight/gates/IKRCompatibleEnterGate.sol:40-48"],"detail":"test_07 shows isCreated = true for an adapter whose parentVault is a stub exposing only asset(). Such a vault controls the share check and the sender passed to deallocate. admit, however, lasts only during that adapter's own reduce-only sale of credit it must already hold in the gated market, and onBuy clears it. The repository tests testEnterGateAttackerGateCannotExit, testEnterGateCreditInOtherMarketCannotExit and testEnterGateZeroForceDeallocateInMarketWithoutCredit pass. No exploit was built. Downgraded from Low: no impact was shown, and the trust is documented.","verified":true,"test":{"path":"test/poc/ForceRatifyReview.t.sol:355","source":"    function test_07_FactorySaltAndProvenance() public {\n        IMidnightAdapterFactory factory = IMidnightAdapterFactory(adapter.factory());\n        uint256[] memory d = new uint256[](1);\n        d[0] = 7 days;\n        bytes32 preSalt = keccak256(\"victim-salt\");\n        vm.prank(attacker);\n        address a1 = factory.createMidnightAdapter(address(vault), d, address(0), preSalt);\n        vm.prank(curator);\n        address a2 = factory.createMidnightAdapter(address(vault), d, address(0), preSalt);\n        console.log(\"front-runner's adapter:\", a1);\n        console.log(\"victim's adapter      :\", a2);\n        assertTrue(a1 != a2);\n        assertTrue(factory.isCreated(a1) && factory.isCreated(a2));\n        vm.prank(curator);\n        vm.expectRevert();\n        factory.createMidnightAdapter(address(vault), d, address(0), preSalt);\n\n        FakeVault fake = new FakeVault(address(underlyingToken));\n        vm.prank(attacker);\n        address a3 = factory.createMidnightAdapter(address(fake), d, address(0), preSalt);\n        console.log(\"adapter of a contract that is no VaultV2, isCreated (1 = yes):\", factory.isCreated(a3) ? 1 : 0);\n        assertTrue(factory.isCreated(a3));\n    }"},"command":"forge build src lib/midnight/src/Midnight.sol lib/midnight/src/ratifiers && forge test --match-path test/poc/ForceRatifyReview.t.sol --match-test 'test_0' -vv","output":"[PASS] test_07_FactorySaltAndProvenance()\nfront-runner's adapter: 0x1c8e1561958999eAf5f7D7b88d4F78c56f7AD160\nvictim's adapter      : 0xE5864780419774B5864884aF7F953eEaCEa179Ad\nadapter of a contract that is no VaultV2, isCreated (1 = yes): 1","known":"Cantina 3.6.3 note 7 (unchanged); README.md:29 (registered factories trusted on isCreated).","from":"fix-force-ratify"},{"rank":10,"title":"A holder of 1 wei of shares can run the force path with 0 assets on any market of the loan token, at no penalty","class":"Informational","refs":["src/adapters/midnight/MidnightAdapter.sol:427-477"],"detail":"test_03: forceDeallocate with 0 assets on a sibling-maturity market that the adapter never held succeeds. It leaves the allocation at 100593430826474621736007 and marketIdsLength at 1. With 1 wei it reverts. The cost is gas only, and the call emits ForceDeallocate and Midnight Take events. The fix-force-ratify review also argued, without running it, that on a held market with a realised loss the call rewrites the stored net credit (the sync withdrawToVault(0) does). That part stays UNVERIFIED.","verified":true,"test":{"path":"test/poc/ForceRatifyReview.t.sol:192","source":"    function test_03_ZeroAssetsOnUnheldSiblingMaturity() public {\n        testMakerBuy();\n        Market memory held = _market(7 days);\n        Market memory sibling = _market(30 days);\n        bytes32 adapterId = keccak256(abi.encode(\"this\", address(adapter)));\n        vm.prank(depositor);\n        vault.transfer(attacker, 1);\n        _prepareForce(attacker, oneToken);\n        vm.prank(attacker);\n        midnight.touchMarket(sibling);\n        uint256 allocBefore = vault.allocation(adapterId);\n        uint256 lenBefore = adapter.marketIdsLength();\n        uint256 netBefore = adapter.marketData(IdLib.toId(held)).netCredit;\n\n        vm.prank(attacker);\n        vault.forceDeallocate(address(adapter), abi.encode(sibling, attacker), 0, attacker);\n\n        console.log(\"allocation(adapterId) before:\", allocBefore);\n        console.log(\"allocation(adapterId) after :\", vault.allocation(adapterId));\n        console.log(\"marketIdsLength before/after:\", lenBefore, adapter.marketIdsLength());\n        assertEq(vault.allocation(adapterId), allocBefore);\n        assertEq(adapter.marketIdsLength(), lenBefore);\n        assertEq(adapter.marketData(IdLib.toId(held)).netCredit, netBefore);\n        assertFalse(_flag(\"inForceDeallocate()\"));\n\n        vm.prank(attacker);\n        (bool ok, bytes memory ret) = address(vault)\n            .call(abi.encodeCall(IVaultV2.forceDeallocate, (address(adapter), abi.encode(sibling, attacker), 1, attacker)));\n        console.log(\"1 wei force call on unheld market succeeded (0 = reverted):\", ok ? 1 : 0);\n        assertFalse(ok);\n        assertEq(_sel(ret), IMidnight.MakerCreditOrDebtIncreased.selector);\n    }"},"command":"forge build src lib/midnight/src/Midnight.sol lib/midnight/src/ratifiers && forge test --match-path test/poc/ForceRatifyReview.t.sol --match-test 'test_0' -vv","output":"[PASS] test_03_ZeroAssetsOnUnheldSiblingMaturity()\nallocation(adapterId) before: 100593430826474621736007\nallocation(adapterId) after : 100593430826474621736007\nmarketIdsLength before/after: 1 1\n1 wei force call on unheld market succeeded (0 = reverted): 0","known":null,"from":"fix-force-ratify"},{"rank":11,"title":"A Midnight authorization granted by an allocator also confers ratification rights for every adapter of every vault where it is allocator","class":"Informational","refs":["src/adapters/midnight/ratifiers/MidnightAdapterPriceRatifierV1.sol:20-21","src/adapters/midnight/ratifiers/MidnightAdapterPriceRatifierV1.sol:38-44","src/adapters/midnight/ratifiers/MidnightAdapterPriceRatifierV1.sol:74-80"],"detail":"test_06: a Midnight delegate of an allocator ratifies a root directly. Relaying a signature also needs that same full authorization. A relayer therefore controls the allocator's Midnight positions and its ratifications on all adapters. A narrower per-ratifier delegation would avoid this. Only the Price ratifier was run. The Rate ratifier has the same code for these paths, which was checked by reading only.","verified":true,"test":{"path":"test/poc/ForceRatifyReview.t.sol:281","source":"    function test_06_RatifierAuthorizationAndSig() public {\n        bytes32 root = keccak256(\"root\");\n        address delegate = makeAddr(\"delegate\");\n        bytes4 unauthorized = IMidnightAdapterPriceRatifierV1.Unauthorized.selector;\n\n        vm.prank(attacker);\n        vm.expectRevert(unauthorized);\n        priceSubRatifier.setIsRootRatified(address(adapter), root, true, allocator);\n\n        // The adapter is itself an allocator of its vault and is self-authorized on Midnight.\n        assertTrue(vault.isAllocator(address(adapter)));\n        assertTrue(midnight.isAuthorized(address(adapter), address(adapter)));\n        vm.prank(attacker);\n        vm.expectRevert(unauthorized);\n        priceSubRatifier.setIsRootRatified(address(adapter), root, true, address(adapter));\n\n        vm.prank(sentinel);\n        vm.expectRevert(unauthorized);\n        priceSubRatifier.setIsRootRatified(address(adapter), root, true, sentinel);\n\n        // A shareholder who authorized the adapter for an in-kind exit gains nothing on the ratifier.\n        vm.prank(attacker);\n        midnight.setIsAuthorized(address(adapter), true, attacker);\n        vm.prank(attacker);\n        vm.expectRevert(unauthorized);\n        priceSubRatifier.setIsRootRatified(address(adapter), root, true, attacker);\n\n        vm.prank(allocator);\n        midnight.setIsAuthorized(delegate, true, allocator);\n        vm.prank(delegate);\n        priceSubRatifier.setIsRootRatified(address(adapter), root, true, allocator);\n        assertTrue(priceSubRatifier.isRootRatified(address(adapter), root));\n        vm.prank(sentinel);\n        priceSubRatifier.setIsRootRatified(address(adapter), root, false, sentinel);\n        assertFalse(priceSubRatifier.isRootRatified(address(adapter), root));\n\n        (address signer, uint256 pk) = makeAddrAndKey(\"signerAllocator\");\n        _submitAndSet(address(vault), abi.encodeCall(IVaultV2.setIsAllocator, (signer, true)));\n        bytes32 root2 = keccak256(\"root2\");\n        uint256 deadline = block.timestamp + 1 days;\n        (uint8 v, bytes32 r, bytes32 s) = _sig(pk, root2, true, 0, deadline);\n\n        // TRST-R-6: another allocator, a sentinel and a stranger can no longer submit the signature.\n        vm.prank(allocator);\n        vm.expectRevert(unauthorized);\n        priceSubRatifier.setIsRootRatifiedWithSig(address(adapter), root2, 1, true, 0, deadline, v, r, s);\n        vm.prank(sentinel);\n        vm.expectRevert(unauthorized);\n        priceSubRatifier.setIsRootRatifiedWithSig(address(adapter), root2, 1, true, 0, deadline, v, r, s);\n        vm.prank(attacker);\n        vm.expectRevert(unauthorized);\n        priceSubRatifier.setIsRootRatifiedWithSig(address(adapter), root2, 1, true, 0, deadline, v, r, s);\n        // Another height or maker recovers another signer.\n        vm.prank(signer);\n        vm.expectRevert();\n        priceSubRatifier.setIsRootRatifiedWithSig(address(adapter), root2, 2, true, 0, deadline, v, r, s);\n\n        vm.prank(signer);\n        priceSubRatifier.setIsRootRatifiedWithSig(address(adapter), root2, 1, true, 0, deadline, v, r, s);\n        assertTrue(priceSubRatifier.isRootRatified(address(adapter), root2));\n        console.log(\"rootNonce after signed ratification:\", priceSubRatifier.rootNonce(address(adapter), root2));\n\n        // Direct revocation leaves the nonce where it was (TRST-R-5, known), but the used signature cannot re-ratify.\n        vm.prank(sentinel);\n        priceSubRatifier.setIsRootRatified(address(adapter), root2, false, sent\n// ... truncated; full file: see after-fix-force-ratify reviewTest.source (identical, re-run here)"},"command":"forge build src lib/midnight/src/Midnight.sol lib/midnight/src/ratifiers && forge test --match-path test/poc/ForceRatifyReview.t.sol --match-test 'test_0' -vv","output":"[PASS] test_06_RatifierAuthorizationAndSig()\nrootNonce after signed ratification: 1\nrootNonce after direct revocation: 1","known":"NatSpec MidnightAdapterPriceRatifierV1.sol:20; TRST-R-6 suggests documenting it.","from":"fix-force-ratify"},{"rank":12,"title":"A duration cap stops counting a position one second after it was bought with exactly that duration left","class":"Informational","refs":["src/adapters/midnight/MidnightAdapter.sol:586-603","src/adapters/midnight/MidnightAdapter.sol:816-834"],"detail":"test_08: durationAllocations(1)[0] is 100593430826474621736007 right after a buy of a 7-day market against a 7-day duration, and 0 one second later. A duration D therefore never limits markets bought with D-1 seconds or less left. This matches the documented 'counts toward every duration <= its remaining TTM', and curators should choose ladders with it in mind.","verified":true,"test":{"path":"test/poc/ForceRatifyReview.t.sol:381","source":"    function test_08_DurationsEdges() public {\n        IMidnightAdapterFactory factory = IMidnightAdapterFactory(adapter.factory());\n        uint256[] memory d8 = new uint256[](8);\n        for (uint256 i; i < 8; i++) {\n            d8[i] = i + 1;\n        }\n        d8[6] = type(uint32).max - 1;\n        d8[7] = type(uint32).max;\n        IMidnightAdapter a = IMidnightAdapter(factory.createMidnightAdapter(address(vault), d8, address(0), \"d8\"));\n        uint256[] memory got = a.durations();\n        assertEq(got.length, 8);\n        for (uint256 i; i < 8; i++) {\n            assertEq(got[i], d8[i]);\n        }\n        console.log(\"durations()[7] round trip:\", got[7]);\n\n        uint256[] memory bad = new uint256[](9);\n        for (uint256 i; i < 9; i++) {\n            bad[i] = i + 1;\n        }\n        vm.expectRevert();\n        factory.createMidnightAdapter(address(vault), bad, address(0), \"d9\");\n        bad = new uint256[](1);\n        vm.expectRevert();\n        factory.createMidnightAdapter(address(vault), bad, address(0), \"zero\");\n        bad[0] = uint256(type(uint32).max) + 1;\n        vm.expectRevert();\n        factory.createMidnightAdapter(address(vault), bad, address(0), \"high\");\n        bad = new uint256[](2);\n        bad[0] = 5;\n        bad[1] = 5;\n        vm.expectRevert();\n        factory.createMidnightAdapter(address(vault), bad, address(0), \"equal\");\n        IMidnightAdapter e =\n            IMidnightAdapter(factory.createMidnightAdapter(address(vault), new uint256[](0), address(0), \"empty\"));\n        assertEq(e.durations().length, 0);\n\n        bytes32 newId = keccak256(abi.encode(\"this/duration\", address(adapter), uint256(7 days)));\n        bytes32 oldId = keccak256(abi.encode(\"duration\", address(adapter), uint256(7 days)));\n        console.log(\"absoluteCap of this/duration id:\", vault.absoluteCap(newId));\n        console.log(\"absoluteCap of the audited duration id:\", vault.absoluteCap(oldId));\n        assertGt(vault.absoluteCap(newId), 0);\n        assertEq(vault.absoluteCap(oldId), 0);\n\n        testMakerBuy();\n        (bool ok, bytes memory ret) =\n            address(adapter).staticcall(abi.encodeWithSignature(\"durationAllocations(uint256)\", uint256(1)));\n        require(ok, \"durationAllocations\");\n        uint256[] memory allocations = abi.decode(ret, (uint256[]));\n        bytes32 id = IdLib.toId(_market(7 days));\n        console.log(\"durationAllocations(1)[0]:\", allocations[0]);\n        console.log(\"stored net credit        :\", adapter.marketData(id).netCredit);\n        assertEq(allocations[0], adapter.marketData(id).netCredit);\n        vm.warp(block.timestamp + 1);\n        (, ret) = address(adapter).staticcall(abi.encodeWithSignature(\"durationAllocations(uint256)\", uint256(1)));\n        console.log(\"durationAllocations(1)[0] one second later:\", abi.decode(ret, (uint256[]))[0]);\n    }"},"command":"forge build src lib/midnight/src/Midnight.sol lib/midnight/src/ratifiers && forge test --match-path test/poc/ForceRatifyReview.t.sol --match-test 'test_0' -vv","output":"[PASS] test_08_DurationsEdges()\ndurations()[7] round trip: 4294967295\nabsoluteCap of this/duration id: 340282366920938463463374607431768211455\nabsoluteCap of the audited duration id: 0\ndurationAllocations(1)[0]: 100593430826474621736007\nstored net credit        : 100593430826474621736007\ndurationAllocations(1)[0] one second later: 0","known":"NatSpec MidnightAdapter.sol:67; README.md:50.","from":"fix-force-ratify"},{"rank":13,"title":"A named funding adapter is always deallocated for the full buyerAssets, and empty callbackData reverts","class":"Informational","refs":["src/adapters/midnight/MidnightAdapter.sol:36-38","src/adapters/midnight/MidnightAdapter.sol:578-584"],"detail":"The vault held more than 1e18 idle, yet the funding adapter was deallocated for the full 1e18 (repository test). A buy offer with empty callbackData reverts at the abi.decode at 578. At the audited commit, funding covered only paidAssets - idle and only when callbackData was non-empty, so integrators who encode offers must change. Allocators choose this, and it is documented.","verified":true,"test":{"path":"test/MidnightAdapterTest.sol:4599, test/MidnightAdapterTest.sol:4644","source":"    function testOnBuyFundsFromCallbackDataAdapterWithIdleAssets() public {\n        AdapterMock fundingAdapter = new AdapterMock(address(parentVault));\n        parentVault.allocate(address(fundingAdapter), hex\"\", 2e18);\n        assertGt(loanToken.balanceOf(address(parentVault)), 1e18, \"vault has idle assets\");\n\n        Offer memory offer = makeBuyOffer(30 days, 1e18, MAX_TICK);\n        offer.callbackData = abi.encode(address(fundingAdapter), bytes(\"\"));\n        midnight.supplyCollateral(offer.market, 0, offer.maxUnits, taker);\n        midnight.supplyCollateral(offer.market, 1, offer.maxUnits, taker);\n        take(offer);\n\n        assertEq(fundingAdapter.recordedDeallocateAssets(), 1e18, \"full paidAssets deallocated\");\n        assertEq(loanToken.balanceOf(address(fundingAdapter)), 1e18, \"funding adapter funded the buy\");\n        assertGt(loanToken.balanceOf(address(parentVault)), 1e18, \"vault idle assets remain\");\n    }\n\n    function testOnBuyEmptyCallbackDataReverts() public {\n        Offer memory offer = makeBuyOffer(30 days, 1e18, MAX_TICK);\n        offer.callbackData = bytes(\"\");\n        midnight.supplyCollateral(offer.market, 0, offer.maxUnits, taker);\n        midnight.supplyCollateral(offer.market, 1, offer.maxUnits, taker);\n\n        vm.expectRevert();\n        take(offer);\n    }"},"command":"forge test --match-path test/MidnightAdapterTest.sol --match-test 'testOnBuyFundsFromCallbackDataAdapterWithIdleAssets|testOnBuyEmptyCallbackDataReverts'","output":"[PASS] testOnBuyFundsFromCallbackDataAdapterWithIdleAssets()\n[PASS] testOnBuyEmptyCallbackDataReverts()","known":"NatSpec MidnightAdapter.sol:36-38; README.md:94-95.","from":"fix-buy"},{"rank":14,"title":"The factory has no lookup by vault and salt, and a repeated identical deployment fails by CREATE2 collision","class":"Informational","refs":["src/adapters/midnight/MidnightAdapterFactory.sol:15","src/adapters/midnight/MidnightAdapterFactory.sol:35-39"],"detail":"The audited midnightAdapter[parentVault][salt] mapping is gone. Integrations must compute the CREATE2 address (a function of msg.sender, preSalt, durations and enterGateFactory) or read the event. test_07 shows that a front-runner using the victim's preSalt gets a different address, and that a second identical call by the same sender reverts.","verified":true,"test":{"path":"test/poc/ForceRatifyReview.t.sol:355","source":"    function test_07_FactorySaltAndProvenance() public {\n        IMidnightAdapterFactory factory = IMidnightAdapterFactory(adapter.factory());\n        uint256[] memory d = new uint256[](1);\n        d[0] = 7 days;\n        bytes32 preSalt = keccak256(\"victim-salt\");\n        vm.prank(attacker);\n        address a1 = factory.createMidnightAdapter(address(vault), d, address(0), preSalt);\n        vm.prank(curator);\n        address a2 = factory.createMidnightAdapter(address(vault), d, address(0), preSalt);\n        console.log(\"front-runner's adapter:\", a1);\n        console.log(\"victim's adapter      :\", a2);\n        assertTrue(a1 != a2);\n        assertTrue(factory.isCreated(a1) && factory.isCreated(a2));\n        vm.prank(curator);\n        vm.expectRevert();\n        factory.createMidnightAdapter(address(vault), d, address(0), preSalt);\n\n        FakeVault fake = new FakeVault(address(underlyingToken));\n        vm.prank(attacker);\n        address a3 = factory.createMidnightAdapter(address(fake), d, address(0), preSalt);\n        console.log(\"adapter of a contract that is no VaultV2, isCreated (1 = yes):\", factory.isCreated(a3) ? 1 : 0);\n        assertTrue(factory.isCreated(a3));\n    }"},"command":"forge build src lib/midnight/src/Midnight.sol lib/midnight/src/ratifiers && forge test --match-path test/poc/ForceRatifyReview.t.sol --match-test 'test_0' -vv","output":"[PASS] test_07_FactorySaltAndProvenance()\nfront-runner's adapter: 0x1c8e1561958999eAf5f7D7b88d4F78c56f7AD160\nvictim's adapter      : 0xE5864780419774B5864884aF7F953eEaCEa179Ad\nadapter of a contract that is no VaultV2, isCreated (1 = yes): 1","known":"MidnightAdapterFactory.sol:28 (salt derived from msg.sender); TRST-R-4.","from":"fix-force-ratify"}],"dropped":[{"title":"'taker sales after fees always fail' (wording in fix-sell note 3)","why":"Merged into rank 6 and corrected: the sale fails only when the settlement fee at ttm 0 is non-zero; with no fee, a sale at price 1 passes (repository test testMaxNetSellRatePostMaturityRequiresFaceValue)."},{"title":"Low class of 'Factory registers adapters of any parentVault' (fix-force-ratify)","why":"Kept as rank 9, but downgraded to Informational: no impact was shown, the existing gate tests pass, and README:29 documents the isCreated trust."}],"fixes":[{"priorId":"Cantina 3.2.3","status":"fixed","tested":true,"test":{"path":"test/MidnightAdapterTest.sol:2481, test/MidnightAdapterTest.sol:2492, test/MidnightAdapterTest.sol:2528","names":["testDurationAbsoluteCapZeroRejectsZeroUnitBuy","testDurationAbsoluteCapZeroDoesNotBlockShorterBuys","testDurationCapsUseScopedVaultIds"],"command":"forge test --match-path test/MidnightAdapterTest.sol --match-test 'testDurationAbsoluteCapZeroRejectsZeroUnitBuy|testDurationAbsoluteCapZeroDoesNotBlockShorterBuys|testDurationCapsUseScopedVaultIds'","output":"[PASS] testDurationAbsoluteCapZeroRejectsZeroUnitBuy()\n[PASS] testDurationAbsoluteCapZeroDoesNotBlockShorterBuys()\n[PASS] testDurationCapsUseScopedVaultIds()"},"note":"absoluteCap > 0 is required for each affected duration (596). A zero-unit buy reaching a duration with an unset cap reverts."},{"priorId":"Cantina 3.2.8","status":"fixed","tested":true,"test":{"path":"test/MidnightAdapterTest.sol:3267, test/MidnightAdapterTest.sol:3420","names":["testBuyRoundsCarriedValueDown","testZeroUnitBuyDoesNotInsertMarket"],"command":"forge test --match-path test/MidnightAdapterTest.sol --match-test 'testBuyRoundsCarriedValueDown|testZeroUnitBuyDoesNotInsertMarket'","output":"[PASS] testBuyRoundsCarriedValueDown()\n[PASS] testZeroUnitBuyDoesNotInsertMarket()","extra":"test/poc/NotesReview.t.sol test_B2_RateFloorDrift (see entry rank 7)"},"note":"The carried value is floored (545). In my test_B2_RateFloorDrift, three zero-unit buys left netRate at 20140582732 and realAssets unchanged."},{"priorId":"Cantina 3.2.11","status":"fixed","tested":true,"test":{"path":"test/MidnightAdapterTest.sol:1605, test/MidnightAdapterTest.sol:1519, test/MidnightAdapterTest.sol:1481","names":["testMinNetBuyRateIsMarginal","testMinNetBuyRateBoundary","testBuyAfterLossSale"],"command":"forge test --match-path test/MidnightAdapterTest.sol --match-test 'testMinNetBuyRateIsMarginal|testMinNetBuyRateBoundary|testBuyAfterLossSale'","output":"[PASS] testMinNetBuyRateIsMarginal()\n[PASS] testMinNetBuyRateBoundary(uint256,uint256,uint256)\n[PASS] testBuyAfterLossSale()"},"note":"The blended-rate check has been replaced by a per-trade NetBuyRateTooLow check (537)."},{"priorId":"Cantina 3.6.6","status":"partial","tested":true,"test":{"path":"test/MidnightAdapterTest.sol:3267, test/MidnightAdapterTest.sol:3489","names":["testBuyRoundsCarriedValueDown","testSecondBuyAccruesExistingDiscount"],"command":"forge test --match-path test/MidnightAdapterTest.sol --match-test 'testBuyRoundsCarriedValueDown|testSecondBuyAccruesExistingDiscount'","output":"[PASS] testBuyRoundsCarriedValueDown()\n[PASS] testSecondBuyAccruesExistingDiscount()"},"note":"The bias is now bounded and documented (NatSpec 19-24). The residual early recognition of 540032400388 wei per 1e18 buy on 5.26e23 credit was measured in test_B2."},{"priorId":"TrustSec TRST-L-5","status":"partial","tested":true,"test":{"path":"test/MidnightAdapterTest.sol:544, test/MidnightAdapterTest.sol:1501","names":["testMinNetBuyRateDirections","testMinNetBuyRateRejectsPreviouslyRatifiedZeroRateOffer"],"command":"forge test --match-path test/MidnightAdapterTest.sol --match-test 'testMinNetBuyRateDirections|testMinNetBuyRateRejectsPreviouslyRatifiedZeroRateOffer'","output":"[PASS] testMinNetBuyRateDirections(uint128,uint128)\n[PASS] testMinNetBuyRateRejectsPreviouslyRatifiedZeroRateOffer()"},"note":"Lowering is timelocked. The default is still 0, so par buys pass until the curator raises it."},{"priorId":"TrustSec TRST-PR-1","status":"fixed","tested":true,"test":{"path":"test/MidnightAdapterTest.sol:3445, test/MidnightAdapterTest.sol:5174, test/MidnightAdapterTest.sol:3883","names":["testMakerBuyRestoresLowMidnightAllowance","testWithdrawToVaultRestoresLowAllowance","testForceDeallocateRestoresMidnightAllowance"],"command":"forge test --match-path test/MidnightAdapterTest.sol --match-test 'testMakerBuyRestoresLowMidnightAllowance|testWithdrawToVaultRestoresLowAllowance|testForceDeallocateRestoresMidnightAllowance'","output":"[PASS] testMakerBuyRestoresLowMidnightAllowance()\n[PASS] testWithdrawToVaultRestoresLowAllowance()\n[PASS] testForceDeallocateRestoresMidnightAllowance()"},"note":"forceApproveMax is called at 426 and 613."},{"priorId":"TrustSec TRST-R-2","status":"partial","tested":true,"test":{"path":"test/MidnightAdapterTest.sol:5881, test/MidnightAdapterTest.sol:5333, test/MidnightAdapterTest.sol:1567","names":["testMarketDataPacking","testBuyMaturityOverflow","testBuyNetRateAboveUint64Reverts"],"command":"forge test --match-path test/MidnightAdapterTest.sol --match-test 'testMarketDataPacking|testBuyMaturityOverflow|testBuyNetRateAboveUint64Reverts'","output":"[PASS] testMarketDataPacking(bool,bool)\n[PASS] testBuyMaturityOverflow()\n[PASS] testBuyNetRateAboveUint64Reverts()"},"note":"Maturity is uint40, but the rate is still uint64, so extreme-rate buys still revert."},{"priorId":"TrustSec TRST-R-7","status":"partial","tested":true,"test":{"path":"test/MidnightAdapterTest.sol:1605, test/MidnightAdapterTest.sol:1818","names":["testMinNetBuyRateIsMarginal","testMaxNetSellRateBoundary"],"command":"forge test --match-path test/MidnightAdapterTest.sol --match-test 'testMinNetBuyRateIsMarginal|testMaxNetSellRateBoundary'","output":"[PASS] testMinNetBuyRateIsMarginal()\n[PASS] testMaxNetSellRateBoundary()"},"note":"There are per-trade checks but no TTM-keyed curve."},{"priorId":"TrustSec TRST-R-13","status":"partial","tested":true,"test":{"path":"test/MidnightAdapterTest.sol:5047, test/MidnightAdapterTest.sol:5022, test/MidnightAdapterTest.sol:7097, test/MidnightAdapterTest.sol:5805","names":["testBuyerCallbackDepositUsesPreTradeSharePrice","testMakerTakeWithoutAccrualInSameTransaction","testBackingSelfFunding","testBuySelfFundedSameMarketEmitsNetCreditBeforeNestedWithdrawal"],"command":"forge test --match-path test/MidnightAdapterTest.sol --match-test 'testBuyerCallbackDepositUsesPreTradeSharePrice|testMakerTakeWithoutAccrualInSameTransaction|testBackingSelfFunding|testBuySelfFundedSameMarketEmitsNetCreditBeforeNestedWithdrawal'","output":"[PASS] testBuyerCallbackDepositUsesPreTradeSharePrice()\n[PASS] testMakerTakeWithoutAccrualInSameTransaction(bool)\n[PASS] testBackingSelfFunding(bool,bool)\n[PASS] testBuySelfFundedSameMarketEmitsNetCreditBeforeNestedWithdrawal()"},"note":"The transient pre-buy override and its documentation (118, 508) are exercised. The fix-buy edge cases (a)-(f) were not each tested separately."},{"priorId":"TrustSec TRST-R-14","status":"fixed","tested":true,"test":{"path":"test/MidnightAdapterTest.sol:3219, test/MidnightAdapterTest.sol:3289, test/MidnightAdapterTest.sol:3267","names":["testTakeRoundingShortfallUsesInterestThatRoundsDown","testShortfallRoundsTargetAmortizedValueUp","testBuyRoundsCarriedValueDown"],"command":"forge test --match-path test/MidnightAdapterTest.sol --match-test 'testTakeRoundingShortfallUsesInterestThatRoundsDown|testShortfallRoundsTargetAmortizedValueUp|testBuyRoundsCarriedValueDown'","output":"[PASS] testTakeRoundingShortfallUsesInterestThatRoundsDown()\n[PASS] testShortfallRoundsTargetAmortizedValueUp()\n[PASS] testBuyRoundsCarriedValueDown()"},"note":"Rounding is documented at 19-24 and 146."},{"priorId":"Cantina 3.1.1","status":"partial","tested":true,"test":{"path":"test/MidnightAdapterTest.sol:5489, test/MidnightAdapterTest.sol:5537, test/MidnightAdapterTest.sol:827, test/MidnightAdapterTest.sol:5639","names":["testProportionalShortfall","testShortfallSharedAcrossTwoMarkets","testShortfallAllowanceBlocksShortfallSale","testShortfallSkipsMaturedAndZeroRateMarkets"],"command":"forge test --match-path test/MidnightAdapterTest.sol --match-test 'testProportionalShortfall|testShortfallSharedAcrossTwoMarkets|testShortfallAllowanceBlocksShortfallSale|testShortfallSkipsMaturedAndZeroRateMarkets'","output":"[PASS] testProportionalShortfall(uint256,bool)\n[PASS] testShortfallSharedAcrossTwoMarkets()\n[PASS] testShortfallAllowanceBlocksShortfallSale()\n[PASS] testShortfallSkipsMaturedAndZeroRateMarkets()"},"note":"The shortfall is still capitalised into rates, but it is bounded by shortfallAllowance and maxNetSellRate."},{"priorId":"Cantina 3.2.4","status":"partial","tested":true,"test":{"path":"test/MidnightAdapterTest.sol:1872, test/MidnightAdapterTest.sol:1204","names":["testMinForceSellPriceBoundary","testForceSellablePreventsBuys"],"command":"forge test --match-path test/MidnightAdapterTest.sol --match-test 'testMinForceSellPriceBoundary|testForceSellablePreventsBuys'","output":"[PASS] testMinForceSellPriceBoundary(bool)\n[PASS] testForceSellablePreventsBuys(bool)"},"note":"Buys are blocked only once forceSellable is set. minForceSellPrice defaults to 0 and is immediate (entry rank 1)."},{"priorId":"Cantina 3.2.7","status":"fixed","tested":true,"test":{"path":"test/MidnightAdapterTest.sol:1279, test/MidnightAdapterTest.sol:1891, test/MidnightAdapterTest.sol:1241","names":["testForceSellableIsPerMarketAndCanBeDisabled","testMinForceSellPriceIgnoredInOtherMarkets","testForceSellableOverridesShortfallAllowance"],"command":"forge test --match-path test/MidnightAdapterTest.sol --match-test 'testForceSellableIsPerMarketAndCanBeDisabled|testMinForceSellPriceIgnoredInOtherMarkets|testForceSellableOverridesShortfallAllowance'","output":"[PASS] testForceSellableIsPerMarketAndCanBeDisabled()\n[PASS] testMinForceSellPriceIgnoredInOtherMarkets()\n[PASS] testForceSellableOverridesShortfallAllowance(bool)"},"note":"The global face-value flags are gone, and the policy is per market."},{"priorId":"Cantina 3.2.10","status":"fixed","tested":true,"test":{"path":"test/MidnightAdapterTest.sol:544, test/MidnightAdapterTest.sol:609, test/MidnightAdapterTest.sol:674, test/MidnightAdapterTest.sol:2135, test/MidnightAdapterTest.sol:2092","names":["testMinNetBuyRateDirections","testShortfallAllowanceDirections","testMaxNetSellRateDirections","testDecreaseMaxTtm","testIncreaseMaxTtmNotTimelocked"],"command":"forge test --match-path test/MidnightAdapterTest.sol --match-test 'testMinNetBuyRateDirections|testShortfallAllowanceDirections|testMaxNetSellRateDirections|testDecreaseMaxTtm|testIncreaseMaxTtmNotTimelocked'","output":"[PASS] testMinNetBuyRateDirections(uint128,uint128)\n[PASS] testShortfallAllowanceDirections(uint128,uint128)\n[PASS] testMaxNetSellRateDirections(uint128,uint128)\n[PASS] testDecreaseMaxTtm(uint256,uint256,bool)\n[PASS] testIncreaseMaxTtmNotTimelocked(address,uint256)"},"note":"The setters are now directional. Exceptions: setMinForceSellPrice (rank 1), and pending relaxations survive tightenings (rank 2)."},{"priorId":"Cantina 3.6.4","status":"fixed","tested":true,"test":{"path":"test/MidnightAdapterTest.sol:1838, test/MidnightAdapterTest.sol:1241","names":["testForceSellableOverridesMaxNetSellRate","testForceSellableOverridesShortfallAllowance"],"command":"forge test --match-path test/MidnightAdapterTest.sol --match-test 'testForceSellableOverridesMaxNetSellRate|testForceSellableOverridesShortfallAllowance'","output":"[PASS] testForceSellableOverridesMaxNetSellRate()\n[PASS] testForceSellableOverridesShortfallAllowance(bool)"},"note":"Precedence is unambiguous: forceSellable supersedes the other checks."},{"priorId":"Cantina 3.6.5","status":"partial","tested":true,"test":{"path":"test/MidnightAdapterTest.sol:5149, test/MidnightAdapterTest.sol:4724","names":["testWithdrawToVaultOK","testDeallocateNotParentVault"],"command":"forge test --match-path test/MidnightAdapterTest.sol --match-test 'testWithdrawToVaultOK|testDeallocateNotParentVault'","output":"[PASS] testWithdrawToVaultOK()\n[PASS] testDeallocateNotParentVault(address)"},"note":"withdrawToVault is internal (718), and grep of src/adapters/midnight/interfaces for withdrawToVault returned nothing (exit 1). The step gain at withdrawal remains, but only permissioned roles can trigger it."},{"priorId":"TrustSec TRST-R-3","status":"fixed","tested":true,"test":{"path":"test/MidnightAdapterTest.sol:4929, test/MidnightAdapterTest.sol:3945","names":["testForceDeallocateRealVaultWithPenalty","testForceDeallocateRealVaultWithSettlementFee"],"command":"forge test --match-path test/MidnightAdapterTest.sol --match-test 'testForceDeallocateRealVaultWithPenalty|testForceDeallocateRealVaultWithSettlementFee'","output":"[PASS] testForceDeallocateRealVaultWithPenalty()\n[PASS] testForceDeallocateRealVaultWithSettlementFee()"},"note":"The forceDeallocate branch no longer accrues."},{"priorId":"TrustSec TRST-R-15","status":"fixed","tested":true,"test":{"path":"test/MidnightAdapterTest.sol:2135, test/MidnightAdapterTest.sol:2092","names":["testDecreaseMaxTtm","testIncreaseMaxTtmNotTimelocked"],"command":"forge test --match-path test/MidnightAdapterTest.sol --match-test 'testDecreaseMaxTtm|testIncreaseMaxTtmNotTimelocked'","output":"[PASS] testDecreaseMaxTtm(uint256,uint256,bool)\n[PASS] testIncreaseMaxTtmNotTimelocked(address,uint256)"},"note":"decreaseMaxTtm is immediate for the curator or a sentinel. A pending increase survives it unless revoked (rank 2 shows the same pattern for maxNetSellRate)."},{"priorId":"TrustSec TRST-CR-1","status":"partial","tested":true,"test":{"path":"test/MidnightAdapterTest.sol:976, test/MidnightAdapterTest.sol:866","names":["testForceRemoveTimelock","testSetForceSellableNotTimelocked"],"command":"forge test --match-path test/MidnightAdapterTest.sol --match-test 'testForceRemoveTimelock|testSetForceSellableNotTimelocked'","output":"[PASS] testForceRemoveTimelock(address)\n[PASS] testSetForceSellableNotTimelocked(address,bytes32)"},"note":"Centralisation remains by design. See ranks 1 and 4."},{"priorId":"TrustSec TRST-CR-2","status":"partial","tested":true,"test":{"path":"test/MidnightAdapterTest.sol:1626, test/MidnightAdapterTest.sol:1818, test/MidnightAdapterTest.sol:1872","names":["testMinNetBuyRateAllocatorTakeRealVault","testMaxNetSellRateBoundary","testMinForceSellPriceBoundary"],"command":"forge test --match-path test/MidnightAdapterTest.sol --match-test 'testMinNetBuyRateAllocatorTakeRealVault|testMaxNetSellRateBoundary|testMinForceSellPriceBoundary'","output":"[PASS] testMinNetBuyRateAllocatorTakeRealVault()\n[PASS] testMaxNetSellRateBoundary()\n[PASS] testMinForceSellPriceBoundary(bool)"},"note":"Bounds work only as configured."},{"priorId":"TrustSec TRST-CR-3","status":"partial","tested":true,"test":{"path":"test/MidnightAdapterTest.sol:2135, test/MidnightAdapterTest.sol:2015, test/MidnightAdapterTest.sol:1094","names":["testDecreaseMaxTtm","testSentinelCanRemoveSubRatifier","testForceRemoveRealVaultWithSentinelAfterAllocatorRevocation"],"command":"forge test --match-path test/MidnightAdapterTest.sol --match-test 'testDecreaseMaxTtm|testSentinelCanRemoveSubRatifier|testForceRemoveRealVaultWithSentinelAfterAllocatorRevocation'","output":"[PASS] testDecreaseMaxTtm(uint256,uint256,bool)\n[PASS] testSentinelCanRemoveSubRatifier(address)\n[PASS] testForceRemoveRealVaultWithSentinelAfterAllocatorRevocation()"},"note":"These are the expected sentinel powers."}],"notCovered":["No exploit test was built for an attacker-deployed adapter (stub vault) admitting itself in a real IKRCompatibleEnterGate market (rank 9). It rests on the argument and on existing tests.","The rank 10 claim that a 0-asset force call on a held market with a realised loss resyncs stored net credit was not run.","No reentrancy test with a hostile gate or token inside the inForceDeallocate window (rank 3).","The Rate ratifier was not run separately (rank 11).","TRST-R-13 edge cases (a)-(f) were covered only through the existing tests listed, not one by one.","MidnightAdapterGasTest was not run: it needs a full build.","No fuzz or invariant campaign beyond the default runs of the repository fuzz tests listed."]}