Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
Problem: import/export roundtrip test fail contract storage
Browse files Browse the repository at this point in the history
Closes: #589

- don't hash the key again in InitGenesis
  • Loading branch information
yihuang committed Sep 24, 2021
1 parent 692fd95 commit 9589b2f
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 19 deletions.
1 change: 0 additions & 1 deletion x/evm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ func (k Keeper) GetAccountStorage(ctx sdk.Context, address common.Address) (type

func (k Keeper) DeleteState(addr common.Address, key common.Hash) {
store := prefix.NewStore(k.Ctx().KVStore(k.storeKey), types.AddressStoragePrefix(addr))
key = types.KeyAddressStorage(addr, key)
store.Delete(key.Bytes())
}

Expand Down
4 changes: 1 addition & 3 deletions x/evm/keeper/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,9 @@ func (k *Keeper) GetRefund() uint64 {
// State
// ----------------------------------------------------------------------------

func doGetState(ctx sdk.Context, storeKey sdk.StoreKey, addr common.Address, hash common.Hash) common.Hash {
func doGetState(ctx sdk.Context, storeKey sdk.StoreKey, addr common.Address, key common.Hash) common.Hash {
store := prefix.NewStore(ctx.KVStore(storeKey), types.AddressStoragePrefix(addr))

key := types.KeyAddressStorage(addr, hash)
value := store.Get(key.Bytes())
if len(value) == 0 {
return common.Hash{}
Expand Down Expand Up @@ -496,7 +495,6 @@ func (k *Keeper) SetState(addr common.Address, key, value common.Hash) {

ctx := k.Ctx()
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.AddressStoragePrefix(addr))
key = types.KeyAddressStorage(addr, key)

action := "updated"
if ethermint.IsEmptyHash(value.Hex()) {
Expand Down
15 changes: 0 additions & 15 deletions x/evm/types/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package types

import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
)

const (
Expand Down Expand Up @@ -69,17 +68,3 @@ func AddressStoragePrefix(address common.Address) []byte {
func StateKey(address common.Address, key []byte) []byte {
return append(AddressStoragePrefix(address), key...)
}

// KeyAddressStorage returns the key hash to access a given account state. The composite key
// (address + hash) is hashed using Keccak256.
func KeyAddressStorage(address common.Address, hash common.Hash) common.Hash {
prefix := address.Bytes()
key := hash.Bytes()

compositeKey := make([]byte, len(prefix)+len(key))

copy(compositeKey, prefix)
copy(compositeKey[len(prefix):], key)

return crypto.Keccak256Hash(compositeKey)
}

0 comments on commit 9589b2f

Please sign in to comment.