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 upgrade type verification function #3453

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
995c1f1
added validateProposedUpgradeFields function and CheckIsOpen helper f…
colin-axner Apr 12, 2023
f8f6ad4
added unit test for CheckIsOpen
chatton Apr 13, 2023
808ec70
adding unit tests for ValidateProposedUpgradeFields
chatton Apr 13, 2023
8dd0c44
fix linter
chatton Apr 13, 2023
64878ae
update to use errorsmod instead of sdk errors
chatton Apr 13, 2023
51bb7a7
added upgrade verification function and unit tests
chatton Apr 13, 2023
f203df9
improved variable naming
chatton Apr 13, 2023
837e3c9
Merge branch '04-channel-upgrades' into cian/issue#3445-add-verifiabl…
chatton Apr 13, 2023
5f9ad67
re-arranged order of test functions
chatton Apr 13, 2023
7bdf33c
Merge branch 'cian/issue#3445-add-verifiable-upgrade-type-and-validat…
chatton Apr 13, 2023
04dd0af
addressing PR feedback
chatton Apr 13, 2023
d66fe9d
addressing PR feedback
chatton Apr 17, 2023
18dbffe
addressing PR feedback
chatton Apr 17, 2023
a3da022
bump interchain account demo to v0.5.1
chatton Apr 17, 2023
fc7bd1f
merge base branch
chatton Apr 17, 2023
9b71740
remove CheckIsOpen
chatton Apr 17, 2023
7215e84
updated godoc
chatton Apr 17, 2023
0c3774f
Merge branch 'cian/issue#3445-add-verifiable-upgrade-type-and-validat…
chatton Apr 17, 2023
8bb69f3
inverted ordering logic
chatton Apr 17, 2023
b514798
renamed from existingChannel to currentChannel
chatton Apr 17, 2023
6882530
merge 04-channel-upgrades
chatton Apr 18, 2023
aaaf02d
removed unused verify functions
chatton Apr 18, 2023
4e1c741
merge 04-channel-upgrades
chatton Apr 18, 2023
75bc62d
addressing PR feedback
chatton Apr 18, 2023
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
88 changes: 25 additions & 63 deletions modules/core/03-connection/keeper/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,16 +364,15 @@ func (k Keeper) VerifyNextSequenceRecv(
return nil
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the diff in this file is quite confusing, the following functions were removed

  • VerifyChannelUpgradeSequence
  • VerifyChannelUpgradeTimeout

}

// VerifyChannelUpgradeSequence verifies a proof of the upgrade sequence number to be
// used during channel upgrades.
func (k Keeper) VerifyChannelUpgradeSequence(
// VerifyChannelUpgradeError verifies a proof of the provided upgrade error receipt.
func (k Keeper) VerifyChannelUpgradeError(
ctx sdk.Context,
connection exported.ConnectionI,
height exported.Height,
proof []byte,
portID,
channelID string,
upgradeSequence uint64,
errorReceipt channeltypes.ErrorReceipt,
) error {
clientID := connection.GetClientID()
clientState, clientStore, err := k.getClientStateAndVerificationStore(ctx, clientID)
Expand All @@ -385,32 +384,37 @@ func (k Keeper) VerifyChannelUpgradeSequence(
return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status)
}

merklePath := commitmenttypes.NewMerklePath(host.ChannelUpgradeSequencePath(portID, channelID))
merklePath := commitmenttypes.NewMerklePath(host.ChannelUpgradeErrorPath(portID, channelID))
merklePath, err = commitmenttypes.ApplyPrefix(connection.GetCounterparty().GetPrefix(), merklePath)
if err != nil {
return err
}

bz, err := k.cdc.Marshal(&errorReceipt)
if err != nil {
return err
}

if err := clientState.VerifyMembership(
ctx, clientStore, k.cdc, height,
0, 0, // skip delay period checks for non-packet processing verification
proof, merklePath, sdk.Uint64ToBigEndian(upgradeSequence),
proof, merklePath, bz,
); err != nil {
return errorsmod.Wrapf(err, "failed upgrade sequence verification for client (%s)", clientID)
return errorsmod.Wrapf(err, "failed upgrade error receipt verification for client (%s)", clientID)
}

return nil
}

