Skip to content
DoS Audit finding Intermediate

Price cannot be represented when a high-value base asset is quoted in a high-decimal asset

The DEX stores prices in a 128-bit fixed-point type with 24 decimals, whose maximum value is about 3.4e14. For a valid pair such as WBTC quoted in DAI, the scaled internal price reaches about 1.1e15, so the price cannot be stored and trades in that market fail.

0xShoonya Follow

Originally disclosed on Sherlock

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

Found by

0xShoonya

Summary

A design flaw in the DEX's price representation logic can render certain trading pairs non-functional. The internal price calculation for pairs where a high-value base asset is quoted in a high-decimal asset (e.g., WBTC/DAI) can exceed the maximum value of the Udec128_24 type used for storage. This causes transactions to fail, effectively creating a denial of service for that market.

Root Cause

We have this information from the README:

The DEX contract is intended to work with tokens with >= 0 and <=18 decimal places (ie, issues related to the token having >=0 and <=18 decimals can be considered valid and in scope) and prices as low as 0.00001 USD (an example of this would be the SHIB token).

The internal price is stored as a Price, which is a type alias for Udec128_24. This is a 128-bit unsigned number with 24 fixed decimal places. Its maximum representable value is (2^128 - 1) / 10^24, which is approximately 3.4e14.

JavaScript
    // (2^128 - 1) / 10^24 = 3.4e+14
    pub type Price = Udec128_24;

The DEX converts human-readable prices into an internal format by scaling them based on the decimal counts of the two tokens involved. This is the formula used:

JavaScript
Internal Price = Nominal Price * (Base Unit of Base Token / Base Unit of Quote Token)

The issue is that for certain valid pairs under the README's definition, this scaling formula produces a result that overflows the Udec128_24 limit. A concrete example is the WBTC/DAI pair.

Let's apply this exact logic to our problematic pair.

  • Pair: WBTC (base) vs. DAI (quote)
  • Nominal Price: 1 BTC = $110,000 DAI
  • Decimals:
    • WBTC (base_decimals): 8 (Its smallest unit, a satoshi, is 1e-8 WBTC)
    • DAI (quote_decimals): 18 (Its smallest unit is 1e-18 DAI)

Applying the scaling formula:

  • Internal Price = 110,000 * 1e-8 / 1e-18
  • Internal Price = 110,000 * 10^(18 - 8)
  • Internal Price = 110,000 * 10^10
  • Internal Price = 1.1e15

This calculated Internal Price of 1.1e15 is substantially larger than the maximum representable value of ~3.4e14. The price itself cannot be stored, leading to an arithmetic overflow.

This failure directly contradicts the README's promise to support all tokens with 0 to 18 decimals, as this common and realistic pair is fundamentally incompatible.

Internal pre-conditions

.

External pre-conditions

.

Attack Scenario

.

Impact

The DEX cannot support essential trading pairs like WBTC/DAI which are in-scope as per the README

Mitigation

Consider upgrading Price to a 256-bit fixed-point type

The original report as published on Sherlock, by 0xShoonya. 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

The internal price type is a 128-bit fixed-point number with 24 decimals, which is too small for the scaled prices of valid pairs where a high-value base asset is quoted in a high-decimal asset.

Impact

Trading pairs such as WBTC/DAI, which the README says are in scope, cannot be supported because the price overflows and transactions fail, creating a denial of service for that market.

What the attacker needed

A pair with a high-value base asset; a quote asset with many decimals; price scaling exceeds the type limit

The fix

The price type should be upgraded to a 256-bit fixed-point type so the scaled values fit.

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 price is kept in a fixed-size number format, a bit like a box with a maximum size. Some trading pairs, such as bitcoin priced in a token with many decimal places, need a number bigger than the box allows. When that happens the calculation fails and the market cannot be used.

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

View all

8 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.