Skip to content

Commit

Permalink
Add solo machine timestamp check (cosmos#7392)
Browse files Browse the repository at this point in the history
* add check in header updates for non decreasing timestamp

Add check in update.go that the header timestamp is non decreasing compared to the consensus state timestamp. Unit test added in update_test.go

* update error message

* update godoc

Co-authored-by: Federico Kunze <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 25, 2020
1 parent 0ddb2bd commit 2a4d0ec
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
12 changes: 11 additions & 1 deletion x/ibc/light-clients/solomachine/types/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
// CheckHeaderAndUpdateState checks if the provided header is valid and updates
// the consensus state if appropriate. It returns an error if:
// - the client or header provided are not parseable to solo machine types
// - the header sequence does not match the current sequence
// - the header timestamp is less than the consensus state timestamp
// - the currently registered public key did not provide the update signature
func (cs ClientState) CheckHeaderAndUpdateState(
ctx sdk.Context, cdc codec.BinaryMarshaler, clientStore sdk.KVStore,
Expand All @@ -37,7 +39,15 @@ func checkHeader(cdc codec.BinaryMarshaler, clientState *ClientState, header *He
if header.Sequence != clientState.Sequence {
return sdkerrors.Wrapf(
clienttypes.ErrInvalidHeader,
"sequence provided in the header does not match the client state sequence (%d != %d)", header.Sequence, clientState.Sequence,
"header sequence does not match the client state sequence (%d != %d)", header.Sequence, clientState.Sequence,
)
}

// assert update timestamp is not less than current consensus state timestamp
if header.Timestamp < clientState.ConsensusState.Timestamp {
return sdkerrors.Wrapf(
clienttypes.ErrInvalidHeader,
"header timestamp is less than to the consensus state timestamp (%d < %d)", header.Timestamp, clientState.ConsensusState.Timestamp,
)
}

Expand Down
9 changes: 9 additions & 0 deletions x/ibc/light-clients/solomachine/types/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ func (suite *SoloMachineTestSuite) TestCheckHeaderAndUpdateState() {
},
false,
},
{
"invalid timestamp in header",
func() {
clientState = suite.solomachine.ClientState()
h := suite.solomachine.CreateHeader()
h.Timestamp--
header = h
}, false,
},
{
"signature uses wrong sequence",
func() {
Expand Down

0 comments on commit 2a4d0ec

Please sign in to comment.