Skip to content
Access control Audit finding Intermediate

Attackers can drain the `OracleLess` contract by creating an order with a `malicious tokenIn` and executing it with a `malicious target`

The OracleLess contract does not verify that tokenIn is a legitimate ERC20 token and does not validate the target and txData in fillOrder, allowing an attacker to create an order with a malicious token and execute it with a malicious target to drain all USDT from the contract.

0xaxaxa Follow with BugPull, Ragnarok and 1 other

Originally disclosed on Sherlock

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

Found by

0xaxaxa, BugPull, Ragnarok, whitehair0330

Summary

In the OracleLess contract, the createOrder() function does not verify whether the tokenIn is a legitimate ERC20 token, allowing attackers to create an order with a malicious token. Additionally, the fillOrder() function does not check if the target and txData are valid, enabling attackers to execute their order with a malicious target and txData.

Root Cause

The OracleLess.createOrder() function does not verify whether tokenIn is a legitimate ERC20 token.

Additionally, the OracleLess.fillOrder() function does not check if target and txData are valid.

Internal pre-conditions

External pre-conditions

Attack Path

Let's consider the following scenario:

  1. Alice, the attacker, creates a malicious token.

  2. Alice creates an order with her malicious token:

    • tokenIn: Alice's malicious token
    • tokenOut: WETH
    • minAmountOut: 0
  3. Alice calls the fillOrder() function to execute her malicious order, setting parameters as follows:

    • target: address of USDT

    • txData: transfer all USDT in the OracleLess contract to Alice.

      Solidity
          function fillOrder(
              ...
      
      118     (uint256 amountOut, uint256 tokenInRefund) = execute(
                  target,
                  txData,
                  order
              );
      
              ...
          }
      
    • At line 118 of the fillOrder() function, execute() is invoked:

      <details> <summary> execute() </summary>
            function execute(
                address target,
                bytes calldata txData,
                Order memory order
            ) internal returns (uint256 amountOut, uint256 tokenInRefund) {
                //update accounting
                uint256 initialTokenIn = order.tokenIn.balanceOf(address(this));
                uint256 initialTokenOut = order.tokenOut.balanceOf(address(this));
      
                //approve
        237     order.tokenIn.safeApprove(target, order.amountIn);
      
                //perform the call
        240     (bool success, bytes memory reason) = target.call(txData);
      
                if (!success) {
                    revert TransactionFailed(reason);
                }
      
                uint256 finalTokenIn = order.tokenIn.balanceOf(address(this));
                require(finalTokenIn >= initialTokenIn - order.amountIn, "over spend");
                uint256 finalTokenOut = order.tokenOut.balanceOf(address(this));
      
                require(
        251         finalTokenOut - initialTokenOut > order.minAmountOut,
                    "Too Little Received"
                );
      
                amountOut = finalTokenOut - initialTokenOut;
                tokenInRefund = order.amountIn - (initialTokenIn - finalTokenIn);
            }
      
      </details>
      • At line 237 of the execute() function, tokenIn.safeApprove() is called. Alice made her malicious tokenIn as follows:
        Solidity
            function approve(address spender, uint256 amount) public virtual override returns (bool) {
                WETH.transfer(msg.sender, 1);
                return true;
            }
        
        This transfers 1 wei of WETH to the OracleLess contract.
      • At line 240, all USDT are transferred to Alice, as target is USDT and txData is set to transfer to Alice.
      • At line 251, finalTokenOut - initialTokenOut will be 1, as the contract has already received 1 wei. Thus, the require statement will pass since order.minAmountOut was set 0.

As a result, Alice can drain all USDT from the OracleLess contract.

Impact

Attackers can drain the OracleLess contract by using malicious token, target, and txData.

PoC

Mitigation

It is recommended to implement a whitelist mechanism for token, target, and txData.

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.

How it worked

Impact

Attackers can drain all USDT from the OracleLess contract.

What the attacker needed

Attacker can create a malicious token; Contract holds USDT

The fix

The protocol team fixed this issue in the following PRs/commits: https://github.com/gfx-labs/oku-custom-order-types/pull/1

How it was found

  1. Alice creates a malicious token.
  2. Alice creates an order with her malicious token as tokenIn, WETH as tokenOut, and minAmountOut set to 0.
  3. Alice calls fillOrder() with target set to the USDT address and txData set to transfer all USDT in the OracleLess contract to Alice.
  4. The malicious token's approve function transfers 1 wei of WETH to the OracleLess contract, making the finalTokenOut - initialTokenOut equal to 1, which passes the require statement since minAmountOut is 0.
  5. All USDT is transferred to Alice.

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 to swap tokens. The contract failed to check that the token used in an order was real and that the instructions for filling the order were safe. An attacker could use a fake token and a malicious instruction to steal all the USDT held by the contract.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

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.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.