Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: impl check reject transfer if len(hops) > 0 and ics20-1 #6675

5 changes: 5 additions & 0 deletions modules/apps/transfer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ func (k Keeper) sendTransfer(
return 0, errorsmod.Wrapf(ibcerrors.ErrInvalidRequest, "cannot transfer multiple coins with ics20-1")
}

// reject transfer forwarding hops is not empty with ics20-1
if appVersion == types.V1 && len(forwarding.Hops) > 0 {
return 0, errorsmod.Wrapf(ibcerrors.ErrInvalidRequest, "reject transfer forwarding hops is not empty with ics20-1")
}

crodriguezvega marked this conversation as resolved.
Show resolved Hide resolved
destinationPort := channel.Counterparty.PortId
destinationChannel := channel.Counterparty.ChannelId

Expand Down
49 changes: 47 additions & 2 deletions modules/apps/transfer/keeper/relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (suite *KeeperTestSuite) TestSendTransfer() {
timeoutHeight clienttypes.Height
memo string
expEscrowAmount sdkmath.Int // total amount in escrow for denom on receiving chain

forwarding types.Forwarding
)

testCases := []struct {
Expand Down Expand Up @@ -80,6 +80,35 @@ func (suite *KeeperTestSuite) TestSendTransfer() {
},
nil,
},
{
"successful transfer len hops is empty with ics20-1",
func() {
expEscrowAmount = sdkmath.NewInt(100)

// Set version to isc20-1.
path.EndpointA.UpdateChannel(func(channel *channeltypes.Channel) {
channel.Version = types.V1
})
},
nil,
},
{
"successful transfer len hops is not empty with ics20-2",
func() {
expEscrowAmount = sdkmath.NewInt(100)

// Set version to isc20-2.
path.EndpointA.UpdateChannel(func(channel *channeltypes.Channel) {
channel.Version = types.V2
})
crodriguezvega marked this conversation as resolved.
Show resolved Hide resolved

forwarding = types.NewForwarding(false, types.Hop{
PortId: path.EndpointA.ChannelConfig.PortID,
ChannelId: path.EndpointA.ChannelID,
})
},
nil,
},
{
"successful transfer of IBC token with memo",
func() {
Expand Down Expand Up @@ -146,6 +175,21 @@ func (suite *KeeperTestSuite) TestSendTransfer() {
},
channeltypes.ErrInvalidPacket,
},
{
"failure: transfer len hops is not empty with ics20-1",
func() {
// Set version to isc20-1.
path.EndpointA.UpdateChannel(func(channel *channeltypes.Channel) {
channel.Version = types.V1
})

forwarding = types.NewForwarding(false, types.Hop{
PortId: path.EndpointA.ChannelConfig.PortID,
ChannelId: path.EndpointA.ChannelID,
})
},
ibcerrors.ErrInvalidRequest,
},
}

for _, tc := range testCases {
Expand All @@ -162,6 +206,7 @@ func (suite *KeeperTestSuite) TestSendTransfer() {
memo = ""
timeoutHeight = suite.chainB.GetTimeoutHeight()
expEscrowAmount = sdkmath.ZeroInt()
forwarding = emptyForwarding

// create IBC token on chainA
transferMsg := types.NewMsgTransfer(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, sdk.NewCoins(coin), suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String(), suite.chainA.GetTimeoutHeight(), 0, "", emptyForwarding)
Expand All @@ -184,7 +229,7 @@ func (suite *KeeperTestSuite) TestSendTransfer() {
suite.chainB.SenderAccount.GetAddress().String(),
timeoutHeight, 0, // only use timeout height
memo,
emptyForwarding,
forwarding,
)

res, err := suite.chainA.GetSimApp().TransferKeeper.Transfer(suite.chainA.GetContext(), msg)
Expand Down
Loading