Commit b0454fa2 authored by George Hotz's avatar George Hotz

minigeth is running in mipsevm

parent 7e156f2e
...@@ -94,7 +94,7 @@ type jsoncontract struct { ...@@ -94,7 +94,7 @@ type jsoncontract struct {
//var ram []byte //var ram []byte
//var regs [4096]byte //var regs [4096]byte
var debug bool = false var debug int = 0
var ram map[uint64](uint32) var ram map[uint64](uint32)
func opStaticCall(pc *uint64, interpreter *vm.EVMInterpreter, scope *vm.ScopeContext) ([]byte, error) { func opStaticCall(pc *uint64, interpreter *vm.EVMInterpreter, scope *vm.ScopeContext) ([]byte, error) {
...@@ -119,14 +119,17 @@ func opStaticCall(pc *uint64, interpreter *vm.EVMInterpreter, scope *vm.ScopeCon ...@@ -119,14 +119,17 @@ func opStaticCall(pc *uint64, interpreter *vm.EVMInterpreter, scope *vm.ScopeCon
//scope.Memory.GetPtr(int64(inOffset.Uint64()), int64(inSize.Uint64())) //scope.Memory.GetPtr(int64(inOffset.Uint64()), int64(inSize.Uint64()))
ret := common.BigToHash(big.NewInt(int64(nret))).Bytes() ret := common.BigToHash(big.NewInt(int64(nret))).Bytes()
if debug { if debug >= 2 {
fmt.Println("HOOKED READ! ", fmt.Sprintf("%x = %x", addr, nret)) fmt.Println("HOOKED READ! ", fmt.Sprintf("%x = %x", addr, nret))
} }
if addr == 0xc0000080 && debug >= 1 {
fmt.Printf("PC %x\n", nret)
}
scope.Memory.Set(retOffset.Uint64(), retSize.Uint64(), ret) scope.Memory.Set(retOffset.Uint64(), retSize.Uint64(), ret)
} else if args[0] == 184 { } else if args[0] == 184 {
addr := common.BytesToHash(args[0x24:0x44]).Big().Uint64() addr := common.BytesToHash(args[0x24:0x44]).Big().Uint64()
dat := common.BytesToHash(args[0x44:0x64]).Big().Uint64() dat := common.BytesToHash(args[0x44:0x64]).Big().Uint64()
if debug { if debug >= 2 {
fmt.Println("HOOKED WRITE! ", fmt.Sprintf("%x = %x", addr, dat)) fmt.Println("HOOKED WRITE! ", fmt.Sprintf("%x = %x", addr, dat))
} }
ram[addr] = uint32(dat) ram[addr] = uint32(dat)
...@@ -218,8 +221,13 @@ func main() { ...@@ -218,8 +221,13 @@ func main() {
//debug = true //debug = true
if len(os.Args) > 1 { if len(os.Args) > 1 {
debug = true if os.Args[1] == "/tmp/minigeth.bin" {
runTest(os.Args[1], 20, interpreter, bytecode) debug = 1
runTest(os.Args[1], 20, interpreter, bytecode)
} else {
debug = 2
runTest(os.Args[1], 20, interpreter, bytecode)
}
} else { } else {
files, err := ioutil.ReadDir("test/bin") files, err := ioutil.ReadDir("test/bin")
if err != nil { if err != nil {
......
#!/bin/bash -e
(cd ../ && npx hardhat compile)
(cd ../risc && ./build.sh && COMPILE=1 ./run.py)
go build
./mipsevm /tmp/minigeth.bin
...@@ -24,9 +24,6 @@ mu = Uc(UC_ARCH_MIPS, UC_MODE_32 + UC_MODE_BIG_ENDIAN) ...@@ -24,9 +24,6 @@ mu = Uc(UC_ARCH_MIPS, UC_MODE_32 + UC_MODE_BIG_ENDIAN)
mregs = [UC_MIPS_REG_AT, UC_MIPS_REG_V0, UC_MIPS_REG_V1, UC_MIPS_REG_A0, UC_MIPS_REG_A1, UC_MIPS_REG_A2, UC_MIPS_REG_A3] mregs = [UC_MIPS_REG_AT, UC_MIPS_REG_V0, UC_MIPS_REG_V1, UC_MIPS_REG_A0, UC_MIPS_REG_A1, UC_MIPS_REG_A2, UC_MIPS_REG_A3]
regs = ["at", "v0", "v1", "a0", "a1", "a2", "a3"] regs = ["at", "v0", "v1", "a0", "a1", "a2", "a3"]
SIZE = 16*1024*1024
heap_start = 0x20000000 # 0x20000000-0x30000000 heap_start = 0x20000000 # 0x20000000-0x30000000
# input oracle @ 0x30000000 # input oracle @ 0x30000000
# output oracle @ 0x30000800 # output oracle @ 0x30000800
...@@ -279,7 +276,9 @@ elf.seek(0) ...@@ -279,7 +276,9 @@ elf.seek(0)
#print(hex(rte)) #print(hex(rte))
# program memory (16 MB) # program memory (16 MB)
mu.mem_map(0, SIZE) prog_size = (len(data)+0xFFF) & ~0xFFF
mu.mem_map(0, prog_size)
print("malloced 0x%x for program" % prog_size)
# heap (256 MB) @ 0x20000000 # heap (256 MB) @ 0x20000000
mu.mem_map(heap_start, 256*1024*1024) mu.mem_map(heap_start, 256*1024*1024)
...@@ -369,8 +368,14 @@ mu.hook_add(UC_HOOK_INTR, hook_interrupt) ...@@ -369,8 +368,14 @@ mu.hook_add(UC_HOOK_INTR, hook_interrupt)
if tracelevel == 4: if tracelevel == 4:
start_instrumenting() start_instrumenting()
with open("/tmp/minigeth.bin", "wb") as f:
f.write(mu.mem_read(0, prog_size))
if os.getenv("COMPILE", None) == "1":
exit(0)
try: try:
mu.emu_start(entry, SIZE) mu.emu_start(entry, -1)
except unicorn.UcError: except unicorn.UcError:
pass pass
......
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