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.
Experimental
eth_getWitness
RPC call implementation that computes the block witness for the MPT.This works roughly along the following lines:
This implementation is currently incomplete and still lacks support for the following cases which will be future work:
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.