0x73696d616f / codeup-issues-external

Smart Contract and configuration scripts for codeup.app DEFI game based on Ethereum story
https://codeup.app
0 stars 0 forks source link

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

Open 0x73696d616f opened 1 week ago

0x73696d616f commented 1 week ago

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:

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 {
Maxim280596 commented 1 week ago

I did as you recommended

0x73696d616f commented 1 week ago

Fixed in #4864ad9.