Create order can be DOSed as there is no compulsory fee collected during the creation/cancellation of orders
The smart contract allows users to create orders without paying a fee, and the number of pending orders is capped. An attacker can fill all available order slots with orders that can never be executed, and when the admin cancels them, the attacker can immediately recreate them, causing a denial of service for legitimate users.
BugPull Follow with krot-0025, xiaoming90 and 1 other
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-11-oku-judging/issues/429
Found by
BugPull, krot-0025, xiaoming90, zxriptor
Summary
No response
Root Cause
No response
Internal pre-conditions
No response
External pre-conditions
No response
Attack Path
Assume that:
maxPendingOrdersis set to 25, which is similar to the value configured in the test scriptminOrderSizeis set to 10 USD, which is similar to the value configured in the test script
Bob (malicious user) can spend 250 USD to create 25 orders, which will cause the number of pending orders to reach the maxPendingOrders (25) limit. For each of the orders Bob created, he intentionally configured the order in a way that it will always never be in range. For instance, setting the takeProfit, stopPrice, and/or stopLimitPrice to uint256.max - 1. In this case, no one can fill his orders.
The protocol admin can attempt to delete Bob's order by calling adminCancelOrder function to remove Bob's order from the pendingOrderIds to reduce the size. When Bob's order is canceled, the 10 USD worth of assets will be refunded back to Bob.
The issue is that this protocol is intended to be deployed on Optimism as per the Contest's README where the gas fee is extremely cheap. Thus, Bob can simply use the refunded 10 USD worth of assets and create a new order again.
Thus, whenever the admin cancels Bob's order, he can always re-create a new one again. As a result, whenever innocent users attempt to create an order, it will always revert with a "Max Order Count Reached" error.
File: Bracket.sol
444: function _createOrder(
..SNIP..
462: require(
463: pendingOrderIds.length < MASTER.maxPendingOrders(),
464: "Max Order Count Reached"
465: );
File: StopLimit.sol
300: function _createOrder(
..SNIP..
320: require(
321: pendingOrderIds.length < MASTER.maxPendingOrders(),
322: "Max Order Count Reached"
323: );
Impact
Medium. DOS and broken functionality. This DOS can be repeated infinitely, and the cost of attack is low.
PoC
No response
Mitigation
Consider collecting fees upon creating new orders or canceling existing orders so that attackers will not be incentivized to do so, as it would be economically infeasible.
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/gfx-labs/oku-custom-order-types/pull/1
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 absence of a fee for creating or cancelling orders allows an attacker to repeatedly fill the order slots at low cost.
Impact
Legitimate users are unable to create orders, causing a denial of service that can be repeated indefinitely at low cost.
What the attacker needed
Attacker has funds to create orders; maxPendingOrders limit is set; no fee for order creation or cancellation
The fix
The protocol team fixed this issue by collecting fees upon creating or canceling orders, as indicated in the referenced pull request.
How it was found
- Attacker creates 25 orders with parameters that ensure they will never be executed (e.g., takeProfit set to uint256.max - 1).
- The pending orders reach the maxPendingOrders limit.
- Legitimate users cannot create new orders because the contract reverts with 'Max Order Count Reached'.
- Admin cancels the attacker's orders, refunding the attacker's funds.
- Attacker uses the refunded funds to create new orders, repeating the attack.
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.
This is a smart contract bug where a user can block others from creating orders. The attacker creates many orders that can never be filled, using up all available slots. Even if the admin cancels them, the attacker can quickly create new ones because there is no fee to discourage this.
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.