Commit 64807a35 authored by George Hotz's avatar George Hotz

events in minievm

parent b8868034
...@@ -35,14 +35,13 @@ contract MIPS { ...@@ -35,14 +35,13 @@ contract MIPS {
bool constant public debug = true; bool constant public debug = true;
event DidStep(bytes32 stateHash);
event DidWriteMemory(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) {
if (address(m) != address(0)) { if (address(m) != address(0)) {
if (debug) { emit DidWriteMemory(addr, value);
assembly {
// TODO: this is actually doing an SLOAD first
sstore(addr, value)
}
}
return m.WriteMemory(stateHash, addr, value); return m.WriteMemory(stateHash, addr, value);
} else { } else {
assembly { assembly {
...@@ -53,21 +52,10 @@ contract MIPS { ...@@ -53,21 +52,10 @@ contract MIPS {
} }
} }
function DebugEmit(uint32 val) internal view { function ReadMemory(bytes32 stateHash, uint32 addr) internal returns (uint32 ret) {
if (debug) {
uint256 junk;
assembly {
junk := sload(val)
}
require(junk != 0x133713371337, "huh");
}
}
function ReadMemory(bytes32 stateHash, uint32 addr) internal view returns (uint32 ret) {
if (address(m) != address(0)) { if (address(m) != address(0)) {
DebugEmit(addr);
ret = m.ReadMemory(stateHash, addr); ret = m.ReadMemory(stateHash, addr);
DebugEmit(ret); emit DidReadMemory(addr, ret);
} else { } else {
assembly { assembly {
ret := sload(addr) ret := sload(addr)
...@@ -121,7 +109,6 @@ contract MIPS { ...@@ -121,7 +109,6 @@ contract MIPS {
return (stateHash, exit); return (stateHash, exit);
} }
event Stepped(bytes32 stateHash);
function Step(bytes32 stateHash) public returns (bytes32 newStateHash) { function Step(bytes32 stateHash) public returns (bytes32 newStateHash) {
uint32 pc = ReadMemory(stateHash, REG_PC); uint32 pc = ReadMemory(stateHash, REG_PC);
if (pc == 0x5ead0000) { if (pc == 0x5ead0000) {
...@@ -129,7 +116,7 @@ contract MIPS { ...@@ -129,7 +116,7 @@ contract MIPS {
} }
newStateHash = stepPC(stateHash, pc, pc+4); newStateHash = stepPC(stateHash, pc, pc+4);
if (address(m) != address(0)) { if (address(m) != address(0)) {
emit Stepped(newStateHash); emit DidStep(newStateHash);
} }
} }
......
...@@ -42,7 +42,13 @@ func NewStateDB(debug int, realState bool) *StateDB { ...@@ -42,7 +42,13 @@ 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) {
fmt.Println("AddLog", log) 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") {
fmt.Printf("W: %x <- %x\n", bytesTo32(log.Data[0:32]), bytesTo32(log.Data[32:]))
} else {
fmt.Println("AddLog", log.Topics, log.Data)
}
} }
func (s *StateDB) AddPreimage(hash common.Hash, preimage []byte) {} func (s *StateDB) AddPreimage(hash common.Hash, preimage []byte) {}
func (s *StateDB) AddRefund(gas uint64) {} func (s *StateDB) AddRefund(gas uint64) {}
......
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