# Addresses can be pre-populated with bad data

PreimageOracle.loadPrecompilePreimagePart accepts arbitrary precompile addresses, letting attackers pre-populate preimagePartOk for future precompiles and validate invalid MIPS proofs.

- Payout: Audit contest
- Severity: medium
- Program: Optimism
- Found by: bronze\_pickaxe
- Disclosed: 2024-08-16
- Write-up quality: 7/10
- Original: https://github.com/code-423n4/2024-07-optimism-findings/issues/78
- Library page: https://bugbountylibrary.com/r/c4%3A2024-07-optimism%3AM-03
- Tags: area:web3 domain:web3 impact:integrity kind:contest platform:code4rena sev:medium tech:go tech:solidity technique:source-review vuln:access-control vuln:business-logic

**Target:** PreimageOracle.sol precompile preimage loading (Cannon/MIPS fault proof)
**Root cause:** loadPrecompilePreimagePart does not restrict _precompile to existing precompile addresses, so anyone can set preimagePartOk[_key][_offset]=true for a key derived from a not-yet-existing precompile address; when that precompile is later added and accelerated, the stale validated data is trusted by readPreimage.
**Steps:**
1. Call `oracle.loadPrecompilePreimagePart(0, address(0x0b), hex"deadbeef1337")` with a future precompile address
2. Key = precompilePreimageKey(0x0b, input); storage preimagePartOk[key][0] set true
3. Later when 0x0b precompile is added and op-program requests it, `readPreimage(key,0)` returns attacker data instead of real precompile output
4. MIPS/mips.go consume the forged preimage, validating an invalid proof step
**How found:** Reading loadPrecompilePreimagePart and noticing the unchecked _precompile parameter, then tracing readPreimage's preimagePartOk require to see that pre-populated keys bypass validation; PoC test confirmed readPreimage succeeds for a fake precompile.
**Exploitation:** Attacker pre-populates preimagePartOk for a precompile address that does not yet exist but will be added on L1; once added and accelerated by op-program, the oracle serves attacker-controlled data, allowing invalid fault-proof step validation.
**Insight:** When a contract intentionally skips validating an identifier to support future additions (forward-compat precompiles), check whether attacker-set state keyed on that identifier persists and later collides with the real future entity.

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

**PoC test pre-populating future precompile 0x0b**

```
function test_poc() public {
        bytes memory input = hex"deadbeef1337";
        uint256 offset = 0x00;
        // Newly added precompile
        address precompile = address(bytes20(uint160(0x0b)));
        bytes32 key = precompilePreimageKey(precompile, input);
        oracle.loadPrecompilePreimagePart(offset, precompile, input);

        // try reading, it should succeed
        oracle.readPreimage(key, offset);
    }
```

