Commit dc8ce147 authored by George Hotz's avatar George Hotz

more generic fix

parent 9e366fb3
......@@ -443,7 +443,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 = _editBranchIndexRLP(newBranch, branchKey, lastNode.decoded[lastNode.decoded.length-1]);
newBranch = _editBranchIndex(newBranch, branchKey, _getNodeValue(lastNode));
}
}
......@@ -648,7 +648,19 @@ library Lib_MerkleTrie {
bytes memory _value
)
{
return Lib_RLPReader.readBytes(_node.decoded[_node.decoded.length - 1]);
Lib_RLPReader.RLPItem memory _in = _node.decoded[_node.decoded.length - 1];
// this is bytes only if the length is 32
(
uint256 itemOffset,
uint256 itemLength,
Lib_RLPReader.RLPItemType itemType
) = Lib_RLPReader._decodeLength(_in);
if (itemType == Lib_RLPReader.RLPItemType.DATA_ITEM) {
return Lib_RLPReader._copy(_in.ptr, itemOffset, itemLength);
} else {
return Lib_RLPReader._copy(_in.ptr, 0, _in.length);
}
}
/**
......@@ -908,21 +920,6 @@ 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.
......
......@@ -457,7 +457,7 @@ library Lib_RLPReader {
function _decodeLength(
RLPItem memory _in
)
private
internal
pure
returns (
uint256,
......@@ -564,7 +564,7 @@ library Lib_RLPReader {
uint256 _offset,
uint256 _length
)
private
internal
pure
returns (
bytes memory
......
......@@ -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)
})*/
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment