mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-02-13 05:04:49 +00:00
core: check for permission in System.Contract.Call(Ex)
This commit is contained in:
parent
5514b3f52f
commit
c69f8a2fa3
2 changed files with 13 additions and 13 deletions
|
@ -88,15 +88,6 @@ type ContractMD struct {
|
||||||
Methods map[string]MethodAndPrice
|
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.
|
// NewContractMD returns Contract with the specified list of methods.
|
||||||
func NewContractMD(name string) *ContractMD {
|
func NewContractMD(name string) *ContractMD {
|
||||||
c := &ContractMD{
|
c := &ContractMD{
|
||||||
|
|
|
@ -484,12 +484,21 @@ func contractCallExInternal(ic *interop.Context, v *vm.VM, h []byte, method stac
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("invalid contract hash")
|
return errors.New("invalid contract hash")
|
||||||
}
|
}
|
||||||
script := ic.GetContract(u)
|
cs, err := ic.DAO.GetContractState(u)
|
||||||
if script == nil {
|
if err != nil {
|
||||||
return errors.New("contract not found")
|
return errors.New("contract not found")
|
||||||
}
|
}
|
||||||
// TODO perform flags checking after #923
|
bs, err := method.TryBytes()
|
||||||
v.LoadScript(script)
|
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(args)
|
||||||
v.Estack().PushVal(method)
|
v.Estack().PushVal(method)
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Add table
Reference in a new issue