forge-std icon indicating copy to clipboard operation
forge-std copied to clipboard

StdStorage Slot find does not find storage slot for short strings.

Open rzmahmood opened this issue 2 years ago • 2 comments

Example contract:

contract MyContract {
   // short string as it only has 31 characters
    string public exists = "thequickbrownfoxjumpsoverthelaz";
}

Script:

contract MyScript is Script {
    using stdStorage for StdStorage;

    function run() public {
        uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
        vm.startBroadcast(deployerPrivateKey);

        MyContract s = new MyContract();

        uint256 slot = stdstore.target(address(s)).sig("exists()").find();
        console2.log(slot);
        vm.stopBroadcast();
    }
}

Output:

stdStorage find(StdStorage): Slot(s) not found.

rzmahmood avatar Apr 11 '23 23:04 rzmahmood

This is currently not supported, more discussion in https://github.com/foundry-rs/foundry/issues/3869

@brockelmore has a PR that should fix this in https://github.com/foundry-rs/forge-std/pull/259, but I'm not sure of the status of it

Edit: Hm actually per https://github.com/foundry-rs/foundry/issues/3869#issuecomment-1362963430 maybe this should work, let me try to reproduce

mds1 avatar Apr 11 '23 23:04 mds1

Ok I was able to reproduce. Also tried using PR #259 but got [FAIL. Reason: stdStorage find(StdStorage): No storage use detected for target.] as the error. In both cases I did verify that the data was in slot 0 (i.e. solc isn't optimizing away storage into immutables or anything)

mds1 avatar Apr 11 '23 23:04 mds1