Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make explicit the validity of the empty set in MerkleProof.sol #5142

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -246,6 +250,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 @@ -326,6 +334,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 @@ -404,6 +416,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