// VerifyChannelUpgradeTimeout verifies the proof that a particular timeout has been stored in the upgrade timeout path.
func (k Keeper) VerifyChannelUpgradeTimeout(
// VerifyChannelUpgradeErrorAbsence verifies a proof of the absence of a
// channel upgrade error.
func (k Keeper) VerifyChannelUpgradeErrorAbsence(
ctx sdk.Context,
connection exported.ConnectionI,
height exported.Height,
proof []byte,
portID,
channelID string,
upgradeTimeout channeltypes.UpgradeTimeout,
) error {
clientID := connection.GetClientID()
clientState, clientStore, err := k.getClientStateAndVerificationStore(ctx, clientID)
Expand All @@ -422,37 +426,32 @@ func (k Keeper) VerifyChannelUpgradeTimeout(
return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status)
}

merklePath := commitmenttypes.NewMerklePath(host.ChannelUpgradeTimeoutPath(portID, channelID))
merklePath := commitmenttypes.NewMerklePath(host.ChannelUpgradeErrorPath(portID, channelID))
merklePath, err = commitmenttypes.ApplyPrefix(connection.GetCounterparty().GetPrefix(), merklePath)
if err != nil {
return err
}

bz, err := k.cdc.Marshal(&upgradeTimeout)
if err != nil {
return err
}

if err := clientState.VerifyMembership(
if err := clientState.VerifyNonMembership(
ctx, clientStore, k.cdc, height,
0, 0, // skip delay period checks for non-packet processing verification
proof, merklePath, bz,
0, 0,
proof, merklePath,
); err != nil {
return errorsmod.Wrapf(err, "failed upgrade timeout verification for client (%s) on channel (%s)", clientID, channelID)
return errorsmod.Wrapf(err, "failed upgrade error receipt absence verification for client (%s)", clientID)
}

return nil
}

// VerifyChannelUpgradeError verifies a proof of the provided upgrade error receipt.
func (k Keeper) VerifyChannelUpgradeError(
// VerifyChannelUpgrade verifies the proof that a particular proposed upgrade has been stored in the upgrade path.
func (k Keeper) VerifyChannelUpgrade(
ctx sdk.Context,
connection exported.ConnectionI,
height exported.Height,
proof []byte,
portID,
channelID string,
errorReceipt channeltypes.ErrorReceipt,
upgrade channeltypes.Upgrade,
) error {
clientID := connection.GetClientID()
clientState, clientStore, err := k.getClientStateAndVerificationStore(ctx, clientID)
Expand All @@ -464,13 +463,13 @@ func (k Keeper) VerifyChannelUpgradeError(
return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status)
}

merklePath := commitmenttypes.NewMerklePath(host.ChannelUpgradeErrorPath(portID, channelID))
merklePath := commitmenttypes.NewMerklePath(host.ChannelUpgradePath(portID, channelID))
merklePath, err = commitmenttypes.ApplyPrefix(connection.GetCounterparty().GetPrefix(), merklePath)
if err != nil {
return err
}

bz, err := k.cdc.Marshal(&errorReceipt)
bz, err := k.cdc.Marshal(&upgrade)
if err != nil {
return err
}
Expand All @@ -480,44 +479,7 @@ func (k Keeper) VerifyChannelUpgradeError(
0, 0, // skip delay period checks for non-packet processing verification
proof, merklePath, bz,
); err != nil {
return errorsmod.Wrapf(err, "failed upgrade error receipt verification for client (%s)", clientID)
}

return nil
}

// VerifyChannelUpgradeErrorAbsence verifies a proof of the absence of a
// channel upgrade error.
func (k Keeper) VerifyChannelUpgradeErrorAbsence(
ctx sdk.Context,
connection exported.ConnectionI,
height exported.Height,
proof []byte,
portID,
channelID string,
) error {
clientID := connection.GetClientID()
clientState, clientStore, err := k.getClientStateAndVerificationStore(ctx, clientID)
if err != nil {
return err
}

if status := k.clientKeeper.GetClientStatus(ctx, clientState, clientID); status != exported.Active {
return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status)
}

merklePath := commitmenttypes.NewMerklePath(host.ChannelUpgradeErrorPath(portID, channelID))
merklePath, err = commitmenttypes.ApplyPrefix(connection.GetCounterparty().GetPrefix(), merklePath)
if err != nil {
return err
}

if err := clientState.VerifyNonMembership(
ctx, clientStore, k.cdc, height,
0, 0,
proof, merklePath,
); err != nil {
return errorsmod.Wrapf(err, "failed upgrade error receipt absence verification for client (%s)", clientID)
return errorsmod.Wrapf(err, "failed upgrade verification for client (%s) on channel (%s)", clientID, channelID)
}

return nil
Expand Down
Loading