diff --git a/x/ibc/applications/transfer/types/keys.go b/x/ibc/applications/transfer/types/keys.go index f1fbffd951..1b0e45b9c7 100644 --- a/x/ibc/applications/transfer/types/keys.go +++ b/x/ibc/applications/transfer/types/keys.go @@ -1,6 +1,8 @@ package types import ( + "fmt" + "github.com/tendermint/tendermint/crypto" sdk "github.com/cosmos/cosmos-sdk/types" @@ -43,5 +45,5 @@ var ( // port associated with the channel ID so that the address created is actually // unique. func GetEscrowAddress(portID, channelID string) sdk.AccAddress { - return sdk.AccAddress(crypto.AddressHash([]byte(portID + channelID))) + return sdk.AccAddress(crypto.AddressHash([]byte(fmt.Sprintf("%s/%s", portID, channelID)))) } diff --git a/x/ibc/applications/transfer/types/keys_test.go b/x/ibc/applications/transfer/types/keys_test.go new file mode 100644 index 0000000000..9ab3314c2e --- /dev/null +++ b/x/ibc/applications/transfer/types/keys_test.go @@ -0,0 +1,24 @@ +package types_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/types" +) + +// Test that there is domain separation between the port id and the channel id otherwise an +// escrow address may overlap with another channel end +func TestGetEscrowAddress(t *testing.T) { + var ( + port1 = "transfer" + channel1 = "channel" + port2 = "transfercha" + channel2 = "nnel" + ) + + escrow1 := types.GetEscrowAddress(port1, channel1) + escrow2 := types.GetEscrowAddress(port2, channel2) + require.NotEqual(t, escrow1, escrow2) +}