Skip to content

Switch SMT node hashing to the v6a construction#168

Merged
b3y0urs3lf merged 2 commits into
mainfrom
feat/smt-v6a-node-hash
Jul 8, 2026
Merged

Switch SMT node hashing to the v6a construction#168
b3y0urs3lf merged 2 commits into
mainfrom
feat/smt-v6a-node-hash

Conversation

@jait91

@jait91 jait91 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Implements yellowpaper Appendix C.3.2: internal nodes now commit to their
absolute region — H(0x01 || depth || region_32B || left || right). Leaf
hashes and proof shapes unchanged; verifiers recompute the region from the
proven key, so nothing new is transmitted.

  • Regions are derived, never persisted: from the inserted key at creation,
    from NodeKey + compressed path at load (guarded by
    key.DepthBits() + path.Len() == depth), preserved across restructures.
  • Empty-tree root is now the all-zero hash (spec , matches the SDKs).
  • TreeLayout bumped to yellowpaper-rsmt-sha256-v6a: pre-v6a data refuses
    to 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 SparseMerkleTree
reproduces 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

@jait91 jait91 requested a review from MastaP July 7, 2026 11:07
@jait91 jait91 self-assigned this Jul 7, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread pkg/api/inclusion_cert.go
@MastaP MastaP assigned b3y0urs3lf and unassigned jait91 Jul 7, 2026
@b3y0urs3lf b3y0urs3lf merged commit ddb1d5c into main Jul 8, 2026
3 checks passed
@b3y0urs3lf b3y0urs3lf deleted the feat/smt-v6a-node-hash branch July 8, 2026 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switch SMT root/inclusion proof hashing from version 3o to 6a

3 participants