Skip to content
DoS Audit finding Intermediate

Bracket and StopLimit contracts are vulnerable to DoS attacks

The Bracket and StopLimit contracts allow users to create orders with the recipient set to the zero address. When the admin tries to cancel such an order, the token transfer to the zero address reverts for tokens like USDT, making the order uncancellable and allowing an attacker to fill the pending order array and cause a denial of service.

Contest-Squad Follow with vinica_boy

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-11-oku-judging/issues/72

Found by

Contest-Squad, vinica_boy

Summary

Users can create uncancellable order and brick the Bracket and StopLimit contracts. Both contracts have an upper limit for their pending orders defined in AutomationMaster contract. This will ensure that length of the pendingOrderIds array wont grow indefinitely and it can be traversed with the current gas block limit. Also, the admin can cancel orders if users create inexecutable order which only take space in the array.

But there is case where orders wont be possible to be cancelled by admin when the tokenIn is USDT which will allow users to fulfill the supported amount of orders with order that will never be in range to be executed. For example bracket order for WETH with stopPrice = 0 and takeProfit = 100000 USD

Root Cause

In _cancelOrder() the tokenIn amount is send back to the recipient: order.tokenIn.safeTransfer(order.recipient, order.amountIn)

But this call will always revert for order.recipient = address(0). Here is the _transfer() function of USDT:

Solidity
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
        require(sender != address(0), "ERC20: transfer from the zero address");
@>      require(recipient != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(sender, recipient, amount);

        _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
        _balances[recipient] = _balances[recipient].add(amount);
        emit Transfer(sender, recipient, amount);
    }

And when order is created, recipient can be set to address(0) since there are no constraints.

_cancelOrder(): https://github.com/sherlock-audit/2024-11-oku/blob/ee3f781a73d65e33fb452c9a44eb1337c5cfdbd6/oku-custom-order-types/contracts/automatedTrigger/Bracket.sol#L501C1-L520C6

Internal pre-conditions

N/A

External pre-conditions

N/A

Attack Path

User create enough orders with recipient set to address(0) to make the length of pendingOrderIds reach AutomationMaster.maxPendingOrders. We assume that this does not lead to DoS and array elements can be traversed within the block gas limit. Admin cannot cancel such orders and can only increase the maxPendingOrders. This process can happen again and again until the size of pendingOrderIds and maxPendingOrders reach numbers for which gas cost to traverse the whole array would be more than the current gas block limit.

Impact

Complete DoS for Bracket and StopLimit contracts.

PoC

N/A

Mitigation

Ensure order recipient to be different than address(0).

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

The original report as published on Sherlock, by Contest-Squad. 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 order creation function does not validate that the recipient is not the zero address, and the cancellation function attempts to transfer tokens to that address, which reverts for tokens like USDT.

Impact

This could lead to a complete denial of service for the Bracket and StopLimit contracts, preventing any new orders from being processed.

What the attacker needed

Attacker can create orders; Token used is USDT or similar

The fix

The order creation should require that the recipient is not the zero address.

How it was found

  1. Create many orders with recipient set to address(0) until the pendingOrderIds array reaches the maximum allowed.
  2. The admin cannot cancel these orders because the token transfer to address(0) reverts.
  3. The admin can only increase maxPendingOrders, but the attacker can repeat the process until the array is too large to traverse within the block gas limit.

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.

These smart contracts let users place orders that can be cancelled later. If a user sets the recipient of an order to the zero address (a special address that means 'nobody'), the cancellation fails because the token (like USDT) refuses to send funds to that address. An attacker can create many such orders, filling up the list of pending orders so that no new orders can be processed, effectively stopping the service.

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 from Oku's New Order Types Contract Contest

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.