diff --git a/pkg/smartcontract/manifest/manifest.go b/pkg/smartcontract/manifest/manifest.go index 5c002381e..900701cef 100644 --- a/pkg/smartcontract/manifest/manifest.go +++ b/pkg/smartcontract/manifest/manifest.go @@ -118,7 +118,19 @@ func (m *Manifest) IsValid(hash util.Uint160) error { return errors.New("duplicate trusted contracts") } } - return Permissions(m.Permissions).AreValid() + err = Permissions(m.Permissions).AreValid() + if err != nil { + return err + } + si, err := m.ToStackItem() + if err != nil { + return fmt.Errorf("failed to check manifest serialisation: %w", err) + } + _, err = stackitem.Serialize(si) + if err != nil { + return fmt.Errorf("manifest is not serializable: %w", err) + } + return nil } // IsStandardSupported denotes whether the specified standard is supported by the contract. diff --git a/pkg/smartcontract/manifest/manifest_test.go b/pkg/smartcontract/manifest/manifest_test.go index 2b9b20bae..47ad9805e 100644 --- a/pkg/smartcontract/manifest/manifest_test.go +++ b/pkg/smartcontract/manifest/manifest_test.go @@ -2,6 +2,7 @@ package manifest import ( "encoding/json" + "fmt" "math/big" "testing" @@ -243,6 +244,18 @@ func TestIsValid(t *testing.T) { require.Error(t, m.IsValid(contractHash)) }) }) + m.Groups = m.Groups[:0] + + t.Run("invalid, unserializable", func(t *testing.T) { + for i := 0; i < stackitem.MaxSerialized; i++ { + m.ABI.Events = append(m.ABI.Events, Event{ + Name: fmt.Sprintf("Event%d", i), + Parameters: []Parameter{}, + }) + } + err := m.IsValid(contractHash) + require.ErrorIs(t, err, stackitem.ErrTooBig) + }) } func TestManifestToStackItem(t *testing.T) {