Skip to content

Hotfix/function to use hashed key #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions contracts/tree.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ library PatriciaTree {
}

function doesInclude(Tree storage tree, bytes key) internal view returns (bool) {
bytes32 valueHash = _findNode(tree, key);
return doesIncludeHashedKey(tree, keccak256(key));
}

function doesIncludeHashedKey(Tree storage tree, bytes32 hashedKey) internal view returns (bool) {
bytes32 valueHash = _findNodeWithHashedKey(tree, hashedKey);
return (valueHash != bytes32(0));
}

Expand Down Expand Up @@ -114,12 +118,21 @@ library PatriciaTree {
bytes32 potentialSiblingValue,
uint branchMask,
bytes32[] _siblings
) {
return getNonInclusionProofWithHashedKey(tree, keccak256(key));
}

function getNonInclusionProofWithHashedKey(Tree storage tree, bytes32 hashedKey) internal view returns (
bytes32 potentialSiblingLabel,
bytes32 potentialSiblingValue,
uint branchMask,
bytes32[] _siblings
){
uint length;
uint numSiblings;

// Start from root edge
D.Label memory label = D.Label(keccak256(key), 256);
D.Label memory label = D.Label(hashedKey, 256);
D.Edge memory e = tree.rootEdge;
bytes32[256] memory siblings;

Expand Down Expand Up @@ -268,10 +281,14 @@ library PatriciaTree {
}

function _findNode(Tree storage tree, bytes key) private view returns (bytes32) {
return _findNodeWithHashedKey(tree, keccak256(key));
}

function _findNodeWithHashedKey(Tree storage tree, bytes32 hashedKey) private view returns (bytes32) {
if (tree.rootEdge.node == 0 && tree.rootEdge.label.length == 0) {
return 0;
} else {
D.Label memory k = D.Label(keccak256(key), 256);
D.Label memory k = D.Label(hashedKey, 256);
return _findAtEdge(tree, tree.rootEdge, k);
}
}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "solidity-patricia-tree",
"version": "1.1.0",
"version": "1.1.1",
"description": "Patricia Tree solidity implemenation",
"directories": {
"test": "test"
Expand Down