Skip to content

cl/merkle_tree: add EIP-7916 progressive merkleization#22446

Merged
AskAlexSharov merged 5 commits into
erigontech:mainfrom
JackCC703:eip-7916-progressive-merkleization
Jul 16, 2026
Merged

cl/merkle_tree: add EIP-7916 progressive merkleization#22446
AskAlexSharov merged 5 commits into
erigontech:mainfrom
JackCC703:eip-7916-progressive-merkleization

Conversation

@JackCC703

Copy link
Copy Markdown
Contributor

Summary

  • add MerkleizeProgressive following the recursive subtree layout defined by EIP-7916
  • preserve the input chunks because MerkleizeVector hashes its input in place
  • add pinned reference vectors covering progressive subtree boundaries

Motivation

This provides a reusable progressive Merkleization primitive for future ProgressiveList-based SSZ work, including EIP-7807.

Testing

  • go test ./cl/merkle_tree -count=1

@domiwei domiwei left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@JackCC703

Copy link
Copy Markdown
Contributor Author

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.
I’ve added the overflow guard.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 MerkleizeProgressive that progressively merkleizes input chunks without mutating the caller’s slice (by copying per-subtree before calling MerkleizeVector).
  • 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.

@AskAlexSharov
AskAlexSharov enabled auto-merge July 16, 2026 04:53
@AskAlexSharov
AskAlexSharov added this pull request to the merge queue Jul 16, 2026
Merged via the queue into erigontech:main with commit ba06662 Jul 16, 2026
91 checks passed
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.

4 participants