Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imp(ante): depecrate legacy EIP712 ante handler #2078

Merged
merged 4 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### API Breaking

- (inflation) [#2015](https://github.com/evmos/evmos/pull/2015) Rename `inflation` module to `inflation/v1`.
- (ante) [#2078](https://github.com/evmos/evmos/pull/2078) depecrate legacy EIP712 ante handler

### Features

Expand Down
5 changes: 1 addition & 4 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
switch typeURL := opts[0].GetTypeUrl(); typeURL {
case "/ethermint.evm.v1.ExtensionOptionsEthereumTx":
// handle as *evmtypes.MsgEthereumTx
anteHandler = newMonoEVMAnteHandler(options) // TODO: replace for mono EVM AnteHandler
case "/ethermint.types.v1.ExtensionOptionsWeb3Tx":
// handle as normal Cosmos SDK tx, except signature is checked for EIP712 representation
anteHandler = newLegacyCosmosAnteHandlerEip712(options)
anteHandler = newMonoEVMAnteHandler(options)

Check warning on line 29 in app/ante/ante.go

View check run for this annotation

Codecov / codecov/patch

app/ante/ante.go#L29

Added line #L29 was not covered by tests
case "/ethermint.types.v1.ExtensionOptionDynamicFeeTx":
// cosmos-sdk tx with dynamic fee extension
anteHandler = newCosmosAnteHandler(options)
Expand Down
1 change: 0 additions & 1 deletion app/ante/cosmos/authz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,6 @@ func (suite *AnteTestSuite) TestRejectMsgsInAuthz() {
suite.app,
utiltx.EIP712TxArgs{
CosmosTxArgs: cosmosTxArgs,
UseLegacyExtension: true,
UseLegacyTypedData: true,
},
)
Expand Down
34 changes: 0 additions & 34 deletions app/ante/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ package ante

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
sdkvesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
cosmosante "github.com/evmos/evmos/v15/app/ante/cosmos"
evmante "github.com/evmos/evmos/v15/app/ante/evm"
evmtypes "github.com/evmos/evmos/v15/x/evm/types"
)

func newMonoEVMAnteHandler(options HandlerOptions) sdk.AnteHandler {
Expand Down Expand Up @@ -48,32 +43,3 @@ func newEVMAnteHandler(options HandlerOptions) sdk.AnteHandler { //nolint: unuse
evmante.NewEthEmitEventDecorator(options.EvmKeeper),
)
}

// newCosmosAnteHandlerEip712 creates the ante handler for transactions signed with EIP712
func newLegacyCosmosAnteHandlerEip712(options HandlerOptions) sdk.AnteHandler {
return sdk.ChainAnteDecorators(
cosmosante.RejectMessagesDecorator{}, // reject MsgEthereumTxs
cosmosante.NewAuthzLimiterDecorator( // disable the Msg types that cannot be included on an authz.MsgExec msgs field
sdk.MsgTypeURL(&evmtypes.MsgEthereumTx{}),
sdk.MsgTypeURL(&sdkvesting.MsgCreateVestingAccount{}),
),
ante.NewSetUpContextDecorator(),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
cosmosante.NewMinGasPriceDecorator(options.FeeMarketKeeper, options.EvmKeeper),
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
cosmosante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.DistributionKeeper, options.FeegrantKeeper, options.StakingKeeper, options.TxFeeChecker),
cosmosante.NewVestingDelegationDecorator(options.AccountKeeper, options.StakingKeeper, options.BankKeeper, options.Cdc),
// SetPubKeyDecorator must be called before all signature verification decorators
ante.NewSetPubKeyDecorator(options.AccountKeeper),
ante.NewValidateSigCountDecorator(options.AccountKeeper),
ante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer),
// Note: signature verification uses EIP instead of the cosmos signature validator
//nolint: staticcheck
cosmosante.NewLegacyEip712SigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
evmante.NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper),
)
}
3 changes: 0 additions & 3 deletions app/ante/evm/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ type AnteTestSuite struct {
enableFeemarket bool
enableLondonHF bool
evmParamsOption func(*evmtypes.Params)
useLegacyEIP712Extension bool
useLegacyEIP712TypedData bool
}

