From 012a853b9248f2fd85c9101a9a41fbefa6e562ab Mon Sep 17 00:00:00 2001 From: DimitrisJim Date: Tue, 8 Aug 2023 16:51:35 +0300 Subject: [PATCH] call verification of counterparty channel, upgrade in upgradetry. --- modules/core/04-channel/keeper/upgrade.go | 24 +++++++++++++++++++ .../core/04-channel/keeper/upgrade_test.go | 11 ++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/modules/core/04-channel/keeper/upgrade.go b/modules/core/04-channel/keeper/upgrade.go index 20dd1c7d14c..ee9ce6c2849 100644 --- a/modules/core/04-channel/keeper/upgrade.go +++ b/modules/core/04-channel/keeper/upgrade.go @@ -168,6 +168,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 be42bebf33d..0758a8d09c2 100644 --- a/modules/core/04-channel/keeper/upgrade_test.go +++ b/modules/core/04-channel/keeper/upgrade_test.go @@ -258,7 +258,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} },