Skip to content

Commit

Permalink
apply review
Browse files Browse the repository at this point in the history
  • Loading branch information
obatirou committed Jan 14, 2025
1 parent 89a67c7 commit 2249331
Showing 1 changed file with 32 additions and 27 deletions.
59 changes: 32 additions & 27 deletions cairo/ethereum/cancun/state.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -191,25 +191,31 @@ func get_transient_storage{poseidon_ptr: PoseidonBuiltin*}(
local __fp__: felt* = fp_and_pc.fp_val;

// read the MappingAddressTrieBytes32U256
let dict_ptr = cast(transient_storage.value._tries.value.dict_ptr, DictAccess*);
with poseidon_ptr, dict_ptr {
let (trie_ptr) = hashdict_read(1, &address.value);
}

// Update the dict_ptr to point to the new dict
let new_dict_ptr = cast(dict_ptr, AddressTrieBytes32U256DictAccess*);
let original_mapping = transient_storage.value._tries.value.original_mapping;
tempvar _tries = MappingAddressTrieBytes32U256(
new MappingAddressTrieBytes32U256Struct(
transient_storage.value._tries.value.dict_ptr_start, new_dict_ptr, original_mapping
),
);
tempvar transient_storage = TransientStorage(
new TransientStorageStruct(_tries, transient_storage.value._snapshots)
let transient_storage_tries_dict_ptr = cast(
transient_storage.value._tries.value.dict_ptr, DictAccess*
);
with poseidon_ptr {
let (trie_ptr) = hashdict_read{dict_ptr=transient_storage_tries_dict_ptr}(
1, &address.value
);
}

// check if value is a default value or not
// If no storage trie is associated to that address, return the 0 default
if (trie_ptr == 0) {
let new_transient_storage_tries_dict_ptr = cast(
transient_storage_tries_dict_ptr, AddressTrieBytes32U256DictAccess*
);
tempvar transient_storage_tries = MappingAddressTrieBytes32U256(
new MappingAddressTrieBytes32U256Struct(
transient_storage.value._tries.value.dict_ptr_start,
new_transient_storage_tries_dict_ptr,
transient_storage.value._tries.value.original_mapping,
),
);
tempvar transient_storage = TransientStorage(
new TransientStorageStruct(transient_storage_tries, transient_storage.value._snapshots)
);
tempvar result = U256(new U256Struct(0, 0));
return result;
}
Expand All @@ -221,21 +227,20 @@ func get_transient_storage{poseidon_ptr: PoseidonBuiltin*}(
let value = trie_get_TrieBytes32U256(key);
}

// Update the dict_ptr to point to the new dict
tempvar new_trie = TrieBytes32U256(
new TrieBytes32U256Struct(trie.value.secured, trie.value.default, trie.value._data)
);
tempvar new_dict_access = new AddressTrieBytes32U256DictAccess(
address, transient_storage.value._tries.value.dict_ptr_start.prev_value, new_trie
);
let original_mapping = transient_storage.value._tries.value.original_mapping;
tempvar _tries = MappingAddressTrieBytes32U256(
tempvar transient_storage_tries = MappingAddressTrieBytes32U256(
new MappingAddressTrieBytes32U256Struct(
transient_storage.value._tries.value.dict_ptr_start, new_dict_access, original_mapping
transient_storage.value._tries.value.dict_ptr_start,
new AddressTrieBytes32U256DictAccess(
key=transient_storage.value._tries.value.dict_ptr.key,
prev_value=transient_storage.value._tries.value.dict_ptr.prev_value,
new_value=trie,
),
transient_storage.value._tries.value.original_mapping,
),
);

tempvar transient_storage = TransientStorage(
new TransientStorageStruct(_tries, transient_storage.value._snapshots)
new TransientStorageStruct(transient_storage_tries, transient_storage.value._snapshots)
);

return value;
Expand Down

0 comments on commit 2249331

Please sign in to comment.