manifest: disallow null groups, fix #3522

IsValid() is used by both compiler and ContractManagement then.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
This commit is contained in:
Roman Khimov 2024-07-26 11:22:03 +03:00
parent f0ae14e4db
commit e861aeec2e
4 changed files with 15 additions and 4 deletions

View file

@ -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{
{

View file

@ -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{
{

View file

@ -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)

View file

@ -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}