foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
8.27k stars 1.75k forks source link

feat(cast): Storage slot computation for variable names / expressions in `cast storage` #6218

Closed ckoopmann closed 1 month ago

ckoopmann commented 1 year ago

Component

Cast

Describe the feature you would like

I use cast storage to get the value of a private storage variable on a smart contract. Currently this requires me to calculate the storage slot separately which can be quite complex. It'd be great if there was a way to automate this and query a variables value by name.

For example for the following contract

contract PrivateStorage {
       uint256 private myUint;
       uint256[] private myArray;
       mapping(uint256 => mapping(uint256 => uint256)) private myMapping;
}

It would be nice to be able to query cast storage <ADDRESS> "myUint" In addition it would be nice to query also more complex nested expressions such as:

Alternatively one could introduce a new command cast storage-slot that just calculate the slot for such an expression which the user could then chain with the cast storage command to get the value. For this to work, the contract source code needs to be available, for example for verified contracts on etherscan.

Additional context

No response

zerosnacks commented 1 month ago

Hi @ckoopmann thanks for your suggestion!

I feel this is better suited for a decompilation tool like Heimdall or Dedaub as it has a more sophisticated understanding of the storage layout based on advanced heuristics. cast simply operates on the ABI which does not included private variables.

For now marking this as not planned