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

fix: check pubkey type from validator params #724

Merged
merged 7 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (global) [\#694](https://github.com/line/lbm-sdk/pull/694) replace deprecated functions since go 1.16 or 1.17
* (x/bankplus) [\#705](https://github.com/line/lbm-sdk/pull/705) add missing blockedAddr checking in bankplus
* (x/foundation) [\#712](https://github.com/line/lbm-sdk/pull/712) fix x/foundation EndBlocker
* (baseapp) [\#724](https://github.com/line/lbm-sdk/pull/705) add checking pubkey type from validator params
dudong2 marked this conversation as resolved.
Show resolved Hide resolved

### Breaking Changes
* (proto) [\#564](https://github.com/line/lbm-sdk/pull/564) change gRPC path to original cosmos path
Expand Down
10 changes: 10 additions & 0 deletions baseapp/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

abci "github.com/line/ostracon/abci/types"
ocproto "github.com/line/ostracon/proto/ostracon/types"
octypes "github.com/line/ostracon/types"

sdk "github.com/line/lbm-sdk/types"
)
Expand Down Expand Up @@ -82,5 +83,14 @@ func ValidateValidatorParams(i interface{}) error {
return errors.New("validator allowed pubkey types must not be empty")
}

for _, pubKeyType := range v.PubKeyTypes {
switch pubKeyType {
case octypes.ABCIPubKeyTypeBls12WithEd25519, octypes.ABCIPubKeyTypeEd25519, octypes.ABCIPubKeyTypeSecp256k1, octypes.ABCIPubKeyTypeBls12:
continue
default:
return fmt.Errorf("not-allowed pubkey type: %s", pubKeyType)
}
}

return nil
}
1 change: 1 addition & 0 deletions baseapp/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func TestValidateValidatorParams(t *testing.T) {
{ocproto.ValidatorParams{}, true},
{ocproto.ValidatorParams{PubKeyTypes: []string{}}, true},
{ocproto.ValidatorParams{PubKeyTypes: []string{"secp256k1"}}, false},
{ocproto.ValidatorParams{PubKeyTypes: []string{"invalidPubKeyType"}}, true},
}

for _, tc := range testCases {
Expand Down