From 19b361b9c0b065c989ae203d82a7a89975f75dac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Thu, 15 Apr 2021 11:35:59 +0200 Subject: [PATCH 1/2] fix solo machine proofHeight bug --- .../06-solomachine/types/client_state.go | 48 +++++++------------ 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/modules/light-clients/06-solomachine/types/client_state.go b/modules/light-clients/06-solomachine/types/client_state.go index efa740cab6a..869e4f4f203 100644 --- a/modules/light-clients/06-solomachine/types/client_state.go +++ b/modules/light-clients/06-solomachine/types/client_state.go @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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, @@ -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 } @@ -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, @@ -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 } @@ -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, @@ -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 } @@ -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, @@ -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 } @@ -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 } @@ -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) } @@ -481,6 +467,8 @@ func produceVerificationArgs( return nil, nil, 0, 0, err } + sequence := cs.GetLatestHeight().GetRevisionHeight() + return publicKey, sigData, timestamp, sequence, nil } From 5908b242aab05e3fdfdc0a6c2f74c0a5ceb6c2c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Thu, 15 Apr 2021 12:15:55 +0200 Subject: [PATCH 2/2] update docs --- modules/light-clients/06-solomachine/spec/01_concepts.md | 3 ++- modules/light-clients/06-solomachine/spec/04_messages.md | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/light-clients/06-solomachine/spec/01_concepts.md b/modules/light-clients/06-solomachine/spec/01_concepts.md index a121803f43c..de62bdf70d4 100644 --- a/modules/light-clients/06-solomachine/spec/01_concepts.md +++ b/modules/light-clients/06-solomachine/spec/01_concepts.md @@ -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 diff --git a/modules/light-clients/06-solomachine/spec/04_messages.md b/modules/light-clients/06-solomachine/spec/04_messages.md index 465ea6229a7..5b159c3976a 100644 --- a/modules/light-clients/06-solomachine/spec/04_messages.md +++ b/modules/light-clients/06-solomachine/spec/04_messages.md @@ -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). +