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

Commit

Permalink
move some validation to ValidateBasic
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Jul 18, 2022
1 parent 922a609 commit c8deef5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
19 changes: 9 additions & 10 deletions app/ante/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ func (esvd EthSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, s
err.Error(),
)
}

// set up the sender to the transaction field if not already
msgEthTx.From = sender.Hex()
}

Expand Down Expand Up @@ -421,23 +423,18 @@ func (vbd EthValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu
baseFee := vbd.evmKeeper.GetBaseFee(ctx, ethCfg)

for _, msg := range protoTx.GetMsgs() {
if err := msg.ValidateBasic(); err != nil {
return ctx, sdkerrors.Wrap(err, "msg basic validation failed")
}

msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx)
if !ok {
return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil))
}

// Validate Size_ field, should be kept empty
if msgEthTx.Size_ != 0 {
return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "dirty tx size field %f, expected: 0", msgEthTx.Size_)
}
// Validate Hash field
expHash := msgEthTx.AsTransaction().Hash().Hex()
if msgEthTx.Hash != expHash {
return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid tx hash %s, expected: %s", msgEthTx.Hash, expHash)
}
// Validate `From` field
if msgEthTx.From != "" {
return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid From %s, expect empty string", msgEthTx.From)
return ctx, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid From %s, expect empty string", msgEthTx.From)
}

txGasLimit += msgEthTx.GetGas()
Expand Down Expand Up @@ -482,6 +479,8 @@ func (vbd EthValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu
if len(sigs) > 0 {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "for eth tx Signatures should be empty")
}
} else {
return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid tx type %T, didn't implement interface protoTxProvider", tx)
}

return next(ctx, tx, simulate)
Expand Down
11 changes: 11 additions & 0 deletions x/evm/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,17 @@ func (msg MsgEthereumTx) ValidateBasic() error {
}
}

// Validate Size_ field, should be kept empty
if msg.Size_ != 0 {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "tx size is deprecated")
}

// Validate Hash field
txHash := msg.AsTransaction().Hash().Hex()
if msg.Hash != txHash {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid tx hash %s, expected: %s", msg.Hash, txHash)
}

txData, err := UnpackTxData(msg.Data)
if err != nil {
return sdkerrors.Wrap(err, "failed to unpack tx data")
Expand Down

0 comments on commit c8deef5

Please sign in to comment.