Skip to content

Commit

Permalink
wip: update ante handler
Browse files Browse the repository at this point in the history
  • Loading branch information
boodyvo committed Oct 31, 2024
1 parent 6a2ba62 commit 499be6a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/ante/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,18 @@ func (vbd EthValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu
return next(ctx, tx, simulate)
}

fmt.Println("EthValidateBasicDecorator.AnteHandle", tx)
fmt.Println("EthValidateBasicDecorator.AnteHandle start")
for _, msg := range tx.GetMsgs() {
fmt.Println("EthValidateBasicDecorator.AnteHandle", msg.String())
}

//sigetheriumTx, ok := tx.(*evmtypes.MsgEthereumTx)
sigetheriumTx, ok := tx.(sdk.HasValidateBasic)
if ok {
fmt.Println("going to validate basic")
err := sigetheriumTx.ValidateBasic()
// ErrNoSignatures is fine with eth tx
fmt.Println("validation error is ", err)
if err != nil && !errors.Is(err, errortypes.ErrNoSignatures) {
return ctx, errorsmod.Wrap(err, "tx basic validation failed")
}
Expand All @@ -132,12 +134,15 @@ func (vbd EthValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu
// 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)
fmt.Println("wrapperTx", wrapperTx, ok)
if !ok {
return ctx, errorsmod.Wrapf(errortypes.ErrUnknownRequest, "invalid tx type %T, didn't implement interface protoTxProvider", tx)
}

protoTx := wrapperTx.GetProtoTx()
body := protoTx.Body
fmt.Println("protoTx", protoTx)
fmt.Println("body", body)
if body.Memo != "" || body.TimeoutHeight != uint64(0) || len(body.NonCriticalExtensionOptions) > 0 {
return ctx, errorsmod.Wrap(errortypes.ErrInvalidRequest,
"for eth tx body Memo TimeoutHeight NonCriticalExtensionOptions should be empty")
Expand Down Expand Up @@ -174,6 +179,7 @@ func (vbd EthValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu
evmDenom := evmParams.GetEvmDenom()

for _, msg := range protoTx.GetMsgs() {
fmt.Println("eth msg", msg)
msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx)
if !ok {
return ctx, errorsmod.Wrapf(errortypes.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil))
Expand Down Expand Up @@ -213,5 +219,7 @@ func (vbd EthValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu
return ctx, errorsmod.Wrapf(errortypes.ErrInvalidRequest, "invalid AuthInfo Fee GasLimit (%d != %d)", authInfo.Fee.GasLimit, txGasLimit)
}

fmt.Println("going to call next for eth ante")

return next(ctx, tx, simulate)
}
5 changes: 5 additions & 0 deletions encoding/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"github.com/cosmos/gogoproto/proto"
enccodec "github.com/evmos/ethermint/encoding/codec"
"github.com/evmos/ethermint/simapp/params"
evmtypes "github.com/evmos/ethermint/x/evm/types"
"google.golang.org/protobuf/reflect/protoreflect"
)

// MakeConfig creates an EncodingConfig for testing
Expand All @@ -38,6 +40,9 @@ func MakeConfig() params.EncodingConfig {
ValidatorAddressCodec: address.Bech32Codec{
Bech32Prefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(),
},
CustomGetSigners: map[protoreflect.FullName]signing.GetSignersFunc{
evmtypes.MsgEthereumTxGetSigner.MsgType: evmtypes.MsgEthereumTxGetSigner.Fn,
},
}
interfaceRegistry, err := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{
ProtoFiles: proto.HybridResolver,
Expand Down
17 changes: 17 additions & 0 deletions x/evm/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
package types

import (
txsigning "cosmossdk.io/x/tx/signing"
"errors"
"fmt"
signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing"
"google.golang.org/protobuf/reflect/protoreflect"
"math/big"

sdkmath "cosmossdk.io/math"
Expand All @@ -33,6 +35,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/signing"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
"github.com/evmos/ethermint/types"
protov1 "github.com/golang/protobuf/proto" //nolint:staticcheck
protov2 "google.golang.org/protobuf/proto"

"github.com/ethereum/go-ethereum/common"
Expand All @@ -55,6 +58,12 @@ const (
TypeMsgEthereumTx = "ethereum_tx"
)

var MsgEthereumTxGetSigner = txsigning.CustomGetSigner{
MsgType: protoreflect.FullName(protov1.MessageName(&MsgEthereumTx{})),
// func(proto.Message) ([][]byte, error)
Fn: GetSigners,
}

// NewTx returns a reference to a new Ethereum transaction message.
func NewTx(
chainID *big.Int, nonce uint64, to *common.Address, amount *big.Int,
Expand Down Expand Up @@ -244,6 +253,14 @@ func (msg *MsgEthereumTx) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{signer}
}

// func(proto.Message) ([][]byte, error)
func GetSigners(msg protov2.Message) ([][]byte, error) {
fmt.Println("Test Eth Get signers is invoked")
fmt.Println("Eth message type", msg.ProtoReflect().Type())

return nil, nil
}

// GetSignBytes returns the Amino bytes of an Ethereum transaction message used
// for signing.
//
Expand Down

0 comments on commit 499be6a

Please sign in to comment.