{
  "angle": "Interaction with Vault V2 roles, caps and allocation ids (MidnightAdapter allocate/deallocate/forceDeallocate, ids(), duration caps, durationAllocations, stored net credit vs vault allocation, adapter timelocks and role checks)",
  "commit": "bbeda7b27ae80abcf070e0158cb8a31e87bb2286",
  "hasCandidates": false,
  "status": "BLOCKED_PARTIAL: the brief's Step 1 (clone + forge build + test) and every PoC could not be executed. The bash sandbox on this machine has no outbound network: `git clone https://github.com/morpho-org/vault-v2` failed with `fatal: unable to access 'https://github.com/morpho-org/vault-v2/': Proxy CONNECT aborted`, and curl to github.com, raw.githubusercontent.com, registry.npmjs.org, www.google.com, gitlab.com returned HTTP 000 (Proxy CONNECT aborted). forge (/home/imd470/.foundry/bin/forge) and aderyn are installed; slither was not found. Source code was read only through a web-fetch tool that returns model-summarised excerpts of the pinned files, not a local checkout. Because the brief requires a Foundry PoC run against the pinned commit for any candidate, no candidate is reported; all observations below are UNVERIFIED (verified=false). The two prior audit drafts (audits/2026-10-12-midnight-adapter-cantina-draft.pdf, audits/2026-10-12-midnight-adapter-trustsec-draft.pdf) were downloaded but only as compressed PDF bytes; no PDF text extractor was available, so the prior-audit cross-check was NOT performed and any item below may duplicate a prior finding.",
  "candidates": [],
  "lowInfo": [
    {
      "title": "Family id and collateral-token id are not scoped to the adapter, so two Midnight adapters on the same vault (and Morpho Market V1 adapters on the collateral-token id) share caps, measured in different units",
      "class": "Informational",
      "verified": false,
      "refs": [
        "src/adapters/midnight/MidnightAdapter.sol: ids(Market) (VIEWS section)",
        "src/adapters/MorphoMarketV1AdapterV2.sol: ids(MarketParams)"
      ],
      "detail": "MidnightAdapter.ids() returns [adapterId = keccak256(abi.encode(\"this\", address(this))), keccak256(abi.encode(\"collateralParams/rcfThreshold/liquidatorGate/enterGate\", collateralParams, rcfThreshold, liquidatorGate, enterGate)), keccak256(abi.encode(\"collateralToken\", token)) for each collateral]. Only adapterId includes address(this). The family preimage has no \"this/\" prefix, while MorphoMarketV1AdapterV2 scopes its per-market id with keccak256(abi.encode(\"this/marketParams\", address(this), marketParams)). So: (a) if a vault uses two MidnightAdapters (e.g. different duration sets or enterGateFactory), both add to the same family cap; (b) the collateral-token id is shared with MorphoMarketV1AdapterV2 (same preimage \"collateralToken\", token), but Midnight adds face-value stored net credit while the Blue adapter adds supplied assets. This looks deliberate (vault-wide exposure per collateral). Still, curators should know that caps on these ids add up exposures across adapters in different units, and that face value overstates a Midnight position's present value before maturity. The README says caps limit stored net credit, not amortized net credit. Not a bypass: sharing makes caps stricter, not looser. UNVERIFIED: read from fetched source, no test run."
    },
    {
      "title": "Duration caps are enforced only by the adapter at buy time; the vault never records allocations for duration ids",
      "class": "Informational",
      "verified": false,
      "refs": [
        "src/adapters/midnight/MidnightAdapter.sol: onBuy duration-cap loop (durationId = keccak256(abi.encode(\"this/duration\", address(this), packedDurations.get(i))))",
        "src/adapters/midnight/MidnightAdapter.sol: durationAllocations(uint256)"
      ],
      "detail": "ids() never returns duration ids. The vault's caps[durationId].allocation therefore stays 0, and IVaultV2.allocation(durationId) does not show duration exposure. onBuy reads absoluteCap(durationId) and relativeCap(durationId) from the vault and compares them with durationAllocations(), which sums the adapter's stored netCredit over marketIds bucketed by stored maturity. Consequences, all consistent with the design as read: (1) only durations <= the bought market's ttm are checked (affectedDurationCount), and a buy with ttm < the smallest duration skips duration checks entirely; (2) as with vault caps, lowering a duration cap below the current exposure forces nothing and only blocks later buys that touch that duration; (3) a duration cap of 0 makes every buy whose ttm >= that duration revert (DurationZeroAbsoluteCap), so curators must set non-zero caps on all configured duration ids before the adapter can buy long-dated credit; (4) the relative duration check uses firstTotalAssets, matching the vault's own relative-cap semantics. I found no way for an allocator or a third party to raise duration exposure without passing through onBuy. Sales, withdrawals, forceDeallocate and forceRemove only lower stored netCredit. UNVERIFIED (no fuzz test run)."
    },
    {
      "title": "Vault allocation follows the adapter's stored net credit, which lags real credit after losses or continuous fees until someone calls deallocate with assets = 0",
      "class": "Informational",
      "verified": false,
      "refs": [
        "src/adapters/midnight/MidnightAdapter.sol: withdrawToVault (NatSpec: can be called with withdrawnAssets == 0 to synchronize marketData after a loss)",
        "src/adapters/midnight/MidnightAdapter.sol: deallocate forceDeallocate branch, onBuy, forceRemove"
      ],
      "detail": "Every path returns change = currentNetCredit(marketId) - marketData[marketId].netCredit and then stores the new value. So for each id, the vault's allocation equals the sum of stored netCredit over the markets that map to it, provided ids(market) is deterministic, which it is: it depends only on the Market struct and adapterId, and forceRemove rebuilds the struct with Midnight.toMarket. Between syncs, Midnight bad debt (lossFactor) or pending continuous fees lower real credit while stored netCredit and the vault allocation stay higher. This over-counts against caps, which is conservative: it can block buys but cannot bypass a cap. The next operation on the market, including a permissionless forceDeallocate, realises the drift in one change. A sync needs an allocator or sentinel calling vault.deallocate(adapter, abi.encode(market), 0). This matches the documented intent. I found no path where stored netCredit rises above the vault allocation, or where a market with non-zero stored netCredit leaves marketIds (onBuy pushes when old==0 && new>0 and removes when new==0 && old>0; withdrawToVault and forceDeallocate remove when new==0 && old>0; forceRemove zeroes and removes). UNVERIFIED."
    },
    {
      "title": "Allocator role held by the adapter extends deallocation power to sub-ratifiers and to takers of ratified maker buy offers (via callback funding data)",
      "class": "Informational",
      "verified": false,
      "refs": [
        "src/adapters/midnight/MidnightAdapter.sol: onBuy funding branch (abi.decode(data, (address, bytes)) then IVaultV2(parentVault).deallocate(fundingAdapter, fundingData, buyerAssets))",
        "src/adapters/midnight/README.md: allocator requirement"
      ],
      "detail": "The README requires the adapter to hold the vault allocator role. In onBuy, (fundingAdapter, fundingData) comes from the callback data. When the adapter is the taker, the allocator supplies it through take(). When the adapter is a maker, it comes from the offer's callbackData, which a sub-ratifier approved and which anyone may then take on Midnight. The adapter then calls vault.deallocate(fundingAdapter, fundingData, buyerAssets) as an allocator, against any adapter of the vault. Sub-ratifiers are set by allocators (setIsSubRatifier), so this stays within the trusted role model. Still, a sub-ratifier, or an offer it approves, can choose which adapter of the vault gets drained to fund a buy, and when the buy happens is up to the taker. Caps (vault ids and duration ids) are checked when the offer is taken, not when it is approved. multicall uses delegatecall to address(this) and the adapter makes only hard-coded vault calls, so I found no path that lets an untrusted caller use the adapter's allocator role for other vault functions such as setLiquidityAdapterAndData. Trusted-role behaviour, so informational only. UNVERIFIED."
    },
    {
      "title": "forceRemove (timelocked, executable by anyone once the timelock ends) and adapter-initiated sales depend on the adapter keeping the vault allocator (or sentinel) role",
      "class": "Informational",
      "verified": false,
      "refs": [
        "src/adapters/midnight/MidnightAdapter.sol: forceRemove (IVaultV2(parentVault).deallocate(address(this), abi.encode(ids(market), -int256(oldNetCredit)), 0))",
        "src/VaultV2.sol: deallocate role check (isAllocator[msg.sender] || isSentinel[msg.sender])"
      ],
      "detail": "timelocked() checks only executableAt, the timelock expiry and abdicated, not the caller, as in Vault V2. So once its timelock passes, anyone can execute a submitted forceRemove. Its vault.deallocate call (and the sell-callback deallocation) only succeeds while the adapter is an allocator or sentinel of the vault. If the role is revoked, forceRemove of a market with stored netCredit > 0 reverts, while allocator- or sentinel-driven withdrawToVault through vault.deallocate keeps working. The README states this requirement, so this is a configuration note, not a bug. UNVERIFIED."
    },
    {
      "title": "Only the adapter itself can raise vault allocations; non-vault callers cannot reach allocate or deallocate",
      "class": "Informational",
      "verified": false,
      "refs": [
        "src/adapters/midnight/MidnightAdapter.sol: allocate (require(msg.sender == parentVault); require(sender == address(this), SelfAllocationOnly()); returnExactBytes(data))",
        "src/adapters/midnight/MidnightAdapter.sol: deallocate (selector/sender dispatch)"
      ],
      "detail": "Negative result, recorded as coverage. allocate is view, requires msg.sender == parentVault and sender == address(this), and echoes data. Any other allocator calling vault.allocate(midnightAdapter, ...) reverts, so allocation increases only come from onBuy, which applies the buy checks and duration caps first. deallocate requires msg.sender == parentVault and dispatches on the selector the vault passes (msg.sig). (a) forceDeallocate.selector: permissionless sale to a taker who is the sender or authorised by the taker on Midnight, and who holds vault shares. (b) sender != adapter: withdrawToVault(abi.decode(data, (Market))), reachable only by vault allocators or sentinels. (c) sender == adapter: echo, reachable only from the adapter's own vault.deallocate calls. Those use data it built itself (self-funded onBuy, forceRemove) or a fundingAdapter other than itself; fundingAdapter == address(this) is routed through withdrawToVault. I found no way for an outside caller to make the vault call deallocate with sender == adapter and caller-chosen bytes. Midnight requires strictly increasing collateral tokens at market creation (CollateralParamsNotSorted), so ids() cannot contain the same collateral-token id twice. UNVERIFIED (no test run)."
    },
    {
      "title": "Adapter timelock system mirrors Vault V2; no role or timelock bypass found",
      "class": "Informational",
      "verified": false,
      "refs": [
        "src/adapters/midnight/MidnightAdapter.sol: submit, timelocked, revoke, increaseTimelock, decreaseTimelock, abdicate, multicall"
      ],
      "detail": "Negative result. submit is curator-only, limits data to 68 bytes, and refuses data already pending. For decreaseTimelock it applies the target selector's timelock (data[4:8]); submit reverts if data is shorter than 8 bytes. revoke is curator or sentinel. Timelocked functions (increase/decreaseTimelock, abdicate, increaseMaxTtm, setForceSellable, setSkimRecipient, decreaseMinNetBuyRate, increaseShortfallAllowance, increaseMaxNetSellRate, forceRemove) consume executableAt[msg.data]. multicall delegatecalls into self, so msg.sender and the inner msg.data are preserved and timelocked() matches the inner calldata. A non-canonical calldata variant of a submitted operation would need dirty padding, which the ABI v2 decoder rejects, so revoke cannot be dodged that way. Immediate tightening setters (increaseMinNetBuyRate, decreaseShortfallAllowance, decreaseMaxNetSellRate, setMinForceSellPrice: curator; decreaseMaxTtm, unsetForceSellable: curator or sentinel) match the README. setMinForceSellPrice is immediate in both directions; the README states this. As in Vault V2, timelock[abdicate.selector] and other timelocks start at 0 until the curator raises them (trusted-role behaviour). UNVERIFIED."
    }
  ],
  "covered": [
    "Read (via web fetch of the pinned commit, not a local checkout) MidnightAdapter.sol: state, constructor, multicall, submit/timelocked/revoke/increaseTimelock/decreaseTimelock/abdicate, role helpers isCurator/isSentinel/isAllocator and their call sites, allocate, deallocate (forceDeallocate / allocator-sentinel / self branches), onBuy (buy checks, market list update, accrueInterest, funding deallocation, duration absolute and relative caps, final vault.allocate), withdrawToVault, forceRemove, ids(), durationAllocations().",
    "Read src/adapters/midnight/README.md for roles, caps, timelocks and accepted risks.",
    "Read VaultV2.sol cap semantics: caps are checked on allocate for every returned id (ZeroAbsoluteCap, AbsoluteCapExceeded, relative cap vs firstTotalAssets, WAD = no relative cap), deallocate requires allocation > 0 per id and checks no caps, forceDeallocate is permissionless with a penalty taken from onBehalf with an allowance check, allocate is allocator-only and deallocate is allocator or sentinel.",
    "Compared id preimages with MorphoMarketV1AdapterV2.ids().",
    "Checked Midnight (lib/midnight @ 4e2570e51171d09228645b2d5bdf84ef24b1720b) for collateral-token uniqueness (strictly increasing), credit transfers without consent (none found: credit moves only through take with taker authorisation and ratified maker offers), take parameters and callback order, and withdraw authorisation.",
    "Traced by hand that the vault allocation per id equals the sum of stored netCredit over the markets that map to it, the marketIds add/remove conditions, and the duration bucket logic (durations <= ttm are counted, consistently between durationAllocations and onBuy's affectedDurationCount)."
  ],
  "notCovered": [
    "Step 1 build/test: not executed. The bash sandbox has no network ('Proxy CONNECT aborted' for github.com and every other host tried), so the repo and submodules could not be cloned and forge build / forge test were never run.",
    "No PoC, fuzz or invariant test was written or run, so every item above is UNVERIFIED. Slither was not found on the machine; Aderyn was not run because there was no checkout.",
    "Prior-audit cross-check: both 2026-10-12 Midnight adapter drafts (Cantina, TrustSec) were fetched as compressed PDF bytes only; no PDF text extractor was available, so findings were not compared with them.",
    "onSell (sale callback deallocation and shortfall accounting), realAssets during in-progress buys, the take() entry point in full, and the forceDeallocate token flow (who pays Midnight for the taker's credit and whether the vault pulls exactly `assets`) were read only as summaries, not line by line.",
    "Exact line numbers: files were read through a summarising fetch tool, so refs give function names instead of line numbers.",
    "Gates, ratifiers, PackedDurationsLib internals and factory deployment belong to other items in this batch and were not reviewed here."
  ]
}
