# Invalid DISPUTED_L2_BLOCK_NUMBER is passed to VM

FaultDisputeGame passes uncapped DISPUTED_L2_BLOCK_NUMBER to op-program, letting an attacker challenge valid output roots for blocks earlier than the safe head.

- Payout: Audit contest
- Severity: high
- Program: Optimism
- Found by: xuwinnie
- Disclosed: 2024-08-16
- Write-up quality: 8/10
- Original: https://github.com/code-423n4/2024-07-optimism-findings/issues/36
- Library page: https://bugbountylibrary.com/r/c4%3A2024-07-optimism%3AH-01
- Tags: area:web3 domain:web3 impact:integrity kind:contest platform:code4rena sev:high tech:evm technique:chained technique:source-review vuln:accounting-error vuln:business-logic

**Target:** FaultDisputeGame.addLocalData / op-program VM input
**Root cause:** addLocalData computes DISPUTED_L2_BLOCK_NUMBER as startingBlock + traceIndex + 1 without capping at the claimed L2 block number, so op-program derives past the claimed block to the safe head and rejects valid earlier claims.
**Steps:**
1. Set up game with split-depth span 8, starting block 0; Alice claims B2, Bob claims B3 at same L1 head.
2. Bob attacks by claiming B3 (trace index 3).
3. Alice attacks claiming B2 at trace index 1.
4. Bob defends claiming B3 at trace index 2.
5. Alice attacks B2 ->3 B3; addLocalData computes l2Number = 0 + traceIndex(SPLIT_DEPTH) + 1 = 3, identical VM inputs to Bob's own valid defense.
6. VM cannot distinguish contexts, so the same trace is both defensible and attackable, contradicting determinism.
**How found:** Observed that game-tree span at split depth far exceeds distance between starting and claimed block; reasoned that when starting+traceIndex+1 exceeds claimed block, honest party should keep committing to claimed root, but contract always passes starting+traceIndex+1, so VM runs to safe head. Constructed two-game scenario showing identical VM inputs must be both defensible and attackable.
**Exploitation:** Attacker posts a counter-claim whose trace includes one extra valid safe block past the honest output root; at split depth both agree on block 13 but disagree on block 14, and op-program derives past block 13 to resolve block 14 as valid, invalidating the honest claim. Requires manipulating game so the dishonest actor posts the first bottom-half claim or honest actor's post-state is honest.
**Insight:** When a VM's inputs are derived from position indices rather than the actual claimed value, check whether two distinct game contexts collapse to identical VM inputs — determinism then makes a valid trace attackable. Cap derived block numbers at the claimed value.

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

**addLocalData computing DISPUTED_L2_BLOCK_NUMBER without cap**

```
uint256 l2Number = startingOutputRoot.l2BlockNumber + disputedPos.traceIndex(SPLIT_DEPTH) + 1;

                oracle.loadLocalData(_ident, uuid.raw(), bytes32(l2Number << 0xC0), 8, _partOffset);
```

**Recommended mitigation capping block number**

```
uint256 l2Number = min(startingOutputRoot.l2BlockNumber + disputedPos.traceIndex(SPLIT_DEPTH) + 1, l2BlockNumber());
```

