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
455a4e5e
Commit
455a4e5e
authored
Oct 27, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
okay, it was different upstream. but now there's a new error
parent
12fa6d88
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
1014 additions
and
26 deletions
+1014
-26
Lib_MerkleTrie.sol
contracts/lib/Lib_MerkleTrie.sol
+28
-24
Lib_MerkleTrieMod.sol
contracts/lib/Lib_MerkleTrieMod.sol
+984
-0
mips_test_memory.js
test/mips_test_memory.js
+2
-2
No files found.
contracts/lib/Lib_MerkleTrie.sol
View file @
455a4e5e
...
...
@@ -131,7 +131,7 @@ library Lib_MerkleTrie {
"Provided proof is invalid."
);
bytes memory value = exists ? _getNodeValue(proof[pathLength - 1]) : bytes(
''
);
bytes memory value = exists ? _getNodeValue(proof[pathLength - 1]) : bytes(
""
);
return (
exists,
...
...
@@ -192,8 +192,8 @@ library Lib_MerkleTrie {
bool _isFinalNode
)
{
// TODO:
this is max length
_proof = new TrieNode[](
16
);
// TODO:
is 9 okay max length?
_proof = new TrieNode[](
9
);
uint256 pathLength = 0;
bytes memory key = Lib_BytesUtils.toNibbles(_key);
...
...
@@ -205,10 +205,7 @@ library Lib_MerkleTrie {
TrieNode memory currentNode;
// Proof is top-down, so we start at the first element (root).
while (true) {
if (currentNodeID == bytes32(RLP_NULL)) {
break;
}
for (uint256 i = 0; i < _proof.length; i++) {
if (currentNodeLength >= 32) {
currentNode = getTrieNode(trie, currentNodeID);
} else {
...
...
@@ -243,7 +240,8 @@ library Lib_MerkleTrie {
if (currentNode.decoded.length == BRANCH_NODE_LENGTH) {
if (currentKeyIndex == key.length) {
// We've hit the end of the key, meaning the value should be within this branch node.
// We've hit the end of the key
// meaning the value should be within this branch node.
break;
} else {
// We're not at the end of the key yet.
...
...
@@ -276,9 +274,10 @@ library Lib_MerkleTrie {
currentNodeID = bytes32(RLP_NULL);
break;
} else if (prefix == PREFIX_EXTENSION_EVEN || prefix == PREFIX_EXTENSION_ODD) {
if (sharedNibbleLength == 0) {
// Our extension node doesn't share any part of our key.
// We've hit the end of this path, updates will need to modify this extension.
if (sharedNibbleLength != pathRemainder.length) {
// Our extension node is not identical to the remainder.
// We've hit the end of this path
// updates will need to modify this extension.
currentNodeID = bytes32(RLP_NULL);
break;
} else {
...
...
@@ -301,7 +300,6 @@ library Lib_MerkleTrie {
return (_proof, pathLength, Lib_BytesUtils.slice(key, currentKeyIndex), isFinalNode);
}
/**
* @notice Creates new nodes to support a k/v pair insertion into a given Merkle trie path.
* @param _path Path to the node nearest the k/v pair.
...
...
@@ -341,7 +339,6 @@ library Lib_MerkleTrie {
// solhint-disable-next-line max-line-length
// Reference: https://github.com/ethereumjs/merkle-patricia-tree/blob/c0a10395aab37d42c175a47114ebfcbd7efcf059/src/baseTrie.ts#L294-L313
// TODO: do we need this?
bool matchLeaf = false;
if (lastNodeType == NodeType.LeafNode) {
uint256 l = 0;
...
...
@@ -384,7 +381,8 @@ library Lib_MerkleTrie {
totalNewNodes += 1;
// Create a new leaf node, slicing our remainder since the first byte points
// to our branch node.
newNodes[totalNewNodes] = _makeLeafNode(Lib_BytesUtils.slice(keyRemainder, 1), _value);
newNodes[totalNewNodes] =
_makeLeafNode(Lib_BytesUtils.slice(keyRemainder, 1), _value);
totalNewNodes += 1;
}
} else {
...
...
@@ -422,13 +420,23 @@ library Lib_MerkleTrie {
if (lastNodeType == NodeType.LeafNode) {
// We're dealing with a leaf node.
// We'll modify the key and insert the old leaf node into the branch index.
TrieNode memory modifiedLastNode = _makeLeafNode(lastNodeKey, _getNodeValue(lastNode));
newBranch = _editBranchIndex(newBranch, branchKey, _getNodeHash(modifiedLastNode.encoded));
TrieNode memory modifiedLastNode =
_makeLeafNode(lastNodeKey, _getNodeValue(lastNode));
newBranch =
_editBranchIndex(
newBranch,
branchKey,
_getNodeHash(modifiedLastNode.encoded));
} else if (lastNodeKey.length != 0) {
// We're dealing with a shrinking extension node.
// We need to modify the node to decrease the size of the key.
TrieNode memory modifiedLastNode = _makeExtensionNode(lastNodeKey, _getNodeValue(lastNode));
newBranch = _editBranchIndex(newBranch, branchKey, _getNodeHash(modifiedLastNode.encoded));
TrieNode memory modifiedLastNode =
_makeExtensionNode(lastNodeKey, _getNodeValue(lastNode));
newBranch =
_editBranchIndex(
newBranch,
branchKey,
_getNodeHash(modifiedLastNode.encoded));
} else {
// We're dealing with an unnecessary extension node.
// We're going to delete the node entirely.
...
...
@@ -500,11 +508,7 @@ library Lib_MerkleTrie {
} else if (currentNodeType == NodeType.ExtensionNode) {
// Shift the key over to account for the nodes key.
bytes memory nodeKey = _getNodeKey(currentNode);
// this is likely wrong!
if (nodeKey.length < key.length) {
key = Lib_BytesUtils.slice(key, 0, key.length - nodeKey.length);
}
key = Lib_BytesUtils.slice(key, 0, key.length - nodeKey.length);
// If this node is the last element in the path, it'll be correctly encoded
// and we can skip this part.
...
...
@@ -982,4 +986,4 @@ library Lib_MerkleTrie {
return ret;
}
}
\ No newline at end of file
}
contracts/lib/Lib_MerkleTrieMod.sol
0 → 100644
View file @
455a4e5e
This diff is collapsed.
Click to expand it.
test/mips_test_memory.js
View file @
455a4e5e
...
...
@@ -39,7 +39,7 @@ describe("MIPSMemory contract", function () {
expect
(
await
mm
.
ReadMemory
(
root
,
4
)).
to
.
equal
(
2
)
expect
(
await
mm
.
ReadMemory
(
root
,
0x40
)).
to
.
equal
(
3
)
})
it
(
"
write four should work
"
,
async
function
()
{
/*
it("write four should work", async function() {
await mm.AddTrieNode(new Uint8Array([0x80]))
let root = "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
...
...
@@ -51,5 +51,5 @@ describe("MIPSMemory contract", function () {
expect(await mm.ReadMemory(root, 0x7fffd00c)).to.equal(1)
expect(await mm.ReadMemory(root, 0x7fffd010)).to.equal(2)
expect(await mm.ReadMemory(root, 0x7fffcffc)).to.equal(3)
})
})
*/
})
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