From 7e0a70b06aa639eb4747ce8f97b6a07009356b92 Mon Sep 17 00:00:00 2001 From: MalteHerrmann <42640438+MalteHerrmann@users.noreply.github.com> Date: Wed, 23 Nov 2022 15:59:04 +0100 Subject: [PATCH] Adjust deprecated sdkerrors import (#1493) --- app/ante/ante.go | 11 ++++---- app/ante/eip712.go | 55 +++++++++++++++++++------------------ app/ante/eth.go | 51 +++++++++++++++++----------------- app/ante/fee_checker.go | 7 +++-- app/ante/fee_market.go | 4 +-- app/ante/fees.go | 17 ++++++------ app/ante/handler_options.go | 13 +++++---- app/ante/mempool.go | 9 +++--- app/ante/reject_msgs.go | 7 +++-- app/ante/setup.go | 41 +++++++++++++-------------- app/ante/sigverify.go | 13 +++++---- 11 files changed, 119 insertions(+), 109 deletions(-) diff --git a/app/ante/ante.go b/app/ante/ante.go index 20770690d9..88bb9d0ed8 100644 --- a/app/ante/ante.go +++ b/app/ante/ante.go @@ -6,9 +6,10 @@ import ( tmlog "github.com/tendermint/tendermint/libs/log" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/crypto/types/multisig" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errortypes "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/tx/signing" authante "github.com/cosmos/cosmos-sdk/x/auth/ante" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -51,8 +52,8 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { // cosmos-sdk tx with dynamic fee extension anteHandler = newCosmosAnteHandler(options) default: - return ctx, sdkerrors.Wrapf( - sdkerrors.ErrUnknownExtensionOptions, + return ctx, errorsmod.Wrapf( + errortypes.ErrUnknownExtensionOptions, "rejecting tx with unsupported extension option: %s", typeURL, ) } @@ -66,7 +67,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { case sdk.Tx: anteHandler = newCosmosAnteHandler(options) default: - return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid transaction type: %T", tx) + return ctx, errorsmod.Wrapf(errortypes.ErrUnknownRequest, "invalid transaction type: %T", tx) } return anteHandler(ctx, tx, sim) @@ -75,7 +76,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { func Recover(logger tmlog.Logger, err *error) { if r := recover(); r != nil { - *err = sdkerrors.Wrapf(sdkerrors.ErrPanic, "%v", r) + *err = errorsmod.Wrapf(errortypes.ErrPanic, "%v", r) if e, ok := r.(error); ok { logger.Error( diff --git a/app/ante/eip712.go b/app/ante/eip712.go index f12b96fe4d..b3f3823110 100644 --- a/app/ante/eip712.go +++ b/app/ante/eip712.go @@ -3,11 +3,12 @@ package ante import ( "fmt" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errortypes "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/tx/signing" authante "github.com/cosmos/cosmos-sdk/x/auth/ante" "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" @@ -63,12 +64,12 @@ func (svd Eip712SigVerificationDecorator) AnteHandle(ctx sdk.Context, sigTx, ok := tx.(authsigning.SigVerifiableTx) if !ok { - return ctx, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "tx %T doesn't implement authsigning.SigVerifiableTx", tx) + return ctx, errorsmod.Wrapf(errortypes.ErrInvalidType, "tx %T doesn't implement authsigning.SigVerifiableTx", tx) } authSignTx, ok := tx.(authsigning.Tx) if !ok { - return ctx, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "tx %T doesn't implement the authsigning.Tx interface", tx) + return ctx, errorsmod.Wrapf(errortypes.ErrInvalidType, "tx %T doesn't implement the authsigning.Tx interface", tx) } // stdSigs contains the sequence number, account number, and signatures. @@ -82,12 +83,12 @@ func (svd Eip712SigVerificationDecorator) AnteHandle(ctx sdk.Context, // EIP712 allows just one signature if len(sigs) != 1 { - return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "invalid number of signers (%d); EIP712 signatures allows just one signature", len(sigs)) + return ctx, errorsmod.Wrapf(errortypes.ErrUnauthorized, "invalid number of signers (%d); EIP712 signatures allows just one signature", len(sigs)) } // check that signer length and signature length are the same if len(sigs) != len(signerAddrs) { - return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "invalid number of signer; expected: %d, got %d", len(signerAddrs), len(sigs)) + return ctx, errorsmod.Wrapf(errortypes.ErrUnauthorized, "invalid number of signer; expected: %d, got %d", len(signerAddrs), len(sigs)) } // EIP712 has just one signature, avoid looping here and only read index 0 @@ -102,13 +103,13 @@ func (svd Eip712SigVerificationDecorator) AnteHandle(ctx sdk.Context, // retrieve pubkey pubKey := acc.GetPubKey() if !simulate && pubKey == nil { - return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidPubKey, "pubkey on account is not set") + return ctx, errorsmod.Wrap(errortypes.ErrInvalidPubKey, "pubkey on account is not set") } // Check account sequence number. if sig.Sequence != acc.GetSequence() { - return ctx, sdkerrors.Wrapf( - sdkerrors.ErrWrongSequence, + return ctx, errorsmod.Wrapf( + errortypes.ErrWrongSequence, "account sequence mismatch, expected %d, got %d", acc.GetSequence(), sig.Sequence, ) } @@ -134,7 +135,7 @@ func (svd Eip712SigVerificationDecorator) AnteHandle(ctx sdk.Context, if err := VerifySignature(pubKey, signerData, sig.Data, svd.signModeHandler, authSignTx); err != nil { errMsg := fmt.Errorf("signature verification failed; please verify account number (%d) and chain-id (%s): %w", accNum, chainID, err) - return ctx, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, errMsg.Error()) + return ctx, errorsmod.Wrap(errortypes.ErrUnauthorized, errMsg.Error()) } return next(ctx, tx, simulate) @@ -152,12 +153,12 @@ func VerifySignature( switch data := sigData.(type) { case *signing.SingleSignatureData: if data.SignMode != signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON { - return sdkerrors.Wrapf(sdkerrors.ErrNotSupported, "unexpected SignatureData %T: wrong SignMode", sigData) + return errorsmod.Wrapf(errortypes.ErrNotSupported, "unexpected SignatureData %T: wrong SignMode", sigData) } // Note: this prevents the user from sending thrash data in the signature field if len(data.Signature) != 0 { - return sdkerrors.Wrap(sdkerrors.ErrTooManySignatures, "invalid signature value; EIP712 must have the cosmos transaction signature empty") + return errorsmod.Wrap(errortypes.ErrTooManySignatures, "invalid signature value; EIP712 must have the cosmos transaction signature empty") } // @contract: this code is reached only when Msg has Web3Tx extension (so this custom Ante handler flow), @@ -165,7 +166,7 @@ func VerifySignature( msgs := tx.GetMsgs() if len(msgs) == 0 { - return sdkerrors.Wrap(sdkerrors.ErrNoSignatures, "tx doesn't contain any msgs to verify signature") + return errorsmod.Wrap(errortypes.ErrNoSignatures, "tx doesn't contain any msgs to verify signature") } txBytes := legacytx.StdSignBytes( @@ -182,33 +183,33 @@ func VerifySignature( signerChainID, err := ethermint.ParseChainID(signerData.ChainID) if err != nil { - return sdkerrors.Wrapf(err, "failed to parse chainID: %s", signerData.ChainID) + return errorsmod.Wrapf(err, "failed to parse chainID: %s", signerData.ChainID) } txWithExtensions, ok := tx.(authante.HasExtensionOptionsTx) if !ok { - return sdkerrors.Wrap(sdkerrors.ErrUnknownExtensionOptions, "tx doesnt contain any extensions") + return errorsmod.Wrap(errortypes.ErrUnknownExtensionOptions, "tx doesnt contain any extensions") } opts := txWithExtensions.GetExtensionOptions() if len(opts) != 1 { - return sdkerrors.Wrap(sdkerrors.ErrUnknownExtensionOptions, "tx doesnt contain expected amount of extension options") + return errorsmod.Wrap(errortypes.ErrUnknownExtensionOptions, "tx doesnt contain expected amount of extension options") } extOpt, ok := opts[0].GetCachedValue().(*ethermint.ExtensionOptionsWeb3Tx) if !ok { - return sdkerrors.Wrap(sdkerrors.ErrInvalidChainID, "unknown extension option") + return errorsmod.Wrap(errortypes.ErrInvalidChainID, "unknown extension option") } if extOpt.TypedDataChainID != signerChainID.Uint64() { - return sdkerrors.Wrap(sdkerrors.ErrInvalidChainID, "invalid chainID") + return errorsmod.Wrap(errortypes.ErrInvalidChainID, "invalid chainID") } if len(extOpt.FeePayer) == 0 { - return sdkerrors.Wrap(sdkerrors.ErrUnknownExtensionOptions, "no feePayer on ExtensionOptionsWeb3Tx") + return errorsmod.Wrap(errortypes.ErrUnknownExtensionOptions, "no feePayer on ExtensionOptionsWeb3Tx") } feePayer, err := sdk.AccAddressFromBech32(extOpt.FeePayer) if err != nil { - return sdkerrors.Wrap(err, "failed to parse feePayer from ExtensionOptionsWeb3Tx") + return errorsmod.Wrap(err, "failed to parse feePayer from ExtensionOptionsWeb3Tx") } feeDelegation := &eip712.FeeDelegationOptions{ @@ -217,7 +218,7 @@ func VerifySignature( typedData, err := eip712.WrapTxToTypedData(ethermintCodec, extOpt.TypedDataChainID, msgs[0], txBytes, feeDelegation) if err != nil { - return sdkerrors.Wrap(err, "failed to pack tx data in EIP712 object") + return errorsmod.Wrap(err, "failed to pack tx data in EIP712 object") } sigHash, _, err := apitypes.TypedDataAndHash(typedData) @@ -227,7 +228,7 @@ func VerifySignature( feePayerSig := extOpt.FeePayerSig if len(feePayerSig) != ethcrypto.SignatureLength { - return sdkerrors.Wrap(sdkerrors.ErrorInvalidSigner, "signature length doesn't match typical [R||S||V] signature 65 bytes") + return errorsmod.Wrap(errortypes.ErrorInvalidSigner, "signature length doesn't match typical [R||S||V] signature 65 bytes") } // Remove the recovery offset if needed (ie. Metamask eip712 signature) @@ -237,12 +238,12 @@ func VerifySignature( feePayerPubkey, err := secp256k1.RecoverPubkey(sigHash, feePayerSig) if err != nil { - return sdkerrors.Wrap(err, "failed to recover delegated fee payer from sig") + return errorsmod.Wrap(err, "failed to recover delegated fee payer from sig") } ecPubKey, err := ethcrypto.UnmarshalPubkey(feePayerPubkey) if err != nil { - return sdkerrors.Wrap(err, "failed to unmarshal recovered fee payer pubkey") + return errorsmod.Wrap(err, "failed to unmarshal recovered fee payer pubkey") } pk := ðsecp256k1.PubKey{ @@ -250,23 +251,23 @@ func VerifySignature( } if !pubKey.Equals(pk) { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidPubKey, "feePayer pubkey %s is different from transaction pubkey %s", pubKey, pk) + return errorsmod.Wrapf(errortypes.ErrInvalidPubKey, "feePayer pubkey %s is different from transaction pubkey %s", pubKey, pk) } recoveredFeePayerAcc := sdk.AccAddress(pk.Address().Bytes()) if !recoveredFeePayerAcc.Equals(feePayer) { - return sdkerrors.Wrapf(sdkerrors.ErrorInvalidSigner, "failed to verify delegated fee payer %s signature", recoveredFeePayerAcc) + return errorsmod.Wrapf(errortypes.ErrorInvalidSigner, "failed to verify delegated fee payer %s signature", recoveredFeePayerAcc) } // VerifySignature of ethsecp256k1 accepts 64 byte signature [R||S] // WARNING! Under NO CIRCUMSTANCES try to use pubKey.VerifySignature there if !secp256k1.VerifySignature(pubKey.Bytes(), sigHash, feePayerSig[:len(feePayerSig)-1]) { - return sdkerrors.Wrap(sdkerrors.ErrorInvalidSigner, "unable to verify signer signature of EIP712 typed data") + return errorsmod.Wrap(errortypes.ErrorInvalidSigner, "unable to verify signer signature of EIP712 typed data") } return nil default: - return sdkerrors.Wrapf(sdkerrors.ErrTooManySignatures, "unexpected SignatureData %T", sigData) + return errorsmod.Wrapf(errortypes.ErrTooManySignatures, "unexpected SignatureData %T", sigData) } } diff --git a/app/ante/eth.go b/app/ante/eth.go index 5751c2cad4..684dd8f96b 100644 --- a/app/ante/eth.go +++ b/app/ante/eth.go @@ -4,10 +4,11 @@ import ( "math" "math/big" + errorsmod "cosmossdk.io/errors" sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errortypes "github.com/cosmos/cosmos-sdk/types/errors" ethermint "github.com/evmos/ethermint/types" evmkeeper "github.com/evmos/ethermint/x/evm/keeper" @@ -51,18 +52,18 @@ func (avd EthAccountVerificationDecorator) AnteHandle( for i, msg := range tx.GetMsgs() { msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx) if !ok { - return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil)) + return ctx, errorsmod.Wrapf(errortypes.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil)) } txData, err := evmtypes.UnpackTxData(msgEthTx.Data) if err != nil { - return ctx, sdkerrors.Wrapf(err, "failed to unpack tx data any for tx %d", i) + return ctx, errorsmod.Wrapf(err, "failed to unpack tx data any for tx %d", i) } // sender address should be in the tx cache from the previous AnteHandle call from := msgEthTx.GetFrom() if from.Empty() { - return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "from address cannot be empty") + return ctx, errorsmod.Wrap(errortypes.ErrInvalidAddress, "from address cannot be empty") } // check whether the sender address is EOA @@ -74,12 +75,12 @@ func (avd EthAccountVerificationDecorator) AnteHandle( avd.ak.SetAccount(ctx, acc) acct = statedb.NewEmptyAccount() } else if acct.IsContract() { - return ctx, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, + return ctx, errorsmod.Wrapf(errortypes.ErrInvalidType, "the sender is not EOA: address %s, codeHash <%s>", fromAddr, acct.CodeHash) } if err := evmkeeper.CheckSenderBalance(sdkmath.NewIntFromBigInt(acct.Balance), txData); err != nil { - return ctx, sdkerrors.Wrap(err, "failed to check sender balance") + return ctx, errorsmod.Wrap(err, "failed to check sender balance") } } return next(ctx, tx, simulate) @@ -142,12 +143,12 @@ func (egcd EthGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula for _, msg := range tx.GetMsgs() { msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx) if !ok { - return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil)) + return ctx, errorsmod.Wrapf(errortypes.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil)) } txData, err := evmtypes.UnpackTxData(msgEthTx.Data) if err != nil { - return ctx, sdkerrors.Wrap(err, "failed to unpack tx data") + return ctx, errorsmod.Wrap(err, "failed to unpack tx data") } if ctx.IsCheckTx() && egcd.maxGasWanted != 0 { @@ -174,7 +175,7 @@ func (egcd EthGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula london, ) if err != nil { - return ctx, sdkerrors.Wrapf(err, "failed to deduct transaction costs from user balance") + return ctx, errorsmod.Wrapf(err, "failed to deduct transaction costs from user balance") } events = append(events, @@ -201,8 +202,8 @@ func (egcd EthGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula // from the tx gas pool. The later only has the value so far since the // EthSetupContextDecorator so it will never exceed the block gas limit. if gasWanted > blockGasLimit { - return ctx, sdkerrors.Wrapf( - sdkerrors.ErrOutOfGas, + return ctx, errorsmod.Wrapf( + errortypes.ErrOutOfGas, "tx gas (%d) exceeds block gas limit (%d)", gasWanted, blockGasLimit, @@ -246,14 +247,14 @@ func (ctd CanTransferDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate for _, msg := range tx.GetMsgs() { msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx) if !ok { - return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil)) + return ctx, errorsmod.Wrapf(errortypes.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil)) } baseFee := ctd.evmKeeper.GetBaseFee(ctx, ethCfg) coreMsg, err := msgEthTx.AsMessage(signer, baseFee) if err != nil { - return ctx, sdkerrors.Wrapf( + return ctx, errorsmod.Wrapf( err, "failed to create an ethereum core.Message from signer %T", signer, ) @@ -261,14 +262,14 @@ func (ctd CanTransferDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate if evmtypes.IsLondon(ethCfg, ctx.BlockHeight()) { if baseFee == nil { - return ctx, sdkerrors.Wrap( + return ctx, errorsmod.Wrap( evmtypes.ErrInvalidBaseFee, "base fee is supported but evm block context value is nil", ) } if coreMsg.GasFeeCap().Cmp(baseFee) < 0 { - return ctx, sdkerrors.Wrapf( - sdkerrors.ErrInsufficientFee, + return ctx, errorsmod.Wrapf( + errortypes.ErrInsufficientFee, "max fee per gas less than block base fee (%s < %s)", coreMsg.GasFeeCap(), baseFee, ) @@ -288,8 +289,8 @@ func (ctd CanTransferDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate // check that caller has enough balance to cover asset transfer for **topmost** call // NOTE: here the gas consumed is from the context with the infinite gas meter if coreMsg.Value().Sign() > 0 && !evm.Context().CanTransfer(stateDB, coreMsg.From(), coreMsg.Value()) { - return ctx, sdkerrors.Wrapf( - sdkerrors.ErrInsufficientFunds, + return ctx, errorsmod.Wrapf( + errortypes.ErrInsufficientFunds, "failed to transfer %s from address %s using the EVM block context transfer function", coreMsg.Value(), coreMsg.From(), @@ -319,19 +320,19 @@ func (issd EthIncrementSenderSequenceDecorator) AnteHandle(ctx sdk.Context, tx s for _, msg := range tx.GetMsgs() { msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx) if !ok { - return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil)) + return ctx, errorsmod.Wrapf(errortypes.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil)) } txData, err := evmtypes.UnpackTxData(msgEthTx.Data) if err != nil { - return ctx, sdkerrors.Wrap(err, "failed to unpack tx data") + return ctx, errorsmod.Wrap(err, "failed to unpack tx data") } // increase sequence of sender acc := issd.ak.GetAccount(ctx, msgEthTx.GetFrom()) if acc == nil { - return ctx, sdkerrors.Wrapf( - sdkerrors.ErrUnknownAddress, + return ctx, errorsmod.Wrapf( + errortypes.ErrUnknownAddress, "account %s is nil", common.BytesToAddress(msgEthTx.GetFrom().Bytes()), ) } @@ -340,14 +341,14 @@ func (issd EthIncrementSenderSequenceDecorator) AnteHandle(ctx sdk.Context, tx s // we merged the nonce verification to nonce increment, so when tx includes multiple messages // with same sender, they'll be accepted. if txData.GetNonce() != nonce { - return ctx, sdkerrors.Wrapf( - sdkerrors.ErrInvalidSequence, + return ctx, errorsmod.Wrapf( + errortypes.ErrInvalidSequence, "invalid nonce; got %d, expected %d", txData.GetNonce(), nonce, ) } if err := acc.SetSequence(nonce + 1); err != nil { - return ctx, sdkerrors.Wrapf(err, "failed to set sequence to %d", acc.GetSequence()+1) + return ctx, errorsmod.Wrapf(err, "failed to set sequence to %d", acc.GetSequence()+1) } issd.ak.SetAccount(ctx, acc) diff --git a/app/ante/fee_checker.go b/app/ante/fee_checker.go index 7d9a9ea97d..885aeac15e 100644 --- a/app/ante/fee_checker.go +++ b/app/ante/fee_checker.go @@ -4,10 +4,11 @@ import ( "fmt" "math" + errorsmod "cosmossdk.io/errors" sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errortypes "github.com/cosmos/cosmos-sdk/types/errors" authante "github.com/cosmos/cosmos-sdk/x/auth/ante" ethermint "github.com/evmos/ethermint/types" "github.com/evmos/ethermint/x/evm/types" @@ -64,7 +65,7 @@ func NewDynamicFeeChecker(k DynamicFeeEVMKeeper) authante.TxFeeChecker { baseFeeInt := sdkmath.NewIntFromBigInt(baseFee) if feeCap.LT(baseFeeInt) { - return nil, 0, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "insufficient gas prices; got: %s required: %s", feeCap, baseFeeInt) + return nil, 0, errorsmod.Wrapf(errortypes.ErrInsufficientFee, "insufficient gas prices; got: %s required: %s", feeCap, baseFeeInt) } // calculate the effective gas price using the EIP-1559 logic. @@ -112,7 +113,7 @@ func checkTxFeeWithValidatorMinGasPrices(ctx sdk.Context, tx sdk.FeeTx) (sdk.Coi } if !feeCoins.IsAnyGTE(requiredFees) { - return nil, 0, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "insufficient fees; got: %s required: %s", feeCoins, requiredFees) + return nil, 0, errorsmod.Wrapf(errortypes.ErrInsufficientFee, "insufficient fees; got: %s required: %s", feeCoins, requiredFees) } } diff --git a/app/ante/fee_market.go b/app/ante/fee_market.go index 24cc504b12..c81a0ce19a 100644 --- a/app/ante/fee_market.go +++ b/app/ante/fee_market.go @@ -3,8 +3,8 @@ package ante import ( "math/big" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) // GasWantedDecorator keeps track of the gasWanted amount on the current block in transient store @@ -44,7 +44,7 @@ func (gwd GasWantedDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo // Add total gasWanted to cumulative in block transientStore in FeeMarket module if isBaseFeeEnabled { if _, err := gwd.feeMarketKeeper.AddTransientGasWanted(ctx, gasWanted); err != nil { - return ctx, sdkerrors.Wrapf(err, "failed to add gas wanted to transient store") + return ctx, errorsmod.Wrapf(err, "failed to add gas wanted to transient store") } } diff --git a/app/ante/fees.go b/app/ante/fees.go index 784ead5c33..b0033c02f9 100644 --- a/app/ante/fees.go +++ b/app/ante/fees.go @@ -3,8 +3,9 @@ package ante import ( "math/big" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errortypes "github.com/cosmos/cosmos-sdk/types/errors" ethtypes "github.com/ethereum/go-ethereum/core/types" evmtypes "github.com/evmos/ethermint/x/evm/types" @@ -27,7 +28,7 @@ func NewMinGasPriceDecorator(fk FeeMarketKeeper, ek EVMKeeper) MinGasPriceDecora func (mpd MinGasPriceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { feeTx, ok := tx.(sdk.FeeTx) if !ok { - return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") + return ctx, errorsmod.Wrap(errortypes.ErrTxDecode, "Tx must be a FeeTx") } minGasPrice := mpd.feesKeeper.GetParams(ctx).MinGasPrice @@ -62,7 +63,7 @@ func (mpd MinGasPriceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate } if !feeCoins.IsAnyGTE(requiredFees) { - return ctx, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, + return ctx, errorsmod.Wrapf(errortypes.ErrInsufficientFee, "provided fee < minimum global fee (%s < %s). Please increase the gas price.", feeCoins, requiredFees) @@ -100,8 +101,8 @@ func (empd EthMinGasPriceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul for _, msg := range tx.GetMsgs() { ethMsg, ok := msg.(*evmtypes.MsgEthereumTx) if !ok { - return ctx, sdkerrors.Wrapf( - sdkerrors.ErrUnknownRequest, + return ctx, errorsmod.Wrapf( + errortypes.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil), ) @@ -120,7 +121,7 @@ func (empd EthMinGasPriceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul txData, err := evmtypes.UnpackTxData(ethMsg.Data) if err != nil { - return ctx, sdkerrors.Wrapf(err, "failed to unpack tx data %s", ethMsg.Hash) + return ctx, errorsmod.Wrapf(err, "failed to unpack tx data %s", ethMsg.Hash) } if txData.TxType() != ethtypes.LegacyTxType { @@ -133,8 +134,8 @@ func (empd EthMinGasPriceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul fee := sdk.NewDecFromBigInt(feeAmt) if fee.LT(requiredFee) { - return ctx, sdkerrors.Wrapf( - sdkerrors.ErrInsufficientFee, + return ctx, errorsmod.Wrapf( + errortypes.ErrInsufficientFee, "provided fee < minimum global fee (%d < %d). Please increase the priority tip (for EIP-1559 txs) or the gas prices (for access list or legacy txs)", //nolint:lll fee.TruncateInt().Int64(), requiredFee.TruncateInt().Int64(), ) diff --git a/app/ante/handler_options.go b/app/ante/handler_options.go index 78f9540428..96387aa674 100644 --- a/app/ante/handler_options.go +++ b/app/ante/handler_options.go @@ -1,8 +1,9 @@ package ante import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errortypes "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/x/auth/ante" authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" @@ -32,19 +33,19 @@ type HandlerOptions struct { func (options HandlerOptions) validate() error { if options.AccountKeeper == nil { - return sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler") + return errorsmod.Wrap(errortypes.ErrLogic, "account keeper is required for AnteHandler") } if options.BankKeeper == nil { - return sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler") + return errorsmod.Wrap(errortypes.ErrLogic, "bank keeper is required for AnteHandler") } if options.SignModeHandler == nil { - return sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder") + return errorsmod.Wrap(errortypes.ErrLogic, "sign mode handler is required for ante builder") } if options.FeeMarketKeeper == nil { - return sdkerrors.Wrap(sdkerrors.ErrLogic, "fee market keeper is required for AnteHandler") + return errorsmod.Wrap(errortypes.ErrLogic, "fee market keeper is required for AnteHandler") } if options.EvmKeeper == nil { - return sdkerrors.Wrap(sdkerrors.ErrLogic, "evm keeper is required for AnteHandler") + return errorsmod.Wrap(errortypes.ErrLogic, "evm keeper is required for AnteHandler") } return nil } diff --git a/app/ante/mempool.go b/app/ante/mempool.go index 489436e7fb..2e18f00567 100644 --- a/app/ante/mempool.go +++ b/app/ante/mempool.go @@ -3,8 +3,9 @@ package ante import ( "math/big" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errortypes "github.com/cosmos/cosmos-sdk/types/errors" evmtypes "github.com/evmos/ethermint/x/evm/types" ) @@ -46,7 +47,7 @@ func (mfd EthMempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulat for _, msg := range tx.GetMsgs() { ethMsg, ok := msg.(*evmtypes.MsgEthereumTx) if !ok { - return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil)) + return ctx, errorsmod.Wrapf(errortypes.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil)) } fee := sdk.NewDecFromBigInt(ethMsg.GetFee()) @@ -54,8 +55,8 @@ func (mfd EthMempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulat requiredFee := minGasPrice.Mul(gasLimit) if fee.LT(requiredFee) { - return ctx, sdkerrors.Wrapf( - sdkerrors.ErrInsufficientFee, + return ctx, errorsmod.Wrapf( + errortypes.ErrInsufficientFee, "insufficient fees; got: %s required: %s", fee, requiredFee, ) diff --git a/app/ante/reject_msgs.go b/app/ante/reject_msgs.go index ce752cc09b..f2728895c2 100644 --- a/app/ante/reject_msgs.go +++ b/app/ante/reject_msgs.go @@ -1,8 +1,9 @@ package ante import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errortypes "github.com/cosmos/cosmos-sdk/types/errors" evmtypes "github.com/evmos/ethermint/x/evm/types" ) @@ -15,8 +16,8 @@ type RejectMessagesDecorator struct{} func (rmd RejectMessagesDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { for _, msg := range tx.GetMsgs() { if _, ok := msg.(*evmtypes.MsgEthereumTx); ok { - return ctx, sdkerrors.Wrapf( - sdkerrors.ErrInvalidType, + return ctx, errorsmod.Wrapf( + errortypes.ErrInvalidType, "MsgEthereumTx needs to be contained within a tx with 'ExtensionOptionsEthereumTx' option", ) } diff --git a/app/ante/setup.go b/app/ante/setup.go index 0df520dcab..e12ab255a0 100644 --- a/app/ante/setup.go +++ b/app/ante/setup.go @@ -4,10 +4,11 @@ import ( "errors" "strconv" + errorsmod "cosmossdk.io/errors" sdkmath "cosmossdk.io/math" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errortypes "github.com/cosmos/cosmos-sdk/types/errors" authante "github.com/cosmos/cosmos-sdk/x/auth/ante" ethtypes "github.com/ethereum/go-ethereum/core/types" evmtypes "github.com/evmos/ethermint/x/evm/types" @@ -29,7 +30,7 @@ func (esc EthSetupContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul // all transactions must implement GasTx _, ok := tx.(authante.GasTx) if !ok { - return newCtx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be GasTx") + return newCtx, errorsmod.Wrap(errortypes.ErrTxDecode, "Tx must be GasTx") } // We need to setup an empty gas config so that the gas is consistent with Ethereum. @@ -61,11 +62,11 @@ func (eeed EthEmitEventDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulat for i, msg := range tx.GetMsgs() { msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx) if !ok { - return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil)) + return ctx, errorsmod.Wrapf(errortypes.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil)) } // emit ethereum tx hash as event, should be indexed by tm tx indexer for query purpose. - // it's emitted in ante handler so we can query failed transaction (out of block gas limit). + // it's emitted in ante handler, so we can query failed transaction (out of block gas limit). ctx.EventManager().EmitEvent(sdk.NewEvent( evmtypes.EventTypeEthereumTx, sdk.NewAttribute(evmtypes.AttributeKeyEthereumTxHash, msgEthTx.Hash), @@ -97,40 +98,40 @@ func (vbd EthValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu err := tx.ValidateBasic() // ErrNoSignatures is fine with eth tx - if err != nil && !errors.Is(err, sdkerrors.ErrNoSignatures) { - return ctx, sdkerrors.Wrap(err, "tx basic validation failed") + if err != nil && !errors.Is(err, errortypes.ErrNoSignatures) { + return ctx, errorsmod.Wrap(err, "tx basic validation failed") } // For eth type cosmos tx, some fields should be verified as zero values, // since we will only verify the signature against the hash of the MsgEthereumTx.Data wrapperTx, ok := tx.(protoTxProvider) if !ok { - return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid tx type %T, didn't implement interface protoTxProvider", tx) + return ctx, errorsmod.Wrapf(errortypes.ErrUnknownRequest, "invalid tx type %T, didn't implement interface protoTxProvider", tx) } protoTx := wrapperTx.GetProtoTx() body := protoTx.Body if body.Memo != "" || body.TimeoutHeight != uint64(0) || len(body.NonCriticalExtensionOptions) > 0 { - return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, + return ctx, errorsmod.Wrap(errortypes.ErrInvalidRequest, "for eth tx body Memo TimeoutHeight NonCriticalExtensionOptions should be empty") } if len(body.ExtensionOptions) != 1 { - return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "for eth tx length of ExtensionOptions should be 1") + return ctx, errorsmod.Wrap(errortypes.ErrInvalidRequest, "for eth tx length of ExtensionOptions should be 1") } authInfo := protoTx.AuthInfo if len(authInfo.SignerInfos) > 0 { - return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "for eth tx AuthInfo SignerInfos should be empty") + return ctx, errorsmod.Wrap(errortypes.ErrInvalidRequest, "for eth tx AuthInfo SignerInfos should be empty") } if authInfo.Fee.Payer != "" || authInfo.Fee.Granter != "" { - return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "for eth tx AuthInfo Fee payer and granter should be empty") + return ctx, errorsmod.Wrap(errortypes.ErrInvalidRequest, "for eth tx AuthInfo Fee payer and granter should be empty") } sigs := protoTx.Signatures if len(sigs) > 0 { - return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "for eth tx Signatures should be empty") + return ctx, errorsmod.Wrap(errortypes.ErrInvalidRequest, "for eth tx Signatures should be empty") } txFee := sdk.Coins{} @@ -147,41 +148,41 @@ func (vbd EthValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu for _, msg := range protoTx.GetMsgs() { msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx) if !ok { - return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil)) + return ctx, errorsmod.Wrapf(errortypes.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil)) } // Validate `From` field if msgEthTx.From != "" { - return ctx, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid From %s, expect empty string", msgEthTx.From) + return ctx, errorsmod.Wrapf(errortypes.ErrInvalidRequest, "invalid From %s, expect empty string", msgEthTx.From) } txGasLimit += msgEthTx.GetGas() txData, err := evmtypes.UnpackTxData(msgEthTx.Data) if err != nil { - return ctx, sdkerrors.Wrap(err, "failed to unpack MsgEthereumTx Data") + return ctx, errorsmod.Wrap(err, "failed to unpack MsgEthereumTx Data") } // return error if contract creation or call are disabled through governance if !enableCreate && txData.GetTo() == nil { - return ctx, sdkerrors.Wrap(evmtypes.ErrCreateDisabled, "failed to create new contract") + return ctx, errorsmod.Wrap(evmtypes.ErrCreateDisabled, "failed to create new contract") } else if !enableCall && txData.GetTo() != nil { - return ctx, sdkerrors.Wrap(evmtypes.ErrCallDisabled, "failed to call contract") + return ctx, errorsmod.Wrap(evmtypes.ErrCallDisabled, "failed to call contract") } if baseFee == nil && txData.TxType() == ethtypes.DynamicFeeTxType { - return ctx, sdkerrors.Wrap(ethtypes.ErrTxTypeNotSupported, "dynamic fee tx not supported") + return ctx, errorsmod.Wrap(ethtypes.ErrTxTypeNotSupported, "dynamic fee tx not supported") } txFee = txFee.Add(sdk.Coin{Denom: evmDenom, Amount: sdkmath.NewIntFromBigInt(txData.Fee())}) } if !authInfo.Fee.Amount.IsEqual(txFee) { - return ctx, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid AuthInfo Fee Amount (%s != %s)", authInfo.Fee.Amount, txFee) + return ctx, errorsmod.Wrapf(errortypes.ErrInvalidRequest, "invalid AuthInfo Fee Amount (%s != %s)", authInfo.Fee.Amount, txFee) } if authInfo.Fee.GasLimit != txGasLimit { - return ctx, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid AuthInfo Fee GasLimit (%d != %d)", authInfo.Fee.GasLimit, txGasLimit) + return ctx, errorsmod.Wrapf(errortypes.ErrInvalidRequest, "invalid AuthInfo Fee GasLimit (%d != %d)", authInfo.Fee.GasLimit, txGasLimit) } return next(ctx, tx, simulate) diff --git a/app/ante/sigverify.go b/app/ante/sigverify.go index bd18855eb1..6ddf3c6344 100644 --- a/app/ante/sigverify.go +++ b/app/ante/sigverify.go @@ -3,8 +3,9 @@ package ante import ( "math/big" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errortypes "github.com/cosmos/cosmos-sdk/types/errors" ethtypes "github.com/ethereum/go-ethereum/core/types" evmtypes "github.com/evmos/ethermint/x/evm/types" ) @@ -36,21 +37,21 @@ func (esvd EthSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, s for _, msg := range tx.GetMsgs() { msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx) if !ok { - return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil)) + return ctx, errorsmod.Wrapf(errortypes.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil)) } allowUnprotectedTxs := esvd.evmKeeper.GetAllowUnprotectedTxs(ctx) ethTx := msgEthTx.AsTransaction() if !allowUnprotectedTxs && !ethTx.Protected() { - return ctx, sdkerrors.Wrapf( - sdkerrors.ErrNotSupported, + return ctx, errorsmod.Wrapf( + errortypes.ErrNotSupported, "rejected unprotected Ethereum txs. Please EIP155 sign your transaction to protect it against replay-attacks") } sender, err := signer.Sender(ethTx) if err != nil { - return ctx, sdkerrors.Wrapf( - sdkerrors.ErrorInvalidSigner, + return ctx, errorsmod.Wrapf( + errortypes.ErrorInvalidSigner, "couldn't retrieve sender address from the ethereum transaction: %s", err.Error(), )