Skip to content
This repository has been archived by the owner on Jan 9, 2025. It is now read-only.

Commit

Permalink
fix: returndata of create txs
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat committed Oct 30, 2024
1 parent 8f5c258 commit b4aa867
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cairo_zero/kakarot/interpreter.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ from utils.utils import Helpers
from utils.array import count_not_zero
from utils.uint256 import uint256_sub, uint256_add
from utils.maths import unsigned_div_rem
from utils.bytes import felt_to_bytes20

// @title EVM instructions processing.
// @notice This file contains functions related to the processing of EVM instructions.
Expand Down Expand Up @@ -1103,14 +1104,19 @@ namespace Internals {
let account = State.get_account(evm.message.address.evm);
let account = Account.set_code(account, evm.return_data_len, evm.return_data);

// Convert the EVM address to a 20 bytes array, returndata of the create tx
let evm_address_bytes_len = 20;
let (evm_address_bytes) = alloc();
felt_to_bytes20(evm_address_bytes, evm.message.address.evm);

State.update_account(account);
State.finalize();

// Update gas and return data - we know gas_left > code_deposit_cost
tempvar evm = new model.EVM(
message=evm.message,
return_data_len=2,
return_data=cast(evm.message.address, felt*),
return_data_len=evm_address_bytes_len,
return_data=evm_address_bytes,
program_counter=evm.program_counter,
stopped=evm.stopped,
gas_left=evm.gas_left - code_deposit_cost,
Expand Down
22 changes: 22 additions & 0 deletions cairo_zero/tests/src/kakarot/test_kakarot.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,28 @@ def test_failing_contract(self, cairo_run):
)
assert not evm["reverted"]

@SyscallHandler.patch("IAccount.is_valid_jumpdest", lambda addr, data: [1])
@SyscallHandler.patch("IAccount.get_code_hash", lambda addr, data: [0x1, 0x1])
@SyscallHandler.patch("IERC20.balanceOf", lambda addr, data: [0x1, 0x1])
def test_create_tx_returndata_should_be_20_bytes_evm_address(self, cairo_run):
"""
Bug reported by Protofire for the simulation of the create tx using eth_call.
https://github.com/safe-global/safe-singleton-factory.
"""
evm, _, _, _ = cairo_run(
"eth_call",
origin=0xE1CB04A0FA36DDD16A06EA828007E35E1A3CBC37,
to=None,
gas_limit=1000000,
gas_price=100,
value=0,
data="604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf3",
)
assert (
bytes(evm["return_data"]).hex()
== "914d7fec6aac8cd542e72bca78b30650d45643d7"
)

class TestEthChainIdEntrypoint:
@given(chain_id=integers(min_value=0, max_value=2**64 - 1))
def test_should_return_chain_id_modulo_max_safe_chain_id(
Expand Down

0 comments on commit b4aa867

Please sign in to comment.