fix(evm): skip hash check when the code has been deleted (#1320)
* evm.InitGenesis skip codehash check when the code has been deleted in the evm state * fix lint * just ignore all the codehash check when the evm account code is empty * update changelog * nit * add test * add test Co-authored-by: Daniel Burckhardt <daniel.m.burckhardt@gmail.com> Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
parent
236ca33c53
commit
5879750b30
@ -70,6 +70,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
* (rpc) [#1340](https://github.com/evmos/ethermint/pull/1340) Fix error response when `eth_estimateGas` height provided is not found.
|
||||
* (rpc) [#1354](https://github.com/evmos/ethermint/pull/1354) Fix grpc query failure(`BaseFee` and `EthCall`) on legacy block states.
|
||||
* (cli) [#1362](https://github.com/evmos/ethermint/pull/1362) Fix `index-eth-tx` error when the indexer db is empty.
|
||||
* (state) [#1320](https://github.com/evmos/ethermint/pull/1320) Fix codehash check mismatch when the code has been deleted in the evm state.
|
||||
|
||||
## [v0.19.2] - 2022-08-29
|
||||
|
||||
|
@ -48,11 +48,14 @@ func InitGenesis(
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
code := common.Hex2Bytes(account.Code)
|
||||
codeHash := crypto.Keccak256Hash(code)
|
||||
if !bytes.Equal(ethAcct.GetCodeHash().Bytes(), codeHash.Bytes()) {
|
||||
panic("code don't match codeHash")
|
||||
|
||||
// we ignore the empty Code hash checking, see ethermint PR#1234
|
||||
if len(account.Code) != 0 && !bytes.Equal(ethAcct.GetCodeHash().Bytes(), codeHash.Bytes()) {
|
||||
s := "the evm state code doesn't match with the codehash\n"
|
||||
panic(fmt.Sprintf("%s account: %s , evm state codehash: %v, ethAccount codehash: %v, evm state code: %s\n",
|
||||
s, account.Address, codeHash, ethAcct.GetCodeHash(), account.Code))
|
||||
}
|
||||
|
||||
k.SetCode(ctx, codeHash.Bytes(), code)
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
"github.com/evmos/ethermint/crypto/ethsecp256k1"
|
||||
etherminttypes "github.com/evmos/ethermint/types"
|
||||
"github.com/evmos/ethermint/x/evm"
|
||||
"github.com/evmos/ethermint/x/evm/statedb"
|
||||
"github.com/evmos/ethermint/x/evm/types"
|
||||
@ -96,6 +97,45 @@ func (suite *EvmTestSuite) TestInitGenesis() {
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"ignore empty account code checking",
|
||||
func() {
|
||||
acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, address.Bytes())
|
||||
|
||||
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)
|
||||
},
|
||||
&types.GenesisState{
|
||||
Params: types.DefaultParams(),
|
||||
Accounts: []types.GenesisAccount{
|
||||
{
|
||||
Address: address.String(),
|
||||
Code: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"ignore empty account code checking with non-empty codehash",
|
||||
func() {
|
||||
ethAcc := ðerminttypes.EthAccount{
|
||||
BaseAccount: authtypes.NewBaseAccount(address.Bytes(), nil, 0, 0),
|
||||
CodeHash: common.BytesToHash([]byte{1, 2, 3}).Hex(),
|
||||
}
|
||||
|
||||
suite.app.AccountKeeper.SetAccount(suite.ctx, ethAcc)
|
||||
},
|
||||
&types.GenesisState{
|
||||
Params: types.DefaultParams(),
|
||||
Accounts: []types.GenesisAccount{
|
||||
{
|
||||
Address: address.String(),
|
||||
Code: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
|
Loading…
Reference in New Issue
Block a user