core: check for permission in System.Contract.Call(Ex)

This commit is contained in:
Evgenii Stratonikov 2020-06-09 16:24:03 +03:00
parent 5514b3f52f
commit c69f8a2fa3
2 changed files with 13 additions and 13 deletions

View file

@ -88,15 +88,6 @@ type ContractMD struct {
Methods map[string]MethodAndPrice
}
// GetContract returns script of the contract with the specified hash.
func (ic *Context) GetContract(h util.Uint160) []byte {
cs, err := ic.DAO.GetContractState(h)
if err != nil {
return nil
}
return cs.Script
}
// NewContractMD returns Contract with the specified list of methods.
func NewContractMD(name string) *ContractMD {
c := &ContractMD{

View file

@ -484,12 +484,21 @@ func contractCallExInternal(ic *interop.Context, v *vm.VM, h []byte, method stac
if err != nil {
return errors.New("invalid contract hash")
}
script := ic.GetContract(u)
if script == nil {
cs, err := ic.DAO.GetContractState(u)
if err != nil {
return errors.New("contract not found")
}
// TODO perform flags checking after #923
v.LoadScript(script)
bs, err := method.TryBytes()
if err != nil {
return err
}
curr, err := ic.DAO.GetContractState(v.GetCurrentScriptHash())
if err == nil {
if !curr.Manifest.CanCall(&cs.Manifest, string(bs)) {
return errors.New("disallowed method call")
}
}
v.LoadScript(cs.Script)
v.Estack().PushVal(args)
v.Estack().PushVal(method)
return nil