feat(mpt): Don't seal MPT in place by default #981
Labels
A-executor
Area: kona-executor crate
A-mpt
Area: kona-mpt crate
H-interop
Hardfork: Interop related
K-feature
Kind: feature
Overview
The current behavior of the
TrieNode
when computing the root is to do it in-place by default. This prevents a good deal of copies of intermediate nodes while computing the hash.However, the method we currently use hinges on an assumption that the block we're processing is actually canonical. In order to compute the output root of the block (or fetch the
L2ToL1MessagePasser
storage root for the Isthmus fork), we first seal the trie, and then re-open it via an MPT proof we fetch from a remote node. If the remote node has a different block at the given height, which can be the case for the interop proof's first sub-problem, execution would fail.To allow for non-canonical blocks to be processed by
kona
, we need to keep a cache of the intermediates we generate. To do this, do not seal the trie up in place, but instead copy nodes as they're being encoded for hashing, leaving the originals in their place. Upon the traversal to theL2ToL1MessagePasser
account in the state root after it has been computed, new trie nodes won't need to be fetched from the remote node, just existing ones that went un-changed in the worst case.Bonus Points
For programs that use kona for multi-block range proofs, leaving the entire trie open and having to re-hash intermediates that may have not been touched in the current block is fairly inefficient. While not a requirement to get the interop proof working, adding a copy-on-write cache for trie nodes when they're hashed would prevent unnecessary inefficiencies during state root computation, especially in projects like
op-succinct
.Context
kona/crates/mpt/src/node.rs
Lines 121 to 130 in 71a02cc
kona/crates/executor/src/executor/mod.rs
Lines 78 to 92 in 71a02cc
kona/crates/executor/src/db/mod.rs
Lines 175 to 183 in 71a02cc
kona/bin/host/src/interop/fetcher.rs
Lines 532 to 551 in 71a02cc
The text was updated successfully, but these errors were encountered: