diff --git a/pkg/config/protocol_config.go b/pkg/config/protocol_config.go index 943ad6791..6dc745504 100644 --- a/pkg/config/protocol_config.go +++ b/pkg/config/protocol_config.go @@ -130,6 +130,9 @@ func (p *ProtocolConfiguration) Validate() error { } var arr = make([]heightNumber, 0, len(p.CommitteeHistory)) for h, n := range p.CommitteeHistory { + if n == 0 { + return fmt.Errorf("invalid CommitteeHistory: bad members count (%d) for height %d", n, h) + } if int(n) > len(p.StandbyCommittee) { return fmt.Errorf("too small StandbyCommittee for required number of committee members at %d", h) } @@ -148,6 +151,9 @@ func (p *ProtocolConfiguration) Validate() error { } arr = arr[:0] for h, n := range p.ValidatorsHistory { + if n == 0 { + return fmt.Errorf("invalid ValidatorsHistory: bad members count (%d) for height %d", n, h) + } if int(n) > len(p.StandbyCommittee) { return fmt.Errorf("too small StandbyCommittee for required number of validators at %d", h) } diff --git a/pkg/config/protocol_config_test.go b/pkg/config/protocol_config_test.go index 05731813b..c95a2fc1a 100644 --- a/pkg/config/protocol_config_test.go +++ b/pkg/config/protocol_config_test.go @@ -110,6 +110,28 @@ func TestProtocolConfigurationValidation(t *testing.T) { ValidatorsHistory: map[uint32]uint32{0: 4, 100: 4}, } require.Error(t, p.Validate()) + p = &ProtocolConfiguration{ + StandbyCommittee: []string{ + "02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2", + "02103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e", + "03d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699", + "02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62", + }, + CommitteeHistory: map[uint32]uint32{0: 0, 100: 4}, + ValidatorsHistory: map[uint32]uint32{0: 1, 100: 4}, + } + require.Error(t, p.Validate()) + p = &ProtocolConfiguration{ + StandbyCommittee: []string{ + "02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2", + "02103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e", + "03d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699", + "02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62", + }, + CommitteeHistory: map[uint32]uint32{0: 1, 100: 4}, + ValidatorsHistory: map[uint32]uint32{0: 0, 100: 4}, + } + require.Error(t, p.Validate()) p = &ProtocolConfiguration{ Hardforks: map[string]uint32{ "Unknown": 123, // Unknown hard-fork.