From e47d1a4dc8e1646fab2a2d680c90e2565d185643 Mon Sep 17 00:00:00 2001 From: Aleksandr Bezobchuk Date: Wed, 24 Oct 2018 08:21:14 -0400 Subject: [PATCH] Fix invalid code hash algo --- state/state_object.go | 7 +++---- state/statedb.go | 6 ++---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/state/state_object.go b/state/state_object.go index 45d6108a4..a9ae9cf45 100644 --- a/state/state_object.go +++ b/state/state_object.go @@ -8,17 +8,16 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" auth "github.com/cosmos/cosmos-sdk/x/auth" - tmcrypto "github.com/tendermint/tendermint/crypto" - "github.com/cosmos/ethermint/types" ethcmn "github.com/ethereum/go-ethereum/common" ethstate "github.com/ethereum/go-ethereum/core/state" + ethcrypto "github.com/ethereum/go-ethereum/crypto" ) var ( _ ethstate.StateObject = (*stateObject)(nil) - emptyCodeHash = tmcrypto.Sha256(nil) + emptyCodeHash = ethcrypto.Keccak256(nil) ) type ( @@ -363,5 +362,5 @@ func (so stateObject) GetStorageByAddressKey(key []byte) ethcmn.Hash { copy(compositeKey, prefix) copy(compositeKey[len(prefix):], key) - return ethcmn.BytesToHash(tmcrypto.Sha256(compositeKey)) + return ethcrypto.Keccak256Hash(compositeKey) } diff --git a/state/statedb.go b/state/statedb.go index abd318fdc..cfbe50d93 100644 --- a/state/statedb.go +++ b/state/statedb.go @@ -9,11 +9,10 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" - tmcrypto "github.com/tendermint/tendermint/crypto" - ethcmn "github.com/ethereum/go-ethereum/common" ethstate "github.com/ethereum/go-ethereum/core/state" ethtypes "github.com/ethereum/go-ethereum/core/types" + ethcrypto "github.com/ethereum/go-ethereum/crypto" ) var ( @@ -140,8 +139,7 @@ func (csdb *CommitStateDB) SetState(addr ethcmn.Address, key, value ethcmn.Hash) func (csdb *CommitStateDB) SetCode(addr ethcmn.Address, code []byte) { so := csdb.GetOrNewStateObject(addr) if so != nil { - key := ethcmn.BytesToHash(tmcrypto.Sha256(code)) - so.SetCode(key, code) + so.SetCode(ethcrypto.Keccak256Hash(code), code) } }