From c3fabdf19a4dee3412c7f582fa757c9544e5058f Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 21 Sep 2020 17:34:40 +0300 Subject: [PATCH] native: don't push void result in Call This was done in https://github.com/neo-project/neo/pull/1693 for native calls. `OnPersist` script still uses `DROP` though as value is pushed via `CheckReturn` logic for regular calls. --- pkg/core/interop/context.go | 2 ++ pkg/core/interop/contract/call.go | 2 +- pkg/core/native/interop.go | 5 ++++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/core/interop/context.go b/pkg/core/interop/context.go index e1db69a207..61ab10961e 100644 --- a/pkg/core/interop/context.go +++ b/pkg/core/interop/context.go @@ -82,6 +82,7 @@ type Method = func(ic *Context, args []stackitem.Item) stackitem.Item // MethodAndPrice is a native-contract method descriptor. type MethodAndPrice struct { Func Method + MD *manifest.Method Price int64 RequiredFlags smartcontract.CallFlag } @@ -123,6 +124,7 @@ func NewContractMD(name string) *ContractMD { // AddMethod adds new method to a native contract. func (c *ContractMD) AddMethod(md *MethodAndPrice, desc *manifest.Method, safe bool) { c.Manifest.ABI.Methods = append(c.Manifest.ABI.Methods, *desc) + md.MD = desc c.Methods[desc.Name] = *md if safe { c.Manifest.SafeMethods.Add(desc.Name) diff --git a/pkg/core/interop/contract/call.go b/pkg/core/interop/contract/call.go index 86adf6df8e..6560dd2c70 100644 --- a/pkg/core/interop/contract/call.go +++ b/pkg/core/interop/contract/call.go @@ -77,8 +77,8 @@ func callExInternal(ic *interop.Context, h []byte, name string, args []stackitem } // use Jump not Call here because context was loaded in LoadScript above. ic.VM.Jump(ic.VM.Context(), md.Offset) - ic.VM.Context().CheckReturn = true } + ic.VM.Context().CheckReturn = true md = cs.Manifest.ABI.GetMethod(manifest.MethodInit) if md != nil { diff --git a/pkg/core/native/interop.go b/pkg/core/native/interop.go index 0c752f8e2d..05ee8afcb2 100644 --- a/pkg/core/native/interop.go +++ b/pkg/core/native/interop.go @@ -6,6 +6,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/interop" "github.com/nspcc-dev/neo-go/pkg/core/state" + "github.com/nspcc-dev/neo-go/pkg/smartcontract" ) // Deploy deploys native contract. @@ -62,6 +63,8 @@ func Call(ic *interop.Context) error { return errors.New("gas limit exceeded") } result := m.Func(ic, args) - ic.VM.Estack().PushVal(result) + if m.MD.ReturnType != smartcontract.VoidType { + ic.VM.Estack().PushVal(result) + } return nil }