{
 "angle": "Price and rate ratifier checks: stale, manipulated or boundary inputs (MidnightAdapterPriceRatifierV1, MidnightAdapterRateRatifierV1, MidnightAdapter.isRatified / setIsSubRatifier / setConsumed)",
 "commit": "bbeda7b27ae80abcf070e0158cb8a31e87bb2286",
 "hasCandidates": false,
 "candidates": [],
 "summary": "No finding survived. One candidate (setConsumed on group 0 blocking forceDeallocate) was written as a Foundry PoC against the real Midnight and Vault V2, and the PoC disproved it. Every other path through the ratifiers I checked holds, or is already reported in the TrustSec or Cantina drafts, or is accepted in NatSpec. Four observations are listed under lowInfo.",
 "lowInfo": [
  {
   "title": "Rate ratifier: a sell leaf with a very large rate overflows WAD + rate * ttm and cannot be taken before maturity (it panics instead of meaning 'any price')",
   "class": "Informational",
   "verified": true,
   "refs": [
    "src/adapters/midnight/ratifiers/MidnightAdapterRateRatifierV1.sol:105-108"
   ],
   "detail": "isRatified computes WAD + rate * timeToMaturity with checked arithmetic. If an allocator signs a sell leaf with rate = type(uint256).max (or any rate > (2^256-1-WAD)/ttm) to mean 'sell at any price', every take before maturity reverts with Panic(0x11), not WorsePrice. Once block.timestamp >= maturity (ttm = 0) the same leaf is accepted at a price of at least WAD. Nothing is lost: the offer just cannot be filled, and the leaf is allocator-chosen. Test test/poc/RateRatifierBoundaries.t.sol::testHugeRateSellOfferOverflowsBeforeMaturity passes. Log: 'ttm before maturity 31536000 -> panic 0x11', 'at maturity, price 1000000000000000000 accepted'. Possible fix: document an upper bound on rate, or saturate (if rate > (type(uint256).max - WAD) / ttm, treat the limit as 0 for sells and revert WorsePrice for buys)."
  },
  {
   "title": "Re-enabling a disabled sub-ratifier revives every root still ratified in it, including roots from removed allocators and roots a sentinel only 'cancelled' by disabling the sub-ratifier",
   "class": "Informational",
   "verified": false,
   "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/MidnightAdapterRateRatifierV1.sol:23"
   ],
   "detail": "setIsSubRatifier stores only a boolean. Ratifications live in the sub-ratifier, keyed by (maker, root), and are not tied to an epoch. A sentinel can only disable the whole sub-ratifier (setIsSubRatifier(x, false)) as an emergency stop. If any allocator later re-enables it to publish new offers, every old root comes back at once. That includes roots ratified by allocators who have since been removed, which the NatSpec says 'remain ratified after an allocator is removed, until explicitly unratified'. This requires a trusted allocator action and is consistent with that accepted risk, so it is not a finding. Worth documenting: before re-enabling, unratify old roots one by one, or set consumed for their groups. Suggested hardening: an epoch counter per (maker, sub-ratifier) included in isRatified. UNVERIFIED: no PoC was written for this item."
  },
  {
   "title": "Midnight NatSpec says setConsumed(group, type(uint128).max) 'cancels all offers', but it does not block the adapter's group-0 forceDeallocate offer (checked; not an issue)",
   "class": "Informational",
   "verified": true,
   "refs": [
    "src/adapters/midnight/MidnightAdapter.sol:342-346",
    "src/adapters/midnight/MidnightAdapter.sol:436-452",
    "lib/midnight/src/Midnight.sol:717-722"
   ],
   "detail": "Candidate tested and rejected. forceDeallocate builds its own sell offer with group bytes32(0) and maxAssets type(uint128).max. Any sentinel or allocator can call adapter.setConsumed(bytes32(0), type(uint128).max), and Midnight never lets that value go down. I expected this to block in-kind redemptions permanently. It does not, because the offer uses tick 0 (price 0): sellerAssets = 0, so consumed + 0 <= maxAssets still passes, and payment happens outside Midnight. PoC test/poc/SetConsumedGroupZeroBlocksIKR.t.sol (inherits MidnightAdapterIntegrationTest; real Midnight, VaultV2 and MidnightAdapterFactory) was run with: forge test --match-contract SetConsumedGroupZeroBlocksIKRTest -vv. Result: '[FAIL: forceDeallocate should revert]', i.e. forceDeallocate still succeeded after consumed[adapter][0] = 340282366920938463463374607431768211455. Logs: vault idle 1, adapter realAssets 100000000000030600145311, forceDeallocate of 1000e18 ok before. Remaining informational point: if the forceDeallocate offer ever moves off tick 0 or onto a maxUnits cap, this would become a permanent IKR block that a sentinel can trigger. A comment at MidnightAdapter.sol:442-450 would protect that invariant. TrustSec separately notes that 'fully consumed' offers can still be taken for 0 units."
  },
  {
   "title": "Signature malleability and stale-nonce replay of setIsRootRatifiedWithSig only produce no-op calls and extra events",
   "class": "Informational",
   "verified": true,
   "refs": [
    "src/adapters/midnight/ratifiers/MidnightAdapterPriceRatifierV1.sol:70-91",
    "src/adapters/midnight/ratifiers/MidnightAdapterRateRatifierV1.sol:72-93"
   ],
   "detail": "ecrecover accepts both s and n-s, and a used nonce below rootNonce is accepted when the stored status already equals the signed one. A replayed or malleated signature can therefore only rewrite the same status and emit another SetIsRootRatifiedWithSig event, and only when the caller is the signer or is authorized by the signer on Midnight. Indexers counting events should deduplicate by (maker, root, nonce). The existing testSignatureReplayAndStatusChange covers the no-op behaviour. The related problem, that a direct setIsRootRatified does not bump the nonce so an outstanding signature can re-ratify a root a sentinel cancelled, is already TRST-R-5 and out of scope. Delegated submission is TRST-R-6, also out of scope."
  }
 ],
 "covered": [
  "Build: cloned morpho-org/vault-v2 at bbeda7b27ae80abcf070e0158cb8a31e87bb2286 with submodules. Built with Foundry 1.9.0 (solc 0.8.19/0.8.21/0.8.26/0.8.28/0.8.34/0.8.37), skipping unrelated test files to fit the time budget. A full 'forge build' with every test was started twice but stopped by my own 590 s timeout during the via-IR compile of 261 test files. The full suite was NOT run.",
  "Tests run: test/MidnightAdapterRatifiersV1Test.sol::MidnightAdapterRateRatifierV1Test (inherited, 38 tests) plus 4 new boundary tests in test/poc/RateRatifierBoundaries.t.sol: 42 passed, 0 failed (forge test --match-contract RateRatifierBoundariesTest -vv). The 8 MidnightAdapterIntegrationTest flows inherited by the PoC all passed.",
  "Diffed both adapter ratifiers against lib/midnight/src/ratifiers/{Price,Rate}RatifierV1.sol. Only the authorization differs: parent-vault allocator/sentinel plus onBehalf delegation through the maker's Midnight isAuthorized, instead of maker authorization. The MIDNIGHT immutable was also removed.",
  "Authorization: onBehalf must currently be an allocator (or a sentinel when unratifying), and msg.sender must be onBehalf or authorized by onBehalf on the maker's Midnight. Removing the role invalidates delegates and signatures (existing tests testRemovedRoleDelegateRejected, testRemovedAllocatorSignatureRejectedButApprovedRootsPersist). An arbitrary 'maker' contract can only write ratification[thatMaker], and MidnightAdapter.isRatified requires offer.maker == address(this), so a fake maker cannot affect a real adapter. The adapter itself is an allocator. Nobody but the adapter is authorized on Midnight for it (constructor setIsAuthorized(self)), and it has no arbitrary-call path (multicall only delegatecalls itself), so it cannot be used as onBehalf.",
  "Signatures: the digest binds typehash(height), maker, root, status, nonce and deadline. The domain binds chainId and verifyingContract, and is recomputed every call, so it stays fork-safe. Price and rate typehashes differ, so there is no replay across ratifiers, adapters or chains (existing testSignatureCannotCrossChainOrRatifier, testSignedFieldsCannotBeChanged). ecrecover returning 0 is rejected. Malleability is harmless (see lowInfo).",
  "Merkle proofs: the leaf hash covers every Offer field, including market (chainId, midnight, loanToken, collaterals, maturity, gates), buy, maker, start, expiry, tick or rate, allowedTaker, group, callback, keccak(callbackData) (the funding source), receiverIfMakerIsSeller, ratifier, reduceOnly, maxUnits, maxAssets and continuousFeeCap. Changing side, maker or rate fails with InvalidProof (new testSideMakerRateTampering). An internal node cannot pass as a leaf, since the leaf preimage is a 17-word EIP-712 struct and nodes are 64-byte keccak pairs. leafIndex >> proof.length == 0 is enforced.",
  "Taker: allowedTaker is checked against the taker passed by Midnight, and Midnight's take requires taker == msg.sender or authorization. The forceDeallocate front-running issue in the earlier taker design is TRST-L-1 and out of scope.",
  "Rate boundaries: ttm = zeroFloorSub(maturity, now). At or after maturity, buys need price <= WAD and sells need price >= WAD (fuzz testZeroTtmBoundaries). Over rate 0..1e12/s and ttm 1 s..365 d, rounding never accepts a buy above, or a sell below, the rate-implied price (fuzz testPriceBoundsConservative). Large rates overflow (lowInfo). Tick 0 and MAX_TICK (price WAD) were exercised. The adapter's onBuy separately rejects buys at or after maturity.",
  "Cancellation: unratifying a root makes isRatified revert NotRatified (existing testRevocationBlocksOffer). Sentinels can only unratify. setIsSubRatifier lets sentinels only disable. setConsumed is open to allocators and sentinels, and its interaction with the forceDeallocate group-0 offer was tested (lowInfo #3).",
  "MidnightAdapter.isRatified: the inForceDeallocate bypass is set only around the adapter's own take, and onBuy clears it before the token transfer. Gate, oracle and ratifier calls made inside take are view (STATICCALL), so nothing can re-enter take while the bypass is set.",
  "Prior audits read (text extracted from audits/2026-10-12-midnight-adapter-{cantina,trustsec}-draft.pdf). Already reported, so excluded: Cantina 3.2.2 (isRatified not bound to Midnight), 3.2.9 (offers naming another ratifier), 3.2.4 (tick-0 sells), 3.1.1 (ratifier price not independent of allocator); TrustSec TRST-R-5 (no nonce on direct setter), TRST-R-6 (signatures submitted by other authorized parties, delegation scope), TRST-R-12, TRST-SR-3 (simple interest), TRST-L-1, and the setConsumed NatSpec note."
 ],
 "notCovered": [
  "The full repository test suite (all 261 test files) was not run, because of compile time on this machine.",
  "No independent clean-clone re-run of the tests by a second agent.",
  "Gas or griefing limits of very deep proofs (height up to 256 in isLeaf, 20 in the typehash) were not measured.",
  "Non-standard loan tokens (hooks or fee-on-transfer) during the inForceDeallocate window were not examined.",
  "The sub-ratifier revival scenario (lowInfo #2) has no PoC."
 ]
}