diff --git a/pkg/core/native/designate.go b/pkg/core/native/designate.go index 8383d5c4f..6225e8cd1 100644 --- a/pkg/core/native/designate.go +++ b/pkg/core/native/designate.go @@ -30,6 +30,9 @@ type Designate struct { const ( designateContractID = -5 designateName = "Designation" + + // maxNodeCount is the maximum number of nodes to set the role for. + maxNodeCount = 32 ) // Role represents type of participant. @@ -45,6 +48,7 @@ const ( var ( ErrInvalidRole = errors.New("invalid role") ErrEmptyNodeList = errors.New("node list is empty") + ErrLargeNodeList = errors.New("node list is too large") ) func isValidRole(r Role) bool { @@ -162,9 +166,13 @@ func (s *Designate) designateAsRole(ic *interop.Context, args []stackitem.Item) // DesignateAsRole sets nodes for role r. func (s *Designate) DesignateAsRole(ic *interop.Context, r Role, pubs keys.PublicKeys) error { - if len(pubs) == 0 { + length := len(pubs) + if length == 0 { return ErrEmptyNodeList } + if length > maxNodeCount { + return ErrLargeNodeList + } if !isValidRole(r) { return ErrInvalidRole } diff --git a/pkg/core/native_designate_test.go b/pkg/core/native_designate_test.go index c15098a59..83d7e31c1 100644 --- a/pkg/core/native_designate_test.go +++ b/pkg/core/native_designate_test.go @@ -92,6 +92,9 @@ func TestDesignate_DesignateAsRole(t *testing.T) { err = des.DesignateAsRole(ic, native.RoleOracle, keys.PublicKeys{}) require.True(t, errors.Is(err, native.ErrEmptyNodeList), "got: %v", err) + err = des.DesignateAsRole(ic, native.RoleOracle, make(keys.PublicKeys, 32+1)) + require.True(t, errors.Is(err, native.ErrLargeNodeList), "got: %v", err) + priv, err := keys.NewPrivateKey() require.NoError(t, err) pub := priv.PublicKey()