add domain separation between port and channel (#7960)

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
colin axnér 2020-11-17 16:37:20 +01:00 committed by GitHub
parent a7435d03eb
commit 03c8fb313d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -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))))
}

View File

@ -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)
}