12345678910111213141516171819202122232425262728293031 |
- // SPDX-License-Identifier: MIT
- // OpenZeppelin Contracts (last updated v5.3.0-rc.0) (utils/cryptography/Hashes.sol)
- pragma solidity ^0.8.20;
- /**
- * @dev Library of standard hash functions.
- *
- * _Available since v5.1._
- */
- 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) internal pure returns (bytes32 value) {
- assembly ("memory-safe") {
- mstore(0x00, a)
- mstore(0x20, b)
- value := keccak256(0x00, 0x40)
- }
- }
- }
|