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
4f8af2dc
Unverified
Commit
4f8af2dc
authored
Jan 31, 2022
by
Doug Hoyte
Committed by
GitHub
Jan 31, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test and docs describing a misuse of MerkleProof (#3090)
Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
parent
a81b07ce
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
1 deletions
+12
-1
MerkleProof.sol
contracts/utils/cryptography/MerkleProof.sol
+6
-1
MerkleProof.test.js
test/utils/cryptography/MerkleProof.test.js
+6
-0
No files found.
contracts/utils/cryptography/MerkleProof.sol
View file @
4f8af2dc
...
@@ -11,6 +11,11 @@ pragma solidity ^0.8.0;
...
@@ -11,6 +11,11 @@ pragma solidity ^0.8.0;
* Note: the hashing algorithm should be keccak256 and pair sorting should be enabled.
* Note: the hashing algorithm should be keccak256 and pair sorting should be enabled.
*
*
* See `test/utils/cryptography/MerkleProof.test.js` for some examples.
* See `test/utils/cryptography/MerkleProof.test.js` for some examples.
*
* WARNING: You should avoid using leaf values that are 64 bytes long prior to
* hashing, or use a hash function other than keccak256 for hashing leaves.
* This is because the concatenation of a sorted pair of internal nodes in
* the merkle tree could be reinterpreted as a leaf value.
*/
*/
library MerkleProof {
library MerkleProof {
/**
/**
...
@@ -28,7 +33,7 @@ library MerkleProof {
...
@@ -28,7 +33,7 @@ library MerkleProof {
}
}
/**
/**
* @dev Returns the rebuilt hash obtained by traversing a Merkle
e
tree up
* @dev Returns the rebuilt hash obtained by traversing a Merkle tree up
* from `leaf` using `proof`. A `proof` is valid if and only if the rebuilt
* from `leaf` using `proof`. A `proof` is valid if and only if the rebuilt
* hash matches the root of the tree. When processing the proof, the pairs
* hash matches the root of the tree. When processing the proof, the pairs
* of leafs & pre-images are assumed to be sorted.
* of leafs & pre-images are assumed to be sorted.
...
...
test/utils/cryptography/MerkleProof.test.js
View file @
4f8af2dc
...
@@ -24,6 +24,12 @@ contract('MerkleProof', function (accounts) {
...
@@ -24,6 +24,12 @@ contract('MerkleProof', function (accounts) {
const
proof
=
merkleTree
.
getHexProof
(
leaf
);
const
proof
=
merkleTree
.
getHexProof
(
leaf
);
expect
(
await
this
.
merkleProof
.
verify
(
proof
,
root
,
leaf
)).
to
.
equal
(
true
);
expect
(
await
this
.
merkleProof
.
verify
(
proof
,
root
,
leaf
)).
to
.
equal
(
true
);
// For demonstration, it is also possible to create valid proofs for certain 64-byte values *not* in elements:
const
noSuchLeaf
=
keccak256
(
Buffer
.
concat
([
keccak256
(
elements
[
0
]),
keccak256
(
elements
[
1
])].
sort
(
Buffer
.
compare
)),
);
expect
(
await
this
.
merkleProof
.
verify
(
proof
.
slice
(
1
),
root
,
noSuchLeaf
)).
to
.
equal
(
true
);
});
});
it
(
'returns false for an invalid Merkle proof'
,
async
function
()
{
it
(
'returns false for an invalid Merkle proof'
,
async
function
()
{
...
...
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