Skip to content

Commit

Permalink
fix: check pubkey type from validator params (#724)
Browse files Browse the repository at this point in the history
* fix: check pubkey type from validator params

* docs: add changelog

* test: remove comments

* Update CHANGELOG.md

Co-authored-by: Youngtaek Yoon <noreply@yoon.anonaddy.me>

Co-authored-by: Youngtaek Yoon <noreply@yoon.anonaddy.me>
  • Loading branch information
dudong2 and 0Tech authored Oct 18, 2022
1 parent 15168bf commit f856957
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
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

0 comments on commit f856957

Please sign in to comment.