Commit 462199c1 authored by George Hotz's avatar George Hotz

working, fixed early exit

parent 3b929256
...@@ -37,6 +37,7 @@ contract MIPS { ...@@ -37,6 +37,7 @@ contract MIPS {
event DidStep(bytes32 stateHash); event DidStep(bytes32 stateHash);
event DidWriteMemory(uint32 addr, uint32 value); event DidWriteMemory(uint32 addr, uint32 value);
event TryReadMemory(uint32 addr);
event DidReadMemory(uint32 addr, uint32 value); event DidReadMemory(uint32 addr, uint32 value);
function WriteMemory(bytes32 stateHash, uint32 addr, uint32 value) internal returns (bytes32) { function WriteMemory(bytes32 stateHash, uint32 addr, uint32 value) internal returns (bytes32) {
...@@ -54,8 +55,9 @@ contract MIPS { ...@@ -54,8 +55,9 @@ contract MIPS {
function ReadMemory(bytes32 stateHash, uint32 addr) internal returns (uint32 ret) { function ReadMemory(bytes32 stateHash, uint32 addr) internal returns (uint32 ret) {
if (address(m) != address(0)) { if (address(m) != address(0)) {
emit TryReadMemory(addr);
ret = m.ReadMemory(stateHash, addr); ret = m.ReadMemory(stateHash, addr);
emit DidReadMemory(addr, ret); //emit DidReadMemory(addr, ret);
} else { } else {
assembly { assembly {
ret := sload(addr) ret := sload(addr)
......
...@@ -204,6 +204,9 @@ library Lib_MerkleTrie { ...@@ -204,6 +204,9 @@ library Lib_MerkleTrie {
// Proof is top-down, so we start at the first element (root). // Proof is top-down, so we start at the first element (root).
while (true) { while (true) {
if (currentNodeID == bytes32(RLP_NULL)) {
break;
}
if (currentNodeLength >= 32) { if (currentNodeLength >= 32) {
currentNode = getTrieNode(trie, currentNodeID); currentNode = getTrieNode(trie, currentNodeID);
} else { } else {
......
...@@ -42,8 +42,10 @@ func NewStateDB(debug int, realState bool) *StateDB { ...@@ -42,8 +42,10 @@ func NewStateDB(debug int, realState bool) *StateDB {
func (s *StateDB) AddAddressToAccessList(addr common.Address) {} func (s *StateDB) AddAddressToAccessList(addr common.Address) {}
func (s *StateDB) AddBalance(addr common.Address, amount *big.Int) {} func (s *StateDB) AddBalance(addr common.Address, amount *big.Int) {}
func (s *StateDB) AddLog(log *types.Log) { func (s *StateDB) AddLog(log *types.Log) {
if log.Topics[0] == common.HexToHash("0x7b1a2ade00e6a076351ef8a0f302b160b7fd0c65c18234dfe8218c4fa4fa10ab") { if log.Topics[0] == common.HexToHash("0x70c25ce54e55d181671946b6120c8147a91806a3620c981a355f3ae5b11deb13") {
fmt.Printf("R: %x -> %x\n", bytesTo32(log.Data[0:32]), bytesTo32(log.Data[32:])) fmt.Printf("R: %x\n", bytesTo32(log.Data[0:32]))
} else if log.Topics[0] == common.HexToHash("0x7b1a2ade00e6a076351ef8a0f302b160b7fd0c65c18234dfe8218c4fa4fa10ab") {
//fmt.Printf("R: %x -> %x\n", bytesTo32(log.Data[0:32]), bytesTo32(log.Data[32:]))
} else if log.Topics[0] == common.HexToHash("0x486ca368095cbbef9046ac7858bec943e866422cc388f49da1aa3aa77c10aa35") { } else if log.Topics[0] == common.HexToHash("0x486ca368095cbbef9046ac7858bec943e866422cc388f49da1aa3aa77c10aa35") {
fmt.Printf("W: %x <- %x\n", bytesTo32(log.Data[0:32]), bytesTo32(log.Data[32:])) fmt.Printf("W: %x <- %x\n", bytesTo32(log.Data[0:32]), bytesTo32(log.Data[32:]))
} else { } else {
......
...@@ -95,7 +95,7 @@ func RamToTrie(ram map[uint32](uint32)) common.Hash { ...@@ -95,7 +95,7 @@ func RamToTrie(ram map[uint32](uint32)) common.Hash {
for _, kv := range sram { for _, kv := range sram {
k, v := uint32(kv>>32), uint32(kv) k, v := uint32(kv>>32), uint32(kv)
k >>= 2 k >>= 2
fmt.Printf("insert %x = %x\n", k, v) //fmt.Printf("insert %x = %x\n", k, v)
tk := make([]byte, 4) tk := make([]byte, 4)
tv := make([]byte, 4) tv := make([]byte, 4)
binary.BigEndian.PutUint32(tk, k) binary.BigEndian.PutUint32(tk, k)
......
...@@ -14,7 +14,7 @@ describe("MIPS contract", function () { ...@@ -14,7 +14,7 @@ describe("MIPS contract", function () {
} }
let root = trieAdd['root'] let root = trieAdd['root']
for (let i = 0; i < 10; i++) { for (let i = 0; i < 15; i++) {
ret = await m.Step(root) ret = await m.Step(root)
const receipt = await ret.wait() const receipt = await ret.wait()
for (l of receipt.logs) { for (l of receipt.logs) {
......
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