Skip to content

Commit

Permalink
smartcontract: require manifest serialization in (*Manifest).IsValid
Browse files Browse the repository at this point in the history
Port the restrictive part of neo-project/neo#2948.

Signed-off-by: Anna Shaleva <[email protected]>
  • Loading branch information
AnnaShaleva committed Nov 22, 2023
1 parent 387c411 commit 6824bd9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/smartcontract/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions pkg/smartcontract/manifest/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package manifest

import (
"encoding/json"
"fmt"
"math/big"
"testing"

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 6824bd9

Please sign in to comment.