Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KGA-25] [KGA-73] fix: set code_address of the deployment code to the created address #1587

Merged
merged 2 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cairo_zero/kakarot/instructions/system_operations.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ namespace SystemOperations {
let (valid_jumpdests_start, valid_jumpdests) = Helpers.initialize_jumpdests(
bytecode_len=size.low, bytecode=bytecode
);
tempvar address_zero = new model.Address(starknet=0, evm=0);
tempvar message = new model.Message(
bytecode=bytecode,
bytecode_len=size.low,
Expand All @@ -175,7 +174,7 @@ namespace SystemOperations {
caller=evm.message.address.evm,
parent=parent,
address=target_account.address,
code_address=address_zero,
code_address=target_account.address,
read_only=FALSE,
is_create=TRUE,
depth=evm.message.depth + 1,
Expand Down
4 changes: 1 addition & 3 deletions cairo_zero/kakarot/interpreter.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -859,15 +859,14 @@ namespace Interpreter {
local bytecode: felt*;
local calldata: felt*;
local intrinsic_gas: felt;
local code_address: model.Address*;
let code_address = address;
if (is_deploy_tx != FALSE) {
let (empty: felt*) = alloc();
let (init_code_words, _) = unsigned_div_rem(bytecode_len + 31, 32);
let init_code_gas = Gas.INIT_CODE_WORD_COST * init_code_words;
assert bytecode = tmp_calldata;
assert calldata = empty;
assert intrinsic_gas = tmp_intrinsic_gas + Gas.CREATE + init_code_gas;
assert code_address = new model.Address(starknet=0, evm=0);
let (valid_jumpdests_start, valid_jumpdests) = Helpers.initialize_jumpdests(
bytecode_len=bytecode_len, bytecode=bytecode
);
Expand All @@ -878,7 +877,6 @@ namespace Interpreter {
assert bytecode = tmp_bytecode;
assert calldata = tmp_calldata;
assert intrinsic_gas = tmp_intrinsic_gas;
assert code_address = address;

let (new_dict) = default_dict_new(0);
tempvar range_check_ptr = range_check_ptr;
Expand Down
38 changes: 38 additions & 0 deletions tests/end_to_end/test_kakarot.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,26 @@ async def test_execute(
if event.from_address != eth.address
] == events

# https://github.com/code-423n4/2024-09-kakarot-findings/issues/44
async def test_execute_jump_creation_code(self, evm: Contract, origin):
params = {
"value": 0,
"code": "605f5f53605660015360025f5ff0",
"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=[],
)
assert result.success == params["success"]

class TestGetStarknetAddress:
async def test_should_return_same_as_deployed_address(self, new_eoa):
eoa = await new_eoa()
Expand Down Expand Up @@ -227,6 +247,24 @@ async def test_eth_call_should_succeed(self, kakarot, new_eoa):
assert result.return_data == []
assert result.gas_used == 21_000

class TestEthCallJumpCreationCodeDeployTx:
async def test_eth_call_jump_creation_code_deploy_tx_should_succeed(
self, kakarot, new_eoa
):
eoa = await new_eoa()
result = await kakarot.functions["eth_call"].call(
nonce=0,
origin=int(eoa.address, 16),
to={"is_some": 0, "value": 0},
gas_limit=TRANSACTION_GAS_LIMIT,
gas_price=1_000,
value=0,
data=bytes.fromhex("605f5f53605660015360025f5ff0"),
access_list=[],
)

assert result.success == 1

async def test_eth_call_should_handle_uninitialized_class_update(
self, kakarot, new_eoa, class_hashes
):
Expand Down
Loading