Skip to content

Commit

Permalink
dev: use consts for empty hash (#1431)
Browse files Browse the repository at this point in the history
<!--- Please provide a general summary of your changes in the title
above -->

<!-- Give an estimate of the time you spent on this PR in terms of work
days.
Did you spend 0.5 days on this PR or rather 2 days?  -->

Time spent on this PR:

## Pull request type

<!-- Please try to limit your pull request to one type,
submit multiple pull requests if needed. -->

Please check the type of change your PR introduces:

- [ ] Bugfix
- [ ] Feature
- [ ] Code style update (formatting, renaming)
- [ ] Refactoring (no functional changes, no api changes)
- [ ] Build related changes
- [ ] Documentation content changes
- [ ] Other (please describe):

## What is the current behavior?

<!-- Please describe the current behavior that you are modifying,
or link to a relevant issue. -->

Resolves #1410

## What is the new behavior?

<!-- Please describe the behavior or changes that are being added by
this PR. -->

-
-
-

<!-- Reviewable:start -->
- - -
This change is [<img src="https://reviewable.io/review_button.svg"
height="34" align="absmiddle"
alt="Reviewable"/>](https://reviewable.io/reviews/kkrt-labs/kakarot/1431)
<!-- Reviewable:end -->
  • Loading branch information
enitrat authored Sep 23, 2024
1 parent 5e75690 commit 8fa6718
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
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;
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

0 comments on commit 8fa6718

Please sign in to comment.