Malicious users can `createOrder` with `0 amount` and make `DOS` for all
The createOrder function allowed orders with zero input amount, letting an attacker create many such orders. This bloated the pendingOrderIds array, causing fillOrder and cancelOrder to run out of gas when iterating it, blocking all users from filling or cancelling orders.
Source: https://github.com/sherlock-audit/2024-11-oku-judging/issues/731
Found by
sakibcy
Summary
Malicious users can createOrder with 0 amount and can cause DOS / block users to fillOrder, cancleOrder
Impact
Malicious users will create huge numbers of orders with 0 amountIn.
Now if anyone wants to fillOrder or cancleOrder they can not do it because:
- Due to the block gas limit, there is a clear limitation in the amount of operation that can be handled in an Array.
ArrayMutation::removeFromArrayis called onfillOrder,cancleOrderfunctions.- Now because the malicious users have created a huge amount of orders with 0 amount,
- When normal users go to
fillOrderorcancleOrderthey simplyrun out of gaswhile iterating a huge array ofpendingOrderIds. - This makes them and every one impossible to do any further action on
fillOrder,cancleOrder
PoC
function createOrder(
IERC20 tokenIn,
IERC20 tokenOut,
uint256 amountIn,
uint256 minAmountOut,
address recipient,
uint16 feeBips,
bool permit,
bytes calldata permitPayload
) external override returns (uint96 orderId) {
//procure tokens
procureTokens(tokenIn, amountIn, recipient, permit, permitPayload);
//construct and store order
orderId = MASTER.generateOrderId(recipient);
orders[orderId] = Order({
orderId: orderId,
tokenIn: tokenIn,
tokenOut: tokenOut,
amountIn: amountIn,
minAmountOut: minAmountOut,
recipient: recipient,
feeBips: feeBips
});
//store pending order
pendingOrderIds.push(orderId);
emit OrderCreated(orderId);
}
Mitigation
We can add checks for the createOrder function something like this
require(amountIn > 0, "amount should be greater than 0")
Or can add code like the other Contracts
MASTER.checkMinOrderSize(tokenIn, amountIn);
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 createOrder function lacked a check to ensure amountIn is greater than zero, allowing an attacker to add many zero-amount orders to the pendingOrderIds array.
Impact
An attacker could block all users from filling or cancelling orders by exhausting gas when iterating the bloated pendingOrderIds array.
What the attacker needed
Attacker can create many orders; no minimum order size check
The fix
The protocol team fixed this issue in a pull request.
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 lets users create orders. An attacker can create many orders with zero amount, which fills up a list. When normal users try to fill or cancel their orders, the contract has to go through that huge list and runs out of gas, so nobody can do anything.
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.