{
 "angle": "fuzz",
 "commit": "bbeda7b27ae80abcf070e0158cb8a31e87bb2286",
 "anySurvives": true,
 "summary": "One candidate (FUZZ-1). It was re-run from a fresh clone at the pinned commit with the PoC byte-identical and Foundry 1.8.5. As written it fails in setUp ('vm.getCode: no matching artifact found') until the src and Midnight artifacts are built; after `forge build src lib/midnight/src/Midnight.sol` both tests pass, with gas and logs identical to the original report. Six extra refutation tests against the real WhitelistEnterSubGate bound the issue: it needs an unused, unexpired signature from a current whitelister. Consumed signatures, expired signatures, future nonces and a removed signer all revert. Neither prior draft has it for the gate, and the gates were outside both prior scopes. TrustSec R-5 is the same pattern in the ratifiers. Verdict: survives as Low (Informational plausible); no fund loss.",
 "checks": [
  {
   "id": "FUZZ-1",
   "title": "WhitelistEnterSubGate: a direct setIsWhitelisted revocation does not invalidate outstanding setIsWhitelistedWithSig signatures, and anyone can submit them, so a revoked account can whitelist itself again until the signature's deadline",
   "reran": true,
   "command": "git clone https://github.com/morpho-org/vault-v2 && cd vault-v2 && git checkout bbeda7b27ae80abcf070e0158cb8a31e87bb2286 && git submodule update --init --recursive && (write poc.source unchanged to test/poc/WhitelistSigSurvivesRevocation.t.sol) && forge build src lib/midnight/src/Midnight.sol && forge test --match-path test/poc/WhitelistSigSurvivesRevocation.t.sol --match-test \"PoC|Cancellation\" -vv",
   "output": "[first attempt, fresh clone, PoC file only, no prior build]\nCompiler run successful!\n\nRan 1 test for test/poc/WhitelistSigSurvivesRevocation.t.sol:WhitelistSigSurvivesRevocationTest\n[FAIL: vm.getCode: no matching artifact found] setUp() (gas: 0)\nSuite result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 20.21ms (0.00ns CPU time)\n\n[after `forge build src lib/midnight/src/Midnight.sol`, same test command, Foundry 1.8.5]\nCompiling 1 files with Solc 0.8.37\nCompiling 32 files with Solc 0.8.37\nSolc 0.8.37 finished in 51.69ms\nCompiling 51 files with Solc 0.8.37\nSolc 0.8.37 finished in 4.92s\nCompiling 76 files with Solc 0.8.28\nSolc 0.8.28 finished in 65.53s\nCompiling 173 files with Solc 0.8.28\nSolc 0.8.28 finished in 91.99s\nSolc 0.8.37 finished in 351.69s\nCompiler run successful!\n\nRan 2 tests for test/poc/WhitelistSigSurvivesRevocation.t.sol:WhitelistSigSurvivesRevocationTest\n[PASS] testCancellationRequiresCounterSignature() (gas: 26734823)\n[PASS] testPoCWhitelistSigSurvivesDirectRevocation() (gas: 29008084)\nLogs:\n  revoked borrower debt (units): 1000000000000000000\n  vault assets lent to revoked borrower: 1000000000000000000\n  adapter net credit: 1000000000000000000\n\nSuite result: ok. 2 passed; 0 failed; 0 skipped; finished in 73.09ms (63.50ms CPU time)\n\nRan 1 test suite in 77.48ms (73.09ms CPU time): 2 tests passed, 0 failed, 0 skipped (2 total tests)",
   "passes": true,
   "repairDiff": "",
   "repairNote": "No source change. The poc.command as written fails in a fresh clone in setUp() with 'vm.getCode: no matching artifact found', because --match-path compiles only the files the test imports, and MidnightAdapterTest.setUp deploys Midnight with deployCode(\"Midnight.sol:Midnight\") (test/MidnightAdapterTest.sol:220) and VaultV2 from out/ artifacts (lines 4301, 6338). Building those artifacts first (`forge build src lib/midnight/src/Midnight.sol`) fixes it. The test file is byte-identical to poc.source. The gas figures (26734823 and 29008084) match the original report exactly.",
   "refutationAttempts": [
    {
     "what": "Does the PoC edit src/ or lib/, or mock Midnight or Vault V2?",
     "result": "No. `git status` in the clone shows only the untracked test/poc/ directory. It uses the real Midnight (artifact via deployCode), the real VaultV2 (out/VaultV2.sol artifact), the real WhitelistEnterSubGate (deployCode ...:default), the real IKRCompatibleEnterGateFactory and the real MidnightAdapterFactory. The loan token is an 18-decimal test token (test/MidnightAdapterTest.sol:226)."
    },
    {
     "what": "Does the attacker get powers from cheatcodes or trusted roles?",
     "result": "No. Trusted roles (roleSetter and whitelisters = the test contract, plus vm.prank of the wrapper roleSetter) act only in setup and in the good-faith revocation. The two attacker steps, setIsWhitelistedWithSig and take, run under vm.prank(taker), an unprivileged account. setIsWhitelistedWithSig (WhitelistEnterSubGate.sol:59-87) has no msg.sender check, so the account can submit by itself. vm.sign uses a key that the test creates for the whitelister, which stands for a signature the whitelister really handed out."
    },
    {
     "what": "Precondition: a signature that was already consumed, then a direct revocation (testUsedSigCannotReAdmit)",
     "result": "Replay reverts with WhitelistedStatusChanged; debtIncreaseAllowed stays false. The impact needs an UNUSED signature (nonce == stored nonce) that is still unexpired. A consumed onboarding signature does not undo a revocation."
    },
    {
     "what": "Mitigation: the roleSetter removes the signing whitelister (testRemovingSignerKillsSig)",
     "result": "Submission reverts InvalidSigner. Removing the signer is an effective but blunt cancellation: it kills every outstanding signature from that whitelister for every account."
    },
    {
     "what": "Deadline bound (testExpiredSigRejected)",
     "result": "After warp to deadline+1, submission reverts DeadlineExpired. The window lasts until the signed deadline, which the whitelister chooses and the contract does not cap."
    },
    {
     "what": "Varying parameters: credit side, signer revokes itself, unrelated third party submits, 365-day deadline used on day 364 (testCreditSideSignerSelfRevokeThirdPartySubmit)",
     "result": "Holds. creditIncreaseAllowed goes false -> true when an arbitrary address submits on day 364. So it holds on both sides, even when the signer itself revoked, with any submitter."
    },
    {
     "what": "Pre-signing future nonces to stockpile re-admissions (testFutureNonceRejected)",
     "result": "A signature with nonce 1 while the stored nonce is 0 reverts InvalidNonce. Each whitelister gives at most one re-admission per account, through its single current-nonce signature."
    },
    {
     "what": "Multiple whitelisters (testTwoSignersTwoReAdmissions)",
     "result": "Nonces are per whitelister, so unused signatures from two whitelisters undo two successive direct revocations (the first signature, once used, can no longer be replayed). The exposure grows with the number of whitelisters that have outstanding signatures."
    },
    {
     "what": "Is the measured effect a real loss?",
     "result": "No fund loss. In the PoC the revoked borrower borrows 1e18 from the adapter's buy offer against collateral (0.5e18 + 0.5e18 supplied by taker in makeEnterGateBuyOffer). The vault holds normal collateralized credit, and net credit is 1e18. The effect is an access-control bypass: the gate's revocation does not take effect for that account until the signature deadline. The loan size depends on the adapter offer and caps, not on the bug."
    },
    {
     "what": "Is the behaviour documented or intended?",
     "result": "Partly. src/adapters/midnight/README.md:174-175 says whitelisters edit lists 'directly with `setIsWhitelisted` or ... by EIP-712 signatures' and that `setIsWhitelistedWithSig` 'accepts a stale nonce when the account is already set to the signed value. The signature must still be unexpired and from a current whitelister.' That gives the validity conditions, unexpired and current whitelister, which an unused signature still meets after a direct revocation. It does NOT say that a direct setIsWhitelisted leaves outstanding signatures valid, and it lists no cancel mechanism. The NatSpec at WhitelistEnterSubGate.sol:58 says signatures exist to be batched with the take by a third party, which confirms permissionless submission is intended. Nothing in lib/midnight docs covers this gate."
    }
   ],
   "extraTests": {
    "path": "test/poc/WhitelistSigRefute.t.sol (standalone: forge-std Test + real WhitelistEnterSubGate via `new`, no mocks)",
    "command": "forge test --match-path test/poc/WhitelistSigRefute.t.sol -vv",
    "output": "Ran 6 tests for test/poc/WhitelistSigRefute.t.sol:WhitelistSigRefuteTest\n[PASS] testCreditSideSignerSelfRevokeThirdPartySubmit() (gas: 379049)\nLogs:\n  credit-side re-admitted after days: 364\n\n[PASS] testExpiredSigRejected() (gas: 307842)\n[PASS] testFutureNonceRejected() (gas: 286322)\n[PASS] testRemovingSignerKillsSig() (gas: 340880)\n[PASS] testTwoSignersTwoReAdmissions() (gas: 568593)\n[PASS] testUsedSigCannotReAdmit() (gas: 398021)\nSuite result: ok. 6 passed; 0 failed; 0 skipped; finished in 43.61ms (52.26ms CPU time)"
   },
   "inPriorAudits": false,
   "priorAuditRef": "Not reported for WhitelistEnterSubGate in either draft. No gate contract is in scope of either: TrustSec draft scope, PDF p.6, commit 6476e9d9, 9 adapter/ratifier/factory files; Cantina draft scope, PDF p.4. The same root-cause PATTERN is TrustSec TRST-R-5 (PDF p.18, printed p.17): 'setIsRootRatified() does not increment rootNonce. A signature for setIsRootRatifiedWithSig() that was created before a root was unratified with setIsRootRatified() therefore remains valid and can ratify the root again.' That is a recommendation without severity, about the ratifiers only. TrustSec TRST-CR-1 (PDF p.25) notes depositors must trust the gate's controller, because 'The gate's whitelist can change at any time'. The Cantina draft has nothing on whitelists, nonces or signatures.",
   "outOfScope": false,
   "why": "WhitelistEnterSubGate.sol is in the listed scope (gates/). It is not a prior-audit duplicate for this contract, because the gates were not in either prior scope, and it is not listed as an accepted risk. A judge may still treat it as a known pattern (TRST-R-5) or as an operational/design matter of trusted whitelisters (Cantina caps 'Protocol design-related issues' and admin errors at Informational). The revoking whitelister acts in good faith; the bypass is done by the untrusted revoked account.",
   "verdict": "survives",
   "severity": "Low",
   "severityReasoning": "Cantina matrix: impact Medium ('non-core functionality failures'). A revocation in a peripheral subgate is ineffective for one account until the signature deadline, with no risk to vault assets: the borrowing is collateralized and the PoC shows no loss. Likelihood Low ('Requires rare conditions'): it needs an unused, unexpired signature from a current whitelister AND a revocation through the direct setter instead of a counter-signature or signer removal. Medium x Low = Low. Downgrade risk: the effect is close to 'Issues without risk to assets' (Low impact), and the remedies (counter-sign, remove whitelister, short deadlines) are in the whitelisters' hands, so Informational is plausible. Not Medium: no loss, no lock, and it is bounded by the deadline and by one re-admission per whitelister per account.",
   "affected": [
    "src/adapters/midnight/gates/WhitelistEnterSubGate.sol:52-56 (setIsWhitelisted writes status, no nonce change)",
    "src/adapters/midnight/gates/WhitelistEnterSubGate.sol:59-87 (setIsWhitelistedWithSig: no msg.sender restriction; lines 76-80 apply the signature when nonce == stored per-whitelister nonce, regardless of status changes made by the direct setter)",
    "src/adapters/midnight/gates/IKRCompatibleEnterGate.sol:56,60 (the wrapper defers creditIncreaseAllowed/debtIncreaseAllowed to the subgate)",
    "src/adapters/midnight/README.md:174-175 (documents validity conditions; silent on direct-setter interaction)"
   ],
   "notes": "The write-up must: (1) say the poc.command needs the artifacts built first (`forge build src lib/midnight/src/Midnight.sol`, or a full `forge build`), because it fails in a fresh clone with 'vm.getCode: no matching artifact found'; (2) state the precondition precisely: the signature must be UNUSED (a consumed signature reverts WhitelistedStatusChanged on replay), unexpired, and from a still-current whitelister; (3) present the impact as an access-control bypass with no fund loss (collateralized 1e18 borrow), not as theft; (4) name the existing mitigations: a counter-signature with the same nonce (testCancellationRequiresCounterSignature), removing the signer via setIsWhitelister (blunt, kills all its signatures), short deadlines; (5) cite TRST-R-5 as the same pattern in the ratifiers and argue that it is distinct (different contract, outside the prior scope, and permissionless submission so the revoked account can self-submit), but warn that it may be judged a known pattern or Informational; (6) quote README.md:175, which documents that signatures stay valid while 'unexpired and from a current whitelister'. Suggested fix stands: bump a per-(side, account) epoch included in the signed struct on every status change, or add an invalidateNonce(creditSide, account, newNonce) for whitelisters, or at least document that direct revocation does not cancel outstanding signatures."
  }
 ],
 "notChecked": [
  "The 12 stateless fuzz properties in the input's fuzzSuite were not re-run: they are not candidates, the source was not reproduced, and compile time per run was about 6-7 minutes on this machine. The lowInfo items were not re-verified."
 ]
}