Skip to content

Commit

Permalink
fix: noop on UpdateState for invalid misbehaviour (#6276)
Browse files Browse the repository at this point in the history
* fix: noop on UpdateState for invalid misbehaviour

* godoc: update godoc for UpdateState

* Update modules/light-clients/07-tendermint/update.go

Co-authored-by: colin axnér <[email protected]>

* chore: add changelog

---------

Co-authored-by: colin axnér <[email protected]>
Co-authored-by: Carlos Rodriguez <[email protected]>
(cherry picked from commit 4f31a3c)

# Conflicts:
#	modules/light-clients/07-tendermint/update.go
  • Loading branch information
damiannolan authored and mergify[bot] committed May 13, 2024
1 parent 2e7e3ea commit a22f9ad
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Ref: https://keepachangelog.com/en/1.0.0/

### State Machine Breaking

* (light-clients/07-tendermint) Fix: No-op to avoid panicking on `UpdateState` for invalid misbehaviour submissions.

### Improvements

* (apps/27-interchain-accounts) [\#6147](https://github.com/cosmos/ibc-go/pull/6147) Emit an event signalling that the host submodule is disabled.
Expand Down
8 changes: 7 additions & 1 deletion modules/light-clients/07-tendermint/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,16 @@ func (cs *ClientState) verifyHeader(
// UpdateState must only be used to update within a single revision, thus header revision number and trusted height's revision
// number must be the same. To update to a new revision, use a separate upgrade path
// UpdateState will prune the oldest consensus state if it is expired.
<<<<<<< HEAD

Check failure on line 131 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / build (arm64)

syntax error: non-declaration statement outside function body

Check failure on line 131 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / build (amd64)

syntax error: non-declaration statement outside function body

Check failure on line 131 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / build (arm)

syntax error: non-declaration statement outside function body

Check failure on line 131 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: non-declaration statement outside function body

Check failure on line 131 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: non-declaration statement outside function body

Check failure on line 131 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: non-declaration statement outside function body

Check failure on line 131 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: non-declaration statement outside function body

Check failure on line 131 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: non-declaration statement outside function body

Check failure on line 131 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: non-declaration statement outside function body

Check failure on line 131 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: non-declaration statement outside function body

Check failure on line 131 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / lint

expected declaration, found '<<' (typecheck)

Check failure on line 131 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: non-declaration statement outside function body
func (cs ClientState) UpdateState(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, clientMsg exported.ClientMessage) []exported.Height {
=======

Check failure on line 133 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / build (arm64)

syntax error: unexpected ==, expecting }

Check failure on line 133 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / build (amd64)

syntax error: unexpected ==, expecting }

Check failure on line 133 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / build (arm)

syntax error: unexpected ==, expecting }

Check failure on line 133 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected ==, expecting }

Check failure on line 133 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected ==, expecting }

Check failure on line 133 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected ==, expecting }

Check failure on line 133 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected ==, expecting }

Check failure on line 133 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected ==, expecting }

Check failure on line 133 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected ==, expecting }

Check failure on line 133 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected ==, expecting }
// If the provided clientMsg is not of type of Header then the handler will noop and empty slice is returned.
func (cs ClientState) UpdateState(ctx sdk.Context, cdc codec.BinaryCodec, clientStore storetypes.KVStore, clientMsg exported.ClientMessage) []exported.Height {
>>>>>>> 4f31a3c6 (fix: noop on UpdateState for invalid misbehaviour (#6276))

Check failure on line 136 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / build (arm64)

syntax error: unexpected >>, expecting }

Check failure on line 136 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / build (arm64)

invalid character U+0023 '#'

Check failure on line 136 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / build (amd64)

syntax error: unexpected >>, expecting }

Check failure on line 136 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / build (amd64)

invalid character U+0023 '#'

Check failure on line 136 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / build (arm)

syntax error: unexpected >>, expecting }

Check failure on line 136 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / build (arm)

invalid character U+0023 '#'

Check failure on line 136 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected >>, expecting }

Check failure on line 136 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / tests (00)

invalid character U+0023 '#'

Check failure on line 136 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected >>, expecting }

Check failure on line 136 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / tests (03)

invalid character U+0023 '#'

Check failure on line 136 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected >>, expecting }

Check failure on line 136 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / tests (01)

invalid character U+0023 '#'

Check failure on line 136 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected >>, expecting }

Check failure on line 136 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / tests (01)

invalid character U+0023 '#'

Check failure on line 136 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected >>, expecting }

Check failure on line 136 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / tests (02)

invalid character U+0023 '#'

Check failure on line 136 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected >>, expecting }

Check failure on line 136 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / tests (02)

invalid character U+0023 '#'

Check failure on line 136 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected >>, expecting }

Check failure on line 136 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / lint

invalid character U+0023 '#' (typecheck)

Check failure on line 136 in modules/light-clients/07-tendermint/update.go

View workflow job for this annotation

GitHub Actions / lint

illegal character U+0023 '#' (typecheck)
header, ok := clientMsg.(*Header)
if !ok {
panic(fmt.Errorf("expected type %T, got %T", &Header{}, clientMsg))
// clientMsg is invalid Misbehaviour, no update necessary
return []exported.Height{}
}

cs.pruneOldestConsensusState(ctx, cdc, clientStore)
Expand Down
9 changes: 6 additions & 3 deletions modules/light-clients/07-tendermint/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,12 @@ func (suite *TendermintTestSuite) TestUpdateState() {
suite.Require().Equal(expConsensusState, updatedConsensusState)

} else {
suite.Require().Panics(func() {
clientState.UpdateState(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), clientStore, clientMessage)
})
consensusHeights = clientState.UpdateState(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), clientStore, clientMessage)
suite.Require().Empty(consensusHeights)

consensusState, found := suite.chainA.GetSimApp().GetIBCKeeper().ClientKeeper.GetClientConsensusState(suite.chainA.GetContext(), path.EndpointA.ClientID, clienttypes.NewHeight(1, uint64(suite.chainB.GetContext().BlockHeight())))
suite.Require().False(found)
suite.Require().Nil(consensusState)
}

// perform custom checks
Expand Down

0 comments on commit a22f9ad

Please sign in to comment.