Skip to content

Commit

Permalink
test: compare transient_storage cairo vs python
Browse files Browse the repository at this point in the history
  • Loading branch information
obatirou committed Jan 14, 2025
1 parent 2249331 commit d5b79df
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
18 changes: 10 additions & 8 deletions cairo/ethereum/cancun/state.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ func get_storage{poseidon_ptr: PoseidonBuiltin*, state: State}(
return value;
}

func get_transient_storage{poseidon_ptr: PoseidonBuiltin*}(
transient_storage: TransientStorage, address: Address, key: Bytes32
func get_transient_storage{poseidon_ptr: PoseidonBuiltin*, transient_storage: TransientStorage}(
address: Address, key: Bytes32
) -> U256 {
alloc_locals;
let fp_and_pc = get_fp_and_pc();
Expand Down Expand Up @@ -222,19 +222,21 @@ func get_transient_storage{poseidon_ptr: PoseidonBuiltin*}(

let trie = TrieBytes32U256(cast(trie_ptr, TrieBytes32U256Struct*));

// read the value from the trie
with trie {
let value = trie_get_TrieBytes32U256(key);
}

hashdict_write{poseidon_ptr=poseidon_ptr, dict_ptr=transient_storage_tries_dict_ptr}(
1, &address.value, cast(trie.value, felt)
);

let new_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 AddressTrieBytes32U256DictAccess(
key=transient_storage.value._tries.value.dict_ptr.key,
prev_value=transient_storage.value._tries.value.dict_ptr.prev_value,
new_value=trie,
),
new_storage_tries_dict_ptr,
transient_storage.value._tries.value.original_mapping,
),
);
Expand Down
6 changes: 4 additions & 2 deletions cairo/tests/ethereum/cancun/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,12 @@ def test_get_transient_storage(
address: Address,
key: Bytes32,
):
cairo_result = cairo_run(
[transient_storage_cairo, result_cairo] = cairo_run(
"get_transient_storage",
transient_storage,
address,
key,
)
assert cairo_result == get_transient_storage(transient_storage, address, key)
result_py = get_transient_storage(transient_storage, address, key)
assert result_cairo == result_py
assert transient_storage_cairo == transient_storage

0 comments on commit d5b79df

Please sign in to comment.