Commit df6dfbb8 authored by George Hotz's avatar George Hotz

refactor to use inputhash instead of input

parent ffe42fb7
...@@ -60,9 +60,16 @@ func main() { ...@@ -60,9 +60,16 @@ func main() {
// init secp256k1BytePoints // init secp256k1BytePoints
crypto.S256() crypto.S256()
// get inputs
inputBytes := oracle.Preimage(oracle.InputHash())
var inputs [6]common.Hash
for i := 0; i < len(inputs); i++ {
inputs[i] = common.BytesToHash(inputBytes[i*0x20 : i*0x20+0x20])
}
// read start block header // read start block header
var parent types.Header var parent types.Header
check(rlp.DecodeBytes(oracle.Preimage(oracle.Input(0)), &parent)) check(rlp.DecodeBytes(oracle.Preimage(inputs[0]), &parent))
// read header // read header
var newheader types.Header var newheader types.Header
...@@ -72,11 +79,11 @@ func main() { ...@@ -72,11 +79,11 @@ func main() {
newheader.BaseFee = misc.CalcBaseFee(params.MainnetChainConfig, &parent) newheader.BaseFee = misc.CalcBaseFee(params.MainnetChainConfig, &parent)
// from input oracle // from input oracle
newheader.TxHash = oracle.Input(1) newheader.TxHash = inputs[1]
newheader.Coinbase = common.BigToAddress(oracle.Input(2).Big()) newheader.Coinbase = common.BigToAddress(inputs[2].Big())
newheader.UncleHash = oracle.Input(3) newheader.UncleHash = inputs[3]
newheader.GasLimit = oracle.Input(4).Big().Uint64() newheader.GasLimit = inputs[4].Big().Uint64()
newheader.Time = oracle.Input(5).Big().Uint64() newheader.Time = inputs[5].Big().Uint64()
bc := core.NewBlockChain(&parent) bc := core.NewBlockChain(&parent)
database := state.NewDatabase(parent) database := state.NewDatabase(parent)
......
...@@ -16,10 +16,6 @@ import ( ...@@ -16,10 +16,6 @@ import (
var preimages = make(map[common.Hash][]byte) var preimages = make(map[common.Hash][]byte)
// only 6 here
var inputs [6]common.Hash
var inputsLoaded bool = false
func byteAt(addr uint64, length int) []byte { func byteAt(addr uint64, length int) []byte {
var ret []byte var ret []byte
bh := (*reflect.SliceHeader)(unsafe.Pointer(&ret)) bh := (*reflect.SliceHeader)(unsafe.Pointer(&ret))
...@@ -29,25 +25,10 @@ func byteAt(addr uint64, length int) []byte { ...@@ -29,25 +25,10 @@ func byteAt(addr uint64, length int) []byte {
return ret return ret
} }
func Input(index int) common.Hash { func InputHash() common.Hash {
if index < 0 || index > 6 { ret := byteAt(0xB0000000, 0x20)
panic("bad input index") os.Stderr.WriteString("********* on chain starts here *********\n")
} return common.BytesToHash(ret)
if !inputsLoaded {
// before this isn't run on chain (confirm this isn't cached)
// does this interact with the GC?
ret := byteAt(0xB0000000, len(inputs)*0x20)
os.Stderr.WriteString("********* on chain starts here *********\n")
for i := 0; i < len(inputs); i++ {
inputs[i] = common.BytesToHash(ret[i*0x20 : i*0x20+0x20])
//fmt.Println(i, inputs[i])
}
inputsLoaded = true
}
return inputs[index]
} }
func Halt() { func Halt() {
......
...@@ -187,13 +187,15 @@ func PrefetchCode(blockNumber *big.Int, addrHash common.Hash) { ...@@ -187,13 +187,15 @@ func PrefetchCode(blockNumber *big.Int, addrHash common.Hash) {
preimages[hash] = ret preimages[hash] = ret
} }
var inputs [6]common.Hash var inputhash common.Hash
var outputs [2]common.Hash
func Input(index int) common.Hash { func InputHash() common.Hash {
return inputs[index] return inputhash
} }
var inputs [6]common.Hash
var outputs [2]common.Hash
func Output(output common.Hash, receipts common.Hash) { func Output(output common.Hash, receipts common.Hash) {
if receipts != outputs[1] { if receipts != outputs[1] {
fmt.Println("WARNING, receipts don't match", receipts, "!=", outputs[1]) fmt.Println("WARNING, receipts don't match", receipts, "!=", outputs[1])
...@@ -282,8 +284,8 @@ func PrefetchBlock(blockNumber *big.Int, startBlock bool, hasher types.TrieHashe ...@@ -282,8 +284,8 @@ func PrefetchBlock(blockNumber *big.Int, startBlock bool, hasher types.TrieHashe
} }
// second block // second block
if blockHeader.ParentHash != Input(0) { if blockHeader.ParentHash != inputs[0] {
fmt.Println(blockHeader.ParentHash, Input(0)) fmt.Println(blockHeader.ParentHash, inputs[0])
panic("block transition isn't correct") panic("block transition isn't correct")
} }
inputs[1] = blockHeader.TxHash inputs[1] = blockHeader.TxHash
...@@ -297,7 +299,10 @@ func PrefetchBlock(blockNumber *big.Int, startBlock bool, hasher types.TrieHashe ...@@ -297,7 +299,10 @@ func PrefetchBlock(blockNumber *big.Int, startBlock bool, hasher types.TrieHashe
for i := 0; i < len(inputs); i++ { for i := 0; i < len(inputs); i++ {
saveinput = append(saveinput, inputs[i].Bytes()[:]...) saveinput = append(saveinput, inputs[i].Bytes()[:]...)
} }
ioutil.WriteFile(fmt.Sprintf("%s/input", root), saveinput, 0644) inputhash = crypto.Keccak256Hash(saveinput)
preimages[inputhash] = saveinput
ioutil.WriteFile(fmt.Sprintf("%s/input", root), inputhash.Bytes(), 0644)
//ioutil.WriteFile(fmt.Sprintf("%s/input", root), saveinput, 0644)
// secret input aka output // secret input aka output
outputs[0] = blockHeader.Root outputs[0] = blockHeader.Root
......
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