Commit b8868034 authored by George Hotz's avatar George Hotz

touch ups

parent d3682d8a
...@@ -128,7 +128,9 @@ contract MIPS { ...@@ -128,7 +128,9 @@ contract MIPS {
return stateHash; return stateHash;
} }
newStateHash = stepPC(stateHash, pc, pc+4); newStateHash = stepPC(stateHash, pc, pc+4);
emit Stepped(newStateHash); if (address(m) != address(0)) {
emit Stepped(newStateHash);
}
} }
// will revert if any required input state is missing // will revert if any required input state is missing
...@@ -180,22 +182,6 @@ contract MIPS { ...@@ -180,22 +182,6 @@ contract MIPS {
storeAddr = rtReg; storeAddr = rtReg;
} }
// memory fetch (all I-type)
// we do the load for stores also
uint32 mem;
if (opcode >= 0x20) {
// M[R[rs]+SignExtImm]
uint32 SignExtImm = SE(insn&0xFFFF, 16);
rs += SignExtImm;
uint32 addr = rs & 0xFFFFFFFC;
mem = ReadMemory(stateHash, addr);
if (opcode >= 0x28 && opcode != 0x30) {
// store
storeAddr = addr;
}
}
if ((opcode >= 4 && opcode < 8) || opcode == 1) { if ((opcode >= 4 && opcode < 8) || opcode == 1) {
bool shouldBranch = false; bool shouldBranch = false;
...@@ -221,6 +207,21 @@ contract MIPS { ...@@ -221,6 +207,21 @@ contract MIPS {
} }
// memory fetch (all I-type)
// we do the load for stores also
uint32 mem;
if (opcode >= 0x20) {
// M[R[rs]+SignExtImm]
uint32 SignExtImm = SE(insn&0xFFFF, 16);
rs += SignExtImm;
uint32 addr = rs & 0xFFFFFFFC;
mem = ReadMemory(stateHash, addr);
if (opcode >= 0x28 && opcode != 0x30) {
// store
storeAddr = addr;
}
}
// ALU // ALU
uint32 val = execute(insn, rs, rt, mem); uint32 val = execute(insn, rs, rt, mem);
......
...@@ -61,7 +61,7 @@ contract MIPSMemory { ...@@ -61,7 +61,7 @@ contract MIPSMemory {
return ret; return ret;
} }
function fb(bytes memory dat) internal view returns (uint32) { function fb(bytes memory dat) internal pure returns (uint32) {
require(dat.length == 4, "wrong length value"); require(dat.length == 4, "wrong length value");
uint32 ret = uint32(uint8(dat[0])) << 24 | uint32 ret = uint32(uint8(dat[0])) << 24 |
uint32(uint8(dat[1])) << 16 | uint32(uint8(dat[1])) << 16 |
......
...@@ -89,7 +89,7 @@ library Lib_MerkleTrie { ...@@ -89,7 +89,7 @@ library Lib_MerkleTrie {
return _getUpdatedTrieRoot(newPath, _key, trie); return _getUpdatedTrieRoot(newPath, _key, trie);
} }
function getRawNode(bytes memory encoded) private view returns (TrieNode memory) { function getRawNode(bytes memory encoded) private pure returns (TrieNode memory) {
return TrieNode({ return TrieNode({
encoded: encoded, encoded: encoded,
decoded: Lib_RLPReader.readList(encoded) decoded: Lib_RLPReader.readList(encoded)
...@@ -97,7 +97,9 @@ library Lib_MerkleTrie { ...@@ -97,7 +97,9 @@ library Lib_MerkleTrie {
} }
function getTrieNode(mapping(bytes32 => bytes) storage trie, bytes32 nodeId) private view returns (TrieNode memory) { function getTrieNode(mapping(bytes32 => bytes) storage trie, bytes32 nodeId) private view returns (TrieNode memory) {
return getRawNode(trie[nodeId]); bytes memory encoded = trie[nodeId];
require(keccak256(encoded) == nodeId, "bad hash in trie lookup");
return getRawNode(encoded);
} }
/** /**
......
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