From de4ed7d020c2ece8b0683d608389016d4b121c45 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 24 Aug 2021 15:50:24 +0300 Subject: [PATCH] runtime: fix CustomGroups witness See neo-project/neo#2586. --- pkg/core/interop/runtime/witness.go | 8 ++------ pkg/core/interop_system_test.go | 20 +------------------- 2 files changed, 3 insertions(+), 25 deletions(-) diff --git a/pkg/core/interop/runtime/witness.go b/pkg/core/interop/runtime/witness.go index 900f5d282..2eb5766af 100644 --- a/pkg/core/interop/runtime/witness.go +++ b/pkg/core/interop/runtime/witness.go @@ -49,16 +49,12 @@ func checkScope(ic *interop.Context, tx *transaction.Transaction, v *vm.VM, hash } } if c.Scopes&transaction.CustomGroups != 0 { - callingScriptHash := v.GetCallingScriptHash() - if callingScriptHash.Equals(util.Uint160{}) { - return false, nil - } if !v.Context().GetCallFlags().Has(callflag.ReadStates) { return false, errors.New("missing ReadStates call flag") } - cs, err := ic.GetContract(callingScriptHash) + cs, err := ic.GetContract(v.GetCurrentScriptHash()) if err != nil { - return false, fmt.Errorf("unable to find calling script: %w", err) + return false, nil } // check if the current group is the required one for _, allowedGroup := range c.AllowedGroups { diff --git a/pkg/core/interop_system_test.go b/pkg/core/interop_system_test.go index 06d89814f..809f38b12 100644 --- a/pkg/core/interop_system_test.go +++ b/pkg/core/interop_system_test.go @@ -1119,23 +1119,6 @@ func TestRuntimeCheckWitness(t *testing.T) { ic.VM.LoadScriptWithHash([]byte{0x1}, random.Uint160(), callflag.AllowCall) check(t, ic, hash.BytesBE(), true) }) - t.Run("CustomGroups, unknown contract", func(t *testing.T) { - hash := random.Uint160() - tx := &transaction.Transaction{ - Signers: []transaction.Signer{ - { - Account: hash, - Scopes: transaction.CustomGroups, - AllowedGroups: []*keys.PublicKey{}, - }, - }, - } - ic.Container = tx - callingScriptHash := scriptHash - loadScriptWithHashAndFlags(ic, script, callingScriptHash, callflag.All) - ic.VM.LoadScriptWithHash([]byte{0x1}, random.Uint160(), callflag.ReadStates) - check(t, ic, hash.BytesBE(), true) - }) }) }) t.Run("positive", func(t *testing.T) { @@ -1200,7 +1183,7 @@ func TestRuntimeCheckWitness(t *testing.T) { check(t, ic, hash.BytesBE(), false, true) }) t.Run("CustomGroups", func(t *testing.T) { - t.Run("empty calling scripthash", func(t *testing.T) { + t.Run("unknown scripthash", func(t *testing.T) { hash := random.Uint160() tx := &transaction.Transaction{ Signers: []transaction.Signer{ @@ -1244,7 +1227,6 @@ func TestRuntimeCheckWitness(t *testing.T) { } require.NoError(t, bc.contracts.Management.PutContractState(ic.DAO, contractState)) loadScriptWithHashAndFlags(ic, contractScript, contractScriptHash, callflag.All) - ic.VM.LoadScriptWithHash([]byte{0x1}, random.Uint160(), callflag.ReadStates) ic.Container = tx check(t, ic, targetHash.BytesBE(), false, true) })