Skip to content

Commit bcd4beb

Browse files
authored
Make explicit the validity of the empty set in MerkleProof.sol (#5142)
1 parent 24a641d commit bcd4beb

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

contracts/utils/cryptography/MerkleProof.sol

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ library MerkleProof {
168168
* This version handles multiproofs in memory with the default hashing function.
169169
*
170170
* CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
171+
*
172+
* NOTE: The _empty set_ (i.e. the case where `proof.length == 0 && leaves.length == 0`) is considered a noop,
173+
* and therefore a valid multiproof (i.e. it returns `true`). Consider disallowing this case if you're not
174+
* validating the leaves elsewhere.
171175
*/
172176
function multiProofVerify(
173177
bytes32[] memory proof,
@@ -247,6 +251,10 @@ library MerkleProof {
247251
* This version handles multiproofs in memory with a custom hashing function.
248252
*
249253
* CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
254+
*
255+
* NOTE: The _empty set_ (i.e. the case where `proof.length == 0 && leaves.length == 0`) is considered a noop,
256+
* and therefore a valid multiproof (i.e. it returns `true`). Consider disallowing this case if you're not
257+
* validating the leaves elsewhere.
250258
*/
251259
function multiProofVerify(
252260
bytes32[] memory proof,
@@ -328,6 +336,10 @@ library MerkleProof {
328336
* This version handles multiproofs in calldata with the default hashing function.
329337
*
330338
* CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
339+
*
340+
* NOTE: The _empty set_ (i.e. the case where `proof.length == 0 && leaves.length == 0`) is considered a noop,
341+
* and therefore a valid multiproof (i.e. it returns `true`). Consider disallowing this case if you're not
342+
* validating the leaves elsewhere.
331343
*/
332344
function multiProofVerifyCalldata(
333345
bytes32[] calldata proof,
@@ -407,6 +419,10 @@ library MerkleProof {
407419
* This version handles multiproofs in calldata with a custom hashing function.
408420
*
409421
* CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
422+
*
423+
* NOTE: The _empty set_ (i.e. the case where `proof.length == 0 && leaves.length == 0`) is considered a noop,
424+
* and therefore a valid multiproof (i.e. it returns `true`). Consider disallowing this case if you're not
425+
* validating the leaves elsewhere.
410426
*/
411427
function multiProofVerifyCalldata(
412428
bytes32[] calldata proof,

scripts/generate/templates/MerkleProof.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ const templateMultiProof = ({ suffix, location, visibility, hash }) => `\
8888
* This version handles multiproofs in ${location} with ${hash ? 'a custom' : 'the default'} hashing function.
8989
*
9090
* CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
91+
*
92+
* NOTE: The _empty set_ (i.e. the case where \`proof.length == 0 && leaves.length == 0\`) is considered a noop,
93+
* and therefore a valid multiproof (i.e. it returns \`true\`). Consider disallowing this case if you're not
94+
* validating the leaves elsewhere.
9195
*/
9296
function multiProofVerify${suffix}(${formatArgsMultiline(
9397
`bytes32[] ${location} proof`,

0 commit comments

Comments
 (0)