Skip to content
DoS Audit finding Intermediate

Users may fail to add liquidity because of overflow

The pool's invariant calculation multiplies two uint128 reserve amounts before taking a square root, so the intermediate product can overflow for tokens with 18 decimals. This makes adding liquidity fail for ordinary amounts such as one ETH paired with several thousand DAI.

0x37 Follow with Khan2013, haxagon and 2 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-09-dango-dex-judging/issues/461

Found by

0x37, Khan2013, haxagon, heavyw8t, holtzzx

Summary

Users may fail to add liquidity because of overflow

Root Cause

In xyk dex pool, we have one normalized_invariant. When we add liquidity, we will calculated the increased normalized_invariant to mint shares.

The normalized_invariant's formula is like sqrt(a * b). Here we should notice that variable a & b is in term of uint128. So a.checked_mul(b) should be in term of uint128.

uint128 is around 1e39. If the decimals for base token and quote token are both 18, then it's quite possible to trigger overflow here.

For example:

  1. DAI as quote token, 18 decimal.
  2. WETH as base token, 18 decimal.
  3. If we provide 1 ETH and 4000 DAI to mint shares. We will fail.
Rust
pub fn normalized_invariant(reserve: &CoinPair) -> MathResult<Uint128> {
    // amount is uint128.
    let a = *reserve.first().amount;
    let b = *reserve.second().amount;
    a.checked_mul(b)?.checked_sqrt()
}

Internal Pre-conditions

N/A

External Pre-conditions

N/A

Attack Path

  1. DAI as quote token, 18 decimal.
  2. WETH as base token, 18 decimal.
  3. If we provide 1 ETH and 4000 DAI to mint shares. We will fail.

Impact

According to the readme, The DEX contract is intended to work with tokens with >= 0 and <=18 decimal places. However, when base token and quote token's decimal is 18. it's easy to block adding liquidity.

PoC

No response

Mitigation

cast uint128 to uint256 when we multiple a with b.

The original report as published on Sherlock, by 0x37. 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 multiplication of the two reserve amounts is performed in uint128, so the product overflows before the square root is taken, even though the final result would fit.

Impact

Adding liquidity can be blocked for pairs where both tokens use 18 decimals, which the readme says the contract is meant to support.

What the attacker needed

Both tokens use 18 decimals; a liquidity provider adds a normal-sized deposit

The fix

The multiplication should be carried out in a wider integer type, such as uint256, before the square root is taken.

How it was found

  1. Use a quote token with 18 decimals, such as DAI.
  2. Use a base token with 18 decimals, such as WETH.
  3. Attempt to add liquidity with one ETH and four thousand DAI to mint shares, and the call fails.

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 stores token amounts in a fixed-size number type that has a maximum value. Multiplying two large amounts can exceed that maximum, which makes the calculation stop with an error instead of returning a result. Here the pool does that multiplication while working out how many shares to give someone adding liquidity, so the deposit simply fails.

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 0x37

View all

79 more disclosed reports, best first.

More from Dango DEX

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.