Switch SMT node hashing to the v6a construction#168
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the Sparse Merkle Tree (SMT) implementation to comply with the yellowpaper v6a specification. Key changes include modifying the internal-node hash to incorporate the node's absolute key prefix (region), updating the empty tree root hash to be all-zero, and adding helper functions to derive these regions. Tests, golden vectors, and inclusion certificate verification have been updated accordingly, and a new interop test suite has been added to ensure parity with the JS SDK. A review comment identifies a bug in RegionFromKeyBytes where masking is incorrectly applied to a shallower byte if the input key is shorter than the expected depth, potentially clearing bits that should be preserved.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Implements yellowpaper Appendix C.3.2: internal nodes now commit to their
absolute region —
H(0x01 || depth || region_32B || left || right). Leafhashes and proof shapes unchanged; verifiers recompute the region from the
proven key, so nothing new is transmitted.
from NodeKey + compressed path at load (guarded by
key.DepthBits() + path.Len() == depth), preserved across restructures.⊥, matches the SDKs).TreeLayoutbumped toyellowpaper-rsmt-sha256-v6a: pre-v6a data refusesto open — all existing trees (incl. perf snapshots) need a rebuild from
finalized history.
Vectors (
internal/smt/v6a_interop_vectors_test.go): empty, one-leaf,shallow split, deep split (diverge at bit 255), multi-leaf, JS parity.
Verified against the JS SDK (unicitynetwork/state-transition-sdk-js#130) in
both directions — Go reproduces their root; their
SparseMerkleTreereproduces all five of ours. Java (unicitynetwork/state-transition-sdk-java#76)
and Rust (unicitynetwork/state-transition-sdk-rust#14) must reproduce at least
the deep-split and multi-leaf roots (multi-byte region packing) before the
coordinated rollover.
Closes #167