From 93cd2ecb73d38dbe1f471e2387deebefa4b0c012 Mon Sep 17 00:00:00 2001 From: Pascal Marco Caversaccio Date: Mon, 5 Dec 2022 14:41:44 +0100 Subject: [PATCH] Improve readability of processMultiProof (#3854) Signed-off-by: Pascal Marco Caversaccio --- contracts/utils/cryptography/MerkleProof.sol | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/contracts/utils/cryptography/MerkleProof.sol b/contracts/utils/cryptography/MerkleProof.sol index 938bd96e1..47c60eb01 100644 --- a/contracts/utils/cryptography/MerkleProof.sol +++ b/contracts/utils/cryptography/MerkleProof.sol @@ -124,7 +124,7 @@ library MerkleProof { bool[] memory proofFlags, bytes32[] memory leaves ) internal pure returns (bytes32 merkleRoot) { - // This function rebuild the root hash by traversing the tree up from the leaves. The root is rebuilt by + // This function rebuilds the root hash by traversing the tree up from the leaves. The root is rebuilt by // consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the // `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of // the merkle tree. @@ -147,7 +147,9 @@ library MerkleProof { // `proof` array. for (uint256 i = 0; i < totalHashes; i++) { bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++]; - bytes32 b = proofFlags[i] ? leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++] : proof[proofPos++]; + bytes32 b = proofFlags[i] + ? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++]) + : proof[proofPos++]; hashes[i] = _hashPair(a, b); } @@ -172,7 +174,7 @@ library MerkleProof { bool[] calldata proofFlags, bytes32[] memory leaves ) internal pure returns (bytes32 merkleRoot) { - // This function rebuild the root hash by traversing the tree up from the leaves. The root is rebuilt by + // This function rebuilds the root hash by traversing the tree up from the leaves. The root is rebuilt by // consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the // `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of // the merkle tree. @@ -195,7 +197,9 @@ library MerkleProof { // `proof` array. for (uint256 i = 0; i < totalHashes; i++) { bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++]; - bytes32 b = proofFlags[i] ? leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++] : proof[proofPos++]; + bytes32 b = proofFlags[i] + ? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++]) + : proof[proofPos++]; hashes[i] = _hashPair(a, b); }