Skip to content
Smart contracts Audit finding Intermediate

CREATE2 address of the uniswap pair used by LaunchPad does not match address of pair deployed by GTELaunchpadV2PairFactory

The Launchpad contract computes a Uniswap pair address using a CREATE2 salt that omits the launchpad LP and fee distributor addresses, so it does not match the address actually deployed by the pair factory. When a user buys enough tokens to exhaust the bonding curve, the pair lookup fails and the transaction reverts, leaving the system stuck in the bonding state.

hgrano Follow with 0xanony, 0xAsen and 42 others

Originally disclosed on Code4rena

Submitted by hgrano, also found by 0xanony, 0xAsen, 0xPhantom, 0xsagetony, 0xsai, 0xShitgem, 0xterrah, AasifUsmani, agadzhalov, anchabadze, AvantGard, Ayomiposi233, bigbear1229, BlackAnon, boredpukar, c0pp3rscr3w3r, codegpt, deccs, dimulski, FalseGenius, gizzy, IvanAlexandur, JuggerNaut63, Legend, lodelux, lonelybones, lufP, MadSisyphus, magiccentaur, mahdifa, max10afternoon, nem0TheFinder, niffylord, nuthan2x, roccomania, saikumar279, serial-coder, SolidityScan, taticuvostru, udogodwin, v2110, Wolf_Kalp, ZeroEx, and zzebra83

launchpad/Launchpad.sol #L569-L587

Consider a situation in which a user has already called GTELaunchpadV2PairFactory::createPair for a quoteToken/launchToken pair, prior to the bonding curve becoming inactive. Then a user buys enough launch tokens to consume all the tokens in the bonding curve, thus we reach Launchpad.sol lines 483-489:

        // Create or get the pair
        try uniV2Factory.createPair(token, data.quote) returns (address p) {
            pair = IUniswapV2Pair(p);
        } catch {
            // Do nothing, pair exists
            // @todo its more gas but lets check pair exists and create if it doesn't.
            // try catch in solidity is horrible and should be avoided
        }

The call to createPair will revert because on GTELaunchpadV2PairFactory.sol:33, the pair creation reverts if it already exists. Therefore the pair variable is not assigned to the address of the newly created pair, but left as its original value which is computed by the Launchpad::pairFor function. This function determines the address on line 571:

pair = IUniswapV2Pair(
            address(
                uint160(
                    uint256(
                        keccak256(
                            abi.encodePacked(
                                hex"ff",
                                factory,
                                keccak256(abi.encodePacked(token0, token1)),
                                uniV2InitCodeHash // init code hash
                            )
                        )
                    )
                )
            )
        );

The salt used only includes token0 and token1, rather than token0, token1, _launchpadLp and _launchpadFeeDistributor as used by the factory, resulting in a different address than what the factory uses.

Impact: the user attempting to buy more tokens than there are remaining in the bonding curve will have their transaction reverted on LaunchPad.sol:491 as the pair address will not be a contract address. The system will be permanently stuck in the bonding state as it won’t be possible to deploy a contract at the pair address.

There is also a second impact of this issue as it also occurs when the rewards program ends for a token. This is evident on LaunchToken.sol:147 which is executed if the token is currently locked but all buyers have since sold their tokens back to the Launchpad. Consequently, Launchpad::endRewards is called but this uses the incorrectly calculated pair address on Launchpad.sol:436:

IGTELaunchpadV2Pair pair = IGTELaunchpadV2Pair(address(pairFor(address(uniV2Factory), msg.sender, quote)));

distributor.endRewards(pair);

This will cause the transaction to revert as there will be no contract at the pair address.

Recommended mitigation steps

Re-factor the code so that the Launchpad::pairFor function returns an address matching that used by the factory.

View detailed Proof of Concept


The original report as published on Code4rena, by hgrano. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

The Launchpad's pairFor function uses a CREATE2 salt containing only the two token addresses, while the factory includes additional constructor arguments, so the computed address differs from the deployed pair.

Impact

The system could become permanently stuck in the bonding state because the pair address cannot be deployed, and endRewards may also revert when the rewards program ends.

What the attacker needed

Pair created before bonding curve ends; user buys all remaining bonding curve tokens

The fix

The pairFor function should be refactored so that it returns the same address as the factory uses.

How it was found

  1. A user calls GTELaunchpadV2PairFactory::createPair for a quoteToken/launchToken pair before the bonding curve becomes inactive.
  2. Another user buys enough launch tokens to consume all tokens in the bonding curve.
  3. The Launchpad calls uniV2Factory.createPair, which reverts because the pair already exists, so the pair variable keeps the value from pairFor.
  4. The pairFor address does not match the deployed pair, so the subsequent check fails and the transaction reverts.

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.

A smart contract can predict where a new contract will be deployed by hashing a 'salt' value. Here the Launchpad uses a different salt from the factory that actually deploys the pair, so it looks for the pair at the wrong address. When the bonding curve is exhausted, the code tries to use that wrong address and the transaction fails.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by hgrano

View all

10 more disclosed reports, best first.

More from GTE Perps and Launchpad

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.