Merge pull request from GHSA-f92v-grc2-w2fg (#1234)
This commit is contained in:
parent
b1cd16e5bf
commit
737c1de694
@ -1,7 +1,6 @@
|
|||||||
package keeper
|
package keeper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
@ -188,7 +187,7 @@ func (k *Keeper) DeleteAccount(ctx sdk.Context, addr common.Address) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: only Ethereum accounts (contracts) can be selfdestructed
|
// NOTE: only Ethereum accounts (contracts) can be selfdestructed
|
||||||
ethAcct, ok := acct.(ethermint.EthAccountI)
|
_, ok := acct.(ethermint.EthAccountI)
|
||||||
if !ok {
|
if !ok {
|
||||||
return sdkerrors.Wrapf(types.ErrInvalidAccount, "type %T, address %s", acct, addr)
|
return sdkerrors.Wrapf(types.ErrInvalidAccount, "type %T, address %s", acct, addr)
|
||||||
}
|
}
|
||||||
@ -198,12 +197,6 @@ func (k *Keeper) DeleteAccount(ctx sdk.Context, addr common.Address) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove code
|
|
||||||
codeHashBz := ethAcct.GetCodeHash().Bytes()
|
|
||||||
if !bytes.Equal(codeHashBz, types.EmptyCodeHash) {
|
|
||||||
k.SetCode(ctx, codeHashBz, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// clear storage
|
// clear storage
|
||||||
k.ForEachStorage(ctx, addr, func(key, _ common.Hash) bool {
|
k.ForEachStorage(ctx, addr, func(key, _ common.Hash) bool {
|
||||||
k.SetState(ctx, addr, key, nil)
|
k.SetState(ctx, addr, key, nil)
|
||||||
|
@ -15,6 +15,7 @@ import (
|
|||||||
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/core/vm"
|
"github.com/ethereum/go-ethereum/core/vm"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
|
"github.com/evmos/ethermint/crypto/ethsecp256k1"
|
||||||
"github.com/evmos/ethermint/tests"
|
"github.com/evmos/ethermint/tests"
|
||||||
"github.com/evmos/ethermint/x/evm/statedb"
|
"github.com/evmos/ethermint/x/evm/statedb"
|
||||||
"github.com/evmos/ethermint/x/evm/types"
|
"github.com/evmos/ethermint/x/evm/types"
|
||||||
@ -420,12 +421,26 @@ func (suite *KeeperTestSuite) TestSuicide() {
|
|||||||
suite.Require().NoError(db.Commit())
|
suite.Require().NoError(db.Commit())
|
||||||
db = suite.StateDB()
|
db = suite.StateDB()
|
||||||
|
|
||||||
|
// Generate 2nd address
|
||||||
|
privkey, _ := ethsecp256k1.GenerateKey()
|
||||||
|
key, err := privkey.ToECDSA()
|
||||||
|
suite.Require().NoError(err)
|
||||||
|
addr2 := crypto.PubkeyToAddress(key.PublicKey)
|
||||||
|
|
||||||
|
// Add code and state to account 2
|
||||||
|
db.SetCode(addr2, code)
|
||||||
|
suite.Require().Equal(code, db.GetCode(addr2))
|
||||||
|
for i := 0; i < 5; i++ {
|
||||||
|
db.SetState(addr2, common.BytesToHash([]byte(fmt.Sprintf("key%d", i))), common.BytesToHash([]byte(fmt.Sprintf("value%d", i))))
|
||||||
|
}
|
||||||
|
|
||||||
// Call Suicide
|
// Call Suicide
|
||||||
suite.Require().Equal(true, db.Suicide(suite.address))
|
suite.Require().Equal(true, db.Suicide(suite.address))
|
||||||
|
|
||||||
// Check suicided is marked
|
// Check suicided is marked
|
||||||
suite.Require().Equal(true, db.HasSuicided(suite.address))
|
suite.Require().Equal(true, db.HasSuicided(suite.address))
|
||||||
|
|
||||||
|
// Commit state
|
||||||
suite.Require().NoError(db.Commit())
|
suite.Require().NoError(db.Commit())
|
||||||
db = suite.StateDB()
|
db = suite.StateDB()
|
||||||
|
|
||||||
@ -441,6 +456,10 @@ func (suite *KeeperTestSuite) TestSuicide() {
|
|||||||
|
|
||||||
// Check account is deleted
|
// Check account is deleted
|
||||||
suite.Require().Equal(common.Hash{}, db.GetCodeHash(suite.address))
|
suite.Require().Equal(common.Hash{}, db.GetCodeHash(suite.address))
|
||||||
|
|
||||||
|
// Check code is still present in addr2 and suicided is false
|
||||||
|
suite.Require().NotNil(db.GetCode(addr2))
|
||||||
|
suite.Require().Equal(false, db.HasSuicided(addr2))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *KeeperTestSuite) TestExist() {
|
func (suite *KeeperTestSuite) TestExist() {
|
||||||
|
Loading…
Reference in New Issue
Block a user