Commit 8977f137 authored by George Hotz's avatar George Hotz

in the embedded world, we use a different oracle

parent 1f3eba66
//go:build mips
package oracle
import (
"fmt"
"io/ioutil"
"math/big"
"os"
"github.com/ethereum/go-ethereum/common"
)
func Preimage(hash common.Hash) []byte {
f, err := os.Open(fmt.Sprintf("/tmp/eth/%s", hash))
if err != nil {
panic("missing preimage")
}
defer f.Close()
ret, err := ioutil.ReadAll(f)
if err != nil {
panic("preimage read failed")
}
return ret
}
// these are stubs in embedded world
func PrefetchStorage(blockNumber *big.Int, addr common.Address, skey common.Hash) {}
func PrefetchAccount(blockNumber *big.Int, addr common.Address) {}
func PrefetchCode(blockNumber *big.Int, addrHash common.Hash) {}
//go:build !mips
package oracle
import (
......@@ -65,7 +67,7 @@ type Account struct {
var nodeUrl = "https://mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161"
func toFilename(key string) string {
return fmt.Sprintf("/tmp/eth/%s", key)
return fmt.Sprintf("/tmp/eth/json_%s", key)
}
func cacheRead(key string) []byte {
......
//go:build !mips
package oracle
import (
"fmt"
"io/ioutil"
"github.com/ethereum/go-ethereum/common"
)
......@@ -10,6 +13,8 @@ var preimages = make(map[common.Hash][]byte)
func Preimage(hash common.Hash) []byte {
val, ok := preimages[hash]
key := fmt.Sprintf("/tmp/eth/%s", hash)
ioutil.WriteFile(key, val, 0644)
if !ok {
fmt.Println("can't find preimage", hash)
panic("preimage missing")
......
......@@ -5,5 +5,4 @@ cp go-ethereum ../risc/go-ethereum
cd ../risc
file go-ethereum
GOOS=linux GOARCH=mips go build test.go
#GOOS=linux GOARCH=mips go build test.go
../data/
\ No newline at end of file
......@@ -16,9 +16,11 @@ regs = ["at", "v0", "v1", "a0", "a1", "a2", "a3"]
SIZE = 16*1024*1024
heap_start = 16*1024*1024
tfd = 10
files = {}
fcnt = 0
def hook_interrupt(uc, intno, user_data):
global heap_start, fcnt
global heap_start, fcnt, files, tfd
pc = uc.reg_read(UC_MIPS_REG_PC)
if intno == 17:
syscall_no = uc.reg_read(UC_MIPS_REG_V0)
......@@ -42,12 +44,15 @@ def hook_interrupt(uc, intno, user_data):
if syscall_no == 4005:
filename = uc.reg_read(UC_MIPS_REG_A0)
print('open("%s")' % uc.mem_read(filename, 0x100).split(b"\x00")[0].decode('utf-8'))
# open fd=4
uc.reg_write(UC_MIPS_REG_V0, 4)
elif syscall_no == 4288:
dfd = uc.reg_read(UC_MIPS_REG_A0)
filename = uc.reg_read(UC_MIPS_REG_A1)
print('openat(%d, "%s")' % (dfd, uc.mem_read(filename, 0x100).split(b"\x00")[0].decode('utf-8')))
filename = uc.mem_read(filename, 0x100).split(b"\x00")[0].decode('utf-8')
print('openat(%d, "%s")' % (dfd, filename))
files[tfd] = open(filename, "rb")
uc.reg_write(UC_MIPS_REG_V0, tfd)
tfd += 1
elif syscall_no == 4238:
addr = uc.reg_read(UC_MIPS_REG_A0)
print("futex", hex(addr))
......@@ -76,8 +81,13 @@ def hook_interrupt(uc, intno, user_data):
buf = uc.reg_read(UC_MIPS_REG_A1)
count = uc.reg_read(UC_MIPS_REG_A2)
print("read", fd, hex(buf), count)
uc.mem_write(buf, b"16384\n\x00")
uc.reg_write(UC_MIPS_REG_V0, 6)
if fd == 4:
uc.mem_write(buf, b"16384\n\x00")
uc.reg_write(UC_MIPS_REG_V0, 6)
else:
ret = files[fd].read(count)
uc.mem_write(buf, ret)
uc.reg_write(UC_MIPS_REG_V0, len(ret))
elif syscall_no == 4246:
print("EXIT")
return False
......
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