Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

* (apps/27-gmp) [\#9077](https://github.com/cosmos/ibc-go/pull/9077) Stop validating `AccountIdentifier.Sender` as a local bech32 address in genesis validation/import; the sender is a counterparty identifier (e.g. an EVM hex address), so exported state containing ICS27 accounts could not be validated or re-imported.
* (core/02-client) [\#9080](https://github.com/cosmos/ibc-go/pull/9080) Return an error from `RecoverClient` when the substitute client is of a different client type than the subject instead of panicking in the subject light client module.
* (apps/pfm) [\#9006](https://github.com/cosmos/ibc-go/pull/9006) fix(apps/pfm): remove legacy params before the v3 to v4 migration
* (apps/rate-limiting) [\#8767](https://github.com/cosmos/ibc-go/pull/8767) Fix string conflict in rate-limiting prefix iterator
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/27-gmp/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ func (k *Keeper) InitGenesis(ctx context.Context, data *types.GenesisState) erro
if _, err := sdk.AccAddressFromBech32(account.AccountAddress); err != nil {
return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err)
}
if _, err := sdk.AccAddressFromBech32(account.AccountId.Sender); err != nil {
return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err)
if err := account.AccountId.Validate(); err != nil {
return err
}

ics27Account := types.ICS27Account{
Expand Down
42 changes: 40 additions & 2 deletions modules/apps/27-gmp/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,23 @@ func (s *KeeperTestSuite) TestInitGenesis() {
ibcerrors.ErrInvalidAddress,
},
{
"failure: invalid sender address",
"success: sender is a counterparty (non-bech32) identifier",
func() {
genesisState.Ics27Accounts[0].AccountId.Sender = invalid
genesisState.Ics27Accounts[0].AccountId.Sender = "0x1234567890abcdef1234567890abcdef12345678"
},
nil,
},
{
"failure: empty sender address",
func() {
genesisState.Ics27Accounts[0].AccountId.Sender = " "
},
ibcerrors.ErrInvalidAddress,
},
{
"failure: sender address exceeds max length",
func() {
genesisState.Ics27Accounts[0].AccountId.Sender = ibctesting.GenerateString(types.MaximumSenderLength + 1)
},
ibcerrors.ErrInvalidAddress,
},
Expand Down Expand Up @@ -132,3 +146,27 @@ func (s *KeeperTestSuite) TestExportGenesis() {
s.Require().Equal(sender, genesisState.Ics27Accounts[0].AccountId.Sender)
s.Require().Equal([]byte(testSalt), genesisState.Ics27Accounts[0].AccountId.Salt)
}

// TestGenesisRoundTripRemoteSender ensures that an ICS27 account created for a
// sender that is not a local bech32 address (e.g. an EVM hex address) survives
// an export -> validate -> import genesis round trip.
func (s *KeeperTestSuite) TestGenesisRoundTripRemoteSender() {
s.SetupTest()
ctx := s.chainA.GetContext()
gmpKeeper := s.chainA.GetSimApp().GMPKeeper

evmSender := "0x1234567890abcdef1234567890abcdef12345678"
packetData := types.NewGMPPacketData(evmSender, "", []byte(testSalt), []byte{}, "")

// account creation happens before the (expected) payload execution failure
_, err := gmpKeeper.OnRecvPacket(ctx, &packetData, ibctesting.FirstClientID)
s.Require().ErrorIs(err, types.ErrInvalidPayload)

exported, err := gmpKeeper.ExportGenesis(ctx)
s.Require().NoError(err)
s.Require().Len(exported.Ics27Accounts, 1)
s.Require().Equal(evmSender, exported.Ics27Accounts[0].AccountId.Sender)

s.Require().NoError(exported.Validate())
s.Require().NoError(gmpKeeper.InitGenesis(ctx, exported))
}
4 changes: 2 additions & 2 deletions modules/apps/27-gmp/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ func (s *AppModuleTestSuite) TestValidateGenesis() {
true,
},
{
"failure: invalid sender address",
"failure: empty sender address",
&types.GenesisState{
Ics27Accounts: []types.RegisteredICS27Account{
{
AccountAddress: s.chainA.SenderAccount.GetAddress().String(),
AccountId: types.AccountIdentifier{
ClientId: ibctesting.FirstClientID,
Sender: "invalid",
Sender: "",
Salt: []byte("salt"),
},
},
Expand Down
21 changes: 21 additions & 0 deletions modules/apps/27-gmp/types/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,27 @@ func NewAccountIdentifier(clientID, sender string, salt []byte) AccountIdentifie
}
}

// Validate performs basic validation of the account identifier fields.
// The sender is an opaque identifier on the counterparty chain (for example an
// EVM hex address or a bech32 address with a foreign prefix), so it is only
// checked for presence and length, mirroring GMPPacketData.ValidateBasic.
func (id AccountIdentifier) Validate() error {
if err := host.ClientIdentifierValidator(id.ClientId); err != nil {
return errorsmod.Wrapf(err, "invalid client ID %s", id.ClientId)
}
if strings.TrimSpace(id.Sender) == "" {
return errorsmod.Wrap(ibcerrors.ErrInvalidAddress, "missing sender address")
}
if len(id.Sender) > MaximumSenderLength {
return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "sender address must not exceed %d bytes", MaximumSenderLength)
}
if len(id.Salt) > MaximumSaltLength {
return errorsmod.Wrapf(ErrInvalidSalt, "salt must not exceed %d bytes", MaximumSaltLength)
}

return nil
}

// NewICS27Account creates a new ICS27Account with the given address and accountId.
func NewICS27Account(addr string, accountID *AccountIdentifier) ICS27Account {
return ICS27Account{
Expand Down
11 changes: 2 additions & 9 deletions modules/apps/27-gmp/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"

host "github.com/lfdt-ibc/ibc-go/v11/modules/core/24-host"
ibcerrors "github.com/lfdt-ibc/ibc-go/v11/modules/core/errors"
)

Expand All @@ -25,14 +24,8 @@ func (gs GenesisState) Validate() error {
if _, err := sdk.AccAddressFromBech32(account.AccountAddress); err != nil {
return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err)
}
if _, err := sdk.AccAddressFromBech32(account.AccountId.Sender); err != nil {
return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err)
}
if err := host.ClientIdentifierValidator(account.AccountId.ClientId); err != nil {
return errorsmod.Wrapf(err, "invalid source client ID %s", account.AccountId.ClientId)
}
if len(account.AccountId.Salt) > MaximumSaltLength {
return errorsmod.Wrapf(ErrInvalidSalt, "salt must not exceed %d bytes", MaximumSaltLength)
if err := account.AccountId.Validate(); err != nil {
return err
}
}

Expand Down
36 changes: 34 additions & 2 deletions modules/apps/27-gmp/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,46 @@ func TestGenesisState_Validate(t *testing.T) {
true,
},
{
"failure: invalid sender address",
"success: sender is a counterparty (non-bech32) identifier",
&types.GenesisState{
Ics27Accounts: []types.RegisteredICS27Account{
{
AccountAddress: validAddress,
AccountId: types.AccountIdentifier{
ClientId: validClientID,
Sender: "invalid",
Sender: "0x1234567890abcdef1234567890abcdef12345678",
Salt: []byte("salt"),
},
},
},
},
false,
},
{
"failure: empty sender address",
&types.GenesisState{
Ics27Accounts: []types.RegisteredICS27Account{
{
AccountAddress: validAddress,
AccountId: types.AccountIdentifier{
ClientId: validClientID,
Sender: " ",
Salt: []byte("salt"),
},
},
},
},
true,
},
{
"failure: sender address exceeds max length",
&types.GenesisState{
Ics27Accounts: []types.RegisteredICS27Account{
{
AccountAddress: validAddress,
AccountId: types.AccountIdentifier{
ClientId: validClientID,
Sender: ibctesting.GenerateString(types.MaximumSenderLength + 1),
Salt: []byte("salt"),
},
},
Expand Down