Commit fb89747e authored by George Hotz's avatar George Hotz

check output in unicorn run

parent 0ea43a93
...@@ -79,8 +79,9 @@ type Account struct { ...@@ -79,8 +79,9 @@ type Account struct {
CodeHash []byte CodeHash []byte
} }
//var nodeUrl = "http://192.168.1.213:8545" var nodeUrl = "http://192.168.1.213:8545"
var nodeUrl = "https://mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161"
//var nodeUrl = "https://mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161"
func toFilename(key string) string { func toFilename(key string) string {
return fmt.Sprintf("%s/json_%s", root, key) return fmt.Sprintf("%s/json_%s", root, key)
......
package main package main
import ( import (
"bytes"
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
...@@ -74,6 +75,8 @@ func RunUnicorn(fn string, ram map[uint32](uint32), totalSteps int, slowMode boo ...@@ -74,6 +75,8 @@ func RunUnicorn(fn string, ram map[uint32](uint32), totalSteps int, slowMode boo
mu, err := uc.NewUnicorn(uc.ARCH_MIPS, uc.MODE_32|uc.MODE_BIG_ENDIAN) mu, err := uc.NewUnicorn(uc.ARCH_MIPS, uc.MODE_32|uc.MODE_BIG_ENDIAN)
check(err) check(err)
root := "/tmp/eth/13284469"
mu.HookAdd(uc.HOOK_INTR, func(mu uc.Unicorn, intno uint32) { mu.HookAdd(uc.HOOK_INTR, func(mu uc.Unicorn, intno uint32) {
if intno != 17 { if intno != 17 {
log.Fatal("invalid interrupt ", intno, " at step ", steps) log.Fatal("invalid interrupt ", intno, " at step ", steps)
...@@ -83,7 +86,7 @@ func RunUnicorn(fn string, ram map[uint32](uint32), totalSteps int, slowMode boo ...@@ -83,7 +86,7 @@ func RunUnicorn(fn string, ram map[uint32](uint32), totalSteps int, slowMode boo
if syscall_no == 4020 { if syscall_no == 4020 {
oracle_hash, _ := mu.MemRead(0xB0001000, 0x20) oracle_hash, _ := mu.MemRead(0xB0001000, 0x20)
hash := common.BytesToHash(oracle_hash) hash := common.BytesToHash(oracle_hash)
key := fmt.Sprintf("/tmp/eth/%s", hash) key := fmt.Sprintf("%s/%s", root, hash)
value, _ := ioutil.ReadFile(key) value, _ := ioutil.ReadFile(key)
tmp := []byte{0, 0, 0, 0} tmp := []byte{0, 0, 0, 0}
...@@ -178,12 +181,20 @@ func RunUnicorn(fn string, ram map[uint32](uint32), totalSteps int, slowMode boo ...@@ -178,12 +181,20 @@ func RunUnicorn(fn string, ram map[uint32](uint32), totalSteps int, slowMode boo
mu.MemWrite(0, dat) mu.MemWrite(0, dat)
// inputs // inputs
inputFile := fmt.Sprintf("/tmp/eth/%d", 13284469) inputFile := fmt.Sprintf("%s/input", root)
inputs, _ := ioutil.ReadFile(inputFile) inputs, _ := ioutil.ReadFile(inputFile)
mu.MemWrite(0xB0000000, inputs) mu.MemWrite(0xB0000000, inputs[0:0xc0])
LoadMappedFile(fn, ram, 0) LoadMappedFile(fn, ram, 0)
LoadMappedFile(inputFile, ram, 0xB0000000) LoadMappedFile(inputFile, ram, 0xB0000000)
mu.Start(0, 0x5ead0004) mu.Start(0, 0x5ead0004)
real := append([]byte{0x13, 0x37, 0xf0, 0x0d}, inputs[0xc0:]...)
output, _ := mu.MemRead(0xB0000800, 0x44)
if bytes.Compare(real, output) != 0 {
log.Fatal("mismatch output")
} else {
fmt.Println("output match")
}
} }
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