From 673e6903d8ce84b1fed3c8ea1c541eb7734d2547 Mon Sep 17 00:00:00 2001 From: summerpro <974741468@qq.com> Date: Thu, 21 Jan 2021 17:40:19 +0800 Subject: [PATCH 1/3] Use value copy instead of pointer copy in stateObject.deepCopy --- x/evm/types/state_object.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/x/evm/types/state_object.go b/x/evm/types/state_object.go index a2dbce62c..bc9842f4e 100644 --- a/x/evm/types/state_object.go +++ b/x/evm/types/state_object.go @@ -400,7 +400,16 @@ func (so *stateObject) GetCommittedState(_ ethstate.Database, key ethcmn.Hash) e func (so *stateObject) ReturnGas(gas *big.Int) {} func (so *stateObject) deepCopy(db *CommitStateDB) *stateObject { - newStateObj := newStateObject(db, so.account) + newAccount := ethermint.ProtoAccount().(*ethermint.EthAccount) + jsonAccount, err := so.account.MarshalJSON() + if err != nil { + return nil + } + err = newAccount.UnmarshalJSON(jsonAccount) + if err != nil { + return nil + } + newStateObj := newStateObject(db, newAccount) newStateObj.code = so.code newStateObj.dirtyStorage = so.dirtyStorage.Copy() From 70506680551afdc604b50e2d833b572650bf46d0 Mon Sep 17 00:00:00 2001 From: summerpro <974741468@qq.com> Date: Mon, 25 Jan 2021 14:36:19 +0800 Subject: [PATCH 2/3] add change log --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 263afeda2..f44783b4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (api) [\#687](https://github.com/cosmos/ethermint/issues/687) Returns error for a transaction with an incorrect nonce. * (evm) [\#674](https://github.com/cosmos/ethermint/issues/674) Reset all cache after account data has been committed in `EndBlock` to make sure every node state consistent. * (evm) [\#672](https://github.com/cosmos/ethermint/issues/672) Fix panic of `wrong Block.Header.AppHash` when restart a node with snapshot. +* (evm) [\#740](https://github.com/cosmos/ethermint/issues/740) Use value copy instead of pointer copy in stateObject.deepCopy. ## [v0.4.0] - 2020-12-15 From 9347eec6165a430179876a21cf0fa41ba59c0748 Mon Sep 17 00:00:00 2001 From: summerpro <974741468@qq.com> Date: Sun, 7 Feb 2021 11:41:42 +0800 Subject: [PATCH 3/3] panic when MarshalJSON failed --- x/evm/types/state_object.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/evm/types/state_object.go b/x/evm/types/state_object.go index bc9842f4e..5afa66c20 100644 --- a/x/evm/types/state_object.go +++ b/x/evm/types/state_object.go @@ -403,11 +403,11 @@ func (so *stateObject) deepCopy(db *CommitStateDB) *stateObject { newAccount := ethermint.ProtoAccount().(*ethermint.EthAccount) jsonAccount, err := so.account.MarshalJSON() if err != nil { - return nil + panic(err) } err = newAccount.UnmarshalJSON(jsonAccount) if err != nil { - return nil + panic(err) } newStateObj := newStateObject(db, newAccount)