|
@@ -41,12 +41,20 @@ library MerkleProof {
|
|
bytes32 proofElement = proof[i];
|
|
bytes32 proofElement = proof[i];
|
|
if (computedHash <= proofElement) {
|
|
if (computedHash <= proofElement) {
|
|
// Hash(current computed hash + current element of the proof)
|
|
// Hash(current computed hash + current element of the proof)
|
|
- computedHash = keccak256(abi.encodePacked(computedHash, proofElement));
|
|
|
|
|
|
+ computedHash = _efficientHash(computedHash, proofElement);
|
|
} else {
|
|
} else {
|
|
// Hash(current element of the proof + current computed hash)
|
|
// Hash(current element of the proof + current computed hash)
|
|
- computedHash = keccak256(abi.encodePacked(proofElement, computedHash));
|
|
|
|
|
|
+ computedHash = _efficientHash(proofElement, computedHash);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return computedHash;
|
|
return computedHash;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ function _efficientHash(bytes32 a, bytes32 b) private pure returns (bytes32 value) {
|
|
|
|
+ assembly {
|
|
|
|
+ mstore(0x00, a)
|
|
|
|
+ mstore(0x20, b)
|
|
|
|
+ value := keccak256(0x00, 0x40)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|