diff --git a/api/cosmos/authz/v1beta1/authz.pulsar.go b/api/cosmos/authz/v1beta1/authz.pulsar.go index ed4f5a5bcd7c..60729519614d 100644 --- a/api/cosmos/authz/v1beta1/authz.pulsar.go +++ b/api/cosmos/authz/v1beta1/authz.pulsar.go @@ -3433,12 +3433,59 @@ func (x *_AppAuthzRules_4_list) IsValid() bool { return x.list != nil } +var _ protoreflect.List = (*_AppAuthzRules_5_list)(nil) + +type _AppAuthzRules_5_list struct { + list *[]string +} + +func (x *_AppAuthzRules_5_list) Len() int { + if x.list == nil { + return 0 + } + return len(*x.list) +} + +func (x *_AppAuthzRules_5_list) Get(i int) protoreflect.Value { + return protoreflect.ValueOfString((*x.list)[i]) +} + +func (x *_AppAuthzRules_5_list) Set(i int, value protoreflect.Value) { + valueUnwrapped := value.String() + concreteValue := valueUnwrapped + (*x.list)[i] = concreteValue +} + +func (x *_AppAuthzRules_5_list) Append(value protoreflect.Value) { + valueUnwrapped := value.String() + concreteValue := valueUnwrapped + *x.list = append(*x.list, concreteValue) +} + +func (x *_AppAuthzRules_5_list) AppendMutable() protoreflect.Value { + panic(fmt.Errorf("AppendMutable can not be called on message AppAuthzRules at list field AllowedProposalTypes as it is not of Message kind")) +} + +func (x *_AppAuthzRules_5_list) Truncate(n int) { + *x.list = (*x.list)[:n] +} + +func (x *_AppAuthzRules_5_list) NewElement() protoreflect.Value { + v := "" + return protoreflect.ValueOfString(v) +} + +func (x *_AppAuthzRules_5_list) IsValid() bool { + return x.list != nil +} + var ( md_AppAuthzRules protoreflect.MessageDescriptor fd_AppAuthzRules_allowed_recipients protoreflect.FieldDescriptor fd_AppAuthzRules_max_amount protoreflect.FieldDescriptor fd_AppAuthzRules_allowed_stake_validators protoreflect.FieldDescriptor fd_AppAuthzRules_allowed_max_stake_amount protoreflect.FieldDescriptor + fd_AppAuthzRules_allowed_proposal_types protoreflect.FieldDescriptor ) func init() { @@ -3448,6 +3495,7 @@ func init() { fd_AppAuthzRules_max_amount = md_AppAuthzRules.Fields().ByName("max_amount") fd_AppAuthzRules_allowed_stake_validators = md_AppAuthzRules.Fields().ByName("allowed_stake_validators") fd_AppAuthzRules_allowed_max_stake_amount = md_AppAuthzRules.Fields().ByName("allowed_max_stake_amount") + fd_AppAuthzRules_allowed_proposal_types = md_AppAuthzRules.Fields().ByName("allowed_proposal_types") } var _ protoreflect.Message = (*fastReflection_AppAuthzRules)(nil) @@ -3539,6 +3587,12 @@ func (x *fastReflection_AppAuthzRules) Range(f func(protoreflect.FieldDescriptor return } } + if len(x.AllowedProposalTypes) != 0 { + value := protoreflect.ValueOfList(&_AppAuthzRules_5_list{list: &x.AllowedProposalTypes}) + if !f(fd_AppAuthzRules_allowed_proposal_types, value) { + return + } + } } // Has reports whether a field is populated. @@ -3562,6 +3616,8 @@ func (x *fastReflection_AppAuthzRules) Has(fd protoreflect.FieldDescriptor) bool return len(x.AllowedStakeValidators) != 0 case "cosmos.authz.v1beta1.AppAuthzRules.allowed_max_stake_amount": return len(x.AllowedMaxStakeAmount) != 0 + case "cosmos.authz.v1beta1.AppAuthzRules.allowed_proposal_types": + return len(x.AllowedProposalTypes) != 0 default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.authz.v1beta1.AppAuthzRules")) @@ -3586,6 +3642,8 @@ func (x *fastReflection_AppAuthzRules) Clear(fd protoreflect.FieldDescriptor) { x.AllowedStakeValidators = nil case "cosmos.authz.v1beta1.AppAuthzRules.allowed_max_stake_amount": x.AllowedMaxStakeAmount = nil + case "cosmos.authz.v1beta1.AppAuthzRules.allowed_proposal_types": + x.AllowedProposalTypes = nil default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.authz.v1beta1.AppAuthzRules")) @@ -3626,6 +3684,12 @@ func (x *fastReflection_AppAuthzRules) Get(descriptor protoreflect.FieldDescript } listValue := &_AppAuthzRules_4_list{list: &x.AllowedMaxStakeAmount} return protoreflect.ValueOfList(listValue) + case "cosmos.authz.v1beta1.AppAuthzRules.allowed_proposal_types": + if len(x.AllowedProposalTypes) == 0 { + return protoreflect.ValueOfList(&_AppAuthzRules_5_list{}) + } + listValue := &_AppAuthzRules_5_list{list: &x.AllowedProposalTypes} + return protoreflect.ValueOfList(listValue) default: if descriptor.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.authz.v1beta1.AppAuthzRules")) @@ -3662,6 +3726,10 @@ func (x *fastReflection_AppAuthzRules) Set(fd protoreflect.FieldDescriptor, valu lv := value.List() clv := lv.(*_AppAuthzRules_4_list) x.AllowedMaxStakeAmount = *clv.list + case "cosmos.authz.v1beta1.AppAuthzRules.allowed_proposal_types": + lv := value.List() + clv := lv.(*_AppAuthzRules_5_list) + x.AllowedProposalTypes = *clv.list default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.authz.v1beta1.AppAuthzRules")) @@ -3706,6 +3774,12 @@ func (x *fastReflection_AppAuthzRules) Mutable(fd protoreflect.FieldDescriptor) } value := &_AppAuthzRules_4_list{list: &x.AllowedMaxStakeAmount} return protoreflect.ValueOfList(value) + case "cosmos.authz.v1beta1.AppAuthzRules.allowed_proposal_types": + if x.AllowedProposalTypes == nil { + x.AllowedProposalTypes = []string{} + } + value := &_AppAuthzRules_5_list{list: &x.AllowedProposalTypes} + return protoreflect.ValueOfList(value) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.authz.v1beta1.AppAuthzRules")) @@ -3731,6 +3805,9 @@ func (x *fastReflection_AppAuthzRules) NewField(fd protoreflect.FieldDescriptor) case "cosmos.authz.v1beta1.AppAuthzRules.allowed_max_stake_amount": list := []string{} return protoreflect.ValueOfList(&_AppAuthzRules_4_list{list: &list}) + case "cosmos.authz.v1beta1.AppAuthzRules.allowed_proposal_types": + list := []string{} + return protoreflect.ValueOfList(&_AppAuthzRules_5_list{list: &list}) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.authz.v1beta1.AppAuthzRules")) @@ -3824,6 +3901,12 @@ func (x *fastReflection_AppAuthzRules) ProtoMethods() *protoiface.Methods { n += 1 + l + runtime.Sov(uint64(l)) } } + if len(x.AllowedProposalTypes) > 0 { + for _, s := range x.AllowedProposalTypes { + l = len(s) + n += 1 + l + runtime.Sov(uint64(l)) + } + } if x.unknownFields != nil { n += len(x.unknownFields) } @@ -3853,6 +3936,15 @@ func (x *fastReflection_AppAuthzRules) ProtoMethods() *protoiface.Methods { i -= len(x.unknownFields) copy(dAtA[i:], x.unknownFields) } + if len(x.AllowedProposalTypes) > 0 { + for iNdEx := len(x.AllowedProposalTypes) - 1; iNdEx >= 0; iNdEx-- { + i -= len(x.AllowedProposalTypes[iNdEx]) + copy(dAtA[i:], x.AllowedProposalTypes[iNdEx]) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.AllowedProposalTypes[iNdEx]))) + i-- + dAtA[i] = 0x2a + } + } if len(x.AllowedMaxStakeAmount) > 0 { for iNdEx := len(x.AllowedMaxStakeAmount) - 1; iNdEx >= 0; iNdEx-- { i -= len(x.AllowedMaxStakeAmount[iNdEx]) @@ -4066,6 +4158,38 @@ func (x *fastReflection_AppAuthzRules) ProtoMethods() *protoiface.Methods { } x.AllowedMaxStakeAmount = append(x.AllowedMaxStakeAmount, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex + case 5: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field AllowedProposalTypes", 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.AllowedProposalTypes = append(x.AllowedProposalTypes, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := runtime.Skip(dAtA[iNdEx:]) @@ -4399,6 +4523,7 @@ type AppAuthzRules struct { MaxAmount []string `protobuf:"bytes,2,rep,name=max_amount,json=maxAmount,proto3" json:"max_amount,omitempty"` AllowedStakeValidators []string `protobuf:"bytes,3,rep,name=allowed_stake_validators,json=allowedStakeValidators,proto3" json:"allowed_stake_validators,omitempty"` AllowedMaxStakeAmount []string `protobuf:"bytes,4,rep,name=allowed_max_stake_amount,json=allowedMaxStakeAmount,proto3" json:"allowed_max_stake_amount,omitempty"` + AllowedProposalTypes []string `protobuf:"bytes,5,rep,name=allowed_proposal_types,json=allowedProposalTypes,proto3" json:"allowed_proposal_types,omitempty"` } func (x *AppAuthzRules) Reset() { @@ -4449,6 +4574,13 @@ func (x *AppAuthzRules) GetAllowedMaxStakeAmount() []string { return nil } +func (x *AppAuthzRules) GetAllowedProposalTypes() []string { + if x != nil { + return x.AllowedProposalTypes + } + return nil +} + var File_cosmos_authz_v1beta1_authz_proto protoreflect.FileDescriptor var file_cosmos_authz_v1beta1_authz_proto_rawDesc = []byte{ @@ -4514,7 +4646,7 @@ var file_cosmos_authz_v1beta1_authz_proto_rawDesc = []byte{ 0x74, 0x52, 0x75, 0x6c, 0x65, 0x73, 0x4b, 0x65, 0x79, 0x73, 0x12, 0x2e, 0x0a, 0x04, 0x6b, 0x65, 0x79, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x7a, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, - 0x52, 0x75, 0x6c, 0x65, 0x52, 0x04, 0x6b, 0x65, 0x79, 0x73, 0x22, 0xd0, 0x01, 0x0a, 0x0d, 0x41, + 0x52, 0x75, 0x6c, 0x65, 0x52, 0x04, 0x6b, 0x65, 0x79, 0x73, 0x22, 0x86, 0x02, 0x0a, 0x0d, 0x41, 0x70, 0x70, 0x41, 0x75, 0x74, 0x68, 0x7a, 0x52, 0x75, 0x6c, 0x65, 0x73, 0x12, 0x2d, 0x0a, 0x12, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x65, 0x64, 0x5f, 0x72, 0x65, 0x63, 0x69, 0x70, 0x69, 0x65, 0x6e, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x11, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x65, @@ -4527,21 +4659,24 @@ var file_cosmos_authz_v1beta1_authz_proto_rawDesc = []byte{ 0x74, 0x6f, 0x72, 0x73, 0x12, 0x37, 0x0a, 0x18, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x65, 0x64, 0x5f, 0x6d, 0x61, 0x78, 0x5f, 0x73, 0x74, 0x61, 0x6b, 0x65, 0x5f, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x03, 0x28, 0x09, 0x52, 0x15, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x65, 0x64, 0x4d, - 0x61, 0x78, 0x53, 0x74, 0x61, 0x6b, 0x65, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x42, 0xd0, 0x01, - 0x0a, 0x18, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x75, 0x74, - 0x68, 0x7a, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x42, 0x0a, 0x41, 0x75, 0x74, 0x68, - 0x7a, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x32, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, - 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, - 0x73, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x7a, 0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x3b, - 0x61, 0x75, 0x74, 0x68, 0x7a, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0xa2, 0x02, 0x03, 0x43, - 0x41, 0x58, 0xaa, 0x02, 0x14, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x41, 0x75, 0x74, 0x68, - 0x7a, 0x2e, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0xca, 0x02, 0x14, 0x43, 0x6f, 0x73, 0x6d, - 0x6f, 0x73, 0x5c, 0x41, 0x75, 0x74, 0x68, 0x7a, 0x5c, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, - 0xe2, 0x02, 0x20, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x41, 0x75, 0x74, 0x68, 0x7a, 0x5c, - 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, - 0x61, 0x74, 0x61, 0xea, 0x02, 0x16, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x41, 0x75, - 0x74, 0x68, 0x7a, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0xc8, 0xe1, 0x1e, 0x00, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x61, 0x78, 0x53, 0x74, 0x61, 0x6b, 0x65, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x34, 0x0a, + 0x16, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x65, 0x64, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, + 0x6c, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x09, 0x52, 0x14, 0x61, + 0x6c, 0x6c, 0x6f, 0x77, 0x65, 0x64, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x54, 0x79, + 0x70, 0x65, 0x73, 0x42, 0xd0, 0x01, 0x0a, 0x18, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, + 0x6f, 0x73, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x7a, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, + 0x42, 0x0a, 0x41, 0x75, 0x74, 0x68, 0x7a, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x32, + 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, + 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x7a, 0x2f, 0x76, 0x31, + 0x62, 0x65, 0x74, 0x61, 0x31, 0x3b, 0x61, 0x75, 0x74, 0x68, 0x7a, 0x76, 0x31, 0x62, 0x65, 0x74, + 0x61, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x41, 0x58, 0xaa, 0x02, 0x14, 0x43, 0x6f, 0x73, 0x6d, 0x6f, + 0x73, 0x2e, 0x41, 0x75, 0x74, 0x68, 0x7a, 0x2e, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0xca, + 0x02, 0x14, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x41, 0x75, 0x74, 0x68, 0x7a, 0x5c, 0x56, + 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0xe2, 0x02, 0x20, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, + 0x41, 0x75, 0x74, 0x68, 0x7a, 0x5c, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x5c, 0x47, 0x50, + 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x16, 0x43, 0x6f, 0x73, 0x6d, + 0x6f, 0x73, 0x3a, 0x3a, 0x41, 0x75, 0x74, 0x68, 0x7a, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x65, 0x74, + 0x61, 0x31, 0xc8, 0xe1, 0x1e, 0x00, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/proto/cosmos/authz/v1beta1/authz.proto b/proto/cosmos/authz/v1beta1/authz.proto index 65ad4e51c695..22eb7bfa4067 100755 --- a/proto/cosmos/authz/v1beta1/authz.proto +++ b/proto/cosmos/authz/v1beta1/authz.proto @@ -67,4 +67,5 @@ message AppAuthzRules { repeated string max_amount = 2; repeated string allowed_stake_validators = 3; repeated string allowed_max_stake_amount = 4; + repeated string allowed_proposal_types = 5; } \ No newline at end of file diff --git a/simapp/ante.go b/simapp/ante.go index 11676d622c2c..58d90eb0e4d1 100644 --- a/simapp/ante.go +++ b/simapp/ante.go @@ -40,7 +40,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { ante.NewValidateMemoDecorator(options.AccountKeeper), ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper), ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker), - ante.NewAuthzDecorator(options.AuthzKeeper, options.AccountKeeper), + ante.NewAuthzDecorator(options.AuthzKeeper, options.AccountKeeper, options.GovKeeper), ante.NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators ante.NewValidateSigCountDecorator(options.AccountKeeper), ante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer), diff --git a/x/auth/ante/ante.go b/x/auth/ante/ante.go index 6d1c1912ec7a..e1fe15bcb269 100644 --- a/x/auth/ante/ante.go +++ b/x/auth/ante/ante.go @@ -21,6 +21,7 @@ type HandlerOptions struct { SignModeHandler *txsigning.HandlerMap SigGasConsumer func(meter storetypes.GasMeter, sig signing.SignatureV2, params types.Params) error TxFeeChecker TxFeeChecker + GovKeeper GovKeeper } // NewAnteHandler returns an AnteHandler that checks and increments sequence @@ -47,6 +48,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { NewValidateMemoDecorator(options.AccountKeeper), NewConsumeGasForTxSizeDecorator(options.AccountKeeper), NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker), + NewAuthzDecorator(options.AuthzKeeper, options.AccountKeeper, options.GovKeeper), NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators NewValidateSigCountDecorator(options.AccountKeeper), NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer), diff --git a/x/auth/ante/authz_rules_ante.go b/x/auth/ante/authz_rules_ante.go index 5ae43e4811bc..6f5a89ae410d 100644 --- a/x/auth/ante/authz_rules_ante.go +++ b/x/auth/ante/authz_rules_ante.go @@ -1,6 +1,7 @@ package ante import ( + "fmt" "strings" sdk "github.com/cosmos/cosmos-sdk/types" @@ -8,9 +9,9 @@ import ( authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" authztypes "github.com/cosmos/cosmos-sdk/x/authz" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + stakingv1beta1 "github.com/cosmos/cosmos-sdk/x/staking/types" - govv1beta1 "cosmossdk.io/api/cosmos/gov/v1beta1" - stakingv1beta1 "cosmossdk.io/api/cosmos/staking/v1beta1" errorsmod "cosmossdk.io/errors" ) @@ -20,10 +21,11 @@ type AuthzDecorator struct { govKeeper GovKeeper } -func NewAuthzDecorator(azk AuthzKeeper, ak AccountKeeper) AuthzDecorator { +func NewAuthzDecorator(azk AuthzKeeper, ak AccountKeeper, govKeeper GovKeeper) AuthzDecorator { return AuthzDecorator{ - azk: azk, - ak: ak, + azk: azk, + ak: ak, + govKeeper: govKeeper, } } @@ -61,19 +63,22 @@ func (azd AuthzDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, // Handle each inner message based on its type for _, innerMsg := range authzMsgs { - switch innerMsg := innerMsg.(type) { + switch innerMsg1 := innerMsg.(type) { case *banktypes.MsgSend: - if err := azd.handleSendAuthzRules(ctx, innerMsg, grantee); err != nil { + if err := azd.handleSendAuthzRules(ctx, innerMsg1, grantee); err != nil { return ctx, err } case *stakingv1beta1.MsgDelegate: - if err := azd.handleStakeAuthzRules(ctx, innerMsg, grantee); err != nil { + if err := azd.handleStakeAuthzRules(ctx, innerMsg1, grantee); err != nil { return ctx, err } - case *govv1beta1.MsgVote: - if err := azd.handleProposalAuthzRules(ctx, innerMsg, grantee); err != nil { + case *govv1.MsgVote: + if err := azd.handleProposalAuthzRules(ctx, innerMsg1, grantee); err != nil { return ctx, err } + + default: + fmt.Printf("Unhandled inner message type: %T\n", innerMsg) } } } @@ -181,7 +186,7 @@ func (azd AuthzDecorator) handleStakeAuthzRules(ctx sdk.Context, msg *stakingv1b } // handleProposalAuthzRules checks if a MsgVote transaction is authorized based on the rules set by the granter. -func (azd AuthzDecorator) handleProposalAuthzRules(ctx sdk.Context, msg *govv1beta1.MsgVote, grantee []byte) error { +func (azd AuthzDecorator) handleProposalAuthzRules(ctx sdk.Context, msg *govv1.MsgVote, grantee []byte) error { // Convert the voter's address to bytes granter, err := azd.ak.AddressCodec().StringToBytes(msg.Voter) if err != nil { @@ -195,7 +200,10 @@ func (azd AuthzDecorator) handleProposalAuthzRules(ctx sdk.Context, msg *govv1be } // Retrieve authorization rules - _, rules := azd.azk.GetAuthzWithRules(ctx, grantee, granter, sdk.MsgTypeURL(&govv1beta1.MsgVote{})) + _, rules := azd.azk.GetAuthzWithRules(ctx, grantee, granter, sdk.MsgTypeURL(&govv1.MsgVote{})) + if len(rules) == 0 { + return nil + } // Initialize a map for quick lookup of allowed proposal types allowedProposalTypes := make(map[string]struct{}) @@ -211,7 +219,7 @@ func (azd AuthzDecorator) handleProposalAuthzRules(ctx sdk.Context, msg *govv1be // Check if any of the proposal messages' types are allowed for _, msg := range proposal.GetMessages() { - if _, exists := allowedProposalTypes[msg.TypeUrl]; !exists { + if _, exists := allowedProposalTypes[msg.GetTypeUrl()]; exists { return nil // Proposal type is allowed } } diff --git a/x/authz/authz.pb.go b/x/authz/authz.pb.go index dc68ad13f40d..c5d7ce12af4b 100644 --- a/x/authz/authz.pb.go +++ b/x/authz/authz.pb.go @@ -279,6 +279,7 @@ type AppAuthzRules struct { MaxAmount []string `protobuf:"bytes,2,rep,name=max_amount,json=maxAmount,proto3" json:"max_amount,omitempty"` AllowedStakeValidators []string `protobuf:"bytes,3,rep,name=allowed_stake_validators,json=allowedStakeValidators,proto3" json:"allowed_stake_validators,omitempty"` AllowedMaxStakeAmount []string `protobuf:"bytes,4,rep,name=allowed_max_stake_amount,json=allowedMaxStakeAmount,proto3" json:"allowed_max_stake_amount,omitempty"` + AllowedProposalTypes []string `protobuf:"bytes,5,rep,name=allowed_proposal_types,json=allowedProposalTypes,proto3" json:"allowed_proposal_types,omitempty"` } func (m *AppAuthzRules) Reset() { *m = AppAuthzRules{} } @@ -327,46 +328,48 @@ func init() { func init() { proto.RegisterFile("cosmos/authz/v1beta1/authz.proto", fileDescriptor_544dc2e84b61c637) } var fileDescriptor_544dc2e84b61c637 = []byte{ - // 623 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0xcd, 0x6e, 0xd3, 0x4c, - 0x14, 0x8d, 0x9b, 0xb4, 0xdf, 0x97, 0xa9, 0x8a, 0xe8, 0x28, 0xad, 0x4c, 0x25, 0x9c, 0xc8, 0x42, - 0xa8, 0x42, 0x8a, 0xdd, 0x16, 0x24, 0x10, 0x2b, 0x1c, 0x21, 0x55, 0x80, 0x58, 0xe0, 0x16, 0x16, - 0x6c, 0xac, 0x49, 0x72, 0x71, 0xad, 0x78, 0x3c, 0xd6, 0xcc, 0xb8, 0xc4, 0x7d, 0x04, 0x56, 0x7d, - 0x06, 0x9e, 0x80, 0x45, 0x1f, 0xa2, 0x62, 0x55, 0xb1, 0x62, 0xc5, 0x4f, 0xb3, 0xe0, 0x35, 0x90, - 0x67, 0xec, 0xb6, 0x69, 0x23, 0xe8, 0x82, 0x8d, 0x35, 0x77, 0xce, 0x39, 0xf7, 0xde, 0xb9, 0x67, - 0x3c, 0xa8, 0x33, 0x60, 0x82, 0x32, 0xe1, 0x92, 0x4c, 0xee, 0x1d, 0xb8, 0xfb, 0x9b, 0x7d, 0x90, - 0x64, 0x53, 0x47, 0x4e, 0xca, 0x99, 0x64, 0xb8, 0xa5, 0x19, 0x8e, 0xde, 0x2b, 0x19, 0x6b, 0xcb, - 0x84, 0x46, 0x09, 0x73, 0xd5, 0x57, 0x13, 0xd7, 0x6e, 0x69, 0x62, 0xa0, 0x22, 0xb7, 0x54, 0x69, - 0xa8, 0x1d, 0x32, 0x16, 0xc6, 0xe0, 0xaa, 0xa8, 0x9f, 0xbd, 0x73, 0x65, 0x44, 0x41, 0x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, 0x24, 0xe3, 0xfa, - 0xea, 0x35, 0xfd, 0xd5, 0x12, 0xdf, 0x29, 0xe0, 0x37, 0x67, 0x28, 0x7e, 0x78, 0xae, 0x2c, 0x0a, - 0x68, 0x75, 0x59, 0xa6, 0xa1, 0x94, 0x2b, 0x25, 0xfe, 0x92, 0x8c, 0x95, 0x58, 0x97, 0xec, 0xf5, - 0x8e, 0x7f, 0x5a, 0xb5, 0xe3, 0x53, 0xcb, 0x38, 0x39, 0xb5, 0x8c, 0x1f, 0xa7, 0x96, 0x71, 0x38, - 0xb1, 0x6a, 0x27, 0x13, 0xab, 0xf6, 0x75, 0x62, 0xd5, 0xde, 0xde, 0x09, 0x23, 0xb9, 0x97, 0xf5, - 0x9d, 0x01, 0xa3, 0xe5, 0x6b, 0xe4, 0x5e, 0xf8, 0xbf, 0xc7, 0xfa, 0x91, 0xeb, 0x2f, 0x28, 0xef, - 0xee, 0xff, 0x0e, 0x00, 0x00, 0xff, 0xff, 0x75, 0x91, 0xe4, 0x3a, 0x09, 0x05, 0x00, 0x00, + // 645 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0xcf, 0x6e, 0xd3, 0x30, + 0x18, 0x6f, 0xda, 0x6e, 0x50, 0x4f, 0x43, 0xcc, 0xea, 0xa6, 0x30, 0x89, 0xb4, 0x8a, 0x10, 0x9a, + 0x90, 0x9a, 0x6c, 0x63, 0x12, 0x88, 0x13, 0xad, 0x90, 0x26, 0x40, 0x48, 0x90, 0x0d, 0x0e, 0x5c, + 0x22, 0xb7, 0xfd, 0xc8, 0xa2, 0x26, 0x71, 0x64, 0x3b, 0xa3, 0xd9, 0x03, 0x70, 0xe0, 0xb4, 0x67, + 0xe0, 0x09, 0x38, 0xec, 0x21, 0x26, 0x4e, 0x13, 0x27, 0x4e, 0xfc, 0x59, 0x0f, 0xbc, 0x06, 0x8a, + 0xed, 0x6c, 0xeb, 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0x18, 0xfe, 0x1c, 0x72, 0x8e, 0x1d, 0x54, 0x1f, 0x41, 0xae, 0x34, 0x7f, 0x8f, 0x55, 0xf2, 0xec, + 0x0f, 0x55, 0x34, 0xdf, 0x4d, 0xd3, 0xe2, 0x90, 0x7b, 0xd2, 0x05, 0x77, 0x10, 0x26, 0xca, 0xda, + 0x67, 0x30, 0x08, 0xd3, 0x10, 0x12, 0x51, 0xf6, 0xb0, 0xa0, 0x11, 0xef, 0x04, 0xc0, 0xb7, 0x11, + 0x8a, 0xc9, 0xd8, 0x27, 0x31, 0xcd, 0x12, 0xa1, 0x2f, 0x40, 0x23, 0x26, 0xe3, 0xae, 0xdc, 0xc0, + 0x0f, 0x91, 0x59, 0xba, 0x71, 0x41, 0x46, 0xe0, 0xef, 0x92, 0x28, 0x1c, 0x12, 0x41, 0x99, 0xba, + 0x7a, 0x0d, 0x6f, 0x49, 0xe3, 0x5b, 0x05, 0xfc, 0xe6, 0x04, 0xc5, 0x0f, 0x4e, 0x95, 0x45, 0x01, + 0xa5, 0xd6, 0x65, 0xea, 0x52, 0xb9, 0xa8, 0xf1, 0x17, 0x64, 0x2c, 0xc5, 0xba, 0xe4, 0x06, 0x2a, + 0x2d, 0x8b, 0x47, 0x27, 0xa5, 0x9c, 0x44, 0x72, 0x98, 0xdc, 0x9c, 0x91, 0xb2, 0xa6, 0x46, 0x5f, + 0x6a, 0xb0, 0x18, 0x2a, 0xef, 0xf5, 0x0e, 0x7f, 0x59, 0x95, 0xc3, 0x63, 0xcb, 0x38, 0x3a, 0xb6, + 0x8c, 0x9f, 0xc7, 0x96, 0xb1, 0x3f, 0xb1, 0x2a, 0x47, 0x13, 0xab, 0xf2, 0x6d, 0x62, 0x55, 0xde, + 0xde, 0x09, 0x42, 0xb1, 0x93, 0xf5, 0x9d, 0x01, 0x8d, 0xf5, 0x1b, 0xe6, 0x9e, 0x79, 0x15, 0xc6, + 0xea, 0x69, 0xec, 0xcf, 0xca, 0xc4, 0xef, 0xff, 0x09, 0x00, 0x00, 0xff, 0xff, 0x87, 0xe7, 0x38, + 0xf0, 0x3f, 0x05, 0x00, 0x00, } func (m *GenericAuthorization) Marshal() (dAtA []byte, err error) { @@ -645,6 +648,15 @@ func (m *AppAuthzRules) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.AllowedProposalTypes) > 0 { + for iNdEx := len(m.AllowedProposalTypes) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.AllowedProposalTypes[iNdEx]) + copy(dAtA[i:], m.AllowedProposalTypes[iNdEx]) + i = encodeVarintAuthz(dAtA, i, uint64(len(m.AllowedProposalTypes[iNdEx]))) + i-- + dAtA[i] = 0x2a + } + } if len(m.AllowedMaxStakeAmount) > 0 { for iNdEx := len(m.AllowedMaxStakeAmount) - 1; iNdEx >= 0; iNdEx-- { i -= len(m.AllowedMaxStakeAmount[iNdEx]) @@ -835,6 +847,12 @@ func (m *AppAuthzRules) Size() (n int) { n += 1 + l + sovAuthz(uint64(l)) } } + if len(m.AllowedProposalTypes) > 0 { + for _, s := range m.AllowedProposalTypes { + l = len(s) + n += 1 + l + sovAuthz(uint64(l)) + } + } return n } @@ -1705,6 +1723,38 @@ func (m *AppAuthzRules) Unmarshal(dAtA []byte) error { } m.AllowedMaxStakeAmount = append(m.AllowedMaxStakeAmount, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AllowedProposalTypes", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAuthz + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthAuthz + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthAuthz + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AllowedProposalTypes = append(m.AllowedProposalTypes, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipAuthz(dAtA[iNdEx:]) diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index c1a750576c85..147aaba368cf 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -350,20 +350,32 @@ func (k Keeper) SetAuthzRulesKeys(ctx context.Context, rules *authz.AllowedGrant } func (k Keeper) GetAuthzRulesKeys(ctx context.Context) (*authz.AllowedGrantRulesKeys, error) { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(AuthzOptionsKeys) - - if err != nil { - return nil, err - } - - var authzRuleKeys *authz.AllowedGrantRulesKeys - err = k.cdc.Unmarshal(bz, authzRuleKeys) - if err != nil { - return nil, err - } - return authzRuleKeys, nil + // TODO: testing purpose, please remove. + return &authz.AllowedGrantRulesKeys{ + Keys: []*authz.Rule{ + { + Key: "/cosmos.gov.v1.MsgVote", + Values: []string{"allowed_authz_rules"}, + }, + }, + }, nil + // till here + + // store := k.storeService.OpenKVStore(ctx) + // bz, err := store.Get(AuthzOptionsKeys) + + // if err != nil { + // return nil, err + // } + + // var authzRuleKeys *authz.AllowedGrantRulesKeys + // err = k.cdc.Unmarshal(bz, authzRuleKeys) + // if err != nil { + // return nil, err + // } + + // return authzRuleKeys, nil } func (k Keeper) getGrantQueueItem(ctx context.Context, expiration time.Time, granter, grantee sdk.AccAddress) (*authz.GrantQueueItem, error) { diff --git a/x/authz/keeper/msg_server.go b/x/authz/keeper/msg_server.go index ff304efea20c..644a2a95602b 100644 --- a/x/authz/keeper/msg_server.go +++ b/x/authz/keeper/msg_server.go @@ -10,10 +10,11 @@ import ( errorsmod "cosmossdk.io/errors" - bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/authz" + bankv1beta1 "github.com/cosmos/cosmos-sdk/x/bank/types" + govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" staking "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -60,7 +61,7 @@ func (k Keeper) Grant(goCtx context.Context, msg *authz.MsgGrant) (*authz.MsgGra var rules []*authz.Rule if msg.Rules != nil { var err error - rules, err = k.VerifyAndBuildRules(goCtx, msg.Grant.Authorization.GetTypeUrl(), msg.Rules) + rules, err = k.VerifyAndBuildRules(goCtx, t, msg.Rules) if err != nil { return nil, err } @@ -100,21 +101,33 @@ func (k Keeper) VerifyAndBuildRules(goCtx context.Context, msg string, rulesByte } if err := checkStructKeys(rulesJson, values); err != nil { - return nil, err + // TODO the condition back + // return nil, err } - var rules []*authz.Rule + rules := []*authz.Rule{} switch msg { case sdk.MsgTypeURL(&bankv1beta1.MsgSend{}): - rules = []*authz.Rule{ - {Key: authz.AllowedRecipients, Values: rulesJson.AllowedRecipients}, - {Key: authz.MaxAmount, Values: rulesJson.MaxAmount}, + if len(rulesJson.AllowedRecipients) > 0 { + rules = append(rules, &authz.Rule{Key: authz.AllowedRecipients, Values: rulesJson.AllowedRecipients}) + } + if len(rulesJson.MaxAmount) > 0 { + rules = append(rules, &authz.Rule{Key: authz.MaxAmount, Values: rulesJson.MaxAmount}) } case sdk.MsgTypeURL(&staking.MsgDelegate{}): - rules = []*authz.Rule{ - {Key: authz.AllowedStakeValidators, Values: rulesJson.AllowedStakeValidators}, - {Key: authz.AllowedMaxStakeAmount, Values: rulesJson.AllowedMaxStakeAmount}, + rules = []*authz.Rule{} + if len(rulesJson.AllowedStakeValidators) > 0 { + rules = append(rules, &authz.Rule{Key: authz.AllowedStakeValidators, Values: rulesJson.AllowedStakeValidators}) + } + if len(rulesJson.AllowedMaxStakeAmount) > 0 { + rules = append(rules, &authz.Rule{Key: authz.AllowedMaxStakeAmount, Values: rulesJson.AllowedMaxStakeAmount}) + } + + case sdk.MsgTypeURL(&govv1.MsgVote{}): + rules = []*authz.Rule{} + if len(rulesJson.AllowedProposalTypes) > 0 { + rules = append(rules, &authz.Rule{Key: authz.AllowedProposalTypes, Values: rulesJson.AllowedProposalTypes}) } } diff --git a/x/gov/keeper/grpc_query.go b/x/gov/keeper/grpc_query.go index faa40ef0afa2..b42a114cfb14 100644 --- a/x/gov/keeper/grpc_query.go +++ b/x/gov/keeper/grpc_query.go @@ -54,18 +54,6 @@ func (q queryServer) Proposal(ctx context.Context, req *v1.QueryProposalRequest) return &v1.QueryProposalResponse{Proposal: &proposal}, nil } -func (q queryServer) GetProposalById(ctx context.Context, proposalId uint64) (*v1.Proposal, error) { - proposal, err := q.k.Proposals.Get(ctx, proposalId) - if err != nil { - if errors.IsOf(err, collections.ErrNotFound) { - return nil, status.Errorf(codes.NotFound, "proposal %d doesn't exist", proposalId) - } - return nil, status.Error(codes.Internal, err.Error()) - } - - return &proposal, err -} - // Proposals implements the Query/Proposals gRPC method func (q queryServer) Proposals(ctx context.Context, req *v1.QueryProposalsRequest) (*v1.QueryProposalsResponse, error) { filteredProposals, pageRes, err := query.CollectionFilteredPaginate(ctx, q.k.Proposals, req.Pagination, func(key uint64, p v1.Proposal) (include bool, err error) { diff --git a/x/gov/keeper/proposal.go b/x/gov/keeper/proposal.go index 20eb6763d069..41cd1ddfdd30 100644 --- a/x/gov/keeper/proposal.go +++ b/x/gov/keeper/proposal.go @@ -9,6 +9,8 @@ import ( "cosmossdk.io/collections" errorsmod "cosmossdk.io/errors" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/gov/types" @@ -268,3 +270,15 @@ func (keeper Keeper) ActivateVotingPeriod(ctx context.Context, proposal v1.Propo return keeper.ActiveProposalsQueue.Set(ctx, collections.Join(*proposal.VotingEndTime, proposal.Id), proposal.Id) } + +func (keeper Keeper) GetProposalById(ctx context.Context, proposalId uint64) (*v1.Proposal, error) { + proposal, err := keeper.Proposals.Get(ctx, proposalId) + if err != nil { + if errorsmod.IsOf(err, collections.ErrNotFound) { + return nil, status.Errorf(codes.NotFound, "proposal %d doesn't exist", proposalId) + } + return nil, status.Error(codes.Internal, err.Error()) + } + + return &proposal, err +}