Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
exchain
nebula
Commits
f622649e
Commit
f622649e
authored
Oct 27, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix lib merkletrie
parent
455a4e5e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
3 deletions
+23
-3
Lib_MerkleTrie.sol
contracts/lib/Lib_MerkleTrie.sol
+23
-3
No files found.
contracts/lib/Lib_MerkleTrie.sol
View file @
f622649e
...
...
@@ -6,6 +6,8 @@ import { Lib_BytesUtils } from "./Lib_BytesUtils.sol";
import { Lib_RLPReader } from "./Lib_RLPReader.sol";
import { Lib_RLPWriter } from "./Lib_RLPWriter.sol";
import "hardhat/console.sol";
/**
* @title Lib_MerkleTrie
*/
...
...
@@ -192,7 +194,7 @@ library Lib_MerkleTrie {
bool _isFinalNode
)
{
// TODO:
is 9 okay max length?
// TODO:
this is max length
_proof = new TrieNode[](9);
uint256 pathLength = 0;
...
...
@@ -206,6 +208,9 @@ library Lib_MerkleTrie {
// Proof is top-down, so we start at the first element (root).
for (uint256 i = 0; i < _proof.length; i++) {
if (currentNodeID == bytes32(RLP_NULL)) {
break;
}
if (currentNodeLength >= 32) {
currentNode = getTrieNode(trie, currentNodeID);
} else {
...
...
@@ -319,7 +324,6 @@ library Lib_MerkleTrie {
bytes memory _value
)
private
pure
returns (
TrieNode[] memory _newPath
)
...
...
@@ -329,6 +333,7 @@ library Lib_MerkleTrie {
// Most of our logic depends on the status of the last node in the path.
TrieNode memory lastNode = _path[_pathLength - 1];
NodeType lastNodeType = _getNodeType(lastNode);
console.log(uint256(lastNodeType));
// Create an array for newly created nodes.
// We need up to three new nodes, depending on the contents of the last node.
...
...
@@ -441,7 +446,7 @@ library Lib_MerkleTrie {
// We're dealing with an unnecessary extension node.
// We're going to delete the node entirely.
// Simply insert its current value into the branch index.
newBranch = _editBranchIndex
(newBranch, branchKey, _getNodeValue(lastNode)
);
newBranch = _editBranchIndex
RLP(newBranch, branchKey, lastNode.decoded[lastNode.decoded.length-1]
);
}
}
...
...
@@ -906,6 +911,21 @@ library Lib_MerkleTrie {
return _makeNode(_branch.decoded);
}
function _editBranchIndexRLP(
TrieNode memory _branch,
uint8 _index,
Lib_RLPReader.RLPItem memory encoded
)
private
pure
returns (
TrieNode memory _updatedNode
)
{
_branch.decoded[_index] = encoded;
return _makeNode(_branch.decoded);
}
/**
* @notice Utility; adds a prefix to a key.
* @param _key Key to prefix.
...
...
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