From f856957435fee025082a65df37e4e96bbb72dc1f Mon Sep 17 00:00:00 2001 From: Sujong Lee Date: Tue, 18 Oct 2022 12:41:51 +0900 Subject: [PATCH] fix: check pubkey type from validator params (#724) * fix: check pubkey type from validator params * docs: add changelog * test: remove comments * Update CHANGELOG.md Co-authored-by: Youngtaek Yoon Co-authored-by: Youngtaek Yoon --- CHANGELOG.md | 1 + baseapp/params.go | 10 ++++++++++ baseapp/params_test.go | 1 + 3 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fb171aea7..8a6262a3a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/baseapp/params.go b/baseapp/params.go index 502955412d..061c6a17ed 100644 --- a/baseapp/params.go +++ b/baseapp/params.go @@ -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" ) @@ -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 } diff --git a/baseapp/params_test.go b/baseapp/params_test.go index a421d13b65..340be7097a 100644 --- a/baseapp/params_test.go +++ b/baseapp/params_test.go @@ -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 {