Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement simplified storage_changes access #17

Open
abourget opened this issue Apr 5, 2023 · 2 comments
Open

Implement simplified storage_changes access #17

abourget opened this issue Apr 5, 2023 · 2 comments

Comments

@abourget
Copy link

abourget commented Apr 5, 2023

Problem

storage_changes and keccak_preimages are powerful primitives in Firehose and Substreams data, that can avoid a huge percentage of eth calls in circulation, and even pick up data that isn't triggered by any log events on Ethereum.

However, accessing those storage changes require reverse interpretation of their keys. That's pretty opaque and can get quite annoying. With the AST, it's possible to know the storage slots, their offsets, and their types to know what technique to use to reverse the keys and interprete the data in the storage slots.

Proposed draft solution

An API like:

StructAccessor{slot: 3, name: "MyObject", fields: vec![
  Uint256Accessor{slot: 1, name: "field1"},
  Uint32Accessor{slot: 2, offset: 0, name: "field2"},
  Uint96Accessor{slot: 2, offset: 4, name: "field3"},
]}

let balance_accessor = MapAccessor<Address, Uint256>{slot: 1, name: "balances"};
let values_accessor = ListAccessor<Uint256>{slot: 1, name: "values"};

let key = balance_accessor.get_key("0x123123123123123");
let value = trx.storage_changes.filter(|el| el.key == key).first(); // is that even Rust? whatever

or something like that.

See https://gist.github.com/gane5h/5bf622cbaaf546d356994a4bec9f6798 for an example AST piece that details the storage layout. This can be extracted from artifacts left over the the solc compiler. This way, we could code gen the above structs.
But we can start with non-codegen'd readers like the above, for the simple cases, when you know which field you want, its type (like a balance) and you can easily discover the slot it is at (by inspecting a few keccak and the keys in ERC20 transfers for instance)

Some reference to decoding storage: https://medium.com/coinmonks/decoding-the-memory-of-an-ethereum-contract-52c256f83f07

@azf20
Copy link

azf20 commented Apr 11, 2023

Would this be Ethereum specific rather than core substreams?

@maoueh
Copy link
Contributor

maoueh commented Apr 11, 2023

That is indeed Ethereum specific, so it will go in substreams-ethereum crate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants