LamboFactory can be permanently DoS-ed due to createPair call reversal
The factory deploys each new token at a predictable address and then creates a Uniswap pair for it, so an attacker can create that pair first. Every later launch then reverts on the pair-exists check, permanently blocking new launches.
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.
function _deployLamboToken(string memory name, string memory tickname) internal returns (address quoteToken) {
// Create a deterministic clone of the LamboToken implementation
>>> quoteToken = Clones.clone(lamboTokenImplementation);
// Initialize the cloned LamboToken
LamboToken(quoteToken).initialize(name, tickname);
emit TokenDeployed(quoteToken);
}
CREATE opcode calculates new contract address based on factory contract address and nonce (number of deployed contracts the factory has previously deployed):
The destination address is calculated as the rightmost 20 bytes (160 bits) of the Keccak-256 hash of the rlp encoding of the sender address followed by its nonce. That is: address = keccak256(rlp([senderaddress,sendernonce]))[12:]
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
function createPair(address tokenA, address tokenB) external returns (address pair) {
require(tokenA != tokenB, 'UniswapV2: IDENTICAL_ADDRESSES');
(address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
require(token0 != address(0), 'UniswapV2: ZERO_ADDRESS');
>>> require(getPair[token0][token1] == address(0), 'UniswapV2: PAIR_EXISTS'); // single check is sufficient
// ... the rest of the code is ommitted ...
}
Recommended mitigation steps
Check pool existence using IUniswapV2Factory.getPair().
Shaneson (Lambo.win) commented:
We would use cloneDeterministic instead of clone, and the backend will pass the random salt from off-chain.
And this is the fixed PR.
I believe with this fix, front-run can still be done. It is better to check if the pair exists, then simply don’t create it. This way, there is zero DoS.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the token address is deterministic and the factory does not check whether a pair already exists before calling createPair, so a pre-created pair makes the call revert.
Impact
New token launches could be permanently blocked, and the judge noted the proposed fix still allows front-running, so checking for an existing pair is better.
What the attacker needed
Attacker can send transactions on-chain; attacker predicts next token address
The fix
The team said it would switch to cloneDeterministic with an off-chain random salt, but the judge advised checking whether the pair exists and skipping creation instead.
How it was found
- Calculate the address of the next token the factory will deploy.
- Call the Uniswap factory to create a pair for that address before the token exists.
- Later launches revert because the pair already exists.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a contract creates another contract, the new address can be worked out in advance from the creator's address and a counter. Here the attacker used that to register the trading pool for a token that did not exist yet. The factory then could not create the same pool again, so its launch function kept failing.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.