Skip to content
Business logic Audit finding Intermediate

stopLimit Id collision with bracket orders due to no validation, opening up an attack to steal funds

The order ID generation in Oku's contracts uses only block number and user address, so two different contracts (Bracket and StopLimit) can produce the same order ID in the same block. An attacker could create orders in both contracts with the same ID and then cancel the order twice to receive duplicate refunds.

056Security Follow with 0rpse, 0x007 and 47 others

Originally disclosed on Sherlock

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

Found by

056Security, 0rpse, 0x007, 0x0x0xw3, 0x37, 0x486776, 0xAadi, 0xNirix, 0xRiO, 0xaxaxa, 0xc0ffEE, 0xeix, 0xhuh2005, 0xmurki, 0xumarkhatab, 62616279727564696e, Afriaudit, Atharv, Bigsam, Boy2000, Breaker, BugPull, Cayde-6, ChinmayF, Contest-Squad, DenTonylifer, ElKu, ExtraCaterpillar, Falendar, IvanFitro, JinxSalamV2, John44, JohnTPark24, Kenn.eth, KungFuPanda, Kyosi, LonWof-Demon, LordAdhaar, Matin, NickAuditor2, NoOneWinner, NoWinner, PNS, PeterSR, PoeAudits, Praise03, Ragnarok, Tri-pathi, TxGuard, Weed0607, Xcrypt, Z3R0, ami, aslanbek, auditism, bughuntoor, chista0x, covey0x07, durov, elvin.a.block, future2_22, hals, iamandreiski, itcruiser00, joshuajee, krot-0025, lanrebayode77, lukris02, mladenov, mxteem, newspacexyz, nfmelendez, nikhil840096, onthehunt, oualidpro, phoenixv110, rudhra1749, safdie, silver_eth, t.aksoy, t0x1c, tedox, tmotfl, tobi0x18, tomadimitrie, vinica_boy, whitehair0330, xiaoming90, xseven, yovchev_yoan, zhenyazhd, zhigang, zhoo, zxriptor

Summary

High-severity vulnerability in Oku's dual-contract architecture where parallel order creation between StopLimit.sol and Bracket.sol enables order data corruption and potential double-refund exploitation through orderId collisions.

Root Cause

Solidity
// Current implementation
function generateOrderId(address user) external returns (uint96) {
    return uint96(uint256(keccak256(abi.encodePacked(
        block.number,
        user
    ))));
}

Deterministic orderId generation lacks contract-specific entropy, allowing cross-contract collisions within the same block.

Internal pre-conditions

  1. Shared AutomationMaster instance between contracts
  2. Mutable orders mapping in Bracket contract
  3. Independent order creation flows
Solidity
mapping(uint96 => Order) public orders;

External pre-conditions

  1. MEV capabilities (same-block execution)
  2. Sufficient token balance for multiple orders
  3. Active protocol state

Attack Path

Solidity
// Block N
// Step 1: Create Bracket order (5000 USDT)
bracket.createOrder({
    amountIn: 5000e6,
    recipient: attacker
});
// OrderId = hash(blockN + attacker)

// Same Block N
// Step 2: Create StopLimit order (10000 USDT)
stopLimit.createOrder({
    amountIn: 10000e6,
    recipient: attacker
});
// Internally calls bracket.fillStopLimitOrder
// Same OrderId = hash(blockN + attacker)

// Step 3: Cancel order twice
bracket.cancelOrder(orderId); // Refunds 10000 USDT
bracket.cancelOrder(orderId); // Refunds 10000 USDT again

Impact

  • Double-spend vulnerability
  • Order state corruption
  • Accounting system compromise
  • Direct financial loss

Mitigation

Solidity
contract AutomationMaster {
    // Add contract-specific entropy
    function generateOrderId(
        address user,
        address contractSource
    ) external returns (uint96) {
        return uint96(uint256(keccak256(abi.encodePacked(
            block.number,
            user,
            contractSource,
            _orderNonce++ // Additional entropy
        ))));
    }
    
    uint256 private _orderNonce;
}

// Update in Bracket.sol
function createOrder(...) external {
    uint96 orderId = MASTER.generateOrderId(msg.sender, address(this));
    // Rest of the function
}

// Update in StopLimit.sol
function createOrder(...) external {
    uint96 orderId = MASTER.generateOrderId(msg.sender, address(this));
    // Rest of the function
}

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 056Security. 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

An attacker could corrupt order data and steal funds through double refunds, leading to direct financial loss.

What the attacker needed

MEV capabilities (same-block execution); Sufficient token balance for multiple orders; Active protocol state

The fix

The protocol team fixed this issue by adding contract-specific entropy and a nonce to the order ID generation.

How it was found

  1. Create a Bracket order with a certain amount.
  2. In the same block, create a StopLimit order with a different amount, which internally calls the Bracket contract and generates the same order ID.
  3. Cancel the order twice using the same order ID to receive duplicate refunds.

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.

When you place an order, the system gives it a unique number. Here, that number is made from the block number and your address, so two different contracts can accidentally create the same number. If that happens, you might be able to cancel the same order twice and get your money back twice.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by 056Security

View all

13 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.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.