Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
openzeppelin-contracts-upgradeable
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
俞永鹏
openzeppelin-contracts-upgradeable
Commits
30e20231
Commit
30e20231
authored
Jun 15, 2017
by
Yondon Fu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix indentation in MerkleProof.sol and remove mock contract
parent
2e0bd06d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
38 deletions
+26
-38
MerkleProof.sol
contracts/MerkleProof.sol
+26
-26
MerkleProofMock.sol
test/helpers/MerkleProofMock.sol
+0
-12
No files found.
contracts/MerkleProof.sol
View file @
30e20231
...
...
@@ -6,33 +6,33 @@ pragma solidity ^0.4.11;
* @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(bytes _proof, bytes32 _root, bytes32 _leaf) constant returns (bool) {
bytes32 proofElement;
bytes32 computedHash = _leaf;
/*
* @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(bytes _proof, bytes32 _root, bytes32 _leaf) constant returns (bool) {
bytes32 proofElement;
bytes32 computedHash = _leaf;
for (uint256 i = 32; i <= _proof.length; i += 32) {
assembly {
// Load the current element of the proof
proofElement := mload(add(_proof, i))
}
for (uint256 i = 32; i <= _proof.length; i += 32) {
assembly {
// Load the current element of the proof
proofElement := mload(add(_proof, i))
}
if (computedHash < proofElement) {
// Hash(current computed hash + current element of the proof)
computedHash = sha3(computedHash, proofElement);
} else {
// Hash(current element of the proof + current computed hash)
computedHash = sha3(proofElement, computedHash);
}
}
// Check if the computed hash (root) is equal to the provided root
return computedHash == _root;
if (computedHash < proofElement) {
// Hash(current computed hash + current element of the proof)
computedHash = sha3(computedHash, proofElement);
} else {
// Hash(current element of the proof + current computed hash)
computedHash = sha3(proofElement, computedHash);
}
}
// Check if the computed hash (root) is equal to the provided root
return computedHash == _root;
}
}
test/helpers/MerkleProofMock.sol
deleted
100644 → 0
View file @
2e0bd06d
pragma solidity ^0.4.11;
import '../../contracts/MerkleProof.sol';
contract MerkleProofMock {
bool public result;
function verifyProof(bytes _proof, bytes32 _root, bytes32 _leaf) {
result = MerkleProof.verifyProof(_proof, _root, _leaf);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment