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

Merged
merged 24 commits into from
Dec 9, 2024
Merged

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.

return nil, err
}

var rejectedTxs []*RejectedTx
includedTxs := make(types.Transactions, 0, block.Transactions().Len())
receipts := make(types.Receipts, 0, block.Transactions().Len())
noop := state.NewNoopWriter()
// noop := state.NewNoopWriter()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change seems not relevant

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is relevant because we are injecting a custom StateWriter. I just left the comment as a reminder of what code was before.

erigon-lib/state/domain_shared.go Outdated Show resolved Hide resolved
@@ -455,7 +459,7 @@ var ChaindataTables = []string{
ActiveValidatorIndicies,
EffectiveBalancesDump,
BalancesDump,

// Witnesses,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

table should be initialised? Please add to comment of witness when values in that bucket become obsolete or so. also could be good to add it to some cleanup lists (to have other that rm chaindata options to reset contents of this bcket

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The table is not used for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove then all references pls

erigon-lib/kv/tables.go Outdated Show resolved Hide resolved
erigon-lib/trie/trie_test.go Show resolved Hide resolved
erigon-lib/commitment/hex_patricia_hashed.go Outdated Show resolved Hide resolved
erigon-lib/commitment/hex_patricia_hashed.go Show resolved Hide resolved
erigon-lib/commitment/hex_patricia_hashed.go Show resolved Hide resolved
erigon-lib/commitment/hex_patricia_hashed.go Show resolved Hide resolved
@antonis19 antonis19 added the zkevm label Dec 9, 2024
@antonis19 antonis19 merged commit 03ef2b6 into main Dec 9, 2024
13 checks passed
@antonis19 antonis19 deleted the feat/mpt-witness-e3-pr branch December 9, 2024 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants