From b69ef908ec419b882661f485cc213e7bc190b320 Mon Sep 17 00:00:00 2001 From: summerpro <974741468@qq.com> Date: Fri, 8 Jan 2021 23:42:11 +0800 Subject: [PATCH 1/5] fix bad-data-bug with multi msgs in module evm --- app/ante/ante.go | 1 + app/ante/validate_msg.go | 42 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 app/ante/validate_msg.go diff --git a/app/ante/ante.go b/app/ante/ante.go index 6ec990664..0baa39590 100644 --- a/app/ante/ante.go +++ b/app/ante/ante.go @@ -49,6 +49,7 @@ func NewAnteHandler(ak auth.AccountKeeper, evmKeeper EVMKeeper, sk types.SupplyK authante.NewSigGasConsumeDecorator(ak, sigGasConsumer), authante.NewSigVerificationDecorator(ak), authante.NewIncrementSequenceDecorator(ak), // innermost AnteDecorator + NewValidateMsgHandlerDecorator(), ) case evmtypes.MsgEthereumTx: diff --git a/app/ante/validate_msg.go b/app/ante/validate_msg.go new file mode 100644 index 000000000..6c926b373 --- /dev/null +++ b/app/ante/validate_msg.go @@ -0,0 +1,42 @@ +package ante + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + evmtypes "github.com/cosmos/ethermint/x/evm/types" +) + +type ValidateMsgHandler func(ctx sdk.Context, msgs []sdk.Msg) error + +type ValidateMsgHandlerDecorator struct { +} + +func NewValidateMsgHandlerDecorator() ValidateMsgHandlerDecorator { + return ValidateMsgHandlerDecorator{} +} + +func (vmhd ValidateMsgHandlerDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { + // *ABORT* the tx in case of failing to validate it in checkTx mode + if ctx.IsCheckTx() { + wrongMsgErr := sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, + "It is not allowed that a transaction with more than one message and contains evm message") + msgs := tx.GetMsgs() + msgNum := len(msgs) + if msgNum == 0 { + return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "The msg array from tx cannot be empty") + } else if msgNum == 1 { + return next(ctx, tx, simulate) + } + + for _, msg := range msgs { + switch msg.(type) { + case evmtypes.MsgEthereumTx: + return ctx, wrongMsgErr + case evmtypes.MsgEthermint: + return ctx, wrongMsgErr + } + } + } + + return next(ctx, tx, simulate) +} From 0cd5a4d35d94c0296c9b3ce2b0f2bd69d8bad532 Mon Sep 17 00:00:00 2001 From: summerpro <974741468@qq.com> Date: Fri, 8 Jan 2021 23:52:34 +0800 Subject: [PATCH 2/5] format code --- app/ante/validate_msg.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/ante/validate_msg.go b/app/ante/validate_msg.go index 6c926b373..a8fffcf16 100644 --- a/app/ante/validate_msg.go +++ b/app/ante/validate_msg.go @@ -30,10 +30,10 @@ func (vmhd ValidateMsgHandlerDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, s for _, msg := range msgs { switch msg.(type) { - case evmtypes.MsgEthereumTx: - return ctx, wrongMsgErr - case evmtypes.MsgEthermint: - return ctx, wrongMsgErr + case evmtypes.MsgEthereumTx: + return ctx, wrongMsgErr + case evmtypes.MsgEthermint: + return ctx, wrongMsgErr } } } From 061af84bfd3781dc854bd90e30a20af6f34c7864 Mon Sep 17 00:00:00 2001 From: summerpro <974741468@qq.com> Date: Sat, 9 Jan 2021 11:21:19 +0800 Subject: [PATCH 3/5] add change log --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 263afeda2..585e38f56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,9 @@ 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) [\#667](https://github.com/cosmos/ethermint/issues/667) There may be bad data points in CommitStateDB when exec evm transaction with multi msgs. +* (evm) [\#668](https://github.com/cosmos/ethermint/issues/668) Bad data may be generated due to insufficient gas during the execution of evm transactions. +* (evm) [\#669](https://github.com/cosmos/ethermint/issues/669) Bad data may be generated due to error returned during the execution of evm transaction. ## [v0.4.0] - 2020-12-15 From 7b561ec5ea724ee0244ad4e5c9b0cb57eb10a8a0 Mon Sep 17 00:00:00 2001 From: summerpro <974741468@qq.com> Date: Thu, 14 Jan 2021 18:08:50 +0800 Subject: [PATCH 4/5] optimize code --- app/ante/ante.go | 23 +++++++++++------------ app/ante/validate_msg.go | 2 -- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/app/ante/ante.go b/app/ante/ante.go index 0baa39590..1bd7511b2 100644 --- a/app/ante/ante.go +++ b/app/ante/ante.go @@ -35,6 +35,17 @@ func NewAnteHandler(ak auth.AccountKeeper, evmKeeper EVMKeeper, sk types.SupplyK ) (newCtx sdk.Context, err error) { var anteHandler sdk.AnteHandler switch tx.(type) { + case evmtypes.MsgEthereumTx: + anteHandler = sdk.ChainAnteDecorators( + NewEthSetupContextDecorator(), // outermost AnteDecorator. EthSetUpContext must be called first + NewEthMempoolFeeDecorator(evmKeeper), + authante.NewValidateBasicDecorator(), + NewEthSigVerificationDecorator(), + NewAccountVerificationDecorator(ak, evmKeeper), + NewNonceVerificationDecorator(ak), + NewEthGasConsumeDecorator(ak, sk, evmKeeper), + NewIncrementSenderSequenceDecorator(ak), // innermost AnteDecorator. + ) case auth.StdTx: anteHandler = sdk.ChainAnteDecorators( authante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first @@ -51,18 +62,6 @@ func NewAnteHandler(ak auth.AccountKeeper, evmKeeper EVMKeeper, sk types.SupplyK authante.NewIncrementSequenceDecorator(ak), // innermost AnteDecorator NewValidateMsgHandlerDecorator(), ) - - case evmtypes.MsgEthereumTx: - anteHandler = sdk.ChainAnteDecorators( - NewEthSetupContextDecorator(), // outermost AnteDecorator. EthSetUpContext must be called first - NewEthMempoolFeeDecorator(evmKeeper), - authante.NewValidateBasicDecorator(), - NewEthSigVerificationDecorator(), - NewAccountVerificationDecorator(ak, evmKeeper), - NewNonceVerificationDecorator(ak), - NewEthGasConsumeDecorator(ak, sk, evmKeeper), - NewIncrementSenderSequenceDecorator(ak), // innermost AnteDecorator. - ) default: return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid transaction type: %T", tx) } diff --git a/app/ante/validate_msg.go b/app/ante/validate_msg.go index a8fffcf16..dba1c2b13 100644 --- a/app/ante/validate_msg.go +++ b/app/ante/validate_msg.go @@ -30,8 +30,6 @@ func (vmhd ValidateMsgHandlerDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, s for _, msg := range msgs { switch msg.(type) { - case evmtypes.MsgEthereumTx: - return ctx, wrongMsgErr case evmtypes.MsgEthermint: return ctx, wrongMsgErr } From 344a28575726d739d0103c99e4f99ad563f52e2e Mon Sep 17 00:00:00 2001 From: summerpro <974741468@qq.com> Date: Thu, 14 Jan 2021 18:21:51 +0800 Subject: [PATCH 5/5] optimize code --- app/ante/validate_msg.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/ante/validate_msg.go b/app/ante/validate_msg.go index dba1c2b13..f398685ef 100644 --- a/app/ante/validate_msg.go +++ b/app/ante/validate_msg.go @@ -32,6 +32,8 @@ func (vmhd ValidateMsgHandlerDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, s switch msg.(type) { case evmtypes.MsgEthermint: return ctx, wrongMsgErr + default: + continue } } }