Skip to content
DoS Audit finding Intermediate

User can pause all auctions by overflow in mid-price average

The mid-price calculation adds the best bid and ask prices without checking for overflow, so an attacker can place a very high ask and a small bid to cause an overflow. This error bubbles up and sets a global PAUSED flag, stopping all auctions across every trading pair.

Ziusz Follow

Originally disclosed on Sherlock

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

Found by

Ziusz

Summary

Unchecked addition of best_bid_price and best_ask_price when saving mid price can cause a global auction pause for all traders as an attacker can place one very high-price ask and one small-price bid so both best prices exist; then mid_price = (bid + ask) / 2 overflows and the auction submessage fails, which sets PAUSED = true.

Root Cause

In cron.rs:630 the mid price is computed by adding both prices then halving:

Rust
fn clear_orders_of_pair(...) -> anyhow::Result<()> {
    // [...]
    let mid_price = match (best_bid_price, best_ask_price) {
        // @audit Can overflow Udec128_24 when ask is near max and bid > 0
        (Some(bid), Some(ask)) => Some(bid.checked_add(ask)?.checked_mul(HALF)?),
        (Some(bid), None) => Some(bid),
        (None, Some(ask)) => Some(ask),
        (None, None) => None,
    };    
    // [...]
}

Adding two Price (Udec128_24) numbers can overflow when ask is near the max and bid is positive. The error bubbles up, the auction submessage fails, and the reply handler pauses trading in cron.rs:65:

Rust
pub fn reply(ctx: SudoCtx, msg: ReplyMsg, res: SubMsgResult) -> StdResult<Response> {
    match msg {
        ReplyMsg::AfterAuction {} => {
            // [...]
            // @audit Any error sets PAUSED to true globally
            PAUSED.save(ctx.storage, &true)?;
            Response::new().add_event(Paused { error: Some(error) })
        },
    }
}

Internal Pre-conditions

  1. The pair has no passive pool reserves yet, so no passive orders cap prices; best bid/ask come only from user orders.

External Pre-conditions

None.

Attack Path

  1. Attacker sends a GTC SELL (ask) with extreme price (A) close to Price max (Udec128_24).
  2. Attacker sends a GTC BUY (bid) with small price (e.g., 1) and quote >= min_order_size (e.g., $10).
  3. No match happens (1 < A), so at end of block, the contract saves resting book.
  4. It computes mid_price = Some(bid.checked_add(ask)?.checked_mul(HALF)?).
  5. bid + ask overflows Udec128_24, so the submessage errors and the reply handler sets PAUSED = true.

Impact

The protocol suffers global DoS on auctions across all pairs. Creating a new pair is permanently poisoned because it always carries the risk of pausing all auctions.

PoC

The issue is quite simple, so I think the example on numbers is enough:

  1. For simplicity, let's say that Price max is 1000.
  2. A user provided 1000 as ask and 1 as bid.
  3. Mid price is getting calculated by this formula: mid_price = Some(bid.checked_add(ask)?.checked_mul(HALF)?).
  4. So it calculates bid + ask = 1000 + 1 = 1001, which overflows over 1000. Transaction reverts before getting to the dividing part.

Mitigation

Never average with (lo + hi) / 2; use lo + (hi − lo) / 2 instead to avoid overflow during the addition.

The original report as published on Sherlock, by Ziusz. 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 mid-price is computed as (bid + ask) / 2 without guarding against overflow when the ask price is near the maximum value.

Impact

The protocol suffers a global denial of service on auctions across all pairs, and creating a new pair is permanently poisoned because it always carries the risk of pausing all auctions.

What the attacker needed

The pair has no passive pool reserves yet

The fix

The mid price should be calculated as lo + (hi - lo) / 2 to avoid overflow during the addition.

How it was found

  1. Attacker places a sell order (ask) with a price close to the maximum allowed value.
  2. Attacker places a buy order (bid) with a very small price and enough quote value to meet the minimum order size.
  3. The orders do not match, so they rest in the order book.
  4. At the end of the block, the contract computes the mid price by adding bid and ask.
  5. The addition overflows, causing an error in the auction submessage.
  6. The error handler sets the global PAUSED flag to true, halting all auctions.

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 calculates an average price by adding two numbers. If the numbers are very large, the addition can overflow (wrap around or fail), which causes an error. That error triggers a safety switch that pauses all trading, so an attacker can stop the whole exchange by placing two orders.

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 Ziusz

View all

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