Skip to content

feat: cast storage modifications to print all state for an address #3332

@mds1

Description

@mds1

Component

Cast

Describe the feature you would like

Moving the discussion from #2494 here

Right now cast storage <address> <slot> prints the the specified slot. Expanding on @onbjerg's suggestion, I'd propose cast storage <address> (i.e. when no slot is specified) to behave as follows:

  1. Fetch the bytecode of the provided address.
  2. If we're in a foundry project, check artifacts for matching bytecode + recompile if needed to get storage layout.
  3. Otherwise, fetch source from etherscan and compile it with the specified settings to get storage layout (this is also useful for debugging txs against a live network where we'd recompile to get source maps).
  4. Print variable names, slots, sizes, offsets, and decoded values in a table similar to the existing one that you get with forge inspect MyContract storage-layout --pretty.

Note this PR does not properly handle dynamic types. It will print the length of an array for array types, and zero for mappings because it doesn't know the keys. I think that's ok for the first version, but I'd love for the next iteration to figure out array lengths and all mapping keys to print the all storage. @banteg has a POC for doing this here: https://github.com/banteg/storage-layout

Originally posted by @mds1 in #2494 (comment)

Definitely +1 for @mds1 cast storage <address> proposal, I think it would also be cool to have a --blocknumber param that lets you do historical queries so that you can write a script that can see how state changes in a contract over a range of blocks

Originally posted by @tynes in #2494 (comment)

Agreed, --block <blockNumber/earliest/latest/pending> is the syntax used elsewhere in cast which we should support here too

Originally posted by @mds1 in #2494 (comment)

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions