Skip to content

Commit

Permalink
disallow localhost client creation in 02-client (#3114)
Browse files Browse the repository at this point in the history
* disallow localhost client creation, adapt tests

* adapting logic to accomodate usage of allowed clients in InitGenesis

* move localhost check to separate conditional
  • Loading branch information
damiannolan authored Feb 8, 2023
1 parent 40ca344 commit c7d798b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ require (
github.com/stretchr/testify v1.8.1
github.com/tendermint/tendermint v0.37.0-rc2
github.com/tendermint/tm-db v0.6.7
golang.org/x/exp v0.0.0-20221019170559-20944726eadf
google.golang.org/genproto v0.0.0-20221227171554-f9683d7f8bef
google.golang.org/grpc v1.52.3
google.golang.org/protobuf v1.28.1
Expand Down Expand Up @@ -147,6 +146,7 @@ require (
go.etcd.io/bbolt v1.3.6 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.4.0 // indirect
golang.org/x/exp v0.0.0-20221019170559-20944726eadf // indirect
golang.org/x/net v0.4.0 // indirect
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 // indirect
golang.org/x/sys v0.3.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions modules/core/02-client/keeper/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import (
func (k Keeper) CreateClient(
ctx sdk.Context, clientState exported.ClientState, consensusState exported.ConsensusState,
) (string, error) {
if clientState.ClientType() == exported.Localhost {
return "", sdkerrors.Wrapf(types.ErrInvalidClientType, "cannot create client of type: %s", clientState.ClientType())
}

params := k.GetParams(ctx)
if !params.IsAllowedClient(clientState.ClientType()) {
return "", sdkerrors.Wrapf(
Expand Down
31 changes: 24 additions & 7 deletions modules/core/02-client/keeper/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,39 @@ import (
"github.com/cosmos/ibc-go/v7/modules/core/exported"
solomachine "github.com/cosmos/ibc-go/v7/modules/light-clients/06-solomachine"
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
localhost "github.com/cosmos/ibc-go/v7/modules/light-clients/09-localhost"
ibctesting "github.com/cosmos/ibc-go/v7/testing"
)

func (suite *KeeperTestSuite) TestCreateClient() {
cases := []struct {
msg string
clientState exported.ClientState
expPass bool
msg string
clientState exported.ClientState
consensusState exported.ConsensusState
expPass bool
}{
{"success", ibctm.NewClientState(testChainID, ibctm.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, testClientHeight, commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath), true},
{"client type not supported", solomachine.NewClientState(0, &solomachine.ConsensusState{PublicKey: suite.solomachine.ConsensusState().PublicKey, Diversifier: suite.solomachine.Diversifier, Timestamp: suite.solomachine.Time}), false},
{
"success: 07-tendermint client type supported",
ibctm.NewClientState(testChainID, ibctm.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, testClientHeight, commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath),
suite.consensusState,
true,
},
{
"success: 06-solomachine client type supported",
solomachine.NewClientState(0, &solomachine.ConsensusState{PublicKey: suite.solomachine.ConsensusState().PublicKey, Diversifier: suite.solomachine.Diversifier, Timestamp: suite.solomachine.Time}),
&solomachine.ConsensusState{PublicKey: suite.solomachine.ConsensusState().PublicKey, Diversifier: suite.solomachine.Diversifier, Timestamp: suite.solomachine.Time},
true,
},
{
"failure: 09-localhost client type not supported",
localhost.NewClientState(clienttypes.GetSelfHeight(suite.ctx)),
nil,
false,
},
}

for i, tc := range cases {

clientID, err := suite.keeper.CreateClient(suite.ctx, tc.clientState, suite.consensusState)
clientID, err := suite.keeper.CreateClient(suite.ctx, tc.clientState, tc.consensusState)
if tc.expPass {
suite.Require().NoError(err, "valid test case %d failed: %s", i, tc.msg)
suite.Require().NotNil(clientID, "valid test case %d failed: %s", i, tc.msg)
Expand Down

0 comments on commit c7d798b

Please sign in to comment.