cl/merkle_tree: add EIP-7916 progressive merkleization#22446
Conversation
domiwei
left a comment
There was a problem hiding this comment.
Looks good — algorithm matches the EIP-7916 spec, reference vectors pass, and the in-place mutation guard is correct.
One optional suggestion: numLeaves * 4 can overflow uint64 to zero when numLeaves reaches 4^31 (2^62), which would cause infinite recursion. In practice this requires ~197 exabytes of input so it's not a real-world risk, but a one-line guard would close the theoretical path:
if numLeaves > math.MaxUint64/4 {
return [32]byte{}, errors.New("progressive tree capacity overflow")
}Non-blocking — approve as-is.
Thanks for pointing this out. |
There was a problem hiding this comment.
Pull request overview
Adds a reusable progressive Merkleization primitive to cl/merkle_tree implementing the EIP-7916 “recursive subtree layout” (1, 4, 16, 64, … capacity subtrees, terminated by a zero chunk), along with pinned reference vectors to validate behavior across subtree boundary transitions.
Changes:
- Introduce
MerkleizeProgressivethat progressively merkleizes input chunks without mutating the caller’s slice (by copying per-subtree before callingMerkleizeVector). - Add reference-vector tests covering progressive subtree boundary transitions and verifying input immutability.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| cl/merkle_tree/progressive.go | Implements EIP-7916 progressive Merkleization with overflow protection and non-mutating behavior. |
| cl/merkle_tree/progressive_test.go | Adds pinned reference vectors and validates that MerkleizeProgressive does not modify input chunks. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
MerkleizeProgressivefollowing the recursive subtree layout defined by EIP-7916MerkleizeVectorhashes its input in placeMotivation
This provides a reusable progressive Merkleization primitive for future
ProgressiveList-based SSZ work, including EIP-7807.Testing
go test ./cl/merkle_tree -count=1