Commit 21f5e0fe authored by George Hotz's avatar George Hotz

working with oracle on pc

parent caca8779
...@@ -83,22 +83,22 @@ contract Challenge { ...@@ -83,22 +83,22 @@ contract Challenge {
// decode the blocks // decode the blocks
Lib_RLPReader.RLPItem[] memory blockNp1 = Lib_RLPReader.readList(blockHeaderNp1); Lib_RLPReader.RLPItem[] memory blockNp1 = Lib_RLPReader.readList(blockHeaderNp1);
bytes32 parentHash = Lib_RLPReader.readBytes32(blockNp1[0]);
require(blockhash(blockNumberN) == parentHash, "parent block hash somehow wrong");
bytes32 newroot = Lib_RLPReader.readBytes32(blockNp1[3]); bytes32 newroot = Lib_RLPReader.readBytes32(blockNp1[3]);
require(assertionRoot != newroot, "asserting that the real state is correct is not a challenge"); require(assertionRoot != newroot, "asserting that the real state is correct is not a challenge");
// input oracle info
bytes32 txhash = Lib_RLPReader.readBytes32(blockNp1[4]);
address coinbase = Lib_RLPReader.readAddress(blockNp1[2]);
bytes32 uncles = Lib_RLPReader.readBytes32(blockNp1[1]);
// load starting info into the input oracle // load starting info into the input oracle
// we both agree at the beginning // we both agree at the beginning
// the first instruction executed in MIPS should be an access of startState // the first instruction executed in MIPS should be an access of startState
// parentblockhash, txhash, coinbase, unclehash, gaslimit
bytes32 startState = GlobalStartState; bytes32 startState = GlobalStartState;
startState = writeBytes32(startState, 0xD0000000, blockhash(blockNumberN)); startState = writeBytes32(startState, 0xD0000000, parentHash);
startState = writeBytes32(startState, 0xD0000020, txhash); startState = writeBytes32(startState, 0xD0000020, Lib_RLPReader.readBytes32(blockNp1[4]));
startState = writeBytes32(startState, 0xD0000040, bytes32(uint256(coinbase))); startState = writeBytes32(startState, 0xD0000040, bytes32(uint256(Lib_RLPReader.readAddress(blockNp1[2]))));
startState = writeBytes32(startState, 0xD0000060, uncles); startState = writeBytes32(startState, 0xD0000060, Lib_RLPReader.readBytes32(blockNp1[1]));
startState = writeBytes32(startState, 0xD0000080, bytes32(Lib_RLPReader.readUint256(blockNp1[9])));
// confirm the finalSystemHash asserts the state you claim (in $t0-$t7) and the machine is stopped // confirm the finalSystemHash asserts the state you claim (in $t0-$t7) and the machine is stopped
// you must load these proofs into MIPS before calling this // you must load these proofs into MIPS before calling this
......
...@@ -101,7 +101,7 @@ func (ethash *Ethash) Finalize(chain consensus.ChainHeaderReader, header *types. ...@@ -101,7 +101,7 @@ func (ethash *Ethash) Finalize(chain consensus.ChainHeaderReader, header *types.
// Accumulate any block and uncle rewards and commit the final state root // Accumulate any block and uncle rewards and commit the final state root
accumulateRewards(chain.Config(), state, header, uncles) accumulateRewards(chain.Config(), state, header, uncles)
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number)) header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
//fmt.Println("new Root", header.Root) fmt.Println("new Root", header.Root)
} }
func (ethash *Ethash) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) { func (ethash *Ethash) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) {
......
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"os" "os"
"strconv" "strconv"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus/misc" "github.com/ethereum/go-ethereum/consensus/misc"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/state"
...@@ -41,17 +42,16 @@ func main() { ...@@ -41,17 +42,16 @@ func main() {
// read header // read header
var newheader types.Header var newheader types.Header
// from parent
newheader.ParentHash = parent.Hash() newheader.ParentHash = parent.Hash()
newheader.TxHash = oracle.Input(1)
newheader.Number = big.NewInt(0).Add(parent.Number, big.NewInt(1)) newheader.Number = big.NewInt(0).Add(parent.Number, big.NewInt(1))
newheader.BaseFee = misc.CalcBaseFee(params.MainnetChainConfig, &parent) newheader.BaseFee = misc.CalcBaseFee(params.MainnetChainConfig, &parent)
/*{
f, _ := os.Open(fmt.Sprintf("data/block_%d", blockNumber+1)) // from input oracle
rlpheader := rlp.NewStream(f, 0) newheader.TxHash = oracle.Input(1)
rlpheader.Decode(&newheader) newheader.Coinbase = common.BigToAddress(oracle.Input(2).Big())
f.Close() newheader.UncleHash = oracle.Input(3)
fmt.Println("read new block") newheader.GasLimit = oracle.Input(4).Big().Uint64()
}*/
bc := core.NewBlockChain() bc := core.NewBlockChain()
database := state.NewDatabase(parent) database := state.NewDatabase(parent)
...@@ -80,16 +80,16 @@ func main() { ...@@ -80,16 +80,16 @@ func main() {
if newheader.TxHash != block.Header().TxHash { if newheader.TxHash != block.Header().TxHash {
panic("wrong transactions for block") panic("wrong transactions for block")
} }
if newheader.UncleHash != block.Header().UncleHash {
panic("wrong uncles for block")
}
_, _, _, err := processor.Process(block, statedb, vmconfig) _, _, _, err := processor.Process(block, statedb, vmconfig)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
newroot := statedb.IntermediateRoot(bc.Config().IsEIP158(newheader.Number))
fmt.Println("process done with hash", parent.Root, "->", block.Header().Root, "real", newheader.Root) fmt.Println("process done with hash", parent.Root, "->", newroot)
if block.Header().Root == newheader.Root { oracle.Output(newroot)
fmt.Println("good transition")
} else {
panic("BAD transition :((")
}
} }
...@@ -159,12 +159,22 @@ func PrefetchCode(blockNumber *big.Int, addrHash common.Hash) { ...@@ -159,12 +159,22 @@ func PrefetchCode(blockNumber *big.Int, addrHash common.Hash) {
preimages[hash] = ret preimages[hash] = ret
} }
var inputs [4]common.Hash var inputs [5]common.Hash
var realoutput common.Hash
func Input(index int) common.Hash { func Input(index int) common.Hash {
return inputs[index] return inputs[index]
} }
func Output(output common.Hash) {
if output == realoutput {
fmt.Println("good transition")
} else {
fmt.Println(output, "!=", realoutput)
panic("BAD transition :((")
}
}
func PrefetchBlock(blockNumber *big.Int, startBlock bool, hasher types.TrieHasher) { func PrefetchBlock(blockNumber *big.Int, startBlock bool, hasher types.TrieHasher) {
r := jsonreq{Jsonrpc: "2.0", Method: "eth_getBlockByNumber", Id: 1} r := jsonreq{Jsonrpc: "2.0", Method: "eth_getBlockByNumber", Id: 1}
r.Params = make([]interface{}, 2) r.Params = make([]interface{}, 2)
...@@ -200,6 +210,8 @@ func PrefetchBlock(blockNumber *big.Int, startBlock bool, hasher types.TrieHashe ...@@ -200,6 +210,8 @@ func PrefetchBlock(blockNumber *big.Int, startBlock bool, hasher types.TrieHashe
inputs[1] = blockHeader.TxHash inputs[1] = blockHeader.TxHash
inputs[2] = blockHeader.Coinbase.Hash() inputs[2] = blockHeader.Coinbase.Hash()
inputs[3] = blockHeader.UncleHash inputs[3] = blockHeader.UncleHash
inputs[4] = common.BigToHash(big.NewInt(int64(blockHeader.GasLimit)))
realoutput = blockHeader.Root
txs := make([]*types.Transaction, len(jr.Result.Transactions)) txs := make([]*types.Transaction, len(jr.Result.Transactions))
for i := 0; i < len(jr.Result.Transactions); i++ { for i := 0; i < len(jr.Result.Transactions); i++ {
......
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