Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

fix bad-data-bug with multi msgs in module evm #694

Closed
wants to merge 11 commits into from
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,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

Expand Down
24 changes: 12 additions & 12 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -49,18 +60,7 @@ func NewAnteHandler(ak auth.AccountKeeper, evmKeeper EVMKeeper, sk types.SupplyK
authante.NewSigGasConsumeDecorator(ak, sigGasConsumer),
authante.NewSigVerificationDecorator(ak),
authante.NewIncrementSequenceDecorator(ak), // innermost AnteDecorator
)

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.
NewValidateMsgHandlerDecorator(),
)
default:
return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid transaction type: %T", tx)
Expand Down
42 changes: 42 additions & 0 deletions app/ante/validate_msg.go
Original file line number Diff line number Diff line change
@@ -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.MsgEthermint:
return ctx, wrongMsgErr
default:
continue
}
}
}

return next(ctx, tx, simulate)
}