Repository: crytic/slither

Issue:
Fatal error during YUL parsing
```
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/slither_analyzer-0.6.12-py3.6.egg/slither/__main__.py", line 612, in main_impl
    printer_classes)
  File "/usr/local/lib/python3.6/dist-packages/slither_analyzer-0.6.12-py3.6.egg/slither/__main__.py", line 68, in process_all
    compilation, args, detector_classes, printer_classes)
  File "/usr/local/lib/python3.6/dist-packages/slither_analyzer-0.6.12-py3.6.egg/slither/__main__.py", line 55, in process_single
    **vars(args))
  File "/usr/local/lib/python3.6/dist-packages/slither_analyzer-0.6.12-py3.6.egg/slither/slither.py", line 86, in __init__
    self._parser.analyze_contracts()
  File "/usr/local/lib/python3.6/dist-packages/slither_analyzer-0.6.12-py3.6.egg/slither/solc_parsing/slitherSolc.py", line 341, in analyze_contracts
    self._analyze_third_part(contracts_to_be_analyzed, libraries)
  File "/usr/local/lib/python3.6/dist-packages/slither_analyzer-0.6.12-py3.6.egg/slither/solc_parsing/slitherSolc.py", line 438, in _analyze_third_part
    self._analyze_variables_modifiers_functions(contract)
  File "/usr/local/lib/python3.6/dist-packages/slither_analyzer-0.6.12-py3.6.egg/slither/solc_parsing/slitherSolc.py", line 478, in _analyze_variables_modifiers_functions
    contract.analyze_content_functions()
  File "/usr/local/lib/python3.6/dist-packages/slither_analyzer-0.6.12-py3.6.egg/slither/solc_parsing/declarations/contract.py", line 356, in analyze_content_functions
    function_parser.analyze_content()
  File "/usr/local/lib/python3.6/dist-packages/slither_analyzer-0.6.12-py3.6.egg/slither/solc_parsing/declarations/function.py", line 303, in analyze_content
    node_parser.analyze_expressions()
  File "/usr/local/lib/python3.6/dist-packages/slither_analyzer-0.6.12-py3.6.egg/slither/solc_parsing/yul/parse_yul.py", line 254, in analyze_expressions
    node.analyze_expressions()
  File "/usr/local/lib/python3.6/dist-packages/slither_analyzer-0.6.12-py3.6.egg/slither/solc_parsing/yul/parse_yul.py", line 42, in analyze_expressions
    expression = parse_yul(self._scope, self, self._unparsed_expression)
  File "/usr/local/lib/python3.6/dist-packages/slither_analyzer-0.6.12-py3.6.egg/slither/solc_parsing/yul/parse_yul.py", line 663, in parse_yul
    op = parsers.get(ast['nodeType'], parse_yul_unsupported)(root, node, ast)
  File "/usr/local/lib/python3.6/dist-packages/slither_analyzer-0.6.12-py3.6.egg/slither/solc_parsing/yul/parse_yul.py", line 570, in parse_yul_assignment
    return _parse_yul_assignment_common(root, node, ast, 'variableNames')
  File "/usr/local/lib/python3.6/dist-packages/slither_analyzer-0.6.12-py3.6.egg/slither/solc_parsing/yul/parse_yul.py", line 552, in _parse_yul_assignment_common
    rhs = parse_yul(root, node, ast['value'])
  File "/usr/local/lib/python3.6/dist-packages/slither_analyzer-0.6.12-py3.6.egg/slither/solc_parsing/yul/parse_yul.py", line 663, in parse_yul
    op = parsers.get(ast['nodeType'], parse_yul_unsupported)(root, node, ast)
  File "/usr/local/lib/python3.6/dist-packages/slither_analyzer-0.6.12-py3.6.egg/slither/solc_parsing/yul/parse_yul.py", line 574, in parse_yul_function_call
    args = [parse_yul(root, node, arg) for arg in ast['arguments']]
  File "/usr/local/lib/python3.6/dist-packages/slither_analyzer-0.6.12-py3.6.egg/slither/solc_parsing/yul/parse_yul.py", line 574, in <listcomp>
    args = [parse_yul(root, node, arg) for arg in ast['arguments']]
  File "/usr/local/lib/python3.6/dist-packages/slither_analyzer-0.6.12-py3.6.egg/slither/solc_parsing/yul/parse_yul.py", line 663, in parse_yul
    op = parsers.get(ast['nodeType'], parse_yul_unsupported)(root, node, ast)
  File "/usr/local/lib/python3.6/dist-packages/slither_analyzer-0.6.12-py3.6.egg/slither/solc_parsing/yul/parse_yul.py", line 637, in parse_yul_identifier
    raise SlitherException(f"unresolved reference to identifier {name}")
slither.exceptions.SlitherException: unresolved reference to identifier PUBLIC_KEY_OFFSET
ERROR:root:Error:
ERROR:root:unresolved reference to identifier PUBLIC_KEY_OFFSET
ERROR:root:Please report an issue to https://github.com/crytic/slither/issues
```

https://github.com/smartcontractkit/chainlink/blob/116d1d27e14715ed444b62faf8e17b4bd25782c0/evm-contracts/src/v0.6/VRFCoordinator.sol#L228



Discussion:

Resolving patch:
diff --git a/slither/solc_parsing/yul/parse_yul.py b/slither/solc_parsing/yul/parse_yul.py
--- a/slither/solc_parsing/yul/parse_yul.py
+++ b/slither/solc_parsing/yul/parse_yul.py
@@ -611,6 +611,10 @@ def parse_yul_identifier(root: YulScope, node: YulNode, ast: Dict) -> Optional[E
         if variable:
             return Identifier(variable)
 
+        variable = root.parent_func.contract.get_state_variable_from_name(name)
+        if variable:
+            return Identifier(variable)
+
     # check yul-scoped variable
     variable = root.get_yul_local_variable_from_name(name)
     if variable:


Test patch: