* Update to ganache-cli v6.1.0 and truffle v4.1.0 * Update to stable version of ganache-cli * fix: update event emission warning - Fix event emission warnings for solidity 4.21 after truffle has been updated to use this version * fix pr review comments * update to truffle v4.1.5 * update package-lock * add additional emit keywords * update solidity-coverage to 0.4.15 * update to solium 1.1.6 * fix MerkleProof coverage analysis by testing through wrapper * change version pragma to ^0.4.21 * fix solium linting errors
36 lines
1.2 KiB
Solidity
36 lines
1.2 KiB
Solidity
pragma solidity ^0.4.21;
|
|
|
|
|
|
/*
|
|
* @title MerkleProof
|
|
* @dev Merkle proof verification
|
|
* @note Based on https://github.com/ameensol/merkle-tree-solidity/blob/master/src/MerkleProof.sol
|
|
*/
|
|
library MerkleProof {
|
|
/*
|
|
* @dev Verifies a Merkle proof proving the existence of a leaf in a Merkle tree. Assumes that each pair of leaves
|
|
* and each pair of pre-images is sorted.
|
|
* @param _proof Merkle proof containing sibling hashes on the branch from the leaf to the root of the Merkle tree
|
|
* @param _root Merkle root
|
|
* @param _leaf Leaf of Merkle tree
|
|
*/
|
|
function verifyProof(bytes32[] _proof, bytes32 _root, bytes32 _leaf) internal pure returns (bool) {
|
|
bytes32 computedHash = _leaf;
|
|
|
|
for (uint256 i = 0; i < _proof.length; i++) {
|
|
bytes32 proofElement = _proof[i];
|
|
|
|
if (computedHash < proofElement) {
|
|
// Hash(current computed hash + current element of the proof)
|
|
computedHash = keccak256(computedHash, proofElement);
|
|
} else {
|
|
// Hash(current element of the proof + current computed hash)
|
|
computedHash = keccak256(proofElement, computedHash);
|
|
}
|
|
}
|
|
|
|
// Check if the computed hash (root) is equal to the provided root
|
|
return computedHash == _root;
|
|
}
|
|
}
|