{
 "commit": "bbeda7b27ae80abcf070e0158cb8a31e87bb2286",
 "checks": [
  {
   "id": "N1",
   "verdict": "confirmed",
   "class": "Informational",
   "classReasoning": "Impact: a curator can lower minForceSellPrice in the same block, and an allocator can then force-sell credit at any price. That realises a loss for depositors with no exit window. Likelihood: low. It needs two trusted roles (curator and allocator) acting against depositors, and the market must already be forceSellable, which takes a timelock (setForceSellable calls timelocked()). README.md:123 states plainly that the setter is immediate in either direction, and README.md:112 says these settings are 'not to provide guarantees to depositors'. The real defect is that the NatSpec at MidnightAdapter.sol:54-55 contradicts this: it says relaxing any of the four guardrails, minForceSellPrice included, is timelocked. A curator relying on it might set timelock[setMinForceSellPrice.selector] (30 days in the test) or abdicate it, expecting protection. Neither has any effect, because setMinForceSellPrice never calls timelocked(). Expected behaviour of a trusted role plus a doc inconsistency, so Informational.",
   "whoCanTrigger": "Curator (lower the price, immediate), then an allocator (take the sale). Only on a market that has already gone through the timelocked setForceSellable. Cost: gas only.",
   "numbers": "minForceSellPrice=0.95e18 first blocks a tick-0 sale (price at tick 0 = 0) with ForceSellPriceTooLow. The curator calls setMinForceSellPrice(id,0) in the same block, even with timelock[setMinForceSellPrice]=30 days. The allocator then sells 1000e18 units for 0 assets. Adapter realAssets goes from 100000000000030600145311 to 99005899300030295949053 (-994100700000304196258, about 994.1 tokens at 18 decimals). Vault totalAssets after accrual is 99005899300030295949054 (was 100000000000000000000000).",
   "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/MidnightAdapter.sol:273-277",
    "src/adapters/midnight/README.md:112",
    "src/adapters/midnight/README.md:123",
    "audits/2026-10-12-midnight-adapter-cantina-draft.pdf and audits/2026-10-12-midnight-adapter-trustsec-draft.pdf: not found (both review commit 6476e9d9). Nearest items: Cantina 3.2.10 'Midnight risk controls lack directional timelocks' (setMinRate/setNoSalesWithShortfall, Low) and TrustSec TRST-L-5 'setMinRate() is not timelocked' (Low). Neither names setMinForceSellPrice. audits/2026-07-08-gates-blackthorn.pdf: not found."
   ],
   "documentedAt": "src/adapters/midnight/README.md:123 \"`setMinForceSellPrice` is curator-only and immediate in either direction.\" (contradicted by src/adapters/midnight/MidnightAdapter.sol:54-55 \"minNetBuyRate, maxNetSellRate, shortfallAllowance and minForceSellPrice help the curator set guardrails for allocators.\" / \"Relaxing these guardrails is timelocked, but these timelocks are not hard guarantees on future interest for depositors.\")",
   "testSource": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nimport \"../integration/MidnightAdapterIntegrationTest.sol\";\nimport {console} from \"../../lib/forge-std/src/console.sol\";\n\ncontract NotesRecheckTest is MidnightAdapterIntegrationTest {\n    using MathLib for uint256;\n\n    function _err(string memory sig) internal pure returns (bytes4) {\n        return bytes4(keccak256(bytes(sig)));\n    }\n\n    function _buyOffer(Market memory market, uint256 units) internal view returns (Offer memory) {\n        return Offer({\n            market: market,\n            buy: true,\n            maker: address(adapter),\n            start: block.timestamp,\n            expiry: market.maturity,\n            tick: TICK,\n            group: keccak256(abi.encode(\"buy\", market.maturity, units)),\n            callback: address(adapter),\n            callbackData: abi.encode(address(0), \"\"),\n            receiverIfMakerIsSeller: address(0),\n            ratifier: address(adapter),\n            reduceOnly: false,\n            maxUnits: uint128(units),\n            maxAssets: 0,\n            continuousFeeCap: type(uint256).max\n        });\n    }\n\n    function _lenderBuyOffer(Market memory market, uint256 units, uint256 tick) internal returns (Offer memory offer, bytes memory ratifierData) {\n        offer = Offer({\n            market: market,\n            buy: true,\n            maker: lender,\n            start: block.timestamp,\n            expiry: market.maturity,\n            tick: tick,\n            group: keccak256(abi.encode(\"force sell\", market.maturity, units, tick)),\n            callback: address(0),\n            callbackData: \"\",\n            receiverIfMakerIsSeller: address(0),\n            ratifier: address(setterRatifier),\n            reduceOnly: false,\n            maxUnits: uint128(units),\n            maxAssets: 0,\n            continuousFeeCap: type(uint256).max\n        });\n        bytes32 root = HashLib.hashOffer(offer);\n        bytes32[] memory proof = new bytes32[](0);\n        ratifierData = abi.encode(root, uint256(0), proof);\n        deal(address(underlyingToken), lender, units);\n        vm.startPrank(lender);\n        SafeERC20Lib.safeApprove(address(underlyingToken), address(midnight), type(uint256).max);\n        midnight.setIsAuthorized(address(setterRatifier), true, lender);\n        setterRatifier.setIsRootRatified(lender, root, true);\n        vm.stopPrank();\n    }\n\n    /// N1: setMinForceSellPrice is immediate in both directions, even with a timelock set on its selector.\n    function testN1_MinForceSellPriceLoweredInstantly() public {\n        testMakerBuy();\n        Market memory market = _market(7 days);\n        bytes32 id = IdLib.toId(market);\n        _submitAndSet(address(adapter), abi.encodeCall(IMidnightAdapterBase.setForceSellable, (id)));\n\n        // Curator sets a 0.95 floor, then tries to timelock the setter: the timelock value is ignored.\n        vm.prank(curator);\n        adapter.setMinForceSellPrice(id, 0.95e18);\n        bytes4 sel = IMidnightAdapterBase.setMinForceSellPrice.selector;\n        _submitAndSet(address(adapter), abi.encodeCall(IMidnightAdapterBase.increaseTimelock, (sel, 30 days)));\n        assertEq(adapter.timelock(sel), 30 days);\n\n        uint256 units = 1000 * oneToken;\n        uint256 tick = 0;\n        (Offer memory offer, bytes memory rd) = _lenderBuyOffer(market, units, tick);\n        console.log(\"price at tick 0 (WAD)\", TickLib.tickToPrice(tick));\n\n        vm.prank(allocator);\n        vm.expectRevert(_err(\"ForceSellPriceTooLow()\"));\n        adapter.take(offer, rd, units, \"\");\n\n        uint256 realBefore = adapter.realAssets();\n        uint256 totalBefore = vault.totalAssets();\n        // Same block, no submit: lowering the floor to 0 is immediate.\n        vm.prank(curator);\n        adapter.setMinForceSellPrice(id, 0);\n        uint256 idleBefore = underlyingToken.balanceOf(address(vault));\n        vm.prank(allocator);\n        adapter.take(offer, rd, units, \"\");\n        uint256 received = underlyingToken.balanceOf(address(vault)) - idleBefore;\n        uint256 realAfter = adapter.realAssets();\n        console.log(\"realAssets before\", realBefore);\n        console.log(\"realAssets after \", realAfter);\n        console.log(\"assets received for 1000e18 units\", received);\n        console.log(\"value lost (realAssets drop - received)\", realBefore - realAfter - received);\n        console.log(\"vault totalAssets before\", totalBefore);\n        console.log(\"vault totalAssets after \", vault.totalAssets());\n        assertLt(received, units / 100);\n    }\n\n    /// N2: tightening does not cancel a pending relaxation, and any account executes it once due.\n    function testN2_TighteningDoesNotCancelPendingRelaxation() public {\n        bytes4 selRate = IMidnightAdapterBase.increaseMaxNetSellRate.selector;\n        bytes4 selAllow = IMidnightAdapterBase.increaseShortfallAllowance.selector;\n        bytes4 selBuy = IMidnightAdapterBase.decreaseMinNetBuyRate.selector;\n        _submitAndSet(address(adapter), abi.encodeCall(IMidnightAdapterBase.increaseTimelock, (selRate, 7 days)));\n        _submitAndSet(address(adapter), abi.encodeCall(IMidnightAdapterBase.increaseTimelock, (selAllow, 7 days)));\n        _submitAndSet(address(adapter), abi.encodeCall(IMidnightAdapterBase.increaseTimelock, (selBuy, 7 days)));\n\n        vm.startPrank(curator);\n        adapter.decreaseShortfallAllowance(type(uint256).max);\n        adapter.increaseMinNetBuyRate(0.05e18 / uint256(365 days));\n        uint256 lax = 1e18 / uint256(365 days);\n        bytes memory relaxRate = abi.encodeCall(IMidnightAdapterBase.increaseMaxNetSellRate, (10 * lax));\n        bytes memory relaxAllow = abi.encodeCall(IMidnightAdapterBase.increaseShortfallAllowance, (1_000_000e18));\n        bytes memory relaxBuy = abi.encodeCall(IMidnightAdapterBase.decreaseMinNetBuyRate, (0));\n        adapter.submit(relaxRate);\n        adapter.submit(relaxAllow);\n        adapter.submit(relaxBuy);\n        // Curator tightens every guardrail immediately.\n        adapter.decreaseMaxNetSellRate(0);\n        adapter.decreaseShortfallAllowance(type(uint256).max);\n        adapter.increaseMinNetBuyRate(0.10e18 / uint256(365 days));\n        vm.stopPrank();\n        assertEq(adapter.maxNetSellRate(), 0);\n        assertEq(adapter.shortfallAllowance(), 0);\n        // The pending relaxations survive the tightening.\n        assertGt(adapter.executableAt(relaxRate), 0);\n        assertGt(adapter.executableAt(relaxAllow), 0);\n        assertGt(adapter.executableAt(relaxBuy), 0);\n\n        vm.warp(block.timestamp + 7 days);\n        address stranger = makeAddr(\"stranger\");\n        assertFalse(vault.isAllocator(stranger) || vault.isSentinel(stranger) || vault.curator() == stranger);\n        vm.startPrank(stranger);\n        (bool ok1,) = address(adapter).call(relaxRate);\n        (bool ok2,) = address(adapter).call(relaxAllow);\n        (bool ok3,) = address(adapter).call(relaxBuy);\n        vm.stopPrank();\n        assertTrue(ok1 && ok2 && ok3);\n        console.log(\"maxNetSellRate after stranger executes\", adapter.maxNetSellRate());\n        console.log(\"shortfallAllowance after stranger executes\", adapter.shortfallAllowance());\n        console.log(\"minNetBuyRate after stranger executes\", adapter.minNetBuyRate());\n        assertEq(adapter.maxNetSellRate(), 10 * lax);\n        assertEq(adapter.shortfallAllowance(), 1_000_000e18);\n        assertEq(adapter.minNetBuyRate(), 0);\n    }\n\n    /// N2 counter-check: a sentinel or curator revoke does cancel it.\n    function testN2_RevokeCancels() public {\n        bytes4 selRate = IMidnightAdapterBase.increaseMaxNetSellRate.selector;\n        _submitAndSet(address(adapter), abi.encodeCall(IMidnightAdapterBase.increaseTimelock, (selRate, 7 days)));\n        bytes memory relaxRate = abi.encodeCall(IMidnightAdapterBase.increaseMaxNetSellRate, (1e18));\n        vm.prank(curator);\n        adapter.submit(relaxRate);\n        vm.prank(sentinel);\n        adapter.revoke(relaxRate);\n        vm.warp(block.timestamp + 7 days);\n        vm.expectRevert(_err(\"DataNotTimelocked()\"));\n        (bool ok,) = address(adapter).call(relaxRate);\n        ok;\n    }\n\n    /// N3: lossFactor maxed out -> forceDeallocate always reverts; allocator 0-asset deallocate resyncs.\n    function testN3_LossFactorMaxedOut() public {\n        testMakerBuy();\n        Market memory market = _market(7 days);\n        bytes32 id = IdLib.toId(market);\n        bytes32 adapterIdLocal = adapter.adapterId();\n\n        // The borrower holds all the debt; collateral goes to zero and bad debt is realized permissionlessly.\n        oracle.setPrice(0);\n        midnight.liquidate(market, 0, 0, 0, borrower, false, address(this), address(0), \"\");\n        assertEq(midnight.lossFactor(id), type(uint128).max, \"lossFactor\");\n\n        console.log(\"stored netCredit   \", uint256(adapter.marketData(id).netCredit));\n        console.log(\"vault allocation(adapterId)\", vault.allocation(adapterIdLocal));\n        console.log(\"realAssets         \", adapter.realAssets());\n        console.log(\"durationAllocations[0]\", adapter.durationAllocations(1)[0]);\n\n        vm.startPrank(depositor);\n        midnight.setIsAuthorized(address(adapter), true, depositor);\n        vm.expectRevert(IMidnight.MarketLossFactorMaxedOut.selector);\n        vault.forceDeallocate(address(adapter), abi.encode(market, depositor), 0, depositor);\n        deal(address(underlyingToken), depositor, 1);\n        SafeERC20Lib.safeApprove(address(underlyingToken), address(adapter), 1);\n        vm.expectRevert(IMidnight.MarketLossFactorMaxedOut.selector);\n        vault.forceDeallocate(address(adapter), abi.encode(market, depositor), 1, depositor);\n        vm.stopPrank();\n\n        // Anyone touching Midnight does not update the adapter's stored state.\n        midnight.updatePosition(market, address(adapter));\n        assertGt(adapter.marketData(id).netCredit, 0);\n\n        // A non-privileged account cannot use deallocate.\n        vm.prank(depositor);\n        vm.expectRevert();\n        vault.deallocate(address(adapter), abi.encode(market), 0);\n\n        // Sentinel deallocate of 0 resyncs.\n        vm.prank(sentinel);\n        vault.deallocate(address(adapter), abi.encode(market), 0);\n        console.log(\"after sentinel deallocate(0): netCredit\", uint256(adapter.marketData(id).netCredit));\n        console.log(\"after sentinel deallocate(0): allocation\", vault.allocation(adapterIdLocal));\n        console.log(\"after sentinel deallocate(0): marketIdsLength\", adapter.marketIdsLength());\n        assertEq(adapter.marketData(id).netCredit, 0);\n        assertEq(vault.allocation(adapterIdLocal), 0);\n    }\n\n    /// N4: disabling a sub-ratifier does not revoke roots; re-enabling lets the old offer fill again.\n    function testN4_SubRatifierReenableRevivesRoot() public {\n        uint256 units = initialAssets * WAD / TickLib.tickToPrice(TICK);\n        Market memory market = _market(7 days);\n        Offer memory offer = _buyOffer(market, units);\n        bytes32 root = HashLib.hashPriceRatifierV1Offer(offer, address(0));\n        vm.prank(allocator);\n        priceSubRatifier.setIsRootRatified(address(adapter), root, true, allocator);\n        bytes32[] memory proof = new bytes32[](0);\n        bytes memory ratifierData = abi.encode(address(priceSubRatifier), abi.encode(root, uint256(0), proof, address(0)));\n        uint256 collateral = units * 2e18 / oneToken;\n        deal(address(collateralToken), borrower, collateral);\n        vm.startPrank(borrower);\n        collateralToken.approve(address(midnight), collateral);\n        midnight.supplyCollateral(market, 0, collateral, borrower);\n        midnight.take(offer, ratifierData, units / 2, borrower, borrower, address(0), \"\");\n        vm.stopPrank();\n        uint256 creditAfterFirst = midnight.credit(IdLib.toId(market), address(adapter));\n\n        // Sentinel disables the sub-ratifier: the offer stops filling.\n        vm.prank(sentinel);\n        adapter.setIsSubRatifier(address(priceSubRatifier), false);\n        vm.prank(borrower);\n        vm.expectRevert(_err(\"SubRatifierFailed()\"));\n        midnight.take(offer, ratifierData, units / 4, borrower, borrower, address(0), \"\");\n        assertTrue(priceSubRatifier.isRootRatified(address(adapter), root), \"root still ratified\");\n\n        // Sentinel cannot re-enable.\n        vm.prank(sentinel);\n        vm.expectRevert(_err(\"NotAuthorized()\"));\n        adapter.setIsSubRatifier(address(priceSubRatifier), true);\n\n        // Allocator re-enables (e.g. to use it for new offers): the old root fills again with the same proof.\n        vm.prank(allocator);\n        adapter.setIsSubRatifier(address(priceSubRatifier), true);\n        vm.prank(borrower);\n        midnight.take(offer, ratifierData, units / 4, borrower, borrower, address(0), \"\");\n        uint256 creditAfterSecond = midnight.credit(IdLib.toId(market), address(adapter));\n        console.log(\"offer units\", units);\n        console.log(\"credit after first fill\", creditAfterFirst);\n        console.log(\"credit after refill post re-enable\", creditAfterSecond);\n        assertGt(creditAfterSecond, creditAfterFirst);\n    }\n}\n",
   "command": "export XDG_DATA_HOME=$PWD/../xdg; forge test --match-path test/poc/NotesRecheckTest.sol --match-test testN1_MinForceSellPriceLoweredInstantly -vv",
   "output": "No files changed, compilation skipped\n\nRan 1 test for test/poc/NotesRecheckTest.sol:NotesRecheckTest\n[PASS] testN1_MinForceSellPriceLoweredInstantly() (gas: 2517227)\nLogs:\n  price at tick 0 (WAD) 0\n  realAssets before 100000000000030600145311\n  realAssets after  99005899300030295949053\n  assets received for 1000e18 units 0\n  value lost (realAssets drop - received) 994100700000304196258\n  vault totalAssets before 100000000000000000000000\n  vault totalAssets after  99005899300030295949054\n\nSuite result: ok. 1 passed; 0 failed; 0 skipped; finished in 19.84ms (5.58ms CPU time)\n\nRan 1 test suite in 22.46ms (19.84ms CPU time): 1 tests passed, 0 failed, 0 skipped (1 total tests)",
   "suggestedFix": "Either fix the NatSpec (MidnightAdapter.sol:54-55) to say minForceSellPrice is immediate in both directions, matching README.md:123. Or split the setter into increaseMinForceSellPrice (curator, immediate) and decreaseMinForceSellPrice (calls timelocked()), so a submitted timelock or abdicate applies when the price is lowered."
  },
  {
   "id": "N2",
   "verdict": "confirmed",
   "class": "Informational",
   "classReasoning": "The claim holds: decreaseMaxNetSellRate, decreaseShortfallAllowance and increaseMinNetBuyRate leave executableAt of a pending relaxation untouched. Once due, an account with no role executes it, because timelocked() (:208-217) checks no caller. This is the documented Vault V2 timelock design: the vault README.md:49 says '(by anyone)', and MidnightAdapter.sol:82 says the adapter uses the same system. Cancelling is done by revoke, which the curator or a sentinel can call, and testN2_RevokeCancels shows it works. Only the curator can create the pending relaxation (a trusted role), and it then runs exactly as submitted. The only risk is operational: a curator who tightens may assume the earlier submission is void. No unprivileged impact, so Informational (documentation); arguably not an issue.",
   "whoCanTrigger": "Only the curator can submit the relaxation. Once due, any account with no role can execute it. Cost: gas.",
   "numbers": "Timelocks of 7 days. Pending: increaseMaxNetSellRate(10*(1e18/365 days)), increaseShortfallAllowance(1e24), decreaseMinNetBuyRate(0). The curator then sets maxNetSellRate=0, shortfallAllowance=0 and minNetBuyRate=0.10e18/365 days at once. After 7 days a stranger (not curator, allocator or sentinel) executes all three: maxNetSellRate=317097919830, shortfallAllowance=1000000000000000000000000, minNetBuyRate=0. A sentinel revoke before the timelock expires makes later execution revert DataNotTimelocked.",
   "refs": [
    "src/adapters/midnight/MidnightAdapter.sol:191-226",
    "src/adapters/midnight/MidnightAdapter.sol:258-270",
    "src/adapters/midnight/MidnightAdapter.sol:291-332",
    "src/adapters/midnight/MidnightAdapter.sol:82",
    "README.md:49",
    "audits: not a finding in either 2026-10-12 draft. Related only: TrustSec TRST-R-11 (actions submitted under lower timelocks remain executable) and Cantina 3.2.4, which notes in passing 'At T, anyone can execute the pending action.' Not in 2026-07-08-gates-blackthorn.pdf."
   ],
   "documentedAt": "README.md:49 \"meaning that doing an action requires submitting it first, and only when the timelock has passed it can be executed (by anyone).\"; src/adapters/midnight/MidnightAdapter.sol:82 \"The system is the same as the one used in VaultV2. Dev comments in VaultV2.sol on timelocks also apply here.\"",
   "testSource": "// test/poc/NotesRecheckTest.sol (functions below). contract NotesRecheckTest is MidnightAdapterIntegrationTest; helpers _err, _buyOffer, _lenderBuyOffer are in the full file given in check N1.\n    /// N2: tightening does not cancel a pending relaxation, and any account executes it once due.\n    function testN2_TighteningDoesNotCancelPendingRelaxation() public {\n        bytes4 selRate = IMidnightAdapterBase.increaseMaxNetSellRate.selector;\n        bytes4 selAllow = IMidnightAdapterBase.increaseShortfallAllowance.selector;\n        bytes4 selBuy = IMidnightAdapterBase.decreaseMinNetBuyRate.selector;\n        _submitAndSet(address(adapter), abi.encodeCall(IMidnightAdapterBase.increaseTimelock, (selRate, 7 days)));\n        _submitAndSet(address(adapter), abi.encodeCall(IMidnightAdapterBase.increaseTimelock, (selAllow, 7 days)));\n        _submitAndSet(address(adapter), abi.encodeCall(IMidnightAdapterBase.increaseTimelock, (selBuy, 7 days)));\n\n        vm.startPrank(curator);\n        adapter.decreaseShortfallAllowance(type(uint256).max);\n        adapter.increaseMinNetBuyRate(0.05e18 / uint256(365 days));\n        uint256 lax = 1e18 / uint256(365 days);\n        bytes memory relaxRate = abi.encodeCall(IMidnightAdapterBase.increaseMaxNetSellRate, (10 * lax));\n        bytes memory relaxAllow = abi.encodeCall(IMidnightAdapterBase.increaseShortfallAllowance, (1_000_000e18));\n        bytes memory relaxBuy = abi.encodeCall(IMidnightAdapterBase.decreaseMinNetBuyRate, (0));\n        adapter.submit(relaxRate);\n        adapter.submit(relaxAllow);\n        adapter.submit(relaxBuy);\n        // Curator tightens every guardrail immediately.\n        adapter.decreaseMaxNetSellRate(0);\n        adapter.decreaseShortfallAllowance(type(uint256).max);\n        adapter.increaseMinNetBuyRate(0.10e18 / uint256(365 days));\n        vm.stopPrank();\n        assertEq(adapter.maxNetSellRate(), 0);\n        assertEq(adapter.shortfallAllowance(), 0);\n        // The pending relaxations survive the tightening.\n        assertGt(adapter.executableAt(relaxRate), 0);\n        assertGt(adapter.executableAt(relaxAllow), 0);\n        assertGt(adapter.executableAt(relaxBuy), 0);\n\n        vm.warp(block.timestamp + 7 days);\n        address stranger = makeAddr(\"stranger\");\n        assertFalse(vault.isAllocator(stranger) || vault.isSentinel(stranger) || vault.curator() == stranger);\n        vm.startPrank(stranger);\n        (bool ok1,) = address(adapter).call(relaxRate);\n        (bool ok2,) = address(adapter).call(relaxAllow);\n        (bool ok3,) = address(adapter).call(relaxBuy);\n        vm.stopPrank();\n        assertTrue(ok1 && ok2 && ok3);\n        console.log(\"maxNetSellRate after stranger executes\", adapter.maxNetSellRate());\n        console.log(\"shortfallAllowance after stranger executes\", adapter.shortfallAllowance());\n        console.log(\"minNetBuyRate after stranger executes\", adapter.minNetBuyRate());\n        assertEq(adapter.maxNetSellRate(), 10 * lax);\n        assertEq(adapter.shortfallAllowance(), 1_000_000e18);\n        assertEq(adapter.minNetBuyRate(), 0);\n    }\n    /// N2 counter-check: a sentinel or curator revoke does cancel it.\n    function testN2_RevokeCancels() public {\n        bytes4 selRate = IMidnightAdapterBase.increaseMaxNetSellRate.selector;\n        _submitAndSet(address(adapter), abi.encodeCall(IMidnightAdapterBase.increaseTimelock, (selRate, 7 days)));\n        bytes memory relaxRate = abi.encodeCall(IMidnightAdapterBase.increaseMaxNetSellRate, (1e18));\n        vm.prank(curator);\n        adapter.submit(relaxRate);\n        vm.prank(sentinel);\n        adapter.revoke(relaxRate);\n        vm.warp(block.timestamp + 7 days);\n        vm.expectRevert(_err(\"DataNotTimelocked()\"));\n        (bool ok,) = address(adapter).call(relaxRate);\n        ok;\n    }\n",
   "command": "export XDG_DATA_HOME=$PWD/../xdg; forge test --match-path test/poc/NotesRecheckTest.sol --match-test testN2_ -vv",
   "output": "No files changed, compilation skipped\n\nRan 2 tests for test/poc/NotesRecheckTest.sol:NotesRecheckTest\n[PASS] testN2_RevokeCancels() (gas: 243987)\n[PASS] testN2_TighteningDoesNotCancelPendingRelaxation() (gas: 917497)\nLogs:\n  maxNetSellRate after stranger executes 317097919830\n  shortfallAllowance after stranger executes 1000000000000000000000000\n  minNetBuyRate after stranger executes 0\n\nSuite result: ok. 2 passed; 0 failed; 0 skipped; finished in 7.31ms (786.79µs CPU time)\n\nRan 1 test suite in 21.69ms (7.31ms CPU time): 2 tests passed, 0 failed, 0 skipped (2 total tests)",
   "suggestedFix": "Document in the adapter README 'Operational constraints' section that an immediate tightening does not cancel a pending relaxation, so the curator should revoke the pending data in the same multicall. Optionally, have the immediate tightening functions reject (or clear) when a matching relaxation is pending. Generic clearing is hard because executableAt is keyed by full calldata."
  },
  {
   "id": "N3",
   "verdict": "confirmed",
   "class": "Informational",
   "classReasoning": "Confirmed: once lossFactor==type(uint128).max, vault.forceDeallocate on that market reverts MarketLossFactorMaxedOut for any amount, 0 included, because the adapter always calls Midnight.take (:469), which requires lossFactor<max (lib/midnight/src/Midnight.sol:332). Only allocator or sentinel deallocate(abi.encode(market),0) resyncs, via withdrawToVault (:717-737), since Midnight.withdraw has no lossFactor check. Impact is limited. realAssets is already correct (it reads live credit when lossFactor!=0, :848-854, and showed 0), so share price and depositor exits on other markets are unaffected. There is nothing left to redeem in-kind in that market, because the adapter's credit there is 0. Only cap bookkeeping stays stale: vault allocations for the adapter, family and collateral ids, durationAllocations, and a marketIds slot. That can block new buys against those caps until a trusted role resyncs. Total bad debt is permissionless to realise but needs a full collateral collapse. No loss of funds, so Informational.",
   "whoCanTrigger": "Anyone can realise the full bad debt with liquidate(...,0,0,...) once collateral value covers none of the debt (a market event, no special cost). The stale allocation can then be cleared only by an allocator or sentinel (vault.deallocate with 0 assets), or by the curator through the timelocked forceRemove. A shareholder cannot clear it.",
   "numbers": "After the adapter's maker buy, the borrower holds all the debt. Oracle price is set to 0 and liquidate(0,0) is called, giving lossFactor=2^128-1. Stored netCredit = vault allocation(adapterId) = durationAllocations[0] = 100593430826474621736007, while realAssets = 0. forceDeallocate with assets 0 and 1 both revert MarketLossFactorMaxedOut. midnight.updatePosition(adapter) leaves the stored netCredit unchanged. A depositor's vault.deallocate reverts. Sentinel deallocate(market,0) sets netCredit to 0, allocation to 0 and marketIdsLength to 0.",
   "refs": [
    "src/adapters/midnight/MidnightAdapter.sol:427-477",
    "src/adapters/midnight/MidnightAdapter.sol:716-737",
    "src/adapters/midnight/MidnightAdapter.sol:846-855",
    "lib/midnight/src/Midnight.sol:332",
    "lib/midnight/src/Midnight.sol:474-493",
    "lib/midnight/test/LiquidationTest.sol:926",
    "audits: not found in either 2026-10-12 draft. Closest: Cantina 3.2.5 'onBuy might revert due to stale allocation checks' (stale netCredit in duration allocations after bad debt, Low). Not in 2026-07-08-gates-blackthorn.pdf."
   ],
   "documentedAt": "src/adapters/midnight/MidnightAdapter.sol:717 \"Can be called with `withdrawnAssets == 0` to synchronize `marketData` after a loss.\" This documents the resync path only. The forceDeallocate revert at a maxed-out lossFactor is not stated in the adapter docs. Midnight's own test lib/midnight/test/LiquidationTest.sol:926 says \"The market is now permanently unusable: any take reverts.\"",
   "testSource": "// test/poc/NotesRecheckTest.sol (functions below). contract NotesRecheckTest is MidnightAdapterIntegrationTest; helpers _err, _buyOffer, _lenderBuyOffer are in the full file given in check N1.\n    /// N3: lossFactor maxed out -> forceDeallocate always reverts; allocator 0-asset deallocate resyncs.\n    function testN3_LossFactorMaxedOut() public {\n        testMakerBuy();\n        Market memory market = _market(7 days);\n        bytes32 id = IdLib.toId(market);\n        bytes32 adapterIdLocal = adapter.adapterId();\n\n        // The borrower holds all the debt; collateral goes to zero and bad debt is realized permissionlessly.\n        oracle.setPrice(0);\n        midnight.liquidate(market, 0, 0, 0, borrower, false, address(this), address(0), \"\");\n        assertEq(midnight.lossFactor(id), type(uint128).max, \"lossFactor\");\n\n        console.log(\"stored netCredit   \", uint256(adapter.marketData(id).netCredit));\n        console.log(\"vault allocation(adapterId)\", vault.allocation(adapterIdLocal));\n        console.log(\"realAssets         \", adapter.realAssets());\n        console.log(\"durationAllocations[0]\", adapter.durationAllocations(1)[0]);\n\n        vm.startPrank(depositor);\n        midnight.setIsAuthorized(address(adapter), true, depositor);\n        vm.expectRevert(IMidnight.MarketLossFactorMaxedOut.selector);\n        vault.forceDeallocate(address(adapter), abi.encode(market, depositor), 0, depositor);\n        deal(address(underlyingToken), depositor, 1);\n        SafeERC20Lib.safeApprove(address(underlyingToken), address(adapter), 1);\n        vm.expectRevert(IMidnight.MarketLossFactorMaxedOut.selector);\n        vault.forceDeallocate(address(adapter), abi.encode(market, depositor), 1, depositor);\n        vm.stopPrank();\n\n        // Anyone touching Midnight does not update the adapter's stored state.\n        midnight.updatePosition(market, address(adapter));\n        assertGt(adapter.marketData(id).netCredit, 0);\n\n        // A non-privileged account cannot use deallocate.\n        vm.prank(depositor);\n        vm.expectRevert();\n        vault.deallocate(address(adapter), abi.encode(market), 0);\n\n        // Sentinel deallocate of 0 resyncs.\n        vm.prank(sentinel);\n        vault.deallocate(address(adapter), abi.encode(market), 0);\n        console.log(\"after sentinel deallocate(0): netCredit\", uint256(adapter.marketData(id).netCredit));\n        console.log(\"after sentinel deallocate(0): allocation\", vault.allocation(adapterIdLocal));\n        console.log(\"after sentinel deallocate(0): marketIdsLength\", adapter.marketIdsLength());\n        assertEq(adapter.marketData(id).netCredit, 0);\n        assertEq(vault.allocation(adapterIdLocal), 0);\n    }\n",
   "command": "export XDG_DATA_HOME=$PWD/../xdg; forge test --match-path test/poc/NotesRecheckTest.sol --match-test testN3_LossFactorMaxedOut -vv",
   "output": "No files changed, compilation skipped\n\nRan 1 test for test/poc/NotesRecheckTest.sol:NotesRecheckTest\n[PASS] testN3_LossFactorMaxedOut() (gas: 2077570)\nLogs:\n  stored netCredit    100593430826474621736007\n  vault allocation(adapterId) 100593430826474621736007\n  realAssets          0\n  durationAllocations[0] 100593430826474621736007\n  after sentinel deallocate(0): netCredit 0\n  after sentinel deallocate(0): allocation 0\n  after sentinel deallocate(0): marketIdsLength 0\n\nSuite result: ok. 1 passed; 0 failed; 0 skipped; finished in 17.33ms (4.14ms CPU time)\n\nRan 1 test suite in 21.23ms (17.33ms CPU time): 1 tests passed, 0 failed, 0 skipped (1 total tests)",
   "suggestedFix": "Document it. Optionally, in the forceDeallocate branch, when IMidnight(midnight).lossFactor(marketId)==type(uint128).max and assets==0, skip the take and just resync stored netCredit (as withdrawToVault does). That lets any shareholder clear stale cap allocations."
  },
  {
   "id": "N4",
   "verdict": "confirmed",
   "class": "Informational",
   "classReasoning": "Confirmed: setIsSubRatifier(false) only gates isRatified (:504). The price ratifier's root state (ratifiers/MidnightAdapterPriceRatifierV1.sol:107) is untouched, so after an allocator calls setIsSubRatifier(true) the same offer and proof fill again. Re-enabling needs an allocator (trusted), since a sentinel cannot re-enable (:349, tested). The ratifier documents that roots persist until explicitly unratified (:21), and sentinels can unratify roots directly (README.md:150, ratifier :38-40). Disabling the sub-ratifier is a pause, not a cancellation. A sentinel who wants to cancel offers must unratify the roots. Trusted-role behaviour plus documentation, so Informational.",
   "whoCanTrigger": "Only an allocator, by re-enabling the sub-ratifier. Then any taker of the still-ratified offer. Cost: gas.",
   "numbers": "Maker buy offer for 100593430826474621736007 units. The first fill of half leaves adapter credit at 50296715413237310868003. A sentinel disables the sub-ratifier, so a take reverts SubRatifierFailed while isRootRatified stays true. A sentinel re-enable reverts NotAuthorized. After an allocator re-enables, a take of a quarter with the old proof succeeds, and credit becomes 75445073119855966302004.",
   "refs": [
    "src/adapters/midnight/MidnightAdapter.sol:348-352",
    "src/adapters/midnight/MidnightAdapter.sol:503-505",
    "src/adapters/midnight/ratifiers/MidnightAdapterPriceRatifierV1.sol:21",
    "src/adapters/midnight/ratifiers/MidnightAdapterPriceRatifierV1.sol:33-48",
    "src/adapters/midnight/ratifiers/MidnightAdapterPriceRatifierV1.sol:107",
    "src/adapters/midnight/README.md:150",
    "audits: not found in either 2026-10-12 draft. Related only: TrustSec TRST-R-5 (a pending allocator setIsRootRatified can re-ratify a root a sentinel unratified). Not in 2026-07-08-gates-blackthorn.pdf."
   ],
   "documentedAt": "src/adapters/midnight/ratifiers/MidnightAdapterPriceRatifierV1.sol:21 \"Approved roots remain ratified after an allocator is removed, until explicitly unratified.\"",
   "testSource": "// test/poc/NotesRecheckTest.sol (functions below). contract NotesRecheckTest is MidnightAdapterIntegrationTest; helpers _err, _buyOffer, _lenderBuyOffer are in the full file given in check N1.\n    /// N4: disabling a sub-ratifier does not revoke roots; re-enabling lets the old offer fill again.\n    function testN4_SubRatifierReenableRevivesRoot() public {\n        uint256 units = initialAssets * WAD / TickLib.tickToPrice(TICK);\n        Market memory market = _market(7 days);\n        Offer memory offer = _buyOffer(market, units);\n        bytes32 root = HashLib.hashPriceRatifierV1Offer(offer, address(0));\n        vm.prank(allocator);\n        priceSubRatifier.setIsRootRatified(address(adapter), root, true, allocator);\n        bytes32[] memory proof = new bytes32[](0);\n        bytes memory ratifierData = abi.encode(address(priceSubRatifier), abi.encode(root, uint256(0), proof, address(0)));\n        uint256 collateral = units * 2e18 / oneToken;\n        deal(address(collateralToken), borrower, collateral);\n        vm.startPrank(borrower);\n        collateralToken.approve(address(midnight), collateral);\n        midnight.supplyCollateral(market, 0, collateral, borrower);\n        midnight.take(offer, ratifierData, units / 2, borrower, borrower, address(0), \"\");\n        vm.stopPrank();\n        uint256 creditAfterFirst = midnight.credit(IdLib.toId(market), address(adapter));\n\n        // Sentinel disables the sub-ratifier: the offer stops filling.\n        vm.prank(sentinel);\n        adapter.setIsSubRatifier(address(priceSubRatifier), false);\n        vm.prank(borrower);\n        vm.expectRevert(_err(\"SubRatifierFailed()\"));\n        midnight.take(offer, ratifierData, units / 4, borrower, borrower, address(0), \"\");\n        assertTrue(priceSubRatifier.isRootRatified(address(adapter), root), \"root still ratified\");\n\n        // Sentinel cannot re-enable.\n        vm.prank(sentinel);\n        vm.expectRevert(_err(\"NotAuthorized()\"));\n        adapter.setIsSubRatifier(address(priceSubRatifier), true);\n\n        // Allocator re-enables (e.g. to use it for new offers): the old root fills again with the same proof.\n        vm.prank(allocator);\n        adapter.setIsSubRatifier(address(priceSubRatifier), true);\n        vm.prank(borrower);\n        midnight.take(offer, ratifierData, units / 4, borrower, borrower, address(0), \"\");\n        uint256 creditAfterSecond = midnight.credit(IdLib.toId(market), address(adapter));\n        console.log(\"offer units\", units);\n        console.log(\"credit after first fill\", creditAfterFirst);\n        console.log(\"credit after refill post re-enable\", creditAfterSecond);\n        assertGt(creditAfterSecond, creditAfterFirst);\n    }\n",
   "command": "export XDG_DATA_HOME=$PWD/../xdg; forge test --match-path test/poc/NotesRecheckTest.sol --match-test testN4_SubRatifierReenableRevivesRoot -vv",
   "output": "No files changed, compilation skipped\n\nRan 1 test for test/poc/NotesRecheckTest.sol:NotesRecheckTest\n[PASS] testN4_SubRatifierReenableRevivesRoot() (gas: 1644686)\nLogs:\n  offer units 100593430826474621736007\n  credit after first fill 50296715413237310868003\n  credit after refill post re-enable 75445073119855966302004\n\nSuite result: ok. 1 passed; 0 failed; 0 skipped; finished in 9.01ms (1.93ms CPU time)\n\nRan 1 test suite in 42.01ms (9.01ms CPU time): 1 tests passed, 0 failed, 0 skipped (1 total tests)",
   "suggestedFix": "Document on setIsSubRatifier that disabling pauses rather than cancels, and that previously ratified roots revive on re-enable, so sentinels should unratify roots (or allocators use setConsumed) to cancel offers. Optionally, store a per-sub-ratifier epoch that increments on disable and require it in ratifierData, so re-enabling does not revive old approvals."
  }
 ]
}