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.
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:
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:
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
- 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
- Attacker sends a GTC SELL (
ask) with extreme price (A) close toPricemax (Udec128_24). - Attacker sends a GTC BUY (
bid) with small price (e.g., 1) andquote >= min_order_size(e.g., $10). - No match happens (
1 < A), so at end of block, the contract saves resting book. - It computes
mid_price = Some(bid.checked_add(ask)?.checked_mul(HALF)?). bid + askoverflowsUdec128_24, so the submessage errors and the reply handler setsPAUSED = 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:
- For simplicity, let's say that
Pricemax is 1000. - A user provided 1000 as
askand 1 asbid. - Mid price is getting calculated by this formula:
mid_price = Some(bid.checked_add(ask)?.checked_mul(HALF)?). - 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.
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
- Attacker places a sell order (ask) with a price close to the maximum allowed value.
- Attacker places a buy order (bid) with a very small price and enough quote value to meet the minimum order size.
- The orders do not match, so they rest in the order book.
- At the end of the block, the contract computes the mid price by adding bid and ask.
- The addition overflows, causing an error in the auction submessage.
- 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.