From 26cce78874ea480446a1fd0a1671cddffb2d0b4f Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 13 Oct 2021 12:04:50 +0200 Subject: [PATCH 1/2] adding unspecified type enum, adding defensive check to ValidateBasic --- docs/ibc/proto-docs.md | 8 +-- .../27-interchain-accounts/types/packet.go | 4 ++ .../types/packet_test.go | 9 +++ .../27-interchain-accounts/types/types.pb.go | 70 ++++++++++--------- .../interchain_accounts/v1/types.proto | 17 ++--- 5 files changed, 63 insertions(+), 45 deletions(-) diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index fe109584bba..b5557d2d923 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -435,13 +435,13 @@ InterchainAccountPacketData is comprised of a raw transaction, type of transacti ### Type -The different types of interchain account transactions -EXECUTE_TX is used when sending a TX from the controller side to the host side. The host side will execute the tx on -behalf of the interchain account. +Type defines a classification of message issued from a controller chain to its associated interchain accounts +host | Name | Number | Description | | ---- | ------ | ----------- | -| TYPE_EXECUTE_TX_UNSPECIFIED | 0 | Execute message type | +| TYPE_UNSPECIFIED | 0 | Default zero value enumeration | +| TYPE_EXECUTE_TX | 1 | Execute a transaction on an interchain accounts host chain | diff --git a/modules/apps/27-interchain-accounts/types/packet.go b/modules/apps/27-interchain-accounts/types/packet.go index d69dfebd30a..8342f911bbf 100644 --- a/modules/apps/27-interchain-accounts/types/packet.go +++ b/modules/apps/27-interchain-accounts/types/packet.go @@ -11,6 +11,10 @@ const MaxMemoCharLength = 256 // ValidateBasic performs basic validation of the interchain account packet data. // The memo may be empty. func (iapd InterchainAccountPacketData) ValidateBasic() error { + if iapd.Type == UNSPECIFIED { + return sdkerrors.Wrap(ErrInvalidOutgoingData, "packet data type cannot be unspecified") + } + if iapd.Data == nil { return sdkerrors.Wrap(ErrInvalidOutgoingData, "packet data cannot be empty") } diff --git a/modules/apps/27-interchain-accounts/types/packet_test.go b/modules/apps/27-interchain-accounts/types/packet_test.go index ce2fab2f5ca..d205a1d007c 100644 --- a/modules/apps/27-interchain-accounts/types/packet_test.go +++ b/modules/apps/27-interchain-accounts/types/packet_test.go @@ -29,6 +29,15 @@ func (suite *TypesTestSuite) TestValidateBasic() { }, true, }, + { + "type unspecified", + types.InterchainAccountPacketData{ + Type: types.UNSPECIFIED, + Data: nil, + Memo: "memo", + }, + false, + }, { "empty data", types.InterchainAccountPacketData{ diff --git a/modules/apps/27-interchain-accounts/types/types.pb.go b/modules/apps/27-interchain-accounts/types/types.pb.go index a4fad957f7f..7ed9c1b9e7e 100644 --- a/modules/apps/27-interchain-accounts/types/types.pb.go +++ b/modules/apps/27-interchain-accounts/types/types.pb.go @@ -24,22 +24,25 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// The different types of interchain account transactions -// EXECUTE_TX is used when sending a TX from the controller side to the host side. The host side will execute the tx on -// behalf of the interchain account. +// Type defines a classification of message issued from a controller chain to its associated interchain accounts +// host type Type int32 const ( - // Execute message type - EXECUTE_TX Type = 0 + // Default zero value enumeration + UNSPECIFIED Type = 0 + // Execute a transaction on an interchain accounts host chain + EXECUTE_TX Type = 1 ) var Type_name = map[int32]string{ - 0: "TYPE_EXECUTE_TX_UNSPECIFIED", + 0: "TYPE_UNSPECIFIED", + 1: "TYPE_EXECUTE_TX", } var Type_value = map[string]int32{ - "TYPE_EXECUTE_TX_UNSPECIFIED": 0, + "TYPE_UNSPECIFIED": 0, + "TYPE_EXECUTE_TX": 1, } func (x Type) String() string { @@ -94,7 +97,7 @@ func (m *InterchainAccountPacketData) GetType() Type { if m != nil { return m.Type } - return EXECUTE_TX + return UNSPECIFIED } func (m *InterchainAccountPacketData) GetData() []byte { @@ -167,31 +170,32 @@ func init() { } var fileDescriptor_39bab93e18d89799 = []byte{ - // 376 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x91, 0x41, 0xeb, 0xd3, 0x30, - 0x18, 0xc6, 0x1b, 0xff, 0x45, 0x66, 0x94, 0x21, 0x65, 0x87, 0xda, 0x41, 0x29, 0xbb, 0x58, 0x84, - 0x26, 0xae, 0x3b, 0x78, 0xd1, 0xc3, 0xdc, 0x2a, 0xec, 0x22, 0xa3, 0x76, 0x30, 0xbd, 0x94, 0x34, - 0x8b, 0x5d, 0x70, 0x6d, 0xca, 0x92, 0x0e, 0xfb, 0x0d, 0x86, 0x27, 0xbf, 0x80, 0x27, 0xbf, 0x8c, - 0xc7, 0x1d, 0x3d, 0xca, 0xf6, 0x45, 0xa4, 0x29, 0x6e, 0x1e, 0x3c, 0x78, 0x7b, 0x78, 0x93, 0xe7, - 0xc9, 0xef, 0xcd, 0x03, 0x27, 0x3c, 0xa3, 0x98, 0x54, 0xd5, 0x8e, 0x53, 0xa2, 0xb8, 0x28, 0x25, - 0xe6, 0xa5, 0x62, 0x7b, 0xba, 0x25, 0xbc, 0x4c, 0x09, 0xa5, 0xa2, 0x2e, 0x95, 0xc4, 0x87, 0x31, - 0x56, 0x4d, 0xc5, 0x24, 0xaa, 0xf6, 0x42, 0x09, 0xeb, 0x29, 0xcf, 0x28, 0xfa, 0xdb, 0x84, 0xfe, - 0x61, 0x42, 0x87, 0xb1, 0xf3, 0x24, 0x17, 0x22, 0xdf, 0x31, 0xac, 0x6d, 0x59, 0xfd, 0x11, 0x93, - 0xb2, 0xe9, 0x32, 0x9c, 0x41, 0x2e, 0x72, 0xa1, 0x25, 0x6e, 0x55, 0x37, 0x1d, 0x1d, 0x01, 0x1c, - 0x2e, 0xae, 0x59, 0xd3, 0x2e, 0x6a, 0x49, 0xe8, 0x27, 0xa6, 0xe6, 0x44, 0x11, 0x6b, 0x0a, 0xcd, - 0x16, 0xc4, 0x06, 0x1e, 0xf0, 0xfb, 0x61, 0x80, 0xfe, 0x13, 0x04, 0x25, 0x4d, 0xc5, 0x62, 0x6d, - 0xb5, 0x2c, 0x68, 0x6e, 0x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bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x51, 0x41, 0x8b, 0xd3, 0x40, + 0x18, 0xcd, 0xb8, 0x41, 0xd6, 0x59, 0xd9, 0x2d, 0x61, 0x0f, 0x31, 0x42, 0x08, 0x2b, 0x62, 0x10, + 0x32, 0xe3, 0x66, 0x0f, 0x5e, 0xbc, 0xd4, 0x6e, 0x84, 0x5e, 0xa4, 0xc4, 0x14, 0xaa, 0x97, 0x30, + 0x99, 0x8e, 0xe9, 0x60, 0x93, 0x09, 0x9d, 0x49, 0x31, 0xff, 0xa0, 0xf4, 0xe4, 0x1f, 0xe8, 0xc9, + 0x3f, 0xe3, 0xb1, 0x47, 0x8f, 0xd2, 0xfe, 0x11, 0xc9, 0x04, 0xdb, 0x1e, 0x3c, 0xec, 0xed, 0xf1, + 0xf8, 0xde, 0x9b, 0xf7, 0xe6, 0xc1, 0x3b, 0x9e, 0x51, 0x4c, 0xaa, 0x6a, 0xce, 0x29, 0x51, 0x5c, + 0x94, 0x12, 0xf3, 0x52, 0xb1, 0x05, 0x9d, 0x11, 0x5e, 0xa6, 0x84, 0x52, 0x51, 0x97, 0x4a, 0xe2, + 0xe5, 0x2d, 0x56, 0x4d, 0xc5, 0x24, 0xaa, 0x16, 0x42, 0x09, 0xeb, 0x15, 0xcf, 0x28, 0x3a, 0x15, + 0xa1, 0xff, 0x88, 0xd0, 0xf2, 0xd6, 0x79, 0x96, 0x0b, 0x91, 0xcf, 0x19, 0xd6, 0xb2, 0xac, 0xfe, + 0x8a, 0x49, 0xd9, 0x74, 0x1e, 0xce, 0x75, 0x2e, 0x72, 0xa1, 0x21, 0x6e, 0x51, 0xc7, 0xde, 0xac, + 0x00, 0x7c, 0x3e, 0x3c, 0x78, 0xf5, 0x3b, 0xab, 0x11, 0xa1, 0xdf, 0x98, 0xba, 0x27, 0x8a, 0x58, + 0x7d, 0x68, 0xb6, 0x41,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, 0xe1, 0xdb, 0xe0, 0xf8, 0x51, + 0xc1, 0x61, 0x66, 0xbd, 0x71, 0xf6, 0x58, 0x57, 0xba, 0xfb, 0x1b, 0x00, 0x00, 0xff, 0xff, 0xfa, + 0xbe, 0xe0, 0xb6, 0x1b, 0x02, 0x00, 0x00, } func (m *InterchainAccountPacketData) Marshal() (dAtA []byte, err error) { diff --git a/proto/ibc/applications/interchain_accounts/v1/types.proto b/proto/ibc/applications/interchain_accounts/v1/types.proto index b8f3683ba44..fe19488d986 100644 --- a/proto/ibc/applications/interchain_accounts/v1/types.proto +++ b/proto/ibc/applications/interchain_accounts/v1/types.proto @@ -5,19 +5,21 @@ import "google/protobuf/any.proto"; import "gogoproto/gogo.proto"; option go_package = "github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"; -// The different types of interchain account transactions -// EXECUTE_TX is used when sending a TX from the controller side to the host side. The host side will execute the tx on -// behalf of the interchain account. +// Type defines a classification of message issued from a controller chain to its associated interchain accounts +// host enum Type { option (gogoproto.goproto_enum_prefix) = false; - // Execute message type - TYPE_EXECUTE_TX_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "EXECUTE_TX"]; + + // Default zero value enumeration + TYPE_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "UNSPECIFIED"]; + // Execute a transaction on an interchain accounts host chain + TYPE_EXECUTE_TX = 1 [(gogoproto.enumvalue_customname) = "EXECUTE_TX"]; } // InterchainAccountPacketData is comprised of a raw transaction, type of transaction and optional memo field. message InterchainAccountPacketData { - Type type = 1; - bytes data = 2; + Type type = 1; + bytes data = 2; string memo = 3; } @@ -25,4 +27,3 @@ message InterchainAccountPacketData { message CosmosTx { repeated google.protobuf.Any messages = 1; } - From bbf1bd11ce378c67bd34654bc1420d5d2a75249d Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 13 Oct 2021 13:33:38 +0200 Subject: [PATCH 2/2] Update modules/apps/27-interchain-accounts/types/packet_test.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> --- modules/apps/27-interchain-accounts/types/packet_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/27-interchain-accounts/types/packet_test.go b/modules/apps/27-interchain-accounts/types/packet_test.go index d205a1d007c..1c8d5c5fc4f 100644 --- a/modules/apps/27-interchain-accounts/types/packet_test.go +++ b/modules/apps/27-interchain-accounts/types/packet_test.go @@ -33,7 +33,7 @@ func (suite *TypesTestSuite) TestValidateBasic() { "type unspecified", types.InterchainAccountPacketData{ Type: types.UNSPECIFIED, - Data: nil, + Data: []byte("data"), Memo: "memo", }, false,