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 all 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 @@ -103,6 +103,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/724) add checking pubkey type from validator params
* (x/staking) [\#726](https://github.com/line/lbm-sdk/pull/726) check allowedList size in StakeAuthorization.Accept()

### Breaking Changes
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