1234567891011121314151617181920212223242526272829 |
- // SPDX-License-Identifier: MIT
- pragma solidity ^0.8.0;
- /**
- * @dev Library of standard hash functions.
- */
- library Hashes {
- /**
- * @dev Commutative Keccak256 hash of a sorted pair of bytes32. Frequently used when working with merkle proofs.
- *
- * NOTE: Equivalent to the `standardNodeHash` in our https://github.com/OpenZeppelin/merkle-tree[JavaScript library].
- */
- function commutativeKeccak256(bytes32 a, bytes32 b) internal pure returns (bytes32) {
- return a < b ? _efficientKeccak256(a, b) : _efficientKeccak256(b, a);
- }
- /**
- * @dev Implementation of keccak256(abi.encode(a, b)) that doesn't allocate or expand memory.
- */
- function _efficientKeccak256(bytes32 a, bytes32 b) private pure returns (bytes32 value) {
- /// @solidity memory-safe-assembly
- assembly {
- mstore(0x00, a)
- mstore(0x20, b)
- value := keccak256(0x00, 0x40)
- }
- }
- }
|