Commit 049555b2 authored by George Hotz's avatar George Hotz

test passes, but it has a different hash

parent be3760dc
......@@ -500,14 +500,17 @@ library Lib_MerkleTrie {
} else if (currentNodeType == NodeType.ExtensionNode) {
// Shift the key over to account for the nodes key.
bytes memory nodeKey = _getNodeKey(currentNode);
key = Lib_BytesUtils.slice(key, 0, key.length - nodeKey.length);
// this is likely wrong!
if (nodeKey.length < key.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.
if (previousNodeHash.length > 0) {
// Re-encode the node based on the previous node.
currentNode = _editExtensionNodeValue(currentNode, previousNodeHash);
//currentNode = _makeExtensionNode(nodeKey, previousNodeHash);
}
} else if (currentNodeType == NodeType.BranchNode) {
// If this node is the last element in the path, it'll be correctly encoded
......
......@@ -26,7 +26,7 @@ func TestBuggedTrie(t *testing.T) {
ram := make(map[uint32](uint32))
ram[0] = 1
ram[4] = 1
ram[4] = 2
root := RamToTrie(ram)
fmt.Println("root(0,4) =", root)
......@@ -34,7 +34,7 @@ func TestBuggedTrie(t *testing.T) {
return Preimages[t]
})
ram[0x40] = 1
ram[0x40] = 3
root = RamToTrie(ram)
fmt.Println("root(0,4,0x40) =", root)
......
......@@ -22,14 +22,21 @@ describe("MIPSMemory contract", function () {
let root = "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
root = await write(mm, root, 0, 1)
root = await write(mm, root, 4, 1)
root = await write(mm, root, 4, 2)
expect(await mm.ReadMemory(root, 0)).to.equal(1)
expect(await mm.ReadMemory(root, 4)).to.equal(2)
})
it("write three should work", async function() {
await mm.AddTrieNode(new Uint8Array([0x80]))
let root = "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
root = await write(mm, root, 0, 1)
root = await write(mm, root, 4, 1)
root = await write(mm, root, 0x40, 1)
root = await write(mm, root, 4, 2)
root = await write(mm, root, 0x40, 3)
expect(await mm.ReadMemory(root, 0)).to.equal(1)
expect(await mm.ReadMemory(root, 4)).to.equal(2)
expect(await mm.ReadMemory(root, 0x40)).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