feat: add detector for singly-hashed Merkle leaves#2946
Open
ep0chzer0 wants to merge 2 commits intocrytic:masterfrom
Open
feat: add detector for singly-hashed Merkle leaves#2946ep0chzer0 wants to merge 2 commits intocrytic:masterfrom
ep0chzer0 wants to merge 2 commits intocrytic:masterfrom
Conversation
aff7cf3 to
24c4892
Compare
Adds a new detector that identifies potential second preimage attacks on Merkle trees when using OpenZeppelin's MerkleProof library. The detector flags cases where the leaf parameter passed to MerkleProof.verify(), verifyCalldata(), processProof(), or processProofCalldata() has fewer than 2 keccak256 hashes applied. Without double-hashing, attackers can potentially forge proofs by presenting intermediate nodes as leaves. Closes crytic#2675 Reference: https://www.rareskills.io/post/merkle-tree-second-preimage-attack
Adds the required test files: - Compiled zip artifact for merkle_singly_hashed_leaf.sol - Snapshot file with expected detector output (5 findings)
24c4892 to
4406e9a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new detector that identifies potential second preimage attacks on Merkle trees when using OpenZeppelin's MerkleProof library.
MerkleProof.verify(),verifyCalldata(),processProof(), andprocessProofCalldata()leafparameter backwards to count keccak256 applicationsCloses #2675
The Vulnerability
When using Merkle proofs, leaves should be double-hashed (
keccak256(keccak256(data))) to prevent second preimage attacks. If a leaf is only singly-hashed or not hashed at all, an attacker who knows an intermediate node value (64 bytes) can forge a valid proof.Reference: https://www.rareskills.io/post/merkle-tree-second-preimage-attack
Example Detection
Test Plan
Note: The test zip artifact and snapshot file need to be generated. I can update once CI runs or if maintainers can provide guidance on generating these without local solc.
Files Changed
slither/detectors/statements/merkle_singly_hashed_leaf.py- New detectorslither/detectors/all_detectors.py- Registrationtests/e2e/detectors/test_detectors.py- Test registrationtests/e2e/detectors/test_data/merkle-singly-hashed-leaf/0.8.20/merkle_singly_hashed_leaf.sol- Test contract