Skip to content

fix(L-02): use default zero hash in place valid 0 leaves#1595

Draft
nadir-akhtar wants to merge 4 commits into
mainfrom
nadir/l-02-valid-0-leaves-fix
Draft

fix(L-02): use default zero hash in place valid 0 leaves#1595
nadir-akhtar wants to merge 4 commits into
mainfrom
nadir/l-02-valid-0-leaves-fix

Conversation

@nadir-akhtar
Copy link
Copy Markdown
Collaborator

Motivation:

0 leaves are currently considered valid within the Merkle library. In the event of an uninitialized struct, this can lead to proofs unintentionally being valid. As such, a default non-zero hash is used to represent these placeholder leaves for padding.

Modifications:

  • Added a new "MERKLE_ZERO_HASH" constant derived from keccak256("MERKLE_ZERO_HASH")
  • Created a new internal helper function to consolidate logic

Result:

  • 0 leaves no longer being valid for constructing proofs.

Note: this change may impact offchain services that generate roots + proofs. This change should only be merged if offchain services are ready to integrate with this change to root & proof calculations. Closing this PR is a possible outcome as this is a non-essential fix.

@nadir-akhtar nadir-akhtar force-pushed the nadir/l-02-valid-0-leaves-fix branch 2 times, most recently from 4bbbcf9 to 10a1dac Compare August 6, 2025 20:55
nadir-akhtar and others added 4 commits August 8, 2025 13:27
<!-- 
    🚨 ATTENTION! 🚨 
    
This PR template is REQUIRED. PRs not following this format will be
closed without review.
    
    Requirements:
- PR title must follow commit conventions:
https://www.conventionalcommits.org/en/v1.0.0/
- Label your PR with the correct type (e.g., 🐛 Bug, ✨ Enhancement, 🧪
Test, etc.)
    - Provide clear and specific details in each section
-->

**Motivation:**

As part of an audit for the Merkle library, several low and
informational findings were found. This PR consolidates all
informational findings to fix, as well as additional commits for
findings discovered along the way, with a specific commit for each
finding.

All Lows are separated into individual PRs into the
[release-dev/merkle-audit-fixes](https://github.com/Layr-Labs/eigenlayer-contracts/tree/release-dev/merkle-audit-fixes)
branch

**Modifications:**

* Completely uplifted natspec, matching current EigenLayer quality and
standards
* Four new error codes:
  * `InvalidIndex` for indices outside of the Merkle tree's max index
* `LeavesNotPowerOfTwo` for leaves (particularly for SHA256 functions)
that don't match the expected length condition
  * `NoLeaves` for an empty `leaves` array
* `NotEnoughLeaves` for leaves (particularly for SHA256 functions) that
are not 2 or greater
* Explicit return in `processInclusionProofKeccak` for 0 length proofs
to return the leaf
* Requirement in `processInclusionProof(Keccak|Sha256)` that the index
is 0, i.e. the index was for a leaf within the tree
* Refactoring in `merkleize(Sha256|Keccak)` and `getProofKeccak` of
logic for readability and performance
* Newly added `getProofSha256` to mirror `getProofKeccak` to reduce
burden of producing roots offchain
* Newly added `isPowerOfTwo` helper function
* Newly added documentation file for the Merkle library

**Result:**

* Improved documentation/natspec
* Four new error codes
* Refactored and simplified code
* Newly added `getProofSha256` and `isPowerOfTwo` functions
* Updated and added unit tests
<!-- 
    🚨 ATTENTION! 🚨 
    
This PR template is REQUIRED. PRs not following this format will be
closed without review.
    
    Requirements:
- PR title must follow commit conventions:
https://www.conventionalcommits.org/en/v1.0.0/
- Label your PR with the correct type (e.g., 🐛 Bug, ✨ Enhancement, 🧪
Test, etc.)
    - Provide clear and specific details in each section
-->

**Motivation:**

Uninitialized roots can lead to issues like the [Nomad bridge
hack](https://medium.com/nomad-xyz-blog/nomad-bridge-hack-root-cause-analysis-875ad2e5aacd).

**Modifications:**

* New error code and documentation
* Added require statements for `verifyInclusion(Keccak|SHA256)`
* Updated documentation for existing error code

**Result:**

Guard against unintialized roots being used in proofs
@nadir-akhtar nadir-akhtar force-pushed the nadir/l-02-valid-0-leaves-fix branch from 10a1dac to 2dd643d Compare August 8, 2025 21:18
@nadir-akhtar nadir-akhtar force-pushed the release-dev/merkle-audit-fixes branch from 30ec964 to 2e9066c Compare August 12, 2025 21:28
Base automatically changed from release-dev/merkle-audit-fixes to main August 13, 2025 22:37
@github-actions github-actions Bot deleted the nadir/l-02-valid-0-leaves-fix branch November 15, 2025 00:17
@nadir-akhtar
Copy link
Copy Markdown
Collaborator Author

@claude Give this a brief review

@claude
Copy link
Copy Markdown

claude Bot commented Jan 30, 2026

Claude encountered an error —— View job

Command failed: git fetch origin --depth=20 nadir/l-02-valid-0-leaves-fix

I'll analyze this and get back to you.

@elhajin
Copy link
Copy Markdown
Contributor

elhajin commented Mar 17, 2026

@claude review that PR , and is it still relevant ?

@github-actions
Copy link
Copy Markdown

Skipped: PR diff failed to apply. Rebase and re-push.

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.

2 participants