Commit 6f7b2c8d authored by George Hotz's avatar George Hotz

woot! we are committing trie nodes

parent 205d51ff
...@@ -82,12 +82,12 @@ contract MIPSMemory { ...@@ -82,12 +82,12 @@ contract MIPSMemory {
proofs[stateHash][addr] = proof; proofs[stateHash][addr] = proof;
}*/ }*/
function WriteMemory(bytes32 stateHash, uint32 addr, uint32 value) public view returns (bytes32) { function WriteMemory(bytes32 stateHash, uint32 addr, uint32 value) public returns (bytes32) {
require(addr & 3 == 0, "write memory must be 32-bit aligned"); require(addr & 3 == 0, "write memory must be 32-bit aligned");
return Lib_MerkleTrie.update(tb(addr>>2), tb(value), trie, stateHash); return Lib_MerkleTrie.update(tb(addr>>2), tb(value), trie, stateHash);
} }
function WriteBytes32(bytes32 stateHash, uint32 addr, bytes32 val) public view returns (bytes32) { function WriteBytes32(bytes32 stateHash, uint32 addr, bytes32 val) public returns (bytes32) {
for (uint32 i = 0; i < 32; i += 4) { for (uint32 i = 0; i < 32; i += 4) {
uint256 tv = uint256(val>>(224-(i*8))); uint256 tv = uint256(val>>(224-(i*8)));
stateHash = WriteMemory(stateHash, addr+i, uint32(tv)); stateHash = WriteMemory(stateHash, addr+i, uint32(tv));
......
...@@ -74,7 +74,6 @@ library Lib_MerkleTrie { ...@@ -74,7 +74,6 @@ library Lib_MerkleTrie {
bytes32 _root bytes32 _root
) )
internal internal
view
returns ( returns (
bytes32 _updatedRoot bytes32 _updatedRoot
) )
...@@ -87,7 +86,7 @@ library Lib_MerkleTrie { ...@@ -87,7 +86,7 @@ library Lib_MerkleTrie {
(TrieNode[] memory proof, uint256 pathLength, bytes memory keyRemainder, ) = _walkNodePath(trie, _key, _root); (TrieNode[] memory proof, uint256 pathLength, bytes memory keyRemainder, ) = _walkNodePath(trie, _key, _root);
TrieNode[] memory newPath = _getNewPath(proof, pathLength, keyRemainder, _value); TrieNode[] memory newPath = _getNewPath(proof, pathLength, keyRemainder, _value);
return _getUpdatedTrieRoot(newPath, _key); return _getUpdatedTrieRoot(newPath, _key, trie);
} }
function getRawNode(bytes memory encoded) private view returns (TrieNode memory) { function getRawNode(bytes memory encoded) private view returns (TrieNode memory) {
...@@ -437,10 +436,10 @@ library Lib_MerkleTrie { ...@@ -437,10 +436,10 @@ library Lib_MerkleTrie {
*/ */
function _getUpdatedTrieRoot( function _getUpdatedTrieRoot(
TrieNode[] memory _nodes, TrieNode[] memory _nodes,
bytes memory _key bytes memory _key,
mapping(bytes32 => bytes) storage trie
) )
private private
pure
returns ( returns (
bytes32 _updatedRoot bytes32 _updatedRoot
) )
...@@ -487,6 +486,9 @@ library Lib_MerkleTrie { ...@@ -487,6 +486,9 @@ library Lib_MerkleTrie {
// Compute the node hash for the next iteration. // Compute the node hash for the next iteration.
previousNodeHash = _getNodeHash(currentNode.encoded); previousNodeHash = _getNodeHash(currentNode.encoded);
if (currentNode.encoded.length >= 32) {
trie[keccak256(currentNode.encoded)] = currentNode.encoded;
}
} }
// Current node should be the root at this point. // Current node should be the root at this point.
......
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