Skip to content

Commit

Permalink
feat: mark_account_created (#441)
Browse files Browse the repository at this point in the history
closes #418
  • Loading branch information
Eikix authored Jan 16, 2025
1 parent 9605606 commit e023608
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
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

0 comments on commit e023608

Please sign in to comment.