Skip to content
DoS Audit finding Intermediate

createPair() expects zero slippage

The createPair() function calls addLiquidity() with zero slippage tolerance, so if the pool's ratio changes before the call, the transaction reverts and users cannot create the pair. An attacker with early access to the new token could front-run the call to cause this denial of service.

sirhashalot Follow

Originally disclosed on Code4rena

Submitted by sirhashalot

The LaunchEvent.sol createPair() function calls router.addLiquidity() with a amountADesired == amountAMin and amountBDesired == amountBMin. Because there is no allowance for slippage, if the zero slippage requirement is not met then the addLiquidity() function will revert and prevent users from using the createPair() function. This could be caused either by frontrunning the createPair call or in a situation where the liquidity pool exists but does not allow for zero slippage with the assets it is holding.

Proof of Concept

The zero slippage addLiquidity call is found in LaunchEvent.sol. This code may have been written with the assumption that only Rocket Joe will have a balance of the new token, so no other user could call the addLiquidity function with both assets, since the whitepaper states “Rocket Joe liquidity launch will complete before launchpad public sale release any tokens to the public”. However, the new token contract should be considered untrusted and Rocket Joe cannot guarantee where all the new tokens are before phase 3 of the Rocket Joe launch event, which is when createPair() is called. The token creator who has control over the token allocation is not controlled by Trader Joe, so an attacker who has early access to the new token can break the outlined assumptions.

Recommended Mitigation Steps

Consider how the launch event functions may break if the new token is launched by an attacker who doesn’t follow the assumptions outlined. One solution for this createPair() issue is to add an input parameter to the function to handle a slippage allowance.

cryptofish7 (Trader Joe) acknowledged


The original report as published on Code4rena, by sirhashalot. 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

Likely the createPair() function hardcodes zero slippage by setting amountAMin equal to amountADesired and amountBMin equal to amountBDesired, leaving no tolerance for pool ratio changes.

Impact

An attacker with early access to the new token could front-run the createPair() call, causing addLiquidity() to revert and preventing the pair from being created, a denial of service.

What the attacker needed

Attacker has early access to new token; attacker can front-run createPair()

The fix

The function should be fixed by adding an input parameter to handle a slippage allowance.

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 adding liquidity to a trading pool, you specify a minimum amount of each token you will accept. This code sets the minimum equal to the desired amount, meaning any change in the pool's ratio will cause the transaction to fail. An attacker who holds the new token could trade first to change the ratio, blocking the legitimate pair creation.

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.

More by sirhashalot

View all

10 more disclosed reports, best first.

More from Trader Joe contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.