forked from cerc-io/laconicd-deprecated
refactor(all): refactor errors import to use cosmossdk.io (#1456)
* refactor (errors) refactor errors import to use cosmossdk.io instead of cosmos-sdk/types/errors * refactor (errors) refactor errors import in ethsecp256k1 file * refactor (errors) add changes to changelog
This commit is contained in:
+3
-2
@@ -1,8 +1,9 @@
|
||||
package evm
|
||||
|
||||
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/evmos/ethermint/x/evm/types"
|
||||
)
|
||||
@@ -19,7 +20,7 @@ func NewHandler(server types.MsgServer) sdk.Handler {
|
||||
return sdk.WrapServiceResult(ctx, res, err)
|
||||
|
||||
default:
|
||||
err := sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", types.ModuleName, msg)
|
||||
err := errorsmod.Wrapf(errortypes.ErrUnknownRequest, "unrecognized %s message type: %T", types.ModuleName, msg)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/evmos/ethermint/x/evm/types"
|
||||
@@ -22,7 +22,7 @@ func NewMultiEvmHooks(hooks ...types.EvmHooks) MultiEvmHooks {
|
||||
func (mh MultiEvmHooks) PostTxProcessing(ctx sdk.Context, msg core.Message, receipt *ethtypes.Receipt) error {
|
||||
for i := range mh {
|
||||
if err := mh[i].PostTxProcessing(ctx, msg, receipt); err != nil {
|
||||
return sdkerrors.Wrapf(err, "EVM hook %T failed", mh[i])
|
||||
return errorsmod.Wrapf(err, "EVM hook %T failed", mh[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -3,11 +3,11 @@ package keeper
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/store/prefix"
|
||||
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
@@ -364,7 +364,7 @@ func (k Keeper) SetTransientGasUsed(ctx sdk.Context, gasUsed uint64) {
|
||||
func (k Keeper) AddTransientGasUsed(ctx sdk.Context, gasUsed uint64) (uint64, error) {
|
||||
result := k.GetTransientGasUsed(ctx) + gasUsed
|
||||
if result < gasUsed {
|
||||
return 0, sdkerrors.Wrap(types.ErrGasOverflow, "transient gas used")
|
||||
return 0, errorsmod.Wrap(types.ErrGasOverflow, "transient gas used")
|
||||
}
|
||||
k.SetTransientGasUsed(ctx, result)
|
||||
return result, nil
|
||||
|
||||
@@ -9,10 +9,10 @@ import (
|
||||
tmbytes "github.com/tendermint/tendermint/libs/bytes"
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
"github.com/armon/go-metrics"
|
||||
"github.com/cosmos/cosmos-sdk/telemetry"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
|
||||
"github.com/evmos/ethermint/x/evm/types"
|
||||
)
|
||||
@@ -45,7 +45,7 @@ func (k *Keeper) EthereumTx(goCtx context.Context, msg *types.MsgEthereumTx) (*t
|
||||
|
||||
response, err := k.ApplyTransaction(ctx, tx)
|
||||
if err != nil {
|
||||
return nil, sdkerrors.Wrap(err, "failed to apply transaction")
|
||||
return nil, errorsmod.Wrap(err, "failed to apply transaction")
|
||||
}
|
||||
|
||||
defer func() {
|
||||
@@ -104,7 +104,7 @@ func (k *Keeper) EthereumTx(goCtx context.Context, msg *types.MsgEthereumTx) (*t
|
||||
for i, log := range response.Logs {
|
||||
value, err := json.Marshal(log)
|
||||
if err != nil {
|
||||
return nil, sdkerrors.Wrap(err, "failed to encode log")
|
||||
return nil, errorsmod.Wrap(err, "failed to encode log")
|
||||
}
|
||||
txLogAttrs[i] = sdk.NewAttribute(types.AttributeKeyTxLog, string(value))
|
||||
}
|
||||
|
||||
@@ -8,8 +8,9 @@ import (
|
||||
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
||||
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"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
|
||||
@@ -46,7 +47,7 @@ func (k *Keeper) EVMConfig(ctx sdk.Context, proposerAddress sdk.ConsAddress) (*t
|
||||
// get the coinbase address from the block proposer
|
||||
coinbase, err := k.GetCoinbaseAddress(ctx, proposerAddress)
|
||||
if err != nil {
|
||||
return nil, sdkerrors.Wrap(err, "failed to obtain coinbase address")
|
||||
return nil, errorsmod.Wrap(err, "failed to obtain coinbase address")
|
||||
}
|
||||
|
||||
baseFee := k.GetBaseFee(ctx, ethCfg)
|
||||
@@ -201,7 +202,7 @@ func (k *Keeper) ApplyTransaction(ctx sdk.Context, tx *ethtypes.Transaction) (*t
|
||||
|
||||
cfg, err := k.EVMConfig(ctx, sdk.ConsAddress(ctx.BlockHeader().ProposerAddress))
|
||||
if err != nil {
|
||||
return nil, sdkerrors.Wrap(err, "failed to load evm config")
|
||||
return nil, errorsmod.Wrap(err, "failed to load evm config")
|
||||
}
|
||||
txConfig := k.TxConfig(ctx, tx.Hash())
|
||||
|
||||
@@ -209,7 +210,7 @@ func (k *Keeper) ApplyTransaction(ctx sdk.Context, tx *ethtypes.Transaction) (*t
|
||||
signer := ethtypes.MakeSigner(cfg.ChainConfig, big.NewInt(ctx.BlockHeight()))
|
||||
msg, err := tx.AsMessage(signer, cfg.BaseFee)
|
||||
if err != nil {
|
||||
return nil, sdkerrors.Wrap(err, "failed to return ethereum transaction as core message")
|
||||
return nil, errorsmod.Wrap(err, "failed to return ethereum transaction as core message")
|
||||
}
|
||||
|
||||
// snapshot to contain the tx processing and post processing in same scope
|
||||
@@ -226,7 +227,7 @@ func (k *Keeper) ApplyTransaction(ctx sdk.Context, tx *ethtypes.Transaction) (*t
|
||||
// pass true to commit the StateDB
|
||||
res, err := k.ApplyMessageWithConfig(tmpCtx, msg, nil, true, cfg, txConfig)
|
||||
if err != nil {
|
||||
return nil, sdkerrors.Wrap(err, "failed to apply ethereum core message")
|
||||
return nil, errorsmod.Wrap(err, "failed to apply ethereum core message")
|
||||
}
|
||||
|
||||
logs := types.LogsToEthereum(res.Logs)
|
||||
@@ -285,7 +286,7 @@ func (k *Keeper) ApplyTransaction(ctx sdk.Context, tx *ethtypes.Transaction) (*t
|
||||
|
||||
// refund gas in order to match the Ethereum gas consumption instead of the default SDK one.
|
||||
if err = k.RefundGas(ctx, msg, msg.Gas()-res.GasUsed, cfg.Params.EvmDenom); err != nil {
|
||||
return nil, sdkerrors.Wrapf(err, "failed to refund gas leftover gas to sender %s", msg.From())
|
||||
return nil, errorsmod.Wrapf(err, "failed to refund gas leftover gas to sender %s", msg.From())
|
||||
}
|
||||
|
||||
if len(receipt.Logs) > 0 {
|
||||
@@ -298,7 +299,7 @@ func (k *Keeper) ApplyTransaction(ctx sdk.Context, tx *ethtypes.Transaction) (*t
|
||||
|
||||
totalGasUsed, err := k.AddTransientGasUsed(ctx, res.GasUsed)
|
||||
if err != nil {
|
||||
return nil, sdkerrors.Wrap(err, "failed to add transient gas used")
|
||||
return nil, errorsmod.Wrap(err, "failed to add transient gas used")
|
||||
}
|
||||
|
||||
// reset the gas meter for current cosmos transaction
|
||||
@@ -358,9 +359,9 @@ func (k *Keeper) ApplyMessageWithConfig(ctx sdk.Context,
|
||||
|
||||
// return error if contract creation or call are disabled through governance
|
||||
if !cfg.Params.EnableCreate && msg.To() == nil {
|
||||
return nil, sdkerrors.Wrap(types.ErrCreateDisabled, "failed to create new contract")
|
||||
return nil, errorsmod.Wrap(types.ErrCreateDisabled, "failed to create new contract")
|
||||
} else if !cfg.Params.EnableCall && msg.To() != nil {
|
||||
return nil, sdkerrors.Wrap(types.ErrCallDisabled, "failed to call contract")
|
||||
return nil, errorsmod.Wrap(types.ErrCallDisabled, "failed to call contract")
|
||||
}
|
||||
|
||||
stateDB := statedb.New(ctx, k, txConfig)
|
||||
@@ -384,13 +385,13 @@ func (k *Keeper) ApplyMessageWithConfig(ctx sdk.Context,
|
||||
intrinsicGas, err := k.GetEthIntrinsicGas(ctx, msg, cfg.ChainConfig, contractCreation)
|
||||
if err != nil {
|
||||
// should have already been checked on Ante Handler
|
||||
return nil, sdkerrors.Wrap(err, "intrinsic gas failed")
|
||||
return nil, errorsmod.Wrap(err, "intrinsic gas failed")
|
||||
}
|
||||
|
||||
// Should check again even if it is checked on Ante Handler, because eth_call don't go through Ante Handler.
|
||||
if leftoverGas < intrinsicGas {
|
||||
// eth_estimateGas will check for this exact error
|
||||
return nil, sdkerrors.Wrap(core.ErrIntrinsicGas, "apply message")
|
||||
return nil, errorsmod.Wrap(core.ErrIntrinsicGas, "apply message")
|
||||
}
|
||||
leftoverGas -= intrinsicGas
|
||||
|
||||
@@ -420,7 +421,7 @@ func (k *Keeper) ApplyMessageWithConfig(ctx sdk.Context,
|
||||
|
||||
// calculate gas refund
|
||||
if msg.Gas() < leftoverGas {
|
||||
return nil, sdkerrors.Wrap(types.ErrGasOverflow, "apply message")
|
||||
return nil, errorsmod.Wrap(types.ErrGasOverflow, "apply message")
|
||||
}
|
||||
// refund gas
|
||||
leftoverGas += GasToRefund(stateDB.GetRefund(), msg.Gas()-leftoverGas, refundQuotient)
|
||||
@@ -434,7 +435,7 @@ func (k *Keeper) ApplyMessageWithConfig(ctx sdk.Context,
|
||||
// The dirty states in `StateDB` is either committed or discarded after return
|
||||
if commit {
|
||||
if err := stateDB.Commit(); err != nil {
|
||||
return nil, sdkerrors.Wrap(err, "failed to commit stateDB")
|
||||
return nil, errorsmod.Wrap(err, "failed to commit stateDB")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -446,7 +447,7 @@ func (k *Keeper) ApplyMessageWithConfig(ctx sdk.Context,
|
||||
minimumGasUsed := gasLimit.Mul(minGasMultiplier)
|
||||
|
||||
if msg.Gas() < leftoverGas {
|
||||
return nil, sdkerrors.Wrapf(types.ErrGasOverflow, "message gas limit < leftover gas (%d < %d)", msg.Gas(), leftoverGas)
|
||||
return nil, errorsmod.Wrapf(types.ErrGasOverflow, "message gas limit < leftover gas (%d < %d)", msg.Gas(), leftoverGas)
|
||||
}
|
||||
temporaryGasUsed := msg.Gas() - leftoverGas
|
||||
gasUsed := sdk.MaxDec(minimumGasUsed, sdk.NewDec(int64(temporaryGasUsed))).TruncateInt().Uint64()
|
||||
@@ -466,7 +467,7 @@ func (k *Keeper) ApplyMessageWithConfig(ctx sdk.Context,
|
||||
func (k *Keeper) ApplyMessage(ctx sdk.Context, msg core.Message, tracer vm.EVMLogger, commit bool) (*types.MsgEthereumTxResponse, error) {
|
||||
cfg, err := k.EVMConfig(ctx, sdk.ConsAddress(ctx.BlockHeader().ProposerAddress))
|
||||
if err != nil {
|
||||
return nil, sdkerrors.Wrap(err, "failed to load evm config")
|
||||
return nil, errorsmod.Wrap(err, "failed to load evm config")
|
||||
}
|
||||
txConfig := statedb.NewEmptyTxConfig(common.BytesToHash(ctx.HeaderHash()))
|
||||
return k.ApplyMessageWithConfig(ctx, msg, tracer, commit, cfg, txConfig)
|
||||
@@ -492,7 +493,7 @@ func (k *Keeper) RefundGas(ctx sdk.Context, msg core.Message, leftoverGas uint64
|
||||
switch remaining.Sign() {
|
||||
case -1:
|
||||
// negative refund errors
|
||||
return sdkerrors.Wrapf(types.ErrInvalidRefund, "refunded amount value cannot be negative %d", remaining.Int64())
|
||||
return errorsmod.Wrapf(types.ErrInvalidRefund, "refunded amount value cannot be negative %d", remaining.Int64())
|
||||
case 1:
|
||||
// positive amount refund
|
||||
refundedCoins := sdk.Coins{sdk.NewCoin(denom, sdkmath.NewIntFromBigInt(remaining))}
|
||||
@@ -501,8 +502,8 @@ func (k *Keeper) RefundGas(ctx sdk.Context, msg core.Message, leftoverGas uint64
|
||||
|
||||
err := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, authtypes.FeeCollectorName, msg.From().Bytes(), refundedCoins)
|
||||
if err != nil {
|
||||
err = sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, "fee collector account failed to refund fees: %s", err.Error())
|
||||
return sdkerrors.Wrapf(err, "failed to refund %d leftover gas (%s)", leftoverGas, refundedCoins.String())
|
||||
err = errorsmod.Wrapf(errortypes.ErrInsufficientFunds, "fee collector account failed to refund fees: %s", err.Error())
|
||||
return errorsmod.Wrapf(err, "failed to refund %d leftover gas (%s)", leftoverGas, refundedCoins.String())
|
||||
}
|
||||
default:
|
||||
// no refund, consume gas and update the tx gas meter
|
||||
@@ -531,7 +532,7 @@ func GetProposerAddress(ctx sdk.Context, proposerAddress sdk.ConsAddress) sdk.Co
|
||||
func (k Keeper) GetCoinbaseAddress(ctx sdk.Context, proposerAddress sdk.ConsAddress) (common.Address, error) {
|
||||
validator, found := k.stakingKeeper.GetValidatorByConsAddr(ctx, GetProposerAddress(ctx, proposerAddress))
|
||||
if !found {
|
||||
return common.Address{}, sdkerrors.Wrapf(
|
||||
return common.Address{}, errorsmod.Wrapf(
|
||||
stakingtypes.ErrNoValidatorFound,
|
||||
"failed to retrieve validator from block proposer address %s",
|
||||
proposerAddress.String(),
|
||||
|
||||
@@ -6,9 +6,9 @@ import (
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
"github.com/cosmos/cosmos-sdk/store/prefix"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
ethermint "github.com/evmos/ethermint/types"
|
||||
"github.com/evmos/ethermint/x/evm/statedb"
|
||||
@@ -189,7 +189,7 @@ func (k *Keeper) DeleteAccount(ctx sdk.Context, addr common.Address) error {
|
||||
// NOTE: only Ethereum accounts (contracts) can be selfdestructed
|
||||
_, ok := acct.(ethermint.EthAccountI)
|
||||
if !ok {
|
||||
return sdkerrors.Wrapf(types.ErrInvalidAccount, "type %T, address %s", acct, addr)
|
||||
return errorsmod.Wrapf(types.ErrInvalidAccount, "type %T, address %s", acct, addr)
|
||||
}
|
||||
|
||||
// clear balance
|
||||
|
||||
+12
-11
@@ -4,9 +4,10 @@ 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"
|
||||
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
|
||||
|
||||
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
||||
@@ -29,7 +30,7 @@ func (k Keeper) DeductTxCostsFromUserBalance(
|
||||
// fetch sender account from signature
|
||||
signerAcc, err := authante.GetSignerAcc(ctx, k.accountKeeper, msgEthTx.GetFrom())
|
||||
if err != nil {
|
||||
return nil, 0, sdkerrors.Wrapf(err, "account not found for sender %s", msgEthTx.From)
|
||||
return nil, 0, errorsmod.Wrapf(err, "account not found for sender %s", msgEthTx.From)
|
||||
}
|
||||
|
||||
gasLimit := txData.GetGas()
|
||||
@@ -41,7 +42,7 @@ func (k Keeper) DeductTxCostsFromUserBalance(
|
||||
|
||||
intrinsicGas, err := core.IntrinsicGas(txData.GetData(), accessList, isContractCreation, homestead, istanbul)
|
||||
if err != nil {
|
||||
return nil, 0, sdkerrors.Wrapf(
|
||||
return nil, 0, errorsmod.Wrapf(
|
||||
err,
|
||||
"failed to retrieve intrinsic gas, contract creation = %t; homestead = %t, istanbul = %t",
|
||||
isContractCreation, homestead, istanbul,
|
||||
@@ -50,8 +51,8 @@ func (k Keeper) DeductTxCostsFromUserBalance(
|
||||
|
||||
// intrinsic gas verification during CheckTx
|
||||
if ctx.IsCheckTx() && gasLimit < intrinsicGas {
|
||||
return nil, 0, sdkerrors.Wrapf(
|
||||
sdkerrors.ErrOutOfGas,
|
||||
return nil, 0, errorsmod.Wrapf(
|
||||
errortypes.ErrOutOfGas,
|
||||
"gas limit too low: %d (gas limit) < %d (intrinsic gas)", gasLimit, intrinsicGas,
|
||||
)
|
||||
}
|
||||
@@ -60,7 +61,7 @@ func (k Keeper) DeductTxCostsFromUserBalance(
|
||||
|
||||
baseFee := k.getBaseFee(ctx, london)
|
||||
if baseFee != nil && txData.GetGasFeeCap().Cmp(baseFee) < 0 {
|
||||
return nil, 0, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee,
|
||||
return nil, 0, errorsmod.Wrapf(errortypes.ErrInsufficientFee,
|
||||
"the tx gasfeecap is lower than the tx baseFee: %s (gasfeecap), %s (basefee) ",
|
||||
txData.GetGasFeeCap(),
|
||||
baseFee)
|
||||
@@ -76,7 +77,7 @@ func (k Keeper) DeductTxCostsFromUserBalance(
|
||||
|
||||
// deduct the full gas cost from the user balance
|
||||
if err := authante.DeductFees(k.bankKeeper, ctx, signerAcc, fees); err != nil {
|
||||
return nil, 0, sdkerrors.Wrapf(
|
||||
return nil, 0, errorsmod.Wrapf(
|
||||
err,
|
||||
"failed to deduct full gas cost %s from the user %s balance",
|
||||
fees, msgEthTx.From,
|
||||
@@ -108,15 +109,15 @@ func CheckSenderBalance(
|
||||
cost := txData.Cost()
|
||||
|
||||
if cost.Sign() < 0 {
|
||||
return sdkerrors.Wrapf(
|
||||
sdkerrors.ErrInvalidCoins,
|
||||
return errorsmod.Wrapf(
|
||||
errortypes.ErrInvalidCoins,
|
||||
"tx cost (%s) is negative and invalid", cost,
|
||||
)
|
||||
}
|
||||
|
||||
if balance.IsNegative() || balance.BigInt().Cmp(cost) < 0 {
|
||||
return sdkerrors.Wrapf(
|
||||
sdkerrors.ErrInsufficientFunds,
|
||||
return errorsmod.Wrapf(
|
||||
errortypes.ErrInsufficientFunds,
|
||||
"sender balance < tx cost (%s < %s)", balance, txData.Cost(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
@@ -91,61 +91,61 @@ func getBlockValue(block *sdkmath.Int) *big.Int {
|
||||
// if any of the block values is uninitialized (i.e nil) or if the EIP150Hash is an invalid hash.
|
||||
func (cc ChainConfig) Validate() error {
|
||||
if err := validateBlock(cc.HomesteadBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "homesteadBlock")
|
||||
return errorsmod.Wrap(err, "homesteadBlock")
|
||||
}
|
||||
if err := validateBlock(cc.DAOForkBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "daoForkBlock")
|
||||
return errorsmod.Wrap(err, "daoForkBlock")
|
||||
}
|
||||
if err := validateBlock(cc.EIP150Block); err != nil {
|
||||
return sdkerrors.Wrap(err, "eip150Block")
|
||||
return errorsmod.Wrap(err, "eip150Block")
|
||||
}
|
||||
if err := validateHash(cc.EIP150Hash); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateBlock(cc.EIP155Block); err != nil {
|
||||
return sdkerrors.Wrap(err, "eip155Block")
|
||||
return errorsmod.Wrap(err, "eip155Block")
|
||||
}
|
||||
if err := validateBlock(cc.EIP158Block); err != nil {
|
||||
return sdkerrors.Wrap(err, "eip158Block")
|
||||
return errorsmod.Wrap(err, "eip158Block")
|
||||
}
|
||||
if err := validateBlock(cc.ByzantiumBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "byzantiumBlock")
|
||||
return errorsmod.Wrap(err, "byzantiumBlock")
|
||||
}
|
||||
if err := validateBlock(cc.ConstantinopleBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "constantinopleBlock")
|
||||
return errorsmod.Wrap(err, "constantinopleBlock")
|
||||
}
|
||||
if err := validateBlock(cc.PetersburgBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "petersburgBlock")
|
||||
return errorsmod.Wrap(err, "petersburgBlock")
|
||||
}
|
||||
if err := validateBlock(cc.IstanbulBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "istanbulBlock")
|
||||
return errorsmod.Wrap(err, "istanbulBlock")
|
||||
}
|
||||
if err := validateBlock(cc.MuirGlacierBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "muirGlacierBlock")
|
||||
return errorsmod.Wrap(err, "muirGlacierBlock")
|
||||
}
|
||||
if err := validateBlock(cc.BerlinBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "berlinBlock")
|
||||
return errorsmod.Wrap(err, "berlinBlock")
|
||||
}
|
||||
if err := validateBlock(cc.LondonBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "londonBlock")
|
||||
return errorsmod.Wrap(err, "londonBlock")
|
||||
}
|
||||
if err := validateBlock(cc.ArrowGlacierBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "arrowGlacierBlock")
|
||||
return errorsmod.Wrap(err, "arrowGlacierBlock")
|
||||
}
|
||||
if err := validateBlock(cc.MergeForkBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "mergeForkBlock")
|
||||
return errorsmod.Wrap(err, "mergeForkBlock")
|
||||
}
|
||||
|
||||
// NOTE: chain ID is not needed to check config order
|
||||
if err := cc.EthereumConfig(nil).CheckConfigForkOrder(); err != nil {
|
||||
return sdkerrors.Wrap(err, "invalid config fork order")
|
||||
return errorsmod.Wrap(err, "invalid config fork order")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateHash(hex string) error {
|
||||
if hex != "" && strings.TrimSpace(hex) == "" {
|
||||
return sdkerrors.Wrap(types.ErrInvalidChainConfig, "hash cannot be blank")
|
||||
return errorsmod.Wrap(types.ErrInvalidChainConfig, "hash cannot be blank")
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -158,7 +158,7 @@ func validateBlock(block *sdkmath.Int) error {
|
||||
}
|
||||
|
||||
if block.IsNegative() {
|
||||
return sdkerrors.Wrapf(
|
||||
return errorsmod.Wrapf(
|
||||
types.ErrInvalidChainConfig, "block value cannot be negative: %s", block,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
|
||||
"github.com/evmos/ethermint/x/evm/types"
|
||||
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
@@ -90,61 +90,61 @@ func getBlockValue(block *sdkmath.Int) *big.Int {
|
||||
// if any of the block values is uninitialized (i.e nil) or if the EIP150Hash is an invalid hash.
|
||||
func (cc ChainConfig) Validate() error {
|
||||
if err := validateBlock(cc.HomesteadBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "homesteadBlock")
|
||||
return errorsmod.Wrap(err, "homesteadBlock")
|
||||
}
|
||||
if err := validateBlock(cc.DAOForkBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "daoForkBlock")
|
||||
return errorsmod.Wrap(err, "daoForkBlock")
|
||||
}
|
||||
if err := validateBlock(cc.EIP150Block); err != nil {
|
||||
return sdkerrors.Wrap(err, "eip150Block")
|
||||
return errorsmod.Wrap(err, "eip150Block")
|
||||
}
|
||||
if err := validateHash(cc.EIP150Hash); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateBlock(cc.EIP155Block); err != nil {
|
||||
return sdkerrors.Wrap(err, "eip155Block")
|
||||
return errorsmod.Wrap(err, "eip155Block")
|
||||
}
|
||||
if err := validateBlock(cc.EIP158Block); err != nil {
|
||||
return sdkerrors.Wrap(err, "eip158Block")
|
||||
return errorsmod.Wrap(err, "eip158Block")
|
||||
}
|
||||
if err := validateBlock(cc.ByzantiumBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "byzantiumBlock")
|
||||
return errorsmod.Wrap(err, "byzantiumBlock")
|
||||
}
|
||||
if err := validateBlock(cc.ConstantinopleBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "constantinopleBlock")
|
||||
return errorsmod.Wrap(err, "constantinopleBlock")
|
||||
}
|
||||
if err := validateBlock(cc.PetersburgBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "petersburgBlock")
|
||||
return errorsmod.Wrap(err, "petersburgBlock")
|
||||
}
|
||||
if err := validateBlock(cc.IstanbulBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "istanbulBlock")
|
||||
return errorsmod.Wrap(err, "istanbulBlock")
|
||||
}
|
||||
if err := validateBlock(cc.MuirGlacierBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "muirGlacierBlock")
|
||||
return errorsmod.Wrap(err, "muirGlacierBlock")
|
||||
}
|
||||
if err := validateBlock(cc.BerlinBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "berlinBlock")
|
||||
return errorsmod.Wrap(err, "berlinBlock")
|
||||
}
|
||||
if err := validateBlock(cc.LondonBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "londonBlock")
|
||||
return errorsmod.Wrap(err, "londonBlock")
|
||||
}
|
||||
if err := validateBlock(cc.ArrowGlacierBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "arrowGlacierBlock")
|
||||
return errorsmod.Wrap(err, "arrowGlacierBlock")
|
||||
}
|
||||
if err := validateBlock(cc.MergeForkBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "mergeForkBlock")
|
||||
return errorsmod.Wrap(err, "mergeForkBlock")
|
||||
}
|
||||
|
||||
// NOTE: chain ID is not needed to check config order
|
||||
if err := cc.EthereumConfig(nil).CheckConfigForkOrder(); err != nil {
|
||||
return sdkerrors.Wrap(err, "invalid config fork order")
|
||||
return errorsmod.Wrap(err, "invalid config fork order")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateHash(hex string) error {
|
||||
if hex != "" && strings.TrimSpace(hex) == "" {
|
||||
return sdkerrors.Wrap(types.ErrInvalidChainConfig, "hash cannot be blank")
|
||||
return errorsmod.Wrap(types.ErrInvalidChainConfig, "hash cannot be blank")
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -157,7 +157,7 @@ func validateBlock(block *sdkmath.Int) error {
|
||||
}
|
||||
|
||||
if block.IsNegative() {
|
||||
return sdkerrors.Wrapf(
|
||||
return errorsmod.Wrapf(
|
||||
types.ErrInvalidChainConfig, "block value cannot be negative: %s", block,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"math/big"
|
||||
"sort"
|
||||
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/core/vm"
|
||||
@@ -440,14 +440,14 @@ func (s *StateDB) Commit() error {
|
||||
obj := s.stateObjects[addr]
|
||||
if obj.suicided {
|
||||
if err := s.keeper.DeleteAccount(s.ctx, obj.Address()); err != nil {
|
||||
return sdkerrors.Wrap(err, "failed to delete account")
|
||||
return errorsmod.Wrap(err, "failed to delete account")
|
||||
}
|
||||
} else {
|
||||
if obj.code != nil && obj.dirtyCode {
|
||||
s.keeper.SetCode(s.ctx, obj.CodeHash(), obj.code)
|
||||
}
|
||||
if err := s.keeper.SetAccount(s.ctx, obj.Address(), obj.account); err != nil {
|
||||
return sdkerrors.Wrap(err, "failed to set account")
|
||||
return errorsmod.Wrap(err, "failed to set account")
|
||||
}
|
||||
for _, key := range obj.dirtyStorage.SortedKeys() {
|
||||
value := obj.dirtyStorage[key]
|
||||
|
||||
@@ -3,8 +3,9 @@ package types
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
sdkmath "cosmossdk.io/math"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||
@@ -183,38 +184,38 @@ func (tx *AccessListTx) SetSignatureValues(chainID, v, r, s *big.Int) {
|
||||
func (tx AccessListTx) Validate() error {
|
||||
gasPrice := tx.GetGasPrice()
|
||||
if gasPrice == nil {
|
||||
return sdkerrors.Wrap(ErrInvalidGasPrice, "cannot be nil")
|
||||
return errorsmod.Wrap(ErrInvalidGasPrice, "cannot be nil")
|
||||
}
|
||||
if !types.IsValidInt256(gasPrice) {
|
||||
return sdkerrors.Wrap(ErrInvalidGasPrice, "out of bound")
|
||||
return errorsmod.Wrap(ErrInvalidGasPrice, "out of bound")
|
||||
}
|
||||
|
||||
if gasPrice.Sign() == -1 {
|
||||
return sdkerrors.Wrapf(ErrInvalidGasPrice, "gas price cannot be negative %s", gasPrice)
|
||||
return errorsmod.Wrapf(ErrInvalidGasPrice, "gas price cannot be negative %s", gasPrice)
|
||||
}
|
||||
|
||||
amount := tx.GetValue()
|
||||
// Amount can be 0
|
||||
if amount != nil && amount.Sign() == -1 {
|
||||
return sdkerrors.Wrapf(ErrInvalidAmount, "amount cannot be negative %s", amount)
|
||||
return errorsmod.Wrapf(ErrInvalidAmount, "amount cannot be negative %s", amount)
|
||||
}
|
||||
if !types.IsValidInt256(amount) {
|
||||
return sdkerrors.Wrap(ErrInvalidAmount, "out of bound")
|
||||
return errorsmod.Wrap(ErrInvalidAmount, "out of bound")
|
||||
}
|
||||
|
||||
if !types.IsValidInt256(tx.Fee()) {
|
||||
return sdkerrors.Wrap(ErrInvalidGasFee, "out of bound")
|
||||
return errorsmod.Wrap(ErrInvalidGasFee, "out of bound")
|
||||
}
|
||||
|
||||
if tx.To != "" {
|
||||
if err := types.ValidateAddress(tx.To); err != nil {
|
||||
return sdkerrors.Wrap(err, "invalid to address")
|
||||
return errorsmod.Wrap(err, "invalid to address")
|
||||
}
|
||||
}
|
||||
|
||||
if tx.GetChainID() == nil {
|
||||
return sdkerrors.Wrap(
|
||||
sdkerrors.ErrInvalidChainID,
|
||||
return errorsmod.Wrap(
|
||||
errortypes.ErrInvalidChainID,
|
||||
"chain ID must be present on AccessList txs",
|
||||
)
|
||||
}
|
||||
|
||||
+19
-19
@@ -6,8 +6,8 @@ import (
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
@@ -92,64 +92,64 @@ func getBlockValue(block *sdkmath.Int) *big.Int {
|
||||
// if any of the block values is uninitialized (i.e nil) or if the EIP150Hash is an invalid hash.
|
||||
func (cc ChainConfig) Validate() error {
|
||||
if err := validateBlock(cc.HomesteadBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "homesteadBlock")
|
||||
return errorsmod.Wrap(err, "homesteadBlock")
|
||||
}
|
||||
if err := validateBlock(cc.DAOForkBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "daoForkBlock")
|
||||
return errorsmod.Wrap(err, "daoForkBlock")
|
||||
}
|
||||
if err := validateBlock(cc.EIP150Block); err != nil {
|
||||
return sdkerrors.Wrap(err, "eip150Block")
|
||||
return errorsmod.Wrap(err, "eip150Block")
|
||||
}
|
||||
if err := validateHash(cc.EIP150Hash); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateBlock(cc.EIP155Block); err != nil {
|
||||
return sdkerrors.Wrap(err, "eip155Block")
|
||||
return errorsmod.Wrap(err, "eip155Block")
|
||||
}
|
||||
if err := validateBlock(cc.EIP158Block); err != nil {
|
||||
return sdkerrors.Wrap(err, "eip158Block")
|
||||
return errorsmod.Wrap(err, "eip158Block")
|
||||
}
|
||||
if err := validateBlock(cc.ByzantiumBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "byzantiumBlock")
|
||||
return errorsmod.Wrap(err, "byzantiumBlock")
|
||||
}
|
||||
if err := validateBlock(cc.ConstantinopleBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "constantinopleBlock")
|
||||
return errorsmod.Wrap(err, "constantinopleBlock")
|
||||
}
|
||||
if err := validateBlock(cc.PetersburgBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "petersburgBlock")
|
||||
return errorsmod.Wrap(err, "petersburgBlock")
|
||||
}
|
||||
if err := validateBlock(cc.IstanbulBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "istanbulBlock")
|
||||
return errorsmod.Wrap(err, "istanbulBlock")
|
||||
}
|
||||
if err := validateBlock(cc.MuirGlacierBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "muirGlacierBlock")
|
||||
return errorsmod.Wrap(err, "muirGlacierBlock")
|
||||
}
|
||||
if err := validateBlock(cc.BerlinBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "berlinBlock")
|
||||
return errorsmod.Wrap(err, "berlinBlock")
|
||||
}
|
||||
if err := validateBlock(cc.LondonBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "londonBlock")
|
||||
return errorsmod.Wrap(err, "londonBlock")
|
||||
}
|
||||
if err := validateBlock(cc.ArrowGlacierBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "arrowGlacierBlock")
|
||||
return errorsmod.Wrap(err, "arrowGlacierBlock")
|
||||
}
|
||||
if err := validateBlock(cc.GrayGlacierBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "GrayGlacierBlock")
|
||||
return errorsmod.Wrap(err, "GrayGlacierBlock")
|
||||
}
|
||||
if err := validateBlock(cc.MergeNetsplitBlock); err != nil {
|
||||
return sdkerrors.Wrap(err, "MergeNetsplitBlock")
|
||||
return errorsmod.Wrap(err, "MergeNetsplitBlock")
|
||||
}
|
||||
|
||||
// NOTE: chain ID is not needed to check config order
|
||||
if err := cc.EthereumConfig(nil).CheckConfigForkOrder(); err != nil {
|
||||
return sdkerrors.Wrap(err, "invalid config fork order")
|
||||
return errorsmod.Wrap(err, "invalid config fork order")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateHash(hex string) error {
|
||||
if hex != "" && strings.TrimSpace(hex) == "" {
|
||||
return sdkerrors.Wrap(ErrInvalidChainConfig, "hash cannot be blank")
|
||||
return errorsmod.Wrap(ErrInvalidChainConfig, "hash cannot be blank")
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -162,7 +162,7 @@ func validateBlock(block *sdkmath.Int) error {
|
||||
}
|
||||
|
||||
if block.IsNegative() {
|
||||
return sdkerrors.Wrapf(
|
||||
return errorsmod.Wrapf(
|
||||
ErrInvalidChainConfig, "block value cannot be negative: %s", block,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/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/msgservice"
|
||||
"github.com/cosmos/cosmos-sdk/types/tx"
|
||||
proto "github.com/gogo/protobuf/proto"
|
||||
@@ -39,12 +40,12 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
|
||||
func PackTxData(txData TxData) (*codectypes.Any, error) {
|
||||
msg, ok := txData.(proto.Message)
|
||||
if !ok {
|
||||
return nil, sdkerrors.Wrapf(sdkerrors.ErrPackAny, "cannot proto marshal %T", txData)
|
||||
return nil, errorsmod.Wrapf(errortypes.ErrPackAny, "cannot proto marshal %T", txData)
|
||||
}
|
||||
|
||||
anyTxData, err := codectypes.NewAnyWithValue(msg)
|
||||
if err != nil {
|
||||
return nil, sdkerrors.Wrap(sdkerrors.ErrPackAny, err.Error())
|
||||
return nil, errorsmod.Wrap(errortypes.ErrPackAny, err.Error())
|
||||
}
|
||||
|
||||
return anyTxData, nil
|
||||
@@ -54,12 +55,12 @@ func PackTxData(txData TxData) (*codectypes.Any, error) {
|
||||
// client state can't be unpacked into a TxData.
|
||||
func UnpackTxData(any *codectypes.Any) (TxData, error) {
|
||||
if any == nil {
|
||||
return nil, sdkerrors.Wrap(sdkerrors.ErrUnpackAny, "protobuf Any message cannot be nil")
|
||||
return nil, errorsmod.Wrap(errortypes.ErrUnpackAny, "protobuf Any message cannot be nil")
|
||||
}
|
||||
|
||||
txData, ok := any.GetCachedValue().(TxData)
|
||||
if !ok {
|
||||
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnpackAny, "cannot unpack Any into TxData %T", any)
|
||||
return nil, errorsmod.Wrapf(errortypes.ErrUnpackAny, "cannot unpack Any into TxData %T", any)
|
||||
}
|
||||
|
||||
return txData, nil
|
||||
|
||||
@@ -3,8 +3,9 @@ package types
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
sdkmath "cosmossdk.io/math"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||
@@ -195,58 +196,58 @@ func (tx *DynamicFeeTx) SetSignatureValues(chainID, v, r, s *big.Int) {
|
||||
// Validate performs a stateless validation of the tx fields.
|
||||
func (tx DynamicFeeTx) Validate() error {
|
||||
if tx.GasTipCap == nil {
|
||||
return sdkerrors.Wrap(ErrInvalidGasCap, "gas tip cap cannot nil")
|
||||
return errorsmod.Wrap(ErrInvalidGasCap, "gas tip cap cannot nil")
|
||||
}
|
||||
|
||||
if tx.GasFeeCap == nil {
|
||||
return sdkerrors.Wrap(ErrInvalidGasCap, "gas fee cap cannot nil")
|
||||
return errorsmod.Wrap(ErrInvalidGasCap, "gas fee cap cannot nil")
|
||||
}
|
||||
|
||||
if tx.GasTipCap.IsNegative() {
|
||||
return sdkerrors.Wrapf(ErrInvalidGasCap, "gas tip cap cannot be negative %s", tx.GasTipCap)
|
||||
return errorsmod.Wrapf(ErrInvalidGasCap, "gas tip cap cannot be negative %s", tx.GasTipCap)
|
||||
}
|
||||
|
||||
if tx.GasFeeCap.IsNegative() {
|
||||
return sdkerrors.Wrapf(ErrInvalidGasCap, "gas fee cap cannot be negative %s", tx.GasFeeCap)
|
||||
return errorsmod.Wrapf(ErrInvalidGasCap, "gas fee cap cannot be negative %s", tx.GasFeeCap)
|
||||
}
|
||||
|
||||
if !types.IsValidInt256(tx.GetGasTipCap()) {
|
||||
return sdkerrors.Wrap(ErrInvalidGasCap, "out of bound")
|
||||
return errorsmod.Wrap(ErrInvalidGasCap, "out of bound")
|
||||
}
|
||||
|
||||
if !types.IsValidInt256(tx.GetGasFeeCap()) {
|
||||
return sdkerrors.Wrap(ErrInvalidGasCap, "out of bound")
|
||||
return errorsmod.Wrap(ErrInvalidGasCap, "out of bound")
|
||||
}
|
||||
|
||||
if tx.GasFeeCap.LT(*tx.GasTipCap) {
|
||||
return sdkerrors.Wrapf(
|
||||
return errorsmod.Wrapf(
|
||||
ErrInvalidGasCap, "max priority fee per gas higher than max fee per gas (%s > %s)",
|
||||
tx.GasTipCap, tx.GasFeeCap,
|
||||
)
|
||||
}
|
||||
|
||||
if !types.IsValidInt256(tx.Fee()) {
|
||||
return sdkerrors.Wrap(ErrInvalidGasFee, "out of bound")
|
||||
return errorsmod.Wrap(ErrInvalidGasFee, "out of bound")
|
||||
}
|
||||
|
||||
amount := tx.GetValue()
|
||||
// Amount can be 0
|
||||
if amount != nil && amount.Sign() == -1 {
|
||||
return sdkerrors.Wrapf(ErrInvalidAmount, "amount cannot be negative %s", amount)
|
||||
return errorsmod.Wrapf(ErrInvalidAmount, "amount cannot be negative %s", amount)
|
||||
}
|
||||
if !types.IsValidInt256(amount) {
|
||||
return sdkerrors.Wrap(ErrInvalidAmount, "out of bound")
|
||||
return errorsmod.Wrap(ErrInvalidAmount, "out of bound")
|
||||
}
|
||||
|
||||
if tx.To != "" {
|
||||
if err := types.ValidateAddress(tx.To); err != nil {
|
||||
return sdkerrors.Wrap(err, "invalid to address")
|
||||
return errorsmod.Wrap(err, "invalid to address")
|
||||
}
|
||||
}
|
||||
|
||||
if tx.GetChainID() == nil {
|
||||
return sdkerrors.Wrap(
|
||||
sdkerrors.ErrInvalidChainID,
|
||||
return errorsmod.Wrap(
|
||||
errortypes.ErrInvalidChainID,
|
||||
"chain ID must be present on AccessList txs",
|
||||
)
|
||||
}
|
||||
|
||||
+22
-22
@@ -4,7 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts/abi"
|
||||
@@ -40,67 +40,67 @@ var ErrPostTxProcessing = errors.New("failed to execute post processing")
|
||||
|
||||
var (
|
||||
// ErrInvalidState returns an error resulting from an invalid Storage State.
|
||||
ErrInvalidState = sdkerrors.Register(ModuleName, codeErrInvalidState, "invalid storage state")
|
||||
ErrInvalidState = errorsmod.Register(ModuleName, codeErrInvalidState, "invalid storage state")
|
||||
|
||||
// ErrExecutionReverted returns an error resulting from an error in EVM execution.
|
||||
ErrExecutionReverted = sdkerrors.Register(ModuleName, codeErrExecutionReverted, vm.ErrExecutionReverted.Error())
|
||||
ErrExecutionReverted = errorsmod.Register(ModuleName, codeErrExecutionReverted, vm.ErrExecutionReverted.Error())
|
||||
|
||||
// ErrChainConfigNotFound returns an error if the chain config cannot be found on the store.
|
||||
ErrChainConfigNotFound = sdkerrors.Register(ModuleName, codeErrChainConfigNotFound, "chain configuration not found")
|
||||
ErrChainConfigNotFound = errorsmod.Register(ModuleName, codeErrChainConfigNotFound, "chain configuration not found")
|
||||
|
||||
// ErrInvalidChainConfig returns an error resulting from an invalid ChainConfig.
|
||||
ErrInvalidChainConfig = sdkerrors.Register(ModuleName, codeErrInvalidChainConfig, "invalid chain configuration")
|
||||
ErrInvalidChainConfig = errorsmod.Register(ModuleName, codeErrInvalidChainConfig, "invalid chain configuration")
|
||||
|
||||
// ErrZeroAddress returns an error resulting from an zero (empty) ethereum Address.
|
||||
ErrZeroAddress = sdkerrors.Register(ModuleName, codeErrZeroAddress, "invalid zero address")
|
||||
ErrZeroAddress = errorsmod.Register(ModuleName, codeErrZeroAddress, "invalid zero address")
|
||||
|
||||
// ErrEmptyHash returns an error resulting from an empty ethereum Hash.
|
||||
ErrEmptyHash = sdkerrors.Register(ModuleName, codeErrEmptyHash, "empty hash")
|
||||
ErrEmptyHash = errorsmod.Register(ModuleName, codeErrEmptyHash, "empty hash")
|
||||
|
||||
// ErrBloomNotFound returns an error if the block bloom cannot be found on the store.
|
||||
ErrBloomNotFound = sdkerrors.Register(ModuleName, codeErrBloomNotFound, "block bloom not found")
|
||||
ErrBloomNotFound = errorsmod.Register(ModuleName, codeErrBloomNotFound, "block bloom not found")
|
||||
|
||||
// ErrTxReceiptNotFound returns an error if the transaction receipt could not be found
|
||||
ErrTxReceiptNotFound = sdkerrors.Register(ModuleName, codeErrTxReceiptNotFound, "transaction receipt not found")
|
||||
ErrTxReceiptNotFound = errorsmod.Register(ModuleName, codeErrTxReceiptNotFound, "transaction receipt not found")
|
||||
|
||||
// ErrCreateDisabled returns an error if the EnableCreate parameter is false.
|
||||
ErrCreateDisabled = sdkerrors.Register(ModuleName, codeErrCreateDisabled, "EVM Create operation is disabled")
|
||||
ErrCreateDisabled = errorsmod.Register(ModuleName, codeErrCreateDisabled, "EVM Create operation is disabled")
|
||||
|
||||
// ErrCallDisabled returns an error if the EnableCall parameter is false.
|
||||
ErrCallDisabled = sdkerrors.Register(ModuleName, codeErrCallDisabled, "EVM Call operation is disabled")
|
||||
ErrCallDisabled = errorsmod.Register(ModuleName, codeErrCallDisabled, "EVM Call operation is disabled")
|
||||
|
||||
// ErrInvalidAmount returns an error if a tx contains an invalid amount.
|
||||
ErrInvalidAmount = sdkerrors.Register(ModuleName, codeErrInvalidAmount, "invalid transaction amount")
|
||||
ErrInvalidAmount = errorsmod.Register(ModuleName, codeErrInvalidAmount, "invalid transaction amount")
|
||||
|
||||
// ErrInvalidGasPrice returns an error if an invalid gas price is provided to the tx.
|
||||
ErrInvalidGasPrice = sdkerrors.Register(ModuleName, codeErrInvalidGasPrice, "invalid gas price")
|
||||
ErrInvalidGasPrice = errorsmod.Register(ModuleName, codeErrInvalidGasPrice, "invalid gas price")
|
||||
|
||||
// ErrInvalidGasFee returns an error if the tx gas fee is out of bound.
|
||||
ErrInvalidGasFee = sdkerrors.Register(ModuleName, codeErrInvalidGasFee, "invalid gas fee")
|
||||
ErrInvalidGasFee = errorsmod.Register(ModuleName, codeErrInvalidGasFee, "invalid gas fee")
|
||||
|
||||
// ErrVMExecution returns an error resulting from an error in EVM execution.
|
||||
ErrVMExecution = sdkerrors.Register(ModuleName, codeErrVMExecution, "evm transaction execution failed")
|
||||
ErrVMExecution = errorsmod.Register(ModuleName, codeErrVMExecution, "evm transaction execution failed")
|
||||
|
||||
// ErrInvalidRefund returns an error if a the gas refund value is invalid.
|
||||
ErrInvalidRefund = sdkerrors.Register(ModuleName, codeErrInvalidRefund, "invalid gas refund amount")
|
||||
ErrInvalidRefund = errorsmod.Register(ModuleName, codeErrInvalidRefund, "invalid gas refund amount")
|
||||
|
||||
// ErrInconsistentGas returns an error if a the gas differs from the expected one.
|
||||
ErrInconsistentGas = sdkerrors.Register(ModuleName, codeErrInconsistentGas, "inconsistent gas")
|
||||
ErrInconsistentGas = errorsmod.Register(ModuleName, codeErrInconsistentGas, "inconsistent gas")
|
||||
|
||||
// ErrInvalidGasCap returns an error if a the gas cap value is negative or invalid
|
||||
ErrInvalidGasCap = sdkerrors.Register(ModuleName, codeErrInvalidGasCap, "invalid gas cap")
|
||||
ErrInvalidGasCap = errorsmod.Register(ModuleName, codeErrInvalidGasCap, "invalid gas cap")
|
||||
|
||||
// ErrInvalidBaseFee returns an error if a the base fee cap value is invalid
|
||||
ErrInvalidBaseFee = sdkerrors.Register(ModuleName, codeErrInvalidBaseFee, "invalid base fee")
|
||||
ErrInvalidBaseFee = errorsmod.Register(ModuleName, codeErrInvalidBaseFee, "invalid base fee")
|
||||
|
||||
// ErrGasOverflow returns an error if gas computation overlow/underflow
|
||||
ErrGasOverflow = sdkerrors.Register(ModuleName, codeErrGasOverflow, "gas computation overflow/underflow")
|
||||
ErrGasOverflow = errorsmod.Register(ModuleName, codeErrGasOverflow, "gas computation overflow/underflow")
|
||||
|
||||
// ErrInvalidAccount returns an error if the account is not an EVM compatible account
|
||||
ErrInvalidAccount = sdkerrors.Register(ModuleName, codeErrInvalidAccount, "account type is not a valid ethereum account")
|
||||
ErrInvalidAccount = errorsmod.Register(ModuleName, codeErrInvalidAccount, "account type is not a valid ethereum account")
|
||||
|
||||
// ErrInvalidGasLimit returns an error if gas limit value is invalid
|
||||
ErrInvalidGasLimit = sdkerrors.Register(ModuleName, codeErrInvalidGasLimit, "invalid gas limit")
|
||||
ErrInvalidGasLimit = errorsmod.Register(ModuleName, codeErrInvalidGasLimit, "invalid gas limit")
|
||||
)
|
||||
|
||||
// NewExecErrorWithReason unpacks the revert return bytes and returns a wrapped error
|
||||
|
||||
@@ -3,7 +3,7 @@ package types
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/evmos/ethermint/types"
|
||||
@@ -160,31 +160,31 @@ func (tx *LegacyTx) SetSignatureValues(_, v, r, s *big.Int) {
|
||||
func (tx LegacyTx) Validate() error {
|
||||
gasPrice := tx.GetGasPrice()
|
||||
if gasPrice == nil {
|
||||
return sdkerrors.Wrap(ErrInvalidGasPrice, "gas price cannot be nil")
|
||||
return errorsmod.Wrap(ErrInvalidGasPrice, "gas price cannot be nil")
|
||||
}
|
||||
|
||||
if gasPrice.Sign() == -1 {
|
||||
return sdkerrors.Wrapf(ErrInvalidGasPrice, "gas price cannot be negative %s", gasPrice)
|
||||
return errorsmod.Wrapf(ErrInvalidGasPrice, "gas price cannot be negative %s", gasPrice)
|
||||
}
|
||||
if !types.IsValidInt256(gasPrice) {
|
||||
return sdkerrors.Wrap(ErrInvalidGasPrice, "out of bound")
|
||||
return errorsmod.Wrap(ErrInvalidGasPrice, "out of bound")
|
||||
}
|
||||
if !types.IsValidInt256(tx.Fee()) {
|
||||
return sdkerrors.Wrap(ErrInvalidGasFee, "out of bound")
|
||||
return errorsmod.Wrap(ErrInvalidGasFee, "out of bound")
|
||||
}
|
||||
|
||||
amount := tx.GetValue()
|
||||
// Amount can be 0
|
||||
if amount != nil && amount.Sign() == -1 {
|
||||
return sdkerrors.Wrapf(ErrInvalidAmount, "amount cannot be negative %s", amount)
|
||||
return errorsmod.Wrapf(ErrInvalidAmount, "amount cannot be negative %s", amount)
|
||||
}
|
||||
if !types.IsValidInt256(amount) {
|
||||
return sdkerrors.Wrap(ErrInvalidAmount, "out of bound")
|
||||
return errorsmod.Wrap(ErrInvalidAmount, "out of bound")
|
||||
}
|
||||
|
||||
if tx.To != "" {
|
||||
if err := types.ValidateAddress(tx.To); err != nil {
|
||||
return sdkerrors.Wrap(err, "invalid to address")
|
||||
return errorsmod.Wrap(err, "invalid to address")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
-6
@@ -7,11 +7,12 @@ import (
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
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/x/auth/ante"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/signing"
|
||||
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
|
||||
@@ -165,23 +166,23 @@ func (msg MsgEthereumTx) Type() string { return TypeMsgEthereumTx }
|
||||
func (msg MsgEthereumTx) ValidateBasic() error {
|
||||
if msg.From != "" {
|
||||
if err := types.ValidateAddress(msg.From); err != nil {
|
||||
return sdkerrors.Wrap(err, "invalid from address")
|
||||
return errorsmod.Wrap(err, "invalid from address")
|
||||
}
|
||||
}
|
||||
|
||||
// Validate Size_ field, should be kept empty
|
||||
if msg.Size_ != 0 {
|
||||
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "tx size is deprecated")
|
||||
return errorsmod.Wrapf(errortypes.ErrInvalidRequest, "tx size is deprecated")
|
||||
}
|
||||
|
||||
txData, err := UnpackTxData(msg.Data)
|
||||
if err != nil {
|
||||
return sdkerrors.Wrap(err, "failed to unpack tx data")
|
||||
return errorsmod.Wrap(err, "failed to unpack tx data")
|
||||
}
|
||||
|
||||
// prevent txs with 0 gas to fill up the mempool
|
||||
if txData.GetGas() == 0 {
|
||||
return sdkerrors.Wrap(ErrInvalidGasLimit, "gas limit must not be zero")
|
||||
return errorsmod.Wrap(ErrInvalidGasLimit, "gas limit must not be zero")
|
||||
}
|
||||
|
||||
if err := txData.Validate(); err != nil {
|
||||
@@ -191,7 +192,7 @@ func (msg MsgEthereumTx) ValidateBasic() error {
|
||||
// Validate Hash field after validated txData to avoid panic
|
||||
txHash := msg.AsTransaction().Hash().Hex()
|
||||
if msg.Hash != txHash {
|
||||
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid tx hash %s, expected: %s", msg.Hash, txHash)
|
||||
return errorsmod.Wrapf(errortypes.ErrInvalidRequest, "invalid tx hash %s, expected: %s", msg.Hash, txHash)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
@@ -17,7 +17,7 @@ func (s Storage) Validate() error {
|
||||
seenStorage := make(map[string]bool)
|
||||
for i, state := range s {
|
||||
if seenStorage[state.Key] {
|
||||
return sdkerrors.Wrapf(ErrInvalidState, "duplicate state key %d: %s", i, state.Key)
|
||||
return errorsmod.Wrapf(ErrInvalidState, "duplicate state key %d: %s", i, state.Key)
|
||||
}
|
||||
|
||||
if err := state.Validate(); err != nil {
|
||||
@@ -51,7 +51,7 @@ func (s Storage) Copy() Storage {
|
||||
// NOTE: state value can be empty
|
||||
func (s State) Validate() error {
|
||||
if strings.TrimSpace(s.Key) == "" {
|
||||
return sdkerrors.Wrap(ErrInvalidState, "state key hash cannot be blank")
|
||||
return errorsmod.Wrap(ErrInvalidState, "state key hash cannot be blank")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/math"
|
||||
@@ -34,7 +34,7 @@ func DecodeTxResponse(in []byte) (*MsgEthereumTxResponse, error) {
|
||||
|
||||
var res MsgEthereumTxResponse
|
||||
if err := proto.Unmarshal(txMsgData.MsgResponses[0].Value, &res); err != nil {
|
||||
return nil, sdkerrors.Wrap(err, "failed to unmarshal tx response message data")
|
||||
return nil, errorsmod.Wrap(err, "failed to unmarshal tx response message data")
|
||||
}
|
||||
|
||||
return &res, nil
|
||||
|
||||
Reference in New Issue
Block a user