From db53c1d435f753fa396dc70b0f5ee36abb82218b Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Wed, 12 Apr 2023 09:46:51 -0500 Subject: [PATCH 01/52] Hard break client.TxConfig --- client/tx_config.go | 3 ++- go.mod | 1 + go.sum | 2 -- x/auth/tx/config.go | 19 +++++++++++-------- x/auth/tx/mode_handler.go | 7 ++++++- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/client/tx_config.go b/client/tx_config.go index 5c5fd2695e40..f864b907e83b 100644 --- a/client/tx_config.go +++ b/client/tx_config.go @@ -1,6 +1,7 @@ package client import ( + txsigning "cosmossdk.io/x/tx/signing" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/tx" signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" @@ -27,7 +28,7 @@ type ( NewTxBuilder() TxBuilder WrapTxBuilder(sdk.Tx) (TxBuilder, error) - SignModeHandler() signing.SignModeHandler + SignModeHandler() txsigning.SignModeHandler } // TxBuilder defines an interface which an application-defined concrete transaction diff --git a/go.mod b/go.mod index 3d278dae0a1a..bf5a9eacde5e 100644 --- a/go.mod +++ b/go.mod @@ -161,6 +161,7 @@ require ( // Below are the long-lived replace of the Cosmos SDK replace ( + cosmossdk.io/x/tx => ./x/tx // use cosmos fork of keyring github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 // dgrijalva/jwt-go is deprecated and doesn't receive security updates. diff --git a/go.sum b/go.sum index 992a527fec0e..e17be66f6829 100644 --- a/go.sum +++ b/go.sum @@ -51,8 +51,6 @@ cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw= cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc h1:9piuA+NYmhe+SyMPtMoboLw/djgDbrI3dD5TG020Tnk= cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc/go.mod h1:UFF5rmjN7WYVfxo6ArdY/l1+yyWMURBWOmSJypGqFHQ= -cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63 h1:zHqj2VwZ/MStFmR7SUe/7gErOFhL9v2rkjmWPB/st34= -cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/x/auth/tx/config.go b/x/auth/tx/config.go index 5cb00e96907d..bbc7c20e4552 100644 --- a/x/auth/tx/config.go +++ b/x/auth/tx/config.go @@ -3,17 +3,17 @@ package tx import ( "fmt" + txsigning "cosmossdk.io/x/tx/signing" "cosmossdk.io/x/tx/signing/textual" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" - "github.com/cosmos/cosmos-sdk/x/auth/signing" ) type config struct { - handler signing.SignModeHandler + handler txsigning.SignModeHandler decoder sdk.TxDecoder encoder sdk.TxEncoder jsonDecoder sdk.TxDecoder @@ -27,25 +27,28 @@ type config struct { // NOTE: Use NewTxConfigWithHandler to provide a custom signing handler in case the sign mode // is not supported by default (eg: SignMode_SIGN_MODE_EIP_191). Use NewTxConfigWithTextual // to enable SIGN_MODE_TEXTUAL (for testing purposes for now). -func NewTxConfig(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signingtypes.SignMode, customSignModes ...signing.SignModeHandler) client.TxConfig { +func NewTxConfig(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signingtypes.SignMode, + customSignModes ...txsigning.SignModeHandler) client.TxConfig { for _, m := range enabledSignModes { if m == signingtypes.SignMode_SIGN_MODE_TEXTUAL { panic("cannot use NewTxConfig with SIGN_MODE_TEXTUAL enabled; please use NewTxConfigWithTextual") } } - return NewTxConfigWithHandler(protoCodec, makeSignModeHandler(enabledSignModes, &textual.SignModeHandler{}, customSignModes...)) + return NewTxConfigWithHandler(protoCodec, makeSignModeHandler(enabledSignModes, &textual.SignModeHandler{}, + customSignModes...)) } // NewTxConfigWithTextual is like NewTxConfig with the ability to add // a SIGN_MODE_TEXTUAL renderer. It is currently still EXPERIMENTAL, for should // be used for TESTING purposes only, until Textual is fully released. -func NewTxConfigWithTextual(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signingtypes.SignMode, textual *textual.SignModeHandler, customSignModes ...signing.SignModeHandler) client.TxConfig { +func NewTxConfigWithTextual(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signingtypes.SignMode, + textual *textual.SignModeHandler, customSignModes ...txsigning.SignModeHandler) client.TxConfig { return NewTxConfigWithHandler(protoCodec, makeSignModeHandler(enabledSignModes, textual, customSignModes...)) } -// NewTxConfig returns a new protobuf TxConfig using the provided ProtoCodec and signing handler. -func NewTxConfigWithHandler(protoCodec codec.ProtoCodecMarshaler, handler signing.SignModeHandler) client.TxConfig { +// NewTxConfigWithHandler returns a new protobuf TxConfig using the provided ProtoCodec and signing handler. +func NewTxConfigWithHandler(protoCodec codec.ProtoCodecMarshaler, handler txsigning.SignModeHandler) client.TxConfig { return &config{ handler: handler, decoder: DefaultTxDecoder(protoCodec), @@ -70,7 +73,7 @@ func (g config) WrapTxBuilder(newTx sdk.Tx) (client.TxBuilder, error) { return newBuilder, nil } -func (g config) SignModeHandler() signing.SignModeHandler { +func (g config) SignModeHandler() txsigning.SignModeHandler { return g.handler } diff --git a/x/auth/tx/mode_handler.go b/x/auth/tx/mode_handler.go index 25a2612b49b7..098da8ff2901 100644 --- a/x/auth/tx/mode_handler.go +++ b/x/auth/tx/mode_handler.go @@ -3,6 +3,7 @@ package tx import ( "fmt" + txsigning "cosmossdk.io/x/tx/signing" "cosmossdk.io/x/tx/signing/textual" signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" @@ -24,7 +25,11 @@ var DefaultSignModes = []signingtypes.SignMode{ // makeSignModeHandler returns the default protobuf SignModeHandler supporting // SIGN_MODE_DIRECT, SIGN_MODE_DIRECT_AUX and SIGN_MODE_LEGACY_AMINO_JSON. -func makeSignModeHandler(modes []signingtypes.SignMode, txt *textual.SignModeHandler, customSignModes ...signing.SignModeHandler) signing.SignModeHandler { +func makeSignModeHandler( + modes []signingtypes.SignMode, + txt *textual.SignModeHandler, + customSignModes ...txsigning.SignModeHandler, +) txsigning.SignModeHandler { if len(modes) < 1 { panic(fmt.Errorf("no sign modes enabled")) } From 0019cb97c0ab70e61a2ad59888899c14c5381d69 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Wed, 12 Apr 2023 09:52:35 -0500 Subject: [PATCH 02/52] incorporate changes from #15713 --- x/auth/ante/ante.go | 4 +-- x/auth/ante/sigverify.go | 48 ++++++++++++++++++++++++++-------- x/auth/signing/verify.go | 39 +++++++++++++++++++++++++++ x/tx/signing/aminojson/time.go | 2 +- 4 files changed, 79 insertions(+), 14 deletions(-) diff --git a/x/auth/ante/ante.go b/x/auth/ante/ante.go index f3b4ebb6a1bf..2351f4601165 100644 --- a/x/auth/ante/ante.go +++ b/x/auth/ante/ante.go @@ -2,13 +2,13 @@ package ante import ( storetypes "cosmossdk.io/store/types" + txsigning "cosmossdk.io/x/tx/signing" errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/tx/signing" - authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" "github.com/cosmos/cosmos-sdk/x/auth/types" ) @@ -18,7 +18,7 @@ type HandlerOptions struct { BankKeeper types.BankKeeper ExtensionOptionChecker ExtensionOptionChecker FeegrantKeeper FeegrantKeeper - SignModeHandler authsigning.SignModeHandler + SignModeHandler txsigning.SignModeHandler SigGasConsumer func(meter storetypes.GasMeter, sig signing.SignatureV2, params types.Params) error TxFeeChecker TxFeeChecker } diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index 422dde1f9978..5776be75013c 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -6,8 +6,13 @@ import ( "encoding/hex" "fmt" + "google.golang.org/protobuf/types/known/anypb" + errorsmod "cosmossdk.io/errors" storetypes "cosmossdk.io/store/types" + "cosmossdk.io/x/tx/decode" + txsigning "cosmossdk.io/x/tx/signing" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" @@ -194,17 +199,17 @@ func (sgcd SigGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula return next(ctx, tx, simulate) } -// Verify all signatures for a tx and return an error if any are invalid. Note, +// SigVerificationDecorator verifies all signatures for a tx and return an error if any are invalid. Note, // the SigVerificationDecorator will not check signatures on ReCheck. // // CONTRACT: Pubkeys are set in context for all signers before this decorator runs // CONTRACT: Tx must implement SigVerifiableTx interface type SigVerificationDecorator struct { ak AccountKeeper - signModeHandler authsigning.SignModeHandler + signModeHandler txsigning.SignModeHandler } -func NewSigVerificationDecorator(ak AccountKeeper, signModeHandler authsigning.SignModeHandler) SigVerificationDecorator { +func NewSigVerificationDecorator(ak AccountKeeper, signModeHandler txsigning.SignModeHandler) SigVerificationDecorator { return SigVerificationDecorator{ ak: ak, signModeHandler: signModeHandler, @@ -279,17 +284,38 @@ func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul if !genesis { accNum = acc.GetAccountNumber() } - signerData := authsigning.SignerData{ - Address: acc.GetAddress().String(), - ChainID: chainID, - AccountNumber: accNum, - Sequence: acc.GetSequence(), - PubKey: pubKey, - } // no need to verify signatures on recheck tx if !simulate && !ctx.IsReCheckTx() { - err := authsigning.VerifySignature(ctx, pubKey, signerData, sig.Data, svd.signModeHandler, tx) + anyPk, _ := codectypes.NewAnyWithValue(pubKey) + + signerData := txsigning.SignerData{ + Address: acc.GetAddress().String(), + ChainID: chainID, + AccountNumber: accNum, + Sequence: acc.GetSequence(), + PubKey: &anypb.Any{ + TypeUrl: anyPk.TypeUrl, + Value: anyPk.Value, + }, + } + decodeCtx, err := decode.NewDecoder(decode.Options{}) + if err != nil { + return ctx, err + } + // note: this is performance hit is temporary. Ultimately, the tx will be decoded once in BaseApp, + // but for now we need double decoding to support both SignModeHandlers. + decodedTx, err := decodeCtx.Decode(ctx.TxBytes()) + if err != nil { + return ctx, err + } + txData := txsigning.TxData{ + Body: decodedTx.Tx.Body, + AuthInfo: decodedTx.Tx.AuthInfo, + AuthInfoBytes: decodedTx.TxRaw.AuthInfoBytes, + BodyBytes: decodedTx.TxRaw.BodyBytes, + } + err = authsigning.VerifySignatureV2(ctx, pubKey, signerData, sig.Data, svd.signModeHandler, txData) if err != nil { var errMsg string if OnlyLegacyAminoSigners(sig.Data) { diff --git a/x/auth/signing/verify.go b/x/auth/signing/verify.go index 3ed7df854623..a0d636654cc7 100644 --- a/x/auth/signing/verify.go +++ b/x/auth/signing/verify.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + txsigning "cosmossdk.io/x/tx/signing" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/crypto/types/multisig" sdk "github.com/cosmos/cosmos-sdk/types" @@ -45,6 +46,44 @@ func VerifySignature(ctx context.Context, pubKey cryptotypes.PubKey, signerData } } +// VerifySignatureV2 verifies a transaction signature contained in SignatureData abstracting over different signing +// modes. It differs from VerifySignature in that it uses the new txsigning.TxData interface in x/tx. +func VerifySignatureV2( + ctx context.Context, + pubKey cryptotypes.PubKey, + signerData txsigning.SignerData, + signatureData signing.SignatureData, + handler txsigning.SignModeHandler, + txData txsigning.TxData, +) error { + switch data := signatureData.(type) { + case *signing.SingleSignatureData: + signBytes, err := handler.GetSignBytes(ctx, signerData, txData) + if err != nil { + return err + } + if !pubKey.VerifySignature(signBytes, data.Signature) { + return fmt.Errorf("unable to verify single signer signature") + } + return nil + + case *signing.MultiSignatureData: + multiPK, ok := pubKey.(multisig.PubKey) + if !ok { + return fmt.Errorf("expected %T, got %T", (multisig.PubKey)(nil), pubKey) + } + err := multiPK.VerifyMultisignature(func(mode signing.SignMode) ([]byte, error) { + return handler.GetSignBytes(ctx, signerData, txData) + }, data) + if err != nil { + return err + } + return nil + default: + return fmt.Errorf("unexpected SignatureData %T", signatureData) + } +} + // GetSignBytesWithContext gets the sign bytes from the sign mode handler. It // checks if the sign mode handler supports SignModeHandlerWithContext, in // which case it passes the context.Context argument. Otherwise, it fallbacks diff --git a/x/tx/signing/aminojson/time.go b/x/tx/signing/aminojson/time.go index aa0ca9c84f5c..da02514c0255 100644 --- a/x/tx/signing/aminojson/time.go +++ b/x/tx/signing/aminojson/time.go @@ -46,7 +46,7 @@ func marshalTimestamp(message protoreflect.Message, writer io.Writer) error { // MaxDurationSeconds the maximum number of seconds (when expressed as nanoseconds) which can fit in an int64. // gogoproto encodes google.protobuf.Duration as a time.Duration, which is 64-bit signed integer. -const MaxDurationSeconds = int64(math.MaxInt64/int(1e9)) - 1 +const MaxDurationSeconds = int64(math.MaxInt64)/1e9 - 1 func marshalDuration(message protoreflect.Message, writer io.Writer) error { fields := message.Descriptor().Fields() From f44fee691a3cdad900135457fd4ba8cbb4992022 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Wed, 12 Apr 2023 12:52:54 -0500 Subject: [PATCH 03/52] Hard fixing --- client/tx/tx.go | 14 +-- client/tx_config.go | 2 +- server/grpc/server.go | 7 +- simapp/go.mod | 2 + simapp/go.sum | 4 +- simapp/simd/cmd/root.go | 9 +- testutil/sims/tx_helpers.go | 9 +- testutil/testnet/genesis.go | 8 +- tools/rosetta/converter.go | 19 ++- tools/rosetta/go.mod | 8 +- tools/rosetta/go.sum | 12 +- x/auth/ante/ante.go | 2 +- x/auth/ante/sigverify.go | 6 +- x/auth/client/cli/tx_multisign.go | 78 ++++++++++++- x/auth/client/cli/validate_sigs.go | 44 ++++++- x/auth/signing/verify.go | 180 ++++++++++++++++++++++------- x/auth/tx/config.go | 6 +- x/auth/tx/config/config.go | 4 +- x/auth/tx/mode_handler.go | 73 ++++++------ 19 files changed, 369 insertions(+), 118 deletions(-) diff --git a/client/tx/tx.go b/client/tx/tx.go index 156b57638001..f7970359787d 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -172,10 +172,8 @@ func SignWithPrivKey( var sigV2 signing.SignatureV2 // Generate the bytes to be signed. - signBytes, err := authsigning.GetSignBytesWithContext(txConfig.SignModeHandler(), ctx, signMode, signerData, txBuilder.GetTx()) - if err != nil { - return sigV2, err - } + signBytes, err := authsigning.AdaptSigningArgs( + ctx, txConfig.TxEncoder(), txConfig.SignModeHandler(), signMode, signerData, priv.PubKey(), txBuilder.GetTx()) // Sign those bytes signature, err := priv.Sign(signBytes) @@ -251,7 +249,8 @@ func Sign(ctx context.Context, txf Factory, name string, txBuilder client.TxBuil signMode := txf.signMode if signMode == signing.SignMode_SIGN_MODE_UNSPECIFIED { // use the SignModeHandler's default mode if unspecified - signMode = txf.txConfig.SignModeHandler().DefaultMode() + // TODO default mode in handler map? + signMode = signing.SignMode_SIGN_MODE_DIRECT } k, err := txf.keybase.Key(name) @@ -313,8 +312,9 @@ func Sign(ctx context.Context, txf Factory, name string, txBuilder client.TxBuil return err } - // Generate the bytes to be signed. - bytesToSign, err := authsigning.GetSignBytesWithContext(txf.txConfig.SignModeHandler(), ctx, signMode, signerData, txBuilder.GetTx()) + bytesToSign, err := authsigning.AdaptSigningArgs( + ctx, txf.txConfig.TxEncoder(), txf.txConfig.SignModeHandler(), + signMode, signerData, pubKey, txBuilder.GetTx()) if err != nil { return err } diff --git a/client/tx_config.go b/client/tx_config.go index f864b907e83b..2d56976a63b0 100644 --- a/client/tx_config.go +++ b/client/tx_config.go @@ -28,7 +28,7 @@ type ( NewTxBuilder() TxBuilder WrapTxBuilder(sdk.Tx) (TxBuilder, error) - SignModeHandler() txsigning.SignModeHandler + SignModeHandler() *txsigning.HandlerMap } // TxBuilder defines an interface which an application-defined concrete transaction diff --git a/server/grpc/server.go b/server/grpc/server.go index d133fe451f15..e5a1abf66178 100644 --- a/server/grpc/server.go +++ b/server/grpc/server.go @@ -5,9 +5,10 @@ import ( "fmt" "net" - "cosmossdk.io/log" "google.golang.org/grpc" + "cosmossdk.io/log" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/server/config" @@ -44,8 +45,8 @@ func NewGRPCServer(clientCtx client.Context, app types.Application, cfg config.G // time. err := reflection.Register(grpcSrv, reflection.Config{ SigningModes: func() map[string]int32 { - modes := make(map[string]int32, len(clientCtx.TxConfig.SignModeHandler().Modes())) - for _, m := range clientCtx.TxConfig.SignModeHandler().Modes() { + modes := make(map[string]int32, len(clientCtx.TxConfig.SignModeHandler().SupportedModes())) + for _, m := range clientCtx.TxConfig.SignModeHandler().SupportedModes() { modes[m.String()] = (int32)(m) } diff --git a/simapp/go.mod b/simapp/go.mod index bc6e72db56ce..86c428101678 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -122,6 +122,7 @@ require ( github.com/hashicorp/yamux v0.1.1 // indirect github.com/hdevalence/ed25519consensus v0.1.0 // indirect github.com/huandu/skiplist v1.2.0 // indirect + github.com/iancoleman/strcase v0.2.0 // indirect github.com/improbable-eng/grpc-web v0.15.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect @@ -202,6 +203,7 @@ replace ( cosmossdk.io/x/evidence => ../x/evidence cosmossdk.io/x/feegrant => ../x/feegrant cosmossdk.io/x/nft => ../x/nft + cosmossdk.io/x/tx => ../x/tx cosmossdk.io/x/upgrade => ../x/upgrade ) diff --git a/simapp/go.sum b/simapp/go.sum index 23c91cbbe3de..72eacc5cb505 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -202,8 +202,6 @@ cosmossdk.io/log v1.0.0 h1:NGKZ/A5rd4PduDfoscgABklX557PWjQINbosZy/m3Jk= cosmossdk.io/log v1.0.0/go.mod h1:CwX9BLiBruZb7lzLlRr3R231d/fVPUXk8gAdV4LQap0= cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw= cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= -cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63 h1:zHqj2VwZ/MStFmR7SUe/7gErOFhL9v2rkjmWPB/st34= -cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= @@ -697,6 +695,8 @@ github.com/huandu/skiplist v1.2.0 h1:gox56QD77HzSC0w+Ws3MH3iie755GBJU1OER3h5VsYw github.com/huandu/skiplist v1.2.0/go.mod h1:7v3iFjLcSAzO4fN5B8dvebvo/qsfumiLiDXMrPiHF9w= github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg= github.com/hydrogen18/memlistener v0.0.0-20200120041712-dcc25e7acd91/go.mod h1:qEIFzExnS6016fRpRfxrExeVn2gbClQA99gQhnIcdhE= +github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0= +github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/imkira/go-interpol v1.1.0/go.mod h1:z0h2/2T3XF8kyEPpRgJ3kmNv+C43p+I/CoI+jC3w2iA= diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index 23e4707be0c5..73945fa8429e 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -5,16 +5,17 @@ import ( "io" "os" - "cosmossdk.io/log" cmtcfg "github.com/cometbft/cometbft/config" dbm "github.com/cosmos/cosmos-db" "github.com/spf13/cobra" "github.com/spf13/viper" + "cosmossdk.io/log" "cosmossdk.io/simapp" "cosmossdk.io/simapp/params" confixcmd "cosmossdk.io/tools/confix/cmd" rosettaCmd "cosmossdk.io/tools/rosetta/cmd" + "github.com/cosmos/cosmos-sdk/x/auth/signing" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/config" @@ -90,9 +91,13 @@ func NewRootCmd() *cobra.Command { if err != nil { return err } + signModes, err := signing.APISignModesToInternal(encodingConfig.TxConfig.SignModeHandler().SupportedModes()) + if err != nil { + return err + } txConfigWithTextual := tx.NewTxConfigWithTextual( codec.NewProtoCodec(encodingConfig.InterfaceRegistry), - encodingConfig.TxConfig.SignModeHandler().Modes(), + signModes, txt, ) initClientCtx = initClientCtx.WithTxConfig(txConfigWithTextual) diff --git a/testutil/sims/tx_helpers.go b/testutil/sims/tx_helpers.go index e6daeb06cc85..907d5ef34f62 100644 --- a/testutil/sims/tx_helpers.go +++ b/testutil/sims/tx_helpers.go @@ -26,7 +26,10 @@ func GenSignedMockTx(r *rand.Rand, txConfig client.TxConfig, msgs []sdk.Msg, fee // create a random length memo memo := simulation.RandStringOfLength(r, simulation.RandIntBetween(r, 0, 100)) - signMode := txConfig.SignModeHandler().DefaultMode() + // TODO + // support default mode? + //signMode := txConfig.SignModeHandler().DefaultMode() + signMode := signing.SignMode_SIGN_MODE_DIRECT // 1st round: set SignatureV2 with empty signatures, to set correct // signer infos. @@ -63,7 +66,9 @@ func GenSignedMockTx(r *rand.Rand, txConfig client.TxConfig, msgs []sdk.Msg, fee PubKey: p.PubKey(), } - signBytes, err := authsign.GetSignBytesWithContext(txConfig.SignModeHandler(), context.Background(), signMode, signerData, tx.GetTx()) + signBytes, err := authsign.AdaptSigningArgs( + context.Background(), txConfig.TxEncoder(), txConfig.SignModeHandler(), signMode, signerData, p.PubKey(), + tx.GetTx()) if err != nil { panic(err) } diff --git a/testutil/testnet/genesis.go b/testutil/testnet/genesis.go index 1f526283c3f8..4b792667efc9 100644 --- a/testutil/testnet/genesis.go +++ b/testutil/testnet/genesis.go @@ -1,12 +1,14 @@ package testnet import ( + "context" "encoding/json" "fmt" "strconv" "time" cmttypes "github.com/cometbft/cometbft/types" + "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" @@ -143,7 +145,10 @@ func (b *GenesisBuilder) GenTx(privVal secp256k1.PrivKey, val cmttypes.GenesisVa } // Generate bytes to be signed. - bytesToSign, err := txConf.SignModeHandler().GetSignBytes( + bytesToSign, err := authsigning.AdaptSigningArgs( + context.Background(), + txConf.TxEncoder(), + txConf.SignModeHandler(), signing.SignMode_SIGN_MODE_DIRECT, authsigning.SignerData{ ChainID: b.chainID, @@ -152,6 +157,7 @@ func (b *GenesisBuilder) GenTx(privVal secp256k1.PrivKey, val cmttypes.GenesisVa // No account or sequence number for gentx. }, + pubKey, txb.GetTx(), ) if err != nil { diff --git a/tools/rosetta/converter.go b/tools/rosetta/converter.go index 5146ef93c470..27be2c22a5e0 100644 --- a/tools/rosetta/converter.go +++ b/tools/rosetta/converter.go @@ -2,13 +2,11 @@ package rosetta import ( "bytes" + "context" "encoding/json" "fmt" "reflect" - sdkmath "cosmossdk.io/math" - crgerrs "cosmossdk.io/tools/rosetta/lib/errors" - crgtypes "cosmossdk.io/tools/rosetta/lib/types" rosettatypes "github.com/coinbase/rosetta-sdk-go/types" abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/crypto" @@ -16,6 +14,10 @@ import ( cmttypes "github.com/cometbft/cometbft/types" secp "github.com/decred/dcrd/dcrec/secp256k1/v4" + sdkmath "cosmossdk.io/math" + crgerrs "cosmossdk.io/tools/rosetta/lib/errors" + crgtypes "cosmossdk.io/tools/rosetta/lib/types" + sdkclient "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -113,7 +115,16 @@ func NewConverter(cdc *codec.ProtoCodec, ir codectypes.InterfaceRegistry, cfg sd txDecode: cfg.TxDecoder(), txEncode: cfg.TxEncoder(), bytesToSign: func(tx authsigning.Tx, signerData authsigning.SignerData) (b []byte, err error) { - bytesToSign, err := cfg.SignModeHandler().GetSignBytes(signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, signerData, tx) + // TODO + // which pubkey? + pubkeys, err := tx.GetPubKeys() + if err != nil { + return nil, err + } + + bytesToSign, err := authsigning.AdaptSigningArgs( + context.Background(), cfg.TxEncoder(), cfg.SignModeHandler(), + signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, signerData, pubkeys[0], tx) if err != nil { return nil, err } diff --git a/tools/rosetta/go.mod b/tools/rosetta/go.mod index 2c7d8eb3c1c3..1bc725a90007 100644 --- a/tools/rosetta/go.mod +++ b/tools/rosetta/go.mod @@ -18,12 +18,12 @@ require ( require ( cosmossdk.io/api v0.4.0 // indirect - cosmossdk.io/collections v0.0.0-20230309163709-87da587416ba // indirect + cosmossdk.io/collections v0.0.0-20230411101845-3d1a0b8840e4 // indirect cosmossdk.io/core v0.6.1 // indirect cosmossdk.io/depinject v1.0.0-alpha.3 // indirect cosmossdk.io/errors v1.0.0-beta.7 // indirect cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc // indirect - cosmossdk.io/x/tx v0.5.0 // indirect + cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect @@ -82,6 +82,7 @@ require ( github.com/hashicorp/yamux v0.1.1 // indirect github.com/hdevalence/ed25519consensus v0.1.0 // indirect github.com/huandu/skiplist v1.2.0 // indirect + github.com/iancoleman/strcase v0.2.0 // indirect github.com/improbable-eng/grpc-web v0.15.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/klauspost/compress v1.16.3 // indirect @@ -137,3 +138,6 @@ require ( pgregory.net/rapid v0.5.5 // indirect sigs.k8s.io/yaml v1.3.0 // indirect ) + +// temp to use local version of cosmos-sdk while in dev +replace github.com/cosmos/cosmos-sdk => ../.. diff --git a/tools/rosetta/go.sum b/tools/rosetta/go.sum index 37504dea060b..bbbf44d13c12 100644 --- a/tools/rosetta/go.sum +++ b/tools/rosetta/go.sum @@ -37,8 +37,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= cosmossdk.io/api v0.4.0 h1:x90DmdidP6EhzktAa/6/IofSHidDnPjahdlrUvyQZQw= cosmossdk.io/api v0.4.0/go.mod h1:TWDzBhUBhI1LhSf2XSYpfIBf6D4mbLu/fvzvDfhcaYM= -cosmossdk.io/collections v0.0.0-20230309163709-87da587416ba h1:S4PYij/tX3Op/hwenVEN9D+M27JRcwSwVqE3UA0BnwM= -cosmossdk.io/collections v0.0.0-20230309163709-87da587416ba/go.mod h1:lpS+G8bGC2anqzWdndTzjnQnuMO/qAcgZUkGJp4i3rc= +cosmossdk.io/collections v0.0.0-20230411101845-3d1a0b8840e4 h1:QQZ0Qz8Gy/EmUNMRiHkUPG3BMA6OqEBp67IsfKETXIU= +cosmossdk.io/collections v0.0.0-20230411101845-3d1a0b8840e4/go.mod h1:/vS4ugR7ad3IciUd5TQuP2Ldz3NukHK2u/l5xTxXbbE= cosmossdk.io/core v0.6.1 h1:OBy7TI2W+/gyn2z40vVvruK3di+cAluinA6cybFbE7s= cosmossdk.io/core v0.6.1/go.mod h1:g3MMBCBXtxbDWBURDVnJE7XML4BG5qENhs0gzkcpuFA= cosmossdk.io/depinject v1.0.0-alpha.3 h1:6evFIgj//Y3w09bqOUOzEpFj5tsxBqdc5CfkO7z+zfw= @@ -51,8 +51,8 @@ cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw= cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc h1:9piuA+NYmhe+SyMPtMoboLw/djgDbrI3dD5TG020Tnk= cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc/go.mod h1:UFF5rmjN7WYVfxo6ArdY/l1+yyWMURBWOmSJypGqFHQ= -cosmossdk.io/x/tx v0.5.0 h1:01wPSoiYDHlfudV0fn867SBXI3uI/8tpatBgVVSnFzI= -cosmossdk.io/x/tx v0.5.0/go.mod h1:kDcwrN6QbCj+9NXVHL8qipMzA9YlMr9NpZa08SHCdLA= +cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63 h1:zHqj2VwZ/MStFmR7SUe/7gErOFhL9v2rkjmWPB/st34= +cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= @@ -172,8 +172,6 @@ github.com/cosmos/cosmos-db v1.0.0-rc.1 h1:SjnT8B6WKMW9WEIX32qMhnEEKcI7ZP0+G1Sa9 github.com/cosmos/cosmos-db v1.0.0-rc.1/go.mod h1:Dnmk3flSf5lkwCqvvjNpoxjpXzhxnCAFzKHlbaForso= github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQYKXTdEcpW6o= github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I= -github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230407105549-64a355c27736 h1:s5qqDSbWPBetLak/tiFUdz58atedY5hzEKu2XAZV2oA= -github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230407105549-64a355c27736/go.mod h1:nUeoGQBaRyGM1OQpQpj3AcdObVkmC6xS6AhyZ8dBZhY= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= @@ -467,6 +465,8 @@ github.com/huandu/skiplist v1.2.0 h1:gox56QD77HzSC0w+Ws3MH3iie755GBJU1OER3h5VsYw github.com/huandu/skiplist v1.2.0/go.mod h1:7v3iFjLcSAzO4fN5B8dvebvo/qsfumiLiDXMrPiHF9w= github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg= github.com/hydrogen18/memlistener v0.0.0-20200120041712-dcc25e7acd91/go.mod h1:qEIFzExnS6016fRpRfxrExeVn2gbClQA99gQhnIcdhE= +github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0= +github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/imkira/go-interpol v1.1.0/go.mod h1:z0h2/2T3XF8kyEPpRgJ3kmNv+C43p+I/CoI+jC3w2iA= diff --git a/x/auth/ante/ante.go b/x/auth/ante/ante.go index 2351f4601165..05c5eb102657 100644 --- a/x/auth/ante/ante.go +++ b/x/auth/ante/ante.go @@ -18,7 +18,7 @@ type HandlerOptions struct { BankKeeper types.BankKeeper ExtensionOptionChecker ExtensionOptionChecker FeegrantKeeper FeegrantKeeper - SignModeHandler txsigning.SignModeHandler + SignModeHandler *txsigning.HandlerMap SigGasConsumer func(meter storetypes.GasMeter, sig signing.SignatureV2, params types.Params) error TxFeeChecker TxFeeChecker } diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index 5776be75013c..b17b06847f78 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -206,10 +206,10 @@ func (sgcd SigGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula // CONTRACT: Tx must implement SigVerifiableTx interface type SigVerificationDecorator struct { ak AccountKeeper - signModeHandler txsigning.SignModeHandler + signModeHandler *txsigning.HandlerMap } -func NewSigVerificationDecorator(ak AccountKeeper, signModeHandler txsigning.SignModeHandler) SigVerificationDecorator { +func NewSigVerificationDecorator(ak AccountKeeper, signModeHandler *txsigning.HandlerMap) SigVerificationDecorator { return SigVerificationDecorator{ ak: ak, signModeHandler: signModeHandler, @@ -315,7 +315,7 @@ func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul AuthInfoBytes: decodedTx.TxRaw.AuthInfoBytes, BodyBytes: decodedTx.TxRaw.BodyBytes, } - err = authsigning.VerifySignatureV2(ctx, pubKey, signerData, sig.Data, svd.signModeHandler, txData) + err = authsigning.VerifySignature(ctx, pubKey, signerData, sig.Data, svd.signModeHandler, txData) if err != nil { var errMsg string if OnlyLegacyAminoSigners(sig.Data) { diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index 34349ec858aa..2dc6745e2332 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -7,8 +7,12 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" + "google.golang.org/protobuf/types/known/anypb" errorsmod "cosmossdk.io/errors" + "cosmossdk.io/x/tx/decode" + txsigning "cosmossdk.io/x/tx/signing" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -124,6 +128,11 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) (err error) { } for _, sig := range sigs { + // TODO abstract, clean up + anyPk, err := codectypes.NewAnyWithValue(sig.PubKey) + if err != nil { + return err + } signingData := signing.SignerData{ Address: sdk.AccAddress(sig.PubKey.Address()).String(), ChainID: txFactory.ChainID(), @@ -131,8 +140,38 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) (err error) { Sequence: txFactory.Sequence(), PubKey: sig.PubKey, } + txSignerData := txsigning.SignerData{ + ChainID: signingData.ChainID, + AccountNumber: signingData.AccountNumber, + Sequence: signingData.Sequence, + Address: signingData.Address, + PubKey: &anypb.Any{ + TypeUrl: anyPk.TypeUrl, + Value: anyPk.Value, + }, + } + + txBytes, err := txCfg.TxEncoder()(txBuilder.GetTx()) + if err != nil { + return err + } + decodeCtx, err := decode.NewDecoder(decode.Options{}) + if err != nil { + return err + } + decodedTx, err := decodeCtx.Decode(txBytes) + if err != nil { + return err + } + txData := txsigning.TxData{ + Body: decodedTx.Tx.Body, + AuthInfo: decodedTx.Tx.AuthInfo, + AuthInfoBytes: decodedTx.TxRaw.AuthInfoBytes, + BodyBytes: decodedTx.TxRaw.BodyBytes, + } - err = signing.VerifySignature(cmd.Context(), sig.PubKey, signingData, sig.Data, txCfg.SignModeHandler(), txBuilder.GetTx()) + err = signing.VerifySignature(cmd.Context(), sig.PubKey, txSignerData, sig.Data, + txCfg.SignModeHandler(), txData) if err != nil { addr, _ := sdk.AccAddressFromHexUnsafe(sig.PubKey.Address().String()) return fmt.Errorf("couldn't verify signature for address %s", addr) @@ -303,8 +342,43 @@ func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error { PubKey: pubKey, } + // TODO abstract, clean up + anyPk, err := codectypes.NewAnyWithValue(multisigPub) + if err != nil { + return err + } + txSignerData := txsigning.SignerData{ + ChainID: signingData.ChainID, + AccountNumber: signingData.AccountNumber, + Sequence: signingData.Sequence, + Address: signingData.Address, + PubKey: &anypb.Any{ + TypeUrl: anyPk.TypeUrl, + Value: anyPk.Value, + }, + } + + txBytes, err := txCfg.TxEncoder()(txBldr.GetTx()) + if err != nil { + return err + } + decodeCtx, err := decode.NewDecoder(decode.Options{}) + if err != nil { + return err + } + decodedTx, err := decodeCtx.Decode(txBytes) + if err != nil { + return err + } + txData := txsigning.TxData{ + Body: decodedTx.Tx.Body, + AuthInfo: decodedTx.Tx.AuthInfo, + AuthInfoBytes: decodedTx.TxRaw.AuthInfoBytes, + BodyBytes: decodedTx.TxRaw.BodyBytes, + } for _, sig := range signatureBatch { - err = signing.VerifySignature(cmd.Context(), sig[i].PubKey, signingData, sig[i].Data, txCfg.SignModeHandler(), txBldr.GetTx()) + err = signing.VerifySignature(cmd.Context(), sig[i].PubKey, txSignerData, sig[i].Data, + txCfg.SignModeHandler(), txData) if err != nil { return fmt.Errorf("couldn't verify signature: %w %v", err, sig) } diff --git a/x/auth/client/cli/validate_sigs.go b/x/auth/client/cli/validate_sigs.go index 6a0b8156c7ff..a9d2aecf2b3e 100644 --- a/x/auth/client/cli/validate_sigs.go +++ b/x/auth/client/cli/validate_sigs.go @@ -4,10 +4,14 @@ import ( "fmt" "github.com/spf13/cobra" + "google.golang.org/protobuf/types/known/anypb" + "cosmossdk.io/x/tx/decode" + txsigning "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" @@ -111,8 +115,46 @@ func printAndValidateSigs( Sequence: accSeq, PubKey: pubKey, } + // TODO abstract, clean up + anyPk, err := codectypes.NewAnyWithValue(pubKey) + if err != nil { + cmd.PrintErrf("failed to pack public key: %v", err) + return false + } + txSignerData := txsigning.SignerData{ + ChainID: signingData.ChainID, + AccountNumber: signingData.AccountNumber, + Sequence: signingData.Sequence, + Address: signingData.Address, + PubKey: &anypb.Any{ + TypeUrl: anyPk.TypeUrl, + Value: anyPk.Value, + }, + } + + txBytes, err := clientCtx.TxConfig.TxEncoder()(tx) + if err != nil { + cmd.PrintErrf("failed to encode transaction: %v", err) + return false + } + decodeCtx, err := decode.NewDecoder(decode.Options{}) + if err != nil { + cmd.PrintErrf("failed to create decoder: %v", err) + return false + } + decodedTx, err := decodeCtx.Decode(txBytes) + if err != nil { + cmd.PrintErrf("failed to decode transaction: %v", err) + return false + } + txData := txsigning.TxData{ + Body: decodedTx.Tx.Body, + AuthInfo: decodedTx.Tx.AuthInfo, + AuthInfoBytes: decodedTx.TxRaw.AuthInfoBytes, + BodyBytes: decodedTx.TxRaw.BodyBytes, + } - err = authsigning.VerifySignature(cmd.Context(), pubKey, signingData, sig.Data, signModeHandler, sigTx) + err = authsigning.VerifySignature(cmd.Context(), pubKey, txSignerData, sig.Data, signModeHandler, txData) if err != nil { return false } diff --git a/x/auth/signing/verify.go b/x/auth/signing/verify.go index a0d636654cc7..459151db3a89 100644 --- a/x/auth/signing/verify.go +++ b/x/auth/signing/verify.go @@ -4,7 +4,12 @@ import ( "context" "fmt" + "google.golang.org/protobuf/types/known/anypb" + + signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + "cosmossdk.io/x/tx/decode" txsigning "cosmossdk.io/x/tx/signing" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/crypto/types/multisig" sdk "github.com/cosmos/cosmos-sdk/types" @@ -13,52 +18,98 @@ import ( // VerifySignature verifies a transaction signature contained in SignatureData abstracting over different signing modes // and single vs multi-signatures. -func VerifySignature(ctx context.Context, pubKey cryptotypes.PubKey, signerData SignerData, sigData signing.SignatureData, handler SignModeHandler, tx sdk.Tx) error { - switch data := sigData.(type) { - case *signing.SingleSignatureData: - signBytes, err := GetSignBytesWithContext(handler, ctx, data.SignMode, signerData, tx) - if err != nil { - return err - } - if !pubKey.VerifySignature(signBytes, data.Signature) { - return fmt.Errorf("unable to verify single signer signature") - } - return nil +//func VerifySignature(ctx context.Context, pubKey cryptotypes.PubKey, signerData SignerData, sigData signing.SignatureData, handler SignModeHandler, tx sdk.Tx) error { +// switch data := sigData.(type) { +// case *signing.SingleSignatureData: +// signBytes, err := GetSignBytesWithContext(handler, ctx, data.SignMode, signerData, tx) +// if err != nil { +// return err +// } +// if !pubKey.VerifySignature(signBytes, data.Signature) { +// return fmt.Errorf("unable to verify single signer signature") +// } +// return nil +// +// case *signing.MultiSignatureData: +// multiPK, ok := pubKey.(multisig.PubKey) +// if !ok { +// return fmt.Errorf("expected %T, got %T", (multisig.PubKey)(nil), pubKey) +// } +// err := multiPK.VerifyMultisignature(func(mode signing.SignMode) ([]byte, error) { +// handlerWithContext, ok := handler.(SignModeHandlerWithContext) +// if ok { +// return handlerWithContext.GetSignBytesWithContext(ctx, mode, signerData, tx) +// } +// return handler.GetSignBytes(mode, signerData, tx) +// }, data) +// if err != nil { +// return err +// } +// return nil +// default: +// return fmt.Errorf("unexpected SignatureData %T", sigData) +// } +//} - case *signing.MultiSignatureData: - multiPK, ok := pubKey.(multisig.PubKey) - if !ok { - return fmt.Errorf("expected %T, got %T", (multisig.PubKey)(nil), pubKey) - } - err := multiPK.VerifyMultisignature(func(mode signing.SignMode) ([]byte, error) { - handlerWithContext, ok := handler.(SignModeHandlerWithContext) - if ok { - return handlerWithContext.GetSignBytesWithContext(ctx, mode, signerData, tx) - } - return handler.GetSignBytes(mode, signerData, tx) - }, data) +func APISignModesToInternal(modes []signingv1beta1.SignMode) ([]signing.SignMode, error) { + internalModes := make([]signing.SignMode, len(modes)) + for i, mode := range modes { + internalMode, err := APISignModeToInternal(mode) if err != nil { - return err + return nil, err } - return nil + internalModes[i] = internalMode + } + return internalModes, nil +} + +func APISignModeToInternal(mode signingv1beta1.SignMode) (signing.SignMode, error) { + switch mode { + case signingv1beta1.SignMode_SIGN_MODE_DIRECT: + return signing.SignMode_SIGN_MODE_DIRECT, nil + case signingv1beta1.SignMode_SIGN_MODE_LEGACY_AMINO_JSON: + return signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, nil + case signingv1beta1.SignMode_SIGN_MODE_TEXTUAL: + return signing.SignMode_SIGN_MODE_TEXTUAL, nil + case signingv1beta1.SignMode_SIGN_MODE_DIRECT_AUX: + return signing.SignMode_SIGN_MODE_DIRECT_AUX, nil + default: + return signing.SignMode_SIGN_MODE_UNSPECIFIED, fmt.Errorf("unsupported sign mode %s", mode) + } +} + +func InternalSignModeToAPI(mode signing.SignMode) (signingv1beta1.SignMode, error) { + switch mode { + case signing.SignMode_SIGN_MODE_DIRECT: + return signingv1beta1.SignMode_SIGN_MODE_DIRECT, nil + case signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON: + return signingv1beta1.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, nil + case signing.SignMode_SIGN_MODE_TEXTUAL: + return signingv1beta1.SignMode_SIGN_MODE_TEXTUAL, nil + case signing.SignMode_SIGN_MODE_DIRECT_AUX: + return signingv1beta1.SignMode_SIGN_MODE_DIRECT_AUX, nil default: - return fmt.Errorf("unexpected SignatureData %T", sigData) + return signingv1beta1.SignMode_SIGN_MODE_UNSPECIFIED, fmt.Errorf("unsupported sign mode %s", mode) } } -// VerifySignatureV2 verifies a transaction signature contained in SignatureData abstracting over different signing +// VerifySignature verifies a transaction signature contained in SignatureData abstracting over different signing // modes. It differs from VerifySignature in that it uses the new txsigning.TxData interface in x/tx. -func VerifySignatureV2( +func VerifySignature( ctx context.Context, pubKey cryptotypes.PubKey, signerData txsigning.SignerData, signatureData signing.SignatureData, - handler txsigning.SignModeHandler, - txData txsigning.TxData, -) error { + handler *txsigning.HandlerMap, + txData txsigning.TxData) error { + switch data := signatureData.(type) { case *signing.SingleSignatureData: - signBytes, err := handler.GetSignBytes(ctx, signerData, txData) + signMode, err := InternalSignModeToAPI(data.SignMode) + if err != nil { + return err + } + signBytes, err := handler.GetSignBytes(ctx, signMode, signerData, txData) if err != nil { return err } @@ -73,7 +124,11 @@ func VerifySignatureV2( return fmt.Errorf("expected %T, got %T", (multisig.PubKey)(nil), pubKey) } err := multiPK.VerifyMultisignature(func(mode signing.SignMode) ([]byte, error) { - return handler.GetSignBytes(ctx, signerData, txData) + signMode, err := InternalSignModeToAPI(mode) + if err != nil { + return nil, err + } + return handler.GetSignBytes(ctx, signMode, signerData, txData) }, data) if err != nil { return err @@ -84,14 +139,55 @@ func VerifySignatureV2( } } -// GetSignBytesWithContext gets the sign bytes from the sign mode handler. It -// checks if the sign mode handler supports SignModeHandlerWithContext, in -// which case it passes the context.Context argument. Otherwise, it fallbacks -// to GetSignBytes. -func GetSignBytesWithContext(h SignModeHandler, ctx context.Context, mode signing.SignMode, data SignerData, tx sdk.Tx) ([]byte, error) { //nolint:revive // refactor this in a future pr - hWithCtx, ok := h.(SignModeHandlerWithContext) - if ok { - return hWithCtx.GetSignBytesWithContext(ctx, mode, data, tx) +func AdaptSigningArgs( + ctx context.Context, + encoder sdk.TxEncoder, + handlerMap *txsigning.HandlerMap, + mode signing.SignMode, + signerData SignerData, + key cryptotypes.PubKey, + tx sdk.Tx, +) ([]byte, error) { + // round trip performance hit. + // could be avoided if we had a way to get the bytes from the txBuilder. + txBytes, err := encoder(tx) + if err != nil { + return nil, err + } + decodeCtx, err := decode.NewDecoder(decode.Options{}) + if err != nil { + return nil, err + } + decodedTx, err := decodeCtx.Decode(txBytes) + if err != nil { + return nil, err + } + txData := txsigning.TxData{ + Body: decodedTx.Tx.Body, + AuthInfo: decodedTx.Tx.AuthInfo, + AuthInfoBytes: decodedTx.TxRaw.AuthInfoBytes, + BodyBytes: decodedTx.TxRaw.BodyBytes, + } + txSignMode, err := InternalSignModeToAPI(mode) + if err != nil { + return nil, err + } + + anyPk, err := codectypes.NewAnyWithValue(key) + if err != nil { + return nil, err + } + + txSignerData := txsigning.SignerData{ + ChainID: signerData.ChainID, + AccountNumber: signerData.AccountNumber, + Sequence: signerData.Sequence, + Address: signerData.Address, + PubKey: &anypb.Any{ + TypeUrl: anyPk.TypeUrl, + Value: anyPk.Value, + }, } - return h.GetSignBytes(mode, data, tx) + // Generate the bytes to be signed. + return handlerMap.GetSignBytes(ctx, txSignMode, txSignerData, txData) } diff --git a/x/auth/tx/config.go b/x/auth/tx/config.go index bbc7c20e4552..9612519d247f 100644 --- a/x/auth/tx/config.go +++ b/x/auth/tx/config.go @@ -13,7 +13,7 @@ import ( ) type config struct { - handler txsigning.SignModeHandler + handler *txsigning.HandlerMap decoder sdk.TxDecoder encoder sdk.TxEncoder jsonDecoder sdk.TxDecoder @@ -48,7 +48,7 @@ func NewTxConfigWithTextual(protoCodec codec.ProtoCodecMarshaler, enabledSignMod } // NewTxConfigWithHandler returns a new protobuf TxConfig using the provided ProtoCodec and signing handler. -func NewTxConfigWithHandler(protoCodec codec.ProtoCodecMarshaler, handler txsigning.SignModeHandler) client.TxConfig { +func NewTxConfigWithHandler(protoCodec codec.ProtoCodecMarshaler, handler *txsigning.HandlerMap) client.TxConfig { return &config{ handler: handler, decoder: DefaultTxDecoder(protoCodec), @@ -73,7 +73,7 @@ func (g config) WrapTxBuilder(newTx sdk.Tx) (client.TxBuilder, error) { return newBuilder, nil } -func (g config) SignModeHandler() txsigning.SignModeHandler { +func (g config) SignModeHandler() *txsigning.HandlerMap { return g.handler } diff --git a/x/auth/tx/config/config.go b/x/auth/tx/config/config.go index dbfa624e0453..0f69e3662100 100644 --- a/x/auth/tx/config/config.go +++ b/x/auth/tx/config/config.go @@ -6,6 +6,7 @@ import ( txconfigv1 "cosmossdk.io/api/cosmos/tx/config/v1" "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" + txsigning "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" @@ -13,7 +14,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/ante" "github.com/cosmos/cosmos-sdk/x/auth/posthandler" - "github.com/cosmos/cosmos-sdk/x/auth/signing" "github.com/cosmos/cosmos-sdk/x/auth/tx" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" ) @@ -37,7 +37,7 @@ type ModuleInputs struct { TxBankKeeper BankKeeper FeeGrantKeeper ante.FeegrantKeeper `optional:"true"` - CustomSignModeHandlers func() []signing.SignModeHandler `optional:"true"` + CustomSignModeHandlers func() []txsigning.SignModeHandler `optional:"true"` } type ModuleOutputs struct { diff --git a/x/auth/tx/mode_handler.go b/x/auth/tx/mode_handler.go index 098da8ff2901..a46546f4ffa1 100644 --- a/x/auth/tx/mode_handler.go +++ b/x/auth/tx/mode_handler.go @@ -1,13 +1,11 @@ package tx import ( - "fmt" - txsigning "cosmossdk.io/x/tx/signing" + stdsigning "cosmossdk.io/x/tx/signing/std" "cosmossdk.io/x/tx/signing/textual" signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" - "github.com/cosmos/cosmos-sdk/x/auth/signing" ) // DefaultSignModes are the default sign modes enabled for protobuf transactions. @@ -29,36 +27,43 @@ func makeSignModeHandler( modes []signingtypes.SignMode, txt *textual.SignModeHandler, customSignModes ...txsigning.SignModeHandler, -) txsigning.SignModeHandler { - if len(modes) < 1 { - panic(fmt.Errorf("no sign modes enabled")) - } - - handlers := make([]signing.SignModeHandler, len(modes)+len(customSignModes)) - - // handle cosmos-sdk defined sign modes - for i, mode := range modes { - switch mode { - case signingtypes.SignMode_SIGN_MODE_DIRECT: - handlers[i] = signModeDirectHandler{} - case signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON: - handlers[i] = signModeLegacyAminoJSONHandler{} - case signingtypes.SignMode_SIGN_MODE_TEXTUAL: - handlers[i] = signModeTextualHandler{t: *txt} - case signingtypes.SignMode_SIGN_MODE_DIRECT_AUX: - handlers[i] = signModeDirectAuxHandler{} - default: - panic(fmt.Errorf("unsupported sign mode %+v", mode)) - } +) *txsigning.HandlerMap { + // TODO parity + //if len(modes) < 1 { + // panic(fmt.Errorf("no sign modes enabled")) + //} + // + //handlers := make([]signing.SignModeHandler, len(modes)+len(customSignModes)) + // + //// handle cosmos-sdk defined sign modes + //for i, mode := range modes { + // switch mode { + // case signingtypes.SignMode_SIGN_MODE_DIRECT: + // handlers[i] = signModeDirectHandler{} + // case signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON: + // handlers[i] = signModeLegacyAminoJSONHandler{} + // case signingtypes.SignMode_SIGN_MODE_TEXTUAL: + // handlers[i] = signModeTextualHandler{t: *txt} + // case signingtypes.SignMode_SIGN_MODE_DIRECT_AUX: + // handlers[i] = signModeDirectAuxHandler{} + // default: + // panic(fmt.Errorf("unsupported sign mode %+v", mode)) + // } + //} + // + //// add custom sign modes + //for i, handler := range customSignModes { + // handlers[i+len(modes)] = handler + //} + // + //return signing.NewSignModeHandlerMap( + // modes[0], + // handlers, + //) + opts := stdsigning.SignModeOptions{} + hmap, err := opts.HandlerMap() + if err != nil { + panic(err) } - - // add custom sign modes - for i, handler := range customSignModes { - handlers[i+len(modes)] = handler - } - - return signing.NewSignModeHandlerMap( - modes[0], - handlers, - ) + return hmap } From 14539c4e00c0090257bee1a9bee19f5fa950cae9 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Wed, 12 Apr 2023 13:00:34 -0500 Subject: [PATCH 04/52] go mod tidy --- go.mod | 1 + go.sum | 2 ++ 2 files changed, 3 insertions(+) diff --git a/go.mod b/go.mod index bf5a9eacde5e..c2c5e3187431 100644 --- a/go.mod +++ b/go.mod @@ -114,6 +114,7 @@ require ( github.com/hashicorp/go-plugin v1.4.9 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/hashicorp/yamux v0.1.1 // indirect + github.com/iancoleman/strcase v0.2.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jmhodges/levigo v1.0.0 // indirect github.com/klauspost/compress v1.16.3 // indirect diff --git a/go.sum b/go.sum index e17be66f6829..58d6d741e458 100644 --- a/go.sum +++ b/go.sum @@ -492,6 +492,8 @@ github.com/huandu/skiplist v1.2.0 h1:gox56QD77HzSC0w+Ws3MH3iie755GBJU1OER3h5VsYw github.com/huandu/skiplist v1.2.0/go.mod h1:7v3iFjLcSAzO4fN5B8dvebvo/qsfumiLiDXMrPiHF9w= github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg= github.com/hydrogen18/memlistener v0.0.0-20200120041712-dcc25e7acd91/go.mod h1:qEIFzExnS6016fRpRfxrExeVn2gbClQA99gQhnIcdhE= +github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0= +github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/imkira/go-interpol v1.1.0/go.mod h1:z0h2/2T3XF8kyEPpRgJ3kmNv+C43p+I/CoI+jC3w2iA= From 5f2b4de328f56261c14f3aba4b9291d83cd771a5 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Wed, 12 Apr 2023 13:12:48 -0500 Subject: [PATCH 05/52] fix breakage in codec from latest main --- codec/proto_codec.go | 46 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/codec/proto_codec.go b/codec/proto_codec.go index 965954ae2df0..97c0e4cfc461 100644 --- a/codec/proto_codec.go +++ b/codec/proto_codec.go @@ -29,7 +29,7 @@ type ProtoCodecMarshaler interface { // encoding. type ProtoCodec struct { interfaceRegistry types.InterfaceRegistry - getSignersCtx *signing.GetSignersContext + signersCtx *signing.Context } var ( @@ -39,16 +39,16 @@ var ( // NewProtoCodec returns a reference to a new ProtoCodec func NewProtoCodec(interfaceRegistry types.InterfaceRegistry) *ProtoCodec { - getSignersCtx, err := signing.NewGetSignersContext( - signing.GetSignersOptions{ - ProtoFiles: interfaceRegistry, + signerCtx, err := signing.NewContext( + signing.Options{ + FileResolver: interfaceRegistry, }) if err != nil { panic(err) } return &ProtoCodec{ interfaceRegistry: interfaceRegistry, - getSignersCtx: getSignersCtx, + signersCtx: signerCtx, } } @@ -286,18 +286,44 @@ func (pc ProtoCodec) GetMsgAnySigners(msg *types.Any) ([]string, proto.Message, return nil, nil, err } - signers, err := pc.getSignersCtx.GetSigners(msgv2) - return signers, msgv2, err + bzSigners, err := pc.signersCtx.GetSigners(msgv2) + if err != nil { + return nil, nil, err + } + + strSigners := make([]string, len(bzSigners)) + for i, bz := range bzSigners { + strSigners[i] = string(bz) + } + return strSigners, msgv2, err } func (pc *ProtoCodec) GetMsgV2Signers(msg proto.Message) ([]string, error) { - return pc.getSignersCtx.GetSigners(msg) + bzSigners, err := pc.signersCtx.GetSigners(msg) + if err != nil { + return nil, err + } + + strSigners := make([]string, len(bzSigners)) + for i, bz := range bzSigners { + strSigners[i] = string(bz) + } + return strSigners, nil } func (pc *ProtoCodec) GetMsgV1Signers(msg gogoproto.Message) ([]string, proto.Message, error) { if msgV2, ok := msg.(proto.Message); ok { - signers, err := pc.getSignersCtx.GetSigners(msgV2) - return signers, msgV2, err + bzSigners, err := pc.signersCtx.GetSigners(msgV2) + if err != nil { + return nil, nil, err + } + + strSigners := make([]string, len(bzSigners)) + for i, bz := range bzSigners { + strSigners[i] = string(bz) + } + + return strSigners, msgV2, err } a, err := types.NewAnyWithValue(msg) if err != nil { From 147cbdf4bdf31b113643874fcd5b7bf43ec1d683 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 13 Apr 2023 10:22:59 -0500 Subject: [PATCH 06/52] remove replace for x/tx --- go.mod | 1 - go.sum | 2 ++ simapp/go.mod | 3 +-- simapp/go.sum | 2 ++ 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index c2c5e3187431..64c3c69642c4 100644 --- a/go.mod +++ b/go.mod @@ -162,7 +162,6 @@ require ( // Below are the long-lived replace of the Cosmos SDK replace ( - cosmossdk.io/x/tx => ./x/tx // use cosmos fork of keyring github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 // dgrijalva/jwt-go is deprecated and doesn't receive security updates. diff --git a/go.sum b/go.sum index 58d6d741e458..ff24a864a321 100644 --- a/go.sum +++ b/go.sum @@ -51,6 +51,8 @@ cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw= cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc h1:9piuA+NYmhe+SyMPtMoboLw/djgDbrI3dD5TG020Tnk= cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc/go.mod h1:UFF5rmjN7WYVfxo6ArdY/l1+yyWMURBWOmSJypGqFHQ= +cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63 h1:zHqj2VwZ/MStFmR7SUe/7gErOFhL9v2rkjmWPB/st34= +cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/simapp/go.mod b/simapp/go.mod index 86c428101678..f809d53af66c 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -15,6 +15,7 @@ require ( cosmossdk.io/x/evidence v0.1.0 cosmossdk.io/x/feegrant v0.0.0-20230117113717-50e7c4a4ceff cosmossdk.io/x/nft v0.0.0-20230113085233-fae3332d62fc + cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63 // indirect cosmossdk.io/x/upgrade v0.0.0-20230127052425-54c8e1568335 github.com/cometbft/cometbft v0.37.1-0.20230411132551-3a91d155e664 github.com/cosmos/cosmos-db v1.0.0-rc.1 @@ -38,7 +39,6 @@ require ( cloud.google.com/go/storage v1.30.0 // indirect cosmossdk.io/collections v0.0.0-20230411101845-3d1a0b8840e4 // indirect cosmossdk.io/errors v1.0.0-beta.7 // indirect - cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect @@ -203,7 +203,6 @@ replace ( cosmossdk.io/x/evidence => ../x/evidence cosmossdk.io/x/feegrant => ../x/feegrant cosmossdk.io/x/nft => ../x/nft - cosmossdk.io/x/tx => ../x/tx cosmossdk.io/x/upgrade => ../x/upgrade ) diff --git a/simapp/go.sum b/simapp/go.sum index 72eacc5cb505..ca30ae7ab564 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -202,6 +202,8 @@ cosmossdk.io/log v1.0.0 h1:NGKZ/A5rd4PduDfoscgABklX557PWjQINbosZy/m3Jk= cosmossdk.io/log v1.0.0/go.mod h1:CwX9BLiBruZb7lzLlRr3R231d/fVPUXk8gAdV4LQap0= cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw= cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= +cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63 h1:zHqj2VwZ/MStFmR7SUe/7gErOFhL9v2rkjmWPB/st34= +cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= From 55e1d368ca60b181f6bf12a52eab00de33ed57d8 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 13 Apr 2023 10:23:52 -0500 Subject: [PATCH 07/52] revert codec/ compat for x/tx 0.6.0 --- codec/proto_codec.go | 46 ++++++++++---------------------------------- 1 file changed, 10 insertions(+), 36 deletions(-) diff --git a/codec/proto_codec.go b/codec/proto_codec.go index 97c0e4cfc461..965954ae2df0 100644 --- a/codec/proto_codec.go +++ b/codec/proto_codec.go @@ -29,7 +29,7 @@ type ProtoCodecMarshaler interface { // encoding. type ProtoCodec struct { interfaceRegistry types.InterfaceRegistry - signersCtx *signing.Context + getSignersCtx *signing.GetSignersContext } var ( @@ -39,16 +39,16 @@ var ( // NewProtoCodec returns a reference to a new ProtoCodec func NewProtoCodec(interfaceRegistry types.InterfaceRegistry) *ProtoCodec { - signerCtx, err := signing.NewContext( - signing.Options{ - FileResolver: interfaceRegistry, + getSignersCtx, err := signing.NewGetSignersContext( + signing.GetSignersOptions{ + ProtoFiles: interfaceRegistry, }) if err != nil { panic(err) } return &ProtoCodec{ interfaceRegistry: interfaceRegistry, - signersCtx: signerCtx, + getSignersCtx: getSignersCtx, } } @@ -286,44 +286,18 @@ func (pc ProtoCodec) GetMsgAnySigners(msg *types.Any) ([]string, proto.Message, return nil, nil, err } - bzSigners, err := pc.signersCtx.GetSigners(msgv2) - if err != nil { - return nil, nil, err - } - - strSigners := make([]string, len(bzSigners)) - for i, bz := range bzSigners { - strSigners[i] = string(bz) - } - return strSigners, msgv2, err + signers, err := pc.getSignersCtx.GetSigners(msgv2) + return signers, msgv2, err } func (pc *ProtoCodec) GetMsgV2Signers(msg proto.Message) ([]string, error) { - bzSigners, err := pc.signersCtx.GetSigners(msg) - if err != nil { - return nil, err - } - - strSigners := make([]string, len(bzSigners)) - for i, bz := range bzSigners { - strSigners[i] = string(bz) - } - return strSigners, nil + return pc.getSignersCtx.GetSigners(msg) } func (pc *ProtoCodec) GetMsgV1Signers(msg gogoproto.Message) ([]string, proto.Message, error) { if msgV2, ok := msg.(proto.Message); ok { - bzSigners, err := pc.signersCtx.GetSigners(msgV2) - if err != nil { - return nil, nil, err - } - - strSigners := make([]string, len(bzSigners)) - for i, bz := range bzSigners { - strSigners[i] = string(bz) - } - - return strSigners, msgV2, err + signers, err := pc.getSignersCtx.GetSigners(msgV2) + return signers, msgV2, err } a, err := types.NewAnyWithValue(msg) if err != nil { From 55acfe35ee660924eff226fd9c6aa7bcba919628 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 13 Apr 2023 10:26:32 -0500 Subject: [PATCH 08/52] x/tx v0.5.1 --- go.mod | 2 +- go.sum | 4 ++-- simapp/go.mod | 2 +- simapp/go.sum | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 64c3c69642c4..82784203564a 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( cosmossdk.io/log v1.0.0 cosmossdk.io/math v1.0.0 cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc - cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63 + cosmossdk.io/x/tx v0.5.1 github.com/99designs/keyring v1.2.1 github.com/armon/go-metrics v0.4.1 github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 diff --git a/go.sum b/go.sum index ff24a864a321..9b53e719dae1 100644 --- a/go.sum +++ b/go.sum @@ -51,8 +51,8 @@ cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw= cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc h1:9piuA+NYmhe+SyMPtMoboLw/djgDbrI3dD5TG020Tnk= cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc/go.mod h1:UFF5rmjN7WYVfxo6ArdY/l1+yyWMURBWOmSJypGqFHQ= -cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63 h1:zHqj2VwZ/MStFmR7SUe/7gErOFhL9v2rkjmWPB/st34= -cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= +cosmossdk.io/x/tx v0.5.1 h1:OcHU8ex3JzxDjexSkMovBx8EnJXcqhrRt7msBq/3vqs= +cosmossdk.io/x/tx v0.5.1/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/simapp/go.mod b/simapp/go.mod index f809d53af66c..ed5ceba50f53 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -15,7 +15,7 @@ require ( cosmossdk.io/x/evidence v0.1.0 cosmossdk.io/x/feegrant v0.0.0-20230117113717-50e7c4a4ceff cosmossdk.io/x/nft v0.0.0-20230113085233-fae3332d62fc - cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63 // indirect + cosmossdk.io/x/tx v0.5.1 // indirect cosmossdk.io/x/upgrade v0.0.0-20230127052425-54c8e1568335 github.com/cometbft/cometbft v0.37.1-0.20230411132551-3a91d155e664 github.com/cosmos/cosmos-db v1.0.0-rc.1 diff --git a/simapp/go.sum b/simapp/go.sum index ca30ae7ab564..4b8d53872602 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -202,8 +202,8 @@ cosmossdk.io/log v1.0.0 h1:NGKZ/A5rd4PduDfoscgABklX557PWjQINbosZy/m3Jk= cosmossdk.io/log v1.0.0/go.mod h1:CwX9BLiBruZb7lzLlRr3R231d/fVPUXk8gAdV4LQap0= cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw= cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= -cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63 h1:zHqj2VwZ/MStFmR7SUe/7gErOFhL9v2rkjmWPB/st34= -cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= +cosmossdk.io/x/tx v0.5.1 h1:OcHU8ex3JzxDjexSkMovBx8EnJXcqhrRt7msBq/3vqs= +cosmossdk.io/x/tx v0.5.1/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= From bedd4b995ac031812a212676c18f91959c66e857 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 13 Apr 2023 10:28:40 -0500 Subject: [PATCH 09/52] add err handling --- client/tx/tx.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/tx/tx.go b/client/tx/tx.go index f7970359787d..f66d2eda493d 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -174,6 +174,9 @@ func SignWithPrivKey( // Generate the bytes to be signed. signBytes, err := authsigning.AdaptSigningArgs( ctx, txConfig.TxEncoder(), txConfig.SignModeHandler(), signMode, signerData, priv.PubKey(), txBuilder.GetTx()) + if err != nil { + return sigV2, err + } // Sign those bytes signature, err := priv.Sign(signBytes) From 21927ef319cd0e4daf37a1d2588a5c562278af8d Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 13 Apr 2023 13:10:58 -0500 Subject: [PATCH 10/52] checkpoint, proto gen --- .gitignore | 3 +- baseapp/block_gas_test.go | 14 +++-- baseapp/msg_service_router_test.go | 7 ++- baseapp/testutil/messages.proto | 3 ++ client/tx/tx_test.go | 11 ++-- types/proto.go | 29 ++++++++++ x/auth/ante/feegrant_test.go | 8 ++- x/auth/ante/sigverify_test.go | 3 +- x/auth/signing/verify.go | 2 +- x/auth/tx/aux_test.go | 24 +++++---- x/auth/tx/config.go | 36 ++++++++++--- x/auth/tx/config/config.go | 19 +++++-- x/auth/tx/config/textual.go | 86 ++++++++++++++++++++++-------- x/auth/tx/direct_test.go | 17 +++--- x/auth/tx/mode_handler.go | 41 +++++++++++--- x/auth/tx/testutil/suite.go | 24 ++++++--- 16 files changed, 246 insertions(+), 81 deletions(-) diff --git a/.gitignore b/.gitignore index e6893eaeeb62..e74d19bc514e 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,7 @@ coverage.txt sim_log_file x/genutil/config x/genutil/data +*.fail # Vagrant .vagrant/ @@ -60,4 +61,4 @@ debug_container.log *.out *.synctex.gz /x/genutil/config/priv_validator_key.json -/x/genutil/data/priv_validator_state.json \ No newline at end of file +/x/genutil/data/priv_validator_state.json diff --git a/baseapp/block_gas_test.go b/baseapp/block_gas_test.go index 9c2ddd1c3c2b..45d786fc4c14 100644 --- a/baseapp/block_gas_test.go +++ b/baseapp/block_gas_test.go @@ -5,15 +5,16 @@ import ( "math" "testing" - "cosmossdk.io/depinject" - "cosmossdk.io/log" - sdkmath "cosmossdk.io/math" abci "github.com/cometbft/cometbft/abci/types" cmtjson "github.com/cometbft/cometbft/libs/json" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" dbm "github.com/cosmos/cosmos-db" "github.com/stretchr/testify/require" + "cosmossdk.io/depinject" + "cosmossdk.io/log" + sdkmath "cosmossdk.io/math" + store "cosmossdk.io/store/types" baseapptestutil "github.com/cosmos/cosmos-sdk/baseapp/testutil" @@ -191,6 +192,9 @@ func TestBaseApp_BlockGas(t *testing.T) { } func createTestTx(txConfig client.TxConfig, txBuilder client.TxBuilder, privs []cryptotypes.PrivKey, accNums, accSeqs []uint64, chainID string) (xauthsigning.Tx, []byte, error) { + // TODO + // default mode in handler? + defaultSignMode := signing.SignMode_SIGN_MODE_DIRECT // First round: we gather all the signer infos. We use the "set empty // signature" hack to do that. var sigsV2 []signing.SignatureV2 @@ -198,7 +202,7 @@ func createTestTx(txConfig client.TxConfig, txBuilder client.TxBuilder, privs [] sigV2 := signing.SignatureV2{ PubKey: priv.PubKey(), Data: &signing.SingleSignatureData{ - SignMode: txConfig.SignModeHandler().DefaultMode(), + SignMode: defaultSignMode, Signature: nil, }, Sequence: accSeqs[i], @@ -221,7 +225,7 @@ func createTestTx(txConfig client.TxConfig, txBuilder client.TxBuilder, privs [] Sequence: accSeqs[i], } sigV2, err := tx.SignWithPrivKey( - context.TODO(), txConfig.SignModeHandler().DefaultMode(), signerData, + context.TODO(), defaultSignMode, signerData, txBuilder, priv, txConfig, accSeqs[i]) if err != nil { return nil, nil, err diff --git a/baseapp/msg_service_router_test.go b/baseapp/msg_service_router_test.go index 16f780e078f0..430d2df0000d 100644 --- a/baseapp/msg_service_router_test.go +++ b/baseapp/msg_service_router_test.go @@ -79,6 +79,9 @@ func TestRegisterMsgServiceTwice(t *testing.T) { func TestMsgService(t *testing.T) { priv, _, _ := testdata.KeyTestPubAddr() + // TODO + // default mode? + defaultSignMode := signing.SignMode_SIGN_MODE_DIRECT var ( appBuilder *runtime.AppBuilder @@ -114,7 +117,7 @@ func TestMsgService(t *testing.T) { sigV2 := signing.SignatureV2{ PubKey: priv.PubKey(), Data: &signing.SingleSignatureData{ - SignMode: txConfig.SignModeHandler().DefaultMode(), + SignMode: defaultSignMode, Signature: nil, }, Sequence: 0, @@ -130,7 +133,7 @@ func TestMsgService(t *testing.T) { Sequence: 0, } sigV2, err = tx.SignWithPrivKey( - nil, txConfig.SignModeHandler().DefaultMode(), signerData, //nolint:staticcheck // SA1019: txConfig.SignModeHandler().DefaultMode() is deprecated: use txConfig.SignModeHandler().DefaultMode() instead. + nil, defaultSignMode, signerData, //nolint:staticcheck // SA1019: txConfig.SignModeHandler().DefaultMode() is deprecated: use txConfig.SignModeHandler().DefaultMode() instead. txBuilder, priv, txConfig, 0) require.NoError(t, err) err = txBuilder.SetSignatures(sigV2) diff --git a/baseapp/testutil/messages.proto b/baseapp/testutil/messages.proto index 6a04a94e5c2b..f5e1fb4b5684 100644 --- a/baseapp/testutil/messages.proto +++ b/baseapp/testutil/messages.proto @@ -1,5 +1,6 @@ syntax = "proto3"; +import "cosmos/msg/v1/msg.proto"; import "gogoproto/gogo.proto"; import "google/protobuf/any.proto"; @@ -18,6 +19,8 @@ message MsgCounter2 { message MsgCreateCounterResponse {} message MsgKeyValue { + option (cosmos.msg.v1.signer) = "signer"; + bytes key = 1; bytes value = 2; string signer = 3; diff --git a/client/tx/tx_test.go b/client/tx/tx_test.go index 202ed022c514..a7f8ff3ceb0a 100644 --- a/client/tx/tx_test.go +++ b/client/tx/tx_test.go @@ -6,10 +6,11 @@ import ( "strings" "testing" - sdkmath "cosmossdk.io/math" "github.com/stretchr/testify/require" "google.golang.org/grpc" + sdkmath "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/codec" @@ -28,6 +29,10 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" ) +// TODO +// default mode? +var defaultSignMode = signingtypes.SignMode_SIGN_MODE_DIRECT + func newTestTxConfig() (client.TxConfig, codec.Codec) { encodingConfig := moduletestutil.MakeTestEncodingConfig() return authtx.NewTxConfig(codec.NewProtoCodec(encodingConfig.InterfaceRegistry), authtx.DefaultSignModes), encodingConfig.Codec @@ -81,7 +86,7 @@ func TestCalculateGas(t *testing.T) { txf := tx.Factory{}. WithChainID("test-chain"). - WithTxConfig(txCfg).WithSignMode(txCfg.SignModeHandler().DefaultMode()) + WithTxConfig(txCfg).WithSignMode(defaultSignMode) t.Run(stc.name, func(t *testing.T) { mockClientCtx := mockContext{ @@ -119,7 +124,7 @@ func TestBuildSimTx(t *testing.T) { WithFees("50stake"). WithMemo("memo"). WithChainID("test-chain"). - WithSignMode(txCfg.SignModeHandler().DefaultMode()). + WithSignMode(defaultSignMode). WithKeybase(kb) msg := banktypes.NewMsgSend(sdk.AccAddress("from"), sdk.AccAddress("to"), nil) diff --git a/types/proto.go b/types/proto.go index a7bc8451b846..5968919732bc 100644 --- a/types/proto.go +++ b/types/proto.go @@ -1,5 +1,12 @@ package types +import ( + "sync" + + "github.com/cosmos/gogoproto/proto" + "google.golang.org/protobuf/reflect/protoregistry" +) + // CustomProtobufType defines the interface custom gogo proto types must implement // in order to be used as a "customtype" extension. // @@ -13,3 +20,25 @@ type CustomProtobufType interface { MarshalJSON() ([]byte, error) UnmarshalJSON(data []byte) error } + +var ( + mu sync.Mutex + mergedRegistry *protoregistry.Files +) + +func MergedProtoRegistry() *protoregistry.Files { + if mergedRegistry != nil { + return mergedRegistry + } + + mu.Lock() + defer mu.Unlock() + + var err error + mergedRegistry, err = proto.MergedRegistry() + if err != nil { + panic(err) + } + + return mergedRegistry +} diff --git a/x/auth/ante/feegrant_test.go b/x/auth/ante/feegrant_test.go index 3cee6394f6b6..87d7f91aef10 100644 --- a/x/auth/ante/feegrant_test.go +++ b/x/auth/ante/feegrant_test.go @@ -1,6 +1,7 @@ package ante_test import ( + "context" "errors" "math/rand" "testing" @@ -200,7 +201,7 @@ func genTxWithFeeGranter(gen client.TxConfig, msgs []sdk.Msg, feeAmt sdk.Coins, memo := simulation.RandStringOfLength(r, simulation.RandIntBetween(r, 0, 100)) - signMode := gen.SignModeHandler().DefaultMode() + signMode := signing.SignMode_SIGN_MODE_DIRECT // 1st round: set SignatureV2 with empty signatures, to set correct // signer infos. @@ -235,7 +236,10 @@ func genTxWithFeeGranter(gen client.TxConfig, msgs []sdk.Msg, feeAmt sdk.Coins, AccountNumber: accNums[i], Sequence: accSeqs[i], } - signBytes, err := gen.SignModeHandler().GetSignBytes(signMode, signerData, tx.GetTx()) + signBytes, err := authsign.AdaptSigningArgs( + context.Background(), gen.TxEncoder(), gen.SignModeHandler(), signMode, signerData, p.PubKey(), + tx.GetTx()) + if err != nil { panic(err) } diff --git a/x/auth/ante/sigverify_test.go b/x/auth/ante/sigverify_test.go index 2af60c81a8ce..73906460f2ee 100644 --- a/x/auth/ante/sigverify_test.go +++ b/x/auth/ante/sigverify_test.go @@ -211,7 +211,8 @@ func TestSigVerification(t *testing.T) { txSigs[0] = signing.SignatureV2{ PubKey: tc.privs[0].PubKey(), Data: &signing.SingleSignatureData{ - SignMode: suite.clientCtx.TxConfig.SignModeHandler().DefaultMode(), + // TODO: default sign mode + SignMode: signing.SignMode_SIGN_MODE_DIRECT, Signature: badSig, }, Sequence: tc.accSeqs[0], diff --git a/x/auth/signing/verify.go b/x/auth/signing/verify.go index 459151db3a89..2eb524209068 100644 --- a/x/auth/signing/verify.go +++ b/x/auth/signing/verify.go @@ -154,7 +154,7 @@ func AdaptSigningArgs( if err != nil { return nil, err } - decodeCtx, err := decode.NewDecoder(decode.Options{}) + decodeCtx, err := decode.NewDecoder(decode.Options{ProtoFiles: sdk.MergedProtoRegistry()}) if err != nil { return nil, err } diff --git a/x/auth/tx/aux_test.go b/x/auth/tx/aux_test.go index 97416a9df891..d08ee5a413bd 100644 --- a/x/auth/tx/aux_test.go +++ b/x/auth/tx/aux_test.go @@ -1,6 +1,7 @@ package tx_test import ( + "context" "testing" "github.com/stretchr/testify/require" @@ -130,17 +131,18 @@ func TestBuilderWithAux(t *testing.T) { PubKey: feepayerPk, Sequence: 15, }) - signBz, err = txConfig.SignModeHandler().GetSignBytes( - signing.SignMode_SIGN_MODE_DIRECT, - authsigning.SignerData{ - Address: feepayerAddr.String(), - ChainID: chainID, - AccountNumber: 11, - Sequence: 15, - PubKey: feepayerPk, - }, - w.GetTx(), - ) + signerData := authsigning.SignerData{ + Address: feepayerAddr.String(), + ChainID: chainID, + AccountNumber: 11, + Sequence: 15, + PubKey: feepayerPk, + } + + signBz, err = authsigning.AdaptSigningArgs( + context.Background(), txConfig.TxEncoder(), txConfig.SignModeHandler(), signing.SignMode_SIGN_MODE_DIRECT, + signerData, feepayerPk, w.GetTx()) + require.NoError(t, err) feepayerSig, err := feepayerPriv.Sign(signBz) require.NoError(t, err) diff --git a/x/auth/tx/config.go b/x/auth/tx/config.go index 9612519d247f..796b4bf3eb5a 100644 --- a/x/auth/tx/config.go +++ b/x/auth/tx/config.go @@ -3,9 +3,11 @@ package tx import ( "fmt" - txsigning "cosmossdk.io/x/tx/signing" - "cosmossdk.io/x/tx/signing/textual" + "google.golang.org/protobuf/reflect/protoregistry" + txsigning "cosmossdk.io/x/tx/signing" + "cosmossdk.io/x/tx/signing/aminojson" + "cosmossdk.io/x/tx/signing/directaux" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -27,6 +29,7 @@ type config struct { // NOTE: Use NewTxConfigWithHandler to provide a custom signing handler in case the sign mode // is not supported by default (eg: SignMode_SIGN_MODE_EIP_191). Use NewTxConfigWithTextual // to enable SIGN_MODE_TEXTUAL (for testing purposes for now). +// TODO: collapse enabledSignModes and customSignModes func NewTxConfig(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signingtypes.SignMode, customSignModes ...txsigning.SignModeHandler) client.TxConfig { for _, m := range enabledSignModes { @@ -35,16 +38,37 @@ func NewTxConfig(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signin } } - return NewTxConfigWithHandler(protoCodec, makeSignModeHandler(enabledSignModes, &textual.SignModeHandler{}, - customSignModes...)) + // prefer depinject usage but permit this; it is primary used in tests. + protoFiles := sdk.MergedProtoRegistry() + typeResolver := protoregistry.GlobalTypes + signersContext, err := txsigning.NewGetSignersContext(txsigning.GetSignersOptions{ProtoFiles: protoFiles}) + if err != nil { + panic(err) + } + + aminoJsonEncoder := aminojson.NewAminoJSON() + signModeOptions := SignModeOptions{ + DirectAux: &directaux.SignModeHandlerOptions{ + FileResolver: protoFiles, + TypeResolver: typeResolver, + SignersContext: signersContext, + }, + AminoJSON: &aminojson.SignModeHandlerOptions{ + FileResolver: protoFiles, + TypeResolver: typeResolver, + Encoder: &aminoJsonEncoder, + }, + } + + return NewTxConfigWithHandler(protoCodec, makeSignModeHandler(enabledSignModes, signModeOptions, customSignModes...)) } // NewTxConfigWithTextual is like NewTxConfig with the ability to add // a SIGN_MODE_TEXTUAL renderer. It is currently still EXPERIMENTAL, for should // be used for TESTING purposes only, until Textual is fully released. func NewTxConfigWithTextual(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signingtypes.SignMode, - textual *textual.SignModeHandler, customSignModes ...txsigning.SignModeHandler) client.TxConfig { - return NewTxConfigWithHandler(protoCodec, makeSignModeHandler(enabledSignModes, textual, customSignModes...)) + signModeOptions SignModeOptions, customSignModes ...txsigning.SignModeHandler) client.TxConfig { + return NewTxConfigWithHandler(protoCodec, makeSignModeHandler(enabledSignModes, signModeOptions, customSignModes...)) } // NewTxConfigWithHandler returns a new protobuf TxConfig using the provided ProtoCodec and signing handler. diff --git a/x/auth/tx/config/config.go b/x/auth/tx/config/config.go index 0f69e3662100..b6d3464fd15b 100644 --- a/x/auth/tx/config/config.go +++ b/x/auth/tx/config/config.go @@ -21,6 +21,7 @@ import ( func init() { appmodule.Register(&txconfigv1.Config{}, appmodule.Provide(ProvideModule), + appmodule.Provide(ProvideSignModeOptions), ) } @@ -34,7 +35,7 @@ type ModuleInputs struct { // BankKeeper is the expected bank keeper to be passed to AnteHandlers BankKeeper authtypes.BankKeeper `optional:"true"` // TxBankKeeper is the expected bank keeper to be passed to Textual - TxBankKeeper BankKeeper + tx.SignModeOptions FeeGrantKeeper ante.FeegrantKeeper `optional:"true"` CustomSignModeHandlers func() []txsigning.SignModeHandler `optional:"true"` @@ -47,16 +48,24 @@ type ModuleOutputs struct { BaseAppOption runtime.BaseAppOption } -func ProvideModule(in ModuleInputs) ModuleOutputs { - textual, err := NewTextualWithBankKeeper(in.TxBankKeeper) +// ProvideSignModeOptions provides the default x/tx SignModeOptions for the SDK. +// TODO +// probably move to x/tx. I would do this now but I'm blocked; latest x/tx does not compile or interop with latest sdk +func ProvideSignModeOptions(bk BankKeeper) tx.SignModeOptions { + opts, err := NewTextualWithBankKeeper(bk) if err != nil { panic(err) } + return opts +} + +func ProvideModule(in ModuleInputs) ModuleOutputs { var txConfig client.TxConfig if in.CustomSignModeHandlers == nil { - txConfig = tx.NewTxConfigWithTextual(in.ProtoCodecMarshaler, tx.DefaultSignModes, textual) + txConfig = tx.NewTxConfigWithTextual(in.ProtoCodecMarshaler, tx.DefaultSignModes, in.SignModeOptions) } else { - txConfig = tx.NewTxConfigWithTextual(in.ProtoCodecMarshaler, tx.DefaultSignModes, textual, in.CustomSignModeHandlers()...) + txConfig = tx.NewTxConfigWithTextual(in.ProtoCodecMarshaler, tx.DefaultSignModes, in.SignModeOptions, + in.CustomSignModeHandlers()...) } baseAppOption := func(app *baseapp.BaseApp) { diff --git a/x/auth/tx/config/textual.go b/x/auth/tx/config/textual.go index 3a93cb689d17..2d686fed0b21 100644 --- a/x/auth/tx/config/textual.go +++ b/x/auth/tx/config/textual.go @@ -3,14 +3,18 @@ package tx import ( "context" - gogoproto "github.com/cosmos/gogoproto/proto" "google.golang.org/grpc" "google.golang.org/grpc/codes" grpcstatus "google.golang.org/grpc/status" + "google.golang.org/protobuf/reflect/protoregistry" bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" + txsigning "cosmossdk.io/x/tx/signing" + "cosmossdk.io/x/tx/signing/aminojson" + "cosmossdk.io/x/tx/signing/directaux" "cosmossdk.io/x/tx/signing/textual" - + types2 "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/tx" "github.com/cosmos/cosmos-sdk/x/bank/types" ) @@ -22,26 +26,46 @@ import ( // // clientCtx := client.GetClientContextFromCmd(cmd) // txt := tx.NewTextualWithGRPCConn(clientCtxx) -func NewTextualWithGRPCConn(grpcConn grpc.ClientConnInterface) (*textual.SignModeHandler, error) { - protoFiles, err := gogoproto.MergedRegistry() +// +// TODO: rename +func NewTextualWithGRPCConn(grpcConn grpc.ClientConnInterface) (tx.SignModeOptions, error) { + protoFiles := types2.MergedProtoRegistry() + typeResolver := protoregistry.GlobalTypes + signersContext, err := txsigning.NewGetSignersContext(txsigning.GetSignersOptions{ProtoFiles: protoFiles}) if err != nil { - return nil, err + return tx.SignModeOptions{}, err } - return textual.NewSignModeHandler(textual.SignModeOptions{ - CoinMetadataQuerier: func(ctx context.Context, denom string) (*bankv1beta1.Metadata, error) { - bankQueryClient := bankv1beta1.NewQueryClient(grpcConn) - res, err := bankQueryClient.DenomMetadata(ctx, &bankv1beta1.QueryDenomMetadataRequest{ - Denom: denom, - }) - if err != nil { - return nil, metadataExists(err) - } + aminoJsonEncoder := aminojson.NewAminoJSON() + signModeOptions := tx.SignModeOptions{ + DirectAux: &directaux.SignModeHandlerOptions{ + FileResolver: protoFiles, + TypeResolver: typeResolver, + SignersContext: signersContext, + }, + AminoJSON: &aminojson.SignModeHandlerOptions{ + FileResolver: protoFiles, + TypeResolver: typeResolver, + Encoder: &aminoJsonEncoder, + }, + Textual: &textual.SignModeOptions{ + CoinMetadataQuerier: func(ctx context.Context, denom string) (*bankv1beta1.Metadata, error) { + bankQueryClient := bankv1beta1.NewQueryClient(grpcConn) + res, err := bankQueryClient.DenomMetadata(ctx, &bankv1beta1.QueryDenomMetadataRequest{ + Denom: denom, + }) + if err != nil { + return nil, metadataExists(err) + } - return res.Metadata, nil + return res.Metadata, nil + }, + FileResolver: protoFiles, + TypeResolver: typeResolver, }, - FileResolver: protoFiles, - }) + } + + return signModeOptions, nil } // NewTextualWithBankKeeper creates a new Textual struct using the given @@ -50,13 +74,16 @@ func NewTextualWithGRPCConn(grpcConn grpc.ClientConnInterface) (*textual.SignMod // Note: Once we switch to ADR-033, and keepers become ADR-033 clients to each // other, this function could probably be deprecated in favor of // `NewTextualWithGRPCConn`. -func NewTextualWithBankKeeper(bk BankKeeper) (*textual.SignModeHandler, error) { - protoFiles, err := gogoproto.MergedRegistry() +// TODO: rename +func NewTextualWithBankKeeper(bk BankKeeper) (tx.SignModeOptions, error) { + protoFiles := types2.MergedProtoRegistry() + typeResolver := protoregistry.GlobalTypes + signersContext, err := txsigning.NewGetSignersContext(txsigning.GetSignersOptions{ProtoFiles: protoFiles}) if err != nil { - return nil, err + return tx.SignModeOptions{}, err } - return textual.NewSignModeHandler(textual.SignModeOptions{ + txtOpts := textual.SignModeOptions{ CoinMetadataQuerier: func(ctx context.Context, denom string) (*bankv1beta1.Metadata, error) { res, err := bk.DenomMetadata(ctx, &types.QueryDenomMetadataRequest{Denom: denom}) if err != nil { @@ -86,7 +113,22 @@ func NewTextualWithBankKeeper(bk BankKeeper) (*textual.SignModeHandler, error) { return m, nil }, FileResolver: protoFiles, - }) + } + + aminoJsonEncoder := aminojson.NewAminoJSON() + return tx.SignModeOptions{ + Textual: &txtOpts, + DirectAux: &directaux.SignModeHandlerOptions{ + FileResolver: protoFiles, + TypeResolver: typeResolver, + SignersContext: signersContext, + }, + AminoJSON: &aminojson.SignModeHandlerOptions{ + FileResolver: protoFiles, + TypeResolver: typeResolver, + Encoder: &aminoJsonEncoder, + }, + }, nil } // metadataExists parses the error, and only propagates the error if it's diff --git a/x/auth/tx/direct_test.go b/x/auth/tx/direct_test.go index 22309639656e..7022de19adcf 100644 --- a/x/auth/tx/direct_test.go +++ b/x/auth/tx/direct_test.go @@ -1,6 +1,7 @@ package tx import ( + "context" "fmt" "testing" @@ -64,9 +65,10 @@ func TestDirectModeHandler(t *testing.T) { require.NoError(t, err) t.Log("verify modes and default-mode") - modeHandler := txConfig.SignModeHandler() - require.Equal(t, modeHandler.DefaultMode(), signingtypes.SignMode_SIGN_MODE_DIRECT) - require.Len(t, modeHandler.Modes(), 1) + defaultSignMode := signingtypes.SignMode_SIGN_MODE_DIRECT + require.Equal(t, defaultSignMode, signingtypes.SignMode_SIGN_MODE_DIRECT) + // TODO, once API is cleaned up, this should be 1 + //require.Len(t, modeHandler.Modes(), 1) signingData := signing.SignerData{ Address: addr.String(), @@ -75,8 +77,9 @@ func TestDirectModeHandler(t *testing.T) { PubKey: pubkey, } - signBytes, err := modeHandler.GetSignBytes(signingtypes.SignMode_SIGN_MODE_DIRECT, signingData, txBuilder.GetTx()) - + signBytes, err := signing.AdaptSigningArgs( + context.Background(), txConfig.TxEncoder(), txConfig.SignModeHandler(), defaultSignMode, signingData, pubkey, + txBuilder.GetTx()) require.NoError(t, err) require.NotNil(t, signBytes) @@ -120,7 +123,9 @@ func TestDirectModeHandler(t *testing.T) { require.NoError(t, err) err = txBuilder.SetSignatures(sig) require.NoError(t, err) - signBytes, err = modeHandler.GetSignBytes(signingtypes.SignMode_SIGN_MODE_DIRECT, signingData, txBuilder.GetTx()) + signBytes, err = signing.AdaptSigningArgs( + context.Background(), txConfig.TxEncoder(), txConfig.SignModeHandler(), defaultSignMode, signingData, pubkey, + txBuilder.GetTx()) require.NoError(t, err) require.Equal(t, expectedSignBytes, signBytes) diff --git a/x/auth/tx/mode_handler.go b/x/auth/tx/mode_handler.go index a46546f4ffa1..14bb397208f8 100644 --- a/x/auth/tx/mode_handler.go +++ b/x/auth/tx/mode_handler.go @@ -2,12 +2,22 @@ package tx import ( txsigning "cosmossdk.io/x/tx/signing" - stdsigning "cosmossdk.io/x/tx/signing/std" + "cosmossdk.io/x/tx/signing/aminojson" + "cosmossdk.io/x/tx/signing/direct" + "cosmossdk.io/x/tx/signing/directaux" "cosmossdk.io/x/tx/signing/textual" - signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" ) +type SignModeOptions struct { + // Textual are options for SIGN_MODE_TEXTUAL + Textual *textual.SignModeOptions + // DirectAux are options for SIGN_MODE_DIRECT_AUX + DirectAux *directaux.SignModeHandlerOptions + // AminoJSON are options for SIGN_MODE_LEGACY_AMINO_JSON + AminoJSON *aminojson.SignModeHandlerOptions +} + // DefaultSignModes are the default sign modes enabled for protobuf transactions. var DefaultSignModes = []signingtypes.SignMode{ signingtypes.SignMode_SIGN_MODE_DIRECT, @@ -25,7 +35,7 @@ var DefaultSignModes = []signingtypes.SignMode{ // SIGN_MODE_DIRECT, SIGN_MODE_DIRECT_AUX and SIGN_MODE_LEGACY_AMINO_JSON. func makeSignModeHandler( modes []signingtypes.SignMode, - txt *textual.SignModeHandler, + opts SignModeOptions, customSignModes ...txsigning.SignModeHandler, ) *txsigning.HandlerMap { // TODO parity @@ -60,10 +70,25 @@ func makeSignModeHandler( // modes[0], // handlers, //) - opts := stdsigning.SignModeOptions{} - hmap, err := opts.HandlerMap() - if err != nil { - panic(err) + + handlers := []txsigning.SignModeHandler{direct.SignModeHandler{}} + if opts.Textual != nil { + h, err := textual.NewSignModeHandler(*opts.Textual) + if err != nil { + panic(err) + } + handlers = append(handlers, h) + } + if opts.DirectAux != nil { + h, err := directaux.NewSignModeHandler(*opts.DirectAux) + if err != nil { + panic(err) + } + handlers = append(handlers, h) + } + if opts.AminoJSON != nil { + handlers = append(handlers, aminojson.NewSignModeHandler(*opts.AminoJSON)) } - return hmap + handlers = append(handlers, customSignModes...) + return txsigning.NewHandlerMap(handlers...) } diff --git a/x/auth/tx/testutil/suite.go b/x/auth/tx/testutil/suite.go index 924f2366ca3b..7f7b56de18c6 100644 --- a/x/auth/tx/testutil/suite.go +++ b/x/auth/tx/testutil/suite.go @@ -2,9 +2,11 @@ package testutil import ( "bytes" + "context" "github.com/stretchr/testify/suite" + signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1" "github.com/cosmos/cosmos-sdk/client" kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" @@ -96,17 +98,21 @@ func (s *TxConfigTestSuite) TestTxBuilderSetSignatures() { s.Require().Error(txBuilder.GetTx().ValidateBasic()) signModeHandler := s.TxConfig.SignModeHandler() - s.Require().Contains(signModeHandler.Modes(), signModeHandler.DefaultMode()) + s.Require().Contains(signModeHandler.SupportedModes(), signingv1beta1.SignMode_SIGN_MODE_DIRECT) + + // TODO + // default sign mode in handler? + defaultSignMode := signingtypes.SignMode_SIGN_MODE_DIRECT // set SignatureV2 without actual signature bytes seq1 := uint64(2) // Arbitrary account sequence - sigData1 := &signingtypes.SingleSignatureData{SignMode: signModeHandler.DefaultMode()} + sigData1 := &signingtypes.SingleSignatureData{SignMode: defaultSignMode} sig1 := signingtypes.SignatureV2{PubKey: pubkey, Data: sigData1, Sequence: seq1} mseq := uint64(4) // Arbitrary account sequence msigData := multisig.NewMultisig(2) - multisig.AddSignature(msigData, &signingtypes.SingleSignatureData{SignMode: signModeHandler.DefaultMode()}, 0) - multisig.AddSignature(msigData, &signingtypes.SingleSignatureData{SignMode: signModeHandler.DefaultMode()}, 1) + multisig.AddSignature(msigData, &signingtypes.SingleSignatureData{SignMode: defaultSignMode}, 0) + multisig.AddSignature(msigData, &signingtypes.SingleSignatureData{SignMode: defaultSignMode}, 1) msig := signingtypes.SignatureV2{PubKey: multisigPk, Data: msigData, Sequence: mseq} // fail validation without required signers @@ -134,7 +140,8 @@ func (s *TxConfigTestSuite) TestTxBuilderSetSignatures() { Sequence: seq1, PubKey: pubkey, } - signBytes, err := signModeHandler.GetSignBytes(signModeHandler.DefaultMode(), signerData, sigTx) + signBytes, err := signing.AdaptSigningArgs(context.Background(), s.TxConfig.TxEncoder(), + s.TxConfig.SignModeHandler(), defaultSignMode, signerData, pubkey, sigTx) s.Require().NoError(err) sigBz, err := privKey.Sign(signBytes) s.Require().NoError(err) @@ -146,7 +153,8 @@ func (s *TxConfigTestSuite) TestTxBuilderSetSignatures() { Sequence: mseq, PubKey: multisigPk, } - mSignBytes, err := signModeHandler.GetSignBytes(signModeHandler.DefaultMode(), signerData, sigTx) + mSignBytes, err := signing.AdaptSigningArgs(context.Background(), s.TxConfig.TxEncoder(), + s.TxConfig.SignModeHandler(), defaultSignMode, signerData, multisigPk, sigTx) s.Require().NoError(err) mSigBz1, err := privKey.Sign(mSignBytes) s.Require().NoError(err) @@ -154,10 +162,10 @@ func (s *TxConfigTestSuite) TestTxBuilderSetSignatures() { s.Require().NoError(err) msigData = multisig.NewMultisig(2) multisig.AddSignature(msigData, &signingtypes.SingleSignatureData{ - SignMode: signModeHandler.DefaultMode(), Signature: mSigBz1, + SignMode: defaultSignMode, Signature: mSigBz1, }, 0) multisig.AddSignature(msigData, &signingtypes.SingleSignatureData{ - SignMode: signModeHandler.DefaultMode(), Signature: mSigBz2, + SignMode: defaultSignMode, Signature: mSigBz2, }, 0) // set signature From 623bacf96bda96e17544c55f891333d8916d592d Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 13 Apr 2023 14:11:12 -0500 Subject: [PATCH 11/52] adjust lots of tests --- baseapp/testutil/messages.pb.go | 51 ++++++++++++++------------- testutil/testdata/testpb/tx.proto | 1 + testutil/testdata/testpb/tx.pulsar.go | 33 ++++++++--------- testutil/testdata/tx.pb.go | 20 +++++------ x/auth/ante/feegrant_test.go | 7 ++-- x/auth/ante/sigverify.go | 2 +- x/auth/ante/testutil_test.go | 10 ++++-- 7 files changed, 69 insertions(+), 55 deletions(-) diff --git a/baseapp/testutil/messages.pb.go b/baseapp/testutil/messages.pb.go index 6ab32a7ce418..533a75289217 100644 --- a/baseapp/testutil/messages.pb.go +++ b/baseapp/testutil/messages.pb.go @@ -7,6 +7,7 @@ import ( context "context" fmt "fmt" _ "github.com/cosmos/cosmos-sdk/codec/types" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/cosmos/gogoproto/grpc" proto "github.com/cosmos/gogoproto/proto" @@ -276,30 +277,32 @@ func init() { func init() { proto.RegisterFile("messages.proto", fileDescriptor_4dc296cbfe5ffcd5) } var fileDescriptor_4dc296cbfe5ffcd5 = []byte{ - // 364 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x92, 0x4f, 0x6b, 0xe2, 0x50, - 0x14, 0xc5, 0xcd, 0x84, 0x51, 0xe7, 0xea, 0xcc, 0x48, 0x90, 0x21, 0x66, 0x20, 0x48, 0x16, 0x83, - 0x1b, 0x13, 0xc8, 0xec, 0xc6, 0xdd, 0x0c, 0x83, 0x2d, 0xc5, 0x0a, 0x29, 0x74, 0xd1, 0x8d, 0xbc, - 0xc4, 0xeb, 0x33, 0x98, 0xbc, 0x17, 0xf2, 0x5e, 0x0a, 0x7e, 0x8b, 0x7e, 0xac, 0x2e, 0x5d, 0x76, - 0x59, 0xf4, 0x8b, 0x94, 0xfc, 0xd3, 0x2e, 0x6a, 0x57, 0x5d, 0xe5, 0x9c, 0x73, 0xc9, 0xef, 0xe4, - 0x5e, 0x02, 0xdf, 0x62, 0x14, 0x82, 0x50, 0x14, 0x76, 0x92, 0x72, 0xc9, 0x8d, 0x3e, 0xe5, 0x94, - 0x17, 0xd2, 0xc9, 0x55, 0x95, 0x0e, 0x28, 0xe7, 0x34, 0x42, 0xa7, 0x70, 0x7e, 0xb6, 0x72, 0x08, - 0xdb, 0x96, 0x23, 0xeb, 0x1a, 0x60, 0x26, 0xe8, 0x3f, 0x9e, 0x31, 0x89, 0xa9, 0xa6, 0x43, 0x2b, - 0x28, 0xa5, 0xae, 0x0c, 0x95, 0x91, 0xea, 0xd5, 0x56, 0xfb, 0x05, 0xdf, 0x57, 0x24, 0x8c, 0x16, - 0x9c, 0x2d, 0xd6, 0x84, 0x2d, 0x23, 0x4c, 0xf5, 0x4f, 0x43, 0x65, 0xd4, 0xf6, 0xbe, 0xe6, 0xf1, - 0x9c, 0x5d, 0x94, 0xa1, 0x35, 0x87, 0xce, 0x89, 0xe7, 0x7e, 0x00, 0xd0, 0x00, 0x3d, 0x07, 0xa6, - 0x48, 0x24, 0x56, 0x58, 0x0f, 0x45, 0xc2, 0x99, 0x40, 0x6b, 0x56, 0x94, 0x5d, 0xe1, 0xf6, 0x96, - 0x44, 0x19, 0x6a, 0x3d, 0x50, 0x37, 0xb8, 0x2d, 0x8a, 0xba, 0x5e, 0x2e, 0xb5, 0x3e, 0x7c, 0xbe, - 0xcf, 0x47, 0x05, 0xba, 0xeb, 0x95, 0x46, 0xfb, 0x01, 0x4d, 0x11, 0x52, 0x86, 0xa9, 0xae, 0x0e, - 0x95, 0xd1, 0x17, 0xaf, 0x72, 0xd6, 0x4f, 0x18, 0x1c, 0xab, 0x6a, 0x68, 0xdd, 0xe5, 0xfe, 0x87, - 0x56, 0x7d, 0xa5, 0x3f, 0xd0, 0xbb, 0x64, 0x41, 0x8a, 0x31, 0x32, 0x59, 0x67, 0x1d, 0xfb, 0xb4, - 0xb6, 0x31, 0xb0, 0xcf, 0x7d, 0xb2, 0x3b, 0x85, 0xf6, 0xf1, 0x38, 0x93, 0x37, 0x38, 0xdd, 0x57, - 0x1c, 0xf7, 0x3d, 0xd0, 0x04, 0xda, 0xc7, 0xc5, 0x1d, 0x50, 0x6f, 0x50, 0x96, 0xef, 0xd6, 0xa1, - 0x61, 0xd8, 0x67, 0x97, 0xf9, 0x3b, 0x7d, 0xdc, 0x9b, 0xca, 0x6e, 0x6f, 0x2a, 0xcf, 0x7b, 0x53, - 0x79, 0x38, 0x98, 0x8d, 0xdd, 0xc1, 0x6c, 0x3c, 0x1d, 0xcc, 0xc6, 0xdd, 0x98, 0x86, 0x72, 0x9d, - 0xf9, 0x76, 0xc0, 0x63, 0x27, 0xe0, 0x22, 0xe6, 0xa2, 0x7a, 0x8c, 0xc5, 0x72, 0xe3, 0xf8, 0x44, - 0x20, 0x49, 0x12, 0x47, 0xa2, 0x90, 0x99, 0x0c, 0x23, 0xbf, 0x59, 0xfc, 0x45, 0xbf, 0x5f, 0x02, - 0x00, 0x00, 0xff, 0xff, 0x23, 0xdc, 0x12, 0x4d, 0x88, 0x02, 0x00, 0x00, + // 387 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x92, 0xcf, 0xca, 0xd3, 0x40, + 0x14, 0xc5, 0x1b, 0x83, 0xdf, 0x57, 0x6f, 0xab, 0x96, 0x50, 0x34, 0x8d, 0x10, 0x4a, 0x16, 0x52, + 0x84, 0x66, 0x30, 0xee, 0xda, 0x9d, 0x22, 0x55, 0x44, 0x0b, 0x11, 0x5c, 0x74, 0x53, 0x26, 0xe9, + 0xed, 0x34, 0x34, 0x99, 0x09, 0x99, 0x49, 0xa1, 0x5b, 0x9f, 0xc0, 0x47, 0xf1, 0x31, 0x5c, 0x76, + 0xe9, 0x52, 0xda, 0x85, 0xaf, 0x21, 0xf9, 0xd7, 0xba, 0xb0, 0xae, 0xbe, 0xd5, 0xdc, 0x73, 0x2e, + 0xf9, 0x9d, 0xcc, 0x61, 0xe0, 0x51, 0x82, 0x52, 0x52, 0x86, 0xd2, 0x4d, 0x33, 0xa1, 0x84, 0xf5, + 0x34, 0x14, 0x32, 0x11, 0x92, 0x24, 0x92, 0x91, 0xdd, 0xcb, 0xe2, 0xa8, 0x17, 0x7d, 0x26, 0x98, + 0x28, 0x47, 0x52, 0x4c, 0xb5, 0x3b, 0x60, 0x42, 0xb0, 0x18, 0x49, 0xa9, 0x82, 0x7c, 0x4d, 0x28, + 0xdf, 0x57, 0x2b, 0xe7, 0x13, 0xc0, 0x47, 0xc9, 0xde, 0x88, 0x9c, 0x2b, 0xcc, 0x0c, 0x13, 0x6e, + 0xc3, 0x6a, 0x34, 0xb5, 0xa1, 0x36, 0xd2, 0xfd, 0x46, 0x1a, 0xcf, 0xe1, 0xf1, 0x9a, 0x46, 0xf1, + 0x52, 0xf0, 0xe5, 0x86, 0xf2, 0x55, 0x8c, 0x99, 0x79, 0x6f, 0xa8, 0x8d, 0xda, 0xfe, 0xc3, 0xc2, + 0x9e, 0xf3, 0x77, 0x95, 0xe9, 0xcc, 0xa1, 0x73, 0xe1, 0x79, 0x77, 0x00, 0xb4, 0xc0, 0x2c, 0x80, + 0x19, 0x52, 0x85, 0x35, 0xd6, 0x47, 0x99, 0x0a, 0x2e, 0xd1, 0x59, 0x94, 0x61, 0x1f, 0x70, 0xff, + 0x85, 0xc6, 0x39, 0x1a, 0x3d, 0xd0, 0xb7, 0xb8, 0x2f, 0x83, 0xba, 0x7e, 0x31, 0x1a, 0x7d, 0xb8, + 0xbf, 0x2b, 0x56, 0x25, 0xba, 0xeb, 0x57, 0xc2, 0x78, 0x02, 0x37, 0x32, 0x62, 0x1c, 0x33, 0x53, + 0x1f, 0x6a, 0xa3, 0x07, 0x7e, 0xad, 0x26, 0x9d, 0xaf, 0xbf, 0xbf, 0xbf, 0xa8, 0x85, 0xf3, 0x0c, + 0x06, 0xe7, 0xdc, 0x26, 0xa1, 0x09, 0xf6, 0xde, 0xc2, 0x6d, 0x53, 0xd9, 0x04, 0x7a, 0xef, 0x79, + 0x98, 0x61, 0x82, 0x5c, 0x35, 0x5e, 0xc7, 0xbd, 0x74, 0x60, 0x0d, 0xdc, 0x6b, 0xff, 0xef, 0xcd, + 0xa0, 0x7d, 0x6e, 0x6a, 0xfa, 0x0f, 0x4e, 0xf7, 0x2f, 0x8e, 0xf7, 0x3f, 0xd0, 0x14, 0xda, 0xe7, + 0x16, 0x08, 0xe8, 0x9f, 0x51, 0x55, 0xdf, 0x36, 0xa6, 0x65, 0xb9, 0x57, 0x2f, 0xf3, 0x7a, 0xf6, + 0xe3, 0x68, 0x6b, 0x87, 0xa3, 0xad, 0xfd, 0x3a, 0xda, 0xda, 0xb7, 0x93, 0xdd, 0x3a, 0x9c, 0xec, + 0xd6, 0xcf, 0x93, 0xdd, 0x5a, 0x8c, 0x59, 0xa4, 0x36, 0x79, 0xe0, 0x86, 0x22, 0x21, 0xf5, 0x8b, + 0xab, 0x8e, 0xb1, 0x5c, 0x6d, 0x49, 0x40, 0x25, 0xd2, 0x34, 0x25, 0x0a, 0xa5, 0xca, 0x55, 0x14, + 0x07, 0x37, 0xe5, 0x93, 0x7a, 0xf5, 0x27, 0x00, 0x00, 0xff, 0xff, 0xea, 0x9d, 0x1c, 0xeb, 0xae, + 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/testutil/testdata/testpb/tx.proto b/testutil/testdata/testpb/tx.proto index 464e3390478b..c97c402fce03 100644 --- a/testutil/testdata/testpb/tx.proto +++ b/testutil/testdata/testpb/tx.proto @@ -30,5 +30,6 @@ message MsgCreateDogResponse { // https://github.com/cosmos/cosmos-sdk/issues/6213. message TestMsg { option (gogoproto.goproto_getters) = false; + option (cosmos.msg.v1.signer) = "signers"; repeated string signers = 1; } diff --git a/testutil/testdata/testpb/tx.pulsar.go b/testutil/testdata/testpb/tx.pulsar.go index b0d653076627..217cad7c6c83 100644 --- a/testutil/testdata/testpb/tx.pulsar.go +++ b/testutil/testdata/testpb/tx.pulsar.go @@ -1557,24 +1557,25 @@ var file_testpb_tx_proto_rawDesc = []byte{ 0x77, 0x6e, 0x65, 0x72, 0x3a, 0x0a, 0x82, 0xe7, 0xb0, 0x2a, 0x05, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x22, 0x2a, 0x0a, 0x14, 0x4d, 0x73, 0x67, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x29, 0x0a, 0x07, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x35, 0x0a, 0x07, 0x54, 0x65, 0x73, 0x74, 0x4d, 0x73, 0x67, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x07, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, - 0x73, 0x3a, 0x04, 0x88, 0xa0, 0x1f, 0x00, 0x32, 0x4d, 0x0a, 0x03, 0x4d, 0x73, 0x67, 0x12, 0x3f, - 0x0a, 0x09, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x67, 0x12, 0x14, 0x2e, 0x74, 0x65, - 0x73, 0x74, 0x70, 0x62, 0x2e, 0x4d, 0x73, 0x67, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x6f, - 0x67, 0x1a, 0x1c, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x4d, 0x73, 0x67, 0x43, 0x72, - 0x65, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x1a, - 0x05, 0x80, 0xe7, 0xb0, 0x2a, 0x01, 0x42, 0x8b, 0x01, 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x2e, 0x74, - 0x65, 0x73, 0x74, 0x70, 0x62, 0x42, 0x07, 0x54, 0x78, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, - 0x5a, 0x3c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x73, - 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, 0x2f, 0x74, - 0x65, 0x73, 0x74, 0x75, 0x74, 0x69, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x64, 0x61, 0x74, 0x61, - 0x5f, 0x70, 0x75, 0x6c, 0x73, 0x61, 0x72, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0xa2, 0x02, - 0x03, 0x54, 0x58, 0x58, 0xaa, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xca, 0x02, 0x06, - 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xe2, 0x02, 0x12, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x5c, - 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x06, 0x54, 0x65, - 0x73, 0x74, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x73, 0x3a, 0x10, 0x88, 0xa0, 0x1f, 0x00, 0x82, 0xe7, 0xb0, 0x2a, 0x07, 0x73, 0x69, 0x67, 0x6e, + 0x65, 0x72, 0x73, 0x32, 0x4d, 0x0a, 0x03, 0x4d, 0x73, 0x67, 0x12, 0x3f, 0x0a, 0x09, 0x43, 0x72, + 0x65, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x67, 0x12, 0x14, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, + 0x2e, 0x4d, 0x73, 0x67, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x67, 0x1a, 0x1c, 0x2e, + 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x4d, 0x73, 0x67, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, + 0x44, 0x6f, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x1a, 0x05, 0x80, 0xe7, 0xb0, + 0x2a, 0x01, 0x42, 0x8b, 0x01, 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, + 0x62, 0x42, 0x07, 0x54, 0x78, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x3c, 0x67, 0x69, + 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, + 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x75, + 0x74, 0x69, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x70, 0x75, 0x6c, + 0x73, 0x61, 0x72, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0xa2, 0x02, 0x03, 0x54, 0x58, 0x58, + 0xaa, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xca, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, + 0x70, 0x62, 0xe2, 0x02, 0x12, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x5c, 0x47, 0x50, 0x42, 0x4d, + 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/testutil/testdata/tx.pb.go b/testutil/testdata/tx.pb.go index b12e6fa2eb3c..664d22c5cce1 100644 --- a/testutil/testdata/tx.pb.go +++ b/testutil/testdata/tx.pb.go @@ -173,7 +173,7 @@ func init() { func init() { proto.RegisterFile("testpb/tx.proto", fileDescriptor_1c54006dba274b2e) } var fileDescriptor_1c54006dba274b2e = []byte{ - // 313 bytes of a gzipped FileDescriptorProto + // 317 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2f, 0x49, 0x2d, 0x2e, 0x29, 0x48, 0xd2, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x83, 0x08, 0x48, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, 0x83, 0x85, 0xf4, 0x41, 0x2c, 0x88, 0xac, 0x94, 0x28, 0x4c, 0x79, @@ -184,16 +184,16 @@ var fileDescriptor_1c54006dba274b2e = []byte{ 0x07, 0x81, 0xc4, 0x85, 0x44, 0xb8, 0x58, 0xf3, 0xcb, 0xf3, 0x52, 0x8b, 0x24, 0x98, 0x14, 0x18, 0x35, 0x38, 0x83, 0x20, 0x1c, 0x2b, 0xae, 0xa6, 0xe7, 0x1b, 0xb4, 0x20, 0x6c, 0x25, 0x2d, 0x2e, 0x11, 0x64, 0x03, 0x83, 0x52, 0x8b, 0x0b, 0xf2, 0xf3, 0x8a, 0x53, 0x85, 0x84, 0xb8, 0x58, 0xf2, - 0x12, 0x73, 0x53, 0xc1, 0x26, 0x73, 0x06, 0x81, 0xd9, 0x4a, 0x9a, 0x5c, 0xec, 0x21, 0xa9, 0xc5, + 0x12, 0x73, 0x53, 0xc1, 0x26, 0x73, 0x06, 0x81, 0xd9, 0x4a, 0xa6, 0x5c, 0xec, 0x21, 0xa9, 0xc5, 0x25, 0xbe, 0xc5, 0xe9, 0x42, 0x12, 0x5c, 0xec, 0xc5, 0x99, 0xe9, 0x79, 0xa9, 0x45, 0xc5, 0x12, - 0x8c, 0x0a, 0xcc, 0x1a, 0x9c, 0x41, 0x30, 0xae, 0x15, 0x4b, 0xc7, 0x02, 0x79, 0x06, 0x23, 0x5f, - 0x2e, 0x66, 0x90, 0x32, 0x7b, 0x2e, 0x4e, 0x84, 0x5b, 0x45, 0x60, 0xce, 0x43, 0xb6, 0x50, 0x4a, - 0x06, 0x9b, 0x28, 0xcc, 0x19, 0x52, 0xac, 0x0d, 0xcf, 0x37, 0x68, 0x31, 0x3a, 0x79, 0x9c, 0x78, - 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, - 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x5e, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, - 0x5e, 0x72, 0x7e, 0xae, 0x3e, 0x34, 0xd0, 0x20, 0x94, 0x6e, 0x71, 0x4a, 0x36, 0x38, 0x58, 0x4b, - 0x4b, 0x32, 0x73, 0xe0, 0xe1, 0x9b, 0xc4, 0x06, 0x0e, 0x47, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, - 0xff, 0x0a, 0x96, 0x8c, 0x83, 0xa8, 0x01, 0x00, 0x00, + 0x8c, 0x0a, 0xcc, 0x1a, 0x9c, 0x41, 0x30, 0xae, 0x95, 0x40, 0xc7, 0x02, 0x79, 0x06, 0x90, 0x05, + 0x30, 0x11, 0x23, 0x5f, 0x2e, 0x66, 0x90, 0x16, 0x7b, 0x2e, 0x4e, 0x84, 0xbb, 0x45, 0x60, 0x4e, + 0x45, 0xb6, 0x5c, 0x4a, 0x06, 0x9b, 0x28, 0xcc, 0x49, 0x52, 0xac, 0x0d, 0xcf, 0x37, 0x68, 0x31, + 0x3a, 0x79, 0x9c, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, + 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x5e, 0x7a, 0x66, + 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x3e, 0x34, 0x00, 0x21, 0x94, 0x6e, 0x71, 0x4a, + 0x36, 0x38, 0x88, 0x4b, 0x4b, 0x32, 0x73, 0xe0, 0x61, 0x9d, 0xc4, 0x06, 0x0e, 0x53, 0x63, 0x40, + 0x00, 0x00, 0x00, 0xff, 0xff, 0xc4, 0x88, 0xf7, 0xab, 0xb4, 0x01, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/auth/ante/feegrant_test.go b/x/auth/ante/feegrant_test.go index 87d7f91aef10..e34a549ff199 100644 --- a/x/auth/ante/feegrant_test.go +++ b/x/auth/ante/feegrant_test.go @@ -168,15 +168,18 @@ func TestDeductFeesNoDelegation(t *testing.T) { var defaultGenTxGas uint64 = 10000000 tx, err := genTxWithFeeGranter(protoTxCfg, msgs, fee, defaultGenTxGas, suite.ctx.ChainID(), accNums, seqs, feeAcc, privs...) + txBytes, err := protoTxCfg.TxEncoder()(tx) require.NoError(t, err) - _, err = feeAnteHandler(suite.ctx, tx, false) // tests only feegrant ante + bytesCtx := suite.ctx.WithTxBytes(txBytes) + require.NoError(t, err) + _, err = feeAnteHandler(bytesCtx, tx, false) // tests only feegrant ante if tc.valid { require.NoError(t, err) } else { testutil.AssertError(t, err, tc.err, tc.errMsg) } - _, err = anteHandlerStack(suite.ctx, tx, false) // tests while stack + _, err = anteHandlerStack(bytesCtx, tx, false) // tests while stack if tc.valid { require.NoError(t, err) } else { diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index b17b06847f78..a2c5295c5931 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -299,7 +299,7 @@ func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul Value: anyPk.Value, }, } - decodeCtx, err := decode.NewDecoder(decode.Options{}) + decodeCtx, err := decode.NewDecoder(decode.Options{ProtoFiles: sdk.MergedProtoRegistry()}) if err != nil { return ctx, err } diff --git a/x/auth/ante/testutil_test.go b/x/auth/ante/testutil_test.go index 76cf9d39c9dd..0680513cd4f5 100644 --- a/x/auth/ante/testutil_test.go +++ b/x/auth/ante/testutil_test.go @@ -153,7 +153,10 @@ func (suite *AnteTestSuite) DeliverMsgs(t *testing.T, privs []cryptotypes.PrivKe tx, txErr := suite.CreateTestTx(suite.ctx, privs, accNums, accSeqs, chainID, signing.SignMode_SIGN_MODE_DIRECT) require.NoError(t, txErr) - return suite.anteHandler(suite.ctx, tx, simulate) + txBytes, err := suite.clientCtx.TxConfig.TxEncoder()(tx) + bytesCtx := suite.ctx.WithTxBytes(txBytes) + require.NoError(t, err) + return suite.anteHandler(bytesCtx, tx, simulate) } func (suite *AnteTestSuite) RunTestCase(t *testing.T, tc TestCase, args TestCaseArgs) { @@ -165,7 +168,10 @@ func (suite *AnteTestSuite) RunTestCase(t *testing.T, tc TestCase, args TestCase // ante handlers, but here we sometimes also test the tx creation // process. tx, txErr := suite.CreateTestTx(suite.ctx, args.privs, args.accNums, args.accSeqs, args.chainID, signing.SignMode_SIGN_MODE_DIRECT) - newCtx, anteErr := suite.anteHandler(suite.ctx, tx, tc.simulate) + txBytes, err := suite.clientCtx.TxConfig.TxEncoder()(tx) + require.NoError(t, err) + bytesCtx := suite.ctx.WithTxBytes(txBytes) + newCtx, anteErr := suite.anteHandler(bytesCtx, tx, tc.simulate) if tc.expPass { require.NoError(t, txErr) From 43ea1b464754eff3a1f4811cd405489948454b79 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 13 Apr 2023 15:18:31 -0500 Subject: [PATCH 12/52] fixed ante tests --- testutil/testdata/testpb/tx.proto | 2 + testutil/testdata/testpb/tx.pulsar.go | 63 ++++++++++++++------------- testutil/testdata/tx.pb.go | 45 ++++++++++--------- x/auth/ante/sigverify_test.go | 11 ++++- 4 files changed, 68 insertions(+), 53 deletions(-) diff --git a/testutil/testdata/testpb/tx.proto b/testutil/testdata/testpb/tx.proto index c97c402fce03..72df915b1363 100644 --- a/testutil/testdata/testpb/tx.proto +++ b/testutil/testdata/testpb/tx.proto @@ -1,6 +1,7 @@ syntax = "proto3"; package testpb; +import "amino/amino.proto"; import "gogoproto/gogo.proto"; import "testpb/testdata.proto"; import "cosmos/msg/v1/msg.proto"; @@ -31,5 +32,6 @@ message MsgCreateDogResponse { message TestMsg { option (gogoproto.goproto_getters) = false; option (cosmos.msg.v1.signer) = "signers"; + option (amino.name) = "testpb/TestMsg"; repeated string signers = 1; } diff --git a/testutil/testdata/testpb/tx.pulsar.go b/testutil/testdata/testpb/tx.pulsar.go index 217cad7c6c83..5e4213c4802a 100644 --- a/testutil/testdata/testpb/tx.pulsar.go +++ b/testutil/testdata/testpb/tx.pulsar.go @@ -2,6 +2,7 @@ package testpb import ( + _ "cosmossdk.io/api/amino" _ "cosmossdk.io/api/cosmos/msg/v1" fmt "fmt" runtime "github.com/cosmos/cosmos-proto/runtime" @@ -1545,37 +1546,39 @@ var File_testpb_tx_proto protoreflect.FileDescriptor var file_testpb_tx_proto_rawDesc = []byte{ 0x0a, 0x0f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2f, 0x74, 0x78, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x12, 0x06, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x1a, 0x14, 0x67, 0x6f, 0x67, 0x6f, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x6f, 0x67, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, - 0x15, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x64, 0x61, 0x74, 0x61, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x17, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x6d, - 0x73, 0x67, 0x2f, 0x76, 0x31, 0x2f, 0x6d, 0x73, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, - 0x4f, 0x0a, 0x0c, 0x4d, 0x73, 0x67, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x67, 0x12, - 0x1d, 0x0a, 0x03, 0x64, 0x6f, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x74, - 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x44, 0x6f, 0x67, 0x52, 0x03, 0x64, 0x6f, 0x67, 0x12, 0x14, - 0x0a, 0x05, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x6f, - 0x77, 0x6e, 0x65, 0x72, 0x3a, 0x0a, 0x82, 0xe7, 0xb0, 0x2a, 0x05, 0x6f, 0x77, 0x6e, 0x65, 0x72, - 0x22, 0x2a, 0x0a, 0x14, 0x4d, 0x73, 0x67, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x67, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x35, 0x0a, 0x07, - 0x54, 0x65, 0x73, 0x74, 0x4d, 0x73, 0x67, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x69, 0x67, 0x6e, 0x65, - 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x07, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, - 0x73, 0x3a, 0x10, 0x88, 0xa0, 0x1f, 0x00, 0x82, 0xe7, 0xb0, 0x2a, 0x07, 0x73, 0x69, 0x67, 0x6e, - 0x65, 0x72, 0x73, 0x32, 0x4d, 0x0a, 0x03, 0x4d, 0x73, 0x67, 0x12, 0x3f, 0x0a, 0x09, 0x43, 0x72, - 0x65, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x67, 0x12, 0x14, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, - 0x2e, 0x4d, 0x73, 0x67, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x67, 0x1a, 0x1c, 0x2e, + 0x6f, 0x12, 0x06, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x1a, 0x11, 0x61, 0x6d, 0x69, 0x6e, 0x6f, + 0x2f, 0x61, 0x6d, 0x69, 0x6e, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x14, 0x67, 0x6f, + 0x67, 0x6f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x6f, 0x67, 0x6f, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x1a, 0x15, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x64, + 0x61, 0x74, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x17, 0x63, 0x6f, 0x73, 0x6d, 0x6f, + 0x73, 0x2f, 0x6d, 0x73, 0x67, 0x2f, 0x76, 0x31, 0x2f, 0x6d, 0x73, 0x67, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x22, 0x4f, 0x0a, 0x0c, 0x4d, 0x73, 0x67, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, + 0x6f, 0x67, 0x12, 0x1d, 0x0a, 0x03, 0x64, 0x6f, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x0b, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x44, 0x6f, 0x67, 0x52, 0x03, 0x64, 0x6f, + 0x67, 0x12, 0x14, 0x0a, 0x05, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x05, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x3a, 0x0a, 0x82, 0xe7, 0xb0, 0x2a, 0x05, 0x6f, 0x77, + 0x6e, 0x65, 0x72, 0x22, 0x2a, 0x0a, 0x14, 0x4d, 0x73, 0x67, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, + 0x44, 0x6f, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, + 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, + 0x48, 0x0a, 0x07, 0x54, 0x65, 0x73, 0x74, 0x4d, 0x73, 0x67, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x69, + 0x67, 0x6e, 0x65, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x07, 0x73, 0x69, 0x67, + 0x6e, 0x65, 0x72, 0x73, 0x3a, 0x23, 0x88, 0xa0, 0x1f, 0x00, 0x82, 0xe7, 0xb0, 0x2a, 0x07, 0x73, + 0x69, 0x67, 0x6e, 0x65, 0x72, 0x73, 0x8a, 0xe7, 0xb0, 0x2a, 0x0e, 0x74, 0x65, 0x73, 0x74, 0x70, + 0x62, 0x2f, 0x54, 0x65, 0x73, 0x74, 0x4d, 0x73, 0x67, 0x32, 0x4d, 0x0a, 0x03, 0x4d, 0x73, 0x67, + 0x12, 0x3f, 0x0a, 0x09, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x67, 0x12, 0x14, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x4d, 0x73, 0x67, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, - 0x44, 0x6f, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x1a, 0x05, 0x80, 0xe7, 0xb0, - 0x2a, 0x01, 0x42, 0x8b, 0x01, 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, - 0x62, 0x42, 0x07, 0x54, 0x78, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x3c, 0x67, 0x69, - 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, - 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x75, - 0x74, 0x69, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x70, 0x75, 0x6c, - 0x73, 0x61, 0x72, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0xa2, 0x02, 0x03, 0x54, 0x58, 0x58, - 0xaa, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xca, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, - 0x70, 0x62, 0xe2, 0x02, 0x12, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x5c, 0x47, 0x50, 0x42, 0x4d, - 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x44, 0x6f, 0x67, 0x1a, 0x1c, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x4d, 0x73, 0x67, + 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x1a, 0x05, 0x80, 0xe7, 0xb0, 0x2a, 0x01, 0x42, 0x8b, 0x01, 0x0a, 0x0a, 0x63, 0x6f, 0x6d, + 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x42, 0x07, 0x54, 0x78, 0x50, 0x72, 0x6f, 0x74, 0x6f, + 0x50, 0x01, 0x5a, 0x3c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, + 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, + 0x2f, 0x74, 0x65, 0x73, 0x74, 0x75, 0x74, 0x69, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x64, 0x61, + 0x74, 0x61, 0x5f, 0x70, 0x75, 0x6c, 0x73, 0x61, 0x72, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, + 0xa2, 0x02, 0x03, 0x54, 0x58, 0x58, 0xaa, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xca, + 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xe2, 0x02, 0x12, 0x54, 0x65, 0x73, 0x74, 0x70, + 0x62, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x06, + 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/testutil/testdata/tx.pb.go b/testutil/testdata/tx.pb.go index 664d22c5cce1..e2d416faa41e 100644 --- a/testutil/testdata/tx.pb.go +++ b/testutil/testdata/tx.pb.go @@ -7,6 +7,7 @@ import ( context "context" fmt "fmt" _ "github.com/cosmos/cosmos-sdk/types/msgservice" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/cosmos/gogoproto/grpc" proto "github.com/cosmos/gogoproto/proto" @@ -173,27 +174,29 @@ func init() { func init() { proto.RegisterFile("testpb/tx.proto", fileDescriptor_1c54006dba274b2e) } var fileDescriptor_1c54006dba274b2e = []byte{ - // 317 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2f, 0x49, 0x2d, 0x2e, - 0x29, 0x48, 0xd2, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x83, 0x08, 0x48, - 0x89, 0xa4, 0xe7, 0xa7, 0xe7, 0x83, 0x85, 0xf4, 0x41, 0x2c, 0x88, 0xac, 0x94, 0x28, 0x4c, 0x79, - 0x6a, 0x71, 0x49, 0x4a, 0x62, 0x49, 0x22, 0x54, 0x58, 0x3c, 0x39, 0xbf, 0x38, 0x37, 0xbf, 0x58, - 0x3f, 0xb7, 0x38, 0x5d, 0xbf, 0xcc, 0x10, 0x44, 0x41, 0x24, 0x94, 0xfc, 0xb9, 0x78, 0x7c, 0x8b, - 0xd3, 0x9d, 0x8b, 0x52, 0x13, 0x4b, 0x52, 0x5d, 0xf2, 0xd3, 0x85, 0x64, 0xb9, 0x98, 0x53, 0xf2, - 0xd3, 0x25, 0x18, 0x15, 0x18, 0x35, 0xb8, 0x8d, 0xb8, 0xf5, 0x20, 0xa6, 0xe9, 0xb9, 0xe4, 0xa7, - 0x07, 0x81, 0xc4, 0x85, 0x44, 0xb8, 0x58, 0xf3, 0xcb, 0xf3, 0x52, 0x8b, 0x24, 0x98, 0x14, 0x18, - 0x35, 0x38, 0x83, 0x20, 0x1c, 0x2b, 0xae, 0xa6, 0xe7, 0x1b, 0xb4, 0x20, 0x6c, 0x25, 0x2d, 0x2e, - 0x11, 0x64, 0x03, 0x83, 0x52, 0x8b, 0x0b, 0xf2, 0xf3, 0x8a, 0x53, 0x85, 0x84, 0xb8, 0x58, 0xf2, - 0x12, 0x73, 0x53, 0xc1, 0x26, 0x73, 0x06, 0x81, 0xd9, 0x4a, 0xa6, 0x5c, 0xec, 0x21, 0xa9, 0xc5, - 0x25, 0xbe, 0xc5, 0xe9, 0x42, 0x12, 0x5c, 0xec, 0xc5, 0x99, 0xe9, 0x79, 0xa9, 0x45, 0xc5, 0x12, - 0x8c, 0x0a, 0xcc, 0x1a, 0x9c, 0x41, 0x30, 0xae, 0x95, 0x40, 0xc7, 0x02, 0x79, 0x06, 0x90, 0x05, - 0x30, 0x11, 0x23, 0x5f, 0x2e, 0x66, 0x90, 0x16, 0x7b, 0x2e, 0x4e, 0x84, 0xbb, 0x45, 0x60, 0x4e, - 0x45, 0xb6, 0x5c, 0x4a, 0x06, 0x9b, 0x28, 0xcc, 0x49, 0x52, 0xac, 0x0d, 0xcf, 0x37, 0x68, 0x31, - 0x3a, 0x79, 0x9c, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, - 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x5e, 0x7a, 0x66, - 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x3e, 0x34, 0x00, 0x21, 0x94, 0x6e, 0x71, 0x4a, - 0x36, 0x38, 0x88, 0x4b, 0x4b, 0x32, 0x73, 0xe0, 0x61, 0x9d, 0xc4, 0x06, 0x0e, 0x53, 0x63, 0x40, - 0x00, 0x00, 0x00, 0xff, 0xff, 0xc4, 0x88, 0xf7, 0xab, 0xb4, 0x01, 0x00, 0x00, + // 337 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x90, 0x31, 0x4b, 0xc3, 0x40, + 0x14, 0xc7, 0x73, 0xd6, 0xb6, 0xe4, 0x2a, 0x8a, 0x21, 0x62, 0x08, 0x1a, 0x4b, 0x5d, 0x4a, 0xc0, + 0x1c, 0xd6, 0xad, 0x8b, 0xa0, 0x1d, 0xba, 0x14, 0x21, 0x38, 0xb9, 0xa5, 0xed, 0x71, 0x06, 0x4d, + 0x5e, 0xc9, 0xbb, 0xaa, 0xa3, 0x38, 0x89, 0x93, 0x1f, 0xc1, 0x8f, 0xd0, 0x8f, 0xe1, 0xd8, 0xd1, + 0x51, 0xda, 0xa1, 0x5f, 0x43, 0x72, 0x97, 0x68, 0x07, 0x97, 0xbc, 0xff, 0xfb, 0x3d, 0xf2, 0xbf, + 0xf7, 0xfe, 0x74, 0x47, 0x72, 0x94, 0x93, 0x21, 0x93, 0x4f, 0xc1, 0x24, 0x03, 0x09, 0x56, 0x4d, + 0x03, 0x77, 0x37, 0x4a, 0xe2, 0x14, 0x98, 0xfa, 0xea, 0x91, 0x6b, 0x0b, 0x10, 0xa0, 0x24, 0xcb, + 0x55, 0x41, 0xf7, 0x4a, 0x07, 0x8e, 0x72, 0x1c, 0xc9, 0xa8, 0xc0, 0xfb, 0x23, 0xc0, 0x04, 0x90, + 0x25, 0x28, 0xd8, 0xc3, 0x69, 0x5e, 0xf4, 0xa0, 0x75, 0x45, 0xb7, 0x06, 0x28, 0x2e, 0x33, 0x1e, + 0x49, 0xde, 0x03, 0x61, 0x1d, 0xd2, 0xca, 0x18, 0x84, 0x43, 0x9a, 0xa4, 0xdd, 0xe8, 0x34, 0x02, + 0xed, 0x16, 0xf4, 0x40, 0x84, 0x39, 0xb7, 0x6c, 0x5a, 0x85, 0xc7, 0x94, 0x67, 0xce, 0x46, 0x93, + 0xb4, 0xcd, 0x50, 0x37, 0x5d, 0xfa, 0xb2, 0x9a, 0xf9, 0x5a, 0xb7, 0x7c, 0x6a, 0xaf, 0x1b, 0x86, + 0x1c, 0x27, 0x90, 0x22, 0xb7, 0x2c, 0xba, 0x99, 0x46, 0x09, 0x57, 0xce, 0x66, 0xa8, 0x74, 0xab, + 0x4f, 0xeb, 0xd7, 0x1c, 0xe5, 0x00, 0x85, 0xe5, 0xd0, 0x3a, 0xc6, 0x22, 0xe5, 0x19, 0x3a, 0xa4, + 0x59, 0x69, 0x9b, 0x61, 0xd9, 0x76, 0x8f, 0x5f, 0x3f, 0x8e, 0x8c, 0xfc, 0x81, 0x92, 0xbc, 0xad, + 0x66, 0xfe, 0x76, 0x71, 0x66, 0xf1, 0x7b, 0x67, 0x40, 0x2b, 0xb9, 0xcb, 0x39, 0x35, 0xff, 0x4e, + 0xb1, 0xcb, 0xed, 0xd7, 0xf7, 0x71, 0x0f, 0xfe, 0xa3, 0xe5, 0x96, 0x6e, 0xf5, 0x79, 0x35, 0xf3, + 0xc9, 0x45, 0xff, 0x73, 0xe1, 0x91, 0xf9, 0xc2, 0x23, 0xdf, 0x0b, 0x8f, 0xbc, 0x2f, 0x3d, 0x63, + 0xbe, 0xf4, 0x8c, 0xaf, 0xa5, 0x67, 0xdc, 0x04, 0x22, 0x96, 0xb7, 0xd3, 0x61, 0x30, 0x82, 0x84, + 0x15, 0x99, 0xea, 0x72, 0x82, 0xe3, 0x3b, 0x95, 0xfa, 0x54, 0xc6, 0xf7, 0xbf, 0xf1, 0x0f, 0x6b, + 0x2a, 0xe6, 0xb3, 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x89, 0xf1, 0xc8, 0x3c, 0xda, 0x01, 0x00, + 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/auth/ante/sigverify_test.go b/x/auth/ante/sigverify_test.go index 73906460f2ee..6be5d71ee985 100644 --- a/x/auth/ante/sigverify_test.go +++ b/x/auth/ante/sigverify_test.go @@ -126,7 +126,7 @@ func TestConsumeSignatureVerificationGas(t *testing.T) { func TestSigVerification(t *testing.T) { suite := SetupTestSuite(t, true) - suite.txBankKeeper.EXPECT().DenomMetadata(suite.ctx, gomock.Any()).Return(&banktypes.QueryDenomMetadataResponse{}, nil).AnyTimes() + suite.txBankKeeper.EXPECT().DenomMetadata(gomock.Any(), gomock.Any()).Return(&banktypes.QueryDenomMetadataResponse{}, nil).AnyTimes() enabledSignModes := []signing.SignMode{signing.SignMode_SIGN_MODE_DIRECT, signing.SignMode_SIGN_MODE_TEXTUAL, signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON} // Since TEXTUAL is not enabled by default, we create a custom TxConfig @@ -221,7 +221,10 @@ func TestSigVerification(t *testing.T) { tx = suite.txBuilder.GetTx() } - _, err = antehandler(suite.ctx, tx, false) + txBytes, err := suite.clientCtx.TxConfig.TxEncoder()(tx) + require.NoError(t, err) + byteCtx := suite.ctx.WithTxBytes(txBytes) + _, err = antehandler(byteCtx, tx, false) if tc.shouldErr { require.NotNil(t, err, "TestCase %d: %s did not error as expected", i, tc.name) } else { @@ -289,6 +292,10 @@ func runSigDecorators(t *testing.T, params types.Params, _ bool, privs ...crypto svd := ante.NewSigVerificationDecorator(suite.accountKeeper, suite.clientCtx.TxConfig.SignModeHandler()) antehandler := sdk.ChainAnteDecorators(spkd, svgc, svd) + txBytes, err := suite.clientCtx.TxConfig.TxEncoder()(tx) + require.NoError(t, err) + suite.ctx = suite.ctx.WithTxBytes(txBytes) + // Determine gas consumption of antehandler with default params before := suite.ctx.GasMeter().GasConsumed() ctx, err := antehandler(suite.ctx, tx, false) From bff8090267d465d588cdd5d12f499245723e37c0 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 13 Apr 2023 16:19:19 -0500 Subject: [PATCH 13/52] merged fix --- x/auth/client/cli/validate_sigs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/auth/client/cli/validate_sigs.go b/x/auth/client/cli/validate_sigs.go index a9d2aecf2b3e..cf1b57f1fc2c 100644 --- a/x/auth/client/cli/validate_sigs.go +++ b/x/auth/client/cli/validate_sigs.go @@ -137,7 +137,7 @@ func printAndValidateSigs( cmd.PrintErrf("failed to encode transaction: %v", err) return false } - decodeCtx, err := decode.NewDecoder(decode.Options{}) + decodeCtx, err := decode.NewDecoder(decode.Options{ProtoFiles: sdk.MergedProtoRegistry()}) if err != nil { cmd.PrintErrf("failed to create decoder: %v", err) return false From 0a25910ac561de210aa33fb2f7541556180e88b0 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 13 Apr 2023 16:19:46 -0500 Subject: [PATCH 14/52] revert (temporarily) x/tx to 0.5.1 --- go.mod | 1 + x/tx/CHANGELOG.md | 12 - x/tx/decode/decode.go | 55 +- x/tx/decode/decode_test.go | 26 +- x/tx/internal/testpb/signers.proto | 7 - x/tx/internal/testpb/signers.pulsar.go | 617 +++------------------- x/tx/signing/aminojson/time.go | 2 +- x/tx/signing/directaux/direct_aux.go | 43 +- x/tx/signing/directaux/direct_aux_test.go | 24 +- x/tx/signing/get_signers.go | 222 ++++++++ x/tx/signing/get_signers_test.go | 113 ++++ x/tx/signing/textual/bench_test.go | 63 +-- x/tx/signing/textual/message.go | 6 +- 13 files changed, 482 insertions(+), 709 deletions(-) create mode 100644 x/tx/signing/get_signers.go create mode 100644 x/tx/signing/get_signers_test.go diff --git a/go.mod b/go.mod index 82784203564a..46e9f4820ba1 100644 --- a/go.mod +++ b/go.mod @@ -172,6 +172,7 @@ replace ( github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.8.1 // Downgraded to avoid bugs in following commits which caused simulations to fail. github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 + cosmossdk.io/x/tx => x/tx ) retract ( diff --git a/x/tx/CHANGELOG.md b/x/tx/CHANGELOG.md index 2b5921d98676..dd956831e654 100644 --- a/x/tx/CHANGELOG.md +++ b/x/tx/CHANGELOG.md @@ -31,22 +31,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## Unreleased -### API Breaking - -* [#15709](https://github.com/cosmos/cosmos-sdk/pull/15709): - * `GetSignersContext` has been renamed to `signing.Context` - * `GetSigners` now returns `[][]byte` instead of `[]string` - * `GetSignersOptions` has been renamed to `signing.Options` and requires `address.Codec`s for account and validator addresses - * `GetSignersOptions.ProtoFiles` has been renamed to `signing.Options.FileResolver` - -## v0.5.1 - ### Features * [#15414](https://github.com/cosmos/cosmos-sdk/pull/15414) Add basic transaction decoding support. -## v0.5.0 - ### API Breaking * [#15581](https://github.com/cosmos/cosmos-sdk/pull/15581) `GetSignersOptions` and `directaux.SignModeHandlerOptions` now diff --git a/x/tx/decode/decode.go b/x/tx/decode/decode.go index d046a396d01e..4ee08437707f 100644 --- a/x/tx/decode/decode.go +++ b/x/tx/decode/decode.go @@ -1,13 +1,12 @@ package decode import ( - "fmt" - - v1beta1 "cosmossdk.io/api/cosmos/tx/v1beta1" - "cosmossdk.io/errors" "github.com/cosmos/cosmos-proto/anyutil" "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/reflect/protoregistry" + v1beta1 "cosmossdk.io/api/cosmos/tx/v1beta1" + "cosmossdk.io/errors" "cosmossdk.io/x/tx/signing" ) @@ -16,28 +15,51 @@ type DecodedTx struct { Messages []proto.Message Tx *v1beta1.Tx TxRaw *v1beta1.TxRaw - Signers [][]byte + Signers []string TxBodyHasUnknownNonCriticals bool } // Decoder contains the dependencies required for decoding transactions. type Decoder struct { - signingCtx *signing.Context + getSignersCtx *signing.GetSignersContext + typeResolver protoregistry.MessageTypeResolver + protoFiles *protoregistry.Files } // Options are options for creating a Decoder. type Options struct { - SigningContext *signing.Context + // ProtoFiles are the protobuf files to use for resolving message descriptors. + // If it is nil, the global protobuf registry will be used. + ProtoFiles *protoregistry.Files + TypeResolver protoregistry.MessageTypeResolver + SigningContext *signing.GetSignersContext } // NewDecoder creates a new Decoder for decoding transactions. func NewDecoder(options Options) (*Decoder, error) { - if options.SigningContext == nil { - return nil, fmt.Errorf("signing context is required") + if options.ProtoFiles == nil { + options.ProtoFiles = protoregistry.GlobalFiles + } + + if options.TypeResolver == nil { + options.TypeResolver = protoregistry.GlobalTypes + } + + getSignersCtx := options.SigningContext + if getSignersCtx == nil { + var err error + getSignersCtx, err = signing.NewGetSignersContext(signing.GetSignersOptions{ + ProtoFiles: options.ProtoFiles, + }) + if err != nil { + return nil, err + } } return &Decoder{ - signingCtx: options.SigningContext, + getSignersCtx: getSignersCtx, + protoFiles: options.ProtoFiles, + typeResolver: options.TypeResolver, }, nil } @@ -52,8 +74,7 @@ func (d *Decoder) Decode(txBytes []byte) (*DecodedTx, error) { var raw v1beta1.TxRaw // reject all unknown proto fields in the root TxRaw - fileResolver := d.signingCtx.FileResolver() - err = RejectUnknownFieldsStrict(txBytes, raw.ProtoReflect().Descriptor(), fileResolver) + err = RejectUnknownFieldsStrict(txBytes, raw.ProtoReflect().Descriptor(), d.protoFiles) if err != nil { return nil, errors.Wrap(ErrTxDecode, err.Error()) } @@ -66,7 +87,7 @@ func (d *Decoder) Decode(txBytes []byte) (*DecodedTx, error) { var body v1beta1.TxBody // allow non-critical unknown fields in TxBody - txBodyHasUnknownNonCriticals, err := RejectUnknownFields(raw.BodyBytes, body.ProtoReflect().Descriptor(), true, fileResolver) + txBodyHasUnknownNonCriticals, err := RejectUnknownFields(raw.BodyBytes, body.ProtoReflect().Descriptor(), true, d.protoFiles) if err != nil { return nil, errors.Wrap(ErrTxDecode, err.Error()) } @@ -79,7 +100,7 @@ func (d *Decoder) Decode(txBytes []byte) (*DecodedTx, error) { var authInfo v1beta1.AuthInfo // reject all unknown proto fields in AuthInfo - err = RejectUnknownFieldsStrict(raw.AuthInfoBytes, authInfo.ProtoReflect().Descriptor(), fileResolver) + err = RejectUnknownFieldsStrict(raw.AuthInfoBytes, authInfo.ProtoReflect().Descriptor(), d.protoFiles) if err != nil { return nil, errors.Wrap(ErrTxDecode, err.Error()) } @@ -95,15 +116,15 @@ func (d *Decoder) Decode(txBytes []byte) (*DecodedTx, error) { Signatures: raw.Signatures, } - var signers [][]byte + var signers []string var msgs []proto.Message for _, anyMsg := range body.Messages { - msg, signerErr := anyutil.Unpack(anyMsg, fileResolver, d.signingCtx.TypeResolver()) + msg, signerErr := anyutil.Unpack(anyMsg, d.protoFiles, d.typeResolver) if signerErr != nil { return nil, errors.Wrap(ErrTxDecode, signerErr.Error()) } msgs = append(msgs, msg) - ss, signerErr := d.signingCtx.GetSigners(msg) + ss, signerErr := d.getSignersCtx.GetSigners(msg) if signerErr != nil { return nil, errors.Wrap(ErrTxDecode, signerErr.Error()) } diff --git a/x/tx/decode/decode_test.go b/x/tx/decode/decode_test.go index 1c095030e6b1..a7169a9989da 100644 --- a/x/tx/decode/decode_test.go +++ b/x/tx/decode/decode_test.go @@ -1,7 +1,6 @@ package decode_test import ( - "encoding/hex" "fmt" "testing" @@ -10,10 +9,8 @@ import ( "cosmossdk.io/api/cosmos/crypto/secp256k1" signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1" txv1beta1 "cosmossdk.io/api/cosmos/tx/v1beta1" - "cosmossdk.io/x/tx/decode" "cosmossdk.io/x/tx/internal/testpb" - "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-proto/anyutil" "github.com/stretchr/testify/require" @@ -39,16 +36,6 @@ func TestDecode(t *testing.T) { Sequence: accSeq, }) - signingCtx, err := signing.NewContext(signing.Options{ - AddressCodec: dummyAddressCodec{}, - ValidatorAddressCodec: dummyAddressCodec{}, - }) - require.NoError(t, err) - decoder, err := decode.NewDecoder(decode.Options{ - SigningContext: signingCtx, - }) - require.NoError(t, err) - testCases := []struct { name string msg proto.Message @@ -96,6 +83,9 @@ func TestDecode(t *testing.T) { txBytes, err := proto.Marshal(tx) require.NoError(t, err) + decoder, err := decode.NewDecoder(decode.Options{}) + require.NoError(t, err) + decodeTx, err := decoder.Decode(txBytes) if tc.error != "" { require.EqualError(t, err, tc.error) @@ -109,13 +99,3 @@ func TestDecode(t *testing.T) { }) } } - -type dummyAddressCodec struct{} - -func (d dummyAddressCodec) StringToBytes(text string) ([]byte, error) { - return hex.DecodeString(text) -} - -func (d dummyAddressCodec) BytesToString(bz []byte) (string, error) { - return hex.EncodeToString(bz), nil -} diff --git a/x/tx/internal/testpb/signers.proto b/x/tx/internal/testpb/signers.proto index dfd6db078646..26b9867b2ad6 100644 --- a/x/tx/internal/testpb/signers.proto +++ b/x/tx/internal/testpb/signers.proto @@ -1,7 +1,6 @@ syntax = "proto3"; import "cosmos/msg/v1/msg.proto"; -import "cosmos_proto/cosmos.proto"; option go_package = "cosmossdk.io/x/tx/internal/testpb"; @@ -59,12 +58,6 @@ message BadSigner { option (cosmos.msg.v1.signer) = "signer"; bytes signer = 1; } - message NoSignerOption { bytes signer = 1; } - -message ValidatorSigner { - option (cosmos.msg.v1.signer) = "signer"; - string signer = 1 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"]; -} \ No newline at end of file diff --git a/x/tx/internal/testpb/signers.pulsar.go b/x/tx/internal/testpb/signers.pulsar.go index f7ce5db88e20..b554e807f002 100644 --- a/x/tx/internal/testpb/signers.pulsar.go +++ b/x/tx/internal/testpb/signers.pulsar.go @@ -4,7 +4,6 @@ package testpb import ( _ "cosmossdk.io/api/cosmos/msg/v1" fmt "fmt" - _ "github.com/cosmos/cosmos-proto" runtime "github.com/cosmos/cosmos-proto/runtime" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoiface "google.golang.org/protobuf/runtime/protoiface" @@ -1369,7 +1368,7 @@ func (x *NestedSigner_Inner) ProtoReflect() protoreflect.Message { } func (x *NestedSigner_Inner) slowProtoReflect() protoreflect.Message { - mi := &file_signers_proto_msgTypes[9] + mi := &file_signers_proto_msgTypes[8] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2283,7 +2282,7 @@ func (x *RepeatedNestedSigner_Inner) ProtoReflect() protoreflect.Message { } func (x *RepeatedNestedSigner_Inner) slowProtoReflect() protoreflect.Message { - mi := &file_signers_proto_msgTypes[10] + mi := &file_signers_proto_msgTypes[9] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -3184,7 +3183,7 @@ func (x *NestedRepeatedSigner_Inner) ProtoReflect() protoreflect.Message { } func (x *NestedRepeatedSigner_Inner) slowProtoReflect() protoreflect.Message { - mi := &file_signers_proto_msgTypes[11] + mi := &file_signers_proto_msgTypes[10] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -4158,7 +4157,7 @@ func (x *RepeatedNestedRepeatedSigner_Inner) ProtoReflect() protoreflect.Message } func (x *RepeatedNestedRepeatedSigner_Inner) slowProtoReflect() protoreflect.Message { - mi := &file_signers_proto_msgTypes[12] + mi := &file_signers_proto_msgTypes[11] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -5416,426 +5415,6 @@ func (x *fastReflection_NoSignerOption) ProtoMethods() *protoiface.Methods { } } -var ( - md_ValidatorSigner protoreflect.MessageDescriptor - fd_ValidatorSigner_signer protoreflect.FieldDescriptor -) - -func init() { - file_signers_proto_init() - md_ValidatorSigner = File_signers_proto.Messages().ByName("ValidatorSigner") - fd_ValidatorSigner_signer = md_ValidatorSigner.Fields().ByName("signer") -} - -var _ protoreflect.Message = (*fastReflection_ValidatorSigner)(nil) - -type fastReflection_ValidatorSigner ValidatorSigner - -func (x *ValidatorSigner) ProtoReflect() protoreflect.Message { - return (*fastReflection_ValidatorSigner)(x) -} - -func (x *ValidatorSigner) slowProtoReflect() protoreflect.Message { - mi := &file_signers_proto_msgTypes[8] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -var _fastReflection_ValidatorSigner_messageType fastReflection_ValidatorSigner_messageType -var _ protoreflect.MessageType = fastReflection_ValidatorSigner_messageType{} - -type fastReflection_ValidatorSigner_messageType struct{} - -func (x fastReflection_ValidatorSigner_messageType) Zero() protoreflect.Message { - return (*fastReflection_ValidatorSigner)(nil) -} -func (x fastReflection_ValidatorSigner_messageType) New() protoreflect.Message { - return new(fastReflection_ValidatorSigner) -} -func (x fastReflection_ValidatorSigner_messageType) Descriptor() protoreflect.MessageDescriptor { - return md_ValidatorSigner -} - -// Descriptor returns message descriptor, which contains only the protobuf -// type information for the message. -func (x *fastReflection_ValidatorSigner) Descriptor() protoreflect.MessageDescriptor { - return md_ValidatorSigner -} - -// Type returns the message type, which encapsulates both Go and protobuf -// type information. If the Go type information is not needed, -// it is recommended that the message descriptor be used instead. -func (x *fastReflection_ValidatorSigner) Type() protoreflect.MessageType { - return _fastReflection_ValidatorSigner_messageType -} - -// New returns a newly allocated and mutable empty message. -func (x *fastReflection_ValidatorSigner) New() protoreflect.Message { - return new(fastReflection_ValidatorSigner) -} - -// Interface unwraps the message reflection interface and -// returns the underlying ProtoMessage interface. -func (x *fastReflection_ValidatorSigner) Interface() protoreflect.ProtoMessage { - return (*ValidatorSigner)(x) -} - -// Range iterates over every populated field in an undefined order, -// calling f for each field descriptor and value encountered. -// Range returns immediately if f returns false. -// While iterating, mutating operations may only be performed -// on the current field descriptor. -func (x *fastReflection_ValidatorSigner) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { - if x.Signer != "" { - value := protoreflect.ValueOfString(x.Signer) - if !f(fd_ValidatorSigner_signer, value) { - return - } - } -} - -// Has reports whether a field is populated. -// -// Some fields have the property of nullability where it is possible to -// distinguish between the default value of a field and whether the field -// was explicitly populated with the default value. Singular message fields, -// member fields of a oneof, and proto2 scalar fields are nullable. Such -// fields are populated only if explicitly set. -// -// In other cases (aside from the nullable cases above), -// a proto3 scalar field is populated if it contains a non-zero value, and -// a repeated field is populated if it is non-empty. -func (x *fastReflection_ValidatorSigner) Has(fd protoreflect.FieldDescriptor) bool { - switch fd.FullName() { - case "ValidatorSigner.signer": - return x.Signer != "" - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: ValidatorSigner")) - } - panic(fmt.Errorf("message ValidatorSigner does not contain field %s", fd.FullName())) - } -} - -// Clear clears the field such that a subsequent Has call reports false. -// -// Clearing an extension field clears both the extension type and value -// associated with the given field number. -// -// Clear is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_ValidatorSigner) Clear(fd protoreflect.FieldDescriptor) { - switch fd.FullName() { - case "ValidatorSigner.signer": - x.Signer = "" - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: ValidatorSigner")) - } - panic(fmt.Errorf("message ValidatorSigner does not contain field %s", fd.FullName())) - } -} - -// Get retrieves the value for a field. -// -// For unpopulated scalars, it returns the default value, where -// the default value of a bytes scalar is guaranteed to be a copy. -// For unpopulated composite types, it returns an empty, read-only view -// of the value; to obtain a mutable reference, use Mutable. -func (x *fastReflection_ValidatorSigner) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { - switch descriptor.FullName() { - case "ValidatorSigner.signer": - value := x.Signer - return protoreflect.ValueOfString(value) - default: - if descriptor.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: ValidatorSigner")) - } - panic(fmt.Errorf("message ValidatorSigner does not contain field %s", descriptor.FullName())) - } -} - -// Set stores the value for a field. -// -// For a field belonging to a oneof, it implicitly clears any other field -// that may be currently set within the same oneof. -// For extension fields, it implicitly stores the provided ExtensionType. -// When setting a composite type, it is unspecified whether the stored value -// aliases the source's memory in any way. If the composite value is an -// empty, read-only value, then it panics. -// -// Set is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_ValidatorSigner) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { - switch fd.FullName() { - case "ValidatorSigner.signer": - x.Signer = value.Interface().(string) - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: ValidatorSigner")) - } - panic(fmt.Errorf("message ValidatorSigner does not contain field %s", fd.FullName())) - } -} - -// Mutable returns a mutable reference to a composite type. -// -// If the field is unpopulated, it may allocate a composite value. -// For a field belonging to a oneof, it implicitly clears any other field -// that may be currently set within the same oneof. -// For extension fields, it implicitly stores the provided ExtensionType -// if not already stored. -// It panics if the field does not contain a composite type. -// -// Mutable is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_ValidatorSigner) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { - switch fd.FullName() { - case "ValidatorSigner.signer": - panic(fmt.Errorf("field signer of message ValidatorSigner is not mutable")) - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: ValidatorSigner")) - } - panic(fmt.Errorf("message ValidatorSigner does not contain field %s", fd.FullName())) - } -} - -// NewField returns a new value that is assignable to the field -// for the given descriptor. For scalars, this returns the default value. -// For lists, maps, and messages, this returns a new, empty, mutable value. -func (x *fastReflection_ValidatorSigner) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { - switch fd.FullName() { - case "ValidatorSigner.signer": - return protoreflect.ValueOfString("") - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: ValidatorSigner")) - } - panic(fmt.Errorf("message ValidatorSigner does not contain field %s", fd.FullName())) - } -} - -// WhichOneof reports which field within the oneof is populated, -// returning nil if none are populated. -// It panics if the oneof descriptor does not belong to this message. -func (x *fastReflection_ValidatorSigner) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { - switch d.FullName() { - default: - panic(fmt.Errorf("%s is not a oneof field in ValidatorSigner", d.FullName())) - } - panic("unreachable") -} - -// GetUnknown retrieves the entire list of unknown fields. -// The caller may only mutate the contents of the RawFields -// if the mutated bytes are stored back into the message with SetUnknown. -func (x *fastReflection_ValidatorSigner) GetUnknown() protoreflect.RawFields { - return x.unknownFields -} - -// SetUnknown stores an entire list of unknown fields. -// The raw fields must be syntactically valid according to the wire format. -// An implementation may panic if this is not the case. -// Once stored, the caller must not mutate the content of the RawFields. -// An empty RawFields may be passed to clear the fields. -// -// SetUnknown is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_ValidatorSigner) SetUnknown(fields protoreflect.RawFields) { - x.unknownFields = fields -} - -// IsValid reports whether the message is valid. -// -// An invalid message is an empty, read-only value. -// -// An invalid message often corresponds to a nil pointer of the concrete -// message type, but the details are implementation dependent. -// Validity is not part of the protobuf data model, and may not -// be preserved in marshaling or other operations. -func (x *fastReflection_ValidatorSigner) IsValid() bool { - return x != nil -} - -// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. -// This method may return nil. -// -// The returned methods type is identical to -// "google.golang.org/protobuf/runtime/protoiface".Methods. -// Consult the protoiface package documentation for details. -func (x *fastReflection_ValidatorSigner) ProtoMethods() *protoiface.Methods { - size := func(input protoiface.SizeInput) protoiface.SizeOutput { - x := input.Message.Interface().(*ValidatorSigner) - if x == nil { - return protoiface.SizeOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Size: 0, - } - } - options := runtime.SizeInputToOptions(input) - _ = options - var n int - var l int - _ = l - l = len(x.Signer) - if l > 0 { - n += 1 + l + runtime.Sov(uint64(l)) - } - if x.unknownFields != nil { - n += len(x.unknownFields) - } - return protoiface.SizeOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Size: n, - } - } - - marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) { - x := input.Message.Interface().(*ValidatorSigner) - if x == nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, nil - } - options := runtime.MarshalInputToOptions(input) - _ = options - size := options.Size(x) - dAtA := make([]byte, size) - i := len(dAtA) - _ = i - var l int - _ = l - if x.unknownFields != nil { - i -= len(x.unknownFields) - copy(dAtA[i:], x.unknownFields) - } - if len(x.Signer) > 0 { - i -= len(x.Signer) - copy(dAtA[i:], x.Signer) - i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Signer))) - i-- - dAtA[i] = 0xa - } - if input.Buf != nil { - input.Buf = append(input.Buf, dAtA...) - } else { - input.Buf = dAtA - } - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, nil - } - unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) { - x := input.Message.Interface().(*ValidatorSigner) - if x == nil { - return protoiface.UnmarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Flags: input.Flags, - }, nil - } - options := runtime.UnmarshalInputToOptions(input) - _ = options - dAtA := input.Buf - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: ValidatorSigner: wiretype end group for non-group") - } - if fieldNum <= 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: ValidatorSigner: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Signer", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - x.Signer = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := runtime.Skip(dAtA[iNdEx:]) - if err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if (iNdEx + skippy) > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - if !options.DiscardUnknown { - x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) - } - iNdEx += skippy - } - } - - if iNdEx > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil - } - return &protoiface.Methods{ - NoUnkeyedLiterals: struct{}{}, - Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown, - Size: size, - Marshal: marshal, - Unmarshal: unmarshal, - Merge: nil, - CheckInitialized: nil, - } -} - // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.27.0 @@ -6129,41 +5708,6 @@ func (x *NoSignerOption) GetSigner() []byte { return nil } -type ValidatorSigner struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Signer string `protobuf:"bytes,1,opt,name=signer,proto3" json:"signer,omitempty"` -} - -func (x *ValidatorSigner) Reset() { - *x = ValidatorSigner{} - if protoimpl.UnsafeEnabled { - mi := &file_signers_proto_msgTypes[8] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ValidatorSigner) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ValidatorSigner) ProtoMessage() {} - -// Deprecated: Use ValidatorSigner.ProtoReflect.Descriptor instead. -func (*ValidatorSigner) Descriptor() ([]byte, []int) { - return file_signers_proto_rawDescGZIP(), []int{8} -} - -func (x *ValidatorSigner) GetSigner() string { - if x != nil { - return x.Signer - } - return "" -} - type NestedSigner_Inner struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -6175,7 +5719,7 @@ type NestedSigner_Inner struct { func (x *NestedSigner_Inner) Reset() { *x = NestedSigner_Inner{} if protoimpl.UnsafeEnabled { - mi := &file_signers_proto_msgTypes[9] + mi := &file_signers_proto_msgTypes[8] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -6210,7 +5754,7 @@ type RepeatedNestedSigner_Inner struct { func (x *RepeatedNestedSigner_Inner) Reset() { *x = RepeatedNestedSigner_Inner{} if protoimpl.UnsafeEnabled { - mi := &file_signers_proto_msgTypes[10] + mi := &file_signers_proto_msgTypes[9] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -6245,7 +5789,7 @@ type NestedRepeatedSigner_Inner struct { func (x *NestedRepeatedSigner_Inner) Reset() { *x = NestedRepeatedSigner_Inner{} if protoimpl.UnsafeEnabled { - mi := &file_signers_proto_msgTypes[11] + mi := &file_signers_proto_msgTypes[10] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -6280,7 +5824,7 @@ type RepeatedNestedRepeatedSigner_Inner struct { func (x *RepeatedNestedRepeatedSigner_Inner) Reset() { *x = RepeatedNestedRepeatedSigner_Inner{} if protoimpl.UnsafeEnabled { - mi := &file_signers_proto_msgTypes[12] + mi := &file_signers_proto_msgTypes[11] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -6309,65 +5853,57 @@ var File_signers_proto protoreflect.FileDescriptor var file_signers_proto_rawDesc = []byte{ 0x0a, 0x0d, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x17, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x6d, 0x73, 0x67, 0x2f, 0x76, 0x31, 0x2f, 0x6d, - 0x73, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x19, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, - 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x22, 0x33, 0x0a, 0x0c, 0x53, 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x53, 0x69, 0x67, - 0x6e, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x3a, 0x0b, 0x82, 0xe7, 0xb0, - 0x2a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x22, 0x35, 0x0a, 0x0e, 0x52, 0x65, 0x70, 0x65, - 0x61, 0x74, 0x65, 0x64, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x69, - 0x67, 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x06, 0x73, 0x69, 0x67, 0x6e, - 0x65, 0x72, 0x3a, 0x0b, 0x82, 0xe7, 0xb0, 0x2a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x22, - 0x73, 0x0a, 0x0c, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x12, - 0x29, 0x0a, 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, - 0x2e, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x2e, 0x49, 0x6e, - 0x6e, 0x65, 0x72, 0x52, 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x1a, 0x2c, 0x0a, 0x05, 0x49, 0x6e, - 0x6e, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x3a, 0x0b, 0x82, 0xe7, 0xb0, - 0x2a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x3a, 0x0a, 0x82, 0xe7, 0xb0, 0x2a, 0x05, 0x69, - 0x6e, 0x6e, 0x65, 0x72, 0x22, 0x83, 0x01, 0x0a, 0x14, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, - 0x64, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x12, 0x31, 0x0a, - 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x52, - 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x53, 0x69, 0x67, - 0x6e, 0x65, 0x72, 0x2e, 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x52, 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, - 0x1a, 0x2c, 0x0a, 0x05, 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x69, 0x67, - 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, - 0x72, 0x3a, 0x0b, 0x82, 0xe7, 0xb0, 0x2a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x3a, 0x0a, - 0x82, 0xe7, 0xb0, 0x2a, 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x22, 0x83, 0x01, 0x0a, 0x14, 0x4e, - 0x65, 0x73, 0x74, 0x65, 0x64, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x53, 0x69, 0x67, - 0x6e, 0x65, 0x72, 0x12, 0x31, 0x0a, 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x52, 0x65, 0x70, 0x65, 0x61, - 0x74, 0x65, 0x64, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x2e, 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x52, - 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x1a, 0x2c, 0x0a, 0x05, 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x12, + 0x73, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x33, 0x0a, 0x0c, 0x53, 0x69, 0x6d, 0x70, + 0x6c, 0x65, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x69, 0x67, 0x6e, + 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, + 0x3a, 0x0b, 0x82, 0xe7, 0xb0, 0x2a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x22, 0x35, 0x0a, + 0x0e, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x3a, 0x0b, 0x82, 0xe7, 0xb0, 0x2a, 0x06, 0x73, 0x69, - 0x67, 0x6e, 0x65, 0x72, 0x3a, 0x0a, 0x82, 0xe7, 0xb0, 0x2a, 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, - 0x22, 0x93, 0x01, 0x0a, 0x1c, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x4e, 0x65, 0x73, - 0x74, 0x65, 0x64, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x53, 0x69, 0x67, 0x6e, 0x65, - 0x72, 0x12, 0x39, 0x0a, 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, - 0x32, 0x23, 0x2e, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x4e, 0x65, 0x73, 0x74, 0x65, - 0x64, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x2e, - 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x52, 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x1a, 0x2c, 0x0a, 0x05, - 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x18, - 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x3a, 0x0b, 0x82, - 0xe7, 0xb0, 0x2a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x3a, 0x0a, 0x82, 0xe7, 0xb0, 0x2a, - 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x22, 0x30, 0x0a, 0x09, 0x42, 0x61, 0x64, 0x53, 0x69, 0x67, - 0x6e, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x0c, 0x52, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x3a, 0x0b, 0x82, 0xe7, 0xb0, - 0x2a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x22, 0x28, 0x0a, 0x0e, 0x4e, 0x6f, 0x53, 0x69, - 0x67, 0x6e, 0x65, 0x72, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x69, - 0x67, 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x73, 0x69, 0x67, 0x6e, - 0x65, 0x72, 0x22, 0x59, 0x0a, 0x0f, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x53, - 0x69, 0x67, 0x6e, 0x65, 0x72, 0x12, 0x39, 0x0a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x21, 0xd2, 0xb4, 0x2d, 0x1d, 0x63, 0x6f, 0x73, 0x6d, 0x6f, - 0x73, 0x2e, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x41, 0x64, 0x64, 0x72, 0x65, - 0x73, 0x73, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x52, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, - 0x3a, 0x0b, 0x82, 0xe7, 0xb0, 0x2a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x42, 0x3b, 0x42, - 0x0c, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, - 0x29, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x78, 0x2f, - 0x74, 0x78, 0x2f, 0x74, 0x65, 0x78, 0x74, 0x75, 0x61, 0x6c, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, - 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x33, + 0x67, 0x6e, 0x65, 0x72, 0x22, 0x73, 0x0a, 0x0c, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x53, 0x69, + 0x67, 0x6e, 0x65, 0x72, 0x12, 0x29, 0x0a, 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x53, 0x69, 0x67, 0x6e, + 0x65, 0x72, 0x2e, 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x52, 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x1a, + 0x2c, 0x0a, 0x05, 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x69, 0x67, 0x6e, + 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, + 0x3a, 0x0b, 0x82, 0xe7, 0xb0, 0x2a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x3a, 0x0a, 0x82, + 0xe7, 0xb0, 0x2a, 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x22, 0x83, 0x01, 0x0a, 0x14, 0x52, 0x65, + 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x53, 0x69, 0x67, 0x6e, + 0x65, 0x72, 0x12, 0x31, 0x0a, 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, 0x03, 0x28, + 0x0b, 0x32, 0x1b, 0x2e, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x4e, 0x65, 0x73, 0x74, + 0x65, 0x64, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x2e, 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x52, 0x05, + 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x1a, 0x2c, 0x0a, 0x05, 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x12, 0x16, + 0x0a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, + 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x3a, 0x0b, 0x82, 0xe7, 0xb0, 0x2a, 0x06, 0x73, 0x69, 0x67, + 0x6e, 0x65, 0x72, 0x3a, 0x0a, 0x82, 0xe7, 0xb0, 0x2a, 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x22, + 0x83, 0x01, 0x0a, 0x14, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, + 0x65, 0x64, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x12, 0x31, 0x0a, 0x05, 0x69, 0x6e, 0x6e, 0x65, + 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, + 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x2e, 0x49, + 0x6e, 0x6e, 0x65, 0x72, 0x52, 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x1a, 0x2c, 0x0a, 0x05, 0x49, + 0x6e, 0x6e, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x18, 0x01, + 0x20, 0x03, 0x28, 0x09, 0x52, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x3a, 0x0b, 0x82, 0xe7, + 0xb0, 0x2a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x3a, 0x0a, 0x82, 0xe7, 0xb0, 0x2a, 0x05, + 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x22, 0x93, 0x01, 0x0a, 0x1c, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, + 0x65, 0x64, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, + 0x53, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x12, 0x39, 0x0a, 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x18, + 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, + 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x53, 0x69, + 0x67, 0x6e, 0x65, 0x72, 0x2e, 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x52, 0x05, 0x69, 0x6e, 0x6e, 0x65, + 0x72, 0x1a, 0x2c, 0x0a, 0x05, 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x69, + 0x67, 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x06, 0x73, 0x69, 0x67, 0x6e, + 0x65, 0x72, 0x3a, 0x0b, 0x82, 0xe7, 0xb0, 0x2a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x3a, + 0x0a, 0x82, 0xe7, 0xb0, 0x2a, 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x22, 0x30, 0x0a, 0x09, 0x42, + 0x61, 0x64, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x69, 0x67, 0x6e, + 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, + 0x3a, 0x0b, 0x82, 0xe7, 0xb0, 0x2a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x22, 0x28, 0x0a, + 0x0e, 0x4e, 0x6f, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, + 0x16, 0x0a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, + 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x42, 0x3b, 0x42, 0x0c, 0x53, 0x69, 0x67, 0x6e, 0x65, + 0x72, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x29, 0x63, 0x6f, 0x73, 0x6d, 0x6f, + 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x78, 0x2f, 0x74, 0x78, 0x2f, 0x74, 0x65, 0x78, + 0x74, 0x75, 0x61, 0x6c, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, + 0x73, 0x74, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -6382,7 +5918,7 @@ func file_signers_proto_rawDescGZIP() []byte { return file_signers_proto_rawDescData } -var file_signers_proto_msgTypes = make([]protoimpl.MessageInfo, 13) +var file_signers_proto_msgTypes = make([]protoimpl.MessageInfo, 12) var file_signers_proto_goTypes = []interface{}{ (*SimpleSigner)(nil), // 0: SimpleSigner (*RepeatedSigner)(nil), // 1: RepeatedSigner @@ -6392,17 +5928,16 @@ var file_signers_proto_goTypes = []interface{}{ (*RepeatedNestedRepeatedSigner)(nil), // 5: RepeatedNestedRepeatedSigner (*BadSigner)(nil), // 6: BadSigner (*NoSignerOption)(nil), // 7: NoSignerOption - (*ValidatorSigner)(nil), // 8: ValidatorSigner - (*NestedSigner_Inner)(nil), // 9: NestedSigner.Inner - (*RepeatedNestedSigner_Inner)(nil), // 10: RepeatedNestedSigner.Inner - (*NestedRepeatedSigner_Inner)(nil), // 11: NestedRepeatedSigner.Inner - (*RepeatedNestedRepeatedSigner_Inner)(nil), // 12: RepeatedNestedRepeatedSigner.Inner + (*NestedSigner_Inner)(nil), // 8: NestedSigner.Inner + (*RepeatedNestedSigner_Inner)(nil), // 9: RepeatedNestedSigner.Inner + (*NestedRepeatedSigner_Inner)(nil), // 10: NestedRepeatedSigner.Inner + (*RepeatedNestedRepeatedSigner_Inner)(nil), // 11: RepeatedNestedRepeatedSigner.Inner } var file_signers_proto_depIdxs = []int32{ - 9, // 0: NestedSigner.inner:type_name -> NestedSigner.Inner - 10, // 1: RepeatedNestedSigner.inner:type_name -> RepeatedNestedSigner.Inner - 11, // 2: NestedRepeatedSigner.inner:type_name -> NestedRepeatedSigner.Inner - 12, // 3: RepeatedNestedRepeatedSigner.inner:type_name -> RepeatedNestedRepeatedSigner.Inner + 8, // 0: NestedSigner.inner:type_name -> NestedSigner.Inner + 9, // 1: RepeatedNestedSigner.inner:type_name -> RepeatedNestedSigner.Inner + 10, // 2: NestedRepeatedSigner.inner:type_name -> NestedRepeatedSigner.Inner + 11, // 3: RepeatedNestedRepeatedSigner.inner:type_name -> RepeatedNestedRepeatedSigner.Inner 4, // [4:4] is the sub-list for method output_type 4, // [4:4] is the sub-list for method input_type 4, // [4:4] is the sub-list for extension type_name @@ -6513,18 +6048,6 @@ func file_signers_proto_init() { } } file_signers_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ValidatorSigner); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_signers_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*NestedSigner_Inner); i { case 0: return &v.state @@ -6536,7 +6059,7 @@ func file_signers_proto_init() { return nil } } - file_signers_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { + file_signers_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*RepeatedNestedSigner_Inner); i { case 0: return &v.state @@ -6548,7 +6071,7 @@ func file_signers_proto_init() { return nil } } - file_signers_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { + file_signers_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*NestedRepeatedSigner_Inner); i { case 0: return &v.state @@ -6560,7 +6083,7 @@ func file_signers_proto_init() { return nil } } - file_signers_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} { + file_signers_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*RepeatedNestedRepeatedSigner_Inner); i { case 0: return &v.state @@ -6579,7 +6102,7 @@ func file_signers_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_signers_proto_rawDesc, NumEnums: 0, - NumMessages: 13, + NumMessages: 12, NumExtensions: 0, NumServices: 0, }, diff --git a/x/tx/signing/aminojson/time.go b/x/tx/signing/aminojson/time.go index da02514c0255..aa0ca9c84f5c 100644 --- a/x/tx/signing/aminojson/time.go +++ b/x/tx/signing/aminojson/time.go @@ -46,7 +46,7 @@ func marshalTimestamp(message protoreflect.Message, writer io.Writer) error { // MaxDurationSeconds the maximum number of seconds (when expressed as nanoseconds) which can fit in an int64. // gogoproto encodes google.protobuf.Duration as a time.Duration, which is 64-bit signed integer. -const MaxDurationSeconds = int64(math.MaxInt64)/1e9 - 1 +const MaxDurationSeconds = int64(math.MaxInt64/int(1e9)) - 1 func marshalDuration(message protoreflect.Message, writer io.Writer) error { fields := message.Descriptor().Fields() diff --git a/x/tx/signing/directaux/direct_aux.go b/x/tx/signing/directaux/direct_aux.go index f20b56f513e0..8738834906e1 100644 --- a/x/tx/signing/directaux/direct_aux.go +++ b/x/tx/signing/directaux/direct_aux.go @@ -16,30 +16,32 @@ import ( // SignModeHandler is the SIGN_MODE_DIRECT_AUX implementation of signing.SignModeHandler. type SignModeHandler struct { - signersContext *signing.Context + signersContext *signing.GetSignersContext fileResolver signing.ProtoFileResolver typeResolver protoregistry.MessageTypeResolver } // SignModeHandlerOptions are the options for the SignModeHandler. type SignModeHandlerOptions struct { - // TypeResolver is the protoregistry.MessageTypeResolver to use for resolving protobuf types when unpacking any messages. + // FileResolver is the protodesc.Resolver to use for resolving proto files when unpacking any messages. + FileResolver signing.ProtoFileResolver + + // TypeResolver is the protoregistry.MessageTypeResolver to use for resolving proto types when unpacking any messages. TypeResolver protoregistry.MessageTypeResolver - // SignersContext is the signing.Context to use for getting signers. - SignersContext *signing.Context + // SignersContext is the signing.GetSignersContext to use for getting signers. + SignersContext *signing.GetSignersContext } // NewSignModeHandler returns a new SignModeHandler. func NewSignModeHandler(options SignModeHandlerOptions) (SignModeHandler, error) { h := SignModeHandler{} - if options.SignersContext == nil { - return h, fmt.Errorf("signers context is required") + if options.FileResolver == nil { + h.fileResolver = protoregistry.GlobalFiles + } else { + h.fileResolver = options.FileResolver } - h.signersContext = options.SignersContext - - h.fileResolver = h.signersContext.FileResolver() if options.TypeResolver == nil { h.typeResolver = protoregistry.GlobalTypes @@ -47,6 +49,16 @@ func NewSignModeHandler(options SignModeHandlerOptions) (SignModeHandler, error) h.typeResolver = options.TypeResolver } + if options.SignersContext == nil { + var err error + h.signersContext, err = signing.NewGetSignersContext(signing.GetSignersOptions{ProtoFiles: h.fileResolver}) + if err != nil { + return h, err + } + } else { + h.signersContext = options.SignersContext + } + return h, nil } @@ -59,18 +71,18 @@ func (h SignModeHandler) Mode() signingv1beta1.SignMode { // getFirstSigner returns the first signer from the first message in the tx. It replicates behavior in // https://github.com/cosmos/cosmos-sdk/blob/4a6a1e3cb8de459891cb0495052589673d14ef51/x/auth/tx/builder.go#L142 -func (h SignModeHandler) getFirstSigner(txData signing.TxData) ([]byte, error) { +func (h SignModeHandler) getFirstSigner(txData signing.TxData) (string, error) { if len(txData.Body.Messages) == 0 { - return nil, fmt.Errorf("no signer found") + return "", fmt.Errorf("no signer found") } msg, err := anyutil.Unpack(txData.Body.Messages[0], h.fileResolver, h.typeResolver) if err != nil { - return nil, err + return "", err } signer, err := h.signersContext.GetSigners(msg) if err != nil { - return nil, err + return "", err } return signer[0], nil } @@ -85,10 +97,7 @@ func (h SignModeHandler) GetSignBytes( if err != nil { return nil, err } - feePayer, err = h.signersContext.AddressCodec().BytesToString(fp) - if err != nil { - return nil, err - } + feePayer = fp } if feePayer == signerData.Address { return nil, fmt.Errorf("fee payer %s cannot sign with %s: unauthorized", diff --git a/x/tx/signing/directaux/direct_aux_test.go b/x/tx/signing/directaux/direct_aux_test.go index 4fba90b7e1aa..2f7ca5440b85 100644 --- a/x/tx/signing/directaux/direct_aux_test.go +++ b/x/tx/signing/directaux/direct_aux_test.go @@ -2,11 +2,9 @@ package directaux_test import ( "context" - "encoding/hex" "fmt" "testing" - "cosmossdk.io/core/address" "github.com/cosmos/cosmos-proto/anyutil" "github.com/stretchr/testify/require" "google.golang.org/protobuf/proto" @@ -17,7 +15,6 @@ import ( "cosmossdk.io/api/cosmos/crypto/secp256k1" signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1" txv1beta1 "cosmossdk.io/api/cosmos/tx/v1beta1" - "cosmossdk.io/x/tx/signing" "cosmossdk.io/x/tx/signing/directaux" ) @@ -86,14 +83,7 @@ func TestDirectAuxHandler(t *testing.T) { AuthInfoBytes: authInfoBz, BodyBytes: bodyBz, } - signersCtx, err := signing.NewContext(signing.Options{ - AddressCodec: dummyAddressCodec{}, - ValidatorAddressCodec: dummyAddressCodec{}, - }) - require.NoError(t, err) - modeHandler, err := directaux.NewSignModeHandler(directaux.SignModeHandlerOptions{ - SignersContext: signersCtx, - }) + modeHandler, err := directaux.NewSignModeHandler(directaux.SignModeHandlerOptions{}) require.NoError(t, err) t.Log("verify fee payer cannot use SIGN_MODE_DIRECT_AUX") @@ -153,15 +143,3 @@ func TestDirectAuxHandler(t *testing.T) { require.NoError(t, err) require.NotEqual(t, expectedSignBytes, signBytes) } - -type dummyAddressCodec struct{} - -func (d dummyAddressCodec) StringToBytes(text string) ([]byte, error) { - return hex.DecodeString(text) -} - -func (d dummyAddressCodec) BytesToString(bz []byte) (string, error) { - return hex.EncodeToString(bz), nil -} - -var _ address.Codec = dummyAddressCodec{} diff --git a/x/tx/signing/get_signers.go b/x/tx/signing/get_signers.go new file mode 100644 index 000000000000..eabd70ed03d3 --- /dev/null +++ b/x/tx/signing/get_signers.go @@ -0,0 +1,222 @@ +package signing + +import ( + "errors" + "fmt" + + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/reflect/protodesc" + "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/reflect/protoregistry" + "google.golang.org/protobuf/types/dynamicpb" + + msgv1 "cosmossdk.io/api/cosmos/msg/v1" +) + +// GetSignersContext is a context for retrieving the list of signers from a +// message where signers are specified by the cosmos.msg.v1.signer protobuf +// option. +type GetSignersContext struct { + protoFiles ProtoFileResolver + getSignersFuncs map[protoreflect.FullName]getSignersFunc +} + +// GetSignersOptions are options for creating GetSignersContext. +type GetSignersOptions struct { + // ProtoFiles are the protobuf files to use for resolving message descriptors. + // If it is nil, the global protobuf registry will be used. + ProtoFiles ProtoFileResolver +} + +// ProtoFileResolver is a protodesc.Resolver that also allows iterating over all +// files descriptors. It is a subset of the methods supported by protoregistry.Files. +type ProtoFileResolver interface { + protodesc.Resolver + RangeFiles(func(protoreflect.FileDescriptor) bool) +} + +// NewGetSignersContext creates a new GetSignersContext using the provided options. +func NewGetSignersContext(options GetSignersOptions) (*GetSignersContext, error) { + protoFiles := options.ProtoFiles + if protoFiles == nil { + protoFiles = protoregistry.GlobalFiles + } + + c := &GetSignersContext{ + protoFiles: protoFiles, + getSignersFuncs: map[protoreflect.FullName]getSignersFunc{}, + } + + return c, c.init() +} + +type getSignersFunc func(proto.Message) []string + +func getSignersFieldNames(descriptor protoreflect.MessageDescriptor) ([]string, error) { + signersFields := proto.GetExtension(descriptor.Options(), msgv1.E_Signer).([]string) + if len(signersFields) == 0 { + return nil, fmt.Errorf("no cosmos.msg.v1.signer option found for message %s", descriptor.FullName()) + } + + return signersFields, nil +} + +// init performs a dry run of getting all msg's signers. This has 2 benefits: +// - it will error if any Msg has forgotten the "cosmos.msg.v1.signer" +// annotation +// - it will pre-populate the context's internal cache for getSignersFuncs +// so that calling it in antehandlers will be faster. +func (c *GetSignersContext) init() error { + var errs []error + c.protoFiles.RangeFiles(func(fd protoreflect.FileDescriptor) bool { + for i := 0; i < fd.Services().Len(); i++ { + sd := fd.Services().Get(i) + // We use the heuristic that services named "Msg" are exactly the + // ones that need the proto annotation check. + if sd.Name() != "Msg" { + continue + } + + for j := 0; j < sd.Methods().Len(); j++ { + md := sd.Methods().Get(j).Input() + msg := dynamicpb.NewMessage(md) + _, err := c.GetSigners(msg) + if err != nil { + errs = append(errs, err) + } + } + } + + return true + }) + + return errors.Join(errs...) +} + +func (*GetSignersContext) makeGetSignersFunc(descriptor protoreflect.MessageDescriptor) (getSignersFunc, error) { + signersFields, err := getSignersFieldNames(descriptor) + if err != nil { + return nil, err + } + + fieldGetters := make([]func(proto.Message, []string) []string, len(signersFields)) + for i, fieldName := range signersFields { + field := descriptor.Fields().ByName(protoreflect.Name(fieldName)) + if field == nil { + return nil, fmt.Errorf("field %s not found in message %s", fieldName, descriptor.FullName()) + } + + if field.IsMap() || field.HasOptionalKeyword() { + return nil, fmt.Errorf("cosmos.msg.v1.signer field %s in message %s must not be a map or optional", fieldName, descriptor.FullName()) + } + + switch field.Kind() { + case protoreflect.StringKind: + if field.IsList() { + fieldGetters[i] = func(msg proto.Message, arr []string) []string { + signers := msg.ProtoReflect().Get(field).List() + n := signers.Len() + for i := 0; i < n; i++ { + arr = append(arr, signers.Get(i).String()) + } + return arr + } + } else { + fieldGetters[i] = func(msg proto.Message, arr []string) []string { + return append(arr, msg.ProtoReflect().Get(field).String()) + } + } + case protoreflect.MessageKind: + isList := field.IsList() + nestedMessage := field.Message() + nestedSignersFields, err := getSignersFieldNames(nestedMessage) + if err != nil { + return nil, err + } + + if len(nestedSignersFields) != 1 { + return nil, fmt.Errorf("nested cosmos.msg.v1.signer option in message %s must contain only one value", nestedMessage.FullName()) + } + + nestedFieldName := nestedSignersFields[0] + nestedField := nestedMessage.Fields().ByName(protoreflect.Name(nestedFieldName)) + nestedIsList := nestedField.IsList() + if nestedField == nil { + return nil, fmt.Errorf("field %s not found in message %s", nestedFieldName, nestedMessage.FullName()) + } + + if nestedField.Kind() != protoreflect.StringKind || nestedField.IsMap() || nestedField.HasOptionalKeyword() { + return nil, fmt.Errorf("nested signer field %s in message %s must be a simple string", nestedFieldName, nestedMessage.FullName()) + } + + if isList { + if nestedIsList { + fieldGetters[i] = func(msg proto.Message, arr []string) []string { + msgs := msg.ProtoReflect().Get(field).List() + m := msgs.Len() + for i := 0; i < m; i++ { + signers := msgs.Get(i).Message().Get(nestedField).List() + n := signers.Len() + for j := 0; j < n; j++ { + arr = append(arr, signers.Get(j).String()) + } + } + return arr + } + } else { + fieldGetters[i] = func(msg proto.Message, arr []string) []string { + msgs := msg.ProtoReflect().Get(field).List() + m := msgs.Len() + for i := 0; i < m; i++ { + arr = append(arr, msgs.Get(i).Message().Get(nestedField).String()) + } + return arr + } + } + } else { + if nestedIsList { + fieldGetters[i] = func(msg proto.Message, arr []string) []string { + nestedMsg := msg.ProtoReflect().Get(field).Message() + signers := nestedMsg.Get(nestedField).List() + n := signers.Len() + for j := 0; j < n; j++ { + arr = append(arr, signers.Get(j).String()) + } + return arr + } + } else { + fieldGetters[i] = func(msg proto.Message, arr []string) []string { + return append(arr, msg.ProtoReflect().Get(field).Message().Get(nestedField).String()) + } + } + } + + default: + return nil, fmt.Errorf("unexpected field type %s for field %s in message %s", field.Kind(), fieldName, descriptor.FullName()) + } + } + + return func(message proto.Message) []string { + var signers []string + for _, getter := range fieldGetters { + signers = getter(message, signers) + } + return signers + }, nil +} + +// GetSigners returns the signers for a given message. +func (c *GetSignersContext) GetSigners(msg proto.Message) ([]string, error) { + messageDescriptor := msg.ProtoReflect().Descriptor() + f, ok := c.getSignersFuncs[messageDescriptor.FullName()] + if !ok { + var err error + f, err = c.makeGetSignersFunc(messageDescriptor) + if err != nil { + return nil, err + } + c.getSignersFuncs[messageDescriptor.FullName()] = f + } + + return f(msg), nil +} diff --git a/x/tx/signing/get_signers_test.go b/x/tx/signing/get_signers_test.go new file mode 100644 index 000000000000..f52fe54542aa --- /dev/null +++ b/x/tx/signing/get_signers_test.go @@ -0,0 +1,113 @@ +package signing + +import ( + "testing" + + bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" + groupv1 "cosmossdk.io/api/cosmos/group/v1" + "github.com/stretchr/testify/require" + "google.golang.org/protobuf/proto" + + "cosmossdk.io/x/tx/internal/testpb" +) + +func TestGetSigners(t *testing.T) { + ctx, err := NewGetSignersContext(GetSignersOptions{}) + require.NoError(t, err) + tests := []struct { + name string + msg proto.Message + want []string + wantErr bool + }{ + { + name: "MsgSend", + msg: &bankv1beta1.MsgSend{ + FromAddress: "foo", + }, + want: []string{"foo"}, + }, + { + name: "MsgMultiSend", + msg: &bankv1beta1.MsgMultiSend{ + Inputs: []*bankv1beta1.Input{ + {Address: "foo"}, + {Address: "bar"}, + }, + }, + want: []string{"foo", "bar"}, + }, + { + name: "MsgSubmitProposal", + msg: &groupv1.MsgSubmitProposal{ + Proposers: []string{"foo", "bar"}, + }, + want: []string{"foo", "bar"}, + }, + { + name: "simple", + msg: &testpb.SimpleSigner{Signer: "foo"}, + want: []string{"foo"}, + }, + { + name: "repeated", + msg: &testpb.RepeatedSigner{Signer: []string{"foo", "bar"}}, + want: []string{"foo", "bar"}, + }, + { + name: "nested", + msg: &testpb.NestedSigner{Inner: &testpb.NestedSigner_Inner{Signer: "foo"}}, + want: []string{"foo"}, + }, + { + name: "nested repeated", + msg: &testpb.NestedRepeatedSigner{Inner: &testpb.NestedRepeatedSigner_Inner{Signer: []string{"foo", "bar"}}}, + want: []string{"foo", "bar"}, + }, + { + name: "repeated nested", + msg: &testpb.RepeatedNestedSigner{Inner: []*testpb.RepeatedNestedSigner_Inner{ + {Signer: "foo"}, + {Signer: "bar"}, + }}, + want: []string{"foo", "bar"}, + }, + { + name: "nested repeated", + msg: &testpb.NestedRepeatedSigner{Inner: &testpb.NestedRepeatedSigner_Inner{ + Signer: []string{"foo", "bar"}, + }}, + want: []string{"foo", "bar"}, + }, + { + name: "repeated nested repeated", + msg: &testpb.RepeatedNestedRepeatedSigner{Inner: []*testpb.RepeatedNestedRepeatedSigner_Inner{ + {Signer: []string{"foo", "bar"}}, + {Signer: []string{"baz", "bam"}}, + {Signer: []string{"blah"}}, + }}, + want: []string{"foo", "bar", "baz", "bam", "blah"}, + }, + { + name: "bad", + msg: &testpb.BadSigner{}, + wantErr: true, + }, + { + name: "no signer", + msg: &testpb.NoSignerOption{}, + wantErr: true, + }, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + signers, err := ctx.GetSigners(test.msg) + if test.wantErr { + require.Error(t, err) + } else { + require.NoError(t, err) + } + require.Equal(t, test.want, signers) + }) + } +} diff --git a/x/tx/signing/textual/bench_test.go b/x/tx/signing/textual/bench_test.go index d113b39bd302..0e2c4b70123a 100644 --- a/x/tx/signing/textual/bench_test.go +++ b/x/tx/signing/textual/bench_test.go @@ -1,17 +1,11 @@ -package textual_test +package textual import ( "bytes" "context" - "encoding/json" - "os" "testing" - "github.com/stretchr/testify/require" "google.golang.org/protobuf/reflect/protoreflect" - - "cosmossdk.io/x/tx/internal/testpb" - "cosmossdk.io/x/tx/signing/textual" ) var intValues = []protoreflect.Value{ @@ -28,7 +22,7 @@ var intValues = []protoreflect.Value{ func BenchmarkIntValueRendererFormat(b *testing.B) { ctx := context.Background() - ivr := textual.NewIntValueRenderer(fieldDescriptorFromName("UINT64")) + ivr := new(intValueRenderer) b.ResetTimer() b.ReportAllocs() @@ -55,7 +49,7 @@ var decimalValues = []protoreflect.Value{ func BenchmarkDecimalValueRendererFormat(b *testing.B) { ctx := context.Background() - dvr := textual.NewDecValueRenderer() + dvr := new(decValueRenderer) b.ResetTimer() b.ReportAllocs() @@ -82,7 +76,7 @@ var byteValues = []protoreflect.Value{ func BenchmarkBytesValueRendererFormat(b *testing.B) { ctx := context.Background() - bvr := textual.NewBytesValueRenderer() + bvr := new(bytesValueRenderer) b.ResetTimer() b.ReportAllocs() @@ -94,52 +88,3 @@ func BenchmarkBytesValueRendererFormat(b *testing.B) { } } } - -var sink any - -func BenchmarkMessageValueRenderer_parseRepeated(b *testing.B) { - ctx := context.Background() - raw, err := os.ReadFile("./internal/testdata/repeated.json") - require.NoError(b, err) - - type rendScreens struct { - rend textual.ValueRenderer - screens []textual.Screen - } - - var rsL []*rendScreens - - var testCases []repeatedJSONTest - err = json.Unmarshal(raw, &testCases) - require.NoError(b, err) - - tr, err := textual.NewSignModeHandler(textual.SignModeOptions{CoinMetadataQuerier: mockCoinMetadataQuerier}) - for _, tc := range testCases { - rend := textual.NewMessageValueRenderer(tr, (&testpb.Qux{}).ProtoReflect().Descriptor()) - require.NoError(b, err) - - screens, err := rend.Format(ctx, protoreflect.ValueOf(tc.Proto.ProtoReflect())) - require.NoError(b, err) - require.Equal(b, tc.Screens, screens) - - rsL = append(rsL, &rendScreens{ - rend: rend, - screens: screens, - }) - } - - b.ReportAllocs() - b.ResetTimer() - - for i := 0; i < b.N; i++ { - for _, rs := range rsL { - sink, _ = rs.rend.Parse(ctx, rs.screens) - } - } - - if sink == nil { - b.Fatal("Benchmark did not run!") - } - // Reset the sink for reuse. - sink = nil -} diff --git a/x/tx/signing/textual/message.go b/x/tx/signing/textual/message.go index 83668cd7a298..9affadba8602 100644 --- a/x/tx/signing/textual/message.go +++ b/x/tx/signing/textual/message.go @@ -261,11 +261,11 @@ func (mr *messageValueRenderer) Parse(ctx context.Context, screens []Screen) (pr return protoreflect.ValueOfMessage(msg), nil } -// -var headerRegex = regexp.MustCompile(`(\d+) .+`) - func (mr *messageValueRenderer) parseRepeated(ctx context.Context, screens []Screen, l protoreflect.List, vr ValueRenderer) error { + // + headerRegex := *regexp.MustCompile(`(\d+) .+`) res := headerRegex.FindAllStringSubmatch(screens[0].Content, -1) + if res == nil { return errors.New("failed to match ") } From 3f0a4f272e52dc70720dcea4545204a8780ee90f Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 13 Apr 2023 16:22:18 -0500 Subject: [PATCH 15/52] rm files --- go.mod | 2 +- x/tx/signing/context.go | 320 ----------------------------------- x/tx/signing/context_test.go | 170 ------------------- 3 files changed, 1 insertion(+), 491 deletions(-) delete mode 100644 x/tx/signing/context.go delete mode 100644 x/tx/signing/context_test.go diff --git a/go.mod b/go.mod index 46e9f4820ba1..3d0ecab10d83 100644 --- a/go.mod +++ b/go.mod @@ -172,7 +172,7 @@ replace ( github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.8.1 // Downgraded to avoid bugs in following commits which caused simulations to fail. github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 - cosmossdk.io/x/tx => x/tx + cosmossdk.io/x/tx => ./x/tx ) retract ( diff --git a/x/tx/signing/context.go b/x/tx/signing/context.go deleted file mode 100644 index c8afe2e83891..000000000000 --- a/x/tx/signing/context.go +++ /dev/null @@ -1,320 +0,0 @@ -package signing - -import ( - "errors" - "fmt" - - "cosmossdk.io/core/address" - cosmos_proto "github.com/cosmos/cosmos-proto" - "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/reflect/protodesc" - "google.golang.org/protobuf/reflect/protoreflect" - "google.golang.org/protobuf/reflect/protoregistry" - "google.golang.org/protobuf/types/dynamicpb" - - msgv1 "cosmossdk.io/api/cosmos/msg/v1" -) - -// Context is a context for retrieving the list of signers from a -// message where signers are specified by the cosmos.msg.v1.signer protobuf -// option. It also contains the ProtoFileResolver and address.Codec's used -// for resolving message descriptors and converting addresses. -type Context struct { - fileResolver ProtoFileResolver - typeResolver protoregistry.MessageTypeResolver - addressCodec address.Codec - validatorAddressCodec address.Codec - getSignersFuncs map[protoreflect.FullName]getSignersFunc -} - -// Options are options for creating Context which will be used for signing operations. -type Options struct { - // FileResolver is the protobuf file resolver to use for resolving message descriptors. - // If it is nil, the global protobuf registry will be used. - FileResolver ProtoFileResolver - - // TypeResolver is the protobuf type resolver to use for resolving message types. - TypeResolver protoregistry.MessageTypeResolver - - // AddressCodec is the codec for converting addresses between strings and bytes. - AddressCodec address.Codec - - // ValidatorAddressCodec is the codec for converting validator addresses between strings and bytes. - ValidatorAddressCodec address.Codec -} - -// ProtoFileResolver is a protodesc.Resolver that also allows iterating over all -// files descriptors. It is a subset of the methods supported by protoregistry.Files. -type ProtoFileResolver interface { - protodesc.Resolver - RangeFiles(func(protoreflect.FileDescriptor) bool) -} - -// NewContext creates a new Context using the provided options. -func NewContext(options Options) (*Context, error) { - protoFiles := options.FileResolver - if protoFiles == nil { - protoFiles = protoregistry.GlobalFiles - } - - protoTypes := options.TypeResolver - if protoTypes == nil { - protoTypes = protoregistry.GlobalTypes - } - - if options.AddressCodec == nil { - return nil, errors.New("address codec is required") - } - - if options.ValidatorAddressCodec == nil { - return nil, errors.New("validator address codec is required") - } - - c := &Context{ - fileResolver: protoFiles, - typeResolver: protoTypes, - addressCodec: options.AddressCodec, - validatorAddressCodec: options.ValidatorAddressCodec, - getSignersFuncs: map[protoreflect.FullName]getSignersFunc{}, - } - - return c, c.init() -} - -type getSignersFunc func(proto.Message) ([][]byte, error) - -func getSignersFieldNames(descriptor protoreflect.MessageDescriptor) ([]string, error) { - signersFields := proto.GetExtension(descriptor.Options(), msgv1.E_Signer).([]string) - if len(signersFields) == 0 { - return nil, fmt.Errorf("no cosmos.msg.v1.signer option found for message %s", descriptor.FullName()) - } - - return signersFields, nil -} - -// init performs a dry run of getting all msg's signers. This has 2 benefits: -// - it will error if any Msg has forgotten the "cosmos.msg.v1.signer" -// annotation -// - it will pre-populate the context's internal cache for getSignersFuncs -// so that calling it in antehandlers will be faster. -func (c *Context) init() error { - var errs []error - c.fileResolver.RangeFiles(func(fd protoreflect.FileDescriptor) bool { - for i := 0; i < fd.Services().Len(); i++ { - sd := fd.Services().Get(i) - // We use the heuristic that services named "Msg" are exactly the - // ones that need the proto annotation check. - if sd.Name() != "Msg" { - continue - } - - for j := 0; j < sd.Methods().Len(); j++ { - md := sd.Methods().Get(j).Input() - msg := dynamicpb.NewMessage(md) - _, err := c.GetSigners(msg) - if err != nil { - errs = append(errs, err) - } - } - } - - return true - }) - - return errors.Join(errs...) -} - -func (c *Context) makeGetSignersFunc(descriptor protoreflect.MessageDescriptor) (getSignersFunc, error) { - signersFields, err := getSignersFieldNames(descriptor) - if err != nil { - return nil, err - } - - fieldGetters := make([]func(proto.Message, [][]byte) ([][]byte, error), len(signersFields)) - for i, fieldName := range signersFields { - field := descriptor.Fields().ByName(protoreflect.Name(fieldName)) - if field == nil { - return nil, fmt.Errorf("field %s not found in message %s", fieldName, descriptor.FullName()) - } - - if field.IsMap() || field.HasOptionalKeyword() { - return nil, fmt.Errorf("cosmos.msg.v1.signer field %s in message %s must not be a map or optional", fieldName, descriptor.FullName()) - } - - switch field.Kind() { - case protoreflect.StringKind: - addrCdc := c.getAddressCodec(field) - if field.IsList() { - fieldGetters[i] = func(msg proto.Message, arr [][]byte) ([][]byte, error) { - signers := msg.ProtoReflect().Get(field).List() - n := signers.Len() - for i := 0; i < n; i++ { - addrStr := signers.Get(i).String() - addrBz, err := addrCdc.StringToBytes(addrStr) - if err != nil { - return nil, err - } - arr = append(arr, addrBz) - } - return arr, nil - } - } else { - fieldGetters[i] = func(msg proto.Message, arr [][]byte) ([][]byte, error) { - addrStr := msg.ProtoReflect().Get(field).String() - addrBz, err := addrCdc.StringToBytes(addrStr) - if err != nil { - return nil, err - } - return append(arr, addrBz), nil - } - } - case protoreflect.MessageKind: - isList := field.IsList() - nestedMessage := field.Message() - nestedSignersFields, err := getSignersFieldNames(nestedMessage) - if err != nil { - return nil, err - } - - if len(nestedSignersFields) != 1 { - return nil, fmt.Errorf("nested cosmos.msg.v1.signer option in message %s must contain only one value", nestedMessage.FullName()) - } - - nestedFieldName := nestedSignersFields[0] - nestedField := nestedMessage.Fields().ByName(protoreflect.Name(nestedFieldName)) - nestedIsList := nestedField.IsList() - if nestedField == nil { - return nil, fmt.Errorf("field %s not found in message %s", nestedFieldName, nestedMessage.FullName()) - } - - if nestedField.Kind() != protoreflect.StringKind || nestedField.IsMap() || nestedField.HasOptionalKeyword() { - return nil, fmt.Errorf("nested signer field %s in message %s must be a simple string", nestedFieldName, nestedMessage.FullName()) - } - - addrCdc := c.getAddressCodec(nestedField) - - if isList { - if nestedIsList { - fieldGetters[i] = func(msg proto.Message, arr [][]byte) ([][]byte, error) { - msgs := msg.ProtoReflect().Get(field).List() - m := msgs.Len() - for i := 0; i < m; i++ { - signers := msgs.Get(i).Message().Get(nestedField).List() - n := signers.Len() - for j := 0; j < n; j++ { - addrStr := signers.Get(j).String() - addrBz, err := addrCdc.StringToBytes(addrStr) - if err != nil { - return nil, err - } - arr = append(arr, addrBz) - } - } - return arr, nil - } - } else { - fieldGetters[i] = func(msg proto.Message, arr [][]byte) ([][]byte, error) { - msgs := msg.ProtoReflect().Get(field).List() - m := msgs.Len() - for i := 0; i < m; i++ { - addrStr := msgs.Get(i).Message().Get(nestedField).String() - addrBz, err := addrCdc.StringToBytes(addrStr) - if err != nil { - return nil, err - } - arr = append(arr, addrBz) - } - return arr, nil - } - } - } else { - if nestedIsList { - fieldGetters[i] = func(msg proto.Message, arr [][]byte) ([][]byte, error) { - nestedMsg := msg.ProtoReflect().Get(field).Message() - signers := nestedMsg.Get(nestedField).List() - n := signers.Len() - for j := 0; j < n; j++ { - addrStr := signers.Get(j).String() - addrBz, err := addrCdc.StringToBytes(addrStr) - if err != nil { - return nil, err - } - arr = append(arr, addrBz) - } - return arr, nil - } - } else { - fieldGetters[i] = func(msg proto.Message, arr [][]byte) ([][]byte, error) { - addrStr := msg.ProtoReflect().Get(field).Message().Get(nestedField).String() - addrBz, err := addrCdc.StringToBytes(addrStr) - if err != nil { - return nil, err - } - return append(arr, addrBz), nil - } - } - } - - default: - return nil, fmt.Errorf("unexpected field type %s for field %s in message %s", field.Kind(), fieldName, descriptor.FullName()) - } - } - - return func(message proto.Message) ([][]byte, error) { - var signers [][]byte - for _, getter := range fieldGetters { - signers, err = getter(message, signers) - if err != nil { - return nil, err - } - } - return signers, nil - }, nil -} - -func (c *Context) getAddressCodec(field protoreflect.FieldDescriptor) address.Codec { - scalarOpt := proto.GetExtension(field.Options(), cosmos_proto.E_Scalar) - addrCdc := c.addressCodec - if scalarOpt != nil { - if scalarOpt.(string) == "cosmos.ValidatorAddressString" { - addrCdc = c.validatorAddressCodec - } - } - - return addrCdc -} - -// GetSigners returns the signers for a given message. -func (c *Context) GetSigners(msg proto.Message) ([][]byte, error) { - messageDescriptor := msg.ProtoReflect().Descriptor() - f, ok := c.getSignersFuncs[messageDescriptor.FullName()] - if !ok { - var err error - f, err = c.makeGetSignersFunc(messageDescriptor) - if err != nil { - return nil, err - } - c.getSignersFuncs[messageDescriptor.FullName()] = f - } - - return f(msg) -} - -// AddressCodec returns the address codec used by the context. -func (c *Context) AddressCodec() address.Codec { - return c.addressCodec -} - -// ValidatorAddressCodec returns the validator address codec used by the context. -func (c *Context) ValidatorAddressCodec() address.Codec { - return c.validatorAddressCodec -} - -// FileResolver returns the proto file resolver used by the context. -func (c *Context) FileResolver() ProtoFileResolver { - return c.fileResolver -} - -func (c *Context) TypeResolver() protoregistry.MessageTypeResolver { - return c.typeResolver -} diff --git a/x/tx/signing/context_test.go b/x/tx/signing/context_test.go deleted file mode 100644 index a5979e300d73..000000000000 --- a/x/tx/signing/context_test.go +++ /dev/null @@ -1,170 +0,0 @@ -package signing - -import ( - "encoding/hex" - "strings" - "testing" - - bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" - groupv1 "cosmossdk.io/api/cosmos/group/v1" - "cosmossdk.io/core/address" - "github.com/stretchr/testify/require" - "google.golang.org/protobuf/proto" - - "cosmossdk.io/x/tx/internal/testpb" -) - -func TestGetSigners(t *testing.T) { - ctx, err := NewContext(Options{ - AddressCodec: dummyAddressCodec{}, - ValidatorAddressCodec: dummyValidatorAddressCodec{}, - }) - require.NoError(t, err) - tests := []struct { - name string - msg proto.Message - want [][]byte - wantErr bool - }{ - { - name: "MsgSend", - msg: &bankv1beta1.MsgSend{ - FromAddress: hex.EncodeToString([]byte("foo")), - }, - want: [][]byte{[]byte("foo")}, - }, - { - name: "MsgMultiSend", - msg: &bankv1beta1.MsgMultiSend{ - Inputs: []*bankv1beta1.Input{ - {Address: hex.EncodeToString([]byte("foo"))}, - {Address: hex.EncodeToString([]byte("bar"))}, - }, - }, - want: [][]byte{[]byte("foo"), []byte("bar")}, - }, - { - name: "MsgSubmitProposal", - msg: &groupv1.MsgSubmitProposal{ - Proposers: []string{ - hex.EncodeToString([]byte("foo")), - hex.EncodeToString([]byte("bar")), - }, - }, - want: [][]byte{[]byte("foo"), []byte("bar")}, - }, - { - name: "simple", - msg: &testpb.SimpleSigner{Signer: hex.EncodeToString([]byte("foo"))}, - want: [][]byte{[]byte("foo")}, - }, - { - name: "repeated", - msg: &testpb.RepeatedSigner{Signer: []string{ - hex.EncodeToString([]byte("foo")), - hex.EncodeToString([]byte("bar")), - }}, - want: [][]byte{[]byte("foo"), []byte("bar")}, - }, - { - name: "nested", - msg: &testpb.NestedSigner{Inner: &testpb.NestedSigner_Inner{Signer: hex.EncodeToString([]byte("foo"))}}, - want: [][]byte{[]byte("foo")}, - }, - { - name: "nested repeated", - msg: &testpb.NestedRepeatedSigner{Inner: &testpb.NestedRepeatedSigner_Inner{Signer: []string{ - hex.EncodeToString([]byte("foo")), - hex.EncodeToString([]byte("bar")), - }}}, - want: [][]byte{[]byte("foo"), []byte("bar")}, - }, - { - name: "repeated nested", - msg: &testpb.RepeatedNestedSigner{Inner: []*testpb.RepeatedNestedSigner_Inner{ - {Signer: hex.EncodeToString([]byte("foo"))}, - {Signer: hex.EncodeToString([]byte("bar"))}, - }}, - want: [][]byte{[]byte("foo"), []byte("bar")}, - }, - { - name: "nested repeated", - msg: &testpb.NestedRepeatedSigner{Inner: &testpb.NestedRepeatedSigner_Inner{ - Signer: []string{ - hex.EncodeToString([]byte("foo")), - hex.EncodeToString([]byte("bar")), - }, - }}, - want: [][]byte{[]byte("foo"), []byte("bar")}, - }, - { - name: "repeated nested repeated", - msg: &testpb.RepeatedNestedRepeatedSigner{Inner: []*testpb.RepeatedNestedRepeatedSigner_Inner{ - {Signer: []string{ - hex.EncodeToString([]byte("foo")), - hex.EncodeToString([]byte("bar")), - }}, - {Signer: []string{ - hex.EncodeToString([]byte("baz")), - hex.EncodeToString([]byte("bam")), - }}, - {Signer: []string{ - hex.EncodeToString([]byte("blah")), - }}, - }}, - want: [][]byte{[]byte("foo"), []byte("bar"), []byte("baz"), []byte("bam"), []byte("blah")}, - }, - { - name: "bad", - msg: &testpb.BadSigner{}, - wantErr: true, - }, - { - name: "no signer", - msg: &testpb.NoSignerOption{}, - wantErr: true, - }, - { - name: "validator signer", - msg: &testpb.ValidatorSigner{ - Signer: "val" + hex.EncodeToString([]byte("foo")), - }, - want: [][]byte{[]byte("foo")}, - }, - } - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - signers, err := ctx.GetSigners(test.msg) - if test.wantErr { - require.Error(t, err) - } else { - require.NoError(t, err) - } - require.Equal(t, test.want, signers) - }) - } -} - -type dummyAddressCodec struct{} - -func (d dummyAddressCodec) StringToBytes(text string) ([]byte, error) { - return hex.DecodeString(text) -} - -func (d dummyAddressCodec) BytesToString(bz []byte) (string, error) { - return hex.EncodeToString(bz), nil -} - -var _ address.Codec = dummyAddressCodec{} - -type dummyValidatorAddressCodec struct{} - -func (d dummyValidatorAddressCodec) StringToBytes(text string) ([]byte, error) { - return hex.DecodeString(strings.TrimPrefix(text, "val")) -} - -func (d dummyValidatorAddressCodec) BytesToString(bz []byte) (string, error) { - return "val" + hex.EncodeToString(bz), nil -} - -var _ address.Codec = dummyValidatorAddressCodec{} From d24dbc2c194659b7b298625b9c7da44c17e9a547 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 13 Apr 2023 16:28:14 -0500 Subject: [PATCH 16/52] fix tx_test --- x/authz/client/cli/tx_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/x/authz/client/cli/tx_test.go b/x/authz/client/cli/tx_test.go index 1d4c5eff1a6d..9db7b6db1c64 100644 --- a/x/authz/client/cli/tx_test.go +++ b/x/authz/client/cli/tx_test.go @@ -7,12 +7,14 @@ import ( "testing" "time" - sdkmath "cosmossdk.io/math" abci "github.com/cometbft/cometbft/abci/types" rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock" "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/suite" + sdkmath "cosmossdk.io/math" + + _ "cosmossdk.io/api/cosmos/authz/v1beta1" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" From 2e627584cefcdee0cafa591ebd59ed8cc1c163f7 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 13 Apr 2023 16:31:38 -0500 Subject: [PATCH 17/52] revert x/tx --- go.mod | 1 - x/group/client/cli/tx_test.go | 4 +- x/tx/CHANGELOG.md | 12 + x/tx/decode/decode.go | 55 +- x/tx/decode/decode_test.go | 26 +- x/tx/internal/testpb/signers.proto | 7 + x/tx/internal/testpb/signers.pulsar.go | 617 +++++++++++++++++++--- x/tx/signing/context.go | 320 +++++++++++ x/tx/signing/context_test.go | 170 ++++++ x/tx/signing/directaux/direct_aux.go | 43 +- x/tx/signing/directaux/direct_aux_test.go | 24 +- x/tx/signing/get_signers.go | 222 -------- x/tx/signing/get_signers_test.go | 113 ---- x/tx/signing/textual/bench_test.go | 63 ++- x/tx/signing/textual/message.go | 6 +- 15 files changed, 1201 insertions(+), 482 deletions(-) create mode 100644 x/tx/signing/context.go create mode 100644 x/tx/signing/context_test.go delete mode 100644 x/tx/signing/get_signers.go delete mode 100644 x/tx/signing/get_signers_test.go diff --git a/go.mod b/go.mod index 3d0ecab10d83..82784203564a 100644 --- a/go.mod +++ b/go.mod @@ -172,7 +172,6 @@ replace ( github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.8.1 // Downgraded to avoid bugs in following commits which caused simulations to fail. github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 - cosmossdk.io/x/tx => ./x/tx ) retract ( diff --git a/x/group/client/cli/tx_test.go b/x/group/client/cli/tx_test.go index f9377eb67dba..e585393945f5 100644 --- a/x/group/client/cli/tx_test.go +++ b/x/group/client/cli/tx_test.go @@ -10,12 +10,14 @@ import ( "strings" "testing" - sdkmath "cosmossdk.io/math" abci "github.com/cometbft/cometbft/abci/types" rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock" "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/suite" + _ "cosmossdk.io/api/cosmos/group/v1" + sdkmath "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/crypto/hd" diff --git a/x/tx/CHANGELOG.md b/x/tx/CHANGELOG.md index dd956831e654..2b5921d98676 100644 --- a/x/tx/CHANGELOG.md +++ b/x/tx/CHANGELOG.md @@ -31,10 +31,22 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## Unreleased +### API Breaking + +* [#15709](https://github.com/cosmos/cosmos-sdk/pull/15709): + * `GetSignersContext` has been renamed to `signing.Context` + * `GetSigners` now returns `[][]byte` instead of `[]string` + * `GetSignersOptions` has been renamed to `signing.Options` and requires `address.Codec`s for account and validator addresses + * `GetSignersOptions.ProtoFiles` has been renamed to `signing.Options.FileResolver` + +## v0.5.1 + ### Features * [#15414](https://github.com/cosmos/cosmos-sdk/pull/15414) Add basic transaction decoding support. +## v0.5.0 + ### API Breaking * [#15581](https://github.com/cosmos/cosmos-sdk/pull/15581) `GetSignersOptions` and `directaux.SignModeHandlerOptions` now diff --git a/x/tx/decode/decode.go b/x/tx/decode/decode.go index 4ee08437707f..d046a396d01e 100644 --- a/x/tx/decode/decode.go +++ b/x/tx/decode/decode.go @@ -1,12 +1,13 @@ package decode import ( - "github.com/cosmos/cosmos-proto/anyutil" - "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/reflect/protoregistry" + "fmt" v1beta1 "cosmossdk.io/api/cosmos/tx/v1beta1" "cosmossdk.io/errors" + "github.com/cosmos/cosmos-proto/anyutil" + "google.golang.org/protobuf/proto" + "cosmossdk.io/x/tx/signing" ) @@ -15,51 +16,28 @@ type DecodedTx struct { Messages []proto.Message Tx *v1beta1.Tx TxRaw *v1beta1.TxRaw - Signers []string + Signers [][]byte TxBodyHasUnknownNonCriticals bool } // Decoder contains the dependencies required for decoding transactions. type Decoder struct { - getSignersCtx *signing.GetSignersContext - typeResolver protoregistry.MessageTypeResolver - protoFiles *protoregistry.Files + signingCtx *signing.Context } // Options are options for creating a Decoder. type Options struct { - // ProtoFiles are the protobuf files to use for resolving message descriptors. - // If it is nil, the global protobuf registry will be used. - ProtoFiles *protoregistry.Files - TypeResolver protoregistry.MessageTypeResolver - SigningContext *signing.GetSignersContext + SigningContext *signing.Context } // NewDecoder creates a new Decoder for decoding transactions. func NewDecoder(options Options) (*Decoder, error) { - if options.ProtoFiles == nil { - options.ProtoFiles = protoregistry.GlobalFiles - } - - if options.TypeResolver == nil { - options.TypeResolver = protoregistry.GlobalTypes - } - - getSignersCtx := options.SigningContext - if getSignersCtx == nil { - var err error - getSignersCtx, err = signing.NewGetSignersContext(signing.GetSignersOptions{ - ProtoFiles: options.ProtoFiles, - }) - if err != nil { - return nil, err - } + if options.SigningContext == nil { + return nil, fmt.Errorf("signing context is required") } return &Decoder{ - getSignersCtx: getSignersCtx, - protoFiles: options.ProtoFiles, - typeResolver: options.TypeResolver, + signingCtx: options.SigningContext, }, nil } @@ -74,7 +52,8 @@ func (d *Decoder) Decode(txBytes []byte) (*DecodedTx, error) { var raw v1beta1.TxRaw // reject all unknown proto fields in the root TxRaw - err = RejectUnknownFieldsStrict(txBytes, raw.ProtoReflect().Descriptor(), d.protoFiles) + fileResolver := d.signingCtx.FileResolver() + err = RejectUnknownFieldsStrict(txBytes, raw.ProtoReflect().Descriptor(), fileResolver) if err != nil { return nil, errors.Wrap(ErrTxDecode, err.Error()) } @@ -87,7 +66,7 @@ func (d *Decoder) Decode(txBytes []byte) (*DecodedTx, error) { var body v1beta1.TxBody // allow non-critical unknown fields in TxBody - txBodyHasUnknownNonCriticals, err := RejectUnknownFields(raw.BodyBytes, body.ProtoReflect().Descriptor(), true, d.protoFiles) + txBodyHasUnknownNonCriticals, err := RejectUnknownFields(raw.BodyBytes, body.ProtoReflect().Descriptor(), true, fileResolver) if err != nil { return nil, errors.Wrap(ErrTxDecode, err.Error()) } @@ -100,7 +79,7 @@ func (d *Decoder) Decode(txBytes []byte) (*DecodedTx, error) { var authInfo v1beta1.AuthInfo // reject all unknown proto fields in AuthInfo - err = RejectUnknownFieldsStrict(raw.AuthInfoBytes, authInfo.ProtoReflect().Descriptor(), d.protoFiles) + err = RejectUnknownFieldsStrict(raw.AuthInfoBytes, authInfo.ProtoReflect().Descriptor(), fileResolver) if err != nil { return nil, errors.Wrap(ErrTxDecode, err.Error()) } @@ -116,15 +95,15 @@ func (d *Decoder) Decode(txBytes []byte) (*DecodedTx, error) { Signatures: raw.Signatures, } - var signers []string + var signers [][]byte var msgs []proto.Message for _, anyMsg := range body.Messages { - msg, signerErr := anyutil.Unpack(anyMsg, d.protoFiles, d.typeResolver) + msg, signerErr := anyutil.Unpack(anyMsg, fileResolver, d.signingCtx.TypeResolver()) if signerErr != nil { return nil, errors.Wrap(ErrTxDecode, signerErr.Error()) } msgs = append(msgs, msg) - ss, signerErr := d.getSignersCtx.GetSigners(msg) + ss, signerErr := d.signingCtx.GetSigners(msg) if signerErr != nil { return nil, errors.Wrap(ErrTxDecode, signerErr.Error()) } diff --git a/x/tx/decode/decode_test.go b/x/tx/decode/decode_test.go index a7169a9989da..1c095030e6b1 100644 --- a/x/tx/decode/decode_test.go +++ b/x/tx/decode/decode_test.go @@ -1,6 +1,7 @@ package decode_test import ( + "encoding/hex" "fmt" "testing" @@ -9,8 +10,10 @@ import ( "cosmossdk.io/api/cosmos/crypto/secp256k1" signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1" txv1beta1 "cosmossdk.io/api/cosmos/tx/v1beta1" + "cosmossdk.io/x/tx/decode" "cosmossdk.io/x/tx/internal/testpb" + "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-proto/anyutil" "github.com/stretchr/testify/require" @@ -36,6 +39,16 @@ func TestDecode(t *testing.T) { Sequence: accSeq, }) + signingCtx, err := signing.NewContext(signing.Options{ + AddressCodec: dummyAddressCodec{}, + ValidatorAddressCodec: dummyAddressCodec{}, + }) + require.NoError(t, err) + decoder, err := decode.NewDecoder(decode.Options{ + SigningContext: signingCtx, + }) + require.NoError(t, err) + testCases := []struct { name string msg proto.Message @@ -83,9 +96,6 @@ func TestDecode(t *testing.T) { txBytes, err := proto.Marshal(tx) require.NoError(t, err) - decoder, err := decode.NewDecoder(decode.Options{}) - require.NoError(t, err) - decodeTx, err := decoder.Decode(txBytes) if tc.error != "" { require.EqualError(t, err, tc.error) @@ -99,3 +109,13 @@ func TestDecode(t *testing.T) { }) } } + +type dummyAddressCodec struct{} + +func (d dummyAddressCodec) StringToBytes(text string) ([]byte, error) { + return hex.DecodeString(text) +} + +func (d dummyAddressCodec) BytesToString(bz []byte) (string, error) { + return hex.EncodeToString(bz), nil +} diff --git a/x/tx/internal/testpb/signers.proto b/x/tx/internal/testpb/signers.proto index 26b9867b2ad6..dfd6db078646 100644 --- a/x/tx/internal/testpb/signers.proto +++ b/x/tx/internal/testpb/signers.proto @@ -1,6 +1,7 @@ syntax = "proto3"; import "cosmos/msg/v1/msg.proto"; +import "cosmos_proto/cosmos.proto"; option go_package = "cosmossdk.io/x/tx/internal/testpb"; @@ -58,6 +59,12 @@ message BadSigner { option (cosmos.msg.v1.signer) = "signer"; bytes signer = 1; } + message NoSignerOption { bytes signer = 1; } + +message ValidatorSigner { + option (cosmos.msg.v1.signer) = "signer"; + string signer = 1 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"]; +} \ No newline at end of file diff --git a/x/tx/internal/testpb/signers.pulsar.go b/x/tx/internal/testpb/signers.pulsar.go index b554e807f002..f7ce5db88e20 100644 --- a/x/tx/internal/testpb/signers.pulsar.go +++ b/x/tx/internal/testpb/signers.pulsar.go @@ -4,6 +4,7 @@ package testpb import ( _ "cosmossdk.io/api/cosmos/msg/v1" fmt "fmt" + _ "github.com/cosmos/cosmos-proto" runtime "github.com/cosmos/cosmos-proto/runtime" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoiface "google.golang.org/protobuf/runtime/protoiface" @@ -1368,7 +1369,7 @@ func (x *NestedSigner_Inner) ProtoReflect() protoreflect.Message { } func (x *NestedSigner_Inner) slowProtoReflect() protoreflect.Message { - mi := &file_signers_proto_msgTypes[8] + mi := &file_signers_proto_msgTypes[9] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2282,7 +2283,7 @@ func (x *RepeatedNestedSigner_Inner) ProtoReflect() protoreflect.Message { } func (x *RepeatedNestedSigner_Inner) slowProtoReflect() protoreflect.Message { - mi := &file_signers_proto_msgTypes[9] + mi := &file_signers_proto_msgTypes[10] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -3183,7 +3184,7 @@ func (x *NestedRepeatedSigner_Inner) ProtoReflect() protoreflect.Message { } func (x *NestedRepeatedSigner_Inner) slowProtoReflect() protoreflect.Message { - mi := &file_signers_proto_msgTypes[10] + mi := &file_signers_proto_msgTypes[11] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -4157,7 +4158,7 @@ func (x *RepeatedNestedRepeatedSigner_Inner) ProtoReflect() protoreflect.Message } func (x *RepeatedNestedRepeatedSigner_Inner) slowProtoReflect() protoreflect.Message { - mi := &file_signers_proto_msgTypes[11] + mi := &file_signers_proto_msgTypes[12] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -5415,6 +5416,426 @@ func (x *fastReflection_NoSignerOption) ProtoMethods() *protoiface.Methods { } } +var ( + md_ValidatorSigner protoreflect.MessageDescriptor + fd_ValidatorSigner_signer protoreflect.FieldDescriptor +) + +func init() { + file_signers_proto_init() + md_ValidatorSigner = File_signers_proto.Messages().ByName("ValidatorSigner") + fd_ValidatorSigner_signer = md_ValidatorSigner.Fields().ByName("signer") +} + +var _ protoreflect.Message = (*fastReflection_ValidatorSigner)(nil) + +type fastReflection_ValidatorSigner ValidatorSigner + +func (x *ValidatorSigner) ProtoReflect() protoreflect.Message { + return (*fastReflection_ValidatorSigner)(x) +} + +func (x *ValidatorSigner) slowProtoReflect() protoreflect.Message { + mi := &file_signers_proto_msgTypes[8] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +var _fastReflection_ValidatorSigner_messageType fastReflection_ValidatorSigner_messageType +var _ protoreflect.MessageType = fastReflection_ValidatorSigner_messageType{} + +type fastReflection_ValidatorSigner_messageType struct{} + +func (x fastReflection_ValidatorSigner_messageType) Zero() protoreflect.Message { + return (*fastReflection_ValidatorSigner)(nil) +} +func (x fastReflection_ValidatorSigner_messageType) New() protoreflect.Message { + return new(fastReflection_ValidatorSigner) +} +func (x fastReflection_ValidatorSigner_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_ValidatorSigner +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_ValidatorSigner) Descriptor() protoreflect.MessageDescriptor { + return md_ValidatorSigner +} + +// Type returns the message type, which encapsulates both Go and protobuf +// type information. If the Go type information is not needed, +// it is recommended that the message descriptor be used instead. +func (x *fastReflection_ValidatorSigner) Type() protoreflect.MessageType { + return _fastReflection_ValidatorSigner_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_ValidatorSigner) New() protoreflect.Message { + return new(fastReflection_ValidatorSigner) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_ValidatorSigner) Interface() protoreflect.ProtoMessage { + return (*ValidatorSigner)(x) +} + +// Range iterates over every populated field in an undefined order, +// calling f for each field descriptor and value encountered. +// Range returns immediately if f returns false. +// While iterating, mutating operations may only be performed +// on the current field descriptor. +func (x *fastReflection_ValidatorSigner) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if x.Signer != "" { + value := protoreflect.ValueOfString(x.Signer) + if !f(fd_ValidatorSigner_signer, value) { + return + } + } +} + +// Has reports whether a field is populated. +// +// Some fields have the property of nullability where it is possible to +// distinguish between the default value of a field and whether the field +// was explicitly populated with the default value. Singular message fields, +// member fields of a oneof, and proto2 scalar fields are nullable. Such +// fields are populated only if explicitly set. +// +// In other cases (aside from the nullable cases above), +// a proto3 scalar field is populated if it contains a non-zero value, and +// a repeated field is populated if it is non-empty. +func (x *fastReflection_ValidatorSigner) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + case "ValidatorSigner.signer": + return x.Signer != "" + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: ValidatorSigner")) + } + panic(fmt.Errorf("message ValidatorSigner does not contain field %s", fd.FullName())) + } +} + +// Clear clears the field such that a subsequent Has call reports false. +// +// Clearing an extension field clears both the extension type and value +// associated with the given field number. +// +// Clear is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_ValidatorSigner) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + case "ValidatorSigner.signer": + x.Signer = "" + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: ValidatorSigner")) + } + panic(fmt.Errorf("message ValidatorSigner does not contain field %s", fd.FullName())) + } +} + +// Get retrieves the value for a field. +// +// For unpopulated scalars, it returns the default value, where +// the default value of a bytes scalar is guaranteed to be a copy. +// For unpopulated composite types, it returns an empty, read-only view +// of the value; to obtain a mutable reference, use Mutable. +func (x *fastReflection_ValidatorSigner) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + case "ValidatorSigner.signer": + value := x.Signer + return protoreflect.ValueOfString(value) + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: ValidatorSigner")) + } + panic(fmt.Errorf("message ValidatorSigner does not contain field %s", descriptor.FullName())) + } +} + +// Set stores the value for a field. +// +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType. +// When setting a composite type, it is unspecified whether the stored value +// aliases the source's memory in any way. If the composite value is an +// empty, read-only value, then it panics. +// +// Set is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_ValidatorSigner) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + case "ValidatorSigner.signer": + x.Signer = value.Interface().(string) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: ValidatorSigner")) + } + panic(fmt.Errorf("message ValidatorSigner does not contain field %s", fd.FullName())) + } +} + +// Mutable returns a mutable reference to a composite type. +// +// If the field is unpopulated, it may allocate a composite value. +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType +// if not already stored. +// It panics if the field does not contain a composite type. +// +// Mutable is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_ValidatorSigner) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "ValidatorSigner.signer": + panic(fmt.Errorf("field signer of message ValidatorSigner is not mutable")) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: ValidatorSigner")) + } + panic(fmt.Errorf("message ValidatorSigner does not contain field %s", fd.FullName())) + } +} + +// NewField returns a new value that is assignable to the field +// for the given descriptor. For scalars, this returns the default value. +// For lists, maps, and messages, this returns a new, empty, mutable value. +func (x *fastReflection_ValidatorSigner) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "ValidatorSigner.signer": + return protoreflect.ValueOfString("") + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: ValidatorSigner")) + } + panic(fmt.Errorf("message ValidatorSigner does not contain field %s", fd.FullName())) + } +} + +// WhichOneof reports which field within the oneof is populated, +// returning nil if none are populated. +// It panics if the oneof descriptor does not belong to this message. +func (x *fastReflection_ValidatorSigner) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in ValidatorSigner", d.FullName())) + } + panic("unreachable") +} + +// GetUnknown retrieves the entire list of unknown fields. +// The caller may only mutate the contents of the RawFields +// if the mutated bytes are stored back into the message with SetUnknown. +func (x *fastReflection_ValidatorSigner) GetUnknown() protoreflect.RawFields { + return x.unknownFields +} + +// SetUnknown stores an entire list of unknown fields. +// The raw fields must be syntactically valid according to the wire format. +// An implementation may panic if this is not the case. +// Once stored, the caller must not mutate the content of the RawFields. +// An empty RawFields may be passed to clear the fields. +// +// SetUnknown is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_ValidatorSigner) SetUnknown(fields protoreflect.RawFields) { + x.unknownFields = fields +} + +// IsValid reports whether the message is valid. +// +// An invalid message is an empty, read-only value. +// +// An invalid message often corresponds to a nil pointer of the concrete +// message type, but the details are implementation dependent. +// Validity is not part of the protobuf data model, and may not +// be preserved in marshaling or other operations. +func (x *fastReflection_ValidatorSigner) IsValid() bool { + return x != nil +} + +// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. +// This method may return nil. +// +// The returned methods type is identical to +// "google.golang.org/protobuf/runtime/protoiface".Methods. +// Consult the protoiface package documentation for details. +func (x *fastReflection_ValidatorSigner) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*ValidatorSigner) + if x == nil { + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: 0, + } + } + options := runtime.SizeInputToOptions(input) + _ = options + var n int + var l int + _ = l + l = len(x.Signer) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } + if x.unknownFields != nil { + n += len(x.unknownFields) + } + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: n, + } + } + + marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) { + x := input.Message.Interface().(*ValidatorSigner) + if x == nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + options := runtime.MarshalInputToOptions(input) + _ = options + size := options.Size(x) + dAtA := make([]byte, size) + i := len(dAtA) + _ = i + var l int + _ = l + if x.unknownFields != nil { + i -= len(x.unknownFields) + copy(dAtA[i:], x.unknownFields) + } + if len(x.Signer) > 0 { + i -= len(x.Signer) + copy(dAtA[i:], x.Signer) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Signer))) + i-- + dAtA[i] = 0xa + } + if input.Buf != nil { + input.Buf = append(input.Buf, dAtA...) + } else { + input.Buf = dAtA + } + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) { + x := input.Message.Interface().(*ValidatorSigner) + if x == nil { + return protoiface.UnmarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Flags: input.Flags, + }, nil + } + options := runtime.UnmarshalInputToOptions(input) + _ = options + dAtA := input.Buf + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: ValidatorSigner: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: ValidatorSigner: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Signer", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.Signer = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := runtime.Skip(dAtA[iNdEx:]) + if err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if !options.DiscardUnknown { + x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + } + iNdEx += skippy + } + } + + if iNdEx > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil + } + return &protoiface.Methods{ + NoUnkeyedLiterals: struct{}{}, + Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown, + Size: size, + Marshal: marshal, + Unmarshal: unmarshal, + Merge: nil, + CheckInitialized: nil, + } +} + // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.27.0 @@ -5708,6 +6129,41 @@ func (x *NoSignerOption) GetSigner() []byte { return nil } +type ValidatorSigner struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Signer string `protobuf:"bytes,1,opt,name=signer,proto3" json:"signer,omitempty"` +} + +func (x *ValidatorSigner) Reset() { + *x = ValidatorSigner{} + if protoimpl.UnsafeEnabled { + mi := &file_signers_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ValidatorSigner) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ValidatorSigner) ProtoMessage() {} + +// Deprecated: Use ValidatorSigner.ProtoReflect.Descriptor instead. +func (*ValidatorSigner) Descriptor() ([]byte, []int) { + return file_signers_proto_rawDescGZIP(), []int{8} +} + +func (x *ValidatorSigner) GetSigner() string { + if x != nil { + return x.Signer + } + return "" +} + type NestedSigner_Inner struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -5719,7 +6175,7 @@ type NestedSigner_Inner struct { func (x *NestedSigner_Inner) Reset() { *x = NestedSigner_Inner{} if protoimpl.UnsafeEnabled { - mi := &file_signers_proto_msgTypes[8] + mi := &file_signers_proto_msgTypes[9] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -5754,7 +6210,7 @@ type RepeatedNestedSigner_Inner struct { func (x *RepeatedNestedSigner_Inner) Reset() { *x = RepeatedNestedSigner_Inner{} if protoimpl.UnsafeEnabled { - mi := &file_signers_proto_msgTypes[9] + mi := &file_signers_proto_msgTypes[10] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -5789,7 +6245,7 @@ type NestedRepeatedSigner_Inner struct { func (x *NestedRepeatedSigner_Inner) Reset() { *x = NestedRepeatedSigner_Inner{} if protoimpl.UnsafeEnabled { - mi := &file_signers_proto_msgTypes[10] + mi := &file_signers_proto_msgTypes[11] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -5824,7 +6280,7 @@ type RepeatedNestedRepeatedSigner_Inner struct { func (x *RepeatedNestedRepeatedSigner_Inner) Reset() { *x = RepeatedNestedRepeatedSigner_Inner{} if protoimpl.UnsafeEnabled { - mi := &file_signers_proto_msgTypes[11] + mi := &file_signers_proto_msgTypes[12] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -5853,57 +6309,65 @@ var File_signers_proto protoreflect.FileDescriptor var file_signers_proto_rawDesc = []byte{ 0x0a, 0x0d, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x17, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x6d, 0x73, 0x67, 0x2f, 0x76, 0x31, 0x2f, 0x6d, - 0x73, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x33, 0x0a, 0x0c, 0x53, 0x69, 0x6d, 0x70, - 0x6c, 0x65, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x69, 0x67, 0x6e, - 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, - 0x3a, 0x0b, 0x82, 0xe7, 0xb0, 0x2a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x22, 0x35, 0x0a, - 0x0e, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x12, + 0x73, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x19, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, + 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x22, 0x33, 0x0a, 0x0c, 0x53, 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x53, 0x69, 0x67, + 0x6e, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x3a, 0x0b, 0x82, 0xe7, 0xb0, + 0x2a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x22, 0x35, 0x0a, 0x0e, 0x52, 0x65, 0x70, 0x65, + 0x61, 0x74, 0x65, 0x64, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x69, + 0x67, 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x06, 0x73, 0x69, 0x67, 0x6e, + 0x65, 0x72, 0x3a, 0x0b, 0x82, 0xe7, 0xb0, 0x2a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x22, + 0x73, 0x0a, 0x0c, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x12, + 0x29, 0x0a, 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, + 0x2e, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x2e, 0x49, 0x6e, + 0x6e, 0x65, 0x72, 0x52, 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x1a, 0x2c, 0x0a, 0x05, 0x49, 0x6e, + 0x6e, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x3a, 0x0b, 0x82, 0xe7, 0xb0, + 0x2a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x3a, 0x0a, 0x82, 0xe7, 0xb0, 0x2a, 0x05, 0x69, + 0x6e, 0x6e, 0x65, 0x72, 0x22, 0x83, 0x01, 0x0a, 0x14, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, + 0x64, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x12, 0x31, 0x0a, + 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x52, + 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x53, 0x69, 0x67, + 0x6e, 0x65, 0x72, 0x2e, 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x52, 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, + 0x1a, 0x2c, 0x0a, 0x05, 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x69, 0x67, + 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, + 0x72, 0x3a, 0x0b, 0x82, 0xe7, 0xb0, 0x2a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x3a, 0x0a, + 0x82, 0xe7, 0xb0, 0x2a, 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x22, 0x83, 0x01, 0x0a, 0x14, 0x4e, + 0x65, 0x73, 0x74, 0x65, 0x64, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x53, 0x69, 0x67, + 0x6e, 0x65, 0x72, 0x12, 0x31, 0x0a, 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x52, 0x65, 0x70, 0x65, 0x61, + 0x74, 0x65, 0x64, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x2e, 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x52, + 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x1a, 0x2c, 0x0a, 0x05, 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x3a, 0x0b, 0x82, 0xe7, 0xb0, 0x2a, 0x06, 0x73, 0x69, - 0x67, 0x6e, 0x65, 0x72, 0x22, 0x73, 0x0a, 0x0c, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x53, 0x69, - 0x67, 0x6e, 0x65, 0x72, 0x12, 0x29, 0x0a, 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x53, 0x69, 0x67, 0x6e, - 0x65, 0x72, 0x2e, 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x52, 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x1a, - 0x2c, 0x0a, 0x05, 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x69, 0x67, 0x6e, - 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, - 0x3a, 0x0b, 0x82, 0xe7, 0xb0, 0x2a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x3a, 0x0a, 0x82, - 0xe7, 0xb0, 0x2a, 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x22, 0x83, 0x01, 0x0a, 0x14, 0x52, 0x65, - 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x53, 0x69, 0x67, 0x6e, - 0x65, 0x72, 0x12, 0x31, 0x0a, 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, 0x03, 0x28, - 0x0b, 0x32, 0x1b, 0x2e, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x4e, 0x65, 0x73, 0x74, - 0x65, 0x64, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x2e, 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x52, 0x05, - 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x1a, 0x2c, 0x0a, 0x05, 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x12, 0x16, - 0x0a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, - 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x3a, 0x0b, 0x82, 0xe7, 0xb0, 0x2a, 0x06, 0x73, 0x69, 0x67, - 0x6e, 0x65, 0x72, 0x3a, 0x0a, 0x82, 0xe7, 0xb0, 0x2a, 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x22, - 0x83, 0x01, 0x0a, 0x14, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, - 0x65, 0x64, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x12, 0x31, 0x0a, 0x05, 0x69, 0x6e, 0x6e, 0x65, - 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, - 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x2e, 0x49, - 0x6e, 0x6e, 0x65, 0x72, 0x52, 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x1a, 0x2c, 0x0a, 0x05, 0x49, - 0x6e, 0x6e, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x18, 0x01, - 0x20, 0x03, 0x28, 0x09, 0x52, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x3a, 0x0b, 0x82, 0xe7, - 0xb0, 0x2a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x3a, 0x0a, 0x82, 0xe7, 0xb0, 0x2a, 0x05, - 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x22, 0x93, 0x01, 0x0a, 0x1c, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, - 0x65, 0x64, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, - 0x53, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x12, 0x39, 0x0a, 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x18, - 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, - 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x53, 0x69, - 0x67, 0x6e, 0x65, 0x72, 0x2e, 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x52, 0x05, 0x69, 0x6e, 0x6e, 0x65, - 0x72, 0x1a, 0x2c, 0x0a, 0x05, 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x69, - 0x67, 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x06, 0x73, 0x69, 0x67, 0x6e, - 0x65, 0x72, 0x3a, 0x0b, 0x82, 0xe7, 0xb0, 0x2a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x3a, - 0x0a, 0x82, 0xe7, 0xb0, 0x2a, 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x22, 0x30, 0x0a, 0x09, 0x42, - 0x61, 0x64, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x69, 0x67, 0x6e, - 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, - 0x3a, 0x0b, 0x82, 0xe7, 0xb0, 0x2a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x22, 0x28, 0x0a, - 0x0e, 0x4e, 0x6f, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, - 0x16, 0x0a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, - 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x42, 0x3b, 0x42, 0x0c, 0x53, 0x69, 0x67, 0x6e, 0x65, - 0x72, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x29, 0x63, 0x6f, 0x73, 0x6d, 0x6f, - 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x78, 0x2f, 0x74, 0x78, 0x2f, 0x74, 0x65, 0x78, - 0x74, 0x75, 0x61, 0x6c, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, - 0x73, 0x74, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x67, 0x6e, 0x65, 0x72, 0x3a, 0x0a, 0x82, 0xe7, 0xb0, 0x2a, 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, + 0x22, 0x93, 0x01, 0x0a, 0x1c, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x4e, 0x65, 0x73, + 0x74, 0x65, 0x64, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x53, 0x69, 0x67, 0x6e, 0x65, + 0x72, 0x12, 0x39, 0x0a, 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x23, 0x2e, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x4e, 0x65, 0x73, 0x74, 0x65, + 0x64, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x2e, + 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x52, 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x1a, 0x2c, 0x0a, 0x05, + 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x18, + 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x3a, 0x0b, 0x82, + 0xe7, 0xb0, 0x2a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x3a, 0x0a, 0x82, 0xe7, 0xb0, 0x2a, + 0x05, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x22, 0x30, 0x0a, 0x09, 0x42, 0x61, 0x64, 0x53, 0x69, 0x67, + 0x6e, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0c, 0x52, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x3a, 0x0b, 0x82, 0xe7, 0xb0, + 0x2a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x22, 0x28, 0x0a, 0x0e, 0x4e, 0x6f, 0x53, 0x69, + 0x67, 0x6e, 0x65, 0x72, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x69, + 0x67, 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x73, 0x69, 0x67, 0x6e, + 0x65, 0x72, 0x22, 0x59, 0x0a, 0x0f, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x53, + 0x69, 0x67, 0x6e, 0x65, 0x72, 0x12, 0x39, 0x0a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x21, 0xd2, 0xb4, 0x2d, 0x1d, 0x63, 0x6f, 0x73, 0x6d, 0x6f, + 0x73, 0x2e, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x41, 0x64, 0x64, 0x72, 0x65, + 0x73, 0x73, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x52, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, + 0x3a, 0x0b, 0x82, 0xe7, 0xb0, 0x2a, 0x06, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x42, 0x3b, 0x42, + 0x0c, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, + 0x29, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x78, 0x2f, + 0x74, 0x78, 0x2f, 0x74, 0x65, 0x78, 0x74, 0x75, 0x61, 0x6c, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, + 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var ( @@ -5918,7 +6382,7 @@ func file_signers_proto_rawDescGZIP() []byte { return file_signers_proto_rawDescData } -var file_signers_proto_msgTypes = make([]protoimpl.MessageInfo, 12) +var file_signers_proto_msgTypes = make([]protoimpl.MessageInfo, 13) var file_signers_proto_goTypes = []interface{}{ (*SimpleSigner)(nil), // 0: SimpleSigner (*RepeatedSigner)(nil), // 1: RepeatedSigner @@ -5928,16 +6392,17 @@ var file_signers_proto_goTypes = []interface{}{ (*RepeatedNestedRepeatedSigner)(nil), // 5: RepeatedNestedRepeatedSigner (*BadSigner)(nil), // 6: BadSigner (*NoSignerOption)(nil), // 7: NoSignerOption - (*NestedSigner_Inner)(nil), // 8: NestedSigner.Inner - (*RepeatedNestedSigner_Inner)(nil), // 9: RepeatedNestedSigner.Inner - (*NestedRepeatedSigner_Inner)(nil), // 10: NestedRepeatedSigner.Inner - (*RepeatedNestedRepeatedSigner_Inner)(nil), // 11: RepeatedNestedRepeatedSigner.Inner + (*ValidatorSigner)(nil), // 8: ValidatorSigner + (*NestedSigner_Inner)(nil), // 9: NestedSigner.Inner + (*RepeatedNestedSigner_Inner)(nil), // 10: RepeatedNestedSigner.Inner + (*NestedRepeatedSigner_Inner)(nil), // 11: NestedRepeatedSigner.Inner + (*RepeatedNestedRepeatedSigner_Inner)(nil), // 12: RepeatedNestedRepeatedSigner.Inner } var file_signers_proto_depIdxs = []int32{ - 8, // 0: NestedSigner.inner:type_name -> NestedSigner.Inner - 9, // 1: RepeatedNestedSigner.inner:type_name -> RepeatedNestedSigner.Inner - 10, // 2: NestedRepeatedSigner.inner:type_name -> NestedRepeatedSigner.Inner - 11, // 3: RepeatedNestedRepeatedSigner.inner:type_name -> RepeatedNestedRepeatedSigner.Inner + 9, // 0: NestedSigner.inner:type_name -> NestedSigner.Inner + 10, // 1: RepeatedNestedSigner.inner:type_name -> RepeatedNestedSigner.Inner + 11, // 2: NestedRepeatedSigner.inner:type_name -> NestedRepeatedSigner.Inner + 12, // 3: RepeatedNestedRepeatedSigner.inner:type_name -> RepeatedNestedRepeatedSigner.Inner 4, // [4:4] is the sub-list for method output_type 4, // [4:4] is the sub-list for method input_type 4, // [4:4] is the sub-list for extension type_name @@ -6048,7 +6513,7 @@ func file_signers_proto_init() { } } file_signers_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*NestedSigner_Inner); i { + switch v := v.(*ValidatorSigner); i { case 0: return &v.state case 1: @@ -6060,7 +6525,7 @@ func file_signers_proto_init() { } } file_signers_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*RepeatedNestedSigner_Inner); i { + switch v := v.(*NestedSigner_Inner); i { case 0: return &v.state case 1: @@ -6072,7 +6537,7 @@ func file_signers_proto_init() { } } file_signers_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*NestedRepeatedSigner_Inner); i { + switch v := v.(*RepeatedNestedSigner_Inner); i { case 0: return &v.state case 1: @@ -6084,6 +6549,18 @@ func file_signers_proto_init() { } } file_signers_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*NestedRepeatedSigner_Inner); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_signers_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*RepeatedNestedRepeatedSigner_Inner); i { case 0: return &v.state @@ -6102,7 +6579,7 @@ func file_signers_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_signers_proto_rawDesc, NumEnums: 0, - NumMessages: 12, + NumMessages: 13, NumExtensions: 0, NumServices: 0, }, diff --git a/x/tx/signing/context.go b/x/tx/signing/context.go new file mode 100644 index 000000000000..c8afe2e83891 --- /dev/null +++ b/x/tx/signing/context.go @@ -0,0 +1,320 @@ +package signing + +import ( + "errors" + "fmt" + + "cosmossdk.io/core/address" + cosmos_proto "github.com/cosmos/cosmos-proto" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/reflect/protodesc" + "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/reflect/protoregistry" + "google.golang.org/protobuf/types/dynamicpb" + + msgv1 "cosmossdk.io/api/cosmos/msg/v1" +) + +// Context is a context for retrieving the list of signers from a +// message where signers are specified by the cosmos.msg.v1.signer protobuf +// option. It also contains the ProtoFileResolver and address.Codec's used +// for resolving message descriptors and converting addresses. +type Context struct { + fileResolver ProtoFileResolver + typeResolver protoregistry.MessageTypeResolver + addressCodec address.Codec + validatorAddressCodec address.Codec + getSignersFuncs map[protoreflect.FullName]getSignersFunc +} + +// Options are options for creating Context which will be used for signing operations. +type Options struct { + // FileResolver is the protobuf file resolver to use for resolving message descriptors. + // If it is nil, the global protobuf registry will be used. + FileResolver ProtoFileResolver + + // TypeResolver is the protobuf type resolver to use for resolving message types. + TypeResolver protoregistry.MessageTypeResolver + + // AddressCodec is the codec for converting addresses between strings and bytes. + AddressCodec address.Codec + + // ValidatorAddressCodec is the codec for converting validator addresses between strings and bytes. + ValidatorAddressCodec address.Codec +} + +// ProtoFileResolver is a protodesc.Resolver that also allows iterating over all +// files descriptors. It is a subset of the methods supported by protoregistry.Files. +type ProtoFileResolver interface { + protodesc.Resolver + RangeFiles(func(protoreflect.FileDescriptor) bool) +} + +// NewContext creates a new Context using the provided options. +func NewContext(options Options) (*Context, error) { + protoFiles := options.FileResolver + if protoFiles == nil { + protoFiles = protoregistry.GlobalFiles + } + + protoTypes := options.TypeResolver + if protoTypes == nil { + protoTypes = protoregistry.GlobalTypes + } + + if options.AddressCodec == nil { + return nil, errors.New("address codec is required") + } + + if options.ValidatorAddressCodec == nil { + return nil, errors.New("validator address codec is required") + } + + c := &Context{ + fileResolver: protoFiles, + typeResolver: protoTypes, + addressCodec: options.AddressCodec, + validatorAddressCodec: options.ValidatorAddressCodec, + getSignersFuncs: map[protoreflect.FullName]getSignersFunc{}, + } + + return c, c.init() +} + +type getSignersFunc func(proto.Message) ([][]byte, error) + +func getSignersFieldNames(descriptor protoreflect.MessageDescriptor) ([]string, error) { + signersFields := proto.GetExtension(descriptor.Options(), msgv1.E_Signer).([]string) + if len(signersFields) == 0 { + return nil, fmt.Errorf("no cosmos.msg.v1.signer option found for message %s", descriptor.FullName()) + } + + return signersFields, nil +} + +// init performs a dry run of getting all msg's signers. This has 2 benefits: +// - it will error if any Msg has forgotten the "cosmos.msg.v1.signer" +// annotation +// - it will pre-populate the context's internal cache for getSignersFuncs +// so that calling it in antehandlers will be faster. +func (c *Context) init() error { + var errs []error + c.fileResolver.RangeFiles(func(fd protoreflect.FileDescriptor) bool { + for i := 0; i < fd.Services().Len(); i++ { + sd := fd.Services().Get(i) + // We use the heuristic that services named "Msg" are exactly the + // ones that need the proto annotation check. + if sd.Name() != "Msg" { + continue + } + + for j := 0; j < sd.Methods().Len(); j++ { + md := sd.Methods().Get(j).Input() + msg := dynamicpb.NewMessage(md) + _, err := c.GetSigners(msg) + if err != nil { + errs = append(errs, err) + } + } + } + + return true + }) + + return errors.Join(errs...) +} + +func (c *Context) makeGetSignersFunc(descriptor protoreflect.MessageDescriptor) (getSignersFunc, error) { + signersFields, err := getSignersFieldNames(descriptor) + if err != nil { + return nil, err + } + + fieldGetters := make([]func(proto.Message, [][]byte) ([][]byte, error), len(signersFields)) + for i, fieldName := range signersFields { + field := descriptor.Fields().ByName(protoreflect.Name(fieldName)) + if field == nil { + return nil, fmt.Errorf("field %s not found in message %s", fieldName, descriptor.FullName()) + } + + if field.IsMap() || field.HasOptionalKeyword() { + return nil, fmt.Errorf("cosmos.msg.v1.signer field %s in message %s must not be a map or optional", fieldName, descriptor.FullName()) + } + + switch field.Kind() { + case protoreflect.StringKind: + addrCdc := c.getAddressCodec(field) + if field.IsList() { + fieldGetters[i] = func(msg proto.Message, arr [][]byte) ([][]byte, error) { + signers := msg.ProtoReflect().Get(field).List() + n := signers.Len() + for i := 0; i < n; i++ { + addrStr := signers.Get(i).String() + addrBz, err := addrCdc.StringToBytes(addrStr) + if err != nil { + return nil, err + } + arr = append(arr, addrBz) + } + return arr, nil + } + } else { + fieldGetters[i] = func(msg proto.Message, arr [][]byte) ([][]byte, error) { + addrStr := msg.ProtoReflect().Get(field).String() + addrBz, err := addrCdc.StringToBytes(addrStr) + if err != nil { + return nil, err + } + return append(arr, addrBz), nil + } + } + case protoreflect.MessageKind: + isList := field.IsList() + nestedMessage := field.Message() + nestedSignersFields, err := getSignersFieldNames(nestedMessage) + if err != nil { + return nil, err + } + + if len(nestedSignersFields) != 1 { + return nil, fmt.Errorf("nested cosmos.msg.v1.signer option in message %s must contain only one value", nestedMessage.FullName()) + } + + nestedFieldName := nestedSignersFields[0] + nestedField := nestedMessage.Fields().ByName(protoreflect.Name(nestedFieldName)) + nestedIsList := nestedField.IsList() + if nestedField == nil { + return nil, fmt.Errorf("field %s not found in message %s", nestedFieldName, nestedMessage.FullName()) + } + + if nestedField.Kind() != protoreflect.StringKind || nestedField.IsMap() || nestedField.HasOptionalKeyword() { + return nil, fmt.Errorf("nested signer field %s in message %s must be a simple string", nestedFieldName, nestedMessage.FullName()) + } + + addrCdc := c.getAddressCodec(nestedField) + + if isList { + if nestedIsList { + fieldGetters[i] = func(msg proto.Message, arr [][]byte) ([][]byte, error) { + msgs := msg.ProtoReflect().Get(field).List() + m := msgs.Len() + for i := 0; i < m; i++ { + signers := msgs.Get(i).Message().Get(nestedField).List() + n := signers.Len() + for j := 0; j < n; j++ { + addrStr := signers.Get(j).String() + addrBz, err := addrCdc.StringToBytes(addrStr) + if err != nil { + return nil, err + } + arr = append(arr, addrBz) + } + } + return arr, nil + } + } else { + fieldGetters[i] = func(msg proto.Message, arr [][]byte) ([][]byte, error) { + msgs := msg.ProtoReflect().Get(field).List() + m := msgs.Len() + for i := 0; i < m; i++ { + addrStr := msgs.Get(i).Message().Get(nestedField).String() + addrBz, err := addrCdc.StringToBytes(addrStr) + if err != nil { + return nil, err + } + arr = append(arr, addrBz) + } + return arr, nil + } + } + } else { + if nestedIsList { + fieldGetters[i] = func(msg proto.Message, arr [][]byte) ([][]byte, error) { + nestedMsg := msg.ProtoReflect().Get(field).Message() + signers := nestedMsg.Get(nestedField).List() + n := signers.Len() + for j := 0; j < n; j++ { + addrStr := signers.Get(j).String() + addrBz, err := addrCdc.StringToBytes(addrStr) + if err != nil { + return nil, err + } + arr = append(arr, addrBz) + } + return arr, nil + } + } else { + fieldGetters[i] = func(msg proto.Message, arr [][]byte) ([][]byte, error) { + addrStr := msg.ProtoReflect().Get(field).Message().Get(nestedField).String() + addrBz, err := addrCdc.StringToBytes(addrStr) + if err != nil { + return nil, err + } + return append(arr, addrBz), nil + } + } + } + + default: + return nil, fmt.Errorf("unexpected field type %s for field %s in message %s", field.Kind(), fieldName, descriptor.FullName()) + } + } + + return func(message proto.Message) ([][]byte, error) { + var signers [][]byte + for _, getter := range fieldGetters { + signers, err = getter(message, signers) + if err != nil { + return nil, err + } + } + return signers, nil + }, nil +} + +func (c *Context) getAddressCodec(field protoreflect.FieldDescriptor) address.Codec { + scalarOpt := proto.GetExtension(field.Options(), cosmos_proto.E_Scalar) + addrCdc := c.addressCodec + if scalarOpt != nil { + if scalarOpt.(string) == "cosmos.ValidatorAddressString" { + addrCdc = c.validatorAddressCodec + } + } + + return addrCdc +} + +// GetSigners returns the signers for a given message. +func (c *Context) GetSigners(msg proto.Message) ([][]byte, error) { + messageDescriptor := msg.ProtoReflect().Descriptor() + f, ok := c.getSignersFuncs[messageDescriptor.FullName()] + if !ok { + var err error + f, err = c.makeGetSignersFunc(messageDescriptor) + if err != nil { + return nil, err + } + c.getSignersFuncs[messageDescriptor.FullName()] = f + } + + return f(msg) +} + +// AddressCodec returns the address codec used by the context. +func (c *Context) AddressCodec() address.Codec { + return c.addressCodec +} + +// ValidatorAddressCodec returns the validator address codec used by the context. +func (c *Context) ValidatorAddressCodec() address.Codec { + return c.validatorAddressCodec +} + +// FileResolver returns the proto file resolver used by the context. +func (c *Context) FileResolver() ProtoFileResolver { + return c.fileResolver +} + +func (c *Context) TypeResolver() protoregistry.MessageTypeResolver { + return c.typeResolver +} diff --git a/x/tx/signing/context_test.go b/x/tx/signing/context_test.go new file mode 100644 index 000000000000..a5979e300d73 --- /dev/null +++ b/x/tx/signing/context_test.go @@ -0,0 +1,170 @@ +package signing + +import ( + "encoding/hex" + "strings" + "testing" + + bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" + groupv1 "cosmossdk.io/api/cosmos/group/v1" + "cosmossdk.io/core/address" + "github.com/stretchr/testify/require" + "google.golang.org/protobuf/proto" + + "cosmossdk.io/x/tx/internal/testpb" +) + +func TestGetSigners(t *testing.T) { + ctx, err := NewContext(Options{ + AddressCodec: dummyAddressCodec{}, + ValidatorAddressCodec: dummyValidatorAddressCodec{}, + }) + require.NoError(t, err) + tests := []struct { + name string + msg proto.Message + want [][]byte + wantErr bool + }{ + { + name: "MsgSend", + msg: &bankv1beta1.MsgSend{ + FromAddress: hex.EncodeToString([]byte("foo")), + }, + want: [][]byte{[]byte("foo")}, + }, + { + name: "MsgMultiSend", + msg: &bankv1beta1.MsgMultiSend{ + Inputs: []*bankv1beta1.Input{ + {Address: hex.EncodeToString([]byte("foo"))}, + {Address: hex.EncodeToString([]byte("bar"))}, + }, + }, + want: [][]byte{[]byte("foo"), []byte("bar")}, + }, + { + name: "MsgSubmitProposal", + msg: &groupv1.MsgSubmitProposal{ + Proposers: []string{ + hex.EncodeToString([]byte("foo")), + hex.EncodeToString([]byte("bar")), + }, + }, + want: [][]byte{[]byte("foo"), []byte("bar")}, + }, + { + name: "simple", + msg: &testpb.SimpleSigner{Signer: hex.EncodeToString([]byte("foo"))}, + want: [][]byte{[]byte("foo")}, + }, + { + name: "repeated", + msg: &testpb.RepeatedSigner{Signer: []string{ + hex.EncodeToString([]byte("foo")), + hex.EncodeToString([]byte("bar")), + }}, + want: [][]byte{[]byte("foo"), []byte("bar")}, + }, + { + name: "nested", + msg: &testpb.NestedSigner{Inner: &testpb.NestedSigner_Inner{Signer: hex.EncodeToString([]byte("foo"))}}, + want: [][]byte{[]byte("foo")}, + }, + { + name: "nested repeated", + msg: &testpb.NestedRepeatedSigner{Inner: &testpb.NestedRepeatedSigner_Inner{Signer: []string{ + hex.EncodeToString([]byte("foo")), + hex.EncodeToString([]byte("bar")), + }}}, + want: [][]byte{[]byte("foo"), []byte("bar")}, + }, + { + name: "repeated nested", + msg: &testpb.RepeatedNestedSigner{Inner: []*testpb.RepeatedNestedSigner_Inner{ + {Signer: hex.EncodeToString([]byte("foo"))}, + {Signer: hex.EncodeToString([]byte("bar"))}, + }}, + want: [][]byte{[]byte("foo"), []byte("bar")}, + }, + { + name: "nested repeated", + msg: &testpb.NestedRepeatedSigner{Inner: &testpb.NestedRepeatedSigner_Inner{ + Signer: []string{ + hex.EncodeToString([]byte("foo")), + hex.EncodeToString([]byte("bar")), + }, + }}, + want: [][]byte{[]byte("foo"), []byte("bar")}, + }, + { + name: "repeated nested repeated", + msg: &testpb.RepeatedNestedRepeatedSigner{Inner: []*testpb.RepeatedNestedRepeatedSigner_Inner{ + {Signer: []string{ + hex.EncodeToString([]byte("foo")), + hex.EncodeToString([]byte("bar")), + }}, + {Signer: []string{ + hex.EncodeToString([]byte("baz")), + hex.EncodeToString([]byte("bam")), + }}, + {Signer: []string{ + hex.EncodeToString([]byte("blah")), + }}, + }}, + want: [][]byte{[]byte("foo"), []byte("bar"), []byte("baz"), []byte("bam"), []byte("blah")}, + }, + { + name: "bad", + msg: &testpb.BadSigner{}, + wantErr: true, + }, + { + name: "no signer", + msg: &testpb.NoSignerOption{}, + wantErr: true, + }, + { + name: "validator signer", + msg: &testpb.ValidatorSigner{ + Signer: "val" + hex.EncodeToString([]byte("foo")), + }, + want: [][]byte{[]byte("foo")}, + }, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + signers, err := ctx.GetSigners(test.msg) + if test.wantErr { + require.Error(t, err) + } else { + require.NoError(t, err) + } + require.Equal(t, test.want, signers) + }) + } +} + +type dummyAddressCodec struct{} + +func (d dummyAddressCodec) StringToBytes(text string) ([]byte, error) { + return hex.DecodeString(text) +} + +func (d dummyAddressCodec) BytesToString(bz []byte) (string, error) { + return hex.EncodeToString(bz), nil +} + +var _ address.Codec = dummyAddressCodec{} + +type dummyValidatorAddressCodec struct{} + +func (d dummyValidatorAddressCodec) StringToBytes(text string) ([]byte, error) { + return hex.DecodeString(strings.TrimPrefix(text, "val")) +} + +func (d dummyValidatorAddressCodec) BytesToString(bz []byte) (string, error) { + return "val" + hex.EncodeToString(bz), nil +} + +var _ address.Codec = dummyValidatorAddressCodec{} diff --git a/x/tx/signing/directaux/direct_aux.go b/x/tx/signing/directaux/direct_aux.go index 8738834906e1..f20b56f513e0 100644 --- a/x/tx/signing/directaux/direct_aux.go +++ b/x/tx/signing/directaux/direct_aux.go @@ -16,32 +16,30 @@ import ( // SignModeHandler is the SIGN_MODE_DIRECT_AUX implementation of signing.SignModeHandler. type SignModeHandler struct { - signersContext *signing.GetSignersContext + signersContext *signing.Context fileResolver signing.ProtoFileResolver typeResolver protoregistry.MessageTypeResolver } // SignModeHandlerOptions are the options for the SignModeHandler. type SignModeHandlerOptions struct { - // FileResolver is the protodesc.Resolver to use for resolving proto files when unpacking any messages. - FileResolver signing.ProtoFileResolver - - // TypeResolver is the protoregistry.MessageTypeResolver to use for resolving proto types when unpacking any messages. + // TypeResolver is the protoregistry.MessageTypeResolver to use for resolving protobuf types when unpacking any messages. TypeResolver protoregistry.MessageTypeResolver - // SignersContext is the signing.GetSignersContext to use for getting signers. - SignersContext *signing.GetSignersContext + // SignersContext is the signing.Context to use for getting signers. + SignersContext *signing.Context } // NewSignModeHandler returns a new SignModeHandler. func NewSignModeHandler(options SignModeHandlerOptions) (SignModeHandler, error) { h := SignModeHandler{} - if options.FileResolver == nil { - h.fileResolver = protoregistry.GlobalFiles - } else { - h.fileResolver = options.FileResolver + if options.SignersContext == nil { + return h, fmt.Errorf("signers context is required") } + h.signersContext = options.SignersContext + + h.fileResolver = h.signersContext.FileResolver() if options.TypeResolver == nil { h.typeResolver = protoregistry.GlobalTypes @@ -49,16 +47,6 @@ func NewSignModeHandler(options SignModeHandlerOptions) (SignModeHandler, error) h.typeResolver = options.TypeResolver } - if options.SignersContext == nil { - var err error - h.signersContext, err = signing.NewGetSignersContext(signing.GetSignersOptions{ProtoFiles: h.fileResolver}) - if err != nil { - return h, err - } - } else { - h.signersContext = options.SignersContext - } - return h, nil } @@ -71,18 +59,18 @@ func (h SignModeHandler) Mode() signingv1beta1.SignMode { // getFirstSigner returns the first signer from the first message in the tx. It replicates behavior in // https://github.com/cosmos/cosmos-sdk/blob/4a6a1e3cb8de459891cb0495052589673d14ef51/x/auth/tx/builder.go#L142 -func (h SignModeHandler) getFirstSigner(txData signing.TxData) (string, error) { +func (h SignModeHandler) getFirstSigner(txData signing.TxData) ([]byte, error) { if len(txData.Body.Messages) == 0 { - return "", fmt.Errorf("no signer found") + return nil, fmt.Errorf("no signer found") } msg, err := anyutil.Unpack(txData.Body.Messages[0], h.fileResolver, h.typeResolver) if err != nil { - return "", err + return nil, err } signer, err := h.signersContext.GetSigners(msg) if err != nil { - return "", err + return nil, err } return signer[0], nil } @@ -97,7 +85,10 @@ func (h SignModeHandler) GetSignBytes( if err != nil { return nil, err } - feePayer = fp + feePayer, err = h.signersContext.AddressCodec().BytesToString(fp) + if err != nil { + return nil, err + } } if feePayer == signerData.Address { return nil, fmt.Errorf("fee payer %s cannot sign with %s: unauthorized", diff --git a/x/tx/signing/directaux/direct_aux_test.go b/x/tx/signing/directaux/direct_aux_test.go index 2f7ca5440b85..4fba90b7e1aa 100644 --- a/x/tx/signing/directaux/direct_aux_test.go +++ b/x/tx/signing/directaux/direct_aux_test.go @@ -2,9 +2,11 @@ package directaux_test import ( "context" + "encoding/hex" "fmt" "testing" + "cosmossdk.io/core/address" "github.com/cosmos/cosmos-proto/anyutil" "github.com/stretchr/testify/require" "google.golang.org/protobuf/proto" @@ -15,6 +17,7 @@ import ( "cosmossdk.io/api/cosmos/crypto/secp256k1" signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1" txv1beta1 "cosmossdk.io/api/cosmos/tx/v1beta1" + "cosmossdk.io/x/tx/signing" "cosmossdk.io/x/tx/signing/directaux" ) @@ -83,7 +86,14 @@ func TestDirectAuxHandler(t *testing.T) { AuthInfoBytes: authInfoBz, BodyBytes: bodyBz, } - modeHandler, err := directaux.NewSignModeHandler(directaux.SignModeHandlerOptions{}) + signersCtx, err := signing.NewContext(signing.Options{ + AddressCodec: dummyAddressCodec{}, + ValidatorAddressCodec: dummyAddressCodec{}, + }) + require.NoError(t, err) + modeHandler, err := directaux.NewSignModeHandler(directaux.SignModeHandlerOptions{ + SignersContext: signersCtx, + }) require.NoError(t, err) t.Log("verify fee payer cannot use SIGN_MODE_DIRECT_AUX") @@ -143,3 +153,15 @@ func TestDirectAuxHandler(t *testing.T) { require.NoError(t, err) require.NotEqual(t, expectedSignBytes, signBytes) } + +type dummyAddressCodec struct{} + +func (d dummyAddressCodec) StringToBytes(text string) ([]byte, error) { + return hex.DecodeString(text) +} + +func (d dummyAddressCodec) BytesToString(bz []byte) (string, error) { + return hex.EncodeToString(bz), nil +} + +var _ address.Codec = dummyAddressCodec{} diff --git a/x/tx/signing/get_signers.go b/x/tx/signing/get_signers.go deleted file mode 100644 index eabd70ed03d3..000000000000 --- a/x/tx/signing/get_signers.go +++ /dev/null @@ -1,222 +0,0 @@ -package signing - -import ( - "errors" - "fmt" - - "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/reflect/protodesc" - "google.golang.org/protobuf/reflect/protoreflect" - "google.golang.org/protobuf/reflect/protoregistry" - "google.golang.org/protobuf/types/dynamicpb" - - msgv1 "cosmossdk.io/api/cosmos/msg/v1" -) - -// GetSignersContext is a context for retrieving the list of signers from a -// message where signers are specified by the cosmos.msg.v1.signer protobuf -// option. -type GetSignersContext struct { - protoFiles ProtoFileResolver - getSignersFuncs map[protoreflect.FullName]getSignersFunc -} - -// GetSignersOptions are options for creating GetSignersContext. -type GetSignersOptions struct { - // ProtoFiles are the protobuf files to use for resolving message descriptors. - // If it is nil, the global protobuf registry will be used. - ProtoFiles ProtoFileResolver -} - -// ProtoFileResolver is a protodesc.Resolver that also allows iterating over all -// files descriptors. It is a subset of the methods supported by protoregistry.Files. -type ProtoFileResolver interface { - protodesc.Resolver - RangeFiles(func(protoreflect.FileDescriptor) bool) -} - -// NewGetSignersContext creates a new GetSignersContext using the provided options. -func NewGetSignersContext(options GetSignersOptions) (*GetSignersContext, error) { - protoFiles := options.ProtoFiles - if protoFiles == nil { - protoFiles = protoregistry.GlobalFiles - } - - c := &GetSignersContext{ - protoFiles: protoFiles, - getSignersFuncs: map[protoreflect.FullName]getSignersFunc{}, - } - - return c, c.init() -} - -type getSignersFunc func(proto.Message) []string - -func getSignersFieldNames(descriptor protoreflect.MessageDescriptor) ([]string, error) { - signersFields := proto.GetExtension(descriptor.Options(), msgv1.E_Signer).([]string) - if len(signersFields) == 0 { - return nil, fmt.Errorf("no cosmos.msg.v1.signer option found for message %s", descriptor.FullName()) - } - - return signersFields, nil -} - -// init performs a dry run of getting all msg's signers. This has 2 benefits: -// - it will error if any Msg has forgotten the "cosmos.msg.v1.signer" -// annotation -// - it will pre-populate the context's internal cache for getSignersFuncs -// so that calling it in antehandlers will be faster. -func (c *GetSignersContext) init() error { - var errs []error - c.protoFiles.RangeFiles(func(fd protoreflect.FileDescriptor) bool { - for i := 0; i < fd.Services().Len(); i++ { - sd := fd.Services().Get(i) - // We use the heuristic that services named "Msg" are exactly the - // ones that need the proto annotation check. - if sd.Name() != "Msg" { - continue - } - - for j := 0; j < sd.Methods().Len(); j++ { - md := sd.Methods().Get(j).Input() - msg := dynamicpb.NewMessage(md) - _, err := c.GetSigners(msg) - if err != nil { - errs = append(errs, err) - } - } - } - - return true - }) - - return errors.Join(errs...) -} - -func (*GetSignersContext) makeGetSignersFunc(descriptor protoreflect.MessageDescriptor) (getSignersFunc, error) { - signersFields, err := getSignersFieldNames(descriptor) - if err != nil { - return nil, err - } - - fieldGetters := make([]func(proto.Message, []string) []string, len(signersFields)) - for i, fieldName := range signersFields { - field := descriptor.Fields().ByName(protoreflect.Name(fieldName)) - if field == nil { - return nil, fmt.Errorf("field %s not found in message %s", fieldName, descriptor.FullName()) - } - - if field.IsMap() || field.HasOptionalKeyword() { - return nil, fmt.Errorf("cosmos.msg.v1.signer field %s in message %s must not be a map or optional", fieldName, descriptor.FullName()) - } - - switch field.Kind() { - case protoreflect.StringKind: - if field.IsList() { - fieldGetters[i] = func(msg proto.Message, arr []string) []string { - signers := msg.ProtoReflect().Get(field).List() - n := signers.Len() - for i := 0; i < n; i++ { - arr = append(arr, signers.Get(i).String()) - } - return arr - } - } else { - fieldGetters[i] = func(msg proto.Message, arr []string) []string { - return append(arr, msg.ProtoReflect().Get(field).String()) - } - } - case protoreflect.MessageKind: - isList := field.IsList() - nestedMessage := field.Message() - nestedSignersFields, err := getSignersFieldNames(nestedMessage) - if err != nil { - return nil, err - } - - if len(nestedSignersFields) != 1 { - return nil, fmt.Errorf("nested cosmos.msg.v1.signer option in message %s must contain only one value", nestedMessage.FullName()) - } - - nestedFieldName := nestedSignersFields[0] - nestedField := nestedMessage.Fields().ByName(protoreflect.Name(nestedFieldName)) - nestedIsList := nestedField.IsList() - if nestedField == nil { - return nil, fmt.Errorf("field %s not found in message %s", nestedFieldName, nestedMessage.FullName()) - } - - if nestedField.Kind() != protoreflect.StringKind || nestedField.IsMap() || nestedField.HasOptionalKeyword() { - return nil, fmt.Errorf("nested signer field %s in message %s must be a simple string", nestedFieldName, nestedMessage.FullName()) - } - - if isList { - if nestedIsList { - fieldGetters[i] = func(msg proto.Message, arr []string) []string { - msgs := msg.ProtoReflect().Get(field).List() - m := msgs.Len() - for i := 0; i < m; i++ { - signers := msgs.Get(i).Message().Get(nestedField).List() - n := signers.Len() - for j := 0; j < n; j++ { - arr = append(arr, signers.Get(j).String()) - } - } - return arr - } - } else { - fieldGetters[i] = func(msg proto.Message, arr []string) []string { - msgs := msg.ProtoReflect().Get(field).List() - m := msgs.Len() - for i := 0; i < m; i++ { - arr = append(arr, msgs.Get(i).Message().Get(nestedField).String()) - } - return arr - } - } - } else { - if nestedIsList { - fieldGetters[i] = func(msg proto.Message, arr []string) []string { - nestedMsg := msg.ProtoReflect().Get(field).Message() - signers := nestedMsg.Get(nestedField).List() - n := signers.Len() - for j := 0; j < n; j++ { - arr = append(arr, signers.Get(j).String()) - } - return arr - } - } else { - fieldGetters[i] = func(msg proto.Message, arr []string) []string { - return append(arr, msg.ProtoReflect().Get(field).Message().Get(nestedField).String()) - } - } - } - - default: - return nil, fmt.Errorf("unexpected field type %s for field %s in message %s", field.Kind(), fieldName, descriptor.FullName()) - } - } - - return func(message proto.Message) []string { - var signers []string - for _, getter := range fieldGetters { - signers = getter(message, signers) - } - return signers - }, nil -} - -// GetSigners returns the signers for a given message. -func (c *GetSignersContext) GetSigners(msg proto.Message) ([]string, error) { - messageDescriptor := msg.ProtoReflect().Descriptor() - f, ok := c.getSignersFuncs[messageDescriptor.FullName()] - if !ok { - var err error - f, err = c.makeGetSignersFunc(messageDescriptor) - if err != nil { - return nil, err - } - c.getSignersFuncs[messageDescriptor.FullName()] = f - } - - return f(msg), nil -} diff --git a/x/tx/signing/get_signers_test.go b/x/tx/signing/get_signers_test.go deleted file mode 100644 index f52fe54542aa..000000000000 --- a/x/tx/signing/get_signers_test.go +++ /dev/null @@ -1,113 +0,0 @@ -package signing - -import ( - "testing" - - bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" - groupv1 "cosmossdk.io/api/cosmos/group/v1" - "github.com/stretchr/testify/require" - "google.golang.org/protobuf/proto" - - "cosmossdk.io/x/tx/internal/testpb" -) - -func TestGetSigners(t *testing.T) { - ctx, err := NewGetSignersContext(GetSignersOptions{}) - require.NoError(t, err) - tests := []struct { - name string - msg proto.Message - want []string - wantErr bool - }{ - { - name: "MsgSend", - msg: &bankv1beta1.MsgSend{ - FromAddress: "foo", - }, - want: []string{"foo"}, - }, - { - name: "MsgMultiSend", - msg: &bankv1beta1.MsgMultiSend{ - Inputs: []*bankv1beta1.Input{ - {Address: "foo"}, - {Address: "bar"}, - }, - }, - want: []string{"foo", "bar"}, - }, - { - name: "MsgSubmitProposal", - msg: &groupv1.MsgSubmitProposal{ - Proposers: []string{"foo", "bar"}, - }, - want: []string{"foo", "bar"}, - }, - { - name: "simple", - msg: &testpb.SimpleSigner{Signer: "foo"}, - want: []string{"foo"}, - }, - { - name: "repeated", - msg: &testpb.RepeatedSigner{Signer: []string{"foo", "bar"}}, - want: []string{"foo", "bar"}, - }, - { - name: "nested", - msg: &testpb.NestedSigner{Inner: &testpb.NestedSigner_Inner{Signer: "foo"}}, - want: []string{"foo"}, - }, - { - name: "nested repeated", - msg: &testpb.NestedRepeatedSigner{Inner: &testpb.NestedRepeatedSigner_Inner{Signer: []string{"foo", "bar"}}}, - want: []string{"foo", "bar"}, - }, - { - name: "repeated nested", - msg: &testpb.RepeatedNestedSigner{Inner: []*testpb.RepeatedNestedSigner_Inner{ - {Signer: "foo"}, - {Signer: "bar"}, - }}, - want: []string{"foo", "bar"}, - }, - { - name: "nested repeated", - msg: &testpb.NestedRepeatedSigner{Inner: &testpb.NestedRepeatedSigner_Inner{ - Signer: []string{"foo", "bar"}, - }}, - want: []string{"foo", "bar"}, - }, - { - name: "repeated nested repeated", - msg: &testpb.RepeatedNestedRepeatedSigner{Inner: []*testpb.RepeatedNestedRepeatedSigner_Inner{ - {Signer: []string{"foo", "bar"}}, - {Signer: []string{"baz", "bam"}}, - {Signer: []string{"blah"}}, - }}, - want: []string{"foo", "bar", "baz", "bam", "blah"}, - }, - { - name: "bad", - msg: &testpb.BadSigner{}, - wantErr: true, - }, - { - name: "no signer", - msg: &testpb.NoSignerOption{}, - wantErr: true, - }, - } - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - signers, err := ctx.GetSigners(test.msg) - if test.wantErr { - require.Error(t, err) - } else { - require.NoError(t, err) - } - require.Equal(t, test.want, signers) - }) - } -} diff --git a/x/tx/signing/textual/bench_test.go b/x/tx/signing/textual/bench_test.go index 0e2c4b70123a..d113b39bd302 100644 --- a/x/tx/signing/textual/bench_test.go +++ b/x/tx/signing/textual/bench_test.go @@ -1,11 +1,17 @@ -package textual +package textual_test import ( "bytes" "context" + "encoding/json" + "os" "testing" + "github.com/stretchr/testify/require" "google.golang.org/protobuf/reflect/protoreflect" + + "cosmossdk.io/x/tx/internal/testpb" + "cosmossdk.io/x/tx/signing/textual" ) var intValues = []protoreflect.Value{ @@ -22,7 +28,7 @@ var intValues = []protoreflect.Value{ func BenchmarkIntValueRendererFormat(b *testing.B) { ctx := context.Background() - ivr := new(intValueRenderer) + ivr := textual.NewIntValueRenderer(fieldDescriptorFromName("UINT64")) b.ResetTimer() b.ReportAllocs() @@ -49,7 +55,7 @@ var decimalValues = []protoreflect.Value{ func BenchmarkDecimalValueRendererFormat(b *testing.B) { ctx := context.Background() - dvr := new(decValueRenderer) + dvr := textual.NewDecValueRenderer() b.ResetTimer() b.ReportAllocs() @@ -76,7 +82,7 @@ var byteValues = []protoreflect.Value{ func BenchmarkBytesValueRendererFormat(b *testing.B) { ctx := context.Background() - bvr := new(bytesValueRenderer) + bvr := textual.NewBytesValueRenderer() b.ResetTimer() b.ReportAllocs() @@ -88,3 +94,52 @@ func BenchmarkBytesValueRendererFormat(b *testing.B) { } } } + +var sink any + +func BenchmarkMessageValueRenderer_parseRepeated(b *testing.B) { + ctx := context.Background() + raw, err := os.ReadFile("./internal/testdata/repeated.json") + require.NoError(b, err) + + type rendScreens struct { + rend textual.ValueRenderer + screens []textual.Screen + } + + var rsL []*rendScreens + + var testCases []repeatedJSONTest + err = json.Unmarshal(raw, &testCases) + require.NoError(b, err) + + tr, err := textual.NewSignModeHandler(textual.SignModeOptions{CoinMetadataQuerier: mockCoinMetadataQuerier}) + for _, tc := range testCases { + rend := textual.NewMessageValueRenderer(tr, (&testpb.Qux{}).ProtoReflect().Descriptor()) + require.NoError(b, err) + + screens, err := rend.Format(ctx, protoreflect.ValueOf(tc.Proto.ProtoReflect())) + require.NoError(b, err) + require.Equal(b, tc.Screens, screens) + + rsL = append(rsL, &rendScreens{ + rend: rend, + screens: screens, + }) + } + + b.ReportAllocs() + b.ResetTimer() + + for i := 0; i < b.N; i++ { + for _, rs := range rsL { + sink, _ = rs.rend.Parse(ctx, rs.screens) + } + } + + if sink == nil { + b.Fatal("Benchmark did not run!") + } + // Reset the sink for reuse. + sink = nil +} diff --git a/x/tx/signing/textual/message.go b/x/tx/signing/textual/message.go index 9affadba8602..83668cd7a298 100644 --- a/x/tx/signing/textual/message.go +++ b/x/tx/signing/textual/message.go @@ -261,11 +261,11 @@ func (mr *messageValueRenderer) Parse(ctx context.Context, screens []Screen) (pr return protoreflect.ValueOfMessage(msg), nil } +// +var headerRegex = regexp.MustCompile(`(\d+) .+`) + func (mr *messageValueRenderer) parseRepeated(ctx context.Context, screens []Screen, l protoreflect.List, vr ValueRenderer) error { - // - headerRegex := *regexp.MustCompile(`(\d+) .+`) res := headerRegex.FindAllStringSubmatch(screens[0].Content, -1) - if res == nil { return errors.New("failed to match ") } From 2c9bd7851205349b3e54bf3b3f4cea398c59212b Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Fri, 14 Apr 2023 10:58:18 -0500 Subject: [PATCH 18/52] comment --- x/group/client/cli/tx_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/group/client/cli/tx_test.go b/x/group/client/cli/tx_test.go index e585393945f5..7853a038e87d 100644 --- a/x/group/client/cli/tx_test.go +++ b/x/group/client/cli/tx_test.go @@ -15,6 +15,7 @@ import ( "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/suite" + // TODO: should amino json encoder receive a different registry to prevent the need for this? _ "cosmossdk.io/api/cosmos/group/v1" sdkmath "cosmossdk.io/math" From e0cecb12a68e60ca164884664185d492d7998688 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Fri, 14 Apr 2023 11:11:12 -0500 Subject: [PATCH 19/52] maybe some fixes --- tools/rosetta/converter.go | 8 +------- types/proto.go | 6 +++--- x/auth/signing/verify.go | 1 + 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/tools/rosetta/converter.go b/tools/rosetta/converter.go index 27be2c22a5e0..07ecdc9c68f7 100644 --- a/tools/rosetta/converter.go +++ b/tools/rosetta/converter.go @@ -115,16 +115,10 @@ func NewConverter(cdc *codec.ProtoCodec, ir codectypes.InterfaceRegistry, cfg sd txDecode: cfg.TxDecoder(), txEncode: cfg.TxEncoder(), bytesToSign: func(tx authsigning.Tx, signerData authsigning.SignerData) (b []byte, err error) { - // TODO - // which pubkey? - pubkeys, err := tx.GetPubKeys() - if err != nil { - return nil, err - } bytesToSign, err := authsigning.AdaptSigningArgs( context.Background(), cfg.TxEncoder(), cfg.SignModeHandler(), - signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, signerData, pubkeys[0], tx) + signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, signerData, signerData.PubKey, tx) if err != nil { return nil, err } diff --git a/types/proto.go b/types/proto.go index 5968919732bc..67da9a53a82a 100644 --- a/types/proto.go +++ b/types/proto.go @@ -27,13 +27,13 @@ var ( ) func MergedProtoRegistry() *protoregistry.Files { + mu.Lock() + + defer mu.Unlock() if mergedRegistry != nil { return mergedRegistry } - mu.Lock() - defer mu.Unlock() - var err error mergedRegistry, err = proto.MergedRegistry() if err != nil { diff --git a/x/auth/signing/verify.go b/x/auth/signing/verify.go index 2eb524209068..243ee5f992ad 100644 --- a/x/auth/signing/verify.go +++ b/x/auth/signing/verify.go @@ -145,6 +145,7 @@ func AdaptSigningArgs( handlerMap *txsigning.HandlerMap, mode signing.SignMode, signerData SignerData, + // TODO refactor, this out and use the pubkey in the SignerData, I don't think this is needed. key cryptotypes.PubKey, tx sdk.Tx, ) ([]byte, error) { From d0317b35fac0135e5cf2b8e8fef5fc8a999f2a0b Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Fri, 14 Apr 2023 11:40:19 -0500 Subject: [PATCH 20/52] fix more test/build failures --- go.mod | 2 +- go.sum | 4 ++-- simapp/go.mod | 2 +- simapp/go.sum | 4 ++-- tests/e2e/auth/suite.go | 2 +- tests/e2e/authz/tx.go | 1 + tests/e2e/feegrant/suite.go | 1 + tools/rosetta/go.mod | 2 +- tools/rosetta/go.sum | 4 ++-- 9 files changed, 12 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 3aa19f7caa40..33f451f22b7d 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( cosmossdk.io/log v1.0.0 cosmossdk.io/math v1.0.0 cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc - cosmossdk.io/x/tx v0.5.1 + cosmossdk.io/x/tx v0.5.2 github.com/99designs/keyring v1.2.1 github.com/armon/go-metrics v0.4.1 github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 diff --git a/go.sum b/go.sum index 266364bc5e79..1c698ee3c42d 100644 --- a/go.sum +++ b/go.sum @@ -51,8 +51,8 @@ cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw= cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc h1:9piuA+NYmhe+SyMPtMoboLw/djgDbrI3dD5TG020Tnk= cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc/go.mod h1:UFF5rmjN7WYVfxo6ArdY/l1+yyWMURBWOmSJypGqFHQ= -cosmossdk.io/x/tx v0.5.1 h1:OcHU8ex3JzxDjexSkMovBx8EnJXcqhrRt7msBq/3vqs= -cosmossdk.io/x/tx v0.5.1/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= +cosmossdk.io/x/tx v0.5.2 h1:phyZggkaIZu8gkknwvpLbz6XIApyNNNuJdALCFflSaw= +cosmossdk.io/x/tx v0.5.2/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/simapp/go.mod b/simapp/go.mod index ed961abeea39..ed306d1bee55 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -15,7 +15,6 @@ require ( cosmossdk.io/x/evidence v0.1.0 cosmossdk.io/x/feegrant v0.0.0-20230117113717-50e7c4a4ceff cosmossdk.io/x/nft v0.0.0-20230113085233-fae3332d62fc - cosmossdk.io/x/tx v0.5.1 // indirect cosmossdk.io/x/upgrade v0.0.0-20230127052425-54c8e1568335 github.com/cometbft/cometbft v0.37.1-0.20230411132551-3a91d155e664 github.com/cosmos/cosmos-db v1.0.0-rc.1 @@ -39,6 +38,7 @@ require ( cloud.google.com/go/storage v1.30.0 // indirect cosmossdk.io/collections v0.0.0-20230411101845-3d1a0b8840e4 // indirect cosmossdk.io/errors v1.0.0-beta.7 // indirect + cosmossdk.io/x/tx v0.5.2 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect diff --git a/simapp/go.sum b/simapp/go.sum index 921a07ce3150..d5b02facf99d 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -202,8 +202,8 @@ cosmossdk.io/log v1.0.0 h1:NGKZ/A5rd4PduDfoscgABklX557PWjQINbosZy/m3Jk= cosmossdk.io/log v1.0.0/go.mod h1:CwX9BLiBruZb7lzLlRr3R231d/fVPUXk8gAdV4LQap0= cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw= cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= -cosmossdk.io/x/tx v0.5.1 h1:OcHU8ex3JzxDjexSkMovBx8EnJXcqhrRt7msBq/3vqs= -cosmossdk.io/x/tx v0.5.1/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= +cosmossdk.io/x/tx v0.5.2 h1:phyZggkaIZu8gkknwvpLbz6XIApyNNNuJdALCFflSaw= +cosmossdk.io/x/tx v0.5.2/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/tests/e2e/auth/suite.go b/tests/e2e/auth/suite.go index 977203e17dc1..3887ee44291f 100644 --- a/tests/e2e/auth/suite.go +++ b/tests/e2e/auth/suite.go @@ -1510,7 +1510,7 @@ func (s *E2ETestSuite) TestTxWithoutPublicKey() { sigV2 := signing.SignatureV2{ PubKey: val1.PubKey, Data: &signing.SingleSignatureData{ - SignMode: txCfg.SignModeHandler().DefaultMode(), + SignMode: signing.SignMode_SIGN_MODE_DIRECT, Signature: nil, }, } diff --git a/tests/e2e/authz/tx.go b/tests/e2e/authz/tx.go index cd39ce0809d4..713c97ab0cda 100644 --- a/tests/e2e/authz/tx.go +++ b/tests/e2e/authz/tx.go @@ -7,6 +7,7 @@ import ( "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/suite" + _ "cosmossdk.io/api/cosmos/authz/v1beta1" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/crypto/hd" diff --git a/tests/e2e/feegrant/suite.go b/tests/e2e/feegrant/suite.go index ab9ca482a450..b22e61ef1f9c 100644 --- a/tests/e2e/feegrant/suite.go +++ b/tests/e2e/feegrant/suite.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/suite" + _ "cosmossdk.io/api/cosmos/feegrant/v1beta1" "cosmossdk.io/x/feegrant" "cosmossdk.io/x/feegrant/client/cli" "github.com/cosmos/cosmos-sdk/client" diff --git a/tools/rosetta/go.mod b/tools/rosetta/go.mod index 3c1a36edef55..e1782e249b0a 100644 --- a/tools/rosetta/go.mod +++ b/tools/rosetta/go.mod @@ -23,7 +23,7 @@ require ( cosmossdk.io/depinject v1.0.0-alpha.3 // indirect cosmossdk.io/errors v1.0.0-beta.7 // indirect cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc // indirect - cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63 // indirect + cosmossdk.io/x/tx v0.5.2 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect diff --git a/tools/rosetta/go.sum b/tools/rosetta/go.sum index 983cea407647..f2fb2a805ce4 100644 --- a/tools/rosetta/go.sum +++ b/tools/rosetta/go.sum @@ -51,8 +51,8 @@ cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw= cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc h1:9piuA+NYmhe+SyMPtMoboLw/djgDbrI3dD5TG020Tnk= cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc/go.mod h1:UFF5rmjN7WYVfxo6ArdY/l1+yyWMURBWOmSJypGqFHQ= -cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63 h1:zHqj2VwZ/MStFmR7SUe/7gErOFhL9v2rkjmWPB/st34= -cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= +cosmossdk.io/x/tx v0.5.2 h1:phyZggkaIZu8gkknwvpLbz6XIApyNNNuJdALCFflSaw= +cosmossdk.io/x/tx v0.5.2/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= From 836509967593ce9567ea553ff8c32fbd7e0c7d7c Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Fri, 14 Apr 2023 12:15:21 -0500 Subject: [PATCH 21/52] use x/tx 0.5.3 --- go.mod | 2 +- go.sum | 4 ++-- simapp/go.mod | 2 +- simapp/go.sum | 4 ++-- tests/e2e/group/tx.go | 1 + tests/go.mod | 2 +- tests/go.sum | 4 ++-- 7 files changed, 10 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 33f451f22b7d..5a57602a34c5 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( cosmossdk.io/log v1.0.0 cosmossdk.io/math v1.0.0 cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc - cosmossdk.io/x/tx v0.5.2 + cosmossdk.io/x/tx v0.5.3 github.com/99designs/keyring v1.2.1 github.com/armon/go-metrics v0.4.1 github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 diff --git a/go.sum b/go.sum index 1c698ee3c42d..6e5d3d2a14d2 100644 --- a/go.sum +++ b/go.sum @@ -51,8 +51,8 @@ cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw= cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc h1:9piuA+NYmhe+SyMPtMoboLw/djgDbrI3dD5TG020Tnk= cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc/go.mod h1:UFF5rmjN7WYVfxo6ArdY/l1+yyWMURBWOmSJypGqFHQ= -cosmossdk.io/x/tx v0.5.2 h1:phyZggkaIZu8gkknwvpLbz6XIApyNNNuJdALCFflSaw= -cosmossdk.io/x/tx v0.5.2/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= +cosmossdk.io/x/tx v0.5.3 h1:8h/Z18uHvFnootFWaMluWyotyp+2uLy+V8gAUJ4Cfi0= +cosmossdk.io/x/tx v0.5.3/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/simapp/go.mod b/simapp/go.mod index ed306d1bee55..3d88bf371bee 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -38,7 +38,7 @@ require ( cloud.google.com/go/storage v1.30.0 // indirect cosmossdk.io/collections v0.0.0-20230411101845-3d1a0b8840e4 // indirect cosmossdk.io/errors v1.0.0-beta.7 // indirect - cosmossdk.io/x/tx v0.5.2 // indirect + cosmossdk.io/x/tx v0.5.3 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect diff --git a/simapp/go.sum b/simapp/go.sum index d5b02facf99d..52b88d117a11 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -202,8 +202,8 @@ cosmossdk.io/log v1.0.0 h1:NGKZ/A5rd4PduDfoscgABklX557PWjQINbosZy/m3Jk= cosmossdk.io/log v1.0.0/go.mod h1:CwX9BLiBruZb7lzLlRr3R231d/fVPUXk8gAdV4LQap0= cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw= cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= -cosmossdk.io/x/tx v0.5.2 h1:phyZggkaIZu8gkknwvpLbz6XIApyNNNuJdALCFflSaw= -cosmossdk.io/x/tx v0.5.2/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= +cosmossdk.io/x/tx v0.5.3 h1:8h/Z18uHvFnootFWaMluWyotyp+2uLy+V8gAUJ4Cfi0= +cosmossdk.io/x/tx v0.5.3/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/tests/e2e/group/tx.go b/tests/e2e/group/tx.go index 6b6265c6c73b..d73b39d91028 100644 --- a/tests/e2e/group/tx.go +++ b/tests/e2e/group/tx.go @@ -11,6 +11,7 @@ import ( "github.com/google/uuid" "github.com/stretchr/testify/suite" + _ "cosmossdk.io/api/cosmos/group/v1" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" diff --git a/tests/go.mod b/tests/go.mod index f1c91aae3b78..15843c4ff8e1 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -13,7 +13,7 @@ require ( cosmossdk.io/x/evidence v0.1.0 cosmossdk.io/x/feegrant v0.0.0-20230117113717-50e7c4a4ceff cosmossdk.io/x/nft v0.0.0-20230113085233-fae3332d62fc - cosmossdk.io/x/tx v0.5.1 + cosmossdk.io/x/tx v0.5.3 cosmossdk.io/x/upgrade v0.0.0-20230127052425-54c8e1568335 github.com/cometbft/cometbft v0.37.1-0.20230411132551-3a91d155e664 github.com/cosmos/cosmos-db v1.0.0-rc.1 diff --git a/tests/go.sum b/tests/go.sum index d32945e16481..283b8f6821ed 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -202,8 +202,8 @@ cosmossdk.io/log v1.0.0 h1:NGKZ/A5rd4PduDfoscgABklX557PWjQINbosZy/m3Jk= cosmossdk.io/log v1.0.0/go.mod h1:CwX9BLiBruZb7lzLlRr3R231d/fVPUXk8gAdV4LQap0= cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw= cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= -cosmossdk.io/x/tx v0.5.1 h1:OcHU8ex3JzxDjexSkMovBx8EnJXcqhrRt7msBq/3vqs= -cosmossdk.io/x/tx v0.5.1/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= +cosmossdk.io/x/tx v0.5.3 h1:8h/Z18uHvFnootFWaMluWyotyp+2uLy+V8gAUJ4Cfi0= +cosmossdk.io/x/tx v0.5.3/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= From dc0d717a2745e414d9e937f1b9ba22188517f429 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Fri, 14 Apr 2023 12:30:23 -0500 Subject: [PATCH 22/52] update rosetta go.mod --- tools/rosetta/go.mod | 2 +- tools/rosetta/go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/rosetta/go.mod b/tools/rosetta/go.mod index e1782e249b0a..8e8b334eb016 100644 --- a/tools/rosetta/go.mod +++ b/tools/rosetta/go.mod @@ -23,7 +23,7 @@ require ( cosmossdk.io/depinject v1.0.0-alpha.3 // indirect cosmossdk.io/errors v1.0.0-beta.7 // indirect cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc // indirect - cosmossdk.io/x/tx v0.5.2 // indirect + cosmossdk.io/x/tx v0.5.3 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect diff --git a/tools/rosetta/go.sum b/tools/rosetta/go.sum index f2fb2a805ce4..a6c36ae7ff27 100644 --- a/tools/rosetta/go.sum +++ b/tools/rosetta/go.sum @@ -51,8 +51,8 @@ cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw= cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc h1:9piuA+NYmhe+SyMPtMoboLw/djgDbrI3dD5TG020Tnk= cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc/go.mod h1:UFF5rmjN7WYVfxo6ArdY/l1+yyWMURBWOmSJypGqFHQ= -cosmossdk.io/x/tx v0.5.2 h1:phyZggkaIZu8gkknwvpLbz6XIApyNNNuJdALCFflSaw= -cosmossdk.io/x/tx v0.5.2/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= +cosmossdk.io/x/tx v0.5.3 h1:8h/Z18uHvFnootFWaMluWyotyp+2uLy+V8gAUJ4Cfi0= +cosmossdk.io/x/tx v0.5.3/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= From 6e691fcf0d057bb9b109d13a4f5883c852655c41 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Fri, 14 Apr 2023 12:36:15 -0500 Subject: [PATCH 23/52] liniting --- tests/e2e/authz/tx.go | 1 + tests/e2e/feegrant/suite.go | 1 + tests/e2e/group/tx.go | 1 + testutil/sims/tx_helpers.go | 2 +- x/auth/ante/feegrant_test.go | 1 + x/auth/signing/verify.go | 35 ----------------------------------- x/auth/tx/config.go | 4 ++-- x/auth/tx/config/textual.go | 8 ++++---- x/auth/tx/direct_test.go | 2 +- x/auth/tx/mode_handler.go | 35 +---------------------------------- 10 files changed, 13 insertions(+), 77 deletions(-) diff --git a/tests/e2e/authz/tx.go b/tests/e2e/authz/tx.go index 713c97ab0cda..7b2084db60ed 100644 --- a/tests/e2e/authz/tx.go +++ b/tests/e2e/authz/tx.go @@ -7,6 +7,7 @@ import ( "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/suite" + // without this import amino json encoding will fail when resolving any types _ "cosmossdk.io/api/cosmos/authz/v1beta1" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec/address" diff --git a/tests/e2e/feegrant/suite.go b/tests/e2e/feegrant/suite.go index b22e61ef1f9c..9797f42ed00e 100644 --- a/tests/e2e/feegrant/suite.go +++ b/tests/e2e/feegrant/suite.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/suite" + // without this import amino json encoding will fail when resolving any types _ "cosmossdk.io/api/cosmos/feegrant/v1beta1" "cosmossdk.io/x/feegrant" "cosmossdk.io/x/feegrant/client/cli" diff --git a/tests/e2e/group/tx.go b/tests/e2e/group/tx.go index f4f551ba3695..9396a946bf46 100644 --- a/tests/e2e/group/tx.go +++ b/tests/e2e/group/tx.go @@ -11,6 +11,7 @@ import ( "github.com/google/uuid" "github.com/stretchr/testify/suite" + // without this import amino json encoding will fail when resolving any types _ "cosmossdk.io/api/cosmos/group/v1" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec/address" diff --git a/testutil/sims/tx_helpers.go b/testutil/sims/tx_helpers.go index 907d5ef34f62..9e9759a5c4fb 100644 --- a/testutil/sims/tx_helpers.go +++ b/testutil/sims/tx_helpers.go @@ -28,7 +28,7 @@ func GenSignedMockTx(r *rand.Rand, txConfig client.TxConfig, msgs []sdk.Msg, fee // TODO // support default mode? - //signMode := txConfig.SignModeHandler().DefaultMode() + // signMode := txConfig.SignModeHandler().DefaultMode() signMode := signing.SignMode_SIGN_MODE_DIRECT // 1st round: set SignatureV2 with empty signatures, to set correct diff --git a/x/auth/ante/feegrant_test.go b/x/auth/ante/feegrant_test.go index e34a549ff199..c8e9b806858d 100644 --- a/x/auth/ante/feegrant_test.go +++ b/x/auth/ante/feegrant_test.go @@ -168,6 +168,7 @@ func TestDeductFeesNoDelegation(t *testing.T) { var defaultGenTxGas uint64 = 10000000 tx, err := genTxWithFeeGranter(protoTxCfg, msgs, fee, defaultGenTxGas, suite.ctx.ChainID(), accNums, seqs, feeAcc, privs...) + require.NoError(t, err) txBytes, err := protoTxCfg.TxEncoder()(tx) require.NoError(t, err) bytesCtx := suite.ctx.WithTxBytes(txBytes) diff --git a/x/auth/signing/verify.go b/x/auth/signing/verify.go index 243ee5f992ad..d5feec069abb 100644 --- a/x/auth/signing/verify.go +++ b/x/auth/signing/verify.go @@ -16,41 +16,6 @@ import ( "github.com/cosmos/cosmos-sdk/types/tx/signing" ) -// VerifySignature verifies a transaction signature contained in SignatureData abstracting over different signing modes -// and single vs multi-signatures. -//func VerifySignature(ctx context.Context, pubKey cryptotypes.PubKey, signerData SignerData, sigData signing.SignatureData, handler SignModeHandler, tx sdk.Tx) error { -// switch data := sigData.(type) { -// case *signing.SingleSignatureData: -// signBytes, err := GetSignBytesWithContext(handler, ctx, data.SignMode, signerData, tx) -// if err != nil { -// return err -// } -// if !pubKey.VerifySignature(signBytes, data.Signature) { -// return fmt.Errorf("unable to verify single signer signature") -// } -// return nil -// -// case *signing.MultiSignatureData: -// multiPK, ok := pubKey.(multisig.PubKey) -// if !ok { -// return fmt.Errorf("expected %T, got %T", (multisig.PubKey)(nil), pubKey) -// } -// err := multiPK.VerifyMultisignature(func(mode signing.SignMode) ([]byte, error) { -// handlerWithContext, ok := handler.(SignModeHandlerWithContext) -// if ok { -// return handlerWithContext.GetSignBytesWithContext(ctx, mode, signerData, tx) -// } -// return handler.GetSignBytes(mode, signerData, tx) -// }, data) -// if err != nil { -// return err -// } -// return nil -// default: -// return fmt.Errorf("unexpected SignatureData %T", sigData) -// } -//} - func APISignModesToInternal(modes []signingv1beta1.SignMode) ([]signing.SignMode, error) { internalModes := make([]signing.SignMode, len(modes)) for i, mode := range modes { diff --git a/x/auth/tx/config.go b/x/auth/tx/config.go index 796b4bf3eb5a..52042b91fe00 100644 --- a/x/auth/tx/config.go +++ b/x/auth/tx/config.go @@ -46,7 +46,7 @@ func NewTxConfig(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signin panic(err) } - aminoJsonEncoder := aminojson.NewAminoJSON() + aminoJSONEncoder := aminojson.NewAminoJSON() signModeOptions := SignModeOptions{ DirectAux: &directaux.SignModeHandlerOptions{ FileResolver: protoFiles, @@ -56,7 +56,7 @@ func NewTxConfig(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signin AminoJSON: &aminojson.SignModeHandlerOptions{ FileResolver: protoFiles, TypeResolver: typeResolver, - Encoder: &aminoJsonEncoder, + Encoder: &aminoJSONEncoder, }, } diff --git a/x/auth/tx/config/textual.go b/x/auth/tx/config/textual.go index 2d686fed0b21..1521c55f65ad 100644 --- a/x/auth/tx/config/textual.go +++ b/x/auth/tx/config/textual.go @@ -36,7 +36,7 @@ func NewTextualWithGRPCConn(grpcConn grpc.ClientConnInterface) (tx.SignModeOptio return tx.SignModeOptions{}, err } - aminoJsonEncoder := aminojson.NewAminoJSON() + aminoJSONEncoder := aminojson.NewAminoJSON() signModeOptions := tx.SignModeOptions{ DirectAux: &directaux.SignModeHandlerOptions{ FileResolver: protoFiles, @@ -46,7 +46,7 @@ func NewTextualWithGRPCConn(grpcConn grpc.ClientConnInterface) (tx.SignModeOptio AminoJSON: &aminojson.SignModeHandlerOptions{ FileResolver: protoFiles, TypeResolver: typeResolver, - Encoder: &aminoJsonEncoder, + Encoder: &aminoJSONEncoder, }, Textual: &textual.SignModeOptions{ CoinMetadataQuerier: func(ctx context.Context, denom string) (*bankv1beta1.Metadata, error) { @@ -115,7 +115,7 @@ func NewTextualWithBankKeeper(bk BankKeeper) (tx.SignModeOptions, error) { FileResolver: protoFiles, } - aminoJsonEncoder := aminojson.NewAminoJSON() + aminoJSONEncoder := aminojson.NewAminoJSON() return tx.SignModeOptions{ Textual: &txtOpts, DirectAux: &directaux.SignModeHandlerOptions{ @@ -126,7 +126,7 @@ func NewTextualWithBankKeeper(bk BankKeeper) (tx.SignModeOptions, error) { AminoJSON: &aminojson.SignModeHandlerOptions{ FileResolver: protoFiles, TypeResolver: typeResolver, - Encoder: &aminoJsonEncoder, + Encoder: &aminoJSONEncoder, }, }, nil } diff --git a/x/auth/tx/direct_test.go b/x/auth/tx/direct_test.go index 7022de19adcf..7f098e4bde95 100644 --- a/x/auth/tx/direct_test.go +++ b/x/auth/tx/direct_test.go @@ -68,7 +68,7 @@ func TestDirectModeHandler(t *testing.T) { defaultSignMode := signingtypes.SignMode_SIGN_MODE_DIRECT require.Equal(t, defaultSignMode, signingtypes.SignMode_SIGN_MODE_DIRECT) // TODO, once API is cleaned up, this should be 1 - //require.Len(t, modeHandler.Modes(), 1) + // require.Len(t, modeHandler.Modes(), 1) signingData := signing.SignerData{ Address: addr.String(), diff --git a/x/auth/tx/mode_handler.go b/x/auth/tx/mode_handler.go index 14bb397208f8..1de426204195 100644 --- a/x/auth/tx/mode_handler.go +++ b/x/auth/tx/mode_handler.go @@ -34,43 +34,10 @@ var DefaultSignModes = []signingtypes.SignMode{ // makeSignModeHandler returns the default protobuf SignModeHandler supporting // SIGN_MODE_DIRECT, SIGN_MODE_DIRECT_AUX and SIGN_MODE_LEGACY_AMINO_JSON. func makeSignModeHandler( - modes []signingtypes.SignMode, + _ []signingtypes.SignMode, opts SignModeOptions, customSignModes ...txsigning.SignModeHandler, ) *txsigning.HandlerMap { - // TODO parity - //if len(modes) < 1 { - // panic(fmt.Errorf("no sign modes enabled")) - //} - // - //handlers := make([]signing.SignModeHandler, len(modes)+len(customSignModes)) - // - //// handle cosmos-sdk defined sign modes - //for i, mode := range modes { - // switch mode { - // case signingtypes.SignMode_SIGN_MODE_DIRECT: - // handlers[i] = signModeDirectHandler{} - // case signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON: - // handlers[i] = signModeLegacyAminoJSONHandler{} - // case signingtypes.SignMode_SIGN_MODE_TEXTUAL: - // handlers[i] = signModeTextualHandler{t: *txt} - // case signingtypes.SignMode_SIGN_MODE_DIRECT_AUX: - // handlers[i] = signModeDirectAuxHandler{} - // default: - // panic(fmt.Errorf("unsupported sign mode %+v", mode)) - // } - //} - // - //// add custom sign modes - //for i, handler := range customSignModes { - // handlers[i+len(modes)] = handler - //} - // - //return signing.NewSignModeHandlerMap( - // modes[0], - // handlers, - //) - handlers := []txsigning.SignModeHandler{direct.SignModeHandler{}} if opts.Textual != nil { h, err := textual.NewSignModeHandler(*opts.Textual) From 0010ceb24714fa0cbef7ec2b25d4292837613a13 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Fri, 14 Apr 2023 12:58:09 -0500 Subject: [PATCH 24/52] linting fixes --- tools/rosetta/converter.go | 1 - x/auth/signing/verify.go | 4 ++-- x/auth/tx/config.go | 6 ++++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/tools/rosetta/converter.go b/tools/rosetta/converter.go index 07ecdc9c68f7..dc754710f76a 100644 --- a/tools/rosetta/converter.go +++ b/tools/rosetta/converter.go @@ -115,7 +115,6 @@ func NewConverter(cdc *codec.ProtoCodec, ir codectypes.InterfaceRegistry, cfg sd txDecode: cfg.TxDecoder(), txEncode: cfg.TxEncoder(), bytesToSign: func(tx authsigning.Tx, signerData authsigning.SignerData) (b []byte, err error) { - bytesToSign, err := authsigning.AdaptSigningArgs( context.Background(), cfg.TxEncoder(), cfg.SignModeHandler(), signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, signerData, signerData.PubKey, tx) diff --git a/x/auth/signing/verify.go b/x/auth/signing/verify.go index d5feec069abb..1156ce7a2ea2 100644 --- a/x/auth/signing/verify.go +++ b/x/auth/signing/verify.go @@ -66,8 +66,8 @@ func VerifySignature( signerData txsigning.SignerData, signatureData signing.SignatureData, handler *txsigning.HandlerMap, - txData txsigning.TxData) error { - + txData txsigning.TxData, +) error { switch data := signatureData.(type) { case *signing.SingleSignatureData: signMode, err := InternalSignModeToAPI(data.SignMode) diff --git a/x/auth/tx/config.go b/x/auth/tx/config.go index 52042b91fe00..3578e44a34cc 100644 --- a/x/auth/tx/config.go +++ b/x/auth/tx/config.go @@ -31,7 +31,8 @@ type config struct { // to enable SIGN_MODE_TEXTUAL (for testing purposes for now). // TODO: collapse enabledSignModes and customSignModes func NewTxConfig(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signingtypes.SignMode, - customSignModes ...txsigning.SignModeHandler) client.TxConfig { + customSignModes ...txsigning.SignModeHandler, +) client.TxConfig { for _, m := range enabledSignModes { if m == signingtypes.SignMode_SIGN_MODE_TEXTUAL { panic("cannot use NewTxConfig with SIGN_MODE_TEXTUAL enabled; please use NewTxConfigWithTextual") @@ -67,7 +68,8 @@ func NewTxConfig(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signin // a SIGN_MODE_TEXTUAL renderer. It is currently still EXPERIMENTAL, for should // be used for TESTING purposes only, until Textual is fully released. func NewTxConfigWithTextual(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signingtypes.SignMode, - signModeOptions SignModeOptions, customSignModes ...txsigning.SignModeHandler) client.TxConfig { + signModeOptions SignModeOptions, customSignModes ...txsigning.SignModeHandler, +) client.TxConfig { return NewTxConfigWithHandler(protoCodec, makeSignModeHandler(enabledSignModes, signModeOptions, customSignModes...)) } From 0b9eb033b7a41f71447aa0b3027480cbb7c663ae Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Fri, 14 Apr 2023 13:36:39 -0500 Subject: [PATCH 25/52] lint fix --- x/auth/ante/feegrant_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x/auth/ante/feegrant_test.go b/x/auth/ante/feegrant_test.go index c8e9b806858d..b63da54c1a8f 100644 --- a/x/auth/ante/feegrant_test.go +++ b/x/auth/ante/feegrant_test.go @@ -243,7 +243,6 @@ func genTxWithFeeGranter(gen client.TxConfig, msgs []sdk.Msg, feeAmt sdk.Coins, signBytes, err := authsign.AdaptSigningArgs( context.Background(), gen.TxEncoder(), gen.SignModeHandler(), signMode, signerData, p.PubKey(), tx.GetTx()) - if err != nil { panic(err) } From caf698719d1ace716d34de0c827fb2f6eb4cfaa8 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Mon, 17 Apr 2023 13:01:35 -0500 Subject: [PATCH 26/52] clean up config --- go.mod | 2 +- go.sum | 4 +- simapp/go.mod | 2 +- simapp/simd/cmd/root.go | 6 +- tests/go.mod | 2 +- types/proto.go | 47 +++++++++-- x/auth/ante/sigverify.go | 1 + x/auth/ante/sigverify_test.go | 13 ++- x/auth/tx/config.go | 17 +++- x/auth/tx/config/config.go | 124 +++++++++++++++++++++++++++- x/auth/tx/config/textual.go | 148 ---------------------------------- 11 files changed, 193 insertions(+), 173 deletions(-) diff --git a/go.mod b/go.mod index b967d4009886..8bc600c39ce6 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( cosmossdk.io/log v1.0.0 cosmossdk.io/math v1.0.0 cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc - cosmossdk.io/x/tx v0.5.3 + cosmossdk.io/x/tx v0.5.4 github.com/99designs/keyring v1.2.1 github.com/armon/go-metrics v0.4.1 github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 diff --git a/go.sum b/go.sum index 7a63435d4709..25814f78a3be 100644 --- a/go.sum +++ b/go.sum @@ -51,8 +51,8 @@ cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw= cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc h1:9piuA+NYmhe+SyMPtMoboLw/djgDbrI3dD5TG020Tnk= cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc/go.mod h1:UFF5rmjN7WYVfxo6ArdY/l1+yyWMURBWOmSJypGqFHQ= -cosmossdk.io/x/tx v0.5.3 h1:8h/Z18uHvFnootFWaMluWyotyp+2uLy+V8gAUJ4Cfi0= -cosmossdk.io/x/tx v0.5.3/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= +cosmossdk.io/x/tx v0.5.4 h1:tOLDbNDT9F9OvAjGfw3K3rjNhSickQDI9S1iSeovB/A= +cosmossdk.io/x/tx v0.5.4/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/simapp/go.mod b/simapp/go.mod index c80cfbd957d4..a17403c29336 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -38,7 +38,7 @@ require ( cloud.google.com/go/storage v1.30.0 // indirect cosmossdk.io/collections v0.1.0 // indirect cosmossdk.io/errors v1.0.0-beta.7 // indirect - cosmossdk.io/x/tx v0.5.3 // indirect + cosmossdk.io/x/tx v0.5.4 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index 6bbed20697fd..3b5b2b400d12 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -87,7 +87,7 @@ func NewRootCmd() *cobra.Command { // TODO Currently, the TxConfig below doesn't include Textual, so // an error will arise when using the --textual flag. // ref: https://github.com/cosmos/cosmos-sdk/issues/11970 - txt, err := txmodule.NewTextualWithGRPCConn(initClientCtx) + opts, err := txmodule.NewSignModeOptionsWithMetadataQueryFn(txmodule.NewGRPCCoinMetadataQueryFn(initClientCtx)) if err != nil { return err } @@ -95,10 +95,10 @@ func NewRootCmd() *cobra.Command { if err != nil { return err } - txConfigWithTextual := tx.NewTxConfigWithTextual( + txConfigWithTextual := tx.NewTxConfigWithOptions( codec.NewProtoCodec(encodingConfig.InterfaceRegistry), signModes, - txt, + opts, ) initClientCtx = initClientCtx.WithTxConfig(txConfigWithTextual) diff --git a/tests/go.mod b/tests/go.mod index 7d6866c27cce..9b8cffd45965 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -13,7 +13,7 @@ require ( cosmossdk.io/x/evidence v0.1.0 cosmossdk.io/x/feegrant v0.0.0-20230117113717-50e7c4a4ceff cosmossdk.io/x/nft v0.0.0-20230113085233-fae3332d62fc - cosmossdk.io/x/tx v0.5.3 + cosmossdk.io/x/tx v0.5.4 cosmossdk.io/x/upgrade v0.0.0-20230127052425-54c8e1568335 github.com/cometbft/cometbft v0.37.1-0.20230411132551-3a91d155e664 github.com/cosmos/cosmos-db v1.0.0-rc.1 diff --git a/types/proto.go b/types/proto.go index 67da9a53a82a..fd2ce21a1b9f 100644 --- a/types/proto.go +++ b/types/proto.go @@ -4,7 +4,10 @@ import ( "sync" "github.com/cosmos/gogoproto/proto" + "google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/protobuf/reflect/protoregistry" + + txsigning "cosmossdk.io/x/tx/signing" ) // CustomProtobufType defines the interface custom gogo proto types must implement @@ -24,21 +27,55 @@ type CustomProtobufType interface { var ( mu sync.Mutex mergedRegistry *protoregistry.Files + _ txsigning.ProtoFileResolver = lazyProtoRegistry{} ) -func MergedProtoRegistry() *protoregistry.Files { - mu.Lock() +type lazyProtoRegistry struct{} +func (l lazyProtoRegistry) init() error { + mu.Lock() defer mu.Unlock() + if mergedRegistry != nil { - return mergedRegistry + return nil } var err error mergedRegistry, err = proto.MergedRegistry() if err != nil { - panic(err) + return err + } + + return nil +} + +func (l lazyProtoRegistry) FindFileByPath(s string) (protoreflect.FileDescriptor, error) { + if mergedRegistry == nil { + if err := l.init(); err != nil { + return nil, err + } } + return mergedRegistry.FindFileByPath(s) +} + +func (l lazyProtoRegistry) FindDescriptorByName(name protoreflect.FullName) (protoreflect.Descriptor, error) { + if mergedRegistry == nil { + if err := l.init(); err != nil { + return nil, err + } + } + return mergedRegistry.FindDescriptorByName(name) +} + +func (l lazyProtoRegistry) RangeFiles(f func(protoreflect.FileDescriptor) bool) { + if mergedRegistry == nil { + if err := l.init(); err != nil { + panic(err) + } + } + mergedRegistry.RangeFiles(f) +} - return mergedRegistry +func MergedProtoRegistry() txsigning.ProtoFileResolver { + return lazyProtoRegistry{} } diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index a2c5295c5931..26da9aac9509 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -299,6 +299,7 @@ func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul Value: anyPk.Value, }, } + // TODO supply protoRegistry.Files or decoder further up decodeCtx, err := decode.NewDecoder(decode.Options{ProtoFiles: sdk.MergedProtoRegistry()}) if err != nil { return ctx, err diff --git a/x/auth/ante/sigverify_test.go b/x/auth/ante/sigverify_test.go index 6be5d71ee985..7b302f584ecf 100644 --- a/x/auth/ante/sigverify_test.go +++ b/x/auth/ante/sigverify_test.go @@ -131,12 +131,11 @@ func TestSigVerification(t *testing.T) { enabledSignModes := []signing.SignMode{signing.SignMode_SIGN_MODE_DIRECT, signing.SignMode_SIGN_MODE_TEXTUAL, signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON} // Since TEXTUAL is not enabled by default, we create a custom TxConfig // here which includes it. - txt, err := txmodule.NewTextualWithGRPCConn(suite.clientCtx) - require.NoError(t, err) - suite.clientCtx.TxConfig = authtx.NewTxConfigWithTextual( + opts, err := txmodule.NewSignModeOptionsWithMetadataQueryFn(txmodule.NewGRPCCoinMetadataQueryFn(suite.clientCtx)) + suite.clientCtx.TxConfig = authtx.NewTxConfigWithOptions( codec.NewProtoCodec(suite.encCfg.InterfaceRegistry), enabledSignModes, - txt, + opts, ) suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder() @@ -163,12 +162,12 @@ func TestSigVerification(t *testing.T) { gasLimit := testdata.NewTestGasLimit() spkd := ante.NewSetPubKeyDecorator(suite.accountKeeper) - txt, err = txmodule.NewTextualWithBankKeeper(suite.txBankKeeper) + opts, err = txmodule.NewSignModeOptionsWithMetadataQueryFn(txmodule.NewBankKeeperCoinMetadataQueryFn(suite.txBankKeeper)) require.NoError(t, err) - anteTxConfig := authtx.NewTxConfigWithTextual( + anteTxConfig := authtx.NewTxConfigWithOptions( codec.NewProtoCodec(suite.encCfg.InterfaceRegistry), enabledSignModes, - txt, + opts, ) svd := ante.NewSigVerificationDecorator(suite.accountKeeper, anteTxConfig.SignModeHandler()) antehandler := sdk.ChainAnteDecorators(spkd, svd) diff --git a/x/auth/tx/config.go b/x/auth/tx/config.go index 3578e44a34cc..6a1cb64554f8 100644 --- a/x/auth/tx/config.go +++ b/x/auth/tx/config.go @@ -29,6 +29,10 @@ type config struct { // NOTE: Use NewTxConfigWithHandler to provide a custom signing handler in case the sign mode // is not supported by default (eg: SignMode_SIGN_MODE_EIP_191). Use NewTxConfigWithTextual // to enable SIGN_MODE_TEXTUAL (for testing purposes for now). +// +// We prefer to use depinject to provide client.TxConfig, but we permit this constructor usage. Within the SDK, +// this constructor is primarily used in tests, but also sees usage in app chains like: +// https://github.com/evmos/evmos/blob/719363fbb92ff3ea9649694bd088e4c6fe9c195f/encoding/config.go#L37 // TODO: collapse enabledSignModes and customSignModes func NewTxConfig(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signingtypes.SignMode, customSignModes ...txsigning.SignModeHandler, @@ -39,7 +43,8 @@ func NewTxConfig(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signin } } - // prefer depinject usage but permit this; it is primary used in tests. + // protoFiles should perhaps be a parameter to this function, but the choice was made here to not break the + // NewTxConfig API. protoFiles := sdk.MergedProtoRegistry() typeResolver := protoregistry.GlobalTypes signersContext, err := txsigning.NewGetSignersContext(txsigning.GetSignersOptions{ProtoFiles: protoFiles}) @@ -64,13 +69,21 @@ func NewTxConfig(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signin return NewTxConfigWithHandler(protoCodec, makeSignModeHandler(enabledSignModes, signModeOptions, customSignModes...)) } +func NewTxConfigWithOptions(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signingtypes.SignMode, + signModeOptions SignModeOptions, customSignModes ...txsigning.SignModeHandler, +) client.TxConfig { + return NewTxConfigWithHandler(protoCodec, makeSignModeHandler(enabledSignModes, signModeOptions, customSignModes...)) +} + // NewTxConfigWithTextual is like NewTxConfig with the ability to add // a SIGN_MODE_TEXTUAL renderer. It is currently still EXPERIMENTAL, for should // be used for TESTING purposes only, until Textual is fully released. +// +// Deprecated: use NewTxConfigWithOptions instead. func NewTxConfigWithTextual(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signingtypes.SignMode, signModeOptions SignModeOptions, customSignModes ...txsigning.SignModeHandler, ) client.TxConfig { - return NewTxConfigWithHandler(protoCodec, makeSignModeHandler(enabledSignModes, signModeOptions, customSignModes...)) + return NewTxConfigWithOptions(protoCodec, enabledSignModes, signModeOptions, customSignModes...) } // NewTxConfigWithHandler returns a new protobuf TxConfig using the provided ProtoCodec and signing handler. diff --git a/x/auth/tx/config/config.go b/x/auth/tx/config/config.go index b6d3464fd15b..e06f39429ddc 100644 --- a/x/auth/tx/config/config.go +++ b/x/auth/tx/config/config.go @@ -1,12 +1,22 @@ package tx import ( + "context" "fmt" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + grpcstatus "google.golang.org/grpc/status" + "google.golang.org/protobuf/reflect/protoregistry" + + bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" txconfigv1 "cosmossdk.io/api/cosmos/tx/config/v1" "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" txsigning "cosmossdk.io/x/tx/signing" + "cosmossdk.io/x/tx/signing/aminojson" + "cosmossdk.io/x/tx/signing/directaux" + "cosmossdk.io/x/tx/signing/textual" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" @@ -16,6 +26,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/posthandler" "github.com/cosmos/cosmos-sdk/x/auth/tx" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/cosmos/cosmos-sdk/x/bank/types" ) func init() { @@ -52,7 +63,7 @@ type ModuleOutputs struct { // TODO // probably move to x/tx. I would do this now but I'm blocked; latest x/tx does not compile or interop with latest sdk func ProvideSignModeOptions(bk BankKeeper) tx.SignModeOptions { - opts, err := NewTextualWithBankKeeper(bk) + opts, err := NewSignModeOptionsWithMetadataQueryFn(NewBankKeeperCoinMetadataQueryFn(bk)) if err != nil { panic(err) } @@ -62,9 +73,9 @@ func ProvideSignModeOptions(bk BankKeeper) tx.SignModeOptions { func ProvideModule(in ModuleInputs) ModuleOutputs { var txConfig client.TxConfig if in.CustomSignModeHandlers == nil { - txConfig = tx.NewTxConfigWithTextual(in.ProtoCodecMarshaler, tx.DefaultSignModes, in.SignModeOptions) + txConfig = tx.NewTxConfigWithOptions(in.ProtoCodecMarshaler, tx.DefaultSignModes, in.SignModeOptions) } else { - txConfig = tx.NewTxConfigWithTextual(in.ProtoCodecMarshaler, tx.DefaultSignModes, in.SignModeOptions, + txConfig = tx.NewTxConfigWithOptions(in.ProtoCodecMarshaler, tx.DefaultSignModes, in.SignModeOptions, in.CustomSignModeHandlers()...) } @@ -130,3 +141,110 @@ func newAnteHandler(txConfig client.TxConfig, in ModuleInputs) (sdk.AnteHandler, return anteHandler, nil } + +// NewBankKeeperCoinMetadataQueryFn creates a new Textual struct using the given +// BankKeeper to retrieve coin metadata. +// +// Note: Once we switch to ADR-033, and keepers become ADR-033 clients to each +// other, this function could probably be deprecated in favor of +// `NewTextualWithGRPCConn`. +func NewBankKeeperCoinMetadataQueryFn(bk BankKeeper) textual.CoinMetadataQueryFn { + return func(ctx context.Context, denom string) (*bankv1beta1.Metadata, error) { + res, err := bk.DenomMetadata(ctx, &types.QueryDenomMetadataRequest{Denom: denom}) + if err != nil { + return nil, metadataExists(err) + } + + m := &bankv1beta1.Metadata{ + Base: res.Metadata.Base, + Display: res.Metadata.Display, + // fields below are not strictly needed by Textual + // but added here for completeness. + Description: res.Metadata.Description, + Name: res.Metadata.Name, + Symbol: res.Metadata.Symbol, + Uri: res.Metadata.URI, + UriHash: res.Metadata.URIHash, + } + m.DenomUnits = make([]*bankv1beta1.DenomUnit, len(res.Metadata.DenomUnits)) + for i, d := range res.Metadata.DenomUnits { + m.DenomUnits[i] = &bankv1beta1.DenomUnit{ + Denom: d.Denom, + Exponent: d.Exponent, + Aliases: d.Aliases, + } + } + + return m, nil + } +} + +// NewGRPCCoinMetadataQueryFn returns a new Textual instance where the metadata +// queries are done via gRPC using the provided GRPC client connection. In the +// SDK, you can pass a client.Context as the GRPC connection. +// +// Example: +// +// clientCtx := client.GetClientContextFromCmd(cmd) +// txt := tx.NewTextualWithGRPCConn(clientCtxx) +func NewGRPCCoinMetadataQueryFn(grpcConn grpc.ClientConnInterface) textual.CoinMetadataQueryFn { + return func(ctx context.Context, denom string) (*bankv1beta1.Metadata, error) { + bankQueryClient := bankv1beta1.NewQueryClient(grpcConn) + res, err := bankQueryClient.DenomMetadata(ctx, &bankv1beta1.QueryDenomMetadataRequest{ + Denom: denom, + }) + if err != nil { + return nil, metadataExists(err) + } + + return res.Metadata, nil + } +} + +// NewSignModeOptionsWithMetadataQueryFn creates a new SignModeOptions instance +func NewSignModeOptionsWithMetadataQueryFn(fn textual.CoinMetadataQueryFn) (tx.SignModeOptions, error) { + protoFiles := sdk.MergedProtoRegistry() + typeResolver := protoregistry.GlobalTypes + signersContext, err := txsigning.NewGetSignersContext(txsigning.GetSignersOptions{ProtoFiles: protoFiles}) + if err != nil { + return tx.SignModeOptions{}, err + } + + aminoJSONEncoder := aminojson.NewAminoJSON() + signModeOptions := tx.SignModeOptions{ + DirectAux: &directaux.SignModeHandlerOptions{ + FileResolver: protoFiles, + TypeResolver: typeResolver, + SignersContext: signersContext, + }, + AminoJSON: &aminojson.SignModeHandlerOptions{ + FileResolver: protoFiles, + TypeResolver: typeResolver, + Encoder: &aminoJSONEncoder, + }, + Textual: &textual.SignModeOptions{ + CoinMetadataQuerier: fn, + FileResolver: protoFiles, + TypeResolver: typeResolver, + }, + } + + return signModeOptions, nil +} + +// metadataExists parses the error, and only propagates the error if it's +// different than a "not found" error. +func metadataExists(err error) error { + status, ok := grpcstatus.FromError(err) + if !ok { + return err + } + + // This means we didn't find any metadata for this denom. Returning + // empty metadata. + if status.Code() == codes.NotFound { + return nil + } + + return err +} diff --git a/x/auth/tx/config/textual.go b/x/auth/tx/config/textual.go index 1521c55f65ad..336f5e5a88d7 100644 --- a/x/auth/tx/config/textual.go +++ b/x/auth/tx/config/textual.go @@ -1,149 +1 @@ package tx - -import ( - "context" - - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - grpcstatus "google.golang.org/grpc/status" - "google.golang.org/protobuf/reflect/protoregistry" - - bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" - txsigning "cosmossdk.io/x/tx/signing" - "cosmossdk.io/x/tx/signing/aminojson" - "cosmossdk.io/x/tx/signing/directaux" - "cosmossdk.io/x/tx/signing/textual" - types2 "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth/tx" - "github.com/cosmos/cosmos-sdk/x/bank/types" -) - -// NewTextualWithGRPCConn returns a new Textual instance where the metadata -// queries are done via gRPC using the provided GRPC client connection. In the -// SDK, you can pass a client.Context as the GRPC connection. -// -// Example: -// -// clientCtx := client.GetClientContextFromCmd(cmd) -// txt := tx.NewTextualWithGRPCConn(clientCtxx) -// -// TODO: rename -func NewTextualWithGRPCConn(grpcConn grpc.ClientConnInterface) (tx.SignModeOptions, error) { - protoFiles := types2.MergedProtoRegistry() - typeResolver := protoregistry.GlobalTypes - signersContext, err := txsigning.NewGetSignersContext(txsigning.GetSignersOptions{ProtoFiles: protoFiles}) - if err != nil { - return tx.SignModeOptions{}, err - } - - aminoJSONEncoder := aminojson.NewAminoJSON() - signModeOptions := tx.SignModeOptions{ - DirectAux: &directaux.SignModeHandlerOptions{ - FileResolver: protoFiles, - TypeResolver: typeResolver, - SignersContext: signersContext, - }, - AminoJSON: &aminojson.SignModeHandlerOptions{ - FileResolver: protoFiles, - TypeResolver: typeResolver, - Encoder: &aminoJSONEncoder, - }, - Textual: &textual.SignModeOptions{ - CoinMetadataQuerier: func(ctx context.Context, denom string) (*bankv1beta1.Metadata, error) { - bankQueryClient := bankv1beta1.NewQueryClient(grpcConn) - res, err := bankQueryClient.DenomMetadata(ctx, &bankv1beta1.QueryDenomMetadataRequest{ - Denom: denom, - }) - if err != nil { - return nil, metadataExists(err) - } - - return res.Metadata, nil - }, - FileResolver: protoFiles, - TypeResolver: typeResolver, - }, - } - - return signModeOptions, nil -} - -// NewTextualWithBankKeeper creates a new Textual struct using the given -// BankKeeper to retrieve coin metadata. -// -// Note: Once we switch to ADR-033, and keepers become ADR-033 clients to each -// other, this function could probably be deprecated in favor of -// `NewTextualWithGRPCConn`. -// TODO: rename -func NewTextualWithBankKeeper(bk BankKeeper) (tx.SignModeOptions, error) { - protoFiles := types2.MergedProtoRegistry() - typeResolver := protoregistry.GlobalTypes - signersContext, err := txsigning.NewGetSignersContext(txsigning.GetSignersOptions{ProtoFiles: protoFiles}) - if err != nil { - return tx.SignModeOptions{}, err - } - - txtOpts := textual.SignModeOptions{ - CoinMetadataQuerier: func(ctx context.Context, denom string) (*bankv1beta1.Metadata, error) { - res, err := bk.DenomMetadata(ctx, &types.QueryDenomMetadataRequest{Denom: denom}) - if err != nil { - return nil, metadataExists(err) - } - - m := &bankv1beta1.Metadata{ - Base: res.Metadata.Base, - Display: res.Metadata.Display, - // fields below are not strictly needed by Textual - // but added here for completeness. - Description: res.Metadata.Description, - Name: res.Metadata.Name, - Symbol: res.Metadata.Symbol, - Uri: res.Metadata.URI, - UriHash: res.Metadata.URIHash, - } - m.DenomUnits = make([]*bankv1beta1.DenomUnit, len(res.Metadata.DenomUnits)) - for i, d := range res.Metadata.DenomUnits { - m.DenomUnits[i] = &bankv1beta1.DenomUnit{ - Denom: d.Denom, - Exponent: d.Exponent, - Aliases: d.Aliases, - } - } - - return m, nil - }, - FileResolver: protoFiles, - } - - aminoJSONEncoder := aminojson.NewAminoJSON() - return tx.SignModeOptions{ - Textual: &txtOpts, - DirectAux: &directaux.SignModeHandlerOptions{ - FileResolver: protoFiles, - TypeResolver: typeResolver, - SignersContext: signersContext, - }, - AminoJSON: &aminojson.SignModeHandlerOptions{ - FileResolver: protoFiles, - TypeResolver: typeResolver, - Encoder: &aminoJSONEncoder, - }, - }, nil -} - -// metadataExists parses the error, and only propagates the error if it's -// different than a "not found" error. -func metadataExists(err error) error { - status, ok := grpcstatus.FromError(err) - if !ok { - return err - } - - // This means we didn't find any metadata for this denom. Returning - // empty metadata. - if status.Code() == codes.NotFound { - return nil - } - - return err -} From a246afc0f2a6b3ad798d5204b88c3a6d369b4085 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Mon, 17 Apr 2023 13:06:08 -0500 Subject: [PATCH 27/52] go mod tidy --- simapp/go.sum | 4 ++-- tests/go.sum | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/simapp/go.sum b/simapp/go.sum index a4f5f5cad7f3..9beca879816a 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -202,8 +202,8 @@ cosmossdk.io/log v1.0.0 h1:NGKZ/A5rd4PduDfoscgABklX557PWjQINbosZy/m3Jk= cosmossdk.io/log v1.0.0/go.mod h1:CwX9BLiBruZb7lzLlRr3R231d/fVPUXk8gAdV4LQap0= cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw= cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= -cosmossdk.io/x/tx v0.5.3 h1:8h/Z18uHvFnootFWaMluWyotyp+2uLy+V8gAUJ4Cfi0= -cosmossdk.io/x/tx v0.5.3/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= +cosmossdk.io/x/tx v0.5.4 h1:tOLDbNDT9F9OvAjGfw3K3rjNhSickQDI9S1iSeovB/A= +cosmossdk.io/x/tx v0.5.4/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/tests/go.sum b/tests/go.sum index e3a1a485473f..b98eae3afa0c 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -202,8 +202,8 @@ cosmossdk.io/log v1.0.0 h1:NGKZ/A5rd4PduDfoscgABklX557PWjQINbosZy/m3Jk= cosmossdk.io/log v1.0.0/go.mod h1:CwX9BLiBruZb7lzLlRr3R231d/fVPUXk8gAdV4LQap0= cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw= cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= -cosmossdk.io/x/tx v0.5.3 h1:8h/Z18uHvFnootFWaMluWyotyp+2uLy+V8gAUJ4Cfi0= -cosmossdk.io/x/tx v0.5.3/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= +cosmossdk.io/x/tx v0.5.4 h1:tOLDbNDT9F9OvAjGfw3K3rjNhSickQDI9S1iSeovB/A= +cosmossdk.io/x/tx v0.5.4/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= From c6f2033f5e25fc190f35de9dc4cbebc9839b6966 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Mon, 17 Apr 2023 13:13:23 -0500 Subject: [PATCH 28/52] tidy rosetta --- tools/rosetta/go.mod | 2 +- tools/rosetta/go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/rosetta/go.mod b/tools/rosetta/go.mod index b03b06e94bfe..347f73350546 100644 --- a/tools/rosetta/go.mod +++ b/tools/rosetta/go.mod @@ -23,7 +23,7 @@ require ( cosmossdk.io/depinject v1.0.0-alpha.3 // indirect cosmossdk.io/errors v1.0.0-beta.7 // indirect cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc // indirect - cosmossdk.io/x/tx v0.5.3 // indirect + cosmossdk.io/x/tx v0.5.4 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect diff --git a/tools/rosetta/go.sum b/tools/rosetta/go.sum index c1ab6c801ad3..e7f1ccce3cca 100644 --- a/tools/rosetta/go.sum +++ b/tools/rosetta/go.sum @@ -51,8 +51,8 @@ cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw= cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc h1:9piuA+NYmhe+SyMPtMoboLw/djgDbrI3dD5TG020Tnk= cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc/go.mod h1:UFF5rmjN7WYVfxo6ArdY/l1+yyWMURBWOmSJypGqFHQ= -cosmossdk.io/x/tx v0.5.3 h1:8h/Z18uHvFnootFWaMluWyotyp+2uLy+V8gAUJ4Cfi0= -cosmossdk.io/x/tx v0.5.3/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= +cosmossdk.io/x/tx v0.5.4 h1:tOLDbNDT9F9OvAjGfw3K3rjNhSickQDI9S1iSeovB/A= +cosmossdk.io/x/tx v0.5.4/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= From 978f4f4b8898e54665d69d11ae35c7ddedd8b25d Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Mon, 17 Apr 2023 13:31:45 -0500 Subject: [PATCH 29/52] rwmutex --- types/proto.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/types/proto.go b/types/proto.go index fd2ce21a1b9f..23d44ebe93ce 100644 --- a/types/proto.go +++ b/types/proto.go @@ -25,7 +25,7 @@ type CustomProtobufType interface { } var ( - mu sync.Mutex + mu sync.RWMutex mergedRegistry *protoregistry.Files _ txsigning.ProtoFileResolver = lazyProtoRegistry{} ) @@ -50,6 +50,8 @@ func (l lazyProtoRegistry) init() error { } func (l lazyProtoRegistry) FindFileByPath(s string) (protoreflect.FileDescriptor, error) { + mu.RLock() + defer mu.RUnlock() if mergedRegistry == nil { if err := l.init(); err != nil { return nil, err @@ -59,6 +61,8 @@ func (l lazyProtoRegistry) FindFileByPath(s string) (protoreflect.FileDescriptor } func (l lazyProtoRegistry) FindDescriptorByName(name protoreflect.FullName) (protoreflect.Descriptor, error) { + mu.RLock() + defer mu.RUnlock() if mergedRegistry == nil { if err := l.init(); err != nil { return nil, err @@ -68,6 +72,8 @@ func (l lazyProtoRegistry) FindDescriptorByName(name protoreflect.FullName) (pro } func (l lazyProtoRegistry) RangeFiles(f func(protoreflect.FileDescriptor) bool) { + mu.RLock() + defer mu.RUnlock() if mergedRegistry == nil { if err := l.init(); err != nil { panic(err) From a8069dcaf32244560a2b8b7cc18df4ee65b529c4 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Mon, 17 Apr 2023 13:57:46 -0500 Subject: [PATCH 30/52] lint fix --- x/auth/ante/sigverify_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/auth/ante/sigverify_test.go b/x/auth/ante/sigverify_test.go index 7b302f584ecf..7d8893c53516 100644 --- a/x/auth/ante/sigverify_test.go +++ b/x/auth/ante/sigverify_test.go @@ -132,6 +132,7 @@ func TestSigVerification(t *testing.T) { // Since TEXTUAL is not enabled by default, we create a custom TxConfig // here which includes it. opts, err := txmodule.NewSignModeOptionsWithMetadataQueryFn(txmodule.NewGRPCCoinMetadataQueryFn(suite.clientCtx)) + require.NoError(t, err) suite.clientCtx.TxConfig = authtx.NewTxConfigWithOptions( codec.NewProtoCodec(suite.encCfg.InterfaceRegistry), enabledSignModes, From 3851398e8206d9bda403fe5a18a30d7bc3b61808 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Mon, 17 Apr 2023 14:48:07 -0500 Subject: [PATCH 31/52] proper lazy init with sync.once --- types/proto.go | 54 +++++++++++++++++--------------------------------- 1 file changed, 18 insertions(+), 36 deletions(-) diff --git a/types/proto.go b/types/proto.go index 23d44ebe93ce..3ace3804b01c 100644 --- a/types/proto.go +++ b/types/proto.go @@ -25,61 +25,43 @@ type CustomProtobufType interface { } var ( - mu sync.RWMutex + once sync.Once mergedRegistry *protoregistry.Files _ txsigning.ProtoFileResolver = lazyProtoRegistry{} ) type lazyProtoRegistry struct{} -func (l lazyProtoRegistry) init() error { - mu.Lock() - defer mu.Unlock() - - if mergedRegistry != nil { - return nil - } - +func (l lazyProtoRegistry) getRegistry() (*protoregistry.Files, error) { var err error - mergedRegistry, err = proto.MergedRegistry() - if err != nil { - return err - } - - return nil + once.Do(func() { + mergedRegistry, err = proto.MergedRegistry() + }) + return mergedRegistry, err } func (l lazyProtoRegistry) FindFileByPath(s string) (protoreflect.FileDescriptor, error) { - mu.RLock() - defer mu.RUnlock() - if mergedRegistry == nil { - if err := l.init(); err != nil { - return nil, err - } + reg, err := l.getRegistry() + if err != nil { + return nil, err } - return mergedRegistry.FindFileByPath(s) + return reg.FindFileByPath(s) } func (l lazyProtoRegistry) FindDescriptorByName(name protoreflect.FullName) (protoreflect.Descriptor, error) { - mu.RLock() - defer mu.RUnlock() - if mergedRegistry == nil { - if err := l.init(); err != nil { - return nil, err - } + reg, err := l.getRegistry() + if err != nil { + return nil, err } - return mergedRegistry.FindDescriptorByName(name) + return reg.FindDescriptorByName(name) } func (l lazyProtoRegistry) RangeFiles(f func(protoreflect.FileDescriptor) bool) { - mu.RLock() - defer mu.RUnlock() - if mergedRegistry == nil { - if err := l.init(); err != nil { - panic(err) - } + reg, err := l.getRegistry() + if err != nil { + panic(err) } - mergedRegistry.RangeFiles(f) + reg.RangeFiles(f) } func MergedProtoRegistry() txsigning.ProtoFileResolver { From 6c363f5a6bc9ad3324ecbaf2838e1e44b58ce680 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Mon, 17 Apr 2023 19:53:02 -0500 Subject: [PATCH 32/52] clean up todos --- baseapp/block_gas_test.go | 3 +-- baseapp/msg_service_router_test.go | 3 +-- client/tx/tx_test.go | 3 +-- testutil/sims/tx_helpers.go | 4 +--- types/proto.go | 3 +++ x/auth/tx/config/config.go | 2 -- x/auth/tx/testutil/suite.go | 3 +-- 7 files changed, 8 insertions(+), 13 deletions(-) diff --git a/baseapp/block_gas_test.go b/baseapp/block_gas_test.go index 45d786fc4c14..3dc5b316ea5c 100644 --- a/baseapp/block_gas_test.go +++ b/baseapp/block_gas_test.go @@ -192,8 +192,7 @@ func TestBaseApp_BlockGas(t *testing.T) { } func createTestTx(txConfig client.TxConfig, txBuilder client.TxBuilder, privs []cryptotypes.PrivKey, accNums, accSeqs []uint64, chainID string) (xauthsigning.Tx, []byte, error) { - // TODO - // default mode in handler? + // TODO: default mode in handler? defaultSignMode := signing.SignMode_SIGN_MODE_DIRECT // First round: we gather all the signer infos. We use the "set empty // signature" hack to do that. diff --git a/baseapp/msg_service_router_test.go b/baseapp/msg_service_router_test.go index 430d2df0000d..1cfffa119694 100644 --- a/baseapp/msg_service_router_test.go +++ b/baseapp/msg_service_router_test.go @@ -79,8 +79,7 @@ func TestRegisterMsgServiceTwice(t *testing.T) { func TestMsgService(t *testing.T) { priv, _, _ := testdata.KeyTestPubAddr() - // TODO - // default mode? + // TODO: default mode? defaultSignMode := signing.SignMode_SIGN_MODE_DIRECT var ( diff --git a/client/tx/tx_test.go b/client/tx/tx_test.go index a7f8ff3ceb0a..8bd71bb81a06 100644 --- a/client/tx/tx_test.go +++ b/client/tx/tx_test.go @@ -29,8 +29,7 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" ) -// TODO -// default mode? +// TODO default mode? var defaultSignMode = signingtypes.SignMode_SIGN_MODE_DIRECT func newTestTxConfig() (client.TxConfig, codec.Codec) { diff --git a/testutil/sims/tx_helpers.go b/testutil/sims/tx_helpers.go index 9e9759a5c4fb..fe7e28af2d58 100644 --- a/testutil/sims/tx_helpers.go +++ b/testutil/sims/tx_helpers.go @@ -26,9 +26,7 @@ func GenSignedMockTx(r *rand.Rand, txConfig client.TxConfig, msgs []sdk.Msg, fee // create a random length memo memo := simulation.RandStringOfLength(r, simulation.RandIntBetween(r, 0, 100)) - // TODO - // support default mode? - // signMode := txConfig.SignModeHandler().DefaultMode() + // TODO support default mode? signMode := signing.SignMode_SIGN_MODE_DIRECT // 1st round: set SignatureV2 with empty signatures, to set correct diff --git a/types/proto.go b/types/proto.go index 3ace3804b01c..d01e278fd3a6 100644 --- a/types/proto.go +++ b/types/proto.go @@ -30,6 +30,7 @@ var ( _ txsigning.ProtoFileResolver = lazyProtoRegistry{} ) +// lazyProtoRegistry is a lazy loading wrapper around the global protobuf registry. type lazyProtoRegistry struct{} func (l lazyProtoRegistry) getRegistry() (*protoregistry.Files, error) { @@ -64,6 +65,8 @@ func (l lazyProtoRegistry) RangeFiles(f func(protoreflect.FileDescriptor) bool) reg.RangeFiles(f) } +// MergedProtoRegistry returns a lazy loading wrapper around the global protobuf registry, a merged registry +// containing both gogo proto and pulsar types. func MergedProtoRegistry() txsigning.ProtoFileResolver { return lazyProtoRegistry{} } diff --git a/x/auth/tx/config/config.go b/x/auth/tx/config/config.go index e06f39429ddc..bfdd99c35dfa 100644 --- a/x/auth/tx/config/config.go +++ b/x/auth/tx/config/config.go @@ -60,8 +60,6 @@ type ModuleOutputs struct { } // ProvideSignModeOptions provides the default x/tx SignModeOptions for the SDK. -// TODO -// probably move to x/tx. I would do this now but I'm blocked; latest x/tx does not compile or interop with latest sdk func ProvideSignModeOptions(bk BankKeeper) tx.SignModeOptions { opts, err := NewSignModeOptionsWithMetadataQueryFn(NewBankKeeperCoinMetadataQueryFn(bk)) if err != nil { diff --git a/x/auth/tx/testutil/suite.go b/x/auth/tx/testutil/suite.go index 7f7b56de18c6..7640d3e192e1 100644 --- a/x/auth/tx/testutil/suite.go +++ b/x/auth/tx/testutil/suite.go @@ -100,8 +100,7 @@ func (s *TxConfigTestSuite) TestTxBuilderSetSignatures() { signModeHandler := s.TxConfig.SignModeHandler() s.Require().Contains(signModeHandler.SupportedModes(), signingv1beta1.SignMode_SIGN_MODE_DIRECT) - // TODO - // default sign mode in handler? + // TODO: default sign mode in handler? defaultSignMode := signingtypes.SignMode_SIGN_MODE_DIRECT // set SignatureV2 without actual signature bytes From 8fc31081f27ec4f6ab253412191f9e9323135ec4 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Tue, 18 Apr 2023 09:08:58 -0500 Subject: [PATCH 33/52] clean up, comments --- client/tx/tx.go | 4 ++-- simapp/simd/cmd/root.go | 4 ---- testutil/sims/tx_helpers.go | 2 +- testutil/testnet/genesis.go | 2 +- tools/rosetta/converter.go | 2 +- x/auth/ante/feegrant_test.go | 2 +- x/auth/signing/verify.go | 8 +++++++- x/auth/tx/aux_test.go | 2 +- x/auth/tx/direct_test.go | 4 ++-- x/auth/tx/testutil/suite.go | 4 ++-- 10 files changed, 18 insertions(+), 16 deletions(-) diff --git a/client/tx/tx.go b/client/tx/tx.go index f66d2eda493d..9a5bf52606e3 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -172,7 +172,7 @@ func SignWithPrivKey( var sigV2 signing.SignatureV2 // Generate the bytes to be signed. - signBytes, err := authsigning.AdaptSigningArgs( + signBytes, err := authsigning.GetSignBytesAdapter( ctx, txConfig.TxEncoder(), txConfig.SignModeHandler(), signMode, signerData, priv.PubKey(), txBuilder.GetTx()) if err != nil { return sigV2, err @@ -315,7 +315,7 @@ func Sign(ctx context.Context, txf Factory, name string, txBuilder client.TxBuil return err } - bytesToSign, err := authsigning.AdaptSigningArgs( + bytesToSign, err := authsigning.GetSignBytesAdapter( ctx, txf.txConfig.TxEncoder(), txf.txConfig.SignModeHandler(), signMode, signerData, pubKey, txBuilder.GetTx()) if err != nil { diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index 3b5b2b400d12..54f3c272704f 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -83,10 +83,6 @@ func NewRootCmd() *cobra.Command { // This needs to go after ReadFromClientConfig, as that function // sets the RPC client needed for SIGN_MODE_TEXTUAL. - // - // TODO Currently, the TxConfig below doesn't include Textual, so - // an error will arise when using the --textual flag. - // ref: https://github.com/cosmos/cosmos-sdk/issues/11970 opts, err := txmodule.NewSignModeOptionsWithMetadataQueryFn(txmodule.NewGRPCCoinMetadataQueryFn(initClientCtx)) if err != nil { return err diff --git a/testutil/sims/tx_helpers.go b/testutil/sims/tx_helpers.go index fe7e28af2d58..293ede0c34a2 100644 --- a/testutil/sims/tx_helpers.go +++ b/testutil/sims/tx_helpers.go @@ -64,7 +64,7 @@ func GenSignedMockTx(r *rand.Rand, txConfig client.TxConfig, msgs []sdk.Msg, fee PubKey: p.PubKey(), } - signBytes, err := authsign.AdaptSigningArgs( + signBytes, err := authsign.GetSignBytesAdapter( context.Background(), txConfig.TxEncoder(), txConfig.SignModeHandler(), signMode, signerData, p.PubKey(), tx.GetTx()) if err != nil { diff --git a/testutil/testnet/genesis.go b/testutil/testnet/genesis.go index 1f9f0d3a2c23..c8086bfe50e8 100644 --- a/testutil/testnet/genesis.go +++ b/testutil/testnet/genesis.go @@ -141,7 +141,7 @@ func (b *GenesisBuilder) GenTx(privVal secp256k1.PrivKey, val cmttypes.GenesisVa } // Generate bytes to be signed. - bytesToSign, err := authsigning.AdaptSigningArgs( + bytesToSign, err := authsigning.GetSignBytesAdapter( context.Background(), txConf.TxEncoder(), txConf.SignModeHandler(), diff --git a/tools/rosetta/converter.go b/tools/rosetta/converter.go index dc754710f76a..6214607a15b2 100644 --- a/tools/rosetta/converter.go +++ b/tools/rosetta/converter.go @@ -115,7 +115,7 @@ func NewConverter(cdc *codec.ProtoCodec, ir codectypes.InterfaceRegistry, cfg sd txDecode: cfg.TxDecoder(), txEncode: cfg.TxEncoder(), bytesToSign: func(tx authsigning.Tx, signerData authsigning.SignerData) (b []byte, err error) { - bytesToSign, err := authsigning.AdaptSigningArgs( + bytesToSign, err := authsigning.GetSignBytesAdapter( context.Background(), cfg.TxEncoder(), cfg.SignModeHandler(), signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, signerData, signerData.PubKey, tx) if err != nil { diff --git a/x/auth/ante/feegrant_test.go b/x/auth/ante/feegrant_test.go index b63da54c1a8f..c85623824353 100644 --- a/x/auth/ante/feegrant_test.go +++ b/x/auth/ante/feegrant_test.go @@ -240,7 +240,7 @@ func genTxWithFeeGranter(gen client.TxConfig, msgs []sdk.Msg, feeAmt sdk.Coins, AccountNumber: accNums[i], Sequence: accSeqs[i], } - signBytes, err := authsign.AdaptSigningArgs( + signBytes, err := authsign.GetSignBytesAdapter( context.Background(), gen.TxEncoder(), gen.SignModeHandler(), signMode, signerData, p.PubKey(), tx.GetTx()) if err != nil { diff --git a/x/auth/signing/verify.go b/x/auth/signing/verify.go index 1156ce7a2ea2..cd0f46f035ea 100644 --- a/x/auth/signing/verify.go +++ b/x/auth/signing/verify.go @@ -16,6 +16,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/tx/signing" ) +// APISignModesToInternal converts a protobuf SignMode array to a signing.SignMode array. func APISignModesToInternal(modes []signingv1beta1.SignMode) ([]signing.SignMode, error) { internalModes := make([]signing.SignMode, len(modes)) for i, mode := range modes { @@ -28,6 +29,7 @@ func APISignModesToInternal(modes []signingv1beta1.SignMode) ([]signing.SignMode return internalModes, nil } +// APISignModeToInternal converts a protobuf SignMode to a signing.SignMode. func APISignModeToInternal(mode signingv1beta1.SignMode) (signing.SignMode, error) { switch mode { case signingv1beta1.SignMode_SIGN_MODE_DIRECT: @@ -43,6 +45,7 @@ func APISignModeToInternal(mode signingv1beta1.SignMode) (signing.SignMode, erro } } +// InternalSignModeToAPI converts a signing.SignMode to a protobuf SignMode. func InternalSignModeToAPI(mode signing.SignMode) (signingv1beta1.SignMode, error) { switch mode { case signing.SignMode_SIGN_MODE_DIRECT: @@ -104,7 +107,10 @@ func VerifySignature( } } -func AdaptSigningArgs( +// GetSignBytesAdapter returns the sign bytes for a given transaction and sign mode. It accepts the arguments expected +// for signing in x/auth/tx and converts them to the arguments expected by the txsigning.HandlerMap, then applies +// HandlerMap.GetSignBytes to get the sign bytes. +func GetSignBytesAdapter( ctx context.Context, encoder sdk.TxEncoder, handlerMap *txsigning.HandlerMap, diff --git a/x/auth/tx/aux_test.go b/x/auth/tx/aux_test.go index d08ee5a413bd..5d5c41cf718f 100644 --- a/x/auth/tx/aux_test.go +++ b/x/auth/tx/aux_test.go @@ -139,7 +139,7 @@ func TestBuilderWithAux(t *testing.T) { PubKey: feepayerPk, } - signBz, err = authsigning.AdaptSigningArgs( + signBz, err = authsigning.GetSignBytesAdapter( context.Background(), txConfig.TxEncoder(), txConfig.SignModeHandler(), signing.SignMode_SIGN_MODE_DIRECT, signerData, feepayerPk, w.GetTx()) diff --git a/x/auth/tx/direct_test.go b/x/auth/tx/direct_test.go index 7f098e4bde95..783afbcb7359 100644 --- a/x/auth/tx/direct_test.go +++ b/x/auth/tx/direct_test.go @@ -77,7 +77,7 @@ func TestDirectModeHandler(t *testing.T) { PubKey: pubkey, } - signBytes, err := signing.AdaptSigningArgs( + signBytes, err := signing.GetSignBytesAdapter( context.Background(), txConfig.TxEncoder(), txConfig.SignModeHandler(), defaultSignMode, signingData, pubkey, txBuilder.GetTx()) require.NoError(t, err) @@ -123,7 +123,7 @@ func TestDirectModeHandler(t *testing.T) { require.NoError(t, err) err = txBuilder.SetSignatures(sig) require.NoError(t, err) - signBytes, err = signing.AdaptSigningArgs( + signBytes, err = signing.GetSignBytesAdapter( context.Background(), txConfig.TxEncoder(), txConfig.SignModeHandler(), defaultSignMode, signingData, pubkey, txBuilder.GetTx()) require.NoError(t, err) diff --git a/x/auth/tx/testutil/suite.go b/x/auth/tx/testutil/suite.go index 7640d3e192e1..162507e42b5e 100644 --- a/x/auth/tx/testutil/suite.go +++ b/x/auth/tx/testutil/suite.go @@ -139,7 +139,7 @@ func (s *TxConfigTestSuite) TestTxBuilderSetSignatures() { Sequence: seq1, PubKey: pubkey, } - signBytes, err := signing.AdaptSigningArgs(context.Background(), s.TxConfig.TxEncoder(), + signBytes, err := signing.GetSignBytesAdapter(context.Background(), s.TxConfig.TxEncoder(), s.TxConfig.SignModeHandler(), defaultSignMode, signerData, pubkey, sigTx) s.Require().NoError(err) sigBz, err := privKey.Sign(signBytes) @@ -152,7 +152,7 @@ func (s *TxConfigTestSuite) TestTxBuilderSetSignatures() { Sequence: mseq, PubKey: multisigPk, } - mSignBytes, err := signing.AdaptSigningArgs(context.Background(), s.TxConfig.TxEncoder(), + mSignBytes, err := signing.GetSignBytesAdapter(context.Background(), s.TxConfig.TxEncoder(), s.TxConfig.SignModeHandler(), defaultSignMode, signerData, multisigPk, sigTx) s.Require().NoError(err) mSigBz1, err := privKey.Sign(mSignBytes) From 7364f41a61bbf724c44687bfac14deb755bf1119 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Tue, 18 Apr 2023 09:10:59 -0500 Subject: [PATCH 34/52] attempt remove redundant arg --- client/tx/tx.go | 4 ++-- testutil/sims/tx_helpers.go | 2 +- testutil/testnet/genesis.go | 1 - tools/rosetta/converter.go | 2 +- x/auth/ante/feegrant_test.go | 3 +-- x/auth/signing/verify.go | 4 +--- x/auth/tx/aux_test.go | 2 +- x/auth/tx/direct_test.go | 4 ++-- x/auth/tx/testutil/suite.go | 4 ++-- 9 files changed, 11 insertions(+), 15 deletions(-) diff --git a/client/tx/tx.go b/client/tx/tx.go index 9a5bf52606e3..097a34d6b62b 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -173,7 +173,7 @@ func SignWithPrivKey( // Generate the bytes to be signed. signBytes, err := authsigning.GetSignBytesAdapter( - ctx, txConfig.TxEncoder(), txConfig.SignModeHandler(), signMode, signerData, priv.PubKey(), txBuilder.GetTx()) + ctx, txConfig.TxEncoder(), txConfig.SignModeHandler(), signMode, signerData, txBuilder.GetTx()) if err != nil { return sigV2, err } @@ -317,7 +317,7 @@ func Sign(ctx context.Context, txf Factory, name string, txBuilder client.TxBuil bytesToSign, err := authsigning.GetSignBytesAdapter( ctx, txf.txConfig.TxEncoder(), txf.txConfig.SignModeHandler(), - signMode, signerData, pubKey, txBuilder.GetTx()) + signMode, signerData, txBuilder.GetTx()) if err != nil { return err } diff --git a/testutil/sims/tx_helpers.go b/testutil/sims/tx_helpers.go index 293ede0c34a2..d10043025cbf 100644 --- a/testutil/sims/tx_helpers.go +++ b/testutil/sims/tx_helpers.go @@ -65,7 +65,7 @@ func GenSignedMockTx(r *rand.Rand, txConfig client.TxConfig, msgs []sdk.Msg, fee } signBytes, err := authsign.GetSignBytesAdapter( - context.Background(), txConfig.TxEncoder(), txConfig.SignModeHandler(), signMode, signerData, p.PubKey(), + context.Background(), txConfig.TxEncoder(), txConfig.SignModeHandler(), signMode, signerData, tx.GetTx()) if err != nil { panic(err) diff --git a/testutil/testnet/genesis.go b/testutil/testnet/genesis.go index c8086bfe50e8..bfc1755c8160 100644 --- a/testutil/testnet/genesis.go +++ b/testutil/testnet/genesis.go @@ -153,7 +153,6 @@ func (b *GenesisBuilder) GenTx(privVal secp256k1.PrivKey, val cmttypes.GenesisVa // No account or sequence number for gentx. }, - pubKey, txb.GetTx(), ) if err != nil { diff --git a/tools/rosetta/converter.go b/tools/rosetta/converter.go index 6214607a15b2..429add923a75 100644 --- a/tools/rosetta/converter.go +++ b/tools/rosetta/converter.go @@ -117,7 +117,7 @@ func NewConverter(cdc *codec.ProtoCodec, ir codectypes.InterfaceRegistry, cfg sd bytesToSign: func(tx authsigning.Tx, signerData authsigning.SignerData) (b []byte, err error) { bytesToSign, err := authsigning.GetSignBytesAdapter( context.Background(), cfg.TxEncoder(), cfg.SignModeHandler(), - signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, signerData, signerData.PubKey, tx) + signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, signerData, tx) if err != nil { return nil, err } diff --git a/x/auth/ante/feegrant_test.go b/x/auth/ante/feegrant_test.go index c85623824353..2c1c307afc4b 100644 --- a/x/auth/ante/feegrant_test.go +++ b/x/auth/ante/feegrant_test.go @@ -241,8 +241,7 @@ func genTxWithFeeGranter(gen client.TxConfig, msgs []sdk.Msg, feeAmt sdk.Coins, Sequence: accSeqs[i], } signBytes, err := authsign.GetSignBytesAdapter( - context.Background(), gen.TxEncoder(), gen.SignModeHandler(), signMode, signerData, p.PubKey(), - tx.GetTx()) + context.Background(), gen.TxEncoder(), gen.SignModeHandler(), signMode, signerData, tx.GetTx()) if err != nil { panic(err) } diff --git a/x/auth/signing/verify.go b/x/auth/signing/verify.go index cd0f46f035ea..bcfa2f8d4932 100644 --- a/x/auth/signing/verify.go +++ b/x/auth/signing/verify.go @@ -116,8 +116,6 @@ func GetSignBytesAdapter( handlerMap *txsigning.HandlerMap, mode signing.SignMode, signerData SignerData, - // TODO refactor, this out and use the pubkey in the SignerData, I don't think this is needed. - key cryptotypes.PubKey, tx sdk.Tx, ) ([]byte, error) { // round trip performance hit. @@ -145,7 +143,7 @@ func GetSignBytesAdapter( return nil, err } - anyPk, err := codectypes.NewAnyWithValue(key) + anyPk, err := codectypes.NewAnyWithValue(signerData.PubKey) if err != nil { return nil, err } diff --git a/x/auth/tx/aux_test.go b/x/auth/tx/aux_test.go index 5d5c41cf718f..90481f5767cc 100644 --- a/x/auth/tx/aux_test.go +++ b/x/auth/tx/aux_test.go @@ -141,7 +141,7 @@ func TestBuilderWithAux(t *testing.T) { signBz, err = authsigning.GetSignBytesAdapter( context.Background(), txConfig.TxEncoder(), txConfig.SignModeHandler(), signing.SignMode_SIGN_MODE_DIRECT, - signerData, feepayerPk, w.GetTx()) + signerData, w.GetTx()) require.NoError(t, err) feepayerSig, err := feepayerPriv.Sign(signBz) diff --git a/x/auth/tx/direct_test.go b/x/auth/tx/direct_test.go index 783afbcb7359..de7ffe76aec5 100644 --- a/x/auth/tx/direct_test.go +++ b/x/auth/tx/direct_test.go @@ -78,7 +78,7 @@ func TestDirectModeHandler(t *testing.T) { } signBytes, err := signing.GetSignBytesAdapter( - context.Background(), txConfig.TxEncoder(), txConfig.SignModeHandler(), defaultSignMode, signingData, pubkey, + context.Background(), txConfig.TxEncoder(), txConfig.SignModeHandler(), defaultSignMode, signingData, txBuilder.GetTx()) require.NoError(t, err) require.NotNil(t, signBytes) @@ -124,7 +124,7 @@ func TestDirectModeHandler(t *testing.T) { err = txBuilder.SetSignatures(sig) require.NoError(t, err) signBytes, err = signing.GetSignBytesAdapter( - context.Background(), txConfig.TxEncoder(), txConfig.SignModeHandler(), defaultSignMode, signingData, pubkey, + context.Background(), txConfig.TxEncoder(), txConfig.SignModeHandler(), defaultSignMode, signingData, txBuilder.GetTx()) require.NoError(t, err) require.Equal(t, expectedSignBytes, signBytes) diff --git a/x/auth/tx/testutil/suite.go b/x/auth/tx/testutil/suite.go index 162507e42b5e..b238d3716fbc 100644 --- a/x/auth/tx/testutil/suite.go +++ b/x/auth/tx/testutil/suite.go @@ -140,7 +140,7 @@ func (s *TxConfigTestSuite) TestTxBuilderSetSignatures() { PubKey: pubkey, } signBytes, err := signing.GetSignBytesAdapter(context.Background(), s.TxConfig.TxEncoder(), - s.TxConfig.SignModeHandler(), defaultSignMode, signerData, pubkey, sigTx) + s.TxConfig.SignModeHandler(), defaultSignMode, signerData, sigTx) s.Require().NoError(err) sigBz, err := privKey.Sign(signBytes) s.Require().NoError(err) @@ -153,7 +153,7 @@ func (s *TxConfigTestSuite) TestTxBuilderSetSignatures() { PubKey: multisigPk, } mSignBytes, err := signing.GetSignBytesAdapter(context.Background(), s.TxConfig.TxEncoder(), - s.TxConfig.SignModeHandler(), defaultSignMode, signerData, multisigPk, sigTx) + s.TxConfig.SignModeHandler(), defaultSignMode, signerData, sigTx) s.Require().NoError(err) mSigBz1, err := privKey.Sign(mSignBytes) s.Require().NoError(err) From a0acb583fa83a270ce130168a21508d0a7fb1839 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Tue, 18 Apr 2023 09:21:04 -0500 Subject: [PATCH 35/52] move lazy registry --- types/proto.go | 57 ----------------------------- types/registry/registry.go | 58 ++++++++++++++++++++++++++++++ x/auth/ante/sigverify.go | 4 +-- x/auth/client/cli/validate_sigs.go | 3 +- x/auth/signing/verify.go | 3 +- x/auth/tx/config.go | 3 +- x/auth/tx/config/config.go | 3 +- 7 files changed, 68 insertions(+), 63 deletions(-) create mode 100644 types/registry/registry.go diff --git a/types/proto.go b/types/proto.go index d01e278fd3a6..a7bc8451b846 100644 --- a/types/proto.go +++ b/types/proto.go @@ -1,15 +1,5 @@ package types -import ( - "sync" - - "github.com/cosmos/gogoproto/proto" - "google.golang.org/protobuf/reflect/protoreflect" - "google.golang.org/protobuf/reflect/protoregistry" - - txsigning "cosmossdk.io/x/tx/signing" -) - // CustomProtobufType defines the interface custom gogo proto types must implement // in order to be used as a "customtype" extension. // @@ -23,50 +13,3 @@ type CustomProtobufType interface { MarshalJSON() ([]byte, error) UnmarshalJSON(data []byte) error } - -var ( - once sync.Once - mergedRegistry *protoregistry.Files - _ txsigning.ProtoFileResolver = lazyProtoRegistry{} -) - -// lazyProtoRegistry is a lazy loading wrapper around the global protobuf registry. -type lazyProtoRegistry struct{} - -func (l lazyProtoRegistry) getRegistry() (*protoregistry.Files, error) { - var err error - once.Do(func() { - mergedRegistry, err = proto.MergedRegistry() - }) - return mergedRegistry, err -} - -func (l lazyProtoRegistry) FindFileByPath(s string) (protoreflect.FileDescriptor, error) { - reg, err := l.getRegistry() - if err != nil { - return nil, err - } - return reg.FindFileByPath(s) -} - -func (l lazyProtoRegistry) FindDescriptorByName(name protoreflect.FullName) (protoreflect.Descriptor, error) { - reg, err := l.getRegistry() - if err != nil { - return nil, err - } - return reg.FindDescriptorByName(name) -} - -func (l lazyProtoRegistry) RangeFiles(f func(protoreflect.FileDescriptor) bool) { - reg, err := l.getRegistry() - if err != nil { - panic(err) - } - reg.RangeFiles(f) -} - -// MergedProtoRegistry returns a lazy loading wrapper around the global protobuf registry, a merged registry -// containing both gogo proto and pulsar types. -func MergedProtoRegistry() txsigning.ProtoFileResolver { - return lazyProtoRegistry{} -} diff --git a/types/registry/registry.go b/types/registry/registry.go new file mode 100644 index 000000000000..533b44848a80 --- /dev/null +++ b/types/registry/registry.go @@ -0,0 +1,58 @@ +package registry + +import ( + "sync" + + "github.com/cosmos/gogoproto/proto" + "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/reflect/protoregistry" + + "cosmossdk.io/x/tx/signing" +) + +var ( + once sync.Once + mergedRegistry *protoregistry.Files + _ signing.ProtoFileResolver = lazyProtoRegistry{} +) + +// lazyProtoRegistry is a lazy loading wrapper around the global protobuf registry. +type lazyProtoRegistry struct{} + +func (l lazyProtoRegistry) getRegistry() (*protoregistry.Files, error) { + var err error + once.Do(func() { + mergedRegistry, err = proto.MergedRegistry() + }) + return mergedRegistry, err +} + +func (l lazyProtoRegistry) FindFileByPath(s string) (protoreflect.FileDescriptor, error) { + reg, err := l.getRegistry() + if err != nil { + return nil, err + } + return reg.FindFileByPath(s) +} + +func (l lazyProtoRegistry) FindDescriptorByName(name protoreflect.FullName) (protoreflect.Descriptor, error) { + reg, err := l.getRegistry() + if err != nil { + return nil, err + } + return reg.FindDescriptorByName(name) +} + +func (l lazyProtoRegistry) RangeFiles(f func(protoreflect.FileDescriptor) bool) { + reg, err := l.getRegistry() + if err != nil { + panic(err) + } + reg.RangeFiles(f) +} + +// MergedProtoRegistry returns a lazy loading wrapper around the global protobuf registry, a merged registry +// containing both gogo proto and pulsar types. +func MergedProtoRegistry() signing.ProtoFileResolver { + return lazyProtoRegistry{} +} diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index 8d20699a126a..c38ec4741d94 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -13,6 +13,7 @@ import ( "cosmossdk.io/x/tx/decode" txsigning "cosmossdk.io/x/tx/signing" codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/types/registry" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" @@ -299,8 +300,7 @@ func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul Value: anyPk.Value, }, } - // TODO supply protoRegistry.Files or decoder further up - decodeCtx, err := decode.NewDecoder(decode.Options{ProtoFiles: sdk.MergedProtoRegistry()}) + decodeCtx, err := decode.NewDecoder(decode.Options{ProtoFiles: registry.MergedProtoRegistry()}) if err != nil { return ctx, err } diff --git a/x/auth/client/cli/validate_sigs.go b/x/auth/client/cli/validate_sigs.go index cf1b57f1fc2c..760ee7dd507b 100644 --- a/x/auth/client/cli/validate_sigs.go +++ b/x/auth/client/cli/validate_sigs.go @@ -13,6 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/tx" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/registry" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" ) @@ -137,7 +138,7 @@ func printAndValidateSigs( cmd.PrintErrf("failed to encode transaction: %v", err) return false } - decodeCtx, err := decode.NewDecoder(decode.Options{ProtoFiles: sdk.MergedProtoRegistry()}) + decodeCtx, err := decode.NewDecoder(decode.Options{ProtoFiles: registry.MergedProtoRegistry()}) if err != nil { cmd.PrintErrf("failed to create decoder: %v", err) return false diff --git a/x/auth/signing/verify.go b/x/auth/signing/verify.go index bcfa2f8d4932..a06596a62700 100644 --- a/x/auth/signing/verify.go +++ b/x/auth/signing/verify.go @@ -13,6 +13,7 @@ import ( cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/crypto/types/multisig" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/registry" "github.com/cosmos/cosmos-sdk/types/tx/signing" ) @@ -124,7 +125,7 @@ func GetSignBytesAdapter( if err != nil { return nil, err } - decodeCtx, err := decode.NewDecoder(decode.Options{ProtoFiles: sdk.MergedProtoRegistry()}) + decodeCtx, err := decode.NewDecoder(decode.Options{ProtoFiles: registry.MergedProtoRegistry()}) if err != nil { return nil, err } diff --git a/x/auth/tx/config.go b/x/auth/tx/config.go index 6a1cb64554f8..b4545fa7443e 100644 --- a/x/auth/tx/config.go +++ b/x/auth/tx/config.go @@ -11,6 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/registry" signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" ) @@ -45,7 +46,7 @@ func NewTxConfig(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signin // protoFiles should perhaps be a parameter to this function, but the choice was made here to not break the // NewTxConfig API. - protoFiles := sdk.MergedProtoRegistry() + protoFiles := registry.MergedProtoRegistry() typeResolver := protoregistry.GlobalTypes signersContext, err := txsigning.NewGetSignersContext(txsigning.GetSignersOptions{ProtoFiles: protoFiles}) if err != nil { diff --git a/x/auth/tx/config/config.go b/x/auth/tx/config/config.go index bfdd99c35dfa..e689167e42f1 100644 --- a/x/auth/tx/config/config.go +++ b/x/auth/tx/config/config.go @@ -22,6 +22,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/runtime" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/registry" "github.com/cosmos/cosmos-sdk/x/auth/ante" "github.com/cosmos/cosmos-sdk/x/auth/posthandler" "github.com/cosmos/cosmos-sdk/x/auth/tx" @@ -201,7 +202,7 @@ func NewGRPCCoinMetadataQueryFn(grpcConn grpc.ClientConnInterface) textual.CoinM // NewSignModeOptionsWithMetadataQueryFn creates a new SignModeOptions instance func NewSignModeOptionsWithMetadataQueryFn(fn textual.CoinMetadataQueryFn) (tx.SignModeOptions, error) { - protoFiles := sdk.MergedProtoRegistry() + protoFiles := registry.MergedProtoRegistry() typeResolver := protoregistry.GlobalTypes signersContext, err := txsigning.NewGetSignersContext(txsigning.GetSignersOptions{ProtoFiles: protoFiles}) if err != nil { From f04a10c6416d266f7a01e9b7a6ff6e208e87c6b4 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Tue, 18 Apr 2023 09:23:12 -0500 Subject: [PATCH 36/52] store init error --- types/registry/registry.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/types/registry/registry.go b/types/registry/registry.go index 533b44848a80..b24a0da4ee4e 100644 --- a/types/registry/registry.go +++ b/types/registry/registry.go @@ -11,20 +11,20 @@ import ( ) var ( - once sync.Once - mergedRegistry *protoregistry.Files - _ signing.ProtoFileResolver = lazyProtoRegistry{} + mergedRegistryOnce sync.Once + mergedRegistry *protoregistry.Files + mergedRegistryErr error + _ signing.ProtoFileResolver = lazyProtoRegistry{} ) // lazyProtoRegistry is a lazy loading wrapper around the global protobuf registry. type lazyProtoRegistry struct{} func (l lazyProtoRegistry) getRegistry() (*protoregistry.Files, error) { - var err error - once.Do(func() { - mergedRegistry, err = proto.MergedRegistry() + mergedRegistryOnce.Do(func() { + mergedRegistry, mergedRegistryErr = proto.MergedRegistry() }) - return mergedRegistry, err + return mergedRegistry, mergedRegistryErr } func (l lazyProtoRegistry) FindFileByPath(s string) (protoreflect.FileDescriptor, error) { From 59ab3ce966cd6ac57ed9211d38430e6b7c7dec99 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Tue, 18 Apr 2023 09:53:38 -0500 Subject: [PATCH 37/52] test fixes --- baseapp/block_gas_test.go | 1 + baseapp/msg_service_router_test.go | 1 + x/auth/ante/feegrant_test.go | 1 + 3 files changed, 3 insertions(+) diff --git a/baseapp/block_gas_test.go b/baseapp/block_gas_test.go index 3dc5b316ea5c..7408873ca67a 100644 --- a/baseapp/block_gas_test.go +++ b/baseapp/block_gas_test.go @@ -222,6 +222,7 @@ func createTestTx(txConfig client.TxConfig, txBuilder client.TxBuilder, privs [] ChainID: chainID, AccountNumber: accNums[i], Sequence: accSeqs[i], + PubKey: priv.PubKey(), } sigV2, err := tx.SignWithPrivKey( context.TODO(), defaultSignMode, signerData, diff --git a/baseapp/msg_service_router_test.go b/baseapp/msg_service_router_test.go index 1cfffa119694..3d18f160fb28 100644 --- a/baseapp/msg_service_router_test.go +++ b/baseapp/msg_service_router_test.go @@ -130,6 +130,7 @@ func TestMsgService(t *testing.T) { ChainID: "test", AccountNumber: 0, Sequence: 0, + PubKey: priv.PubKey(), } sigV2, err = tx.SignWithPrivKey( nil, defaultSignMode, signerData, //nolint:staticcheck // SA1019: txConfig.SignModeHandler().DefaultMode() is deprecated: use txConfig.SignModeHandler().DefaultMode() instead. diff --git a/x/auth/ante/feegrant_test.go b/x/auth/ante/feegrant_test.go index 2c1c307afc4b..3e9b63c5a426 100644 --- a/x/auth/ante/feegrant_test.go +++ b/x/auth/ante/feegrant_test.go @@ -239,6 +239,7 @@ func genTxWithFeeGranter(gen client.TxConfig, msgs []sdk.Msg, feeAmt sdk.Coins, ChainID: chainID, AccountNumber: accNums[i], Sequence: accSeqs[i], + PubKey: p.PubKey(), } signBytes, err := authsign.GetSignBytesAdapter( context.Background(), gen.TxEncoder(), gen.SignModeHandler(), signMode, signerData, tx.GetTx()) From d4bb593558192e1c85241711f502ead4a40be472 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Tue, 18 Apr 2023 11:04:47 -0500 Subject: [PATCH 38/52] handle default sign mode todos --- baseapp/block_gas_test.go | 8 +++++--- baseapp/msg_service_router_test.go | 4 ++-- client/tx/tx.go | 7 +++++-- client/tx/tx_test.go | 5 ++++- go.mod | 2 ++ go.sum | 2 -- testutil/sims/tx_helpers.go | 8 +++++--- x/auth/tx/config/config.go | 12 ++++-------- 8 files changed, 27 insertions(+), 21 deletions(-) diff --git a/baseapp/block_gas_test.go b/baseapp/block_gas_test.go index 7408873ca67a..9b9664b17aaa 100644 --- a/baseapp/block_gas_test.go +++ b/baseapp/block_gas_test.go @@ -192,8 +192,10 @@ func TestBaseApp_BlockGas(t *testing.T) { } func createTestTx(txConfig client.TxConfig, txBuilder client.TxBuilder, privs []cryptotypes.PrivKey, accNums, accSeqs []uint64, chainID string) (xauthsigning.Tx, []byte, error) { - // TODO: default mode in handler? - defaultSignMode := signing.SignMode_SIGN_MODE_DIRECT + defaultSignMode, err := xauthsigning.APISignModeToInternal(txConfig.SignModeHandler().DefaultMode()) + if err != nil { + return nil, nil, err + } // First round: we gather all the signer infos. We use the "set empty // signature" hack to do that. var sigsV2 []signing.SignatureV2 @@ -209,7 +211,7 @@ func createTestTx(txConfig client.TxConfig, txBuilder client.TxBuilder, privs [] sigsV2 = append(sigsV2, sigV2) } - err := txBuilder.SetSignatures(sigsV2...) + err = txBuilder.SetSignatures(sigsV2...) if err != nil { return nil, nil, err } diff --git a/baseapp/msg_service_router_test.go b/baseapp/msg_service_router_test.go index 3d18f160fb28..dd6ba9cfb9db 100644 --- a/baseapp/msg_service_router_test.go +++ b/baseapp/msg_service_router_test.go @@ -79,8 +79,6 @@ func TestRegisterMsgServiceTwice(t *testing.T) { func TestMsgService(t *testing.T) { priv, _, _ := testdata.KeyTestPubAddr() - // TODO: default mode? - defaultSignMode := signing.SignMode_SIGN_MODE_DIRECT var ( appBuilder *runtime.AppBuilder @@ -96,6 +94,8 @@ func TestMsgService(t *testing.T) { // set the TxDecoder in the BaseApp for minimal tx simulations app.SetTxDecoder(txConfig.TxDecoder()) + defaultSignMode, err := authsigning.APISignModeToInternal(txConfig.SignModeHandler().DefaultMode()) + testdata.RegisterInterfaces(interfaceRegistry) testdata.RegisterMsgServer( app.MsgServiceRouter(), diff --git a/client/tx/tx.go b/client/tx/tx.go index 097a34d6b62b..78de623a460e 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -249,11 +249,14 @@ func Sign(ctx context.Context, txf Factory, name string, txBuilder client.TxBuil return errors.New("keybase must be set prior to signing a transaction") } + var err error signMode := txf.signMode if signMode == signing.SignMode_SIGN_MODE_UNSPECIFIED { // use the SignModeHandler's default mode if unspecified - // TODO default mode in handler map? - signMode = signing.SignMode_SIGN_MODE_DIRECT + signMode, err = authsigning.APISignModeToInternal(txf.txConfig.SignModeHandler().DefaultMode()) + if err != nil { + return err + } } k, err := txf.keybase.Key(name) diff --git a/client/tx/tx_test.go b/client/tx/tx_test.go index 8bd71bb81a06..f46b3bf7a9e4 100644 --- a/client/tx/tx_test.go +++ b/client/tx/tx_test.go @@ -30,7 +30,6 @@ import ( ) // TODO default mode? -var defaultSignMode = signingtypes.SignMode_SIGN_MODE_DIRECT func newTestTxConfig() (client.TxConfig, codec.Codec) { encodingConfig := moduletestutil.MakeTestEncodingConfig() @@ -82,6 +81,8 @@ func TestCalculateGas(t *testing.T) { for _, tc := range testCases { stc := tc txCfg, _ := newTestTxConfig() + defaultSignMode, err := signing.APISignModeToInternal(txCfg.SignModeHandler().DefaultMode()) + require.NoError(t, err) txf := tx.Factory{}. WithChainID("test-chain"). @@ -108,6 +109,8 @@ func TestCalculateGas(t *testing.T) { func TestBuildSimTx(t *testing.T) { txCfg, cdc := newTestTxConfig() + defaultSignMode, err := signing.APISignModeToInternal(txCfg.SignModeHandler().DefaultMode()) + require.NoError(t, err) kb, err := keyring.New(t.Name(), "test", t.TempDir(), nil, cdc) require.NoError(t, err) diff --git a/go.mod b/go.mod index 5483eaed7c99..5ce2de226ff9 100644 --- a/go.mod +++ b/go.mod @@ -162,6 +162,8 @@ require ( // Below are the long-lived replace of the Cosmos SDK replace ( + // TODO remove + cosmossdk.io/x/tx => ../cosmos-sdk-dos/x/tx // use cosmos fork of keyring github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 // dgrijalva/jwt-go is deprecated and doesn't receive security updates. diff --git a/go.sum b/go.sum index 016c8dc610f5..dba0dbc975a4 100644 --- a/go.sum +++ b/go.sum @@ -51,8 +51,6 @@ cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw= cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc h1:9piuA+NYmhe+SyMPtMoboLw/djgDbrI3dD5TG020Tnk= cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc/go.mod h1:UFF5rmjN7WYVfxo6ArdY/l1+yyWMURBWOmSJypGqFHQ= -cosmossdk.io/x/tx v0.5.4 h1:tOLDbNDT9F9OvAjGfw3K3rjNhSickQDI9S1iSeovB/A= -cosmossdk.io/x/tx v0.5.4/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/testutil/sims/tx_helpers.go b/testutil/sims/tx_helpers.go index d10043025cbf..415ea292be4a 100644 --- a/testutil/sims/tx_helpers.go +++ b/testutil/sims/tx_helpers.go @@ -26,8 +26,10 @@ func GenSignedMockTx(r *rand.Rand, txConfig client.TxConfig, msgs []sdk.Msg, fee // create a random length memo memo := simulation.RandStringOfLength(r, simulation.RandIntBetween(r, 0, 100)) - // TODO support default mode? - signMode := signing.SignMode_SIGN_MODE_DIRECT + signMode, err := authsign.APISignModeToInternal(txConfig.SignModeHandler().DefaultMode()) + if err != nil { + return nil, err + } // 1st round: set SignatureV2 with empty signatures, to set correct // signer infos. @@ -42,7 +44,7 @@ func GenSignedMockTx(r *rand.Rand, txConfig client.TxConfig, msgs []sdk.Msg, fee } tx := txConfig.NewTxBuilder() - err := tx.SetMsgs(msgs...) + err = tx.SetMsgs(msgs...) if err != nil { return nil, err } diff --git a/x/auth/tx/config/config.go b/x/auth/tx/config/config.go index e689167e42f1..251b548c25da 100644 --- a/x/auth/tx/config/config.go +++ b/x/auth/tx/config/config.go @@ -39,17 +39,13 @@ func init() { type ModuleInputs struct { depinject.In - Config *txconfigv1.Config ProtoCodecMarshaler codec.ProtoCodecMarshaler - - AccountKeeper ante.AccountKeeper `optional:"true"` + SignModeOptions tx.SignModeOptions // BankKeeper is the expected bank keeper to be passed to AnteHandlers - BankKeeper authtypes.BankKeeper `optional:"true"` - // TxBankKeeper is the expected bank keeper to be passed to Textual - tx.SignModeOptions - FeeGrantKeeper ante.FeegrantKeeper `optional:"true"` - + BankKeeper authtypes.BankKeeper `optional:"true"` + AccountKeeper ante.AccountKeeper `optional:"true"` + FeeGrantKeeper ante.FeegrantKeeper `optional:"true"` CustomSignModeHandlers func() []txsigning.SignModeHandler `optional:"true"` } From 96a693d6eecaed0efc13219b925273c94ac19c91 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Tue, 18 Apr 2023 11:12:17 -0500 Subject: [PATCH 39/52] x/tx 0.5.5 --- client/tx/tx_test.go | 2 -- go.mod | 4 +--- simapp/go.mod | 2 +- simapp/go.sum | 4 ++-- tests/go.mod | 2 +- tests/go.sum | 4 ++-- tools/rosetta/go.mod | 2 +- tools/rosetta/go.sum | 4 ++-- x/auth/ante/sigverify_test.go | 6 ++++-- x/auth/tx/testutil/suite.go | 5 ++--- 10 files changed, 16 insertions(+), 19 deletions(-) diff --git a/client/tx/tx_test.go b/client/tx/tx_test.go index f46b3bf7a9e4..20d0a642d860 100644 --- a/client/tx/tx_test.go +++ b/client/tx/tx_test.go @@ -29,8 +29,6 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" ) -// TODO default mode? - func newTestTxConfig() (client.TxConfig, codec.Codec) { encodingConfig := moduletestutil.MakeTestEncodingConfig() return authtx.NewTxConfig(codec.NewProtoCodec(encodingConfig.InterfaceRegistry), authtx.DefaultSignModes), encodingConfig.Codec diff --git a/go.mod b/go.mod index 5ce2de226ff9..6c0a46fbe6a9 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( cosmossdk.io/log v1.0.0 cosmossdk.io/math v1.0.0 cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc - cosmossdk.io/x/tx v0.5.4 + cosmossdk.io/x/tx v0.5.5 github.com/99designs/keyring v1.2.1 github.com/armon/go-metrics v0.4.1 github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 @@ -162,8 +162,6 @@ require ( // Below are the long-lived replace of the Cosmos SDK replace ( - // TODO remove - cosmossdk.io/x/tx => ../cosmos-sdk-dos/x/tx // use cosmos fork of keyring github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 // dgrijalva/jwt-go is deprecated and doesn't receive security updates. diff --git a/simapp/go.mod b/simapp/go.mod index 987be9802dd0..3a3efaf31165 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -38,7 +38,7 @@ require ( cloud.google.com/go/storage v1.30.0 // indirect cosmossdk.io/collections v0.1.0 // indirect cosmossdk.io/errors v1.0.0-beta.7 // indirect - cosmossdk.io/x/tx v0.5.4 // indirect + cosmossdk.io/x/tx v0.5.5 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect diff --git a/simapp/go.sum b/simapp/go.sum index e930460b2aee..93e2139c21c4 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -202,8 +202,8 @@ cosmossdk.io/log v1.0.0 h1:NGKZ/A5rd4PduDfoscgABklX557PWjQINbosZy/m3Jk= cosmossdk.io/log v1.0.0/go.mod h1:CwX9BLiBruZb7lzLlRr3R231d/fVPUXk8gAdV4LQap0= cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw= cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= -cosmossdk.io/x/tx v0.5.4 h1:tOLDbNDT9F9OvAjGfw3K3rjNhSickQDI9S1iSeovB/A= -cosmossdk.io/x/tx v0.5.4/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= +cosmossdk.io/x/tx v0.5.5 h1:9XG3KOrqObt7Rw7KhT7fiqRd6EepUfmA9ERa8CHj1WM= +cosmossdk.io/x/tx v0.5.5/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/tests/go.mod b/tests/go.mod index b11b4f4f4c03..8419aa4f8993 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -13,7 +13,7 @@ require ( cosmossdk.io/x/evidence v0.1.0 cosmossdk.io/x/feegrant v0.0.0-20230117113717-50e7c4a4ceff cosmossdk.io/x/nft v0.0.0-20230113085233-fae3332d62fc - cosmossdk.io/x/tx v0.5.4 + cosmossdk.io/x/tx v0.5.5 cosmossdk.io/x/upgrade v0.0.0-20230127052425-54c8e1568335 github.com/cometbft/cometbft v0.37.1-0.20230411132551-3a91d155e664 github.com/cosmos/cosmos-db v1.0.0-rc.1 diff --git a/tests/go.sum b/tests/go.sum index 361d740ec470..ded5f08b36fe 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -202,8 +202,8 @@ cosmossdk.io/log v1.0.0 h1:NGKZ/A5rd4PduDfoscgABklX557PWjQINbosZy/m3Jk= cosmossdk.io/log v1.0.0/go.mod h1:CwX9BLiBruZb7lzLlRr3R231d/fVPUXk8gAdV4LQap0= cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw= cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= -cosmossdk.io/x/tx v0.5.4 h1:tOLDbNDT9F9OvAjGfw3K3rjNhSickQDI9S1iSeovB/A= -cosmossdk.io/x/tx v0.5.4/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= +cosmossdk.io/x/tx v0.5.5 h1:9XG3KOrqObt7Rw7KhT7fiqRd6EepUfmA9ERa8CHj1WM= +cosmossdk.io/x/tx v0.5.5/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/tools/rosetta/go.mod b/tools/rosetta/go.mod index 1b5c10292264..5298e59c9036 100644 --- a/tools/rosetta/go.mod +++ b/tools/rosetta/go.mod @@ -23,7 +23,7 @@ require ( cosmossdk.io/depinject v1.0.0-alpha.3 // indirect cosmossdk.io/errors v1.0.0-beta.7 // indirect cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc // indirect - cosmossdk.io/x/tx v0.5.4 // indirect + cosmossdk.io/x/tx v0.5.5 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect diff --git a/tools/rosetta/go.sum b/tools/rosetta/go.sum index 196dfd79ddbf..742944d15ace 100644 --- a/tools/rosetta/go.sum +++ b/tools/rosetta/go.sum @@ -51,8 +51,8 @@ cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw= cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc h1:9piuA+NYmhe+SyMPtMoboLw/djgDbrI3dD5TG020Tnk= cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc/go.mod h1:UFF5rmjN7WYVfxo6ArdY/l1+yyWMURBWOmSJypGqFHQ= -cosmossdk.io/x/tx v0.5.4 h1:tOLDbNDT9F9OvAjGfw3K3rjNhSickQDI9S1iSeovB/A= -cosmossdk.io/x/tx v0.5.4/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= +cosmossdk.io/x/tx v0.5.5 h1:9XG3KOrqObt7Rw7KhT7fiqRd6EepUfmA9ERa8CHj1WM= +cosmossdk.io/x/tx v0.5.5/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/x/auth/ante/sigverify_test.go b/x/auth/ante/sigverify_test.go index 7d8893c53516..f6870f24a437 100644 --- a/x/auth/ante/sigverify_test.go +++ b/x/auth/ante/sigverify_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/require" storetypes "cosmossdk.io/store/types" + authsign "github.com/cosmos/cosmos-sdk/x/auth/signing" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" @@ -172,6 +173,8 @@ func TestSigVerification(t *testing.T) { ) svd := ante.NewSigVerificationDecorator(suite.accountKeeper, anteTxConfig.SignModeHandler()) antehandler := sdk.ChainAnteDecorators(spkd, svd) + defaultSignMode, err := authsign.APISignModeToInternal(anteTxConfig.SignModeHandler().DefaultMode()) + require.NoError(t, err) type testCase struct { name string @@ -211,8 +214,7 @@ func TestSigVerification(t *testing.T) { txSigs[0] = signing.SignatureV2{ PubKey: tc.privs[0].PubKey(), Data: &signing.SingleSignatureData{ - // TODO: default sign mode - SignMode: signing.SignMode_SIGN_MODE_DIRECT, + SignMode: defaultSignMode, Signature: badSig, }, Sequence: tc.accSeqs[0], diff --git a/x/auth/tx/testutil/suite.go b/x/auth/tx/testutil/suite.go index b238d3716fbc..ab9ab69096d6 100644 --- a/x/auth/tx/testutil/suite.go +++ b/x/auth/tx/testutil/suite.go @@ -99,9 +99,8 @@ func (s *TxConfigTestSuite) TestTxBuilderSetSignatures() { signModeHandler := s.TxConfig.SignModeHandler() s.Require().Contains(signModeHandler.SupportedModes(), signingv1beta1.SignMode_SIGN_MODE_DIRECT) - - // TODO: default sign mode in handler? - defaultSignMode := signingtypes.SignMode_SIGN_MODE_DIRECT + defaultSignMode, err := signing.APISignModeToInternal(s.TxConfig.SignModeHandler().DefaultMode()) + s.Require().NoError(err) // set SignatureV2 without actual signature bytes seq1 := uint64(2) // Arbitrary account sequence From 0796a6c58b5c16dc6664b66569a856b95327320a Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Tue, 18 Apr 2023 11:14:49 -0500 Subject: [PATCH 40/52] go mod tidy --- go.sum | 2 ++ 1 file changed, 2 insertions(+) diff --git a/go.sum b/go.sum index dba0dbc975a4..07d272880725 100644 --- a/go.sum +++ b/go.sum @@ -51,6 +51,8 @@ cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw= cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc h1:9piuA+NYmhe+SyMPtMoboLw/djgDbrI3dD5TG020Tnk= cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc/go.mod h1:UFF5rmjN7WYVfxo6ArdY/l1+yyWMURBWOmSJypGqFHQ= +cosmossdk.io/x/tx v0.5.5 h1:9XG3KOrqObt7Rw7KhT7fiqRd6EepUfmA9ERa8CHj1WM= +cosmossdk.io/x/tx v0.5.5/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= From ad658b5e5a18ed145bc629c2897dc2716750cbf5 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Tue, 18 Apr 2023 11:34:01 -0500 Subject: [PATCH 41/52] rm more todos --- x/auth/client/cli/tx_multisign.go | 2 -- x/auth/client/cli/validate_sigs.go | 1 - x/auth/tx/direct_test.go | 6 +++--- x/group/client/cli/tx_test.go | 2 +- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index 2dc6745e2332..c1495f767a79 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -128,7 +128,6 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) (err error) { } for _, sig := range sigs { - // TODO abstract, clean up anyPk, err := codectypes.NewAnyWithValue(sig.PubKey) if err != nil { return err @@ -342,7 +341,6 @@ func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error { PubKey: pubKey, } - // TODO abstract, clean up anyPk, err := codectypes.NewAnyWithValue(multisigPub) if err != nil { return err diff --git a/x/auth/client/cli/validate_sigs.go b/x/auth/client/cli/validate_sigs.go index 760ee7dd507b..93c59f903594 100644 --- a/x/auth/client/cli/validate_sigs.go +++ b/x/auth/client/cli/validate_sigs.go @@ -116,7 +116,6 @@ func printAndValidateSigs( Sequence: accSeq, PubKey: pubKey, } - // TODO abstract, clean up anyPk, err := codectypes.NewAnyWithValue(pubKey) if err != nil { cmd.PrintErrf("failed to pack public key: %v", err) diff --git a/x/auth/tx/direct_test.go b/x/auth/tx/direct_test.go index de7ffe76aec5..09365541ee63 100644 --- a/x/auth/tx/direct_test.go +++ b/x/auth/tx/direct_test.go @@ -65,10 +65,10 @@ func TestDirectModeHandler(t *testing.T) { require.NoError(t, err) t.Log("verify modes and default-mode") - defaultSignMode := signingtypes.SignMode_SIGN_MODE_DIRECT + defaultSignMode, err := signing.APISignModeToInternal(txConfig.SignModeHandler().DefaultMode()) + require.NoError(t, err) require.Equal(t, defaultSignMode, signingtypes.SignMode_SIGN_MODE_DIRECT) - // TODO, once API is cleaned up, this should be 1 - // require.Len(t, modeHandler.Modes(), 1) + require.Len(t, txConfig.SignModeHandler().SupportedModes(), 1) signingData := signing.SignerData{ Address: addr.String(), diff --git a/x/group/client/cli/tx_test.go b/x/group/client/cli/tx_test.go index f4847bf3bc4e..b04e3282c70f 100644 --- a/x/group/client/cli/tx_test.go +++ b/x/group/client/cli/tx_test.go @@ -12,7 +12,7 @@ import ( rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock" "github.com/stretchr/testify/suite" - // TODO: should amino json encoder receive a different registry to prevent the need for this? + // without this import amino json encoding will fail when resolving any types _ "cosmossdk.io/api/cosmos/group/v1" sdkmath "cosmossdk.io/math" From c2703934b1bd98b46d9dda5e138d8e6fae6471a5 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Tue, 18 Apr 2023 11:36:22 -0500 Subject: [PATCH 42/52] lint fix --- baseapp/msg_service_router_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/baseapp/msg_service_router_test.go b/baseapp/msg_service_router_test.go index dd6ba9cfb9db..32dfed7aaf7c 100644 --- a/baseapp/msg_service_router_test.go +++ b/baseapp/msg_service_router_test.go @@ -95,6 +95,7 @@ func TestMsgService(t *testing.T) { app.SetTxDecoder(txConfig.TxDecoder()) defaultSignMode, err := authsigning.APISignModeToInternal(txConfig.SignModeHandler().DefaultMode()) + require.NoError(t, err) testdata.RegisterInterfaces(interfaceRegistry) testdata.RegisterMsgServer( From 4ad00c54063ac49a499e9da908a99ec64b959652 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Tue, 18 Apr 2023 12:01:26 -0500 Subject: [PATCH 43/52] clean up handler creation API --- x/auth/tx/config.go | 52 +++++++++++++++++++++------------------ x/auth/tx/mode_handler.go | 8 ++++-- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/x/auth/tx/config.go b/x/auth/tx/config.go index b4545fa7443e..7c82be899b1e 100644 --- a/x/auth/tx/config.go +++ b/x/auth/tx/config.go @@ -7,6 +7,7 @@ import ( txsigning "cosmossdk.io/x/tx/signing" "cosmossdk.io/x/tx/signing/aminojson" + "cosmossdk.io/x/tx/signing/direct" "cosmossdk.io/x/tx/signing/directaux" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" @@ -38,12 +39,6 @@ type config struct { func NewTxConfig(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signingtypes.SignMode, customSignModes ...txsigning.SignModeHandler, ) client.TxConfig { - for _, m := range enabledSignModes { - if m == signingtypes.SignMode_SIGN_MODE_TEXTUAL { - panic("cannot use NewTxConfig with SIGN_MODE_TEXTUAL enabled; please use NewTxConfigWithTextual") - } - } - // protoFiles should perhaps be a parameter to this function, but the choice was made here to not break the // NewTxConfig API. protoFiles := registry.MergedProtoRegistry() @@ -53,27 +48,36 @@ func NewTxConfig(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signin panic(err) } - aminoJSONEncoder := aminojson.NewAminoJSON() - signModeOptions := SignModeOptions{ - DirectAux: &directaux.SignModeHandlerOptions{ - FileResolver: protoFiles, - TypeResolver: typeResolver, - SignersContext: signersContext, - }, - AminoJSON: &aminojson.SignModeHandlerOptions{ - FileResolver: protoFiles, - TypeResolver: typeResolver, - Encoder: &aminoJSONEncoder, - }, + signModeOptions := &SignModeOptions{} + for _, m := range enabledSignModes { + switch m { + case signingtypes.SignMode_SIGN_MODE_DIRECT: + signModeOptions.Direct = &direct.SignModeHandler{} + case signingtypes.SignMode_SIGN_MODE_DIRECT_AUX: + signModeOptions.DirectAux = &directaux.SignModeHandlerOptions{ + FileResolver: protoFiles, + TypeResolver: typeResolver, + SignersContext: signersContext, + } + case signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON: + aminoJSONEncoder := aminojson.NewAminoJSON() + signModeOptions.AminoJSON = &aminojson.SignModeHandlerOptions{ + FileResolver: protoFiles, + TypeResolver: typeResolver, + Encoder: &aminoJSONEncoder, + } + case signingtypes.SignMode_SIGN_MODE_TEXTUAL: + panic("cannot use NewTxConfig with SIGN_MODE_TEXTUAL enabled; please use NewTxConfigWithTextual") + } } - return NewTxConfigWithHandler(protoCodec, makeSignModeHandler(enabledSignModes, signModeOptions, customSignModes...)) + return NewTxConfigWithHandler(protoCodec, makeSignModeHandler(*signModeOptions, customSignModes...)) } -func NewTxConfigWithOptions(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signingtypes.SignMode, - signModeOptions SignModeOptions, customSignModes ...txsigning.SignModeHandler, +func NewTxConfigWithOptions(protoCodec codec.ProtoCodecMarshaler, signModeOptions SignModeOptions, + customSignModes ...txsigning.SignModeHandler, ) client.TxConfig { - return NewTxConfigWithHandler(protoCodec, makeSignModeHandler(enabledSignModes, signModeOptions, customSignModes...)) + return NewTxConfigWithHandler(protoCodec, makeSignModeHandler(signModeOptions, customSignModes...)) } // NewTxConfigWithTextual is like NewTxConfig with the ability to add @@ -81,10 +85,10 @@ func NewTxConfigWithOptions(protoCodec codec.ProtoCodecMarshaler, enabledSignMod // be used for TESTING purposes only, until Textual is fully released. // // Deprecated: use NewTxConfigWithOptions instead. -func NewTxConfigWithTextual(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signingtypes.SignMode, +func NewTxConfigWithTextual(protoCodec codec.ProtoCodecMarshaler, _ []signingtypes.SignMode, signModeOptions SignModeOptions, customSignModes ...txsigning.SignModeHandler, ) client.TxConfig { - return NewTxConfigWithOptions(protoCodec, enabledSignModes, signModeOptions, customSignModes...) + return NewTxConfigWithOptions(protoCodec, signModeOptions, customSignModes...) } // NewTxConfigWithHandler returns a new protobuf TxConfig using the provided ProtoCodec and signing handler. diff --git a/x/auth/tx/mode_handler.go b/x/auth/tx/mode_handler.go index 1de426204195..ff0b3440a4bc 100644 --- a/x/auth/tx/mode_handler.go +++ b/x/auth/tx/mode_handler.go @@ -16,6 +16,8 @@ type SignModeOptions struct { DirectAux *directaux.SignModeHandlerOptions // AminoJSON are options for SIGN_MODE_LEGACY_AMINO_JSON AminoJSON *aminojson.SignModeHandlerOptions + // Direct is the SignModeHandler for SIGN_MODE_DIRECT since it takes options + Direct *direct.SignModeHandler } // DefaultSignModes are the default sign modes enabled for protobuf transactions. @@ -34,11 +36,13 @@ var DefaultSignModes = []signingtypes.SignMode{ // makeSignModeHandler returns the default protobuf SignModeHandler supporting // SIGN_MODE_DIRECT, SIGN_MODE_DIRECT_AUX and SIGN_MODE_LEGACY_AMINO_JSON. func makeSignModeHandler( - _ []signingtypes.SignMode, opts SignModeOptions, customSignModes ...txsigning.SignModeHandler, ) *txsigning.HandlerMap { - handlers := []txsigning.SignModeHandler{direct.SignModeHandler{}} + var handlers []txsigning.SignModeHandler + if opts.Direct != nil { + handlers = append(handlers, opts.Direct) + } if opts.Textual != nil { h, err := textual.NewSignModeHandler(*opts.Textual) if err != nil { From 8e516b2b3c63e0b4672455a0f8caadf2d24aff56 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Tue, 18 Apr 2023 12:17:02 -0500 Subject: [PATCH 44/52] fix more test bugs --- x/auth/ante/sigverify_test.go | 2 -- x/auth/tx/config/config.go | 7 ++++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/x/auth/ante/sigverify_test.go b/x/auth/ante/sigverify_test.go index f6870f24a437..6309f72633f2 100644 --- a/x/auth/ante/sigverify_test.go +++ b/x/auth/ante/sigverify_test.go @@ -136,7 +136,6 @@ func TestSigVerification(t *testing.T) { require.NoError(t, err) suite.clientCtx.TxConfig = authtx.NewTxConfigWithOptions( codec.NewProtoCodec(suite.encCfg.InterfaceRegistry), - enabledSignModes, opts, ) suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder() @@ -168,7 +167,6 @@ func TestSigVerification(t *testing.T) { require.NoError(t, err) anteTxConfig := authtx.NewTxConfigWithOptions( codec.NewProtoCodec(suite.encCfg.InterfaceRegistry), - enabledSignModes, opts, ) svd := ante.NewSigVerificationDecorator(suite.accountKeeper, anteTxConfig.SignModeHandler()) diff --git a/x/auth/tx/config/config.go b/x/auth/tx/config/config.go index 251b548c25da..c383f8533596 100644 --- a/x/auth/tx/config/config.go +++ b/x/auth/tx/config/config.go @@ -15,6 +15,7 @@ import ( "cosmossdk.io/depinject" txsigning "cosmossdk.io/x/tx/signing" "cosmossdk.io/x/tx/signing/aminojson" + "cosmossdk.io/x/tx/signing/direct" "cosmossdk.io/x/tx/signing/directaux" "cosmossdk.io/x/tx/signing/textual" "github.com/cosmos/cosmos-sdk/baseapp" @@ -68,10 +69,9 @@ func ProvideSignModeOptions(bk BankKeeper) tx.SignModeOptions { func ProvideModule(in ModuleInputs) ModuleOutputs { var txConfig client.TxConfig if in.CustomSignModeHandlers == nil { - txConfig = tx.NewTxConfigWithOptions(in.ProtoCodecMarshaler, tx.DefaultSignModes, in.SignModeOptions) + txConfig = tx.NewTxConfigWithOptions(in.ProtoCodecMarshaler, in.SignModeOptions) } else { - txConfig = tx.NewTxConfigWithOptions(in.ProtoCodecMarshaler, tx.DefaultSignModes, in.SignModeOptions, - in.CustomSignModeHandlers()...) + txConfig = tx.NewTxConfigWithOptions(in.ProtoCodecMarshaler, in.SignModeOptions, in.CustomSignModeHandlers()...) } baseAppOption := func(app *baseapp.BaseApp) { @@ -207,6 +207,7 @@ func NewSignModeOptionsWithMetadataQueryFn(fn textual.CoinMetadataQueryFn) (tx.S aminoJSONEncoder := aminojson.NewAminoJSON() signModeOptions := tx.SignModeOptions{ + Direct: &direct.SignModeHandler{}, DirectAux: &directaux.SignModeHandlerOptions{ FileResolver: protoFiles, TypeResolver: typeResolver, From f138251f2fbc2d0cfbcf6584462ff19c98da75cd Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Tue, 18 Apr 2023 12:18:40 -0500 Subject: [PATCH 45/52] finish simd/root command --- simapp/simd/cmd/root.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index 54f3c272704f..84c798aa1714 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -15,8 +15,6 @@ import ( "cosmossdk.io/simapp/params" confixcmd "cosmossdk.io/tools/confix/cmd" rosettaCmd "cosmossdk.io/tools/rosetta/cmd" - "github.com/cosmos/cosmos-sdk/x/auth/signing" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/config" "github.com/cosmos/cosmos-sdk/client/debug" @@ -87,13 +85,8 @@ func NewRootCmd() *cobra.Command { if err != nil { return err } - signModes, err := signing.APISignModesToInternal(encodingConfig.TxConfig.SignModeHandler().SupportedModes()) - if err != nil { - return err - } txConfigWithTextual := tx.NewTxConfigWithOptions( codec.NewProtoCodec(encodingConfig.InterfaceRegistry), - signModes, opts, ) initClientCtx = initClientCtx.WithTxConfig(txConfigWithTextual) From 76c6363c61c75edc7a8ff8570298721f8c3cb491 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Wed, 19 Apr 2023 08:39:19 -0500 Subject: [PATCH 46/52] a little clean up --- baseapp/block_gas_test.go | 1 - x/auth/client/cli/tx_multisign.go | 32 +++++++++---------------------- x/auth/signing/verify.go | 10 +++++----- x/auth/tx/config.go | 1 + x/auth/tx/config/config.go | 1 + 5 files changed, 16 insertions(+), 29 deletions(-) diff --git a/baseapp/block_gas_test.go b/baseapp/block_gas_test.go index 9b9664b17aaa..105cb4f29066 100644 --- a/baseapp/block_gas_test.go +++ b/baseapp/block_gas_test.go @@ -14,7 +14,6 @@ import ( "cosmossdk.io/depinject" "cosmossdk.io/log" sdkmath "cosmossdk.io/math" - store "cosmossdk.io/store/types" baseapptestutil "github.com/cosmos/cosmos-sdk/baseapp/testutil" diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index c1495f767a79..b2cad64a71ef 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -13,6 +13,7 @@ import ( "cosmossdk.io/x/tx/decode" txsigning "cosmossdk.io/x/tx/signing" codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/types/registry" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -132,29 +133,21 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) (err error) { if err != nil { return err } - signingData := signing.SignerData{ - Address: sdk.AccAddress(sig.PubKey.Address()).String(), + txSignerData := txsigning.SignerData{ ChainID: txFactory.ChainID(), AccountNumber: txFactory.AccountNumber(), Sequence: txFactory.Sequence(), - PubKey: sig.PubKey, - } - txSignerData := txsigning.SignerData{ - ChainID: signingData.ChainID, - AccountNumber: signingData.AccountNumber, - Sequence: signingData.Sequence, - Address: signingData.Address, + Address: sdk.AccAddress(sig.PubKey.Address()).String(), PubKey: &anypb.Any{ TypeUrl: anyPk.TypeUrl, Value: anyPk.Value, }, } - txBytes, err := txCfg.TxEncoder()(txBuilder.GetTx()) if err != nil { return err } - decodeCtx, err := decode.NewDecoder(decode.Options{}) + decodeCtx, err := decode.NewDecoder(decode.Options{ProtoFiles: registry.MergedProtoRegistry()}) if err != nil { return err } @@ -333,23 +326,16 @@ func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error { } multisigPub := pubKey.(*kmultisig.LegacyAminoPubKey) multisigSig := multisig.NewMultisig(len(multisigPub.PubKeys)) - signingData := signing.SignerData{ - Address: sdk.AccAddress(pubKey.Address()).String(), - ChainID: txFactory.ChainID(), - AccountNumber: txFactory.AccountNumber(), - Sequence: txFactory.Sequence(), - PubKey: pubKey, - } anyPk, err := codectypes.NewAnyWithValue(multisigPub) if err != nil { return err } txSignerData := txsigning.SignerData{ - ChainID: signingData.ChainID, - AccountNumber: signingData.AccountNumber, - Sequence: signingData.Sequence, - Address: signingData.Address, + ChainID: txFactory.ChainID(), + AccountNumber: txFactory.AccountNumber(), + Sequence: txFactory.Sequence(), + Address: sdk.AccAddress(pubKey.Address()).String(), PubKey: &anypb.Any{ TypeUrl: anyPk.TypeUrl, Value: anyPk.Value, @@ -360,7 +346,7 @@ func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error { if err != nil { return err } - decodeCtx, err := decode.NewDecoder(decode.Options{}) + decodeCtx, err := decode.NewDecoder(decode.Options{ProtoFiles: registry.MergedProtoRegistry()}) if err != nil { return err } diff --git a/x/auth/signing/verify.go b/x/auth/signing/verify.go index a06596a62700..6455e60b782a 100644 --- a/x/auth/signing/verify.go +++ b/x/auth/signing/verify.go @@ -46,8 +46,8 @@ func APISignModeToInternal(mode signingv1beta1.SignMode) (signing.SignMode, erro } } -// InternalSignModeToAPI converts a signing.SignMode to a protobuf SignMode. -func InternalSignModeToAPI(mode signing.SignMode) (signingv1beta1.SignMode, error) { +// internalSignModeToAPI converts a signing.SignMode to a protobuf SignMode. +func internalSignModeToAPI(mode signing.SignMode) (signingv1beta1.SignMode, error) { switch mode { case signing.SignMode_SIGN_MODE_DIRECT: return signingv1beta1.SignMode_SIGN_MODE_DIRECT, nil @@ -74,7 +74,7 @@ func VerifySignature( ) error { switch data := signatureData.(type) { case *signing.SingleSignatureData: - signMode, err := InternalSignModeToAPI(data.SignMode) + signMode, err := internalSignModeToAPI(data.SignMode) if err != nil { return err } @@ -93,7 +93,7 @@ func VerifySignature( return fmt.Errorf("expected %T, got %T", (multisig.PubKey)(nil), pubKey) } err := multiPK.VerifyMultisignature(func(mode signing.SignMode) ([]byte, error) { - signMode, err := InternalSignModeToAPI(mode) + signMode, err := internalSignModeToAPI(mode) if err != nil { return nil, err } @@ -139,7 +139,7 @@ func GetSignBytesAdapter( AuthInfoBytes: decodedTx.TxRaw.AuthInfoBytes, BodyBytes: decodedTx.TxRaw.BodyBytes, } - txSignMode, err := InternalSignModeToAPI(mode) + txSignMode, err := internalSignModeToAPI(mode) if err != nil { return nil, err } diff --git a/x/auth/tx/config.go b/x/auth/tx/config.go index 7c82be899b1e..a83b196e0592 100644 --- a/x/auth/tx/config.go +++ b/x/auth/tx/config.go @@ -9,6 +9,7 @@ import ( "cosmossdk.io/x/tx/signing/aminojson" "cosmossdk.io/x/tx/signing/direct" "cosmossdk.io/x/tx/signing/directaux" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/x/auth/tx/config/config.go b/x/auth/tx/config/config.go index c383f8533596..47176cda1e3e 100644 --- a/x/auth/tx/config/config.go +++ b/x/auth/tx/config/config.go @@ -18,6 +18,7 @@ import ( "cosmossdk.io/x/tx/signing/direct" "cosmossdk.io/x/tx/signing/directaux" "cosmossdk.io/x/tx/signing/textual" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" From 05d52af8e2cd97f62a1c9b2f81731b7aa3327af9 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Wed, 19 Apr 2023 09:34:09 -0500 Subject: [PATCH 47/52] Add CHANGELOG entries for API breaks --- CHANGELOG.md | 5 +++++ x/auth/tx/config/textual.go | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) delete mode 100644 x/auth/tx/config/textual.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a5564e09a57..95995df9dd3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -163,6 +163,11 @@ Ref: https://keepachangelog.com/en/1.0.0/ * `AminoCodec` is marked as deprecated. * (x/crisis) [#15852](https://github.com/cosmos/cosmos-sdk/pull/15852) Crisis keeper now takes a instance of the address codec to be able to decode user addresses * (x/slashing) [#15875](https://github.com/cosmos/cosmos-sdk/pull/15875) `x/slashing.NewAppModule` now requires an `InterfaceRegistry` parameter. +* (client) [#15822](https://github.com/cosmos/cosmos-sdk/pull/15822) The return type of the interface method `TxConfig.SignModeHandler` has been changed to `x/tx/signing.HandlerMap`. +* (x/auth) [#15822](https://github.com/cosmos/cosmos-sdk/pull/15822) The type of struct field `ante.HandlerOptions.SignModeHandler` has been changed to `x/tx/signing.HandlerMap`. + * The signature of `NewSigVerificationDecorator` has been changed to accept a `x/tx/signing.HandlerMap`. + * The signature of `VerifySignature` has been changed to accept a `x/tx/signing.HandlerMap` and other structs from `x/tx` as arguments. + * The signature of `NewTxConfigWithTextual` has been deprecated and its signature changed to accept a `SignModeOptions`. ### Client Breaking Changes diff --git a/x/auth/tx/config/textual.go b/x/auth/tx/config/textual.go deleted file mode 100644 index 336f5e5a88d7..000000000000 --- a/x/auth/tx/config/textual.go +++ /dev/null @@ -1 +0,0 @@ -package tx From f3211b8619085842b10b74b972eeae4fc6d65c78 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Wed, 19 Apr 2023 10:31:15 -0500 Subject: [PATCH 48/52] Add UPGRADING entries --- UPGRADING.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/UPGRADING.md b/UPGRADING.md index 891c6dcba7c0..f2fafaa33a11 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -93,6 +93,10 @@ References to `types/store.go` which contained aliases for store types have been The `store` module is extracted to have a separate go.mod file which allows it be a standalone module. All the store imports are now renamed to use `cosmossdk.io/store` instead of `github.com/cosmos/cosmos-sdk/store` across the SDK. +#### Client + +The return type of the interface method `TxConfig.SignModeHandler()` has been changed from `x/auth/signing.SignModeHandler` to `x/tx/signing.HandlerMap`. This change is transparent to most users as the `TxConfig` interface is typically implemented by private `x/auth/tx.config` struct (as returned by `auth.NewTxConfig`) which has been updated to return the new type. If users have implemented their own `TxConfig` interface, they will need to update their implementation to return the new type. + ### Modules #### `**all**` @@ -105,6 +109,8 @@ It is now recommended to validate message directly in the message server. When t Methods in the `AccountKeeper` now use `context.Context` instead of `sdk.Context`. Any module that has an interface for it will need to update and re-generate mocks if needed. +For ante handler construction via `ante.NewAnteHandler`, the field `ante.HandlerOptions.SignModeHandler` has been updated to `x/tx/signing/HandlerMap` from `x/auth/signing/SignModeHandler`. Callers typically fetch this value from `client.TxConfig.SignModeHandler()` (which is also changed) so this change should be transparent to most users. + #### `x/capability` Capability was moved to [IBC-GO](https://github.com/cosmos/ibc-go). IBC V8 will contain the necessary changes to incorporate the new module location From d1af44cc11e03b0409e5d3027e3e0cece8c99b38 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Wed, 19 Apr 2023 10:51:10 -0500 Subject: [PATCH 49/52] PR fixes --- baseapp/msg_service_router_test.go | 2 +- server/grpc/server.go | 5 +++-- types/registry/registry.go | 26 ++++++++++---------------- x/auth/ante/feegrant_test.go | 2 +- x/auth/client/cli/tx_multisign.go | 11 ++++++----- x/auth/client/cli/validate_sigs.go | 1 + x/auth/tx/config/config.go | 8 ++++---- 7 files changed, 26 insertions(+), 29 deletions(-) diff --git a/baseapp/msg_service_router_test.go b/baseapp/msg_service_router_test.go index 32dfed7aaf7c..cbdbdeda9ee2 100644 --- a/baseapp/msg_service_router_test.go +++ b/baseapp/msg_service_router_test.go @@ -134,7 +134,7 @@ func TestMsgService(t *testing.T) { PubKey: priv.PubKey(), } sigV2, err = tx.SignWithPrivKey( - nil, defaultSignMode, signerData, //nolint:staticcheck // SA1019: txConfig.SignModeHandler().DefaultMode() is deprecated: use txConfig.SignModeHandler().DefaultMode() instead. + nil, defaultSignMode, signerData, txBuilder, priv, txConfig, 0) require.NoError(t, err) err = txBuilder.SetSignatures(sigV2) diff --git a/server/grpc/server.go b/server/grpc/server.go index e5a1abf66178..51bcf3f445b9 100644 --- a/server/grpc/server.go +++ b/server/grpc/server.go @@ -45,8 +45,9 @@ func NewGRPCServer(clientCtx client.Context, app types.Application, cfg config.G // time. err := reflection.Register(grpcSrv, reflection.Config{ SigningModes: func() map[string]int32 { - modes := make(map[string]int32, len(clientCtx.TxConfig.SignModeHandler().SupportedModes())) - for _, m := range clientCtx.TxConfig.SignModeHandler().SupportedModes() { + supportedModes := clientCtx.TxConfig.SignModeHandler().SupportedModes() + modes := make(map[string]int32, len(supportedModes)) + for _, m := range supportedModes { modes[m.String()] = (int32)(m) } diff --git a/types/registry/registry.go b/types/registry/registry.go index b24a0da4ee4e..9fe5c8facc9c 100644 --- a/types/registry/registry.go +++ b/types/registry/registry.go @@ -13,41 +13,35 @@ import ( var ( mergedRegistryOnce sync.Once mergedRegistry *protoregistry.Files - mergedRegistryErr error _ signing.ProtoFileResolver = lazyProtoRegistry{} ) // lazyProtoRegistry is a lazy loading wrapper around the global protobuf registry. type lazyProtoRegistry struct{} -func (l lazyProtoRegistry) getRegistry() (*protoregistry.Files, error) { +func getRegistry() *protoregistry.Files { + var err error mergedRegistryOnce.Do(func() { - mergedRegistry, mergedRegistryErr = proto.MergedRegistry() + mergedRegistry, err = proto.MergedRegistry() + if err != nil { + panic(err) + } }) - return mergedRegistry, mergedRegistryErr + return mergedRegistry } func (l lazyProtoRegistry) FindFileByPath(s string) (protoreflect.FileDescriptor, error) { - reg, err := l.getRegistry() - if err != nil { - return nil, err - } + reg := getRegistry() return reg.FindFileByPath(s) } func (l lazyProtoRegistry) FindDescriptorByName(name protoreflect.FullName) (protoreflect.Descriptor, error) { - reg, err := l.getRegistry() - if err != nil { - return nil, err - } + reg := getRegistry() return reg.FindDescriptorByName(name) } func (l lazyProtoRegistry) RangeFiles(f func(protoreflect.FileDescriptor) bool) { - reg, err := l.getRegistry() - if err != nil { - panic(err) - } + reg := getRegistry() reg.RangeFiles(f) } diff --git a/x/auth/ante/feegrant_test.go b/x/auth/ante/feegrant_test.go index 3e9b63c5a426..31cebeaec981 100644 --- a/x/auth/ante/feegrant_test.go +++ b/x/auth/ante/feegrant_test.go @@ -180,7 +180,7 @@ func TestDeductFeesNoDelegation(t *testing.T) { testutil.AssertError(t, err, tc.err, tc.errMsg) } - _, err = anteHandlerStack(bytesCtx, tx, false) // tests while stack + _, err = anteHandlerStack(bytesCtx, tx, false) // tests whole stack if tc.valid { require.NoError(t, err) } else { diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index b2cad64a71ef..1d1e0b2a5a74 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -117,6 +117,11 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) (err error) { txFactory = txFactory.WithAccountNumber(accnum).WithSequence(seq) } + decoder, err := decode.NewDecoder(decode.Options{ProtoFiles: registry.MergedProtoRegistry()}) + if err != nil { + return err + } + // read each signature and add it to the multisig if valid for i := 2; i < len(args); i++ { sigs, err := unmarshalSignatureJSON(clientCtx, args[i]) @@ -147,11 +152,7 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) (err error) { if err != nil { return err } - decodeCtx, err := decode.NewDecoder(decode.Options{ProtoFiles: registry.MergedProtoRegistry()}) - if err != nil { - return err - } - decodedTx, err := decodeCtx.Decode(txBytes) + decodedTx, err := decoder.Decode(txBytes) if err != nil { return err } diff --git a/x/auth/client/cli/validate_sigs.go b/x/auth/client/cli/validate_sigs.go index 93c59f903594..a38283fd2d51 100644 --- a/x/auth/client/cli/validate_sigs.go +++ b/x/auth/client/cli/validate_sigs.go @@ -156,6 +156,7 @@ func printAndValidateSigs( err = authsigning.VerifySignature(cmd.Context(), pubKey, txSignerData, sig.Data, signModeHandler, txData) if err != nil { + cmd.PrintErrf("failed to verify signature: %v", err) return false } } diff --git a/x/auth/tx/config/config.go b/x/auth/tx/config/config.go index 47176cda1e3e..5a3ce85b32f2 100644 --- a/x/auth/tx/config/config.go +++ b/x/auth/tx/config/config.go @@ -69,11 +69,11 @@ func ProvideSignModeOptions(bk BankKeeper) tx.SignModeOptions { func ProvideModule(in ModuleInputs) ModuleOutputs { var txConfig client.TxConfig - if in.CustomSignModeHandlers == nil { - txConfig = tx.NewTxConfigWithOptions(in.ProtoCodecMarshaler, in.SignModeOptions) - } else { - txConfig = tx.NewTxConfigWithOptions(in.ProtoCodecMarshaler, in.SignModeOptions, in.CustomSignModeHandlers()...) + var customSignModeHandlers []txsigning.SignModeHandler + if in.CustomSignModeHandlers != nil { + customSignModeHandlers = in.CustomSignModeHandlers() } + txConfig = tx.NewTxConfigWithOptions(in.ProtoCodecMarshaler, in.SignModeOptions, customSignModeHandlers...) baseAppOption := func(app *baseapp.BaseApp) { // AnteHandlers From cd4f11f6c868c1c7e1b9d6b82886c7ff4dcdd056 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Wed, 19 Apr 2023 11:08:52 -0500 Subject: [PATCH 50/52] lint fix --- baseapp/msg_service_router_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/baseapp/msg_service_router_test.go b/baseapp/msg_service_router_test.go index cbdbdeda9ee2..3d0b637462cd 100644 --- a/baseapp/msg_service_router_test.go +++ b/baseapp/msg_service_router_test.go @@ -1,6 +1,7 @@ package baseapp_test import ( + "context" "testing" abci "github.com/cometbft/cometbft/abci/types" @@ -134,7 +135,7 @@ func TestMsgService(t *testing.T) { PubKey: priv.PubKey(), } sigV2, err = tx.SignWithPrivKey( - nil, defaultSignMode, signerData, + context.TODO(), defaultSignMode, signerData, txBuilder, priv, txConfig, 0) require.NoError(t, err) err = txBuilder.SetSignatures(sigV2) From 2bb6750ccef1d8a14b52970337ee6a284f0df66e Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 20 Apr 2023 10:34:07 -0500 Subject: [PATCH 51/52] Refactor NewTxConfig --- codec/types/interface_registry.go | 23 +++++++++++------------ x/auth/tx/config.go | 5 +---- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/codec/types/interface_registry.go b/codec/types/interface_registry.go index 57a098e0cbe4..f921d7d05489 100644 --- a/codec/types/interface_registry.go +++ b/codec/types/interface_registry.go @@ -8,7 +8,9 @@ import ( "github.com/cosmos/gogoproto/proto" "google.golang.org/protobuf/reflect/protodesc" "google.golang.org/protobuf/reflect/protoreflect" - "google.golang.org/protobuf/reflect/protoregistry" + + "cosmossdk.io/x/tx/signing" + "github.com/cosmos/cosmos-sdk/types/registry" ) // AnyUnpacker is an interface which allows safely unpacking types packed @@ -96,7 +98,7 @@ type UnpackInterfacesMessage interface { } type interfaceRegistry struct { - *protoregistry.Files + signing.ProtoFileResolver interfaceNames map[string]reflect.Type interfaceImpls map[reflect.Type]interfaceMap implInterfaces map[reflect.Type]reflect.Type @@ -107,21 +109,18 @@ type interfaceMap = map[string]reflect.Type // NewInterfaceRegistry returns a new InterfaceRegistry func NewInterfaceRegistry() InterfaceRegistry { - protoFiles, err := proto.MergedRegistry() - if err != nil { - panic(err) - } + protoFiles := registry.MergedProtoRegistry() return NewInterfaceRegistryWithProtoFiles(protoFiles) } // NewInterfaceRegistryWithProtoFiles returns a new InterfaceRegistry with the specified *protoregistry.Files instance. -func NewInterfaceRegistryWithProtoFiles(files *protoregistry.Files) InterfaceRegistry { +func NewInterfaceRegistryWithProtoFiles(files signing.ProtoFileResolver) InterfaceRegistry { return &interfaceRegistry{ - interfaceNames: map[string]reflect.Type{}, - interfaceImpls: map[reflect.Type]interfaceMap{}, - implInterfaces: map[reflect.Type]reflect.Type{}, - typeURLMap: map[string]reflect.Type{}, - Files: files, + interfaceNames: map[string]reflect.Type{}, + interfaceImpls: map[reflect.Type]interfaceMap{}, + implInterfaces: map[reflect.Type]reflect.Type{}, + typeURLMap: map[string]reflect.Type{}, + ProtoFileResolver: files, } } diff --git a/x/auth/tx/config.go b/x/auth/tx/config.go index a83b196e0592..6d89cd41ecd8 100644 --- a/x/auth/tx/config.go +++ b/x/auth/tx/config.go @@ -13,7 +13,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/registry" signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" ) @@ -40,10 +39,8 @@ type config struct { func NewTxConfig(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signingtypes.SignMode, customSignModes ...txsigning.SignModeHandler, ) client.TxConfig { - // protoFiles should perhaps be a parameter to this function, but the choice was made here to not break the - // NewTxConfig API. - protoFiles := registry.MergedProtoRegistry() typeResolver := protoregistry.GlobalTypes + protoFiles := protoCodec.InterfaceRegistry() signersContext, err := txsigning.NewGetSignersContext(txsigning.GetSignersOptions{ProtoFiles: protoFiles}) if err != nil { panic(err) From 3bcaa98acecbbeb030ac0fea2ab2edb90d7f5e58 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 20 Apr 2023 10:41:54 -0500 Subject: [PATCH 52/52] lazy loading won't work in InterfaceRegistry ctr won't work yet. it is being called in init() lifecycle before all proto files are loaded. the result is much wasted work right now. --- codec/types/interface_registry.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/codec/types/interface_registry.go b/codec/types/interface_registry.go index f921d7d05489..57a098e0cbe4 100644 --- a/codec/types/interface_registry.go +++ b/codec/types/interface_registry.go @@ -8,9 +8,7 @@ import ( "github.com/cosmos/gogoproto/proto" "google.golang.org/protobuf/reflect/protodesc" "google.golang.org/protobuf/reflect/protoreflect" - - "cosmossdk.io/x/tx/signing" - "github.com/cosmos/cosmos-sdk/types/registry" + "google.golang.org/protobuf/reflect/protoregistry" ) // AnyUnpacker is an interface which allows safely unpacking types packed @@ -98,7 +96,7 @@ type UnpackInterfacesMessage interface { } type interfaceRegistry struct { - signing.ProtoFileResolver + *protoregistry.Files interfaceNames map[string]reflect.Type interfaceImpls map[reflect.Type]interfaceMap implInterfaces map[reflect.Type]reflect.Type @@ -109,18 +107,21 @@ type interfaceMap = map[string]reflect.Type // NewInterfaceRegistry returns a new InterfaceRegistry func NewInterfaceRegistry() InterfaceRegistry { - protoFiles := registry.MergedProtoRegistry() + protoFiles, err := proto.MergedRegistry() + if err != nil { + panic(err) + } return NewInterfaceRegistryWithProtoFiles(protoFiles) } // NewInterfaceRegistryWithProtoFiles returns a new InterfaceRegistry with the specified *protoregistry.Files instance. -func NewInterfaceRegistryWithProtoFiles(files signing.ProtoFileResolver) InterfaceRegistry { +func NewInterfaceRegistryWithProtoFiles(files *protoregistry.Files) InterfaceRegistry { return &interfaceRegistry{ - interfaceNames: map[string]reflect.Type{}, - interfaceImpls: map[reflect.Type]interfaceMap{}, - implInterfaces: map[reflect.Type]reflect.Type{}, - typeURLMap: map[string]reflect.Type{}, - ProtoFileResolver: files, + interfaceNames: map[string]reflect.Type{}, + interfaceImpls: map[reflect.Type]interfaceMap{}, + implInterfaces: map[reflect.Type]reflect.Type{}, + typeURLMap: map[string]reflect.Type{}, + Files: files, } }