Skip to content

Commit

Permalink
Update MerkleProof note clarifying empty set definition (#5144)
Browse files Browse the repository at this point in the history
Co-authored-by: cairo <cairoeth@protonmail.com>
Co-authored-by: sudo rm -rf --no-preserve-root / <pcaversaccio@users.noreply.github.com>
Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com>
  • Loading branch information
3 people authored and Amxx committed Oct 2, 2024
1 parent da072a2 commit 0e7f530
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
36 changes: 24 additions & 12 deletions contracts/utils/cryptography/MerkleProof.sol
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,8 @@ library MerkleProof {
*
* 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.
* NOTE: Consider the case where `root == proof[0] && leaves.length == 0` as it will return `true`.
* The `leaves` must be validated independently. See {processMultiProof}.
*/
function multiProofVerify(
bytes32[] memory proof,
Expand All @@ -193,6 +192,10 @@ library MerkleProof {
* CAUTION: Not all Merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree
* is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the
* tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).
*
* NOTE: The _empty set_ (i.e. the case where `proof.length == 1 && leaves.length == 0`) is considered a no-op,
* and therefore a valid multiproof (i.e. it returns `proof[0]`). Consider disallowing this case if you're not
* validating the leaves elsewhere.
*/
function processMultiProof(
bytes32[] memory proof,
Expand Down Expand Up @@ -252,9 +255,8 @@ library MerkleProof {
*
* 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.
* NOTE: Consider the case where `root == proof[0] && leaves.length == 0` as it will return `true`.
* The `leaves` must be validated independently. See {processMultiProof}.
*/
function multiProofVerify(
bytes32[] memory proof,
Expand All @@ -277,6 +279,10 @@ library MerkleProof {
* CAUTION: Not all Merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree
* is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the
* tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).
*
* NOTE: The _empty set_ (i.e. the case where `proof.length == 1 && leaves.length == 0`) is considered a no-op,
* and therefore a valid multiproof (i.e. it returns `proof[0]`). Consider disallowing this case if you're not
* validating the leaves elsewhere.
*/
function processMultiProof(
bytes32[] memory proof,
Expand Down Expand Up @@ -337,9 +343,8 @@ library MerkleProof {
*
* 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.
* NOTE: Consider the case where `root == proof[0] && leaves.length == 0` as it will return `true`.
* The `leaves` must be validated independently. See {processMultiProofCalldata}.
*/
function multiProofVerifyCalldata(
bytes32[] calldata proof,
Expand All @@ -361,6 +366,10 @@ library MerkleProof {
* CAUTION: Not all Merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree
* is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the
* tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).
*
* NOTE: The _empty set_ (i.e. the case where `proof.length == 1 && leaves.length == 0`) is considered a no-op,
* and therefore a valid multiproof (i.e. it returns `proof[0]`). Consider disallowing this case if you're not
* validating the leaves elsewhere.
*/
function processMultiProofCalldata(
bytes32[] calldata proof,
Expand Down Expand Up @@ -420,9 +429,8 @@ library MerkleProof {
*
* 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.
* NOTE: Consider the case where `root == proof[0] && leaves.length == 0` as it will return `true`.
* The `leaves` must be validated independently. See {processMultiProofCalldata}.
*/
function multiProofVerifyCalldata(
bytes32[] calldata proof,
Expand All @@ -445,6 +453,10 @@ library MerkleProof {
* CAUTION: Not all Merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree
* is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the
* tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).
*
* NOTE: The _empty set_ (i.e. the case where `proof.length == 1 && leaves.length == 0`) is considered a no-op,
* and therefore a valid multiproof (i.e. it returns `proof[0]`). Consider disallowing this case if you're not
* validating the leaves elsewhere.
*/
function processMultiProofCalldata(
bytes32[] calldata proof,
Expand Down
9 changes: 6 additions & 3 deletions scripts/generate/templates/MerkleProof.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@ const templateMultiProof = ({ suffix, location, visibility, hash }) => `\
*
* 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.
* NOTE: Consider the case where \`root == proof[0] && leaves.length == 0\` as it will return \`true\`.
* The \`leaves\` must be validated independently. See {processMultiProof${suffix}}.
*/
function multiProofVerify${suffix}(${formatArgsMultiline(
`bytes32[] ${location} proof`,
Expand All @@ -114,6 +113,10 @@ function multiProofVerify${suffix}(${formatArgsMultiline(
* CAUTION: Not all Merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree
* is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the
* tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).
*
* NOTE: The _empty set_ (i.e. the case where \`proof.length == 1 && leaves.length == 0\`) is considered a no-op,
* and therefore a valid multiproof (i.e. it returns \`proof[0]\`). Consider disallowing this case if you're not
* validating the leaves elsewhere.
*/
function processMultiProof${suffix}(${formatArgsMultiline(
`bytes32[] ${location} proof`,
Expand Down

0 comments on commit 0e7f530

Please sign in to comment.