# attacker can drain StopLimit contract funds through Bracket contract because it gives type(uint256).max  allowance to bracket contract for input token in performUpkeep function

StopLimit grants Bracket max allowance; attacker crafts a Bracket order whose swap target is the token itself, pulling StopLimit funds via transferFrom and draining them.

- Payout: Audit contest
- Severity: high
- Program: Oku
- Found by: 0xaxaxa
- Disclosed: 2024-11-22
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2024-11-oku-judging/issues/700
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-11-oku%3AH-5
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:high tech:evm tech:solidity technique:chained technique:source-review vuln:access-control vuln:business-logic

**Target:** StopLimit/Bracket automated trigger contracts (Solidity)
**Root cause:** updateApproval in StopLimit increases Bracket's allowance to type(uint256).max instead of the needed amount, leaving residual unlimited allowance after each fill.
**Steps:**
1. Identify tokenOut tokens for which StopLimit has granted Bracket near-max allowance.
2. Create a readily-executable Bracket order with tokenOut = that token, feeBips=0, recipient=attacker, takeProfit/stopPrice in range.
3. Call Bracket.performUpkeep with target=tokenOut address and txData = `transferFrom(stopLimit, bracket, stopLimitBalance)`.
4. execute() calls target, moving StopLimit tokens into Bracket; balance delta passes minAmountReceived check.
5. adjustedAmount = swapAmountOut is transferred to attacker recipient, draining StopLimit.
**How found:** Code review of updateApproval noticed allowance set to type(uint256).max rather than exact amount; traced that Bracket.execute performs an arbitrary external call with tokenIn approval, allowing the target to be the token itself and pull StopLimit funds via the leftover allowance.
**Exploitation:** Attacker uses the residual max allowance from StopLimit to Bracket as the primitive: a crafted order's swap target is the token contract itself, so the 'swap' is a transferFrom pulling StopLimit's balance into Bracket, which then pays it out to the attacker's recipient with zero fee.
**Escalation:** Repeat across all tokens for which StopLimit holds allowance to Bracket to drain nearly all StopLimit funds.
**Insight:** When a contract grants a spender max allowance, check whether that spender exposes an arbitrary-call/swap primitive: the spender can point the call at the token contract and use transferFrom to siphon the approver's balance, bypassing balance-delta checks because the 'output' token equals the 'input' token.

