From f6319f80e89774ea042f4503e45f951bb754b03b Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 24 Aug 2020 13:18:02 +0300 Subject: [PATCH] interop: allow to call CheckWitness without AllowStates State access is needed only in specific circumstances. --- pkg/core/interop/runtime/witness.go | 7 +++++++ pkg/core/interops.go | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/core/interop/runtime/witness.go b/pkg/core/interop/runtime/witness.go index c06413a8c..d721990c5 100644 --- a/pkg/core/interop/runtime/witness.go +++ b/pkg/core/interop/runtime/witness.go @@ -9,6 +9,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/interop" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" + "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm" ) @@ -20,6 +21,9 @@ func CheckHashedWitness(ic *interop.Context, hash util.Uint160) (bool, error) { return checkScope(ic.DAO, tx, ic.VM, hash) } + if !ic.VM.Context().GetCallFlags().Has(smartcontract.AllowStates) { + return false, errors.New("missing AllowStates call flag") + } return false, errors.New("script container is not a transaction") } @@ -49,6 +53,9 @@ func checkScope(d dao.DAO, tx *transaction.Transaction, v *vm.VM, hash util.Uint if callingScriptHash.Equals(util.Uint160{}) { return false, nil } + if !v.Context().GetCallFlags().Has(smartcontract.AllowStates) { + return false, errors.New("missing AllowStates call flag") + } cs, err := d.GetContractState(callingScriptHash) if err != nil { return false, err diff --git a/pkg/core/interops.go b/pkg/core/interops.go index 7d2a00e1d..4c6ab5af8 100644 --- a/pkg/core/interops.go +++ b/pkg/core/interops.go @@ -77,7 +77,7 @@ var systemInterops = []interop.Function{ {Name: interopnames.SystemJSONDeserialize, Func: json.Deserialize, Price: 500000, ParamCount: 1}, {Name: interopnames.SystemJSONSerialize, Func: json.Serialize, Price: 100000, ParamCount: 1}, {Name: interopnames.SystemRuntimeCheckWitness, Func: runtime.CheckWitness, Price: 30000, - RequiredFlags: smartcontract.AllowStates, ParamCount: 1}, + RequiredFlags: smartcontract.NoneFlag, ParamCount: 1}, {Name: interopnames.SystemRuntimeGasLeft, Func: runtime.GasLeft, Price: 400}, {Name: interopnames.SystemRuntimeGetCallingScriptHash, Func: engineGetCallingScriptHash, Price: 400}, {Name: interopnames.SystemRuntimeGetEntryScriptHash, Func: engineGetEntryScriptHash, Price: 400},