Merge pull request #2142 from nspcc-dev/fix-customgroups-witness-scope

runtime: fix CustomGroups witness
This commit is contained in:
Roman Khimov 2021-08-26 18:13:08 +03:00 committed by GitHub
commit 7b9558d756
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 25 deletions

View file

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

View file

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