diff --git a/modules/core/04-channel/keeper/upgrade.go b/modules/core/04-channel/keeper/upgrade.go index 96e0ddd4e2c..546d0414f74 100644 --- a/modules/core/04-channel/keeper/upgrade.go +++ b/modules/core/04-channel/keeper/upgrade.go @@ -163,6 +163,30 @@ func (k Keeper) ChanUpgradeTry( FlushStatus: types.NOTINFLUSH, } + // verify the counterparty channel state containing the upgrade sequence + if err := k.connectionKeeper.VerifyChannelState( + ctx, + connection, + proofHeight, proofCounterpartyChannel, + channel.Counterparty.PortId, + channel.Counterparty.ChannelId, + counterpartyChannel, + ); err != nil { + return types.Upgrade{}, errorsmod.Wrap(err, "failed to verify counterparty channel state") + } + + // verifies the proof that a particular proposed upgrade has been stored in the upgrade path of the counterparty + if err := k.connectionKeeper.VerifyChannelUpgrade( + ctx, + channel.Counterparty.PortId, + channel.Counterparty.ChannelId, + connection, + counterpartyUpgrade, + proofCounterpartyUpgrade, proofHeight, + ); err != nil { + return types.Upgrade{}, errorsmod.Wrap(err, "failed to verify counterparty upgrade") + } + if err = k.startFlushUpgradeHandshake( ctx, portID, channelID, diff --git a/modules/core/04-channel/keeper/upgrade_test.go b/modules/core/04-channel/keeper/upgrade_test.go index 38aa94d9f05..d01515c4a8e 100644 --- a/modules/core/04-channel/keeper/upgrade_test.go +++ b/modules/core/04-channel/keeper/upgrade_test.go @@ -251,7 +251,16 @@ func (suite *KeeperTestSuite) TestChanUpgradeTry() { types.ErrInvalidUpgrade, }, { - "startFlushUpgradeHandshake fails due to proof verification failure, counterparty upgrade connection hops are tampered with", + "fails due to proof verification failure, counterparty channel ordering does not match expected ordering", + func() { + channel := path.EndpointB.GetChannel() + channel.Ordering = types.ORDERED + path.EndpointB.SetChannel(channel) + }, + commitmenttypes.ErrInvalidProof, + }, + { + "fails due to proof verification failure, counterparty upgrade connection hops are tampered with", func() { counterpartyUpgrade.Fields.ConnectionHops = []string{ibctesting.InvalidID} },