<!-- canonical: https://0xsimao.com/findings/codeup-erc20-forever-creating-uniswap -->

# `Codeup::claimCodeupERC20()` may be forever DoSed by creating the `Uniswap` pool before it is called

Crit/High · Three Sigma · DeFi game · 23rd October, 2024

Finding H-4 of the CODEUP security review.

- Report: /reports/codeup
- Source: https://cdn.sanity.io/files/qoqld077/staging/d9e57830a75b5165fd56e8b88037de7986a165ec.pdf

---

### Description

`Uniswap` pools may be created without the underlying tokens existence, which means that someone may do this before `Codeup::claimCodeupERC20()` is ever called, making it revert when `UniswapV2Factory::createPair()` is called as the pool has already been created.

### Recommendation

`UniswapV2Router::addLiquidity()` creates the pool if it does not yet exist, so there is not need to directly created it. The only concern is setting the `uniswapV2Pool` variable, which may be performed for example by doing:
```solidity
if (uniswapV2Pool == address(0)) {
    uint256 maxFirstLiquidity = MAX_FIRST_LIQUIDITY_AMOUNT;
    uint256 firstLiquidity = wethBalance > maxFirstLiquidity
        ? maxFirstLiquidity
        : wethBalance;

    _addLiquidity(
        routerMemory,
        wethMemory,
        codeupERC20Memory,
        firstLiquidity,
        FIRST_LIQUIDITY_GAME_TOKEN,
        0,
        0,
        currentContract
    );
    
    uniswapV2Pool = IUniswapV2Factory(uniswapV2Factory).getPair(
        wethMemory,
        codeupERC20Memory
    );

    emit PoolCreated(uniswapV2Pool);
} else {
```

---

Related findings:

- [fundLoan() can be DoSed if returnFunds() is called before it.](https://0xsimao.com/findings/maple-finance-iii-fund-sed-return-called): Maple Finance
- [Liquidator will leave a pool with unassigned earnings on `Market::clearBadDebt()` free to claim for anyone when the repaid maturity is not the last](https://0xsimao.com/findings/exactly-protocol-update-staking-contract-ii-liquidator-clear-debt-repaid): Exactly Protocol Update - Staking Contract
- [Uniswap v4 pool initialization can be frontrunned, setting an arbitrary price, and stealing tokens](https://0xsimao.com/findings/spirit-protocol-uniswap-initialization-frontrunned-price): Spirit Protocol
- [ERC20AssetPool and ERC721AssetPool should have the nonReentrant modifier as ERC721 and some tokens have callbacks](https://0xsimao.com/findings/singularity-erc20-erc721-reentrant-callbacks): Singularity
