Submitted by zxriptor, also found by ast3ros, Evo, FalseGenius, Giorgio, Infect3d, inh3l, Le_Rems, m4k2, mrudenko, paco, rouhsamad, shaflow2, SpicyMeatball, TheFabled, threadmodeling, and web3km
https://github.com/code-423n4/2024-12-lambowin/blob/main/src/LamboFactory.sol#L72
LamboFactory.createLaunchPad deploys new token contract and immediately sets up a new Uniswap V2 pool by calling createPair. This can be frontrun by the attacker by setting up a pool for the next token to be deployed.
Contract addresses are deterministic and can be calculated in advance. That opens a possibility for the attacker to pre-calculate the address of the next LamboToken to be deployed. As can be seen below, LamboFactory uses clone() method from OpenZeppelin Clones library, which uses CREATE EMV opCode under the hood.
CREATE opcode calculates new contract address based on factory contract address and nonce (number of deployed contracts the factory has previously deployed):
https://www.evm.codes/#f0
Hence an attacker can calculate the address of the next token to be deployed and directly call UniswapV2Factory.createPair which will result in a new liquidity pool being created BEFORE the token has been deployed.
Such state will lead all subsequent calls to LamboFactory.createLaunchPad to revert, because of the pair existence check in Uniswap code, without the possibility to fix that:
https://github.com/Uniswap/v2-core/blob/master/contracts/UniswapV2Factory.sol#L27
Check pool existence using IUniswapV2Factory.getPair().
Shaneson (Lambo.win) commented:
Koolex (judge) commented:
