foundry-rs / forge-std

Forge Standard Library is a collection of helpful contracts for use with forge and foundry. It leverages forge's cheatcodes to make writing tests easier and faster, while improving the UX of cheatcodes. For more in-depth usage examples checkout the tests.
Apache License 2.0
840 stars 333 forks source link

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

Open rzmahmood opened 1 year ago

rzmahmood commented 1 year ago

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.
mds1 commented 1 year ago

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 commented 1 year ago

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)