Skip to content

Commit

Permalink
add domain separation between port and channel (#7960)
Browse files Browse the repository at this point in the history
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
colin-axner and mergify[bot] authored Nov 17, 2020
1 parent a7435d0 commit 03c8fb3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion x/ibc/applications/transfer/types/keys.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types

import (
"fmt"

"github.com/tendermint/tendermint/crypto"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -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))))
}
24 changes: 24 additions & 0 deletions x/ibc/applications/transfer/types/keys_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 03c8fb3

Please sign in to comment.