From 46fdcebe464c712a30464a05e155dd420ebf3bc3 Mon Sep 17 00:00:00 2001 From: DimitrisJim Date: Tue, 8 Aug 2023 19:08:47 +0300 Subject: [PATCH] Add verification calls in ChanUpgradeAck. --- modules/core/04-channel/keeper/upgrade.go | 24 +++++++++++++++++++ .../core/04-channel/keeper/upgrade_test.go | 19 ++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/modules/core/04-channel/keeper/upgrade.go b/modules/core/04-channel/keeper/upgrade.go index 20dd1c7d14c..3c6b2d89b31 100644 --- a/modules/core/04-channel/keeper/upgrade.go +++ b/modules/core/04-channel/keeper/upgrade.go @@ -269,6 +269,30 @@ func (k Keeper) ChanUpgradeAck( return types.NewUpgradeError(channel.UpgradeSequence, err) } + // verify the counterparty channel state containing the upgrade sequence + if err := k.connectionKeeper.VerifyChannelState( + ctx, + connection, + proofHeight, proofChannel, + channel.Counterparty.PortId, + channel.Counterparty.ChannelId, + counterpartyChannel, + ); err != nil { + return 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, + proofUpgrade, proofHeight, + ); err != nil { + return errorsmod.Wrap(err, "failed to verify counterparty upgrade") + } + if err := k.startFlushUpgradeHandshake(ctx, portID, channelID, upgrade.Fields, counterpartyChannel, counterpartyUpgrade, proofChannel, proofUpgrade, proofHeight); err != nil { return err diff --git a/modules/core/04-channel/keeper/upgrade_test.go b/modules/core/04-channel/keeper/upgrade_test.go index be42bebf33d..dd4dd510d3f 100644 --- a/modules/core/04-channel/keeper/upgrade_test.go +++ b/modules/core/04-channel/keeper/upgrade_test.go @@ -523,12 +523,29 @@ func (suite *KeeperTestSuite) TestChanUpgradeAck() { types.ErrUpgradeNotFound, }, { - "fails due to proof verification failure, counterparty upgrade connection hops are tampered with", + "fails due to upgrade incompatibility", func() { counterpartyUpgrade.Fields.ConnectionHops = []string{ibctesting.InvalidID} }, types.NewUpgradeError(1, types.ErrIncompatibleCounterpartyUpgrade), }, + { + "fails due to proof verification failure, counterparty channel ordering does not match expected ordering", + func() { + channel := path.EndpointA.GetChannel() + channel.Ordering = types.ORDERED + path.EndpointA.SetChannel(channel) + }, + commitmenttypes.ErrInvalidProof, + }, + { + "fails due to proof verification failure, counterparty update has unexpected sequence", + func() { + // Decrementing LatestSequenceSend is sufficient to cause the proof to fail. + counterpartyUpgrade.LatestSequenceSend-- + }, + commitmenttypes.ErrInvalidProof, + }, { "startFlushUpgradeHandshake fails due to mismatch in upgrade ordering", func() {