From 304b9ad3d4cdb76dd043ffdbd99ff30cb9d5cc2d Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 16 Mar 2021 22:47:49 +0300 Subject: [PATCH 1/3] contract: disable notifications for safe methods See neo-project/neo#2339. --- pkg/core/interop/contract/call.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/core/interop/contract/call.go b/pkg/core/interop/contract/call.go index 2bb689138..45963931b 100644 --- a/pkg/core/interop/contract/call.go +++ b/pkg/core/interop/contract/call.go @@ -73,7 +73,7 @@ func callInternal(ic *interop.Context, cs *state.Contract, name string, f callfl hasReturn bool, args []stackitem.Item) error { md := cs.Manifest.ABI.GetMethod(name, len(args)) if md.Safe { - f &^= callflag.WriteStates + f &^= (callflag.WriteStates | callflag.AllowNotify) } else if ctx := ic.VM.Context(); ctx != nil && ctx.IsDeployed() { curr, err := ic.GetContract(ic.VM.GetCurrentScriptHash()) if err == nil { From d1251b8daf41e4e4866518abc25f35532d3b6430 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 16 Mar 2021 22:48:32 +0300 Subject: [PATCH 2/3] core: don't limit on/postPersist methods They read/write/call/notify, so they need everything. --- pkg/core/blockchain.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 96231efc0..25c2ad6d7 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -854,7 +854,7 @@ func (bc *Blockchain) IsExtensibleAllowed(u util.Uint160) bool { func (bc *Blockchain) runPersist(script []byte, block *block.Block, cache *dao.Cached, trig trigger.Type) (*state.AppExecResult, error) { systemInterop := bc.newInteropContext(trig, cache, block, nil) v := systemInterop.SpawnVM() - v.LoadScriptWithFlags(script, callflag.WriteStates|callflag.AllowCall) + v.LoadScriptWithFlags(script, callflag.All) v.SetPriceGetter(systemInterop.GetPrice) if err := v.Run(); err != nil { return nil, fmt.Errorf("VM has failed: %w", err) From 0de72f1dc9dfb627ccf9bf46c51aacacf89e04ba Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 16 Mar 2021 22:49:14 +0300 Subject: [PATCH 3/3] core: fix call flags for Native(On|Post)Persist See neo-project/neo#2339. --- pkg/core/interops.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/core/interops.go b/pkg/core/interops.go index 9cc2aa553..f680a70b3 100644 --- a/pkg/core/interops.go +++ b/pkg/core/interops.go @@ -36,8 +36,8 @@ var systemInterops = []interop.Function{ {Name: interopnames.SystemContractCreateMultisigAccount, Func: contractCreateMultisigAccount, Price: 1 << 8, ParamCount: 2}, {Name: interopnames.SystemContractCreateStandardAccount, Func: contractCreateStandardAccount, Price: 1 << 8, ParamCount: 1}, {Name: interopnames.SystemContractGetCallFlags, Func: contractGetCallFlags, Price: 1 << 10}, - {Name: interopnames.SystemContractNativeOnPersist, Func: native.OnPersist, Price: 0, RequiredFlags: callflag.WriteStates}, - {Name: interopnames.SystemContractNativePostPersist, Func: native.PostPersist, Price: 0, RequiredFlags: callflag.WriteStates}, + {Name: interopnames.SystemContractNativeOnPersist, Func: native.OnPersist, Price: 0, RequiredFlags: callflag.States}, + {Name: interopnames.SystemContractNativePostPersist, Func: native.PostPersist, Price: 0, RequiredFlags: callflag.States}, {Name: interopnames.SystemIteratorCreate, Func: iterator.Create, Price: 1 << 4, ParamCount: 1}, {Name: interopnames.SystemIteratorNext, Func: iterator.Next, Price: 1 << 15, ParamCount: 1}, {Name: interopnames.SystemIteratorValue, Func: iterator.Value, Price: 1 << 4, ParamCount: 1},