diff --git a/core/state/dump.go b/core/state/dump.go index 712f8da1f2ac362165b37143343fe5a84fa30c12..70ea21691489627d1905cd95e17f6ca078034fb1 100644 --- a/core/state/dump.go +++ b/core/state/dump.go @@ -28,17 +28,17 @@ func (self *StateDB) RawDump() World { it := self.trie.Iterator() for it.Next() { - stateObject := NewStateObjectFromBytes(common.BytesToAddress(it.Key), it.Value, self.db) + addr := self.trie.GetKey(it.Key) + stateObject := NewStateObjectFromBytes(common.BytesToAddress(addr), it.Value, self.db) account := Account{Balance: stateObject.balance.String(), Nonce: stateObject.nonce, Root: common.Bytes2Hex(stateObject.Root()), CodeHash: common.Bytes2Hex(stateObject.codeHash)} account.Storage = make(map[string]string) storageIt := stateObject.State.trie.Iterator() for storageIt.Next() { - fmt.Println("value", storageIt.Value) - account.Storage[common.Bytes2Hex(storageIt.Key)] = common.Bytes2Hex(storageIt.Value) + account.Storage[common.Bytes2Hex(self.trie.GetKey(storageIt.Key))] = common.Bytes2Hex(storageIt.Value) } - world.Accounts[common.Bytes2Hex(it.Key)] = account + world.Accounts[common.Bytes2Hex(addr)] = account } return world } diff --git a/trie/secure_trie.go b/trie/secure_trie.go index b9fa376b814d3ad1a5ea33666b41414fcba780b8..f7a1950e5d699e785f59a9bb25ce839e55ee6d5c 100644 --- a/trie/secure_trie.go +++ b/trie/secure_trie.go @@ -2,6 +2,8 @@ package trie import "github.com/ethereum/go-ethereum/crypto" +var keyPrefix = []byte("secure-key-") + type SecureTrie struct { *Trie } @@ -11,7 +13,10 @@ func NewSecure(root []byte, backend Backend) *SecureTrie { } func (self *SecureTrie) Update(key, value []byte) Node { - return self.Trie.Update(crypto.Sha3(key), value) + shaKey := crypto.Sha3(key) + self.Trie.cache.Put(append(keyPrefix, shaKey...), key) + + return self.Trie.Update(shaKey, value) } func (self *SecureTrie) UpdateString(key, value string) Node { return self.Update([]byte(key), []byte(value)) @@ -34,3 +39,7 @@ func (self *SecureTrie) DeleteString(key string) Node { func (self *SecureTrie) Copy() *SecureTrie { return &SecureTrie{self.Trie.Copy()} } + +func (self *SecureTrie) GetKey(shaKey []byte) []byte { + return self.Trie.cache.Get(append(keyPrefix, shaKey...)) +}