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

chore: disallow localhost client creation in 02-client #3114

Merged
merged 3 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
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,
Comment on lines +34 to +37
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've adapted the tests here slightly. This one was actually setup incorrectly and the case was failing on clientState.Initialise() due to non-matching consensus state, rather than it being an unsupported client. Solomachine is now in the list of allowed clients so this test case should pass.

},
{
"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
6 changes: 5 additions & 1 deletion modules/core/02-client/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

var (
// DefaultAllowedClients are "06-solomachine" and "07-tendermint"
DefaultAllowedClients = []string{exported.Solomachine, exported.Tendermint, exported.Localhost}
DefaultAllowedClients = []string{exported.Solomachine, exported.Tendermint}

// KeyAllowedClients is store's key for AllowedClients Params
KeyAllowedClients = []byte("AllowedClients")
Expand Down Expand Up @@ -48,6 +48,10 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {

// IsAllowedClient checks if the given client type is registered on the allowlist.
func (p Params) IsAllowedClient(clientType string) bool {
if clientType == exported.Localhost {
return false
}

for _, allowedClient := range p.AllowedClients {
if allowedClient == clientType {
return true
Expand Down