Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add verification calls for Upgrade, Channel in ChanUpgradeAck. #4312

Merged
merged 2 commits into from
Aug 9, 2023
Merged
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
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 @@ -288,6 +288,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 @@ -525,12 +525,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",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tweaked the message slightly because this now hits the checkForUpgradeCompatibility call that Cian added recently in Ack.

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
Loading