Skip to content

Commit

Permalink
Avoid overflow on empty multiproof (#4564)
Browse files Browse the repository at this point in the history
  • Loading branch information
frangio authored Sep 4, 2023
1 parent c0545f7 commit a503ba1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/large-humans-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': patch
---

`MerkleProof`: Use custom error to report invalid multiproof instead of reverting with overflow panic.
4 changes: 2 additions & 2 deletions contracts/utils/cryptography/MerkleProof.sol
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ library MerkleProof {
uint256 totalHashes = proofFlags.length;

// Check proof validity.
if (leavesLen + proofLen - 1 != totalHashes) {
if (leavesLen + proofLen != totalHashes + 1) {
revert MerkleProofInvalidMultiproof();
}

Expand Down Expand Up @@ -174,7 +174,7 @@ library MerkleProof {
uint256 totalHashes = proofFlags.length;

// Check proof validity.
if (leavesLen + proofLen - 1 != totalHashes) {
if (leavesLen + proofLen != totalHashes + 1) {
revert MerkleProofInvalidMultiproof();
}

Expand Down

0 comments on commit a503ba1

Please sign in to comment.