Skip to content
DoS Audit finding Intermediate

It's possible to create pairs that cannot be taken over

The createPair function does not validate initial parameters, allowing an attacker to set values that cause an overflow in takeOverPool, making the pair impossible to take over and permanently denying service.

y4y Follow with zzykxx

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-03-goat-trading-judging/issues/69

Found by

y4y, zzykxx

Summary

It's possible to create pairs that cannot be taken over and DOS a pair forever.

Vulnerability Detail

A pair is created by calling createPair() which takes the initial parameters of the pair as inputs but the initial parameters are never verified, which makes it possible for an attacker to create a token pair that's impossible to recover via takeOverPool().

There's more ways to create a pair that cannot be taken over, a simple example is to set all of the initial parameters to the maximum possible value:

Solidity
uint112 virtualEth = type(uint112).max;
uint112 bootstrapEth = type(uint112).max;
uint112 initialEth = type(uint112).max;
uint112 initialTokenMatch = type(uint112).max;

This will make takeOverPool() revert for overflow on the internal call to _tokenAmountsForLiquidityBootstrap:

Solidity
uint256 k = virtualEth * initialTokenMatch;
@> tokenAmtForAmm = (k * bootstrapEth) / (totalEth * totalEth);

Here virtualEth, initialTokenMatch and bootstrapEth are all setted to type(uint112).max. The multiplication virtualEth * initialTokenMatch * bootstrapEth performed to calculate tokenAmtForAmm will revert for overflow because 2^112 * 2^112 * 2^112 = 2^336 which is bigger than 2^256.

Impact

Creation of new pairs can be DOSed forever.

Code Snippet

Tool used

Manual Review

Recommendation

Validate a pair initial parameters and mint liquidity on pool creation.

Discussion

sherlock-admin4

The protocol team fixed this issue in the following PRs/commits: https://github.com/inedibleX/goat-trading/pull/10

zzykxx

Looks good, fixes regarding #18, #46, #43, and #69 all involved changes at the takeOverPool() function, summarizing here for all of the issues:

  • The penalty has been removed
  • takeOverPool() now correctly handles the scenario of a pool having 0 liquidity
  • The new initialEth parameter is now being correctly checked against the old one
  • The new virtualEth parameter is now being correctly checked against the old one
  • The minimum amount of extra tokens required to take over the pool has been increased from 10% to 30%

sherlock-admin4

The Lead Senior Watson signed off on the fix.

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

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 does not validate the initial parameters, allowing values that cause an arithmetic overflow in takeOverPool.

Impact

Creation of new pairs can be DOSed forever, preventing any takeover of those pairs.

What the attacker needed

Attacker can call createPair

The fix

The protocol team fixed this issue by validating initial parameters and minting liquidity on pool creation, and later changes to takeOverPool addressed related issues.

How it was found

  1. Call createPair with initial parameters set to the maximum possible value.
  2. Attempt to call takeOverPool on the created pair.
  3. The call reverts due to an overflow in the internal calculation.

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 new trading pair is created, the contract accepts some starting numbers without checking them. An attacker can choose numbers so large that later calculations overflow (exceed the maximum integer size), causing the takeover function to always fail. This means the pair can never be taken over, effectively blocking that feature forever.

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 y4y

View all

7 more disclosed reports, best first.

More from Goat Trading

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.