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
06666be9
Unverified
Commit
06666be9
authored
Apr 08, 2018
by
Francisco Giordano
Committed by
GitHub
Apr 08, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change MerkleProof interface to take array of bytes32 (#879)
parent
915f74c5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
16 deletions
+6
-16
MerkleProof.sol
contracts/MerkleProof.sol
+3
-13
merkleTree.js
test/helpers/merkleTree.js
+3
-3
No files found.
contracts/MerkleProof.sol
View file @
06666be9
...
@@ -14,21 +14,11 @@ library MerkleProof {
...
@@ -14,21 +14,11 @@ library MerkleProof {
* @param _root Merkle root
* @param _root Merkle root
* @param _leaf Leaf of Merkle tree
* @param _leaf Leaf of Merkle tree
*/
*/
function verifyProof(bytes _proof, bytes32 _root, bytes32 _leaf) public pure returns (bool) {
function verifyProof(bytes32[] _proof, bytes32 _root, bytes32 _leaf) public pure returns (bool) {
// Check if proof length is a multiple of 32
if (_proof.length % 32 != 0) {
return false;
}
bytes32 proofElement;
bytes32 computedHash = _leaf;
bytes32 computedHash = _leaf;
for (uint256 i = 32; i <= _proof.length; i += 32) {
for (uint256 i = 0; i < _proof.length; i++) {
// solium-disable-next-line security/no-inline-assembly
bytes32 proofElement = _proof[i];
assembly {
// Load the current element of the proof
proofElement := mload(add(_proof, i))
}
if (computedHash < proofElement) {
if (computedHash < proofElement) {
// Hash(current computed hash + current element of the proof)
// Hash(current computed hash + current element of the proof)
...
...
test/helpers/merkleTree.js
View file @
06666be9
...
@@ -79,7 +79,7 @@ export default class MerkleTree {
...
@@ -79,7 +79,7 @@ export default class MerkleTree {
getHexProof
(
el
)
{
getHexProof
(
el
)
{
const
proof
=
this
.
getProof
(
el
);
const
proof
=
this
.
getProof
(
el
);
return
this
.
bufArrToHex
(
proof
);
return
this
.
bufArrToHex
Arr
(
proof
);
}
}
getPairElement
(
idx
,
layer
)
{
getPairElement
(
idx
,
layer
)
{
...
@@ -117,12 +117,12 @@ export default class MerkleTree {
...
@@ -117,12 +117,12 @@ export default class MerkleTree {
});
});
}
}
bufArrToHex
(
arr
)
{
bufArrToHex
Arr
(
arr
)
{
if
(
arr
.
some
(
el
=>
!
Buffer
.
isBuffer
(
el
)))
{
if
(
arr
.
some
(
el
=>
!
Buffer
.
isBuffer
(
el
)))
{
throw
new
Error
(
'Array is not an array of buffers'
);
throw
new
Error
(
'Array is not an array of buffers'
);
}
}
return
'0x'
+
arr
.
map
(
el
=>
el
.
toString
(
'hex'
)).
join
(
''
);
return
arr
.
map
(
el
=>
'0x'
+
el
.
toString
(
'hex'
)
);
}
}
sortAndConcat
(...
args
)
{
sortAndConcat
(...
args
)
{
...
...
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