{"angle": "factory deployment: address prediction and duplicates", "commit": "bbeda7b27ae80abcf070e0158cb8a31e87bb2286", "hasCandidates": false, "candidates": [], "lowInfo": [{"title": "Anyone can mint factory-registered adapters bound to an arbitrary (attacker-controlled) parentVault; IKRCompatibleEnterGate.admit trusts only factory.isCreated", "class": "Informational", "verified": true, "refs": ["src/adapters/midnight/MidnightAdapterFactory.sol:24-36", "src/adapters/midnight/MidnightAdapter.sol:152-171", "src/adapters/midnight/gates/IKRCompatibleEnterGate.sol:41-49"], "detail": "createMidnightAdapter is permissionless and the constructor only calls parentVault.asset(); parentVault and enterGateFactory are not validated. isCreated therefore means 'deployed by this factory', not 'adapter of a vetted vault'. IKRCompatibleEnterGate.admit(user, factory) accepts any such adapter once the roleSetter has registered the factory. A rogue adapter whose parentVault is a fake contract (balanceOf>0, asset=loan token) passes isCreated and its admit() call is accepted for a non-whitelisted user (PoC test testRogueAdapterPassesIsCreatedAndAdmitsArbitraryUser, verified: isCreated true, admit accepted via Admit event). The adapter's TakerHasNoShares check is then run against the attacker's own vault. I could NOT turn this into a loss: admission is transient and cleared in the adapter's onBuy, the rogue adapter holds no credit to sell (reduceOnly offer) and cannot acquire credit in a gated market without being whitelisted; end-to-end rogue.deallocate reverted (0x96e13529, not decoded). README states registered factories are trusted on isCreated for adapters 'they deployed' and 'their adapters must behave correctly', so this is largely documented trust. Suggested hardening: document that registering a factory admits adapters on any parentVault, or have admit/adapter check a vault registry. Output: [PASS] testNoSquattingAndDuplicateBlocked() Logs: predicted == deployed, duplicate reverts; salt not squattable | [PASS] testRogueAdapterPassesIsCreatedAndAdmitsArbitraryUser() Logs: factory.isCreated(rogue): true; rogue.parentVault == attacker fake vault: true; gate.admit(attacker) from rogue adapter: accepted; fake vault -> rogue.deallocate ok: false 0x96e13529"}, {"title": "Salt binds (preSalt, msg.sender) and initcode hash binds constructor args: no squatting or colliding with other parameters; identical redeploy reverts", "class": "Informational", "verified": true, "refs": ["src/adapters/midnight/MidnightAdapterFactory.sol:28-36", "src/adapters/midnight/gates/IKRCompatibleEnterGateFactory.sol:11-19", "src/adapters/midnight/gates/WhitelistEnterSubGateFactory.sol:11-28"], "detail": "All three factories use CREATE2 with salt=keccak256(abi.encode(preSalt,msg.sender)). Test testNoSquattingAndDuplicateBlocked: an attacker using the same preSalt (other sender, or other durations) lands on different addresses; the victim's address equals the off-chain CREATE2 prediction; a second identical call by the same sender reverts (expected CREATE2 collision, only self-inflicted). No finding. Note a contract sender (bundler/multisig) shares the salt namespace across its users, as the NatSpec already says."}, {"title": "MidnightAdapterFactory runtime size is 23,682 bytes (894 bytes of margin to 24,576); adapter runtime 21,619 bytes", "class": "Informational", "verified": true, "refs": ["src/adapters/midnight/MidnightAdapterFactory.sol:24-36"], "detail": "forge build --sizes (cancun, via_ir, runs 100000): MidnightAdapterFactory runtime 23,682 / initcode 23,854 (limits 24,576 / 49,152); MidnightAdapter runtime 21,619 / initcode 22,937. Both deploy today (tests pass), but the factory embeds the adapter initcode, so future adapter growth of ~900 bytes would make the factory undeployable on chains with the EIP-170 limit. Not exploitable; maintenance risk."}, {"title": "Constructors accept degenerate arguments (empty durations, zero enterGateFactory, subGate/role setters of address(0), non-contract subGate)", "class": "Informational", "verified": false, "refs": ["src/adapters/midnight/MidnightAdapter.sol:152-171", "src/adapters/midnight/gates/IKRCompatibleEnterGate.sol:20-23", "src/adapters/midnight/gates/WhitelistEnterSubGate.sol:34-40"], "detail": "By code reading only (UNVERIFIED, no test): empty durations give an adapter that cannot trade; IKRCompatibleEnterGate with a non-contract subGate makes canIncreaseCredit/Debt revert for every market using it (gate bricked, deployer-only impact); WhitelistEnterSubGate with role setter address(0) makes that side's whitelist permanently unmanageable unless open. All are deployer self-inflicted and each address is unique per deployer, so no third-party impact found."}], "covered": "Cloned vault-v2 at the pinned commit, built with Foundry (full build succeeded; existing tests inherited by my PoC contract passed: testMakerBuy, testTakerBuy/Sell, testMakerSell, testForceSell, testForceDeallocate, testRepayWithdrawRedeem, testWrapperGateForceDeallocateAfterRevocation). Read the three factories, both gates, adapter constructor and admit path. Checked CREATE2 salt derivation and prediction, front-run/squat with other params, duplicate deployment, isCreated trust in IKRCompatibleEnterGate.admit and the adapter's isCreated(enterGate) check, constructor validation, and bytecode/initcode sizes via forge build --sizes. Compared against README accepted-risk text.", "notCovered": "The two prior audit PDFs in audits/ were not read (no PDF text extracted in time), so any overlap with them is unchecked. Full test suite not run beyond the inherited integration tests. The 0x96e13529 revert from the rogue-adapter path was not decoded; no end-to-end exploit of the rogue adapter was achieved. Other angles (accounting, ratifiers, durations, reentrancy) not reviewed. Not tested on forks or other chains (CREATE2 cross-chain address reuse)."}