isGenesis flag is ineffective to control add liquidity flow in RouterV2.addLiquidity()
The isGenesis flag was meant to block external liquidity additions to Genesis Pool pairs before launch, but the RouterV2.addLiquidity check only blocked when totalSupply was zero, and Pair.mint had no isGenesis check at all. An attacker could add a tiny amount of liquidity directly via mint to make totalSupply non-zero, then use the router to add liquidity, disrupting the controlled launch.
Submitted by maxzuvex
Finding description
The check that prevents external liquidity additions to “Genesis Pool” pairs before their official launch are insufficient. The RouterV2.addLiquidity() check can be bypassed once any LP tokens exist (even dust) and Pair.mint() also has no isGenesis check at all, letting direct initial liquidity supply. This damages the controlled launch, let potential price manipulation and launch disruption and clearly stated intended behaviour.
RouterV2.addLiquidityguard issue:
// contracts/RouterV2.sol
function addLiquidity(...) external ensure(deadline) returns ... {
...
require(!(IBaseV1Factory(factory).isGenesis(pair) && IBaseV1Pair(pair).totalSupply() == 0), "NA");
_safeTransferFrom(tokenA, msg.sender, pair, amountA);
_safeTransferFrom(tokenB, msg.sender, pair, amountB);
liquidity = IBaseV1Pair(pair).mint(to);
}
- If
isGenesis(pair)is true andtotalSupply()is 0, the inner condition(true && true)is true. Therequire(!true)fails, correctly blocking. - Once
totalSupply > 0(for example after official GenesisPool launch, or a prior dust minting by an attacker), this check becomesrequire(!(true && false))which isrequire(true), allowing anyone to add liquidity using the router if theisGenesisflag hasn’t been cleared yet. - This means if
isGenesisflag is not set to false immediately before the GenesisPool contract callsaddLiquidity, then after the GenesisPool successfully adds its liquidity (makingtotalSupply > 0), any subsequent call toRouterV2.addLiquidity()for that pair would pass the check, letting external LPs in prematurely. Pair.mint()is not restricted:
// contracts/Pair.sol:
function mint(address to) external lock returns (uint liquidity) {
(uint _reserve0, uint _reserve1) = (reserve0, reserve1);
uint _balance0 = IERC20(token0).balanceOf(address(this));
uint _balance1 = IERC20(token1).balanceOf(address(this));
uint _amount0 = _balance0 - _reserve0;
uint _amount1 = _balance1 - _reserve1;
uint _totalSupply = totalSupply; // gas savings, must be defined here since totalSupply can update in _mintFee
if (_totalSupply == 0) {
liquidity = Math.sqrt(_amount0 * _amount1) - MINIMUM_LIQUIDITY;
_mint(address(0), MINIMUM_LIQUIDITY); // permanently lock the first MINIMUM_LIQUIDITY tokens
} else {
liquidity = Math.min(_amount0 * _totalSupply / _reserve0, _amount1 * _totalSupply / _reserve1);
}
require(liquidity > 0, 'ILM'); // Pair: INSUFFICIENT_LIQUIDITY_MINTED
_mint(to, liquidity);
_update(_balance0, _balance1, _reserve0, _reserve1);
emit Mint(msg.sender, _amount0, _amount1);
}
Pair.sol::mint()does not have anyisGenesisstatus check.- An attacker can transfer minimal
token0andtoken1to a Genesis pair (whereisGenesis == trueandtotalSupply == 0) and callmint()directly. - This mints LP tokens, makes
totalSupply > 0, and bypasses the (already weak)RouterV2.addLiquidityguard for that pair.
Impact
The impact isn’t a direct loss of deposited funds but is a significant disruption to a core protocol mechanism, potentially leading to unfair advantages, poor launch conditions for projects, and reduced trust. This fits a Medium severity: ”Assets not at direct risk, but the function of the protocol or its availability could be impacted, or leak value with a hypothetical attack path with stated assumptions“.
This is also clearly against this statement in contract diff / Liquidity Pool / PairFactory: ”When a pair gets listed as Genesis Pool until it’s not successfully launched noone should be able to add liquidity so we’re using this isGenesis flag to control add liquidity flow”
Recommended mitigation steps
- In
RouterV2.addLiquidityblock if the pair is a Genesis Pool, regardless oftotalSupply.
- require(!(IBaseV1Factory(factory).isGenesis(pair) && IBaseV1Pair(pair).totalSupply() == 0), "NA");
+ require(!IBaseV1Factory(factory).isGenesis(pair), "GENESIS_POOL_LIQUIDITY_LOCKED");
- Restrict
Pair.mint()for genesis pairs by adding a check inPair.sol::mint():
function mint(address to) external lock returns (uint liquidity) {
+ require(!PairFactory(factory).isGenesis(address(this)), "GENESIS_POOL_MINT_LOCKED");
// ... existing mint logic ...
}
Status: Mitigation confirmed. Full details in reports from rayss and maxvzuvex.
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 router's guard only checked totalSupply == 0 instead of the isGenesis flag alone, and the pair's mint function had no isGenesis restriction, so a dust mint could flip the router check.
Impact
The impact is not direct loss of deposited funds but significant disruption to the controlled launch, potentially enabling unfair advantages and poor launch conditions; the report rates this as Medium severity.
What the attacker needed
A Genesis Pool pair exists with isGenesis true; Attacker can transfer tokens to the pair; Attacker can call Pair.mint directly
The fix
The mitigation was confirmed: the router should block any Genesis Pool regardless of totalSupply, and Pair.mint should also check isGenesis.
How it was found
- Identify a Genesis Pool pair where isGenesis is true and totalSupply is zero.
- Transfer a minimal amount of both tokens directly to the pair contract.
- Call Pair.mint() directly to create LP tokens, making totalSupply greater than zero.
- Call RouterV2.addLiquidity() for the same pair; the guard now passes because totalSupply is no longer zero.
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 Genesis Pool is a new trading pair that the project wants to launch in a controlled way, so it uses a flag to stop outsiders from adding liquidity early. The router tried to block this, but its check only worked while the pool had zero LP tokens; an attacker could create a tiny amount of LP tokens directly through the pair contract, which made the router's check pass. After that, anyone could add liquidity through the router before the official launch.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.