foundry icon indicating copy to clipboard operation
foundry copied to clipboard

Improve support for cast storage with local bytecode match

Open wadealexc opened this issue 1 year ago • 2 comments

Component

Cast

Describe the feature you would like

From the docs description of cast storage:

Emit the slot number to get the full storage layout (requires contract to be verified on Etherscan with a Solidity version > 0.6.5 or you must be in a Forge project with a local contract matching the deployed bytecode).

In practice, the local option for cast storage doesn't function very well. There are 2 main cases:

  1. If the target contract is a proxy, the storage layout you want is the implementation contract's. But if the proxy is defined in your local project (even via import from openzeppelin), the fetched bytecode will get a local match and give you results based on the proxy's layout. This is in contrast to the etherscan lookup logic, which handles this pretty well since etherscan's API lets you fetch the implementation contract.
  2. If the target contract has immutable variables or other changes to bytecode that occur during the constructor, the deployed bytecode probably won't find a match in your local artifacts, since the comparison checks for an exact bytecode match.

Suggested improvements:

  1. Ability to supply a flag to cast storage that forces the etherscan lookup, in case the local lookup returns weird results like the ones described above. This one's easy to implement, and I'd be happy open a PR for this if there's interest.
  2. Somehow have a fuzzier bytecode match in the local lookup - one that matches regardless of constructor-set values. I'm not sure what this looks like in practice.

Additional context

In case you're interested in reproducing the things that prompted me to open this issue, what I did was clone and build this repo: https://github.com/Layr-Labs/eigenlayer-contracts

And I'm trying to do mainnet storage lookups for contracts defined there. For example: cast storage 0x54945180dB7943c0ed0FEE7EdaB2Bd24620256bc, which points to a contract behind a proxy (StrategyBaseTVLLimits.sol)

wadealexc avatar Jul 19 '23 18:07 wadealexc