compiler: extend permission check to runtime hashes

If a method is known at compile time we can still check
if it is present in the list of methods of at least one contract.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgeniy Stratonikov 2021-06-25 10:54:00 +03:00
parent 4249674ddc
commit aa76383fa7
4 changed files with 39 additions and 32 deletions

View file

@ -159,34 +159,27 @@ func (c *codegen) processNotify(f *funcScope, args []ast.Expr) {
}
func (c *codegen) processContractCall(f *funcScope, args []ast.Expr) {
var u util.Uint160
// For stdlib calls it is `interop.Hash160(constHash)`
// so we can determine hash at compile-time.
ce, ok := args[0].(*ast.CallExpr)
if !ok || len(ce.Args) != 1 {
return
if ok && len(ce.Args) == 1 {
// Ensure this is a type conversion, not a simple invoke.
se, ok := ce.Fun.(*ast.SelectorExpr)
if ok {
name, _ := c.getFuncNameFromSelector(se)
if _, ok := c.funcs[name]; !ok {
value := c.typeAndValueOf(ce.Args[0]).Value
if value != nil {
s := constant.StringVal(value)
copy(u[:], s) // constant must be big-endian
}
}
}
}
// Ensure this is a type conversion, not a simple invoke.
se, ok := ce.Fun.(*ast.SelectorExpr)
if !ok {
return
}
name, _ := c.getFuncNameFromSelector(se)
if _, ok := c.funcs[name]; ok {
return
}
value := c.typeAndValueOf(ce.Args[0]).Value
if value == nil {
return
}
s := constant.StringVal(value)
var u util.Uint160
copy(u[:], s) // constant must be big-endian
value = c.typeAndValueOf(args[1]).Value
value := c.typeAndValueOf(args[1]).Value
if value == nil {
return
}