You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
951 B
29 lines
951 B
// 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)
|
|
}
|
|
}
|
|
}
|
|
|