From e861aeec2e937750321006b0844e90bd32771823 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 26 Jul 2024 11:22:03 +0300 Subject: [PATCH] manifest: disallow null groups, fix #3522 IsValid() is used by both compiler and ContractManagement then. Signed-off-by: Roman Khimov --- pkg/core/interop/runtime/ext_test.go | 3 ++- pkg/core/native/management_neotest_test.go | 6 ++++-- pkg/smartcontract/manifest/group.go | 3 +++ pkg/smartcontract/manifest/group_test.go | 7 ++++++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/pkg/core/interop/runtime/ext_test.go b/pkg/core/interop/runtime/ext_test.go index f8d2bcf89..7d11f025e 100644 --- a/pkg/core/interop/runtime/ext_test.go +++ b/pkg/core/interop/runtime/ext_test.go @@ -712,7 +712,8 @@ func TestSystemRuntimeNotify_HFBasilisk(t *testing.T) { require.NoError(t, err) m := &manifest.Manifest{ - Name: "ctr", + Name: "ctr", + Groups: []manifest.Group{}, ABI: manifest.ABI{ Methods: []manifest.Method{ { diff --git a/pkg/core/native/management_neotest_test.go b/pkg/core/native/management_neotest_test.go index 8c2f63d7f..7434feb3f 100644 --- a/pkg/core/native/management_neotest_test.go +++ b/pkg/core/native/management_neotest_test.go @@ -52,7 +52,8 @@ func TestManagement_DeployUpdate_HFBasilisk(t *testing.T) { require.NoError(t, err) m := &manifest.Manifest{ - Name: "ctr", + Name: "ctr", + Groups: []manifest.Group{}, ABI: manifest.ABI{ Methods: []manifest.Method{ { @@ -87,7 +88,8 @@ func TestManagement_CallInTheSameBlock(t *testing.T) { require.NoError(t, err) m := &manifest.Manifest{ - Name: "ctr", + Name: "ctr", + Groups: []manifest.Group{}, ABI: manifest.ABI{ Methods: []manifest.Method{ { diff --git a/pkg/smartcontract/manifest/group.go b/pkg/smartcontract/manifest/group.go index 96834ddb0..15485aa3c 100644 --- a/pkg/smartcontract/manifest/group.go +++ b/pkg/smartcontract/manifest/group.go @@ -40,6 +40,9 @@ func (g *Group) IsValid(h util.Uint160) error { // AreValid checks for groups correctness and uniqueness. // If the contract hash is empty, then hash-related checks are omitted. func (g Groups) AreValid(h util.Uint160) error { + if g == nil { + return errors.New("null groups") + } if !h.Equals(util.Uint160{}) { for i := range g { err := g[i].IsValid(h) diff --git a/pkg/smartcontract/manifest/group_test.go b/pkg/smartcontract/manifest/group_test.go index 2390da7f5..d38d8eeb8 100644 --- a/pkg/smartcontract/manifest/group_test.go +++ b/pkg/smartcontract/manifest/group_test.go @@ -19,6 +19,10 @@ func TestGroupJSONInOut(t *testing.T) { } func TestGroupsAreValid(t *testing.T) { + var gps Groups + + require.Error(t, gps.AreValid(util.Uint160{})) // null + h := util.Uint160{42, 42, 42} priv, err := keys.NewPrivateKey() require.NoError(t, err) @@ -29,7 +33,8 @@ func TestGroupsAreValid(t *testing.T) { gcorrect := Group{pub, priv.Sign(h.BytesBE())} gcorrect2 := Group{pub2, priv2.Sign(h.BytesBE())} gincorrect := Group{pub, priv.Sign(h.BytesLE())} - gps := Groups{gcorrect} + + gps = Groups{gcorrect} require.NoError(t, gps.AreValid(h)) gps = Groups{gincorrect}