Commit e0160775 authored by George Hotz's avatar George Hotz

fix chain oracle

parent 7c3b3af0
...@@ -35,7 +35,7 @@ func TestCompareEvmChain(t *testing.T) { ...@@ -35,7 +35,7 @@ func TestCompareEvmChain(t *testing.T) {
fmt.Println("state root", root, "nodes", len(Preimages)) fmt.Println("state root", root, "nodes", len(Preimages))
// deploy chain // deploy chain
interpreter, statedb := GetInterpreter(0, true) interpreter, statedb := GetInterpreter(0, true, "")
DeployChain(interpreter, statedb) DeployChain(interpreter, statedb)
// load chain trie node // load chain trie node
...@@ -68,7 +68,7 @@ func TestCompareEvmChain(t *testing.T) { ...@@ -68,7 +68,7 @@ func TestCompareEvmChain(t *testing.T) {
// run on evm // run on evm
go func() { go func() {
for step := 0; step < totalSteps; step++ { for step := 0; step < totalSteps; step++ {
RunWithRam(ram, 1, 0, nil) RunWithRam(ram, 1, 0, "", nil)
root = RamToTrie(ram) root = RamToTrie(ram)
cuni <- root cuni <- root
} }
......
...@@ -42,7 +42,7 @@ func TestCompareUnicornEvm(t *testing.T) { ...@@ -42,7 +42,7 @@ func TestCompareUnicornEvm(t *testing.T) {
WriteRam(evmram, i, 0) WriteRam(evmram, i, 0)
} }
go RunWithRam(evmram, steps, 0, func(step int, ram map[uint32](uint32)) { go RunWithRam(evmram, steps, 0, "", func(step int, ram map[uint32](uint32)) {
//fmt.Printf("%d evm %x\n", step, ram[0xc0000080]) //fmt.Printf("%d evm %x\n", step, ram[0xc0000080])
cevm <- RegSerialize(ram) cevm <- RegSerialize(ram)
done.Lock() done.Lock()
......
...@@ -40,7 +40,7 @@ func main() { ...@@ -40,7 +40,7 @@ func main() {
LoadMappedFile("../mipigo/minigeth.bin", ram, 0) LoadMappedFile("../mipigo/minigeth.bin", ram, 0)
WriteCheckpoint(ram, "/tmp/cannon/golden.json", -1) WriteCheckpoint(ram, "/tmp/cannon/golden.json", -1)
LoadMappedFile(fmt.Sprintf("%s/input", root), ram, 0x30000000) LoadMappedFile(fmt.Sprintf("%s/input", root), ram, 0x30000000)
RunWithRam(ram, target-1, 0, nil) RunWithRam(ram, target-1, 0, root, nil)
lastStep += target - 1 lastStep += target - 1
fn := fmt.Sprintf("%s/checkpoint_%d.json", root, lastStep) fn := fmt.Sprintf("%s/checkpoint_%d.json", root, lastStep)
WriteCheckpoint(ram, fn, lastStep) WriteCheckpoint(ram, fn, lastStep)
......
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log"
"math/big" "math/big"
"os" "os"
"time" "time"
...@@ -27,15 +28,17 @@ type StateDB struct { ...@@ -27,15 +28,17 @@ type StateDB struct {
PcCount int PcCount int
seenWrite bool seenWrite bool
useRealState bool useRealState bool
root string
} }
func NewStateDB(debug int, realState bool) *StateDB { func NewStateDB(debug int, realState bool, root string) *StateDB {
statedb := &StateDB{} statedb := &StateDB{}
statedb.Bytecodes = make(map[common.Address]([]byte)) statedb.Bytecodes = make(map[common.Address]([]byte))
statedb.RealState = make(map[common.Hash](common.Hash)) statedb.RealState = make(map[common.Hash](common.Hash))
statedb.Debug = debug statedb.Debug = debug
statedb.seenWrite = true statedb.seenWrite = true
statedb.useRealState = realState statedb.useRealState = realState
statedb.root = root
return statedb return statedb
} }
...@@ -124,8 +127,10 @@ func (s *StateDB) GetState(fakeaddr common.Address, hash common.Hash) common.Has ...@@ -124,8 +127,10 @@ func (s *StateDB) GetState(fakeaddr common.Address, hash common.Hash) common.Has
binary.BigEndian.PutUint32(oracle_hash[i:i+4], ram[0x30001000+i]) binary.BigEndian.PutUint32(oracle_hash[i:i+4], ram[0x30001000+i])
} }
hash := common.BytesToHash(oracle_hash) hash := common.BytesToHash(oracle_hash)
// TODO: this is wrong, need root if s.root == "" {
key := fmt.Sprintf("/tmp/eth/%s", hash) log.Fatal("need root if using hash oracle")
}
key := fmt.Sprintf("%s/%s", s.root, hash)
value, _ := ioutil.ReadFile(key) value, _ := ioutil.ReadFile(key)
WriteRam(ram, 0x31000000, uint32(len(value))) WriteRam(ram, 0x31000000, uint32(len(value)))
......
...@@ -15,7 +15,7 @@ func TestMipsChain(t *testing.T) { ...@@ -15,7 +15,7 @@ func TestMipsChain(t *testing.T) {
ram := LoadRam() ram := LoadRam()
root := RamToTrie(ram) root := RamToTrie(ram)
interpreter, statedb := GetInterpreter(1, true) interpreter, statedb := GetInterpreter(1, true, "")
DeployChain(interpreter, statedb) DeployChain(interpreter, statedb)
// load chain trie node // load chain trie node
......
...@@ -27,7 +27,7 @@ func TestSimpleEVM(t *testing.T) { ...@@ -27,7 +27,7 @@ func TestSimpleEVM(t *testing.T) {
LoadMappedFile(fn, ram, 0) LoadMappedFile(fn, ram, 0)
start := time.Now() start := time.Now()
remainingGas, err := RunWithRam(ram, 100, 0, nil) remainingGas, err := RunWithRam(ram, 100, 0, "", nil)
elapsed := time.Now().Sub(start) elapsed := time.Now().Sub(start)
fmt.Println(err, remainingGas, elapsed, fmt.Println(err, remainingGas, elapsed,
......
...@@ -101,7 +101,7 @@ func LoadMappedFile(fn string, ram map[uint32](uint32), base uint32) { ...@@ -101,7 +101,7 @@ func LoadMappedFile(fn string, ram map[uint32](uint32), base uint32) {
} }
func RunFull() { func RunFull() {
interpreter, statedb := GetInterpreter(0, true) interpreter, statedb := GetInterpreter(0, true, "")
DeployChain(interpreter, statedb) DeployChain(interpreter, statedb)
ram := make(map[uint32](uint32)) ram := make(map[uint32](uint32))
......
...@@ -34,8 +34,8 @@ func GetBytecode(deployed bool) []byte { ...@@ -34,8 +34,8 @@ func GetBytecode(deployed bool) []byte {
} }
} }
func GetInterpreter(ldebug int, realState bool) (*vm.EVMInterpreter, *StateDB) { func GetInterpreter(ldebug int, realState bool, root string) (*vm.EVMInterpreter, *StateDB) {
statedb := NewStateDB(ldebug, realState) statedb := NewStateDB(ldebug, realState, root)
var header types.Header var header types.Header
header.Number = big.NewInt(13284469) header.Number = big.NewInt(13284469)
...@@ -52,8 +52,8 @@ func GetInterpreter(ldebug int, realState bool) (*vm.EVMInterpreter, *StateDB) { ...@@ -52,8 +52,8 @@ func GetInterpreter(ldebug int, realState bool) (*vm.EVMInterpreter, *StateDB) {
return interpreter, statedb return interpreter, statedb
} }
func RunWithRam(lram map[uint32](uint32), steps int, debug int, lcallback func(int, map[uint32](uint32))) (uint64, error) { func RunWithRam(lram map[uint32](uint32), steps int, debug int, root string, lcallback func(int, map[uint32](uint32))) (uint64, error) {
interpreter, statedb := GetInterpreter(debug, false) interpreter, statedb := GetInterpreter(debug, false, root)
statedb.Ram = lram statedb.Ram = lram
callback = lcallback callback = lcallback
......
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