Commit 04ff70f6 authored by George Hotz's avatar George Hotz

i see the difference, this is a later problem

parent 027bcb41
......@@ -27,6 +27,26 @@ func deploy(interpreter *vm.EVMInterpreter, statedb *StateDB) {
statedb.Bytecodes[common.HexToAddress("0x1337")] = ret
}
func getTrieNode(str common.Hash, interpreter *vm.EVMInterpreter, statedb *StateDB) []byte {
from := common.Address{}
to := common.HexToAddress("0xBd770416a3345F91E4B34576cb804a576fa48EB1")
gas := uint64(100000000)
input := crypto.Keccak256Hash([]byte("trie(bytes32)")).Bytes()[:4]
input = append(input, str.Bytes()...)
bytecode := statedb.Bytecodes[to]
//fmt.Println("bytecode", len(bytecode))
contract := vm.NewContract(vm.AccountRef(from), vm.AccountRef(to), common.Big0, gas)
contract.SetCallCode(&to, crypto.Keccak256Hash(bytecode), bytecode)
ret, err := interpreter.Run(contract, input, false)
check(err)
fmt.Println("getTrieNode", str, ret)
return ret[64:]
}
func addTrieNode(str []byte, interpreter *vm.EVMInterpreter, statedb *StateDB) {
from := common.Address{}
to := common.HexToAddress("0xBd770416a3345F91E4B34576cb804a576fa48EB1")
......@@ -48,16 +68,6 @@ func addTrieNode(str []byte, interpreter *vm.EVMInterpreter, statedb *StateDB) {
check(err)
}
func RunTest() {
ram := make(map[uint32](uint32))
LoadMappedFile("test/bin/add.bin", ram, 0)
ZeroRegisters(ram)
ram[0xC000007C] = 0x5EAD0000
RunWithRam(ram, 1, 0, nil)
}
func RunFull() {
interpreter, statedb := GetInterpreter(0, true)
deploy(interpreter, statedb)
......@@ -69,7 +79,7 @@ func RunFull() {
ZeroRegisters(ram)
ram[0xC000007C] = 0x5EAD0000
root := RamToTrie(ram)
ParseNode(root, 0)
//ParseNode(root, 0)
ioutil.WriteFile("/tmp/eth/trie.json", TrieToJson(root), 0644)
......@@ -80,7 +90,7 @@ func RunFull() {
fmt.Println("trie is ready, let's run")
fmt.Println("state root", root, "nodes", len(Preimages))
for step := 0; step < 40; step++ {
for step := 0; step < 12; step++ {
// it's run o clock
from := common.Address{}
to := common.HexToAddress("0x1337")
......@@ -105,4 +115,8 @@ func RunFull() {
fmt.Println("new state root", step, root, "gas used", (gas - contract.Gas))
}
}
ParseNode(root, 0, func(t common.Hash) []byte {
return getTrieNode(t, interpreter, statedb)
})
}
......@@ -3,6 +3,8 @@ package main
import (
"fmt"
"testing"
"github.com/ethereum/go-ethereum/common"
)
func TestFull(t *testing.T) {
......@@ -15,9 +17,13 @@ func TestFullEvm(t *testing.T) {
ZeroRegisters(ram)
ram[0xC000007C] = 0x5EAD0000
root := RamToTrie(ram)
for step := 0; step < 12; step++ {
RunWithRam(ram, 1, 0, nil)
root := RamToTrie(ram)
root = RamToTrie(ram)
fmt.Println(step, root)
}
ParseNode(root, 0, func(t common.Hash) []byte {
return Preimages[t]
})
}
......@@ -56,12 +56,12 @@ func (kw PreimageKeyValueWriter) Delete(key []byte) error {
// full nodes / BRANCH_NODE have 17 values, each a hash
// LEAF or EXTENSION nodes have 2 values, a path and value
func ParseNode(node common.Hash, depth int) {
func ParseNode(node common.Hash, depth int, callback func(common.Hash) []byte) {
if depth > 3 {
return
}
sprefix := strings.Repeat(" ", depth)
buf := Preimages[node]
buf := callback(node)
elems, _, err := rlp.SplitList(buf)
check(err)
c, _ := rlp.CountValues(elems)
......@@ -75,7 +75,7 @@ func ParseNode(node common.Hash, depth int) {
if len(val) == 32 {
hh := common.BytesToHash(val)
fmt.Println(sprefix, "node found with len", len(Preimages[hh]))
ParseNode(hh, depth+1)
ParseNode(hh, depth+1, callback)
}
}
}
......
......@@ -13,7 +13,7 @@ func TestTrie(t *testing.T) {
LoadMappedFile("../mipigo/test/test.bin", ram, 0)
ZeroRegisters(ram)
root := RamToTrie(ram)
ParseNode(root, 0)
//ParseNode(root, 0)
dat := SerializeTrie(root)
fmt.Println("serialized length is", len(dat))
......
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