Commit 36ce0212 authored by George Hotz's avatar George Hotz

unicorn running without a working oracle

parent afa5f1fb
......@@ -11,6 +11,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
)
var preimages = make(map[common.Hash][]byte)
......@@ -78,11 +79,11 @@ func Preimage(hash common.Hash) []byte {
size := (int(rawSize[0]) << 24) | (int(rawSize[1]) << 16) | (int(rawSize[2]) << 8) | int(rawSize[3])
ret := common.CopyBytes(byteAt(0x31000004, size))
// this is 20% of the exec instructions
/*realhash := crypto.Keccak256Hash(ret)
// this is 20% of the exec instructions, this speedup is always an option
realhash := crypto.Keccak256Hash(ret)
if realhash != hash {
panic("preimage has wrong hash")
}*/
}
preimages[hash] = ret
return ret
......
......@@ -4,6 +4,8 @@ import (
"fmt"
"io/ioutil"
"log"
"os"
"time"
uc "github.com/unicorn-engine/unicorn/bindings/go/unicorn"
)
......@@ -15,6 +17,11 @@ func check(err error) {
}
var steps int = 0
var heap_start uint64 = 0
func RegRead(u *uc.Unicorn, reg int) {
}
func RunUnicorn(fn string) {
mu, err := uc.NewUnicorn(uc.ARCH_MIPS, uc.MODE_32|uc.MODE_BIG_ENDIAN)
......@@ -22,15 +29,40 @@ func RunUnicorn(fn string) {
mu.HookAdd(uc.HOOK_INTR, func(mu uc.Unicorn, intno uint32) {
if intno != 17 {
log.Fatal("invalid interrupt ", intno)
log.Fatal("invalid interrupt ", intno, " at step ", steps)
}
syscall_no, _ := mu.RegRead(uc.MIPS_REG_V0)
fmt.Println("syscall", syscall_no)
v0 := uint64(0)
if syscall_no == 4004 {
buf, _ := mu.RegRead(uc.MIPS_REG_A1)
count, _ := mu.RegRead(uc.MIPS_REG_A2)
bytes, _ := mu.MemRead(buf, count)
os.Stderr.Write(bytes)
} else if syscall_no == 4090 {
a0, _ := mu.RegRead(uc.MIPS_REG_A0)
sz, _ := mu.RegRead(uc.MIPS_REG_A1)
if a0 == 0 {
v0 = 0x20000000 + heap_start
heap_start += sz
} else {
v0 = a0
}
} else if syscall_no == 4045 {
v0 = 0x40000000
} else if syscall_no == 4120 {
v0 = 1
} else {
fmt.Println("syscall", syscall_no)
}
mu.RegWrite(uc.MIPS_REG_V0, v0)
mu.RegWrite(uc.MIPS_REG_A3, 0)
}, 1, 0)
ministart := time.Now()
mu.HookAdd(uc.HOOK_CODE, func(mu uc.Unicorn, addr uint64, size uint32) {
if steps%10000 == 0 {
fmt.Printf("%6d Code: 0x%x, 0x%x\n", steps, addr, size)
if steps%100000 == 0 {
steps_per_sec := float64(steps) * 1e9 / float64(time.Now().Sub(ministart).Nanoseconds())
fmt.Printf("%6d Code: 0x%x, 0x%x steps per s %f\n", steps, addr, size, steps_per_sec)
}
steps += 1
}, 1, 0)
......
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