Commit 961ba684 authored by George Hotz's avatar George Hotz

move the oracle back to 0x3000...

parent 760bdf77
...@@ -100,13 +100,13 @@ contract Challenge { ...@@ -100,13 +100,13 @@ contract Challenge {
} }
bytes32 startState = GlobalStartState; bytes32 startState = GlobalStartState;
startState = mem.WriteBytes32(startState, 0xB0000000, inputHash); startState = mem.WriteBytes32(startState, 0x30000000, inputHash);
// confirm the finalSystemHash asserts the state you claim and the machine is stopped // confirm the finalSystemHash asserts the state you claim and the machine is stopped
// you must load these trie nodes into MIPSMemory before calling this // you must load these trie nodes into MIPSMemory before calling this
require(mem.ReadMemory(finalSystemState, 0xC0000080) == 0x5EAD0000, "machine is not stopped in final state (PC == 0x5EAD0000)"); require(mem.ReadMemory(finalSystemState, 0xC0000080) == 0x5EAD0000, "machine is not stopped in final state (PC == 0x5EAD0000)");
require(mem.ReadMemory(finalSystemState, 0xB0000800) == 0x1337f00d, "state is not outputted"); require(mem.ReadMemory(finalSystemState, 0x30000800) == 0x1337f00d, "state is not outputted");
require(mem.ReadBytes32(finalSystemState, 0xB0000804) == assertionRoot, "you are claiming a different state root in machine"); require(mem.ReadBytes32(finalSystemState, 0x30000804) == assertionRoot, "you are claiming a different state root in machine");
return newChallengeTrusted(startState, finalSystemState, stepCount); return newChallengeTrusted(startState, finalSystemState, stepCount);
} }
......
...@@ -108,12 +108,12 @@ contract MIPSMemory { ...@@ -108,12 +108,12 @@ contract MIPSMemory {
} }
// MMIO preimage oracle // MMIO preimage oracle
if (addr >= 0xB1000000 && addr < 0xB2000000) { if (addr >= 0x31000000 && addr < 0x32000000) {
bytes32 pihash = ReadBytes32(stateHash, 0xB0001000); bytes32 pihash = ReadBytes32(stateHash, 0x30001000);
if (addr == 0xB1000000) { if (addr == 0x31000000) {
return uint32(preimage[pihash].length); return uint32(preimage[pihash].length);
} }
uint offset = addr-0xB1000004; uint offset = addr-0x31000004;
uint8 a0 = uint8(preimage[pihash][offset]); uint8 a0 = uint8(preimage[pihash][offset]);
uint8 a1 = uint8(preimage[pihash][offset+1]); uint8 a1 = uint8(preimage[pihash][offset+1]);
uint8 a2 = uint8(preimage[pihash][offset+2]); uint8 a2 = uint8(preimage[pihash][offset+2]);
......
...@@ -26,7 +26,7 @@ func byteAt(addr uint64, length int) []byte { ...@@ -26,7 +26,7 @@ func byteAt(addr uint64, length int) []byte {
} }
func InputHash() common.Hash { func InputHash() common.Hash {
ret := byteAt(0xB0000000, 0x20) ret := byteAt(0x30000000, 0x20)
os.Stderr.WriteString("********* on chain starts here *********\n") os.Stderr.WriteString("********* on chain starts here *********\n")
return common.BytesToHash(ret) return common.BytesToHash(ret)
} }
...@@ -38,11 +38,11 @@ func Halt() { ...@@ -38,11 +38,11 @@ func Halt() {
} }
func Output(output common.Hash, receipts common.Hash) { func Output(output common.Hash, receipts common.Hash) {
ret := byteAt(0xB0000804, 0x20) ret := byteAt(0x30000804, 0x20)
copy(ret, output.Bytes()) copy(ret, output.Bytes())
rret := byteAt(0xB0000824, 0x20) rret := byteAt(0x30000824, 0x20)
copy(rret, receipts.Bytes()) copy(rret, receipts.Bytes())
magic := byteAt(0xB0000800, 4) magic := byteAt(0x30000800, 4)
copy(magic, []byte{0x13, 0x37, 0xf0, 0x0d}) copy(magic, []byte{0x13, 0x37, 0xf0, 0x0d})
Halt() Halt()
} }
...@@ -51,7 +51,7 @@ func Preimage(hash common.Hash) []byte { ...@@ -51,7 +51,7 @@ func Preimage(hash common.Hash) []byte {
val, ok := preimages[hash] val, ok := preimages[hash]
if !ok { if !ok {
// load in hash // load in hash
preImageHash := byteAt(0xB0001000, 0x20) preImageHash := byteAt(0x30001000, 0x20)
copy(preImageHash, hash.Bytes()) copy(preImageHash, hash.Bytes())
// used in unicorn emulator to trigger the load // used in unicorn emulator to trigger the load
...@@ -59,9 +59,9 @@ func Preimage(hash common.Hash) []byte { ...@@ -59,9 +59,9 @@ func Preimage(hash common.Hash) []byte {
os.Getpid() os.Getpid()
// ready // ready
rawSize := common.CopyBytes(byteAt(0xB1000000, 4)) rawSize := common.CopyBytes(byteAt(0x31000000, 4))
size := (int(rawSize[0]) << 24) | (int(rawSize[1]) << 16) | (int(rawSize[2]) << 8) | int(rawSize[3]) size := (int(rawSize[0]) << 24) | (int(rawSize[1]) << 16) | (int(rawSize[2]) << 8) | int(rawSize[3])
ret := common.CopyBytes(byteAt(0xB1000004, size)) ret := common.CopyBytes(byteAt(0x31000004, size))
// this is 20% of the exec instructions, this speedup is always an option // this is 20% of the exec instructions, this speedup is always an option
realhash := crypto.Keccak256Hash(ret) realhash := crypto.Keccak256Hash(ret)
......
...@@ -35,7 +35,7 @@ func TestCompareUnicornEvm(t *testing.T) { ...@@ -35,7 +35,7 @@ func TestCompareUnicornEvm(t *testing.T) {
evmram := make(map[uint32](uint32)) evmram := make(map[uint32](uint32))
LoadMappedFile(fn, evmram, 0) LoadMappedFile(fn, evmram, 0)
inputFile := fmt.Sprintf("/tmp/eth/%d", 13284469) inputFile := fmt.Sprintf("/tmp/eth/%d", 13284469)
LoadMappedFile(inputFile, evmram, 0xB0000000) LoadMappedFile(inputFile, evmram, 0x30000000)
// init registers to 0 in evm // init registers to 0 in evm
for i := uint32(0xC0000000); i < 0xC0000000+36*4; i += 4 { for i := uint32(0xC0000000); i < 0xC0000000+36*4; i += 4 {
WriteRam(evmram, i, 0) WriteRam(evmram, i, 0)
......
...@@ -23,7 +23,7 @@ func main() { ...@@ -23,7 +23,7 @@ func main() {
lastStep := 0 lastStep := 0
mu := GetHookedUnicorn(root, ram, func(step int, mu uc.Unicorn, ram map[uint32](uint32)) { mu := GetHookedUnicorn(root, ram, func(step int, mu uc.Unicorn, ram map[uint32](uint32)) {
// this can be raised to 10,000,000 if the files are too large // this can be raised to 10,000,000 if the files are too large
if step%1000000 == 0 { if step%10000000 == 0 {
SyncRegs(mu, ram) SyncRegs(mu, ram)
WriteCheckpoint(ram, root, step) WriteCheckpoint(ram, root, step)
} }
...@@ -31,9 +31,10 @@ func main() { ...@@ -31,9 +31,10 @@ func main() {
}) })
ZeroRegisters(ram) ZeroRegisters(ram)
LoadMappedFileUnicorn(mu, "../mipigo/golden/minigeth.bin", ram, 0) // not ready for golden yet
LoadMappedFileUnicorn(mu, "../mipigo/minigeth.bin", ram, 0)
WriteCheckpoint(ram, root, -1) WriteCheckpoint(ram, root, -1)
LoadMappedFileUnicorn(mu, fmt.Sprintf("%s/input", root), ram, 0xB0000000) LoadMappedFileUnicorn(mu, fmt.Sprintf("%s/input", root), ram, 0x30000000)
mu.Start(0, 0x5ead0004) mu.Start(0, 0x5ead0004)
SyncRegs(mu, ram) SyncRegs(mu, ram)
......
...@@ -80,20 +80,20 @@ func GetHookedUnicorn(root string, ram map[uint32](uint32), callback func(int, u ...@@ -80,20 +80,20 @@ func GetHookedUnicorn(root string, ram map[uint32](uint32), callback func(int, u
syscall_no, _ := mu.RegRead(uc.MIPS_REG_V0) syscall_no, _ := mu.RegRead(uc.MIPS_REG_V0)
v0 := uint64(0) v0 := uint64(0)
if syscall_no == 4020 { if syscall_no == 4020 {
oracle_hash, _ := mu.MemRead(0xB0001000, 0x20) oracle_hash, _ := mu.MemRead(0x30001000, 0x20)
hash := common.BytesToHash(oracle_hash) hash := common.BytesToHash(oracle_hash)
key := fmt.Sprintf("%s/%s", root, 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}
binary.BigEndian.PutUint32(tmp, uint32(len(value))) binary.BigEndian.PutUint32(tmp, uint32(len(value)))
mu.MemWrite(0xB1000000, tmp) mu.MemWrite(0x31000000, tmp)
mu.MemWrite(0xB1000004, value) mu.MemWrite(0x31000004, value)
WriteRam(ram, 0xB1000000, uint32(len(value))) WriteRam(ram, 0x31000000, uint32(len(value)))
value = append(value, 0, 0, 0) value = append(value, 0, 0, 0)
for i := uint32(0); i < ram[0xB1000000]; i += 4 { for i := uint32(0); i < ram[0x31000000]; i += 4 {
WriteRam(ram, 0xB1000004+i, binary.BigEndian.Uint32(value[i:i+4])) WriteRam(ram, 0x31000004+i, binary.BigEndian.Uint32(value[i:i+4]))
} }
} else if syscall_no == 4004 { } else if syscall_no == 4004 {
fd, _ := mu.RegRead(uc.MIPS_REG_A0) fd, _ := mu.RegRead(uc.MIPS_REG_A0)
...@@ -179,12 +179,12 @@ func RunUnicorn(fn string, ram map[uint32](uint32), checkIO bool, callback func( ...@@ -179,12 +179,12 @@ func RunUnicorn(fn string, ram map[uint32](uint32), checkIO bool, callback func(
// inputs // inputs
inputs, _ := ioutil.ReadFile(fmt.Sprintf("%s/input", root)) inputs, _ := ioutil.ReadFile(fmt.Sprintf("%s/input", root))
mu.MemWrite(0xB0000000, inputs[0:0xc0]) mu.MemWrite(0x30000000, inputs[0:0xc0])
// load into ram // load into ram
LoadData(dat, ram, 0) LoadData(dat, ram, 0)
if checkIO { if checkIO {
LoadData(inputs[0:0xc0], ram, 0xB0000000) LoadData(inputs[0:0xc0], ram, 0x30000000)
} }
mu.Start(0, 0x5ead0004) mu.Start(0, 0x5ead0004)
...@@ -192,7 +192,7 @@ func RunUnicorn(fn string, ram map[uint32](uint32), checkIO bool, callback func( ...@@ -192,7 +192,7 @@ func RunUnicorn(fn string, ram map[uint32](uint32), checkIO bool, callback func(
if checkIO { if checkIO {
outputs, _ := ioutil.ReadFile(fmt.Sprintf("%s/output", root)) outputs, _ := ioutil.ReadFile(fmt.Sprintf("%s/output", root))
real := append([]byte{0x13, 0x37, 0xf0, 0x0d}, outputs...) real := append([]byte{0x13, 0x37, 0xf0, 0x0d}, outputs...)
output, _ := mu.MemRead(0xB0000800, 0x44) output, _ := mu.MemRead(0x30000800, 0x44)
if bytes.Compare(real, output) != 0 { if bytes.Compare(real, output) != 0 {
log.Fatal("mismatch output") log.Fatal("mismatch output")
} else { } else {
......
...@@ -37,6 +37,7 @@ describe("Challenge contract", function () { ...@@ -37,6 +37,7 @@ describe("Challenge contract", function () {
while (1) { while (1) {
try { try {
await c.InitiateChallenge(blockNumberN, blockNp1Rlp, assertionRoot, finalSystemState, 1) await c.InitiateChallenge(blockNumberN, blockNp1Rlp, assertionRoot, finalSystemState, 1)
break
} catch(e) { } catch(e) {
const missing = e.toString().split("'")[1] const missing = e.toString().split("'")[1]
if (missing.length == 64) { if (missing.length == 64) {
......
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