Merge pull request from GHSA-mx3r-7hpq-fr4g

* reject invalid `MsgEthereumTx` wrapping tx

Update CHANGELOG.md

* added a unit test

* reject invalid `MsgEthereumTx` wrapping tx in a non-breaking way

Update CHANGELOG.md

* delete code and state on suicide

* fix suicide tests

* update changelog

* update changelog

* delete code hash on suicide

* simplifies delete code

* Apply suggestions from code review

* Update app/ante/ante.go

Co-authored-by: Tomas Tauber <2410580+tomtau@users.noreply.github.com>
Co-authored-by: Freddy Caceres <freddy.caceres@crypto.com>
Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
Prajjwol Gautam
2021-12-23 08:07:23 -08:00
committed by GitHub
co-authored by Tomas Tauber Freddy Caceres Federico Kunze Küllmer
parent bd2c7f2072
commit 0777d0b670
7 changed files with 64 additions and 25 deletions
+2 -9
View File
@@ -1,7 +1,6 @@
package keeper
import (
"bytes"
"math/big"
"github.com/cosmos/cosmos-sdk/codec"
@@ -322,15 +321,9 @@ func (k Keeper) DeleteAccountStorage(addr common.Address) {
}
// DeleteCode removes the contract code byte array from the store associated with
// the given address.
// the given address and empties CodeHash on account.
func (k Keeper) DeleteCode(addr common.Address) {
hash := k.GetCodeHash(addr)
if bytes.Equal(hash.Bytes(), common.BytesToHash(types.EmptyCodeHash).Bytes()) {
return
}
store := prefix.NewStore(k.Ctx().KVStore(k.storeKey), types.KeyPrefixCode)
store.Delete(hash.Bytes())
k.SetCode(addr, nil)
}
// ClearBalance subtracts the EVM all the balance denomination from the address
+3 -1
View File
@@ -543,9 +543,11 @@ func (k *Keeper) Suicide(addr common.Address) bool {
return false
}
// TODO: (@fedekunze) do we also need to delete the storage state and the code?
k.setSuicided(ctx, addr)
// delete account code and state
k.ResetAccount(addr)
k.Logger(ctx).Debug(
"account suicided",
"ethereum-address", addr.Hex(),
+25 -12
View File
@@ -403,20 +403,33 @@ func (suite *KeeperTestSuite) TestCommittedState() {
}
func (suite *KeeperTestSuite) TestSuicide() {
testCases := []struct {
name string
suicided bool
}{
{"success, first time suicided", true},
{"success, already suicided", true},
code := []byte("code")
// Add code to account
suite.app.EvmKeeper.SetCode(suite.address, code)
suite.Require().Equal(code, suite.app.EvmKeeper.GetCode(suite.address))
// Add state to account
for i := 0; i < 5; i++ {
suite.app.EvmKeeper.SetState(suite.address, common.BytesToHash([]byte(fmt.Sprintf("key%d", i))), common.BytesToHash([]byte(fmt.Sprintf("value%d", i))))
}
for _, tc := range testCases {
suite.Run(tc.name, func() {
suite.Require().Equal(tc.suicided, suite.app.EvmKeeper.Suicide(suite.address))
suite.Require().Equal(tc.suicided, suite.app.EvmKeeper.HasSuicided(suite.address))
})
}
// Call Suicide
suite.Require().Equal(true, suite.app.EvmKeeper.Suicide(suite.address))
// Check suicided is marked
suite.Require().Equal(true, suite.app.EvmKeeper.HasSuicided(suite.address))
// Check code is deleted
suite.Require().Nil(suite.app.EvmKeeper.GetCode(suite.address))
// Check state is deleted
var storage types.Storage
err := suite.app.EvmKeeper.ForEachStorage(suite.address, func(key, value common.Hash) bool {
storage = append(storage, types.NewState(key, value))
return true
})
suite.Require().NoError(err)
suite.Require().Equal(0, len(storage))
// Check CodeHash is emptied
suite.Require().Equal(common.BytesToHash(types.EmptyCodeHash).Bytes(), suite.app.EvmKeeper.GetCodeHash(suite.address).Bytes())
}
func (suite *KeeperTestSuite) TestExist() {