Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com> Co-authored-by: cairo <cairoeth@protonmail.com> Co-authored-by: Ernesto García <ernestognw@gmail.com> Co-authored-by: sudo rm -rf --no-preserve-root / <pcaversaccio@users.noreply.github.com> Co-authored-by: danilo neves cruz <cruzdanilo@gmail.com> Co-authored-by: omahs <73983677+omahs@users.noreply.github.com> Co-authored-by: skyge <1506186404li@gmail.com> Co-authored-by: PurrProof <149718167+PurrProof@users.noreply.github.com> Co-authored-by: Eric Lau <ericglau@outlook.com> Co-authored-by: plooten <sunxingzhecrypto@gmail.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Md Zartaj Afser <91191500+Zartaj0@users.noreply.github.com>
32 lines
1.0 KiB
Solidity
32 lines
1.0 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
// OpenZeppelin Contracts (last updated v5.1.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) private pure returns (bytes32 value) {
|
|
assembly ("memory-safe") {
|
|
mstore(0x00, a)
|
|
mstore(0x20, b)
|
|
value := keccak256(0x00, 0x40)
|
|
}
|
|
}
|
|
}
|