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

dev: ensure consistency in EVM storage #828

Open
enitrat opened this issue Aug 19, 2024 · 0 comments
Open

dev: ensure consistency in EVM storage #828

enitrat opened this issue Aug 19, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@enitrat
Copy link
Collaborator

enitrat commented Aug 19, 2024

In CairoZero, the address of an EVM storage is computed as

    // @notice Compute the storage address of the given key when the storage var interface is
    //         Account_storage(key: Uint256)
    // @dev    Just the generated addr method when compiling the account_contract
    func _storage_addr{pedersen_ptr: HashBuiltin*, range_check_ptr}(key: Uint256*) -> (res: felt) {
        let res = 0x0127c52d6fa812547d8a5b435341b8c12e82048913e7193c0e318e8a6642876d;
        let (res) = hash2{hash_ptr=pedersen_ptr}(res, cast(key, felt*)[0]);
        let (res) = hash2{hash_ptr=pedersen_ptr}(res, cast(key, felt*)[1]);
        let (res) = normalize_address(addr=res);
        return (res=res);
    }

Ensure that

        fn write_storage(ref self: ContractState, key: u256, value: u256) {
            self.ownable.assert_only_owner();
            self.Account_storage.write(key, value);
        }

is computing the same key and compatibility is kept.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: 🆕 Backlog
Development

No branches or pull requests

1 participant