{
 "angle": "Enter gates and whitelists (IKRCompatibleEnterGate, WhitelistEnterSubGate, both gate factories, the adapter's admit/unadmit flow during forceDeallocate and its enterGateFactory entry check): bypass, wrong caller, factory misconfiguration",
 "commit": "bbeda7b27ae80abcf070e0158cb8a31e87bb2286",
 "hasCandidates": false,
 "candidates": [],
 "summary": "No Medium/High (or Low with impact) finding survived on this angle. Admission cannot outlive its take, cannot be used by another account, and cannot be reached from attacker-controlled code. Signatures cannot be replayed across sides, gates or chains, or by a revoked whitelister. A fake-vault adapter does pass isCreated, but it cannot leak credit. The two informational items below have passing Foundry tests (test/poc/GatesInfo.t.sol, 3/3 PASS). These tests run against the pinned commit with src/ and lib/ unmodified, using real Midnight (deployed from its artifact) and the real gate and factory contracts. INFO-2 uses a minimal fake vault on purpose, because the fake parent vault is the subject of that test. The independent re-run from a clean clone (Step 4) was not done by this worker.",
 "lowInfo": [
  {
   "title": "A pending setIsWhitelistedWithSig signature cannot be cancelled by the direct setter, by revoking the whitelister role and later re-granting it, or by any explicit cancel function",
   "class": "Informational",
   "verified": true,
   "refs": [
    "src/adapters/midnight/gates/WhitelistEnterSubGate.sol:52-56",
    "src/adapters/midnight/gates/WhitelistEnterSubGate.sol:59-88",
    "src/adapters/midnight/gates/WhitelistEnterSubGate.sol:46-50"
   ],
   "detail": "Nonces are per (side, whitelister, account) and only setIsWhitelistedWithSig advances them (L76-80). setIsWhitelisted (L52-56) changes the list but leaves the nonce as it is. So a whitelister who signed (account, true, nonce n, deadline d) and then sets the account to false directly has not invalidated that signature: anyone holding it can whitelist the account again before d. Revoking the whitelister makes the signature fail with InvalidSigner (L75), but re-granting the role makes it valid again because there is no per-signer epoch. The only way to cancel is for the whitelister to use up nonce n with a second signature of their own (for example (account,false,n)). No function or NatSpec covers this. Impact: an account the whitelister meant to keep out can gain credit or debt entry rights until the deadline. This needs a whitelister signature, which is a trusted-role action, and the deadline bounds it, so it is Informational. PoC: testPendingSignatureSurvivesDirectRevokeAndRoleRegrant shows the old signature whitelisting the account 6 days later, after a direct revoke and a revoke/re-grant of the role (nonce goes 0 -> 1, gate.canIncreaseCredit(account) == true). testWhitelisterCanCancelByConsumingNonce shows the workaround. Command: forge test --match-path test/poc/GatesInfo.t.sol -vv (run from the vault-v2 root at the pinned commit). Output: No files changed, compilation skipped |  | Ran 3 tests for test/poc/GatesInfo.t.sol:GatesInfoTest | [PASS] testFakeVaultAdapterPassesIsCreatedButAdmissionIsTransient() (gas: 6614769) | Logs: |   outsider credit after attempts: 0 |  | [PASS] testPendingSignatureSurvivesDirectRevokeAndRoleRegrant() (gas: 278919) | Logs: |   nonce after replayed signature: 1 |  | [PASS] testWhitelisterCanCancelByConsumingNonce() (gas: 129091) | Suite result: ok. 3 passed; 0 failed; 0 skipped; finished in 4.88ms (3.01ms CPU time) |  | Ran 1 test suite in 21.26ms (4.88ms CPU time): 3 tests passed, 0 failed, 0 skipped (3 total tests) Suggested fix: make setIsWhitelisted increment nonces[side][msg.sender][account], or add invalidateNonce(side, account, newNonce), and document the role re-grant behaviour. The prior TrustSec report raised the analogous point for the ratifier's setIsRootRatified (TRST-R-5) but not for this subgate."
  },
  {
   "title": "MidnightAdapterFactory deploys adapters for any parentVault, so a registered admitter factory vouches for adapters with fake vaults; 'shareholder' admission then means any account",
   "class": "Informational",
   "verified": true,
   "refs": [
    "src/adapters/midnight/MidnightAdapterFactory.sol:29-41",
    "src/adapters/midnight/gates/IKRCompatibleEnterGate.sol:40-48",
    "src/adapters/midnight/MidnightAdapter.sol:427-463"
   ],
   "detail": "IKRCompatibleEnterGate.admit trusts any adapter for which a registered factory returns isCreated. MidnightAdapterFactory.createMidnightAdapter is permissionless and accepts any parentVault and any enterGateFactory. An attacker can therefore deploy an adapter whose 'vault' is their own contract and calls deallocate(..., forceDeallocate.selector, sender) with any sender/taker and any balanceOf. That adapter's call to admit(anyone) on a real IKR gate is accepted. The PoC (testFakeVaultAdapterPassesIsCreatedButAdmissionIsTransient) confirms this: isCreated(fakeAdapter) == true, and the gate emits Admit(fakeAdapter, outsider, factory) for an outsider with no real shares. It also confirms the impact is nil. The admission is cleared in onBuy before the call returns (canIncreaseCredit(outsider) == false right after). A non-zero sale reverts with MakerCreditOrDebtIncreased because the forceDeallocate offer is reduceOnly and the adapter holds no credit. Outsider credit stays 0. Remaining consequence (reasoned, not separately tested): if a whitelister whitelists such an adapter's address on the credit side, its credit can then pass to any account. Whitelisting a MidnightAdapter in effect whitelists every account its parentVault reports as a shareholder. Whitelisters should check that parentVault is a VaultV2 from VaultV2Factory. Cantina 3.6.3 item 7 already noted that the factory does not check parentVault, so this is a documentation point specific to gates. Command: forge test --match-path test/poc/GatesInfo.t.sol -vv."
  },
  {
   "title": "IKRCompatibleEnterGate takes an unverified subGate, and admitter-factory registration follows the subgate's credit-side roleSetter",
   "class": "Informational",
   "verified": false,
   "refs": [
    "src/adapters/midnight/gates/IKRCompatibleEnterGate.sol:22-35",
    "src/adapters/midnight/gates/IKRCompatibleEnterGateFactory.sol:12-21"
   ],
   "detail": "createIKRCompatibleEnterGate accepts any subGate address. It does not check WhitelistEnterSubGateFactory.isCreated. roleSetter() returns subGate.roleSetter(true), so whoever controls the subgate's credit role setter (or an arbitrary subgate contract) controls addAdmitterFactory, and registrations can never be removed. This does not block IKR: canIncreaseCredit short-circuits on the admitted account before calling the subgate (L56), and the adapter checks admitEnabled and admitterFactory(factory) before it first enters a market (MidnightAdapter.sol:565-571). The existing test testEnterGateShareholderExitBypassesRevertingSubGate covers a reverting subgate. Curators should still check the subGate of each gate. This was reviewed by reading the code, with no separate PoC."
  },
  {
   "title": "unadmit() is permissionless",
   "class": "Informational",
   "verified": false,
   "refs": [
    "src/adapters/midnight/gates/IKRCompatibleEnterGate.sol:50-53"
   ],
   "detail": "Anyone can clear the transient admission. In practice this cannot be used to block IKR: between admit (MidnightAdapter.sol:462) and Midnight's canIncreaseCredit check (lib/midnight/src/Midnight.sol:384-387) the only external calls go to Midnight and to the adapter itself (isRatified, which returns at once while inForceDeallocate is set). touchMarket and _updatePosition make no external calls, and the asset transferFrom runs before admit. No third party can run code in that window. This was reviewed by reading the code."
  }
 ],
 "covered": [
  "Build: cloned at the pinned commit with submodules. forge build succeeded, and forge test --match-contract 'Midnight|Gate|Whitelist|IKR' gave 14 suites with 526 tests passed and 0 failed.",
  "IKRCompatibleEnterGate.admit authorisation: needs admitEnabled, admitterFactory[f] and f.isCreated(msg.sender). The caller cannot pass someone else's factory to get past isCreated, because isCreated is checked against msg.sender.",
  "Admission lifetime: `admitted` is transient. The adapter calls admit only in deallocate(forceDeallocate) on market.enterGate, then calls Midnight.take with takerCallback=adapter. Midnight checks canIncreaseCredit before onBuy (Midnight.sol:384-387 vs 432-440), and onBuy unadmits before the token transfers. I traced every external call between admit and unadmit: none goes to attacker-controlled code (touchMarket and _updatePosition are pure storage, and the asset transferFrom runs before admit). On revert, transient storage is rolled back. The PoC confirms admission is false after the call.",
  "Admission used by another account: canIncreaseCredit compares against the single admitted address. The buyer in the adapter's sell offer is always `taker`, the same address that was admitted. The gate is shared across markets, but no other take can run inside the window.",
  "Adapter entry check (onBuy, first entry only, MidnightAdapter.sol:565-571): every way the adapter gains credit goes through onBuy (adapter take uses takerCallback=this, and isRatified requires offer.callback=this). The ratifier bypass under inForceDeallocate only applies to the adapter's own reduceOnly sell offer and is cleared in onBuy.",
  "IKR blocking: canIncreaseCredit short-circuits before the subgate; admitterFactory entries cannot be removed; admitEnabled is immutable; canIncreaseDebt is irrelevant because the sale is reduceOnly. Existing tests cover reverting subgates, revoked vault gates and an attacker-controlled gate.",
  "WhitelistEnterSubGate signatures: the domain includes chainId and verifyingContract (no replay across gates or chains), and the struct includes creditSide (no replay across sides). An ecrecover zero result and revoked whitelisters are rejected. A stale nonce can only repeat the current status (no state change). Malleable s values only allow a no-op replay. multicall uses delegatecall to self and is non-payable. Roles are separated per side.",
  "Factories: CREATE2 salt = keccak(preSalt, msg.sender), so a front-runner cannot squat on an address. Deploying the same salt twice reverts. isCreated is set only for contracts the factory itself deployed.",
  "Prior audits: I extracted the text of both 2026-10-12 drafts (Cantina, TrustSec) and checked them for gate, whitelist, admit and nonce items. Neither covers the IKR gate or subgate. TrustSec TRST-CR-1 describes whitelist gates blocking IKR, which the IKR gate now addresses. TRST-R-5 and R-6 concern the ratifier's signatures, and Cantina 3.6.3 item 7 concerns unverified parentVault."
 ],
 "notCovered": [
  "Step 4 independent re-run from a clean clone by a different agent: not done by this worker.",
  "No fuzz or invariant campaign was written for gates. I relied on the existing test/periphery/WhitelistEnterSubGateTest.sol, IKRCompatibleEnterGate*Test.sol and the MidnightAdapterTest enter-gate tests, which I ran but did not extend beyond the PoC file.",
  "The 2026-07-08 Blackthorn gates audit was not read: its text could not be extracted in the time available.",
  "Interactions with nested vaults or several MidnightAdapters sharing one IKR gate inside a single transaction were reviewed only by reasoning."
 ]
}