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

dev: use consts for empty hash #1431

Merged
merged 3 commits into from
Sep 23, 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
4 changes: 2 additions & 2 deletions src/kakarot/account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ namespace Account {
assert balance_ptr = new Uint256(balance.low, balance.high);
// empty code hash see https://eips.ethereum.org/EIPS/eip-1052
tempvar code_hash_ptr = new Uint256(
304396909071904405792975023732328604784, 262949717399590921288928019264691438528
low=Constants.EMPTY_CODE_HASH_LOW, high=Constants.EMPTY_CODE_HASH_HIGH
);
let account = Account.init(
address=address,
Expand Down Expand Up @@ -699,7 +699,7 @@ namespace Account {
if (code_len == 0) {
// see https://eips.ethereum.org/EIPS/eip-1052
let empty_code_hash = Uint256(
304396909071904405792975023732328604784, 262949717399590921288928019264691438528
low=Constants.EMPTY_CODE_HASH_LOW, high=Constants.EMPTY_CODE_HASH_HIGH
);
return empty_code_hash;
}
Expand Down
3 changes: 2 additions & 1 deletion src/kakarot/constants.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ namespace Constants {
// ACCOUNTS
const MAX_NONCE = 2 ** 64 - 1;
const MAX_CODE_SIZE = 0x6000;

const EMPTY_CODE_HASH_LOW = 0xe500b653ca82273b7bfad8045d85a470;
const EMPTY_CODE_HASH_HIGH = 0xc5d2460186f7233c927e7db2dcc703c0;
ClementWalter marked this conversation as resolved.
Show resolved Hide resolved
const BURN_ADDRESS = 0xdead;
}

Expand Down
3 changes: 2 additions & 1 deletion src/kakarot/state.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ from kakarot.gas import Gas
from utils.dict import default_dict_copy
from utils.utils import Helpers
from utils.uint256 import uint256_add, uint256_sub, uint256_eq
from kakarot.constants import Constants

namespace State {
// @dev Create a new empty State
Expand Down Expand Up @@ -466,7 +467,7 @@ namespace Internals {
let (bytecode) = alloc();
// empty code hash see https://eips.ethereum.org/EIPS/eip-1052
tempvar code_hash_ptr = new Uint256(
304396909071904405792975023732328604784, 262949717399590921288928019264691438528
Constants.EMPTY_CODE_HASH_LOW, Constants.EMPTY_CODE_HASH_HIGH
);
let account = Account.init(
address=address,
Expand Down
5 changes: 2 additions & 3 deletions tests/src/kakarot/test_account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ from starkware.cairo.common.memcpy import memcpy
from kakarot.model import model
from kakarot.account import Account
from tests.utils.helpers import TestHelpers
from kakarot.constants import Constants

func test__init__should_return_account_with_default_dict_as_storage{
syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr, bitwise_ptr: BitwiseBuiltin*
Expand Down Expand Up @@ -173,9 +174,7 @@ func test__fetch_original_storage__state_modified{
let starknet_address = Account.compute_starknet_address(evm_address);
tempvar address = new model.Address(starknet_address, evm_address);
let (local code: felt*) = alloc();
tempvar code_hash = new Uint256(
304396909071904405792975023732328604784, 262949717399590921288928019264691438528
);
tempvar code_hash = new Uint256(Constants.EMPTY_CODE_HASH_LOW, Constants.EMPTY_CODE_HASH_HIGH);
tempvar balance = new Uint256(0, 0);
let account = Account.init(address, 0, code, code_hash, 0, balance);

Expand Down
9 changes: 3 additions & 6 deletions tests/src/kakarot/test_state.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ from backend.starknet import Starknet
from kakarot.state import State, Internals
from kakarot.account import Account
from kakarot.storages import Kakarot_native_token_address
from kakarot.constants import Constants
from utils.dict import dict_keys

func test__init__should_return_state_with_default_dicts() {
Expand Down Expand Up @@ -172,9 +173,7 @@ func test___copy_accounts__should_handle_null_pointers{range_check_ptr}() {
tempvar address = new model.Address(1, 2);
tempvar balance = new Uint256(1, 0);
let (code) = alloc();
tempvar code_hash = new Uint256(
304396909071904405792975023732328604784, 262949717399590921288928019264691438528
);
tempvar code_hash = new Uint256(Constants.EMPTY_CODE_HASH_LOW, Constants.EMPTY_CODE_HASH_HIGH);
let account = Account.init(address, 0, code, code_hash, 1, balance);
dict_write{dict_ptr=accounts}(address.evm, cast(account, felt));
let empty_address = 'empty address';
Expand Down Expand Up @@ -202,9 +201,7 @@ func test__is_account_warm__account_in_state{
tempvar address = new model.Address(starknet_address, evm_address);
tempvar balance = new Uint256(1, 0);
let (code) = alloc();
tempvar code_hash = new Uint256(
304396909071904405792975023732328604784, 262949717399590921288928019264691438528
);
tempvar code_hash = new Uint256(Constants.EMPTY_CODE_HASH_LOW, Constants.EMPTY_CODE_HASH_HIGH);
let account = Account.init(address, 0, code, code_hash, 1, balance);
tempvar state = State.init();

Expand Down
Loading