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

feat: mark_account_created #441

Merged
merged 1 commit into from
Jan 16, 2025
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
32 changes: 32 additions & 0 deletions cairo/ethereum/cancun/state.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ from ethereum.cancun.fork_types import (
MappingBytes32U256,
MappingBytes32U256Struct,
Bytes32U256DictAccess,
SetAddressDictAccess,
SetAddressStruct,
)
from ethereum.cancun.trie import (
TrieBytes32U256,
Expand Down Expand Up @@ -485,3 +487,33 @@ func is_account_empty{poseidon_ptr: PoseidonBuiltin*, state: State}(address: Add
tempvar res = bool(1);
return res;
}

func mark_account_created{poseidon_ptr: PoseidonBuiltin*, state: State}(address: Address) {
alloc_locals;

let created_accounts = state.value.created_accounts;

let fp_and_pc = get_fp_and_pc();
local __fp__: felt* = fp_and_pc.fp_val;

let set_dict_ptr = cast(created_accounts.value.dict_ptr, DictAccess*);
hashdict_write{poseidon_ptr=poseidon_ptr, dict_ptr=set_dict_ptr}(1, &address.value, 1);

// Rebind state
tempvar new_created_account = SetAddress(
new SetAddressStruct(
dict_ptr_start=created_accounts.value.dict_ptr_start,
dict_ptr=cast(set_dict_ptr, SetAddressDictAccess*),
),
);
tempvar state = State(
new StateStruct(
_main_trie=state.value._main_trie,
_storage_tries=state.value._storage_tries,
_snapshots=state.value._snapshots,
created_accounts=new_created_account,
),
);

return ();
}
8 changes: 8 additions & 0 deletions cairo/tests/ethereum/cancun/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
get_storage,
get_transient_storage,
is_account_empty,
mark_account_created,
set_account,
set_storage,
set_transient_storage,
Expand Down Expand Up @@ -100,6 +101,13 @@ def test_is_account_empty(self, cairo_run, data):
assert result_cairo == is_account_empty(state, address)
assert state_cairo == state

@given(data=state_and_address_and_optional_key())
def test_mark_account_created(self, cairo_run, data):
state, address = data
state_cairo = cairo_run("mark_account_created", state, address)
mark_account_created(state, address)
assert state_cairo == state


class TestStateStorage:
@given(data=state_and_address_and_optional_key(key_strategy=bytes32))
Expand Down
Loading