Skip to content

Commit

Permalink
Add verification calls in ChanUpgradeAck.
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisJim committed Aug 8, 2023
1 parent 5721b4d commit 46fdceb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
24 changes: 24 additions & 0 deletions modules/core/04-channel/keeper/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion modules/core/04-channel/keeper/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 46fdceb

Please sign in to comment.