From 0034dc38af4867f90408afb60cd576b6bc966f4c Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Mon, 9 Jan 2023 12:37:31 +0100 Subject: [PATCH 1/7] moving authz protos to transfer.v1 --- go.mod | 2 +- modules/apps/transfer/types/authz.pb.go | 72 +++++++++---------- .../transfer/types/transfer_authz_test.go | 10 +-- .../transfer/{v2 => v1}/authz.proto | 2 +- 4 files changed, 43 insertions(+), 43 deletions(-) rename proto/ibc/applications/transfer/{v2 => v1}/authz.proto (96%) diff --git a/go.mod b/go.mod index caf7821c07e..94a97dc4cba 100644 --- a/go.mod +++ b/go.mod @@ -19,6 +19,7 @@ require ( github.com/stretchr/testify v1.8.1 github.com/tendermint/tendermint v0.34.23 github.com/tendermint/tm-db v0.6.7 + golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e google.golang.org/genproto v0.0.0-20221024183307-1bc688fe9f3e google.golang.org/grpc v1.51.0 google.golang.org/protobuf v1.28.2-0.20220831092852-f930b1dc76e8 @@ -140,7 +141,6 @@ require ( go.etcd.io/bbolt v1.3.6 // indirect go.opencensus.io v0.23.0 // indirect golang.org/x/crypto v0.2.0 // indirect - golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect golang.org/x/net v0.2.0 // indirect golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 // indirect golang.org/x/sys v0.2.0 // indirect diff --git a/modules/apps/transfer/types/authz.pb.go b/modules/apps/transfer/types/authz.pb.go index db9a9e3dbc3..403bd32352d 100644 --- a/modules/apps/transfer/types/authz.pb.go +++ b/modules/apps/transfer/types/authz.pb.go @@ -1,15 +1,15 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: ibc/applications/transfer/v2/authz.proto +// source: ibc/applications/transfer/v1/authz.proto package types import ( fmt "fmt" + _ "github.com/cosmos/cosmos-proto" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" types "github.com/cosmos/cosmos-sdk/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" - _ "github.com/regen-network/cosmos-proto" io "io" math "math" math_bits "math/bits" @@ -41,7 +41,7 @@ func (m *PortChannelAmount) Reset() { *m = PortChannelAmount{} } func (m *PortChannelAmount) String() string { return proto.CompactTextString(m) } func (*PortChannelAmount) ProtoMessage() {} func (*PortChannelAmount) Descriptor() ([]byte, []int) { - return fileDescriptor_c4c17169771443ae, []int{0} + return fileDescriptor_b1a28b55d17325aa, []int{0} } func (m *PortChannelAmount) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -109,7 +109,7 @@ func (m *TransferAuthorization) Reset() { *m = TransferAuthorization{} } func (m *TransferAuthorization) String() string { return proto.CompactTextString(m) } func (*TransferAuthorization) ProtoMessage() {} func (*TransferAuthorization) Descriptor() ([]byte, []int) { - return fileDescriptor_c4c17169771443ae, []int{1} + return fileDescriptor_b1a28b55d17325aa, []int{1} } func (m *TransferAuthorization) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -146,44 +146,44 @@ func (m *TransferAuthorization) GetAllocations() []PortChannelAmount { } func init() { - proto.RegisterType((*PortChannelAmount)(nil), "ibc.applications.transfer.v2.PortChannelAmount") - proto.RegisterType((*TransferAuthorization)(nil), "ibc.applications.transfer.v2.TransferAuthorization") + proto.RegisterType((*PortChannelAmount)(nil), "ibc.applications.transfer.v1.PortChannelAmount") + proto.RegisterType((*TransferAuthorization)(nil), "ibc.applications.transfer.v1.TransferAuthorization") } func init() { - proto.RegisterFile("ibc/applications/transfer/v2/authz.proto", fileDescriptor_c4c17169771443ae) + proto.RegisterFile("ibc/applications/transfer/v1/authz.proto", fileDescriptor_b1a28b55d17325aa) } -var fileDescriptor_c4c17169771443ae = []byte{ +var fileDescriptor_b1a28b55d17325aa = []byte{ // 442 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08,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d, 0xa5, - 0xb3, 0xfe, 0xef, 0x5f, 0xe3, 0xc3, 0x3b, 0x77, 0xcd, 0xde, 0x5f, 0x6d, 0xe2, 0xe0, 0x7a, 0x13, - 0x07, 0xff, 0x36, 0x71, 0xf0, 0x7d, 0x1b, 0x77, 0xae, 0xb7, 0x71, 0xe7, 0xcf, 0x36, 0xee, 0x7c, - 0x3a, 0xbd, 0x6f, 0x81, 0xc8, 0xd9, 0x78, 0x01, 0x64, 0xf5, 0x9a, 0x54, 0x50, 0x34, 0x25, 0xd7, - 0xed, 0x12, 0xee, 0x2c, 0x9f, 0xf5, 0x25, 0x7f, 0x64, 0x77, 0xe1, 0xd5, 0xff, 0x00, 0x00, 0x00, - 0xff, 0xff, 0x1b, 0x30, 0xdf, 0x96, 0xa6, 0x02, 0x00, 0x00, + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x52, 0xc1, 0x8a, 0x13, 0x31, + 0x18, 0xee, 0x6c, 0x17, 0x61, 0x53, 0x56, 0xec, 0xe0, 0xca, 0x74, 0x91, 0x69, 0x99, 0xd3, 0x80, + 0x34, 0xb1, 0x0a, 0x2e, 0xec, 0xc9, 0x76, 0xaf, 0x1e, 0x74, 0x10, 0x04, 0x2f, 0x25, 0x93, 0x89, + 0x6d, 0x70, 0x26, 0xff, 0x90, 0x64, 0x2a, 0xbb, 0x57, 0x5f, 0xc0, 0xd7, 0xd0, 0xb3, 0x0f, 0xb1, + 0x78, 0xda, 0xa3, 0xa7, 0x2a, 0xed, 0x1b, 0xec, 0x13, 0xc8, 0x24, 0x59, 0xe8, 0x52, 0xf0, 0x34, + 0x93, 0xff, 0xfb, 0xfe, 0x2f, 0xf9, 0xbf, 0xef, 0x47, 0xa9, 0xc8, 0x19, 0xa1, 0x75, 0x5d, 0x0a, + 0x46, 0x8d, 0x00, 0xa9, 0x89, 0x51, 0x54, 0xea, 0x4f, 0x5c, 0x91, 0xd5, 0x84, 0xd0,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 0x73, 0x6d, 0x1b, 0x74, 0x86, 0xac, 0xfe, 0x9b, 0x56, 0x3e, 0x7c, + 0x86, 0xfa, 0xb4, 0x2c, 0xe1, 0x0b, 0x2f, 0xe6, 0xb4, 0x28, 0x14, 0xd7, 0x9a, 0xeb, 0xe8, 0x70, + 0xd4, 0x4d, 0x8f, 0xb2, 0x47, 0x1e, 0x98, 0xde, 0xd5, 0x93, 0xaf, 0x01, 0x3a, 0x79, 0xef, 0xc3, + 0x98, 0x36, 0x66, 0x09, 0x4a, 0x5c, 0xd9, 0x8c, 0xc2, 0x0f, 0xa8, 0xd7, 0xb2, 0x7d, 0x62, 0x51, + 0x60, 0x1f, 0x4d, 0xf0, 0xff, 0xa2, 0xc4, 0x7b, 0xae, 0xcf, 0x0e, 0xdb, 0x51, 0xb2, 0x5d, 0xa5, + 0xf3, 0xfe, 0xaf, 0x9f, 0xe3, 0xe3, 0x7b, 0x77, 0xcd, 0xde, 0x5d, 0x6f, 0xe2, 0xe0, 0x66, 0x13, + 0x07, 0x7f, 0x37, 0x71, 0xf0, 0x6d, 0x1b, 0x77, 0x6e, 0xb6, 0x71, 0xe7, 0xf7, 0x36, 0xee, 0x7c, + 0x3c, 0xdb, 0xb7, 0x40, 0xe4, 0x6c, 0xbc, 0x00, 0xb2, 0x7a, 0x45, 0x2a, 0x28, 0x9a, 0x92, 0xeb, + 0x76, 0x09, 0x77, 0x96, 0xcf, 0xfa, 0x92, 0x3f, 0xb0, 0xbb, 0xf0, 0xf2, 0x5f, 0x00, 0x00, 0x00, + 0xff, 0xff, 0x50, 0xcc, 0x73, 0x94, 0xa6, 0x02, 0x00, 0x00, } func (m *PortChannelAmount) Marshal() (dAtA []byte, err error) { diff --git a/modules/apps/transfer/types/transfer_authz_test.go b/modules/apps/transfer/types/transfer_authz_test.go index 022188e747c..873303d7e7a 100644 --- a/modules/apps/transfer/types/transfer_authz_test.go +++ b/modules/apps/transfer/types/transfer_authz_test.go @@ -31,7 +31,7 @@ func TestTransferAuthorization(t *testing.T) { t.Log("verify authorization returns valid method name") require.Equal(t, authorization.MsgTypeURL(), "/ibc.applications.transfer.v1.MsgTransfer") require.NoError(t, authorization.ValidateBasic()) - transfer := NewMsgTransfer(sourcePort, sourceChannel, coin1000, fromAddr.String(), toAddr.String(), timeoutHeight, 0) + transfer := NewMsgTransfer(sourcePort, sourceChannel, coin1000, fromAddr.String(), toAddr.String(), timeoutHeight, 0, "") require.NoError(t, authorization.ValidateBasic()) t.Log("verify updated authorization returns nil") @@ -44,7 +44,7 @@ func TestTransferAuthorization(t *testing.T) { authorization = NewTransferAuthorization([]string{sourcePort}, []string{sourceChannel}, []sdk.Coins{coins1000}, [][]string{{toAddr.String()}}) require.Equal(t, authorization.MsgTypeURL(), "/ibc.applications.transfer.v1.MsgTransfer") require.NoError(t, authorization.ValidateBasic()) - transfer = NewMsgTransfer(sourcePort, sourceChannel, coin500, fromAddr.String(), toAddr.String(), timeoutHeight, 0) + transfer = NewMsgTransfer(sourcePort, sourceChannel, coin500, fromAddr.String(), toAddr.String(), timeoutHeight, 0, "") require.NoError(t, authorization.ValidateBasic()) resp, err = authorization.Accept(ctx, transfer) require.NoError(t, err) @@ -61,7 +61,7 @@ func TestTransferAuthorization(t *testing.T) { t.Log("expect error when spend limit for specific port and channel is not set") authorization = NewTransferAuthorization([]string{sourcePort}, []string{sourceChannel}, []sdk.Coins{coins1000}, [][]string{{toAddr.String()}}) - transfer = NewMsgTransfer(sourcePort2, sourceChannel2, coin500, fromAddr.String(), toAddr.String(), timeoutHeight, 0) + transfer = NewMsgTransfer(sourcePort2, sourceChannel2, coin500, fromAddr.String(), toAddr.String(), timeoutHeight, 0, "") _, err = authorization.Accept(ctx, transfer) require.Error(t, err) @@ -71,7 +71,7 @@ func TestTransferAuthorization(t *testing.T) { []string{sourceChannel, sourceChannel2}, []sdk.Coins{coins1000, coins1000}, [][]string{{toAddr.String()}, {toAddr.String()}}) - transfer = NewMsgTransfer(sourcePort, sourceChannel, coin1000, fromAddr.String(), toAddr.String(), timeoutHeight, 0) + transfer = NewMsgTransfer(sourcePort, sourceChannel, coin1000, fromAddr.String(), toAddr.String(), timeoutHeight, 0, "") resp, err = authorization.Accept(ctx, transfer) require.NoError(t, err) require.NotNil(t, resp.Updated) @@ -80,7 +80,7 @@ func TestTransferAuthorization(t *testing.T) { t.Log("expect error when transferring to not allowed address") authorization = NewTransferAuthorization([]string{sourcePort}, []string{sourceChannel}, []sdk.Coins{coins1000}, [][]string{{fromAddr.String()}}) - transfer = NewMsgTransfer(sourcePort, sourceChannel, coin500, fromAddr.String(), toAddr.String(), timeoutHeight, 0) + transfer = NewMsgTransfer(sourcePort, sourceChannel, coin500, fromAddr.String(), toAddr.String(), timeoutHeight, 0, "") _, err = authorization.Accept(ctx, transfer) require.Error(t, err) } diff --git a/proto/ibc/applications/transfer/v2/authz.proto b/proto/ibc/applications/transfer/v1/authz.proto similarity index 96% rename from proto/ibc/applications/transfer/v2/authz.proto rename to proto/ibc/applications/transfer/v1/authz.proto index 53ee25fc1cb..b1aa9b2adb1 100644 --- a/proto/ibc/applications/transfer/v2/authz.proto +++ b/proto/ibc/applications/transfer/v1/authz.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -package ibc.applications.transfer.v2; +package ibc.applications.transfer.v1; option go_package = "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types"; From ac2f8f4197d0adde0e8edeea4b75d6fa755c0bc1 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Mon, 9 Jan 2023 12:47:21 +0100 Subject: [PATCH 2/7] running make format --- modules/apps/transfer/keeper/msg_server_test.go | 4 +--- modules/apps/transfer/types/transfer_authz.go | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/modules/apps/transfer/keeper/msg_server_test.go b/modules/apps/transfer/keeper/msg_server_test.go index e457d3894cb..e11b2b1dfce 100644 --- a/modules/apps/transfer/keeper/msg_server_test.go +++ b/modules/apps/transfer/keeper/msg_server_test.go @@ -9,9 +9,7 @@ import ( ) func (suite *KeeperTestSuite) TestMsgTransfer() { - var ( - msg *types.MsgTransfer - ) + var msg *types.MsgTransfer testCases := []struct { name string diff --git a/modules/apps/transfer/types/transfer_authz.go b/modules/apps/transfer/types/transfer_authz.go index bcf6e3ebb27..585106e2e9c 100644 --- a/modules/apps/transfer/types/transfer_authz.go +++ b/modules/apps/transfer/types/transfer_authz.go @@ -11,9 +11,7 @@ import ( const gasCostPerIteration = uint64(10) -var ( - _ authz.Authorization = &TransferAuthorization{} -) +var _ authz.Authorization = &TransferAuthorization{} // NewTransferAuthorization creates a new TransferAuthorization object. func NewTransferAuthorization(sourcePorts, sourceChannels []string, spendLimits []sdk.Coins, allowedAddrs [][]string) *TransferAuthorization { From b048ef40f0b75a3cbca586f763f692f30137a3f0 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Mon, 9 Jan 2023 17:21:20 +0100 Subject: [PATCH 3/7] rename allow list and allocation protobuf types --- modules/apps/transfer/types/authz.pb.go | 140 +++++++++--------- modules/apps/transfer/types/transfer_authz.go | 30 ++-- .../ibc/applications/transfer/v1/authz.proto | 9 +- 3 files changed, 90 insertions(+), 89 deletions(-) diff --git a/modules/apps/transfer/types/authz.pb.go b/modules/apps/transfer/types/authz.pb.go index 403bd32352d..38a4d72a5b2 100644 --- a/modules/apps/transfer/types/authz.pb.go +++ b/modules/apps/transfer/types/authz.pb.go @@ -26,29 +26,30 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -type PortChannelAmount struct { +// Allocation defines the spend limit for a particular port and channel +type Allocation struct { // the port on which the packet will be sent SourcePort string `protobuf:"bytes,1,opt,name=source_port,json=sourcePort,proto3" json:"source_port,omitempty" yaml:"source_port"` // the channel by which the packet will be sent SourceChannel string `protobuf:"bytes,2,opt,name=source_channel,json=sourceChannel,proto3" json:"source_channel,omitempty" yaml:"source_channel"` // spend limitation on the channel SpendLimit github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,3,rep,name=spend_limit,json=spendLimit,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"spend_limit"` - // allowed addresses to be sent via transfer message - AllowedAddresses []string `protobuf:"bytes,4,rep,name=allowed_addresses,json=allowedAddresses,proto3" json:"allowed_addresses,omitempty"` + // allow list of receivers, an empty allow list permits any receiver address + AllowList []string `protobuf:"bytes,4,rep,name=allow_list,json=allowList,proto3" json:"allow_list,omitempty"` } -func (m *PortChannelAmount) Reset() { *m = PortChannelAmount{} } -func (m *PortChannelAmount) String() string { return proto.CompactTextString(m) } -func (*PortChannelAmount) ProtoMessage() {} -func (*PortChannelAmount) Descriptor() ([]byte, []int) { +func (m *Allocation) Reset() { *m = Allocation{} } +func (m *Allocation) String() string { return proto.CompactTextString(m) } +func (*Allocation) ProtoMessage() {} +func (*Allocation) Descriptor() ([]byte, []int) { return fileDescriptor_b1a28b55d17325aa, []int{0} } -func (m *PortChannelAmount) XXX_Unmarshal(b []byte) error { +func (m *Allocation) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *PortChannelAmount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *Allocation) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_PortChannelAmount.Marshal(b, m, deterministic) + return xxx_messageInfo_Allocation.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -58,42 +59,42 @@ func (m *PortChannelAmount) XXX_Marshal(b []byte, deterministic bool) ([]byte, e return b[:n], nil } } -func (m *PortChannelAmount) XXX_Merge(src proto.Message) { - xxx_messageInfo_PortChannelAmount.Merge(m, src) +func (m *Allocation) XXX_Merge(src proto.Message) { + xxx_messageInfo_Allocation.Merge(m, src) } -func (m *PortChannelAmount) XXX_Size() int { +func (m *Allocation) XXX_Size() int { return m.Size() } -func (m *PortChannelAmount) XXX_DiscardUnknown() { - xxx_messageInfo_PortChannelAmount.DiscardUnknown(m) +func (m *Allocation) XXX_DiscardUnknown() { + xxx_messageInfo_Allocation.DiscardUnknown(m) } -var xxx_messageInfo_PortChannelAmount proto.InternalMessageInfo +var xxx_messageInfo_Allocation proto.InternalMessageInfo -func (m *PortChannelAmount) GetSourcePort() string { +func (m *Allocation) GetSourcePort() string { if m != nil { return m.SourcePort } return "" } -func (m *PortChannelAmount) GetSourceChannel() string { +func (m *Allocation) GetSourceChannel() string { if m != nil { return m.SourceChannel } return "" } -func (m *PortChannelAmount) GetSpendLimit() github_com_cosmos_cosmos_sdk_types.Coins { +func (m *Allocation) GetSpendLimit() github_com_cosmos_cosmos_sdk_types.Coins { if m != nil { return m.SpendLimit } return nil } -func (m *PortChannelAmount) GetAllowedAddresses() []string { +func (m *Allocation) GetAllowList() []string { if m != nil { - return m.AllowedAddresses + return m.AllowList } return nil } @@ -102,7 +103,7 @@ func (m *PortChannelAmount) GetAllowedAddresses() []string { // the granter's account for ibc transfer on a specific channel type TransferAuthorization struct { // port and channel amounts - Allocations []PortChannelAmount `protobuf:"bytes,1,rep,name=allocations,proto3" json:"allocations"` + Allocations []Allocation `protobuf:"bytes,1,rep,name=allocations,proto3" json:"allocations"` } func (m *TransferAuthorization) Reset() { *m = TransferAuthorization{} } @@ -138,7 +139,7 @@ func (m *TransferAuthorization) XXX_DiscardUnknown() { var xxx_messageInfo_TransferAuthorization proto.InternalMessageInfo -func (m *TransferAuthorization) GetAllocations() []PortChannelAmount { +func (m *TransferAuthorization) GetAllocations() []Allocation { if m != nil { return m.Allocations } @@ -146,7 +147,7 @@ func (m *TransferAuthorization) GetAllocations() []PortChannelAmount { } func init() { - proto.RegisterType((*PortChannelAmount)(nil), "ibc.applications.transfer.v1.PortChannelAmount") + proto.RegisterType((*Allocation)(nil), "ibc.applications.transfer.v1.Allocation") proto.RegisterType((*TransferAuthorization)(nil), "ibc.applications.transfer.v1.TransferAuthorization") } @@ -155,38 +156,37 @@ func init() { } var fileDescriptor_b1a28b55d17325aa = []byte{ - // 442 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x52, 0xc1, 0x8a, 0x13, 0x31, - 0x18, 0xee, 0x6c, 0x17, 0x61, 0x53, 0x56, 0xec, 0xe0, 0xca, 0x74, 0x91, 0x69, 0x99, 0xd3, 0x80, - 0x34, 0xb1, 0x0a, 0x2e, 0xec, 0xc9, 0x76, 0xaf, 0x1e, 0x74, 0x10, 0x04, 0x2f, 0x25, 0x93, 0x89, - 0x6d, 0x70, 0x26, 0xff, 0x90, 0x64, 0x2a, 0xbb, 0x57, 0x5f, 0xc0, 0xd7, 0xd0, 0xb3, 0x0f, 0xb1, - 0x78, 0xda, 0xa3, 0xa7, 0x2a, 0xed, 0x1b, 0xec, 0x13, 0xc8, 0x24, 0x59, 0xe8, 0x52, 0xf0, 0x34, - 0x93, 0xff, 0xfb, 0xfe, 0x2f, 0xf9, 0xbf, 0xef, 0x47, 0xa9, 0xc8, 0x19, 0xa1, 0x75, 0x5d, 0x0a, - 0x46, 0x8d, 0x00, 0xa9, 0x89, 0x51, 0x54, 0xea, 0x4f, 0x5c, 0x91, 0xd5, 0x84, 0xd0, 0xc6, 0x2c, - 0xaf, 0x70, 0xad, 0xc0, 0x40, 0xf8, 0x54, 0xe4, 0x0c, 0xef, 0x32, 0xf1, 0x1d, 0x13, 0xaf, 0x26, - 0xa7, 0x03, 0x06, 0xba, 0x02, 0x3d, 0xb7, 0x5c, 0xe2, 0x0e, 0xae, 0xf1, 0xf4, 0xf1, 0x02, 0x16, - 0xe0, 0xea, 0xed, 0x9f, 0xaf, 0xc6, 0x8e, 0x43, 0x72, 0xaa, 0x39, 0x59, 0x4d, 0x72, 0x6e, 0xe8, - 0x84, 0x30, 0x10, 0xd2, 0xe1, 0xc9, 0xf7, 0x03, 0xd4, 0x7f, 0x0b, 0xca, 0x5c, 0x2c, 0xa9, 0x94, - 0xbc, 0x9c, 0x56, 0xd0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x0e, 0xdb, 0x51, 0xb2, 0x5d, 0xa5, - 0xf3, 0xfe, 0xaf, 0x9f, 0xe3, 0xe3, 0x7b, 0x77, 0xcd, 0xde, 0x5d, 0x6f, 0xe2, 0xe0, 0x66, 0x13, - 0x07, 0x7f, 0x37, 0x71, 0xf0, 0x6d, 0x1b, 0x77, 0x6e, 0xb6, 0x71, 0xe7, 0xf7, 0x36, 0xee, 0x7c, - 0x3c, 0xdb, 0xb7, 0x40, 0xe4, 0x6c, 0xbc, 0x00, 0xb2, 0x7a, 0x45, 0x2a, 0x28, 0x9a, 0x92, 0xeb, - 0x76, 0x09, 0x77, 0x96, 0xcf, 0xfa, 0x92, 0x3f, 0xb0, 0xbb, 0xf0, 0xf2, 0x5f, 0x00, 0x00, 0x00, - 0xff, 0xff, 0x50, 0xcc, 0x73, 0x94, 0xa6, 0x02, 0x00, 0x00, + // 429 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x52, 0xc1, 0x6e, 0xd3, 0x30, + 0x18, 0x6e, 0xd6, 0x09, 0xa9, 0xae, 0x86, 0x44, 0xc4, 0x50, 0x3a, 0x41, 0x5a, 0xe5, 0x94, 0x4b, + 0x6d, 0x0a, 0x12, 0x93, 0x76, 0x62, 0xdd, 0x75, 0x87, 0x11, 0x71, 0xe2, 0x52, 0x39, 0xae, 0x49, + 0x2c, 0x9c, 0xfc, 0x51, 0xec, 0x04, 0x6d, 0xe2, 0x21, 0x38, 0xf0, 0x14, 0x9c, 0x79, 0x88, 0x89, + 0xd3, 0x8e, 0x9c, 0x0a, 0x6a, 0xdf, 0x60, 0x4f, 0x80, 0x62, 0x1b, 0xc8, 0x84, 0xb4, 0x53, 0xf2, + 0xff, 0xdf, 0xf7, 0xfd, 0xfe, 0xfc, 0xf9, 0x47, 0xb1, 0x48, 0x19, 0xa1, 0x55, 0x25, 0x05, 0xa3, + 0x5a, 0x40, 0xa9, 0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 0x3e, 0x73, 0xb5, 0xfe, 0x40, 0xf4, 0x65, 0xc5, + 0x95, 0x11, 0xa8, 0x04, 0x99, 0xf9, 0xe7, 0xdd, 0x78, 0xff, 0x19, 0x42, 0x54, 0x4a, 0xf8, 0xb8, + 0x92, 0x42, 0xe9, 0x60, 0x7f, 0x36, 0x8c, 0x47, 0xc9, 0xc8, 0x74, 0xce, 0x85, 0xd2, 0xd1, 0x27, + 0x74, 0xf8, 0xd6, 0xc5, 0x7e, 0xda, 0xe8, 0x1c, 0x6a, 0x71, 0x65, 0x03, 0xba, 0x40, 0x63, 0xfa, + 0x37, 0x2e, 0x15, 0x78, 0xc6, 0x65, 0x8c, 0xef, 0x7b, 0x34, 0xfc, 0x2f, 0xdf, 0xe5, 0x7e, 0x67, + 0x3a, 0xe9, 0x8f, 0x38, 0x79, 0xf4, 0xfd, 0xdb, 0xfc, 0xe0, 0xce, 0x21, 0xcb, 0x37, 0xd7, 0xdb, + 0xd0, 0xbb, 0xd9, 0x86, 0xde, 0xaf, 0x6d, 0xe8, 0x7d, 0xde, 0x85, 0x83, 0x9b, 0x5d, 0x38, 0xf8, + 0xb1, 0x0b, 0x07, 0xef, 0x8e, 0xff, 0xbf, 0xac, 0x48, 0xd9, 0x3c, 0x03, 0xd2, 0xbe, 0x22, 0x05, + 0xac, 0x1b, 0xc9, 0x55, 0xb7, 0x67, 0xbd, 0xfd, 0x32, 0x09, 0xa4, 0x0f, 0xcc, 0x73, 0xbf, 0xfc, + 0x1d, 0x00, 0x00, 0xff, 0xff, 0xb7, 0xd1, 0x56, 0xd3, 0x89, 0x02, 0x00, 0x00, } -func (m *PortChannelAmount) Marshal() (dAtA []byte, err error) { +func (m *Allocation) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -196,21 +196,21 @@ func (m *PortChannelAmount) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *PortChannelAmount) MarshalTo(dAtA []byte) (int, error) { +func (m *Allocation) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *PortChannelAmount) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *Allocation) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if len(m.AllowedAddresses) > 0 { - for iNdEx := len(m.AllowedAddresses) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.AllowedAddresses[iNdEx]) - copy(dAtA[i:], m.AllowedAddresses[iNdEx]) - i = encodeVarintAuthz(dAtA, i, uint64(len(m.AllowedAddresses[iNdEx]))) + if len(m.AllowList) > 0 { + for iNdEx := len(m.AllowList) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.AllowList[iNdEx]) + copy(dAtA[i:], m.AllowList[iNdEx]) + i = encodeVarintAuthz(dAtA, i, uint64(len(m.AllowList[iNdEx]))) i-- dAtA[i] = 0x22 } @@ -294,7 +294,7 @@ func encodeVarintAuthz(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *PortChannelAmount) Size() (n int) { +func (m *Allocation) Size() (n int) { if m == nil { return 0 } @@ -314,8 +314,8 @@ func (m *PortChannelAmount) Size() (n int) { n += 1 + l + sovAuthz(uint64(l)) } } - if len(m.AllowedAddresses) > 0 { - for _, s := range m.AllowedAddresses { + if len(m.AllowList) > 0 { + for _, s := range m.AllowList { l = len(s) n += 1 + l + sovAuthz(uint64(l)) } @@ -344,7 +344,7 @@ func sovAuthz(x uint64) (n int) { func sozAuthz(x uint64) (n int) { return sovAuthz(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *PortChannelAmount) Unmarshal(dAtA []byte) error { +func (m *Allocation) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -367,10 +367,10 @@ func (m *PortChannelAmount) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: PortChannelAmount: wiretype end group for non-group") + return fmt.Errorf("proto: Allocation: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: PortChannelAmount: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: Allocation: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -473,7 +473,7 @@ func (m *PortChannelAmount) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 4: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AllowedAddresses", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field AllowList", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -501,7 +501,7 @@ func (m *PortChannelAmount) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.AllowedAddresses = append(m.AllowedAddresses, string(dAtA[iNdEx:postIndex])) + m.AllowList = append(m.AllowList, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex default: iNdEx = preIndex @@ -582,7 +582,7 @@ func (m *TransferAuthorization) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Allocations = append(m.Allocations, PortChannelAmount{}) + m.Allocations = append(m.Allocations, Allocation{}) if err := m.Allocations[len(m.Allocations)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } diff --git a/modules/apps/transfer/types/transfer_authz.go b/modules/apps/transfer/types/transfer_authz.go index 585106e2e9c..8d0108e2902 100644 --- a/modules/apps/transfer/types/transfer_authz.go +++ b/modules/apps/transfer/types/transfer_authz.go @@ -15,13 +15,13 @@ var _ authz.Authorization = &TransferAuthorization{} // NewTransferAuthorization creates a new TransferAuthorization object. func NewTransferAuthorization(sourcePorts, sourceChannels []string, spendLimits []sdk.Coins, allowedAddrs [][]string) *TransferAuthorization { - allocations := []PortChannelAmount{} + allocations := []Allocation{} for index := range sourcePorts { - allocations = append(allocations, PortChannelAmount{ - SourcePort: sourcePorts[index], - SourceChannel: sourceChannels[index], - SpendLimit: spendLimits[index], - AllowedAddresses: allowedAddrs[index], + allocations = append(allocations, Allocation{ + SourcePort: sourcePorts[index], + SourceChannel: sourceChannels[index], + SpendLimit: spendLimits[index], + AllowList: allowedAddrs[index], }) } return &TransferAuthorization{ @@ -58,7 +58,7 @@ func (a TransferAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (authz.Accep return authz.AcceptResponse{}, sdkerrors.ErrInsufficientFunds.Wrapf("requested amount is more than spend limit") } - if !IsAllowedAddress(ctx, msgTransfer.Receiver, allocation.AllowedAddresses) { + if !IsAllowedAddress(ctx, msgTransfer.Receiver, allocation.AllowList) { return authz.AcceptResponse{}, sdkerrors.ErrInvalidAddress.Wrapf("not allowed address for transfer") } @@ -71,11 +71,11 @@ func (a TransferAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (authz.Accep Allocations: a.Allocations, }}, nil } - a.Allocations[index] = PortChannelAmount{ - SourcePort: allocation.SourcePort, - SourceChannel: allocation.SourceChannel, - SpendLimit: limitLeft, - AllowedAddresses: allocation.AllowedAddresses, + a.Allocations[index] = Allocation{ + SourcePort: allocation.SourcePort, + SourceChannel: allocation.SourceChannel, + SpendLimit: limitLeft, + AllowList: allocation.AllowList, } return authz.AcceptResponse{Accept: true, Delete: false, Updated: &TransferAuthorization{ @@ -103,11 +103,11 @@ func (a TransferAuthorization) ValidateBasic() error { } found := make(map[string]bool, 0) - for i := 0; i < len(allocation.AllowedAddresses); i++ { - if found[allocation.AllowedAddresses[i]] { + for i := 0; i < len(allocation.AllowList); i++ { + if found[allocation.AllowList[i]] { return ErrDuplicateEntry } - found[allocation.AllowedAddresses[i]] = true + found[allocation.AllowList[i]] = true } } return nil diff --git a/proto/ibc/applications/transfer/v1/authz.proto b/proto/ibc/applications/transfer/v1/authz.proto index b1aa9b2adb1..db3e0bb7636 100644 --- a/proto/ibc/applications/transfer/v1/authz.proto +++ b/proto/ibc/applications/transfer/v1/authz.proto @@ -8,7 +8,8 @@ import "cosmos_proto/cosmos.proto"; import "gogoproto/gogo.proto"; import "cosmos/base/v1beta1/coin.proto"; -message PortChannelAmount { +// Allocation defines the spend limit for a particular port and channel +message Allocation { // the port on which the packet will be sent string source_port = 1 [(gogoproto.moretags) = "yaml:\"source_port\""]; // the channel by which the packet will be sent @@ -16,8 +17,8 @@ message PortChannelAmount { // spend limitation on the channel repeated cosmos.base.v1beta1.Coin spend_limit = 3 [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"]; - // allowed addresses to be sent via transfer message - repeated string allowed_addresses = 4; + // allow list of receivers, an empty allow list permits any receiver address + repeated string allow_list = 4; } // TransferAuthorization allows the grantee to spend up to spend_limit coins from @@ -26,5 +27,5 @@ message TransferAuthorization { option (cosmos_proto.implements_interface) = "Authorization"; // port and channel amounts - repeated PortChannelAmount allocations = 1 [(gogoproto.nullable) = false]; + repeated Allocation allocations = 1 [(gogoproto.nullable) = false]; } From b18fdd7e826e0a703d4e25f6a94f23d0ff475242 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Tue, 10 Jan 2023 10:31:04 +0100 Subject: [PATCH 4/7] use fully qualified interface name in authz.proto --- modules/apps/transfer/types/authz.pb.go | 57 ++++++++++--------- .../ibc/applications/transfer/v1/authz.proto | 2 +- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/modules/apps/transfer/types/authz.pb.go b/modules/apps/transfer/types/authz.pb.go index 38a4d72a5b2..1e81b9968f4 100644 --- a/modules/apps/transfer/types/authz.pb.go +++ b/modules/apps/transfer/types/authz.pb.go @@ -156,34 +156,35 @@ func init() { } var fileDescriptor_b1a28b55d17325aa = []byte{ - // 429 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x52, 0xc1, 0x6e, 0xd3, 0x30, - 0x18, 0x6e, 0xd6, 0x09, 0xa9, 0xae, 0x86,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07, 0xef, 0x8e, 0xff, 0xbf, 0xac, 0x48, 0xd9, 0x3c, 0x03, 0xd2, 0xbe, 0x22, 0x05, - 0xac, 0x1b, 0xc9, 0x55, 0xb7, 0x67, 0xbd, 0xfd, 0x32, 0x09, 0xa4, 0x0f, 0xcc, 0x73, 0xbf, 0xfc, - 0x1d, 0x00, 0x00, 0xff, 0xff, 0xb7, 0xd1, 0x56, 0xd3, 0x89, 0x02, 0x00, 0x00, + // 436 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x52, 0x4d, 0x6e, 0xd3, 0x40, + 0x14, 0x8e, 0x9b, 0x0a, 0x29, 0x13, 0xc1, 0xc2, 0xa2, 0xc8, 0xa9, 0xc0, 0x89, 0xbc, 0x40, 0xde, + 0x64, 0x86, 0x80, 0x44, 0xa5, 0xae, 0x68, 0xba, 0xed, 0xa2, 0x58, 0xac, 0xd8, 0x44, 0xe3, 0xc9, + 0x60, 0x8f, 0x18, 0xfb, 0x59, 0x9e, 0xb1, 0x51, 0x7b, 0x0a, 0x90, 0x38, 0x05, 0x6b, 0x0e, 0x51, + 0xb1, 0xea, 0x92, 0x55, 0x40, 0xc9, 0x0d, 0x7a, 0x02, 0xe4, 0x99, 0x29, 0xb8, 0x42, 0xea, 0xca, + 0x7e, 0x3f, 0xdf, 0x7b, 0xdf, 0xfb, 0xe6, 0x43, 0xb1, 0x48, 0x19, 0xa1, 0x55, 0x25, 0x05, 0xa3, + 0x5a, 0x40, 0xa9, 0x88, 0xae, 0x69, 0xa9, 0x3e, 0xf0, 0x9a, 0xb4, 0x0b, 0x42, 0x1b, 0x9d, 0x5f, + 0xe2, 0xaa, 0x06, 0x0d, 0xfe, 0x53, 0x91, 0x32, 0xdc, 0xef, 0xc4, 0xb7, 0x9d, 0xb8, 0x5d, 0x1c, + 0x4e, 0x18, 0xa8, 0x02, 0xd4, 0xca, 0xf4, 0x12, 0x1b, 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xc5, 0x43, 0x07, 0xef, 0x9c, 0xee, 0x27, 0x8d, 0xce, 0xa1, 0x16, 0x97, 0x56, 0xa1, 0x73, 0x34, + 0xa6, 0x7f, 0xf5, 0x52, 0x81, 0x67, 0x68, 0xc6, 0xf8, 0xbe, 0x57, 0xc3, 0xff, 0x04, 0x5e, 0xee, + 0x77, 0xac, 0x93, 0xfe, 0x88, 0xe3, 0xe7, 0x3f, 0xbe, 0xcf, 0x23, 0x77, 0xa6, 0x75, 0xc2, 0xed, + 0x9d, 0x77, 0x36, 0x2f, 0xdf, 0x5e, 0x6d, 0x43, 0xef, 0x7a, 0x1b, 0x7a, 0xbf, 0xb7, 0xa1, 0xf7, + 0x79, 0x17, 0x0e, 0xae, 0x77, 0xe1, 0xe0, 0xe7, 0x2e, 0x1c, 0xbc, 0x3f, 0xfa, 0x5f, 0x02, 0x91, + 0xb2, 0x79, 0x06, 0xa4, 0x7d, 0x4d, 0x0a, 0x58, 0x37, 0x92, 0xab, 0xce, 0x7d, 0x3d, 0xd7, 0x19, + 0x5d, 0xd2, 0x07, 0xc6, 0x04, 0xaf, 0xfe, 0x04, 0x00, 0x00, 0xff, 0xff, 0x7e, 0xff, 0x95, 0x1c, + 0x9f, 0x02, 0x00, 0x00, } func (m *Allocation) Marshal() (dAtA []byte, err error) { diff --git a/proto/ibc/applications/transfer/v1/authz.proto b/proto/ibc/applications/transfer/v1/authz.proto index db3e0bb7636..53113bf5e11 100644 --- a/proto/ibc/applications/transfer/v1/authz.proto +++ b/proto/ibc/applications/transfer/v1/authz.proto @@ -24,7 +24,7 @@ message Allocation { // TransferAuthorization allows the grantee to spend up to spend_limit coins from // the granter's account for ibc transfer on a specific channel message TransferAuthorization { - option (cosmos_proto.implements_interface) = "Authorization"; + option (cosmos_proto.implements_interface) = "cosmos.authz.v1beta1.Authorization"; // port and channel amounts repeated Allocation allocations = 1 [(gogoproto.nullable) = false]; From eda45ed540f66fd95779cb444f8d3ceef1267e11 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Tue, 10 Jan 2023 13:33:19 +0100 Subject: [PATCH 5/7] adding validate basic tests --- .../transfer/types/transfer_authorization.go | 8 + .../types/transfer_authorization_test.go | 144 ++++++++++++++++-- 2 files changed, 139 insertions(+), 13 deletions(-) diff --git a/modules/apps/transfer/types/transfer_authorization.go b/modules/apps/transfer/types/transfer_authorization.go index 743b86623a0..3d560004f21 100644 --- a/modules/apps/transfer/types/transfer_authorization.go +++ b/modules/apps/transfer/types/transfer_authorization.go @@ -79,16 +79,23 @@ func (a TransferAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (authz.Accep // ValidateBasic implements Authorization.ValidateBasic. func (a TransferAuthorization) ValidateBasic() error { + if len(a.Allocations) == 0 { + return sdkerrors.Wrap(ErrInvalidAuthorization, "allocations cannot be empty") + } + for _, allocation := range a.Allocations { if allocation.SpendLimit == nil { return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "spend limit cannot be nil") } + if err := allocation.SpendLimit.Validate(); err != nil { return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, err.Error()) } + if err := host.PortIdentifierValidator(allocation.SourcePort); err != nil { return sdkerrors.Wrap(err, "invalid source port ID") } + if err := host.ChannelIdentifierValidator(allocation.SourceChannel); err != nil { return sdkerrors.Wrap(err, "invalid source channel ID") } @@ -101,6 +108,7 @@ func (a TransferAuthorization) ValidateBasic() error { found[allocation.AllowList[i]] = true } } + return nil } diff --git a/modules/apps/transfer/types/transfer_authorization_test.go b/modules/apps/transfer/types/transfer_authorization_test.go index 873303d7e7a..cc860c93c86 100644 --- a/modules/apps/transfer/types/transfer_authorization_test.go +++ b/modules/apps/transfer/types/transfer_authorization_test.go @@ -1,4 +1,4 @@ -package types +package types_test import ( "testing" @@ -8,6 +8,10 @@ import ( "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" + clienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" + ibctesting "github.com/cosmos/ibc-go/v6/testing" + "github.com/cosmos/ibc-go/v6/testing/mock" ) var ( @@ -21,17 +25,18 @@ var ( coin500 = sdk.NewCoin("stake", sdk.NewInt(500)) fromAddr = sdk.AccAddress("_____from _____") toAddr = sdk.AccAddress("_______to________") + timeoutHeight = clienttypes.NewHeight(0, 10) ) func TestTransferAuthorization(t *testing.T) { app := simapp.Setup(t, false) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) - authorization := NewTransferAuthorization([]string{sourcePort}, []string{sourceChannel}, []sdk.Coins{coins1000}, [][]string{{toAddr.String()}}) + authorization := types.NewTransferAuthorization([]string{sourcePort}, []string{sourceChannel}, []sdk.Coins{coins1000}, [][]string{{toAddr.String()}}) t.Log("verify authorization returns valid method name") require.Equal(t, authorization.MsgTypeURL(), "/ibc.applications.transfer.v1.MsgTransfer") require.NoError(t, authorization.ValidateBasic()) - transfer := NewMsgTransfer(sourcePort, sourceChannel, coin1000, fromAddr.String(), toAddr.String(), timeoutHeight, 0, "") + transfer := types.NewMsgTransfer(sourcePort, sourceChannel, coin1000, fromAddr.String(), toAddr.String(), timeoutHeight, 0, "") require.NoError(t, authorization.ValidateBasic()) t.Log("verify updated authorization returns nil") @@ -41,16 +46,16 @@ func TestTransferAuthorization(t *testing.T) { require.Nil(t, resp.Updated) t.Log("verify updated authorization returns remaining spent limit") - authorization = NewTransferAuthorization([]string{sourcePort}, []string{sourceChannel}, []sdk.Coins{coins1000}, [][]string{{toAddr.String()}}) + authorization = types.NewTransferAuthorization([]string{sourcePort}, []string{sourceChannel}, []sdk.Coins{coins1000}, [][]string{{toAddr.String()}}) require.Equal(t, authorization.MsgTypeURL(), "/ibc.applications.transfer.v1.MsgTransfer") require.NoError(t, authorization.ValidateBasic()) - transfer = NewMsgTransfer(sourcePort, sourceChannel, coin500, fromAddr.String(), toAddr.String(), timeoutHeight, 0, "") + transfer = types.NewMsgTransfer(sourcePort, sourceChannel, coin500, fromAddr.String(), toAddr.String(), timeoutHeight, 0, "") require.NoError(t, authorization.ValidateBasic()) resp, err = authorization.Accept(ctx, transfer) require.NoError(t, err) require.False(t, resp.Delete) require.NotNil(t, resp.Updated) - sendAuth := NewTransferAuthorization([]string{sourcePort}, []string{sourceChannel}, []sdk.Coins{coins500}, [][]string{{toAddr.String()}}) + sendAuth := types.NewTransferAuthorization([]string{sourcePort}, []string{sourceChannel}, []sdk.Coins{coins500}, [][]string{{toAddr.String()}}) require.Equal(t, sendAuth.String(), resp.Updated.String()) t.Log("expect updated authorization nil after spending remaining amount") @@ -60,27 +65,140 @@ func TestTransferAuthorization(t *testing.T) { require.Nil(t, resp.Updated) t.Log("expect error when spend limit for specific port and channel is not set") - authorization = NewTransferAuthorization([]string{sourcePort}, []string{sourceChannel}, []sdk.Coins{coins1000}, [][]string{{toAddr.String()}}) - transfer = NewMsgTransfer(sourcePort2, sourceChannel2, coin500, fromAddr.String(), toAddr.String(), timeoutHeight, 0, "") + authorization = types.NewTransferAuthorization([]string{sourcePort}, []string{sourceChannel}, []sdk.Coins{coins1000}, [][]string{{toAddr.String()}}) + transfer = types.NewMsgTransfer(sourcePort2, sourceChannel2, coin500, fromAddr.String(), toAddr.String(), timeoutHeight, 0, "") _, err = authorization.Accept(ctx, transfer) require.Error(t, err) t.Log("expect removing only 1 allocation if spend limit is finalized for the port") - authorization = NewTransferAuthorization( + authorization = types.NewTransferAuthorization( []string{sourcePort, sourcePort2}, []string{sourceChannel, sourceChannel2}, []sdk.Coins{coins1000, coins1000}, [][]string{{toAddr.String()}, {toAddr.String()}}) - transfer = NewMsgTransfer(sourcePort, sourceChannel, coin1000, fromAddr.String(), toAddr.String(), timeoutHeight, 0, "") + transfer = types.NewMsgTransfer(sourcePort, sourceChannel, coin1000, fromAddr.String(), toAddr.String(), timeoutHeight, 0, "") resp, err = authorization.Accept(ctx, transfer) require.NoError(t, err) require.NotNil(t, resp.Updated) - require.Equal(t, resp.Updated, NewTransferAuthorization([]string{sourcePort2}, []string{sourceChannel2}, []sdk.Coins{coins1000}, [][]string{{toAddr.String()}})) + require.Equal(t, resp.Updated, types.NewTransferAuthorization([]string{sourcePort2}, []string{sourceChannel2}, []sdk.Coins{coins1000}, [][]string{{toAddr.String()}})) require.False(t, resp.Delete) t.Log("expect error when transferring to not allowed address") - authorization = NewTransferAuthorization([]string{sourcePort}, []string{sourceChannel}, []sdk.Coins{coins1000}, [][]string{{fromAddr.String()}}) - transfer = NewMsgTransfer(sourcePort, sourceChannel, coin500, fromAddr.String(), toAddr.String(), timeoutHeight, 0, "") + authorization = types.NewTransferAuthorization([]string{sourcePort}, []string{sourceChannel}, []sdk.Coins{coins1000}, [][]string{{fromAddr.String()}}) + transfer = types.NewMsgTransfer(sourcePort, sourceChannel, coin500, fromAddr.String(), toAddr.String(), timeoutHeight, 0, "") _, err = authorization.Accept(ctx, transfer) require.Error(t, err) } + +func TestTransferAuthorizationValidateBasic(t *testing.T) { + var transferAuthz types.TransferAuthorization + + testCases := []struct { + name string + malleate func() + expPass bool + }{ + { + "success", + func() {}, + true, + }, + { + "success: empty allow list", + func() { + transferAuthz.Allocations[0].AllowList = []string{} + }, + true, + }, + { + "success: with multiple allocations", + func() { + allocation := types.Allocation{ + SourcePort: types.PortID, + SourceChannel: ibctesting.FirstChannelID, + SpendLimit: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))), + AllowList: []string{}, + } + + transferAuthz.Allocations = append(transferAuthz.Allocations, allocation) + }, + true, + }, + { + "empty allocations", + func() { + transferAuthz = types.TransferAuthorization{Allocations: []types.Allocation{}} + }, + false, + }, + { + "nil allocations", + func() { + transferAuthz = types.TransferAuthorization{} + }, + false, + }, + { + "nil spend limit coins", + func() { + transferAuthz.Allocations[0].SpendLimit = nil + }, + false, + }, + { + "invalid spend limit coins", + func() { + transferAuthz.Allocations[0].SpendLimit = sdk.Coins{sdk.Coin{Denom: ""}} + }, + false, + }, + { + "duplicate entry in allow list", + func() { + transferAuthz.Allocations[0].AllowList = []string{ibctesting.TestAccAddress, ibctesting.TestAccAddress} + }, + false, + }, + { + "invalid port identifier", + func() { + transferAuthz.Allocations[0].SourcePort = "" + }, + false, + }, + { + "invalid channel identifier", + func() { + transferAuthz.Allocations[0].SourceChannel = "" + }, + false, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + transferAuthz = types.TransferAuthorization{ + Allocations: []types.Allocation{ + { + SourcePort: mock.PortID, + SourceChannel: ibctesting.FirstChannelID, + SpendLimit: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))), + AllowList: []string{ + ibctesting.TestAccAddress, + }, + }, + }, + } + + tc.malleate() + + err := transferAuthz.ValidateBasic() + + if tc.expPass { + require.NoError(t, err) + } else { + require.Error(t, err) + } + }) + } +} From ae864699b242ac7531995e89e7e55c82c2ca9ddb Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Tue, 10 Jan 2023 15:33:09 +0100 Subject: [PATCH 6/7] if allow list is empty, permit any receiver --- modules/apps/transfer/types/transfer_authorization.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/apps/transfer/types/transfer_authorization.go b/modules/apps/transfer/types/transfer_authorization.go index 3d560004f21..81cb46ed798 100644 --- a/modules/apps/transfer/types/transfer_authorization.go +++ b/modules/apps/transfer/types/transfer_authorization.go @@ -115,6 +115,10 @@ func (a TransferAuthorization) ValidateBasic() error { // isAllowedAddress returns a boolean indicating if the receiver address is valid for transfer. // gasCostPerIteration gas is consumed for each iteration. func isAllowedAddress(ctx sdk.Context, receiver string, allowedAddrs []string) bool { + if len(allowedAddrs) == 0 { + return true + } + for _, addr := range allowedAddrs { ctx.GasMeter().ConsumeGas(gasCostPerIteration, "transfer authorization") if addr == receiver { From 5b893146275836e3c8575dd5c2b3d7734f72cbab Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 11 Jan 2023 11:31:17 +0100 Subject: [PATCH 7/7] test formatting --- modules/apps/transfer/types/transfer_authorization_test.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/apps/transfer/types/transfer_authorization_test.go b/modules/apps/transfer/types/transfer_authorization_test.go index cc860c93c86..35cc2d89b72 100644 --- a/modules/apps/transfer/types/transfer_authorization_test.go +++ b/modules/apps/transfer/types/transfer_authorization_test.go @@ -183,9 +183,7 @@ func TestTransferAuthorizationValidateBasic(t *testing.T) { SourcePort: mock.PortID, SourceChannel: ibctesting.FirstChannelID, SpendLimit: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))), - AllowList: []string{ - ibctesting.TestAccAddress, - }, + AllowList: []string{ibctesting.TestAccAddress}, }, }, }