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
72289cf6
Commit
72289cf6
authored
Mar 13, 2021
by
github-actions
Browse files
Options
Browse Files
Download
Plain Diff
Merge upstream openzeppelin-contracts into upstream-patched
parents
91dc5604
d5194725
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
7 deletions
+13
-7
MerkleProof.sol
contracts/utils/cryptography/MerkleProof.sol
+7
-1
EnumerableSet.sol
contracts/utils/structs/EnumerableSet.sol
+1
-1
MerkleProof.test.js
test/utils/cryptography/MerkleProof.test.js
+5
-5
No files found.
contracts/utils/cryptography/MerkleProof.sol
View file @
72289cf6
...
...
@@ -3,7 +3,13 @@
pragma solidity ^0.8.0;
/**
* @dev These functions deal with verification of Merkle trees (hash trees),
* @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 {
/**
...
...
contracts/utils/structs/EnumerableSet.sol
View file @
72289cf6
...
...
@@ -89,7 +89,7 @@ library EnumerableSet {
// Move the last value to the index where the value to delete is
set._values[toDeleteIndex] = lastvalue;
// Update the index for the moved value
set._indexes[lastvalue] =
toDeleteIndex + 1; // All indexes are 1-based
set._indexes[lastvalue] =
valueIndex; // Replace lastvalue's index to valueIndex
// Delete the slot where the moved value was stored
set._values.pop();
...
...
test/utils/cryptography/MerkleProof.test.js
View file @
72289cf6
...
...
@@ -14,8 +14,8 @@ contract('MerkleProof', function (accounts) {
describe
(
'verify'
,
function
()
{
it
(
'returns true for a valid Merkle proof'
,
async
function
()
{
const
elements
=
[
'a'
,
'b'
,
'c'
,
'd'
]
;
const
merkleTree
=
new
MerkleTree
(
elements
,
keccak256
,
{
hashLeaves
:
true
});
const
elements
=
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
.
split
(
''
)
;
const
merkleTree
=
new
MerkleTree
(
elements
,
keccak256
,
{
hashLeaves
:
true
,
sortPairs
:
true
});
const
root
=
merkleTree
.
getHexRoot
();
...
...
@@ -28,7 +28,7 @@ contract('MerkleProof', function (accounts) {
it
(
'returns false for an invalid Merkle proof'
,
async
function
()
{
const
correctElements
=
[
'a'
,
'b'
,
'c'
];
const
correctMerkleTree
=
new
MerkleTree
(
correctElements
,
keccak256
,
{
hashLeaves
:
true
});
const
correctMerkleTree
=
new
MerkleTree
(
correctElements
,
keccak256
,
{
hashLeaves
:
true
,
sortPairs
:
true
});
const
correctRoot
=
correctMerkleTree
.
getHexRoot
();
...
...
@@ -37,14 +37,14 @@ contract('MerkleProof', function (accounts) {
const
badElements
=
[
'd'
,
'e'
,
'f'
];
const
badMerkleTree
=
new
MerkleTree
(
badElements
);
const
badProof
=
badMerkleTree
.
getHexProof
(
badElements
[
0
],
keccak256
,
{
hashLeaves
:
true
});
const
badProof
=
badMerkleTree
.
getHexProof
(
badElements
[
0
],
keccak256
,
{
hashLeaves
:
true
,
sortPairs
:
true
});
expect
(
await
this
.
merkleProof
.
verify
(
badProof
,
correctRoot
,
correctLeaf
)).
to
.
equal
(
false
);
});
it
(
'returns false for a Merkle proof of invalid length'
,
async
function
()
{
const
elements
=
[
'a'
,
'b'
,
'c'
];
const
merkleTree
=
new
MerkleTree
(
elements
,
keccak256
,
{
hashLeaves
:
true
});
const
merkleTree
=
new
MerkleTree
(
elements
,
keccak256
,
{
hashLeaves
:
true
,
sortPairs
:
true
});
const
root
=
merkleTree
.
getHexRoot
();
...
...
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