0

This is my contract:

SPDX-License-Identifier: MIT
pragma solidity 0.8.22; 
contract StringStorage { 
    
    string short_string = "ABCD"; 
    string long_string = "ABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCDABCD"; //84 characters long ; 
    
} 

How do I get the first storage slot of long_string? I tried doing keccak256(0x00…01) in an online keccak256 calculator but it returned cb371be217faa47dab94e0d0ff0840c6cbf41645f0dc1a6ae3f34447155a76f3 however when I look in remix IDE debugger it says the slot is 0xb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6. Could someone tell me what I am doing wrong?? I thought the slot of a string greater than 31 bytes was the keccak hash of its slot??

1 Answer 1

1

Do this to get the address of the storage slot in Remix:

function a(uint256 slot) external pure returns (bytes32) {
    return keccak256(abi.encode(slot));
}

This will return 0xb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6

If you use Foundry: cast keccak 0x0000000000000000000000000000000000000000000000000000000000000001 This will also bring back the correct sequence

The online calculator will also return the correct value if the input parameters are correct

enter image description here

And here's a long string in the storages enter image description here

1
  • Thank you this makes a lot more sense now.
    – davidastro
    Dec 27, 2023 at 5:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.