diff --git a/slither/core/declarations/function.py b/slither/core/declarations/function.py index 016f8af41..1dc3538b3 100644 --- a/slither/core/declarations/function.py +++ b/slither/core/declarations/function.py @@ -202,7 +202,13 @@ class Function(ChildContract, ChildInheritance, SourceMapping): self._name = new_name @property - def scope(self): + def scope(self) -> List[str]: + """ + Return a list of name representing the scope of the function + This is used to model nested functions declared in YUL + + :return: + """ return self._scope @scope.setter diff --git a/slither/core/expressions/binary_operation.py b/slither/core/expressions/binary_operation.py index 6f8c0f15f..591319d29 100644 --- a/slither/core/expressions/binary_operation.py +++ b/slither/core/expressions/binary_operation.py @@ -31,6 +31,9 @@ class BinaryOperationType(Enum): ANDAND = 17 # && OROR = 18 # || + # YUL specific operators + # TODO: investigate if we can remove these + # Find the types earlier on, and do the conversion DIVISION_SIGNED = 19 MODULO_SIGNED = 20 LESS_SIGNED = 21 diff --git a/slither/solc_parsing/declarations/function.py b/slither/solc_parsing/declarations/function.py index d87964ac0..a674c5975 100644 --- a/slither/solc_parsing/declarations/function.py +++ b/slither/solc_parsing/declarations/function.py @@ -18,7 +18,7 @@ from slither.solc_parsing.variables.local_variable_init_from_tuple import ( LocalVariableInitFromTupleSolc, ) from slither.solc_parsing.variables.variable_declaration import MultipleVariablesDeclaration -from slither.solc_parsing.yul.parse_yul import YulObject +from slither.solc_parsing.yul.parse_yul import YulBlock from slither.utils.expression_manipulations import SplitTernaryExpression from slither.visitors.expression.export_values import ExportValues from slither.visitors.expression.has_conditional import HasConditional @@ -81,7 +81,7 @@ class FunctionSolc: self.returns_src = SourceMapping() self._node_to_nodesolc: Dict[Node, NodeSolc] = dict() - self._node_to_yulobject: Dict[Node, YulObject] = dict() + self._node_to_yulobject: Dict[Node, YulBlock] = dict() self._local_variables_parser: List[ Union[LocalVariableSolc, LocalVariableInitFromTupleSolc] @@ -319,9 +319,9 @@ class FunctionSolc: self._node_to_nodesolc[node] = node_parser return node_parser - def _new_yul_object(self, src: Union[str, Dict]) -> YulObject: + def _new_yul_block(self, src: Union[str, Dict]) -> YulBlock: node = self._function.new_node(NodeType.ASSEMBLY, src) - yul_object = YulObject(self._function.contract, node, [self._function.name, f"asm_{len(self._node_to_yulobject)}"], parent_func=self._function) + yul_object = YulBlock(self._function.contract, node, [self._function.name, f"asm_{len(self._node_to_yulobject)}"], parent_func=self._function) self._node_to_yulobject[node] = yul_object return yul_object @@ -821,7 +821,7 @@ class FunctionSolc: # Added with solc 0.6 - the yul code is an AST if 'AST' in statement: self._function.contains_assembly = True - yul_object = self._new_yul_object(statement['src']) + yul_object = self._new_yul_block(statement['src']) entrypoint = yul_object.entrypoint exitpoint = yul_object.convert(statement['AST']) diff --git a/slither/solc_parsing/yul/parse_yul.py b/slither/solc_parsing/yul/parse_yul.py index e22c0f5b4..7812b92d0 100644 --- a/slither/solc_parsing/yul/parse_yul.py +++ b/slither/solc_parsing/yul/parse_yul.py @@ -214,7 +214,12 @@ class YulFunction(YulScope): return yul_node -class YulObject(YulScope): +class YulBlock(YulScope): + """ + A YulBlock represents a standalone yul component. + For example an inline assembly block + + """ __slots__ = ["_entrypoint", "_parent_func", "_nodes"] def __init__(self, contract: Contract, entrypoint: Node, id: List[str], **kwargs):