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:
parent
a7435d03eb
commit
03c8fb313d
|
@ -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))))
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
Loading…
Reference in New Issue