Commit c22b2fdc authored by George Hotz's avatar George Hotz

move the oracle from 0x3 -> 0xB

parent 6f95e202
......@@ -105,12 +105,12 @@ contract MIPSMemory {
}
// MMIO preimage oracle
if (addr >= 0x31000000 && addr < 0x32000000) {
bytes32 pihash = ReadBytes32(stateHash, 0x30001000);
if (addr == 0x31000000) {
if (addr >= 0xB1000000 && addr < 0xB2000000) {
bytes32 pihash = ReadBytes32(stateHash, 0xB0001000);
if (addr == 0xB1000000) {
return uint32(preimage[pihash].length);
}
uint offset = addr-0x31000004;
uint offset = addr-0xB1000004;
uint8 a0 = uint8(preimage[pihash][offset]);
uint8 a1 = uint8(preimage[pihash][offset+1]);
uint8 a2 = uint8(preimage[pihash][offset+2]);
......
......@@ -36,7 +36,7 @@ func Input(index int) common.Hash {
if !inputsLoaded {
// before this isn't run on chain (confirm this isn't cached)
// does this interact with the GC?
ret := byteAt(0x30000000, len(inputs)*0x20)
ret := byteAt(0xB0000000, len(inputs)*0x20)
os.Stderr.WriteString("********* on chain starts here *********\n")
......@@ -57,11 +57,11 @@ func Halt() {
}
func Output(output common.Hash, receipts common.Hash) {
ret := byteAt(0x30000804, 0x20)
ret := byteAt(0xB0000804, 0x20)
copy(ret, output.Bytes())
rret := byteAt(0x30000824, 0x20)
rret := byteAt(0xB0000824, 0x20)
copy(rret, receipts.Bytes())
magic := byteAt(0x30000800, 4)
magic := byteAt(0xB0000800, 4)
copy(magic, []byte{0x13, 0x37, 0xf0, 0x0d})
Halt()
}
......@@ -70,7 +70,7 @@ func Preimage(hash common.Hash) []byte {
val, ok := preimages[hash]
if !ok {
// load in hash
preImageHash := byteAt(0x30001000, 0x20)
preImageHash := byteAt(0xB0001000, 0x20)
copy(preImageHash, hash.Bytes())
// used in unicorn emulator to trigger the load
......@@ -78,9 +78,9 @@ func Preimage(hash common.Hash) []byte {
os.Getpid()
// ready
rawSize := common.CopyBytes(byteAt(0x31000000, 4))
rawSize := common.CopyBytes(byteAt(0xB1000000, 4))
size := (int(rawSize[0]) << 24) | (int(rawSize[1]) << 16) | (int(rawSize[2]) << 8) | int(rawSize[3])
ret := common.CopyBytes(byteAt(0x31000004, size))
ret := common.CopyBytes(byteAt(0xB1000004, size))
// this is 20% of the exec instructions, this speedup is always an option
realhash := crypto.Keccak256Hash(ret)
......
......@@ -27,10 +27,10 @@ mregs = [UC_MIPS_REG_AT, UC_MIPS_REG_V0, UC_MIPS_REG_V1, UC_MIPS_REG_A0, UC_MIPS
regs = ["at", "v0", "v1", "a0", "a1", "a2", "a3"]
heap_start = 0x20000000 # 0x20000000-0x30000000
# input oracle @ 0x30000000
# output oracle @ 0x30000800
# preimage oracle (write) @ 0x30001000
# preimage oracle (read) @ 0x31000000-0x32000000 (16 MB)
# input oracle @ 0xB0000000
# output oracle @ 0xB0000800
# preimage oracle (write) @ 0xB0001000
# preimage oracle (read) @ 0xB1000000-0xB2000000 (16 MB)
brk_start = 0x40000000 # 0x40000000-0x80000000
stack_start = 0x7FFFF000
......@@ -99,11 +99,11 @@ def hook_interrupt(uc, intno, user_data):
uc.reg_write(UC_MIPS_REG_A3, 0)
if syscall_no == 4020:
oracle_hash = binascii.hexlify(uc.mem_read(0x30001000, 0x20)).decode('utf-8')
oracle_hash = binascii.hexlify(uc.mem_read(0xB0001000, 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)
uc.mem_write(0xB1000000, struct.pack(">I", len(dat)))
uc.mem_write(0xB1000004, dat)
return True
if syscall_no == 4004:
......@@ -262,13 +262,13 @@ mu.mem_map(heap_start, 256*1024*1024)
mu.mem_map(brk_start, 1024*1024*1024)
# input oracle
mu.mem_map(0x30000000, 0x2000000)
mu.mem_map(0xB0000000, 0x2000000)
if len(sys.argv) > 1:
inputs = open("/tmp/eth/"+sys.argv[1], "rb").read()
else:
inputs = open("/tmp/eth/13284469", "rb").read()
mu.mem_write(0x30000000, inputs)
mu.mem_write(0xB0000000, inputs)
_, r = load_minigeth(mu)
......@@ -290,16 +290,17 @@ try:
mu.emu_start(0, 0x5EAD0000)
died_well = True
except unicorn.UcError:
traceback.print_exc()
pass
if not died_well:
raise Exception("program exitted early")
magic = struct.unpack(">I", mu.mem_read(0x30000800, 4))[0]
magic = struct.unpack(">I", mu.mem_read(0xB0000800, 4))[0]
assert magic == 0x1337f00d
real_hash = binascii.hexlify(inputs[-0x40:-0x20])
compare_hash = binascii.hexlify(mu.mem_read(0x30000804, 0x20))
compare_hash = binascii.hexlify(mu.mem_read(0xB0000804, 0x20))
print("compare", real_hash, "to computed", compare_hash)
if real_hash != compare_hash:
......
......@@ -20,8 +20,8 @@ func RegSerialize(ram map[uint32](uint32)) []uint32 {
var done sync.Mutex
func TestCompare(t *testing.T) {
//fn := "../mipigo/test.bin"
fn := "../mipigo/minigeth.bin"
fn := "../mipigo/test/test.bin"
//fn := "../mipigo/minigeth.bin"
steps := 1000000000
//steps := 1165
......@@ -34,7 +34,7 @@ func TestCompare(t *testing.T) {
ram := make(map[uint32](uint32))
LoadMappedFile(fn, ram, 0)
inputFile := fmt.Sprintf("/tmp/eth/%d", 13284469)
LoadMappedFile(inputFile, ram, 0x30000000)
LoadMappedFile(inputFile, ram, 0xB0000000)
go RunWithRam(ram, steps, 0, func(step int, ram map[uint32](uint32)) {
//fmt.Printf("%d evm %x\n", step, ram[0xc0000080])
......
......@@ -28,7 +28,7 @@ func LoadMappedFile(fn string, ram map[uint32](uint32), base uint32) {
func RunMinigeth(fn string, steps int, debug int) {
ram := make(map[uint32](uint32))
LoadMappedFile(fn, ram, 0)
LoadMappedFile(fmt.Sprintf("/tmp/eth/%d", 13284469), ram, 0x30000000)
LoadMappedFile(fmt.Sprintf("/tmp/eth/%d", 13284469), ram, 0xB0000000)
RunWithRam(ram, steps, debug, nil)
}
......
......@@ -76,20 +76,20 @@ func RunUnicorn(fn string, ram map[uint32](uint32), totalSteps int, callback fun
syscall_no, _ := mu.RegRead(uc.MIPS_REG_V0)
v0 := uint64(0)
if syscall_no == 4020 {
oracle_hash, _ := mu.MemRead(0x30001000, 0x20)
oracle_hash, _ := mu.MemRead(0xB0001000, 0x20)
hash := common.BytesToHash(oracle_hash)
key := fmt.Sprintf("/tmp/eth/%s", hash)
value, _ := ioutil.ReadFile(key)
tmp := []byte{0, 0, 0, 0}
binary.BigEndian.PutUint32(tmp, uint32(len(value)))
mu.MemWrite(0x31000000, tmp)
mu.MemWrite(0x31000004, value)
mu.MemWrite(0xB1000000, tmp)
mu.MemWrite(0xB1000004, value)
WriteRam(ram, 0x31000000, uint32(len(value)))
WriteRam(ram, 0xB1000000, uint32(len(value)))
value = append(value, 0, 0, 0)
for i := uint32(0); i < ram[0x31000000]; i += 4 {
WriteRam(ram, 0x31000004+i, binary.BigEndian.Uint32(value[i:i+4]))
for i := uint32(0); i < ram[0xB1000000]; i += 4 {
WriteRam(ram, 0xB1000004+i, binary.BigEndian.Uint32(value[i:i+4]))
}
} else if syscall_no == 4004 {
fd, _ := mu.RegRead(uc.MIPS_REG_A0)
......@@ -177,10 +177,10 @@ func RunUnicorn(fn string, ram map[uint32](uint32), totalSteps int, callback fun
// inputs
inputFile := fmt.Sprintf("/tmp/eth/%d", 13284469)
inputs, _ := ioutil.ReadFile(inputFile)
mu.MemWrite(0x30000000, inputs)
mu.MemWrite(0xB0000000, inputs)
LoadMappedFile(fn, ram, 0)
LoadMappedFile(inputFile, ram, 0x30000000)
LoadMappedFile(inputFile, ram, 0xB0000000)
mu.Start(0, 0x5ead0004)
}
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