Commit e0160775 authored by George Hotz's avatar George Hotz

fix chain oracle

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