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

Commit 1447418

Browse files
facs95fedekunze
andauthored
Merge pull request from GHSA-f92v-grc2-w2fg
* remove delete code in DeleteAccount * update unit test * refactor test Co-authored-by: Federico Kunze Küllmer <[email protected]>
1 parent bead29c commit 1447418

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

x/evm/keeper/statedb.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package keeper
22

33
import (
4-
"bytes"
54
"fmt"
65
"math/big"
76

@@ -186,7 +185,7 @@ func (k *Keeper) DeleteAccount(ctx sdk.Context, addr common.Address) error {
186185
}
187186

188187
// NOTE: only Ethereum accounts (contracts) can be selfdestructed
189-
ethAcct, ok := acct.(ethermint.EthAccountI)
188+
_, ok := acct.(ethermint.EthAccountI)
190189
if !ok {
191190
return sdkerrors.Wrapf(types.ErrInvalidAccount, "type %T, address %s", acct, addr)
192191
}
@@ -196,12 +195,6 @@ func (k *Keeper) DeleteAccount(ctx sdk.Context, addr common.Address) error {
196195
return err
197196
}
198197

199-
// remove code
200-
codeHashBz := ethAcct.GetCodeHash().Bytes()
201-
if !bytes.Equal(codeHashBz, types.EmptyCodeHash) {
202-
k.SetCode(ctx, codeHashBz, nil)
203-
}
204-
205198
// clear storage
206199
k.ForEachStorage(ctx, addr, func(key, _ common.Hash) bool {
207200
k.SetState(ctx, addr, key, nil)

x/evm/keeper/statedb_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
ethtypes "github.com/ethereum/go-ethereum/core/types"
1616
"github.com/ethereum/go-ethereum/core/vm"
1717
"github.com/ethereum/go-ethereum/crypto"
18+
"github.com/evmos/ethermint/crypto/ethsecp256k1"
1819
"github.com/evmos/ethermint/tests"
1920
"github.com/evmos/ethermint/x/evm/statedb"
2021
"github.com/evmos/ethermint/x/evm/types"
@@ -420,12 +421,26 @@ func (suite *KeeperTestSuite) TestSuicide() {
420421
suite.Require().NoError(db.Commit())
421422
db = suite.StateDB()
422423

424+
// Generate 2nd address
425+
privkey, _ := ethsecp256k1.GenerateKey()
426+
key, err := privkey.ToECDSA()
427+
suite.Require().NoError(err)
428+
addr2 := crypto.PubkeyToAddress(key.PublicKey)
429+
430+
// Add code and state to account 2
431+
db.SetCode(addr2, code)
432+
suite.Require().Equal(code, db.GetCode(addr2))
433+
for i := 0; i < 5; i++ {
434+
db.SetState(addr2, common.BytesToHash([]byte(fmt.Sprintf("key%d", i))), common.BytesToHash([]byte(fmt.Sprintf("value%d", i))))
435+
}
436+
423437
// Call Suicide
424438
suite.Require().Equal(true, db.Suicide(suite.address))
425439

426440
// Check suicided is marked
427441
suite.Require().Equal(true, db.HasSuicided(suite.address))
428442

443+
// Commit state
429444
suite.Require().NoError(db.Commit())
430445
db = suite.StateDB()
431446

@@ -441,6 +456,10 @@ func (suite *KeeperTestSuite) TestSuicide() {
441456

442457
// Check account is deleted
443458
suite.Require().Equal(common.Hash{}, db.GetCodeHash(suite.address))
459+
460+
// Check code is still present in addr2 and suicided is false
461+
suite.Require().NotNil(db.GetCode(addr2))
462+
suite.Require().Equal(false, db.HasSuicided(addr2))
444463
}
445464

446465
func (suite *KeeperTestSuite) TestExist() {

0 commit comments

Comments
 (0)