diff --git a/server/grpc/gogoreflection/fix_registration.go b/server/grpc/gogoreflection/fix_registration.go index 5704f054ff61..fadcdbd20059 100644 --- a/server/grpc/gogoreflection/fix_registration.go +++ b/server/grpc/gogoreflection/fix_registration.go @@ -3,10 +3,12 @@ package gogoreflection import ( "reflect" - _ "github.com/cosmos/cosmos-proto" // look above - _ "github.com/cosmos/gogoproto/gogoproto" // required so it does register the gogoproto file descriptor - gogoproto "github.com/cosmos/gogoproto/proto" - "github.com/golang/protobuf/proto" //nolint:staticcheck // migrate in a future pr + _ "github.com/gogo/protobuf/gogoproto" // required so it does register the gogoproto file descriptor + gogoproto "github.com/gogo/protobuf/proto" + + "github.com/golang/protobuf/proto" + dpb "github.com/golang/protobuf/protoc-gen-go/descriptor" + _ "github.com/regen-network/cosmos-proto" // look above ) func getFileDescriptor(filePath string) []byte { @@ -17,7 +19,7 @@ func getFileDescriptor(filePath string) []byte { return fd } - return proto.FileDescriptor(filePath) //nolint:staticcheck // keep for backward compatibility + return proto.FileDescriptor(filePath) } func getMessageType(name string) reflect.Type { @@ -26,7 +28,7 @@ func getMessageType(name string) reflect.Type { return typ } - return proto.MessageType(name) //nolint:staticcheck // keep for backward compatibility + return proto.MessageType(name) } func getExtension(extID int32, m proto.Message) *gogoproto.ExtensionDesc { @@ -38,7 +40,8 @@ func getExtension(extID int32, m proto.Message) *gogoproto.ExtensionDesc { } // check into proto registry - for id, desc := range proto.RegisteredExtensions(m) { //nolint:staticcheck // keep for backward compatibility + + for id, desc := range proto.RegisteredExtensions(m) { if id == extID { return &gogoproto.ExtensionDesc{ ExtendedType: desc.ExtendedType, @@ -65,7 +68,7 @@ func getExtensionsNumbers(m proto.Message) []int32 { return out } - protoExts := proto.RegisteredExtensions(m) //nolint:staticcheck // kept for backwards compatibility + protoExts := proto.RegisteredExtensions(m) out = make([]int32, 0, len(protoExts)) for id := range protoExts { out = append(out, id) diff --git a/server/grpc/gogoreflection/serverreflection.go b/server/grpc/gogoreflection/serverreflection.go index 11213a19d82f..e209d6fde6da 100644 --- a/server/grpc/gogoreflection/serverreflection.go +++ b/server/grpc/gogoreflection/serverreflection.go @@ -42,7 +42,6 @@ import ( "sort" "sync" - //nolint: staticcheck // keep this import for backward compatibility "github.com/golang/protobuf/proto" dpb "github.com/golang/protobuf/protoc-gen-go/descriptor" "google.golang.org/grpc" diff --git a/x/auth/tx/decoder.go b/x/auth/tx/decoder.go index 05821f29bf23..236bfac0938c 100644 --- a/x/auth/tx/decoder.go +++ b/x/auth/tx/decoder.go @@ -15,7 +15,7 @@ import ( func DefaultJSONTxDecoder(addrCodec address.Codec, cdc codec.Codec, decoder *decode.Decoder) sdk.TxDecoder { return func(txBytes []byte) (sdk.Tx, error) { // Make sure txBytes follow ADR-027. - err := rejectNonADR027(txBytes) + err := rejectNonADR027TxRaw(txBytes) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrTxDecode, err.Error()) } @@ -56,13 +56,14 @@ func DefaultJSONTxDecoder(addrCodec address.Codec, cdc codec.Codec, decoder *dec } } -// rejectNonADR027 rejects txBytes that do not follow ADR-027. This function +// rejectNonADR027TxRaw rejects txBytes that do not follow ADR-027. This is NOT +// a generic ADR-027 checker, it only applies decoding TxRaw. Specifically, it // only checks that: // - field numbers are in ascending order (1, 2, and potentially multiple 3s), -// - and varints as as short as possible. -// All other ADR-027 edge cases (e.g. TxRaw fields having default values) will -// not happen with TxRaw. -func rejectNonADR027(txBytes []byte) error { +// - and varints are as short as possible. +// All other ADR-027 edge cases (e.g. default values) are not applicable with +// TxRaw. +func rejectNonADR027TxRaw(txBytes []byte) error { // Make sure all fields are ordered in ascending order with this variable. prevTagNum := protowire.Number(0) @@ -71,21 +72,25 @@ func rejectNonADR027(txBytes []byte) error { if m < 0 { return fmt.Errorf("invalid length; %w", protowire.ParseError(m)) } + // TxRaw only has bytes fields. if wireType != protowire.BytesType { - return fmt.Errorf("expected %d wire type, got %d", protowire.VarintType, wireType) + return fmt.Errorf("expected %d wire type, got %d", protowire.BytesType, wireType) } + // Make sure fields are ordered in ascending order. if tagNum < prevTagNum { return fmt.Errorf("txRaw must follow ADR-027, got tagNum %d after tagNum %d", tagNum, prevTagNum) } prevTagNum = tagNum // All 3 fields of TxRaw have wireType == 2, so their next component - // is a varint. - // We make sure that the varint is as short as possible. + // is a varint, so we can safely call ConsumeVarint here. + // Byte structure: + // Inner fields are verified in `DefaultTxDecoder` lengthPrefix, m := protowire.ConsumeVarint(txBytes[m:]) if m < 0 { return fmt.Errorf("invalid length; %w", protowire.ParseError(m)) } + // We make sure that this varint is as short as possible. n := varintMinLength(lengthPrefix) if n != m { return fmt.Errorf("length prefix varint for tagNum %d is not as short as possible, read %d, only need %d", tagNum, m, n) @@ -107,23 +112,23 @@ func rejectNonADR027(txBytes []byte) error { func varintMinLength(n uint64) int { switch { // Note: 1<