Skip to content

Commit 84b6d3b

Browse files
authored
Merge pull request #6 from commitground/hotfix/function-to-use-hashed-key
Hotfix/function to use hashed key
2 parents 0760b43 + b73e981 commit 84b6d3b

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

Diff for: contracts/tree.sol

+20-3
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,11 @@ library PartialMerkleTree {
146146
}
147147

148148
function doesInclude(Tree storage tree, bytes key) internal view returns (bool) {
149-
bytes32 valueHash = _findNode(tree, key);
149+
return doesIncludeHashedKey(tree, keccak256(key));
150+
}
151+
152+
function doesIncludeHashedKey(Tree storage tree, bytes32 hashedKey) internal view returns (bool) {
153+
bytes32 valueHash = _findNodeWithHashedKey(tree, hashedKey);
150154
return (valueHash != bytes32(0));
151155
}
152156

@@ -219,12 +223,21 @@ library PartialMerkleTree {
219223
bytes32 potentialSiblingValue,
220224
uint branchMask,
221225
bytes32[] _siblings
226+
) {
227+
return getNonInclusionProofWithHashedKey(tree, keccak256(key));
228+
}
229+
230+
function getNonInclusionProofWithHashedKey(Tree storage tree, bytes32 hashedKey) internal view returns (
231+
bytes32 potentialSiblingLabel,
232+
bytes32 potentialSiblingValue,
233+
uint branchMask,
234+
bytes32[] _siblings
222235
){
223236
uint length;
224237
uint numSiblings;
225238

226239
// Start from root edge
227-
D.Label memory label = D.Label(keccak256(key), 256);
240+
D.Label memory label = D.Label(hashedKey, 256);
228241
D.Edge memory e = tree.rootEdge;
229242
bytes32[256] memory siblings;
230243

@@ -358,10 +371,14 @@ library PartialMerkleTree {
358371
}
359372

360373
function _findNode(Tree storage tree, bytes key) private view returns (bytes32) {
374+
return _findNodeWithHashedKey(tree, keccak256(key));
375+
}
376+
377+
function _findNodeWithHashedKey(Tree storage tree, bytes32 hashedKey) private view returns (bytes32) {
361378
if (tree.rootEdge.node == 0 && tree.rootEdge.label.length == 0) {
362379
return 0;
363380
} else {
364-
D.Label memory k = D.Label(keccak256(key), 256);
381+
D.Label memory k = D.Label(hashedKey, 256);
365382
return _findAtEdge(tree, tree.rootEdge, k);
366383
}
367384
}

Diff for: package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "solidity-partial-tree",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "Solidity implementation of partial merkle tree",
55
"directories": {
66
"test": "test"

0 commit comments

Comments
 (0)