Skip to content

Commit

Permalink
Make explicit the validity of the empty set in MerkleProof.sol (OpenZ…
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestognw committed Aug 7, 2024
1 parent 0af6561 commit b10df77
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions contracts/utils/cryptography/MerkleProof.sol
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ library MerkleProof {
* This version handles multiproofs in memory with the default hashing function.
*
* CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
*
* NOTE: The _empty set_ (i.e. the case where `proof.length == 0 && leaves.length == 0`) is considered a noop,
* and therefore a valid multiproof (i.e. it returns `true`). Consider disallowing this case if you're not
* validating the leaves elsewhere.
*/
function multiProofVerify(
bytes32[] memory proof,
Expand Down Expand Up @@ -247,6 +251,10 @@ library MerkleProof {
* This version handles multiproofs in memory with a custom hashing function.
*
* CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
*
* NOTE: The _empty set_ (i.e. the case where `proof.length == 0 && leaves.length == 0`) is considered a noop,
* and therefore a valid multiproof (i.e. it returns `true`). Consider disallowing this case if you're not
* validating the leaves elsewhere.
*/
function multiProofVerify(
bytes32[] memory proof,
Expand Down Expand Up @@ -328,6 +336,10 @@ library MerkleProof {
* This version handles multiproofs in calldata with the default hashing function.
*
* CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
*
* NOTE: The _empty set_ (i.e. the case where `proof.length == 0 && leaves.length == 0`) is considered a noop,
* and therefore a valid multiproof (i.e. it returns `true`). Consider disallowing this case if you're not
* validating the leaves elsewhere.
*/
function multiProofVerifyCalldata(
bytes32[] calldata proof,
Expand Down Expand Up @@ -407,6 +419,10 @@ library MerkleProof {
* This version handles multiproofs in calldata with a custom hashing function.
*
* CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
*
* NOTE: The _empty set_ (i.e. the case where `proof.length == 0 && leaves.length == 0`) is considered a noop,
* and therefore a valid multiproof (i.e. it returns `true`). Consider disallowing this case if you're not
* validating the leaves elsewhere.
*/
function multiProofVerifyCalldata(
bytes32[] calldata proof,
Expand Down
4 changes: 4 additions & 0 deletions scripts/generate/templates/MerkleProof.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ const templateMultiProof = ({ suffix, location, visibility, hash }) => `\
* This version handles multiproofs in ${location} with ${hash ? 'a custom' : 'the default'} hashing function.
*
* CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
*
* NOTE: The _empty set_ (i.e. the case where \`proof.length == 0 && leaves.length == 0\`) is considered a noop,
* and therefore a valid multiproof (i.e. it returns \`true\`). Consider disallowing this case if you're not
* validating the leaves elsewhere.
*/
function multiProofVerify${suffix}(${formatArgsMultiline(
`bytes32[] ${location} proof`,
Expand Down

0 comments on commit b10df77

Please sign in to comment.