-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Verify Client on Connection Handshake #7057
Changes from 20 commits
aa03892
a7e8646
c8fb33b
fe85a62
ec7edae
56f9773
fa09c9d
1d370e1
8c0a908
7fcf263
69846c4
8ffd01b
73c1786
7d38197
9d3657b
bdf83b5
88ee0d6
7b1ecd7
b6f29a6
4c105fa
dcb0865
2395231
b22a493
6b34ef6
1e56cf3
fd1a83a
ba8e093
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,17 @@ package keeper | |
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"strings" | ||
|
||
"github.com/tendermint/tendermint/libs/log" | ||
"github.com/tendermint/tendermint/light" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec" | ||
codectypes "github.com/cosmos/cosmos-sdk/codec/types" | ||
"github.com/cosmos/cosmos-sdk/store/prefix" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" | ||
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" | ||
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" | ||
|
@@ -197,6 +200,48 @@ func (k Keeper) GetSelfConsensusState(ctx sdk.Context, height uint64) (exported. | |
return consensusState, true | ||
} | ||
|
||
// ValidateSelfClient validates the client parameters for a client of the running chain | ||
// This function is only used to validate the client state the counterparty stores for this chain | ||
func (k Keeper) ValidateSelfClient(ctx sdk.Context, clientState exported.ClientState) error { | ||
tmClient, ok := clientState.(*ibctmtypes.ClientState) | ||
if !ok { | ||
return sdkerrors.Wrapf(types.ErrInvalidClient, "client must be a Tendermint client, expected: %T, got: %T", | ||
&ibctmtypes.ClientState{}, tmClient) | ||
} | ||
|
||
if ctx.ChainID() != tmClient.ChainId { | ||
return sdkerrors.Wrapf(types.ErrInvalidClient, "invalid chain-id. expected: %s, got: %s", | ||
ctx.ChainID(), tmClient.ChainId) | ||
} | ||
|
||
if tmClient.LatestHeight > uint64(ctx.BlockHeight()) { | ||
return sdkerrors.Wrapf(types.ErrInvalidClient, "client has LatestHeight %d greater than chain height %d", | ||
tmClient.LatestHeight, ctx.BlockHeight()) | ||
} | ||
|
||
expectedProofSpecs := commitmenttypes.GetSDKSpecs() | ||
if !reflect.DeepEqual(expectedProofSpecs, tmClient.ProofSpecs) { | ||
return sdkerrors.Wrapf(types.ErrInvalidClient, "client has invalid proof specs. expected: %v got: %v", | ||
expectedProofSpecs, tmClient.ProofSpecs) | ||
} | ||
|
||
if err := light.ValidateTrustLevel(tmClient.TrustLevel.ToTendermint()); err != nil { | ||
return sdkerrors.Wrapf(types.ErrInvalidClient, "trust-level invalid: %v", err) | ||
} | ||
|
||
expectedUbdPeriod := k.stakingKeeper.UnbondingTime(ctx) | ||
if expectedUbdPeriod != tmClient.UnbondingPeriod { | ||
return sdkerrors.Wrapf(types.ErrInvalidClient, "invalid unbonding period. expected: %s, got: %s", | ||
expectedUbdPeriod, tmClient.UnbondingPeriod) | ||
} | ||
|
||
if tmClient.UnbondingPeriod < tmClient.TrustingPeriod { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is currently the only check I enforce on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so; although some values (almost unbonding period and very very low) are practically unworkable, that should be paid attention to by users or relayers when creating a client |
||
return sdkerrors.Wrapf(types.ErrInvalidClient, "unbonding period must be greater than trusting period. unbonding period (%d) < trusting period (%d)", | ||
tmClient.UnbondingPeriod, tmClient.TrustingPeriod) | ||
} | ||
return nil | ||
} | ||
|
||
// IterateClients provides an iterator over all stored light client State | ||
// objects. For each State object, cb will be called. If the cb returns true, | ||
// the iterator will close and stop. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't check:
Maximum clock drift can vary, so I think it's alright not to check that, but we should just make sure there aren't any values which will cause Tendermint to throw errors.
We should probably verify that the latter is
0
initially? Not required security-wise though.Once we add an epoch number we'll need to check that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I can add a frozen check, also epoch is implicitly checked by checking equality on
chainID