Expand Down Expand Up @@ -123,13 +122,11 @@ func TestAnteTestSuite(t *testing.T) {
// LegacyEIP712Extension should not be run with current TypedData encodings, since they are not compatible.
suite.Run(t, &AnteTestSuite{
enableLondonHF: true,
useLegacyEIP712Extension: true,
useLegacyEIP712TypedData: true,
})

suite.Run(t, &AnteTestSuite{
enableLondonHF: true,
useLegacyEIP712Extension: false,
useLegacyEIP712TypedData: true,
})
}
1 change: 0 additions & 1 deletion app/ante/evm/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,6 @@ func (suite *AnteTestSuite) CreateTestEIP712CosmosTxBuilder(
suite.app,
utiltx.EIP712TxArgs{
CosmosTxArgs: cosmosTxArgs,
UseLegacyExtension: suite.useLegacyEIP712Extension,
UseLegacyTypedData: suite.useLegacyEIP712TypedData,
},
)
Expand Down
50 changes: 1 addition & 49 deletions testutil/tx/eip712.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

type EIP712TxArgs struct {
CosmosTxArgs CosmosTxArgs
UseLegacyExtension bool
UseLegacyTypedData bool
}

Expand All @@ -41,12 +40,6 @@ type signatureV2Args struct {
nonce uint64
}

type legacyWeb3ExtensionArgs struct {
feePayer string
chainID uint64
signature []byte
}

// CreateEIP712CosmosTx creates a cosmos tx for typed data according to EIP712.
// Also, signs the tx with the provided messages and private key.
// It returns the signed transaction and an error
Expand Down Expand Up @@ -122,7 +115,6 @@ func PrepareEIP712CosmosTx(
appEvmos,
args,
builder,
chainIDNum,
typedData,
)
}
Expand All @@ -134,7 +126,6 @@ func signCosmosEIP712Tx(
appEvmos *app.Evmos,
args EIP712TxArgs,
builder authtx.ExtensionOptionsTxBuilder,
chainID uint64,
data apitypes.TypedData,
) (client.TxBuilder, error) {
priv := args.CosmosTxArgs.Priv
Expand All @@ -157,25 +148,12 @@ func signCosmosEIP712Tx(
}
signature[crypto.RecoveryIDOffset] += 27 // Transform V from 0/1 to 27/28 according to the yellow paper

if args.UseLegacyExtension {
if err := setBuilderLegacyWeb3Extension(
builder,
legacyWeb3ExtensionArgs{
feePayer: from.String(),
chainID: chainID,
signature: signature,
}); err != nil {
return nil, err
}
}

sigsV2 := getTxSignatureV2(
signatureV2Args{
pubKey: pubKey,
signature: signature,
nonce: nonce,
},
args.UseLegacyExtension,
)

err = builder.SetSignatures(sigsV2)
Expand Down Expand Up @@ -211,35 +189,9 @@ func createTypedData(args typedDataArgs, useLegacy bool) (apitypes.TypedData, er
return eip712.WrapTxToTypedData(args.chainID, args.data)
}

// setBuilderLegacyWeb3Extension creates a legacy ExtensionOptionsWeb3Tx and
// appends it to the builder options.
func setBuilderLegacyWeb3Extension(builder authtx.ExtensionOptionsTxBuilder, args legacyWeb3ExtensionArgs) error {
option, err := codectypes.NewAnyWithValue(&types.ExtensionOptionsWeb3Tx{
FeePayer: args.feePayer,
TypedDataChainID: args.chainID,
FeePayerSig: args.signature,
})
if err != nil {
return err
}

builder.SetExtensionOptions(option)
return nil
}

// getTxSignatureV2 returns the SignatureV2 object corresponding to
// the arguments, using the legacy implementation as needed.
func getTxSignatureV2(args signatureV2Args, useLegacyExtension bool) signing.SignatureV2 {
if useLegacyExtension {
return signing.SignatureV2{
PubKey: args.pubKey,
Data: &signing.SingleSignatureData{
SignMode: signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON,
},
Sequence: args.nonce,
}
}

func getTxSignatureV2(args signatureV2Args) signing.SignatureV2 {
// Must use SIGN_MODE_DIRECT, since Amino has some trouble parsing certain Any values from a SignDoc
// with the Legacy EIP-712 TypedData encodings. This is not an issue with the latest encoding.
return signing.SignatureV2{
Expand Down