# CREATE2 address collision during pool deployment allows for complete draining of the pool

User-controlled CREATE2 salt in PanopticFactory.deployNewPool lets an attacker pre-collide a pool address, pre-approve tokens via selfdestruct, then drain the deployed pool.

- Payout: Audit contest
- Severity: medium
- Program: Panoptic
- Found by: Kalogerone
- Disclosed: 2024-06-24
- Write-up quality: 7/10
- Original: https://github.com/code-423n4/2024-04-panoptic-findings/issues/482
- Library page: https://bugbountylibrary.com/r/c4%3A2024-04-panoptic%3AM-03
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:medium tech:evm tech:solidity technique:chained technique:source-review vuln:accounting-error vuln:business-logic

**Target:** PanopticFactory.deployNewPool / Clones.cloneDeterministic
**Root cause:** deployNewPool passes a fully user-supplied salt to cloneDeterministic, so the resulting pool address is predictable and attacker-influenceable, enabling a CREATE2 address collision with an attacker contract.
**Steps:**
1. Brute-force many salts to enumerate undeployed PanopticPool addresses; store in Bloom filter (meet-in-the-middle, ~2^80).
2. Brute-force attacker contract CREATE2 preimages to collide with one stored pool address `0xCOLLIDED`.
3. Tx1: deploy attack contract at `0xCOLLIDED`, set infinite allowance `0xCOLLIDED -> attacker` for target tokens, `selfdestruct` — all in one tx (EIP-6780 allows same-tx selfdestruct).
4. Tx2: call `deployNewPool(token0, token1, fee, salt)` so the pool deploys at `0xCOLLIDED`.
5. Wait for deposits, then transferFrom the pool's tokens using the pre-set allowance.
**How found:** Reading deployNewPool showed the salt is user-supplied and passed to cloneDeterministic, making pool addresses deterministic and attacker-selectable; combined with EIP-3607/EIP-6780 reasoning about CREATE2 collisions and same-tx selfdestruct to persist allowance state.
**Exploitation:** Attacker pre-computes a salt whose cloneDeterministic address equals an attacker-controlled CREATE2 address. In one tx they deploy a contract there, grant infinite allowance to their wallet, and selfdestruct, leaving allowance state with no code. Later they trigger deployNewPool with that salt so the PanopticPool lands on the same address; the lingering allowance lets them pull all pool tokens once deposits arrive.
**Escalation:** Attacker can target any pool by choosing the salt and wait until the pool accumulates sufficient deposits before draining.
**Insight:** When a factory lets users choose the CREATE2 salt, the deployed address is attacker-predictable; check whether pre-deployment state (allowances, approvals) can be planted at that address via deploy+selfdestruct in one tx, then harvested after the legitimate contract lands there.

## Proof of concept (copied exactly from the original report)

**CREATE2 salt passed to cloneDeterministic**

```
newPoolContract = PanopticPool(POOL_REFERENCE.cloneDeterministic(salt));

        .
        .
        .
    }

    function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) {
        /// @solidity memory-safe-assembly
        assembly {
            // Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes
            // of the `implementation` address with the bytecode before the address.
            mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))
            // Packs the remaining 17 bytes of `implementation` with the bytecode after the address.
            mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3))
@>          instance := create2(0, 0x09, 0x37, salt)
```

**PoC contract deploy and selfdestruct same tx**

```
Paste the following file onto Remix (or a developing environment of choice): [POC](https://gist.github.com/midori-fuse/087aa3248da114a0712757348fcce814)
*   Deploy the contract `Test`.
*   Run the function `Test.test()` with a salt of your choice, and record the returned address. The result will be:
    *   `Test.getAllowance()` for that address will return exactly APPROVE_AMOUNT.
    *   `Test.getCodeSize()` for that address will return exactly zero.
    *   This proves the second property.
*   Using the same salt in step 3, run Test.test() again. The tx will go through, and the result will be:
    *   `Test.test()` returns the same address as with the first run.
    *   `Test.getAllowance()` for that address will return twice of APPROVE_AMOUNT.
    *   `Test.getCodeSize()` for that address will still return zero.
    *   This proves the first property.
```

