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

experimental: MPT block witness for Erigon 3 #12847

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

antonis19
Copy link
Member

Experimental eth_getWitness RPC call implementation that computes the block witness for the MPT.

This works roughly along the following lines:

  • unwind execution to the start of given blockNr
  • execute the block ephemerally and record touched account and storage keys using a custom StateWriter
  • Load each of these keys from the state trie at blockNr-1 and from the resulting grid create a merkle path for each of these keys
  • Merge all the merkle paths to obtain the witness trie
  • Verification step: execute the block "statelessly" by using the witness trie as state and check that the resulting state root matches the state root in the header of the block
  • return the serialized witness

This implementation is currently incomplete and still lacks support for the following cases which will be future work:

  • witness for keys not in the current state trie (often resulting in wrong witness trie root)
  • edge cases where extension, account and storage are fused into one cell in the grid (needs "de-fusing" into multiple expanded trie nodes)
  • unit tests

The code currently works correctly in 85% of the blocks of a small test chain of 161 blocks, for the unsupported cases mentioned above the RPC method will throw a root hash mismatch error.

I am proposing to merge the current PR even though the implementation is incomplete, so that we can incrementally add these features, and to avoid arduous merges or rebasing with main.

@awskii
Copy link
Member

awskii commented Nov 26, 2024

@antonis19 do we need #12783 then?

@antonis19
Copy link
Member Author

@awskii nope, just closed that PR.

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

Successfully merging this pull request may close these issues.

2 participants