Skip to content

Commit a503ba1

Browse files
authored
Avoid overflow on empty multiproof (#4564)
1 parent c0545f7 commit a503ba1

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

.changeset/large-humans-remain.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'openzeppelin-solidity': patch
3+
---
4+
5+
`MerkleProof`: Use custom error to report invalid multiproof instead of reverting with overflow panic.

contracts/utils/cryptography/MerkleProof.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ library MerkleProof {
118118
uint256 totalHashes = proofFlags.length;
119119

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

@@ -174,7 +174,7 @@ library MerkleProof {
174174
uint256 totalHashes = proofFlags.length;
175175

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

0 commit comments

Comments
 (0)