This repository has been archived by the owner on Apr 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 563
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
174 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package ante | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "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" | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
|
||
channelkeeper "github.com/cosmos/ibc-go/v2/modules/core/04-channel/keeper" | ||
ibcante "github.com/cosmos/ibc-go/v2/modules/core/ante" | ||
|
||
evmtypes "github.com/tharsis/ethermint/x/evm/types" | ||
) | ||
|
||
// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC | ||
// channel keeper, EVM Keeper and Fee Market Keeper. | ||
type HandlerOptions struct { | ||
AccountKeeper evmtypes.AccountKeeper | ||
BankKeeper evmtypes.BankKeeper | ||
IBCChannelKeeper channelkeeper.Keeper | ||
FeeMarketKeeper evmtypes.FeeMarketKeeper | ||
EvmKeeper EVMKeeper | ||
FeegrantKeeper ante.FeegrantKeeper | ||
SignModeHandler authsigning.SignModeHandler | ||
SigGasConsumer func(meter sdk.GasMeter, sig signing.SignatureV2, params authtypes.Params) error | ||
} | ||
|
||
func (options HandlerOptions) Validate() error { | ||
if options.AccountKeeper == nil { | ||
return sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler") | ||
} | ||
if options.BankKeeper == nil { | ||
return sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler") | ||
} | ||
if options.SignModeHandler == nil { | ||
return sdkerrors.Wrap(sdkerrors.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") | ||
} | ||
if options.EvmKeeper == nil { | ||
return sdkerrors.Wrap(sdkerrors.ErrLogic, "evm keeper is required for AnteHandler") | ||
} | ||
return nil | ||
} | ||
|
||
func newEthAnteHandler(options HandlerOptions) sdk.AnteHandler { | ||
return sdk.ChainAnteDecorators( | ||
NewEthSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first | ||
NewEthMempoolFeeDecorator(options.EvmKeeper, options.FeeMarketKeeper), // Check eth effective gas price against minimal-gas-prices | ||
NewEthValidateBasicDecorator(options.EvmKeeper), | ||
NewEthSigVerificationDecorator(options.EvmKeeper), | ||
NewEthAccountVerificationDecorator(options.AccountKeeper, options.BankKeeper, options.EvmKeeper), | ||
NewEthNonceVerificationDecorator(options.AccountKeeper), | ||
NewEthGasConsumeDecorator(options.EvmKeeper), | ||
NewCanTransferDecorator(options.EvmKeeper, options.FeeMarketKeeper), | ||
NewEthIncrementSenderSequenceDecorator(options.AccountKeeper), // innermost AnteDecorator. | ||
) | ||
} | ||
|
||
func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler { | ||
return sdk.ChainAnteDecorators( | ||
RejectMessagesDecorator{}, // reject MsgEthereumTxs | ||
ante.NewSetUpContextDecorator(), | ||
ante.NewRejectExtensionOptionsDecorator(), | ||
ante.NewMempoolFeeDecorator(), | ||
ante.NewValidateBasicDecorator(), | ||
ante.NewTxTimeoutHeightDecorator(), | ||
ante.NewValidateMemoDecorator(options.AccountKeeper), | ||
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper), | ||
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper), | ||
// SetPubKeyDecorator must be called before all signature verification decorators | ||
ante.NewSetPubKeyDecorator(options.AccountKeeper), | ||
ante.NewValidateSigCountDecorator(options.AccountKeeper), | ||
ante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer), | ||
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler), | ||
ante.NewIncrementSequenceDecorator(options.AccountKeeper), | ||
ibcante.NewAnteDecorator(options.IBCChannelKeeper), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package ante | ||
|
||
import ( | ||
"math/big" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
tx "github.com/cosmos/cosmos-sdk/types/tx" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core" | ||
"github.com/ethereum/go-ethereum/core/vm" | ||
"github.com/ethereum/go-ethereum/params" | ||
evmtypes "github.com/tharsis/ethermint/x/evm/types" | ||
) | ||
|
||
// EVMKeeper defines the expected keeper interface used on the Eth AnteHandler | ||
type EVMKeeper interface { | ||
vm.StateDB | ||
|
||
ChainID() *big.Int | ||
GetParams(ctx sdk.Context) evmtypes.Params | ||
WithContext(ctx sdk.Context) | ||
ResetRefundTransient(ctx sdk.Context) | ||
NewEVM(msg core.Message, cfg *evmtypes.EVMConfig, tracer vm.Tracer) *vm.EVM | ||
GetCodeHash(addr common.Address) common.Hash | ||
DeductTxCostsFromUserBalance( | ||
ctx sdk.Context, msgEthTx evmtypes.MsgEthereumTx, txData evmtypes.TxData, denom string, homestead, istanbul, london bool, | ||
) (sdk.Coins, error) | ||
BaseFee(ctx sdk.Context, ethCfg *params.ChainConfig) *big.Int | ||
} | ||
|
||
type protoTxProvider interface { | ||
GetProtoTx() *tx.Tx | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package ante | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
evmtypes "github.com/tharsis/ethermint/x/evm/types" | ||
) | ||
|
||
// RejectMessagesDecorator prevents invalid msg types from being executed | ||
type RejectMessagesDecorator struct{} | ||
|
||
// AnteHandle rejects messages that requires ethereum-specific authentication. | ||
// For example `MsgEthereumTx` requires fee to be deducted in the antehandler in | ||
// order to perform the refund. | ||
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, | ||
"MsgEthereumTx needs to be contained within a tx with 'ExtensionOptionsEthereumTx' option", | ||
) | ||
} | ||
} | ||
return next(ctx, tx, simulate) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters