Submitted by ahmedaghadi, also found by gumgumzum
If the creation code consists of JUMP or JUMPI opcode for offset less than creation code length, then the starknet transaction reverts.
The evm.cairo::jump function is called whenever the JUMP or JUMPI opcode is executed. This function is as follows:
It can be seen that, it checks for out_of_range which is new_pc_offset - self.message.bytecode_len. For the creation code, technically bytecode_length should be 0 but here, it will consist the length of the creation code. So, if the new_pc_offset is less than the creation code length, then this check would pass and then it checks for is_valid_jumpdest by calling evm.cairo::is_valid_jumpdest, which is as follows:
Here, let (is_valid) = IAccount.is_valid_jumpdest(code_address.starknet, index); would revert the whole starknet transaction as it will call zero address which isnt IAccount contract. So any contract using CREATE or CREATE2 opcode will be vulnerable to this issue or if a contract makes a callback to another contract by making sure to only send limited gas and handle the revert case properly, the other contract can use CREATE or CREATE2 opcode to make the transaction revert forcefully.
Consider the following code:
Save the above code in a file name creation_code.huff. You can refer Installing Huff, if you dont 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:
The output will be:
The runtime code, after removing the first few bytes which are responsible for deployment:
Also, consider the following code:
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:
The output will be:
The runtime code, after removing the first few bytes which are responsible for deployment:
The create.huff would call CREATE opcode with creation code as 0x5f56 (creation_code.huff).
Now to to run the test, add this file named test_kakarot_jump.py in kakarot/tests/endtoend folder:
You can run the test by:
This test will throw error as follows:
You can see the error Requested contract address 0x0000000000000000000000000000000000000000000000000000000000000000 is not deployed.
Python test suite
For JUMP and JUMPI opcodes, there should be a check whether the current environment is running creation code or runtime code. If its creation code, then it should revert with invalid jump destination error.
Error
ClementWalter (Kakarot) confirmed and commented:
LSDan (judge) decreased severity to Medium:
Kakarot mitigated:
Status: Mitigation confirmed.
