Subtrie, sparse trie, multiproof - these are the terms commonly used to describe parts of the trie that have been touched and/or updated following the state transition. Currently, the closest representation for desired feature is the MultiProof struct. However, we do not have a good way to reveal or update the paths inside this struct.
The update function for the subtrie could be implemented using the following algorithm:
Starting from the root node, remove all nodes matching the updated key from self.nodes by their hash (including the previous leaf at key if present) and retain the in-memory as a stack ([root, ..., parent, leaf?])
Insert the leaf node with the updated value
Pop the ancestor from the stack, update with descendant's node hash and reinsert back to self.nodes one by one
Path-Based Subtrie
This implementation can have inner representation similar to the MultiProof.
Description
Subtrie, sparse trie, multiproof - these are the terms commonly used to describe parts of the trie that have been touched and/or updated following the state transition. Currently, the closest representation for desired feature is the
MultiProof
struct. However, we do not have a good way to reveal or update the paths inside this struct.Requirements
Requirements for the implementation:
TrieUpdates
equivalent toStateRoot
structConsiderations
Hash-Based Subtrie
The "updatable" trie can be represented similarly to the state field of the
ExecutionWitness
.The
update
function for the subtrie could be implemented using the following algorithm:self.nodes
by their hash (including the previous leaf at key if present) and retain the in-memory as a stack ([root, ..., parent, leaf?]
)self.nodes
one by onePath-Based Subtrie
This implementation can have inner representation similar to the
MultiProof
.Then the
update
function could be implemented using the following algorithm:Relevant Links
struct MultiProof
https://github.com/paradigmxyz/reth/blob/f2082e04112bfaa9f2c4a6da0ec3f05d9fba84e1/crates/trie/common/src/proofs.rs#L15-L24