Skip to content

Commit c304b67

Browse files
ernestognwcairoethpcaversaccio
authored
Update MerkleProof note clarifying empty set definition (#5144)
Co-authored-by: cairo <cairoeth@protonmail.com> Co-authored-by: sudo rm -rf --no-preserve-root / <pcaversaccio@users.noreply.github.com>
1 parent bcd4beb commit c304b67

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

contracts/utils/cryptography/MerkleProof.sol

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,8 @@ library MerkleProof {
169169
*
170170
* CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
171171
*
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.
172+
* NOTE: Consider the case where `root == proof[0] && leaves.length == 0` as it will return `true`.
173+
* The `leaves` must be validated independently. See {processMultiProof}.
175174
*/
176175
function multiProofVerify(
177176
bytes32[] memory proof,
@@ -193,6 +192,10 @@ library MerkleProof {
193192
* CAUTION: Not all Merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree
194193
* is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the
195194
* tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).
195+
*
196+
* NOTE: The _empty set_ (i.e. the case where `proof.length == 1 && leaves.length == 0`) is considered a no-op,
197+
* and therefore a valid multiproof (i.e. it returns `proof[0]`). Consider disallowing this case if you're not
198+
* validating the leaves elsewhere.
196199
*/
197200
function processMultiProof(
198201
bytes32[] memory proof,
@@ -252,9 +255,8 @@ library MerkleProof {
252255
*
253256
* CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
254257
*
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.
258+
* NOTE: Consider the case where `root == proof[0] && leaves.length == 0` as it will return `true`.
259+
* The `leaves` must be validated independently. See {processMultiProof}.
258260
*/
259261
function multiProofVerify(
260262
bytes32[] memory proof,
@@ -277,6 +279,10 @@ library MerkleProof {
277279
* CAUTION: Not all Merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree
278280
* is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the
279281
* tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).
282+
*
283+
* NOTE: The _empty set_ (i.e. the case where `proof.length == 1 && leaves.length == 0`) is considered a no-op,
284+
* and therefore a valid multiproof (i.e. it returns `proof[0]`). Consider disallowing this case if you're not
285+
* validating the leaves elsewhere.
280286
*/
281287
function processMultiProof(
282288
bytes32[] memory proof,
@@ -337,9 +343,8 @@ library MerkleProof {
337343
*
338344
* CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
339345
*
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.
346+
* NOTE: Consider the case where `root == proof[0] && leaves.length == 0` as it will return `true`.
347+
* The `leaves` must be validated independently. See {processMultiProofCalldata}.
343348
*/
344349
function multiProofVerifyCalldata(
345350
bytes32[] calldata proof,
@@ -361,6 +366,10 @@ library MerkleProof {
361366
* CAUTION: Not all Merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree
362367
* is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the
363368
* tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).
369+
*
370+
* NOTE: The _empty set_ (i.e. the case where `proof.length == 1 && leaves.length == 0`) is considered a no-op,
371+
* and therefore a valid multiproof (i.e. it returns `proof[0]`). Consider disallowing this case if you're not
372+
* validating the leaves elsewhere.
364373
*/
365374
function processMultiProofCalldata(
366375
bytes32[] calldata proof,
@@ -420,9 +429,8 @@ library MerkleProof {
420429
*
421430
* CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
422431
*
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.
432+
* NOTE: Consider the case where `root == proof[0] && leaves.length == 0` as it will return `true`.
433+
* The `leaves` must be validated independently. See {processMultiProofCalldata}.
426434
*/
427435
function multiProofVerifyCalldata(
428436
bytes32[] calldata proof,
@@ -445,6 +453,10 @@ library MerkleProof {
445453
* CAUTION: Not all Merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree
446454
* is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the
447455
* tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).
456+
*
457+
* NOTE: The _empty set_ (i.e. the case where `proof.length == 1 && leaves.length == 0`) is considered a no-op,
458+
* and therefore a valid multiproof (i.e. it returns `proof[0]`). Consider disallowing this case if you're not
459+
* validating the leaves elsewhere.
448460
*/
449461
function processMultiProofCalldata(
450462
bytes32[] calldata proof,

scripts/generate/templates/MerkleProof.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,8 @@ const templateMultiProof = ({ suffix, location, visibility, hash }) => `\
8989
*
9090
* CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
9191
*
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.
92+
* NOTE: Consider the case where \`root == proof[0] && leaves.length == 0\` as it will return \`true\`.
93+
* The \`leaves\` must be validated independently. See {processMultiProof${suffix}}.
9594
*/
9695
function multiProofVerify${suffix}(${formatArgsMultiline(
9796
`bytes32[] ${location} proof`,
@@ -114,6 +113,10 @@ function multiProofVerify${suffix}(${formatArgsMultiline(
114113
* CAUTION: Not all Merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree
115114
* is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the
116115
* tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).
116+
*
117+
* NOTE: The _empty set_ (i.e. the case where \`proof.length == 1 && leaves.length == 0\`) is considered a no-op,
118+
* and therefore a valid multiproof (i.e. it returns \`proof[0]\`). Consider disallowing this case if you're not
119+
* validating the leaves elsewhere.
117120
*/
118121
function processMultiProof${suffix}(${formatArgsMultiline(
119122
`bytes32[] ${location} proof`,

0 commit comments

Comments
 (0)