Skip to content
DoS Audit finding Advanced

Inconsistent multiplication during order creation and cancellation can lead to panics and Denial of Service during order cancellation

A discrepancy in multiplication logic between order creation and cancellation allows an attacker to create an ASK limit order that always overflows when cancelled, causing a panic. This prevents the administrator from forcefully cancelling orders, leading to a denial of service.

berndartmueller Follow

Originally disclosed on Sherlock

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

Found by

berndartmueller

Summary

A discrepancy in the multiplication logic used between ASK limit order creation and order cancellation allows for the creation of orders that will always cause a panic when cancelled. This will prevent forcefully cancelling orders by the administrator, rendering the OwnerMsg::ForceCancelOrders functionality ineffective.

Root Cause

The root cause is the use of two different multiplication methods that have different overflow behaviors.

  • During order creation in order_creation.rs:90, the quote amount for an ASK order is calculated using base.checked_mul_dec_floor(price). This is an integer-times-decimal multiplication (Int * Dec), which is less susceptible to overflow because it divides by the decimal precision before narrowing the result.

  • During order cancellation in order_cancellation.rs:91, the remaining quote amount is calculated using order.remaining.checked_mul(price). Here, order.remaining is a decimal, resulting in a decimal-times-decimal multiplication (Dec * Dec). This method can overflow with large numbers because it multiplies the underlying raw integer values first, which can exceed the maximum representable value before the final division and narrowing.

The test case audit_int_mul_dec_floor_succeeds_while_dec_mul_overflows below confirms that it is possible for the Int * Dec multiplication to succeed while the Dec * Dec multiplication with the same economic values overflows.

Internal Pre-conditions

  • A user needs to create an order with a relatively small (cheap) base amount (using a denom pair where the base has a high number of decimals so that, e.g., 1e18 + 1 tokens is a $ amount the attacker is willing to lose) and a super high price, such that the product of the two values is close to the overflow point for the Dec * Dec multiplication but not for the Int * Dec multiplication.

External Pre-conditions

None

Attack Path

  1. A malicious user calls the create_order function to place a limit ASK order on the book. They choose base = 1e18 + 1 and price = Int::<u128>::MAX such that the quote amount calculation succeeds using checked_mul_dec_floor.
  2. The order is successfully created and the user's base assets are locked.
  3. At a later time, any attempt by the contract admin to to cancel this (and all others') order, will fail
  4. The cancel_order function is called, which in turn calculates remaining_in_quote using order.remaining.checked_mul(price).
  5. This Dec * Dec multiplication overflows and causes the transaction to panic and revert.
  6. As the cancellation transaction always fails, the order can never be removed from the book, blocking the admin from cleaning up (potentially malicious) orders.

Impact

This constitutes a Denial of Service vector against the administrative OwnerMsg::ForceCancelOrders message to forcefully cancel all orders. The admin will be unable to remove the problematic order from the order book, which could lead to further complications in managing the order book and ensuring its integrity.

PoC

Add the following test case to grug/math/src/multiply_fraction.rs:

Rust
 #[test]
fn audit_int_mul_dec_floor_succeeds_while_dec_mul_overflows() {
    let amount_base = crate::Int::<u128>::new(1_000_000_000_000_000_000u128 + 1); // 1e18 + 1 base tokens
    let price = crate::Udec128_24::raw(crate::Int::<u128>::MAX);

    // Int × Dec with floor succeeds
    let amount_quote = amount_base.checked_mul_dec_floor(price).unwrap();
    // Cross-check with the underlying ratio computation for determinism
    let expected = amount_base
        .checked_multiply_ratio_floor(price.numerator(), crate::Dec::<u128, 24>::PRECISION)
        .unwrap();
    assert_eq!(amount_quote, expected);

    // Convert amount to Dec<_,18> so Dec×Dec narrows a value ~ 2 * u128::MAX
    let amount_dec = amount_base.checked_into_dec::<6>().unwrap();

    // Dec × Dec overflows because the inner exceeds u128 after scaling
    let dec_mul = amount_dec.checked_mul(price);

    assert!(matches!(dec_mul, Err(crate::MathError::OverflowMul { .. })));
}

It shows that it is possible for the Int * Dec multiplication to succeed while the Dec * Dec multiplication with the same economic values overflows.

Mitigation

Consider using a consistent method for calculating quote amounts in both order creation and cancellation. The logic in order_cancellation.rs should be changed to mirror the safer integer-based multiplication used during creation.

For example, the calculation in dango/dex/src/execute/order_cancellation.rs could be changed to:

Rust
let base_atoms = order.remaining.into_int();
let quote_atoms = base_atoms.checked_mul_dec_floor(price)?;
let remaining_in_quote = quote_atoms.checked_into_dec()?;

This ensures that any order that can be created can also be safely cancelled without risk of an arithmetic overflow.

The original report as published on Sherlock, by berndartmueller. 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 root cause is the use of two different multiplication methods with different overflow behaviours: creation uses integer-times-decimal multiplication, while cancellation uses decimal-times-decimal multiplication, which can overflow for the same economic values.

Impact

This constitutes a Denial of Service vector against the administrative force cancel functionality, preventing the admin from removing problematic orders from the order book.

What the attacker needed

Ability to create an order; choose a base amount with high decimals; set a very high price

The fix

The cancellation logic should be changed to use the same safer integer-based multiplication as creation, ensuring any order that can be created can also be safely cancelled.

How it was found

  1. A malicious user calls the create_order function to place a limit ASK order with a small base amount and a very high price.
  2. The order is successfully created and the user's base assets are locked.
  3. Later, the admin attempts to cancel the order using the force cancel functionality.
  4. The cancel_order function calculates the remaining quote amount using decimal-times-decimal multiplication.
  5. This multiplication overflows and causes the transaction to panic and revert.
  6. The order cannot be removed from the book, blocking the admin from cleaning up.

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 you place a trade order, the system calculates how much of one token you need to give for another. The code that creates orders uses a safer multiplication method, but the code that cancels orders uses a riskier one that can overflow (go past the maximum number a computer can store). An attacker can craft an order that is fine to create but always crashes when someone tries to cancel it, so the admin cannot clean up the order book.

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 berndartmueller

View all

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