Skip to content
DoS Audit finding Intermediate

User can brick the `Bracket` contract by inputing malicious `txData`

0xaxaxa Follow with 0xloscar01, 0xpetern and 16 others

Originally disclosed on Sherlock

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

Found by

0xaxaxa, 0xloscar01, 0xpetern, 10ap17, AshishLac, ChinmayF, ExtraCaterpillar, KiroBrejka, Laksmana, Sparrow_Jac, ZanyBonzy, auditism, jah, phoenixv110, t.aksoy, t0x1c, whitehair0330, wickie, y51r

Summary

User can brick the Bracket contract by inputing malicious txData. This is possible because in all of the swap related contracts (OracleLess, Bracket), the txData is provided from the caller one way or another. This will brick the swapping functionality of any token practically locking the funds of every user in the contract. Part of this happens due to the behaviour of safeApprove function, which looks like this:

Solidity
   function safeApprove(IERC20 token, address spender, uint256 value) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

As seen in the block of code, the function requires the value of approval to be 0 or the existing allowance to be 0 in order for the tx to go through.

Root Cause

the behaviour of safeApprove function, which is due to the old OpenZeppelin version used in the system

Internal pre-conditions

User performing an upkeep with malicious txData that will leave 1 wei of a corresponding worth of allowance, which will be enough for the execute function to revert at the following line:

Solidity
    function execute(
        address target,
        bytes memory txData,
        uint256 amountIn,
        IERC20 tokenIn,
        IERC20 tokenOut,
        uint16 bips
    ) internal returns (uint256 swapAmountOut, uint256 tokenInRefund) {
        //update accounting
        uint256 initialTokenIn = tokenIn.balanceOf(address(this));
        uint256 initialTokenOut = tokenOut.balanceOf(address(this));

        //approve
@>        tokenIn.safeApprove(target, amountIn);

External pre-conditions

None

Attack Path

  1. User creates an order
  2. The order is ready to be fulfilled (Ready for the performUpkeep function to be called)
  3. As seen in the following block of code, the caller of performUpkeep function is allowed to specify his perform data input, meaning he is absolutely free to compute the malicious txData, which will have amountIn - 1 as the amount that the target address needs to swap:
Solidity
 function performUpkeep(
@>        bytes calldata performData
    ) external override nonReentrant {
  1. The execute function is called, and the following block of code is executed:
Solidity
    function execute(
        address target,
        bytes memory txData,
        uint256 amountIn,
        IERC20 tokenIn,
        IERC20 tokenOut,
        uint16 bips
    ) internal returns (uint256 swapAmountOut, uint256 tokenInRefund) {
        //update accounting
        uint256 initialTokenIn = tokenIn.balanceOf(address(this));
        uint256 initialTokenOut = tokenOut.balanceOf(address(this));

        //approve
        tokenIn.safeApprove(target, amountIn);

        //perform the call
        (bool success, bytes memory result) = target.call(txData);

We approve the target address with amountIn, which is the amountIn saved in the orders mapping. 5. Then, after the swap is performed, the target address would have used amountIn - 1 tokens to perform the swap, leaving it with 1 wei worth of the corresponding token of allowance, which due to the safeApprove behaviour will revert the function every time someone tries to swap with the same tokenIn as the attacker swapped.

Impact

User can block the usage of every single existing ERC20 including those the system wants to comply with

PoC

No response

Mitigation

The OpenZeppelin version is outdated. Upgrade the version to the newest one possible and use forceApprove instead of safeApprove

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 0xaxaxa. 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.

What is known

A medium-severity doS bug in Oku's New Order Types Contract Contest. Sherlock made it public on 24 December 2024. Found in the 641 audit contest (finding M-4), also found by 18 other wardens.

About DoS

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

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 0xaxaxa

View all

4 more disclosed reports, best first.

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.