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

solo machine proof height fix #123

Closed
wants to merge 2 commits into from
Closed
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
3 changes: 2 additions & 1 deletion modules/light-clients/06-solomachine/spec/01_concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ proof, err := cdc.MarshalBinaryBare(timestampedSignatureData)
```

NOTE: At the end of this process, the sequence associated with the key needs to be updated.
The sequence must be incremented each time proof is generated.
The sequence must be incremented each time proof is generated. The proof height provided
to the SDK messages are discarded and not used.

## Updates By Header

Expand Down
1 change: 1 addition & 0 deletions modules/light-clients/06-solomachine/spec/04_messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ order: 4

The messages used to initialize a solo machine light client are defined in the
core sub-module [02-client](../../../core/spec/04_messages.md).

48 changes: 18 additions & 30 deletions modules/light-clients/06-solomachine/types/client_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ func (cs ClientState) VerifyUpgradeAndUpdateState(
func (cs *ClientState) VerifyClientState(
store sdk.KVStore,
cdc codec.BinaryMarshaler,
height exported.Height,
_ exported.Height,
prefix exported.Prefix,
counterpartyClientIdentifier string,
proof []byte,
clientState exported.ClientState,
) error {
publicKey, sigData, timestamp, sequence, err := produceVerificationArgs(cdc, cs, height, prefix, proof)
publicKey, sigData, timestamp, sequence, err := produceVerificationArgs(cdc, cs, prefix, proof)
if err != nil {
return err
}
Expand Down Expand Up @@ -140,14 +140,14 @@ func (cs *ClientState) VerifyClientState(
func (cs *ClientState) VerifyClientConsensusState(
store sdk.KVStore,
cdc codec.BinaryMarshaler,
height exported.Height,
_ exported.Height,
counterpartyClientIdentifier string,
consensusHeight exported.Height,
prefix exported.Prefix,
proof []byte,
consensusState exported.ConsensusState,
) error {
publicKey, sigData, timestamp, sequence, err := produceVerificationArgs(cdc, cs, height, prefix, proof)
publicKey, sigData, timestamp, sequence, err := produceVerificationArgs(cdc, cs, prefix, proof)
if err != nil {
return err
}
Expand Down Expand Up @@ -178,13 +178,13 @@ func (cs *ClientState) VerifyClientConsensusState(
func (cs *ClientState) VerifyConnectionState(
store sdk.KVStore,
cdc codec.BinaryMarshaler,
height exported.Height,
_ exported.Height,
prefix exported.Prefix,
proof []byte,
connectionID string,
connectionEnd exported.ConnectionI,
) error {
publicKey, sigData, timestamp, sequence, err := produceVerificationArgs(cdc, cs, height, prefix, proof)
publicKey, sigData, timestamp, sequence, err := produceVerificationArgs(cdc, cs, prefix, proof)
if err != nil {
return err
}
Expand Down Expand Up @@ -215,14 +215,14 @@ func (cs *ClientState) VerifyConnectionState(
func (cs *ClientState) VerifyChannelState(
store sdk.KVStore,
cdc codec.BinaryMarshaler,
height exported.Height,
_ exported.Height,
prefix exported.Prefix,
proof []byte,
portID,
channelID string,
channel exported.ChannelI,
) error {
publicKey, sigData, timestamp, sequence, err := produceVerificationArgs(cdc, cs, height, prefix, proof)
publicKey, sigData, timestamp, sequence, err := produceVerificationArgs(cdc, cs, prefix, proof)
if err != nil {
return err
}
Expand Down Expand Up @@ -253,7 +253,7 @@ func (cs *ClientState) VerifyChannelState(
func (cs *ClientState) VerifyPacketCommitment(
store sdk.KVStore,
cdc codec.BinaryMarshaler,
height exported.Height,
_ exported.Height,
_ uint64,
_ uint64,
prefix exported.Prefix,
Expand All @@ -263,7 +263,7 @@ func (cs *ClientState) VerifyPacketCommitment(
packetSequence uint64,
commitmentBytes []byte,
) error {
publicKey, sigData, timestamp, sequence, err := produceVerificationArgs(cdc, cs, height, prefix, proof)
publicKey, sigData, timestamp, sequence, err := produceVerificationArgs(cdc, cs, prefix, proof)
if err != nil {
return err
}
Expand Down Expand Up @@ -294,7 +294,7 @@ func (cs *ClientState) VerifyPacketCommitment(
func (cs *ClientState) VerifyPacketAcknowledgement(
store sdk.KVStore,
cdc codec.BinaryMarshaler,
height exported.Height,
_ exported.Height,
_ uint64,
_ uint64,
prefix exported.Prefix,
Expand All @@ -304,7 +304,7 @@ func (cs *ClientState) VerifyPacketAcknowledgement(
packetSequence uint64,
acknowledgement []byte,
) error {
publicKey, sigData, timestamp, sequence, err := produceVerificationArgs(cdc, cs, height, prefix, proof)
publicKey, sigData, timestamp, sequence, err := produceVerificationArgs(cdc, cs, prefix, proof)
if err != nil {
return err
}
Expand Down Expand Up @@ -336,7 +336,7 @@ func (cs *ClientState) VerifyPacketAcknowledgement(
func (cs *ClientState) VerifyPacketReceiptAbsence(
store sdk.KVStore,
cdc codec.BinaryMarshaler,
height exported.Height,
_ exported.Height,
_ uint64,
_ uint64,
prefix exported.Prefix,
Expand All @@ -345,7 +345,7 @@ func (cs *ClientState) VerifyPacketReceiptAbsence(
channelID string,
packetSequence uint64,
) error {
publicKey, sigData, timestamp, sequence, err := produceVerificationArgs(cdc, cs, height, prefix, proof)
publicKey, sigData, timestamp, sequence, err := produceVerificationArgs(cdc, cs, prefix, proof)
if err != nil {
return err
}
Expand Down Expand Up @@ -376,7 +376,7 @@ func (cs *ClientState) VerifyPacketReceiptAbsence(
func (cs *ClientState) VerifyNextSequenceRecv(
store sdk.KVStore,
cdc codec.BinaryMarshaler,
height exported.Height,
_ exported.Height,
_ uint64,
_ uint64,
prefix exported.Prefix,
Expand All @@ -385,7 +385,7 @@ func (cs *ClientState) VerifyNextSequenceRecv(
channelID string,
nextSequenceRecv uint64,
) error {
publicKey, sigData, timestamp, sequence, err := produceVerificationArgs(cdc, cs, height, prefix, proof)
publicKey, sigData, timestamp, sequence, err := produceVerificationArgs(cdc, cs, prefix, proof)
if err != nil {
return err
}
Expand Down Expand Up @@ -418,15 +418,9 @@ func (cs *ClientState) VerifyNextSequenceRecv(
func produceVerificationArgs(
cdc codec.BinaryMarshaler,
cs *ClientState,
height exported.Height,
prefix exported.Prefix,
proof []byte,
) (cryptotypes.PubKey, signing.SignatureData, uint64, uint64, error) {
if revision := height.GetRevisionNumber(); revision != 0 {
return nil, nil, 0, 0, sdkerrors.Wrapf(sdkerrors.ErrInvalidHeight, "revision must be 0 for solomachine, got revision-number: %d", revision)
}
// sequence is encoded in the revision height of height struct
sequence := height.GetRevisionHeight()
if cs.IsFrozen() {
return nil, nil, 0, 0, clienttypes.ErrClientFrozen
}
Expand Down Expand Up @@ -464,14 +458,6 @@ func produceVerificationArgs(
return nil, nil, 0, 0, sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "consensus state cannot be empty")
}

latestSequence := cs.GetLatestHeight().GetRevisionHeight()
if latestSequence != sequence {
return nil, nil, 0, 0, sdkerrors.Wrapf(
sdkerrors.ErrInvalidHeight,
"client state sequence != proof sequence (%d != %d)", latestSequence, sequence,
)
}

if cs.ConsensusState.GetTimestamp() > timestamp {
return nil, nil, 0, 0, sdkerrors.Wrapf(ErrInvalidProof, "the consensus state timestamp is greater than the signature timestamp (%d >= %d)", cs.ConsensusState.GetTimestamp(), timestamp)
}
Expand All @@ -481,6 +467,8 @@ func produceVerificationArgs(
return nil, nil, 0, 0, err
}

sequence := cs.GetLatestHeight().GetRevisionHeight()

return publicKey, sigData, timestamp, sequence, nil
}

Expand Down