Commit ffe42fb7 authored by George Hotz's avatar George Hotz

separate input and output

parent 69791851
......@@ -187,24 +187,22 @@ func PrefetchCode(blockNumber *big.Int, addrHash common.Hash) {
preimages[hash] = ret
}
var inputs [8]common.Hash
var inputs [6]common.Hash
var outputs [2]common.Hash
func Input(index int) common.Hash {
if index < 0 || index > 5 {
panic("bad input index")
}
return inputs[index]
}
func Output(output common.Hash, receipts common.Hash) {
if receipts != inputs[7] {
fmt.Println("WARNING, receipts don't match", receipts, "!=", inputs[7])
if receipts != outputs[1] {
fmt.Println("WARNING, receipts don't match", receipts, "!=", outputs[1])
panic("BAD receipts")
}
if output == inputs[6] {
if output == outputs[0] {
fmt.Println("good transition")
} else {
fmt.Println(output, "!=", inputs[6])
fmt.Println(output, "!=", outputs[0])
panic("BAD transition :((")
}
}
......@@ -294,17 +292,23 @@ func PrefetchBlock(blockNumber *big.Int, startBlock bool, hasher types.TrieHashe
inputs[4] = common.BigToHash(big.NewInt(int64(blockHeader.GasLimit)))
inputs[5] = common.BigToHash(big.NewInt(int64(blockHeader.Time)))
// secret input
inputs[6] = blockHeader.Root
inputs[7] = blockHeader.ReceiptHash
// save the inputs
saveinput := make([]byte, 0)
for i := 0; i < len(inputs); i++ {
saveinput = append(saveinput, inputs[i].Bytes()[:]...)
}
key := fmt.Sprintf("%s/input", root)
ioutil.WriteFile(key, saveinput, 0644)
ioutil.WriteFile(fmt.Sprintf("%s/input", root), saveinput, 0644)
// secret input aka output
outputs[0] = blockHeader.Root
outputs[1] = blockHeader.ReceiptHash
// save the outputs
saveoutput := make([]byte, 0)
for i := 0; i < len(outputs); i++ {
saveoutput = append(saveoutput, outputs[i].Bytes()[:]...)
}
ioutil.WriteFile(fmt.Sprintf("%s/output", root), saveoutput, 0644)
// save the txs
txs := make([]*types.Transaction, len(jr.Result.Transactions))
......
......@@ -22,6 +22,7 @@ func main() {
lastStep := 0
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
if step%1000000 == 0 {
SyncRegs(mu, ram)
WriteCheckpoint(ram, root, step)
......
......@@ -178,8 +178,7 @@ func RunUnicorn(fn string, ram map[uint32](uint32), checkIO bool, callback func(
mu.MemWrite(0, dat)
// inputs
inputFile := fmt.Sprintf("%s/input", root)
inputs, _ := ioutil.ReadFile(inputFile)
inputs, _ := ioutil.ReadFile(fmt.Sprintf("%s/input", root))
mu.MemWrite(0xB0000000, inputs[0:0xc0])
// load into ram
......@@ -191,7 +190,8 @@ func RunUnicorn(fn string, ram map[uint32](uint32), checkIO bool, callback func(
mu.Start(0, 0x5ead0004)
if checkIO {
real := append([]byte{0x13, 0x37, 0xf0, 0x0d}, inputs[0xc0:]...)
outputs, _ := ioutil.ReadFile(fmt.Sprintf("%s/output", root))
real := append([]byte{0x13, 0x37, 0xf0, 0x0d}, outputs...)
output, _ := mu.MemRead(0xB0000800, 0x44)
if bytes.Compare(real, output) != 0 {
log.Fatal("mismatch output")
......
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