foundry-rs / foundry-rs/foundry

Improve support for cast storage with local bytecode match

Open
#5,437 3 comments 0 reactions 0 assignees View on GitHub
A-compatibility C-cast T-feature
Dominant language
Rust
Stars
10.6k
Forks
2.6k
Avg merge
18h 20m
Merged PRs (30d)
510

Description

### 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](https://github.com/foundry-rs/foundry/blob/master/common/src/abi.rs#L332) 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](https://github.com/foundry-rs/foundry/blob/0e72b71580da73d3d89c9b9aaa1bc832831e0da7/cli/src/cmd/cast/storage.rs#L107-L111).

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`)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.