ethereum / go-verkle

A go implementation of Verkle trees
The Unlicense
209 stars 63 forks source link

add stem to UnkownNode to allow for insertion in proof-of-absence leaf #402

Closed gballet closed 11 months ago

gballet commented 11 months ago

This is a different approach from #401, but I'm not completely sure that it fixes the exact same bug. TLDR: when PBSS was introduced, we started using UnknownNode since there can no longer be a reference to the child in the parent. Notably, this replaced HashedNodes containing a commitment and a stem, which could be used in the event a key [a, b, c, d, ...] was read/written to a proof-of-absence stem [a, b, c, e, ...]. This can happen during the re-execution of a block, in which a new leaf is created, that shares a prefix with a proof-of-absence stem.

If the UnkownNode no longer exists, reading/writing this new key no longer works. To fix this, this PR introduces an optional stem field in UnkownNode, which purpose is to hold this "proof of absence stem" that is currently missing from the tree, so that one can detect if a read/write is invalid execution, or should return nil/insert a new LeafNode.

This PR comes with a test, that should be moved to #400.

gballet commented 11 months ago

401 got merged. It didn't end up being as simple as I hoped, but it's true that it has the advantage of not needed a special handling case in the parent, so the child call will work correctly no matter what the parent's context is. It's more maintainable, eventhough it's a tad less readable imo but time will tell.