native: add calling script hash to NEP5 transfer witness check

Fix transfers from contract's address.
This commit is contained in:
Roman Khimov 2020-07-15 22:52:35 +03:00
parent d4c3a17883
commit 59be6bcd24

View file

@ -175,13 +175,15 @@ func (c *nep5TokenNative) transfer(ic *interop.Context, from, to util.Uint160, a
return errors.New("negative amount") return errors.New("negative amount")
} }
caller := ic.ScriptGetter.GetCallingScriptHash()
if caller.Equals(util.Uint160{}) || !from.Equals(caller) {
ok, err := runtime.CheckHashedWitness(ic, from) ok, err := runtime.CheckHashedWitness(ic, from)
if err != nil { if err != nil {
return err return err
} else if !ok { } else if !ok {
return errors.New("invalid signature") return errors.New("invalid signature")
} }
}
isEmpty := from.Equals(to) || amount.Sign() == 0 isEmpty := from.Equals(to) || amount.Sign() == 0
inc := amount inc := amount
if isEmpty { if isEmpty {