Commit ebded26a authored by George Hotz's avatar George Hotz

switch to oracle

parent a9d4fc11
...@@ -11,6 +11,9 @@ InputOracle -- Preagreed upon inputs (TODO: replace with memory reads from given ...@@ -11,6 +11,9 @@ InputOracle -- Preagreed upon inputs (TODO: replace with memory reads from given
returns returns
$v0 = inputs[$a0] >> $a1 $v0 = inputs[$a0] >> $a1
This has been changed to an MMIO oracle
hash at 0x30001000 loads len at 0x31000000 and data at 0x31000004
PreimageOracle -- key value store PreimageOracle -- key value store
$a0 = dword index in value $a0 = dword index in value
$t0 = hash[31:0] $t0 = hash[31:0]
......
...@@ -5,7 +5,6 @@ package oracle ...@@ -5,7 +5,6 @@ package oracle
import ( import (
"fmt" "fmt"
"io/ioutil"
"math/big" "math/big"
"os" "os"
"reflect" "reflect"
...@@ -65,7 +64,7 @@ func Output(output common.Hash) { ...@@ -65,7 +64,7 @@ func Output(output common.Hash) {
func Preimage(hash common.Hash) []byte { func Preimage(hash common.Hash) []byte {
val, ok := preimages[hash] val, ok := preimages[hash]
if !ok { if !ok {
f, err := os.Open(fmt.Sprintf("/tmp/eth/%s", hash)) /*f, err := os.Open(fmt.Sprintf("/tmp/eth/%s", hash))
if err != nil { if err != nil {
panic("missing preimage") panic("missing preimage")
} }
...@@ -74,7 +73,20 @@ func Preimage(hash common.Hash) []byte { ...@@ -74,7 +73,20 @@ func Preimage(hash common.Hash) []byte {
ret, err := ioutil.ReadAll(f) ret, err := ioutil.ReadAll(f)
if err != nil { if err != nil {
panic("preimage read failed") panic("preimage read failed")
} }*/
// load in hash
preImageHash := byteAt(0x30001000, 0x20)
copy(preImageHash, hash.Bytes())
// used in unicorn emulator to trigger the load
// in onchain mips, it's instant
os.Getpid()
// ready
rawSize := common.CopyBytes(byteAt(0x31000000, 4))
size := (int(rawSize[0]) << 24) | (int(rawSize[1]) << 16) | (int(rawSize[2]) << 8) | int(rawSize[3])
ret := common.CopyBytes(byteAt(0x31000004, size))
realhash := crypto.Keccak256Hash(ret) realhash := crypto.Keccak256Hash(ret)
if realhash != hash { if realhash != hash {
......
...@@ -3,6 +3,7 @@ import os ...@@ -3,6 +3,7 @@ import os
import sys import sys
import math import math
import struct import struct
import binascii
import traceback import traceback
from elftools.elf.elffile import ELFFile from elftools.elf.elffile import ELFFile
from capstone import * from capstone import *
...@@ -26,6 +27,11 @@ SIZE = 16*1024*1024 ...@@ -26,6 +27,11 @@ SIZE = 16*1024*1024
heap_start = 0x20000000 # 0x20000000-0x30000000 heap_start = 0x20000000 # 0x20000000-0x30000000
# input oracle @ 0x30000000 # input oracle @ 0x30000000
# output oracle @ 0x30000800
# preimage oracle (write) @ 0x30001000
# preimage oracle (read) @ 0x31000000-0x32000000 (16 MB)
# preimage oracle (trigger) @ 0x32000000 (returns size)
brk_start = 0x40000000 # 0x40000000-0x80000000 brk_start = 0x40000000 # 0x40000000-0x80000000
# hmm, very slow # hmm, very slow
...@@ -75,6 +81,15 @@ def hook_interrupt(uc, intno, user_data): ...@@ -75,6 +81,15 @@ def hook_interrupt(uc, intno, user_data):
syscall_no = uc.reg_read(UC_MIPS_REG_V0) syscall_no = uc.reg_read(UC_MIPS_REG_V0)
uc.reg_write(UC_MIPS_REG_V0, 0) uc.reg_write(UC_MIPS_REG_V0, 0)
uc.reg_write(UC_MIPS_REG_A3, 0) uc.reg_write(UC_MIPS_REG_A3, 0)
if syscall_no == 4020:
oracle_hash = binascii.hexlify(uc.mem_read(0x30001000, 0x20)).decode('utf-8')
dat = open("/tmp/eth/0x"+oracle_hash, "rb").read()
#print("oracle:", oracle_hash, len(dat))
uc.mem_write(0x31000000, struct.pack(">I", len(dat)))
uc.mem_write(0x31000004, dat)
return True
if syscall_no == 4004: if syscall_no == 4004:
# write # write
fd = uc.reg_read(UC_MIPS_REG_A0) fd = uc.reg_read(UC_MIPS_REG_A0)
...@@ -127,6 +142,9 @@ def hook_interrupt(uc, intno, user_data): ...@@ -127,6 +142,9 @@ def hook_interrupt(uc, intno, user_data):
elif syscall_no == 4222: elif syscall_no == 4222:
# gettid # gettid
return return
elif syscall_no == 4166:
# nanosleep
return
if syscall_no == 4005: if syscall_no == 4005:
filename = uc.reg_read(UC_MIPS_REG_A0) filename = uc.reg_read(UC_MIPS_REG_A0)
...@@ -267,7 +285,7 @@ mu.mem_map(heap_start, 256*1024*1024) ...@@ -267,7 +285,7 @@ mu.mem_map(heap_start, 256*1024*1024)
mu.mem_map(brk_start, 1024*1024*1024) mu.mem_map(brk_start, 1024*1024*1024)
# input oracle # input oracle
mu.mem_map(0x30000000, 4096) mu.mem_map(0x30000000, 0x2000000)
dat = open("/tmp/eth/13284469", "rb").read() dat = open("/tmp/eth/13284469", "rb").read()
mu.mem_write(0x30000000, dat) mu.mem_write(0x30000000, dat)
...@@ -323,8 +341,6 @@ for section in elffile.iter_sections(): ...@@ -323,8 +341,6 @@ for section in elffile.iter_sections():
#mu.hook_add(UC_HOOK_BLOCK, hook_code, user_data=mu) #mu.hook_add(UC_HOOK_BLOCK, hook_code, user_data=mu)
#mu.hook_add(UC_HOOK_CODE, hook_code, user_data=mu)
def hook_mem_invalid(uc, access, address, size, value, user_data): def hook_mem_invalid(uc, access, address, size, value, user_data):
pc = uc.reg_read(UC_MIPS_REG_PC) pc = uc.reg_read(UC_MIPS_REG_PC)
......
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