-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…dity Feature/#20 airdrop liquidity
- Loading branch information
Showing
3 changed files
with
201 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// SPDX-License-Identifier: MIT | ||
// Modified from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.3.0/contracts/utils/cryptography/MerkleProof.sol | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
/** | ||
* @dev These functions deal with verification of Merkle Trees proofs. | ||
* | ||
* The proofs can be generated using the JavaScript library | ||
* https://github.com/miguelmota/merkletreejs[merkletreejs]. | ||
* Note: the hashing algorithm should be keccak256 and pair sorting should be enabled. | ||
* | ||
* See `test/utils/cryptography/MerkleProof.test.js` for some examples. | ||
*/ | ||
library MerkleProof { | ||
/** | ||
* @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree | ||
* defined by `root`. For this, a `proof` must be provided, containing | ||
* sibling hashes on the branch from the leaf to the root of the tree. Each | ||
* pair of leaves and each pair of pre-images are assumed to be sorted. | ||
*/ | ||
function verify( | ||
bytes32[] memory proof, | ||
bytes32 root, | ||
bytes32 leaf | ||
) internal pure returns (bool, uint256) { | ||
bytes32 computedHash = leaf; | ||
uint256 index = 0; | ||
|
||
for (uint256 i = 0; i < proof.length; i++) { | ||
index *= 2; | ||
bytes32 proofElement = proof[i]; | ||
|
||
if (computedHash <= proofElement) { | ||
// Hash(current computed hash + current element of the proof) | ||
computedHash = keccak256(abi.encodePacked(computedHash, proofElement)); | ||
} else { | ||
// Hash(current element of the proof + current computed hash) | ||
computedHash = keccak256(abi.encodePacked(proofElement, computedHash)); | ||
index += 1; | ||
} | ||
} | ||
|
||
// Check if the computed hash (root) is equal to the provided root | ||
return (computedHash == root, index); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters