From 1998892f270b2573e5e23227e2298aab164b0443 Mon Sep 17 00:00:00 2001 From: rustdev Date: Tue, 19 Mar 2024 16:30:10 +0000 Subject: [PATCH 1/2] introduce the validation to now allow timeout timestamp less then Xnanos --- custom/ibc-transfer/keeper/msg_server.go | 8 ++ .../v1beta1/ibctransfermiddleware.proto | 1 + .../types/ibctransfermiddleware.pb.go | 97 +++++++++++++------ .../types/parachain_token_info.pb.go | 2 +- 4 files changed, 77 insertions(+), 31 deletions(-) diff --git a/custom/ibc-transfer/keeper/msg_server.go b/custom/ibc-transfer/keeper/msg_server.go index 12cf61fd7..991bc55b8 100644 --- a/custom/ibc-transfer/keeper/msg_server.go +++ b/custom/ibc-transfer/keeper/msg_server.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "fmt" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" @@ -29,6 +30,9 @@ func (k msgServer) Transfer(goCtx context.Context, msg *types.MsgTransfer) (*typ if params.ChannelFees != nil && len(params.ChannelFees) > 0 { channelFee := findChannelParams(params.ChannelFees, msg.SourceChannel) if channelFee != nil { + if channelFee.MinTimeoutTimestamp > 0 && msg.TimeoutTimestamp < channelFee.MinTimeoutTimestamp { + return nil, ErrInvalidTimeoutTimestamp + } coin := findCoinByDenom(channelFee.AllowedTokens, msg.Token.Denom) if coin != nil { return &types.MsgTransferResponse{}, nil @@ -88,3 +92,7 @@ func findCoinByDenom(allowedTokens []*ibctransfermiddlewaretypes.CoinItem, denom } return nil // If the denom is not found } + +var ( + ErrInvalidTimeoutTimestamp = fmt.Errorf("proto: incorrect timeout timestamp found during ibc transfer") +) diff --git a/proto/composable/ibctransfermiddleware/v1beta1/ibctransfermiddleware.proto b/proto/composable/ibctransfermiddleware/v1beta1/ibctransfermiddleware.proto index 007daf732..1f15c0510 100644 --- a/proto/composable/ibctransfermiddleware/v1beta1/ibctransfermiddleware.proto +++ b/proto/composable/ibctransfermiddleware/v1beta1/ibctransfermiddleware.proto @@ -19,6 +19,7 @@ message ChannelFee{ string channel = 1; repeated CoinItem allowed_tokens = 2; string fee_address = 3 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + uint64 min_timeout_timestamp = 4; } message CoinItem{ diff --git a/x/ibctransfermiddleware/types/ibctransfermiddleware.pb.go b/x/ibctransfermiddleware/types/ibctransfermiddleware.pb.go index 2d0ea9016..67340cec9 100644 --- a/x/ibctransfermiddleware/types/ibctransfermiddleware.pb.go +++ b/x/ibctransfermiddleware/types/ibctransfermiddleware.pb.go @@ -73,9 +73,10 @@ func (m *Params) GetChannelFees() []*ChannelFee { } type ChannelFee struct { - Channel string `protobuf:"bytes,1,opt,name=channel,proto3" json:"channel,omitempty"` - AllowedTokens []*CoinItem `protobuf:"bytes,2,rep,name=allowed_tokens,json=allowedTokens,proto3" json:"allowed_tokens,omitempty"` - FeeAddress string `protobuf:"bytes,3,opt,name=fee_address,json=feeAddress,proto3" json:"fee_address,omitempty"` + Channel string `protobuf:"bytes,1,opt,name=channel,proto3" json:"channel,omitempty"` + AllowedTokens []*CoinItem `protobuf:"bytes,2,rep,name=allowed_tokens,json=allowedTokens,proto3" json:"allowed_tokens,omitempty"` + FeeAddress string `protobuf:"bytes,3,opt,name=fee_address,json=feeAddress,proto3" json:"fee_address,omitempty"` + MinTimeoutTimestamp uint64 `protobuf:"varint,4,opt,name=min_timeout_timestamp,json=minTimeoutTimestamp,proto3" json:"min_timeout_timestamp,omitempty"` } func (m *ChannelFee) Reset() { *m = ChannelFee{} } @@ -132,6 +133,13 @@ func (m *ChannelFee) GetFeeAddress() string { return "" } +func (m *ChannelFee) GetMinTimeoutTimestamp() uint64 { + if m != nil { + return m.MinTimeoutTimestamp + } + return 0 +} + type CoinItem struct { MinFee types.Coin `protobuf:"bytes,1,opt,name=min_fee,json=minFee,proto3" json:"min_fee"` Percentage int64 `protobuf:"varint,2,opt,name=percentage,proto3" json:"percentage,omitempty"` @@ -195,33 +203,35 @@ func init() { } var fileDescriptor_1193893bc248bc1b = []byte{ - // 406 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x92, 0x41, 0xeb, 0xd3, 0x30, - 0x18, 0xc6, 0x9b, 0x0d, 0x36, 0x97, 0xaa, 0x60, 0x19, 0xd8, 0x0d, 0x8c, 0x63, 0xa7, 0x22, 0xd8, - 0xb2, 0x29, 0x88, 0x07, 0x0f, 0x4e, 0x11, 0xbc, 0x49, 0x15, 0x44, 0x2f, 0x25, 0x6d, 0xdf, 0xd6, - 0x60, 0x93, 0x94, 0x24, 0x6c, 0xfa, 0x2d, 0xfc, 0x18, 0x1e, 0x3d, 0x78, 0xf4, 0x03, 0xec, 0x38, - 0x3c, 0x79, 0x12, 0xd9, 0x0e, 0x7e, 0x0d, 0x69, 0x9b, 0x39, 0x85, 0x09, 0xfe, 0x2f, 0x6d, 0xde, - 0xf7, 0xd7, 0xe7, 0xe9, 0x93, 0xbc, 0xc1, 0x8f, 0x33, 0xc9, 0x6b, 0xa9, 0x69, 0x5a, 0x41, 0xc4, - 0xd2, 0xcc, 0x28, 0x2a, 0x74, 0x01, 0x8a, 0xb3, 0x3c, 0xaf, 0x60, 0x43, 0x15, 0x44, 0xeb, 0x45, - 0x0a, 0x86, 0x2e, 0xce, 0xd3, 0xb0, 0x56, 0xd2, 0x48, 0x2f, 0x38, 0xb9, 0x84, 0xe7, 0xbf, 0xb3, - 0x2e, 0xd3, 0x71, 0x29, 0x4b, 0xd9, 0x8a, 0xa2, 0x66, 0xd5, 0xe9, 0xa7, 0x93, 0x4c, 0x6a, 0x2e, - 0x75, 0xd2, 0x81, 0xae, 0xb0, 0x88, 0x74, 0x55, 0x94, 0x52, 0x7d, 0xca, 0x92, 0x49, 0x26, 0x2c, - 0xbf, 0x46, 0x39, 0x13, 0x32, 0x6a, 0x9f, 0xb6, 0x75, 0xdd, 0x4a, 0xb8, 0x2e, 0xa3, 0xf5, 0xa2, - 0x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bb, 0x27, 0x68, 0xb7, 0x27, 0xe8, 0xc7, 0x9e, 0xa0, 0x0f, - 0x07, 0xe2, 0xec, 0x0e, 0xc4, 0xf9, 0x76, 0x20, 0xce, 0xeb, 0x1b, 0xef, 0xfe, 0x71, 0x15, 0xcd, - 0xfb, 0x1a, 0x74, 0x3a, 0x68, 0x87, 0x79, 0xe7, 0x57, 0x00, 0x00, 0x00, 0xff, 0xff, 0x3e, 0xef, - 0x13, 0x3a, 0xbb, 0x02, 0x00, 0x00, + // 438 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x92, 0x4f, 0x8b, 0xd4, 0x30, + 0x18, 0xc6, 0x27, 0x3b, 0xcb, 0xac, 0x9b, 0x51, 0xc1, 0xba, 0x62, 0x76, 0xc1, 0x38, 0xcc, 0xa9, + 0x08, 0xb6, 0x4c, 0x15, 0xc4, 0x83, 0x07, 0x47, 0x11, 0xbc, 0x49, 0x1d, 0x10, 0xbd, 0x94, 0xb4, + 0x7d, 0x5b, 0x83, 0x4d, 0x52, 0x92, 0xb8, 0xab, 0xdf, 0xc2, 0x8f, 0xe1, 0xd1, 0x83, 0x1f, 0x62, + 0x8f, 0x8b, 0x27, 0x4f, 0x22, 0x33, 0x07, 0xaf, 0x7e, 0x04, 0x69, 0x93, 0x71, 0x14, 0x46, 0x70, + 0x2f, 0x4d, 0xde, 0xf7, 0xd7, 0xe7, 0xc9, 0x93, 0x3f, 0xf8, 0x71, 0xa1, 0x44, 0xab, 0x0c, 0xcb, + 0x1b, 0x88, 0x79, 0x5e, 0x58, 0xcd, 0xa4, 0xa9, 0x40, 0x0b, 0x5e, 0x96, 0x0d, 0x9c, 0x30, 0x0d, + 0xf1, 0xf1, 0x2c, 0x07, 0xcb, 0x66, 0xdb, 0x69, 0xd4, 0x6a, 0x65, 0x55, 0x10, 0x6e, 0x5c, 0xa2, + 0xed, 0xff, 0x79, 0x97, 0xa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xd1, 0x92, 0xdd, 0x09, + 0x0a, 0x77, 0xd3, 0xab, 0x82, 0xcb, 0x85, 0x63, 0x8b, 0x35, 0x9a, 0x72, 0x7c, 0x61, 0x9d, 0x24, + 0x78, 0x80, 0xf7, 0x3a, 0x7d, 0x05, 0xd0, 0xef, 0x77, 0x9c, 0x1c, 0x46, 0x7e, 0xcd, 0xee, 0xfe, + 0xfe, 0x4a, 0x3e, 0xdf, 0x3f, 0xfd, 0x76, 0x73, 0xf0, 0xf1, 0xc7, 0xa7, 0x5b, 0x28, 0x1d, 0x09, + 0x2e, 0xbb, 0xe3, 0xa2, 0x18, 0xb7, 0xa0, 0x0b, 0x90, 0x96, 0xd5, 0x40, 0x76, 0x26, 0x28, 0x1c, + 0xa6, 0x7f, 0x74, 0xe6, 0xf7, 0x4e, 0x97, 0x14, 0x9d, 0x2d, 0x29, 0xfa, 0xbe, 0xa4, 0xe8, 0xc3, + 0x8a, 0x0e, 0xce, 0x56, 0x74, 0xf0, 0x75, 0x45, 0x07, 0xaf, 0x6e, 0xbc, 0xfb, 0xc7, 0xf3, 0xb5, + 0xef, 0x5b, 0x30, 0xf9, 0xa8, 0x7f, 0x00, 0x77, 0x7e, 0x05, 0x00, 0x00, 0xff, 0xff, 0x0a, 0x20, + 0x7e, 0x4d, 0xef, 0x02, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -281,6 +291,11 @@ func (m *ChannelFee) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.MinTimeoutTimestamp != 0 { + i = encodeVarintIbctransfermiddleware(dAtA, i, uint64(m.MinTimeoutTimestamp)) + i-- + dAtA[i] = 0x20 + } if len(m.FeeAddress) > 0 { i -= len(m.FeeAddress) copy(dAtA[i:], m.FeeAddress) @@ -396,6 +411,9 @@ func (m *ChannelFee) Size() (n int) { if l > 0 { n += 1 + l + sovIbctransfermiddleware(uint64(l)) } + if m.MinTimeoutTimestamp != 0 { + n += 1 + sovIbctransfermiddleware(uint64(m.MinTimeoutTimestamp)) + } return n } @@ -630,6 +648,25 @@ func (m *ChannelFee) Unmarshal(dAtA []byte) error { } m.FeeAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MinTimeoutTimestamp", wireType) + } + m.MinTimeoutTimestamp = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowIbctransfermiddleware + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MinTimeoutTimestamp |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipIbctransfermiddleware(dAtA[iNdEx:]) diff --git a/x/transfermiddleware/types/parachain_token_info.pb.go b/x/transfermiddleware/types/parachain_token_info.pb.go index 854ea11c0..ea33c7e44 100644 --- a/x/transfermiddleware/types/parachain_token_info.pb.go +++ b/x/transfermiddleware/types/parachain_token_info.pb.go @@ -28,7 +28,7 @@ var _ = time.Kitchen const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // ParachainIBCTokenInfo represents information about transferable IBC tokens -// from Parachain(Substrate based network). +// from Parachain. type ParachainIBCTokenInfo struct { // ibc_denom is the denomination of the ibced token transferred from the // dotsama chain. From d662505a672ca11e137f251d2f87e50fa22aafe1 Mon Sep 17 00:00:00 2001 From: rustdev Date: Tue, 19 Mar 2024 16:46:50 +0000 Subject: [PATCH 2/2] fix lint --- custom/ibc-transfer/keeper/msg_server.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/custom/ibc-transfer/keeper/msg_server.go b/custom/ibc-transfer/keeper/msg_server.go index 991bc55b8..bb9b825f8 100644 --- a/custom/ibc-transfer/keeper/msg_server.go +++ b/custom/ibc-transfer/keeper/msg_server.go @@ -31,7 +31,7 @@ func (k msgServer) Transfer(goCtx context.Context, msg *types.MsgTransfer) (*typ channelFee := findChannelParams(params.ChannelFees, msg.SourceChannel) if channelFee != nil { if channelFee.MinTimeoutTimestamp > 0 && msg.TimeoutTimestamp < channelFee.MinTimeoutTimestamp { - return nil, ErrInvalidTimeoutTimestamp + return nil, fmt.Errorf("incorrect timeout timestamp found during ibc transfer") } coin := findCoinByDenom(channelFee.AllowedTokens, msg.Token.Denom) if coin != nil { @@ -92,7 +92,3 @@ func findCoinByDenom(allowedTokens []*ibctransfermiddlewaretypes.CoinItem, denom } return nil // If the denom is not found } - -var ( - ErrInvalidTimeoutTimestamp = fmt.Errorf("proto: incorrect timeout timestamp found during ibc transfer") -)