From 59be6bcd24f9c38c684c07c60bbeb967057e4f3b Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 15 Jul 2020 22:52:35 +0300 Subject: [PATCH] native: add calling script hash to NEP5 transfer witness check Fix transfers from contract's address. --- pkg/core/native/native_nep5.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pkg/core/native/native_nep5.go b/pkg/core/native/native_nep5.go index 65b039e5c..393e6eabc 100644 --- a/pkg/core/native/native_nep5.go +++ b/pkg/core/native/native_nep5.go @@ -175,13 +175,15 @@ func (c *nep5TokenNative) transfer(ic *interop.Context, from, to util.Uint160, a return errors.New("negative amount") } - ok, err := runtime.CheckHashedWitness(ic, from) - if err != nil { - return err - } else if !ok { - return errors.New("invalid signature") + caller := ic.ScriptGetter.GetCallingScriptHash() + if caller.Equals(util.Uint160{}) || !from.Equals(caller) { + ok, err := runtime.CheckHashedWitness(ic, from) + if err != nil { + return err + } else if !ok { + return errors.New("invalid signature") + } } - isEmpty := from.Equals(to) || amount.Sign() == 0 inc := amount if isEmpty {