Merge pull request #1227 from crytic/dev-modifier-identifier-path

Improve identifier path support
pull/1348/head
Feist Josselin 2 years ago committed by GitHub
commit a2779257de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      slither/solc_parsing/expressions/expression_parsing.py
  2. 13
      slither/solc_parsing/expressions/find_variable.py
  3. BIN
      tests/ast-parsing/compile/modifier_identifier_path.sol-0.8.0-compact.zip
  4. BIN
      tests/ast-parsing/compile/modifier_identifier_path.sol-0.8.1-compact.zip
  5. BIN
      tests/ast-parsing/compile/modifier_identifier_path.sol-0.8.10-compact.zip
  6. BIN
      tests/ast-parsing/compile/modifier_identifier_path.sol-0.8.11-compact.zip
  7. BIN
      tests/ast-parsing/compile/modifier_identifier_path.sol-0.8.12-compact.zip
  8. BIN
      tests/ast-parsing/compile/modifier_identifier_path.sol-0.8.13-compact.zip
  9. BIN
      tests/ast-parsing/compile/modifier_identifier_path.sol-0.8.14-compact.zip
  10. BIN
      tests/ast-parsing/compile/modifier_identifier_path.sol-0.8.15-compact.zip
  11. BIN
      tests/ast-parsing/compile/modifier_identifier_path.sol-0.8.2-compact.zip
  12. BIN
      tests/ast-parsing/compile/modifier_identifier_path.sol-0.8.3-compact.zip
  13. BIN
      tests/ast-parsing/compile/modifier_identifier_path.sol-0.8.4-compact.zip
  14. BIN
      tests/ast-parsing/compile/modifier_identifier_path.sol-0.8.5-compact.zip
  15. BIN
      tests/ast-parsing/compile/modifier_identifier_path.sol-0.8.6-compact.zip
  16. BIN
      tests/ast-parsing/compile/modifier_identifier_path.sol-0.8.7-compact.zip
  17. BIN
      tests/ast-parsing/compile/modifier_identifier_path.sol-0.8.8-compact.zip
  18. BIN
      tests/ast-parsing/compile/modifier_identifier_path.sol-0.8.9-compact.zip
  19. 10
      tests/ast-parsing/expected/modifier_identifier_path.sol-0.8.0-compact.json
  20. 10
      tests/ast-parsing/expected/modifier_identifier_path.sol-0.8.1-compact.json
  21. 10
      tests/ast-parsing/expected/modifier_identifier_path.sol-0.8.10-compact.json
  22. 10
      tests/ast-parsing/expected/modifier_identifier_path.sol-0.8.11-compact.json
  23. 10
      tests/ast-parsing/expected/modifier_identifier_path.sol-0.8.12-compact.json
  24. 10
      tests/ast-parsing/expected/modifier_identifier_path.sol-0.8.13-compact.json
  25. 10
      tests/ast-parsing/expected/modifier_identifier_path.sol-0.8.14-compact.json
  26. 10
      tests/ast-parsing/expected/modifier_identifier_path.sol-0.8.15-compact.json
  27. 10
      tests/ast-parsing/expected/modifier_identifier_path.sol-0.8.2-compact.json
  28. 10
      tests/ast-parsing/expected/modifier_identifier_path.sol-0.8.3-compact.json
  29. 10
      tests/ast-parsing/expected/modifier_identifier_path.sol-0.8.4-compact.json
  30. 10
      tests/ast-parsing/expected/modifier_identifier_path.sol-0.8.5-compact.json
  31. 10
      tests/ast-parsing/expected/modifier_identifier_path.sol-0.8.6-compact.json
  32. 10
      tests/ast-parsing/expected/modifier_identifier_path.sol-0.8.7-compact.json
  33. 10
      tests/ast-parsing/expected/modifier_identifier_path.sol-0.8.8-compact.json
  34. 10
      tests/ast-parsing/expected/modifier_identifier_path.sol-0.8.9-compact.json
  35. 12
      tests/ast-parsing/modifier_identifier_path.sol
  36. 1
      tests/test_ast_parsing.py

@ -643,7 +643,9 @@ def parse_expression(expression: Dict, caller_context: CallerContextExpression)
else: else:
referenced_declaration = None referenced_declaration = None
var, was_created = find_variable(value, caller_context, referenced_declaration) var, was_created = find_variable(
value, caller_context, referenced_declaration, is_identifier_path=True
)
if was_created: if was_created:
var.set_offset(src, caller_context.compilation_unit) var.set_offset(src, caller_context.compilation_unit)

@ -155,6 +155,7 @@ def _find_in_contract(
contract: Optional[Contract], contract: Optional[Contract],
contract_declarer: Optional[Contract], contract_declarer: Optional[Contract],
is_super: bool, is_super: bool,
is_identifier_path: bool = False,
) -> Optional[Union[Variable, Function, Contract, Event, Enum, Structure, CustomError]]: ) -> Optional[Union[Variable, Function, Contract, Event, Enum, Structure, CustomError]]:
if contract is None or contract_declarer is None: if contract is None or contract_declarer is None:
return None return None
@ -197,6 +198,13 @@ def _find_in_contract(
if var_name in modifiers: if var_name in modifiers:
return modifiers[var_name] return modifiers[var_name]
if is_identifier_path:
for sig, modifier in modifiers.items():
if "(" in sig:
sig = sig[0 : sig.find("(")]
if sig == var_name:
return modifier
# structures are looked on the contract declarer # structures are looked on the contract declarer
structures = contract.structures_as_dict structures = contract.structures_as_dict
if var_name in structures: if var_name in structures:
@ -294,6 +302,7 @@ def find_variable(
caller_context: CallerContextExpression, caller_context: CallerContextExpression,
referenced_declaration: Optional[int] = None, referenced_declaration: Optional[int] = None,
is_super: bool = False, is_super: bool = False,
is_identifier_path: bool = False,
) -> Tuple[ ) -> Tuple[
Union[ Union[
Variable, Variable,
@ -321,6 +330,8 @@ def find_variable(
:type referenced_declaration: :type referenced_declaration:
:param is_super: :param is_super:
:type is_super: :type is_super:
:param is_identifier_path:
:type is_identifier_path:
:return: :return:
:rtype: :rtype:
""" """
@ -381,7 +392,7 @@ def find_variable(
else: else:
assert isinstance(underlying_func, FunctionTopLevel) assert isinstance(underlying_func, FunctionTopLevel)
ret = _find_in_contract(var_name, contract, contract_declarer, is_super) ret = _find_in_contract(var_name, contract, contract_declarer, is_super, is_identifier_path)
if ret: if ret:
return ret, False return ret, False

@ -0,0 +1,10 @@
{
"A": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n",
"m()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: _ 1\n\"];\n}\n"
},
"B": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n",
"m()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: _ 1\n\"];\n}\n"
}
}

@ -0,0 +1,10 @@
{
"A": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n",
"m()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: _ 1\n\"];\n}\n"
},
"B": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n",
"m()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: _ 1\n\"];\n}\n"
}
}

@ -0,0 +1,10 @@
{
"A": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n",
"m()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: _ 1\n\"];\n}\n"
},
"B": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n",
"m()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: _ 1\n\"];\n}\n"
}
}

@ -0,0 +1,10 @@
{
"A": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n",
"m()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: _ 1\n\"];\n}\n"
},
"B": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n",
"m()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: _ 1\n\"];\n}\n"
}
}

@ -0,0 +1,10 @@
{
"A": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n",
"m()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: _ 1\n\"];\n}\n"
},
"B": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n",
"m()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: _ 1\n\"];\n}\n"
}
}

@ -0,0 +1,10 @@
{
"A": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n",
"m()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: _ 1\n\"];\n}\n"
},
"B": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n",
"m()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: _ 1\n\"];\n}\n"
}
}

@ -0,0 +1,10 @@
{
"A": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n",
"m()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: _ 1\n\"];\n}\n"
},
"B": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n",
"m()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: _ 1\n\"];\n}\n"
}
}

@ -0,0 +1,10 @@
{
"A": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n",
"m()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: _ 1\n\"];\n}\n"
},
"B": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n",
"m()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: _ 1\n\"];\n}\n"
}
}

@ -0,0 +1,10 @@
{
"A": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n",
"m()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: _ 1\n\"];\n}\n"
},
"B": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n",
"m()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: _ 1\n\"];\n}\n"
}
}

@ -0,0 +1,10 @@
{
"A": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n",
"m()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: _ 1\n\"];\n}\n"
},
"B": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n",
"m()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: _ 1\n\"];\n}\n"
}
}

@ -0,0 +1,10 @@
{
"A": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n",
"m()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: _ 1\n\"];\n}\n"
},
"B": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n",
"m()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: _ 1\n\"];\n}\n"
}
}

@ -0,0 +1,10 @@
{
"A": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n",
"m()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: _ 1\n\"];\n}\n"
},
"B": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n",
"m()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: _ 1\n\"];\n}\n"
}
}

@ -0,0 +1,10 @@
{
"A": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n",
"m()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: _ 1\n\"];\n}\n"
},
"B": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n",
"m()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: _ 1\n\"];\n}\n"
}
}

@ -0,0 +1,10 @@
{
"A": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n",
"m()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: _ 1\n\"];\n}\n"
},
"B": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n",
"m()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: _ 1\n\"];\n}\n"
}
}

@ -0,0 +1,10 @@
{
"A": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n",
"m()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: _ 1\n\"];\n}\n"
},
"B": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n",
"m()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: _ 1\n\"];\n}\n"
}
}

@ -0,0 +1,10 @@
{
"A": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n",
"m()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: _ 1\n\"];\n}\n"
},
"B": {
"f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n",
"m()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: _ 1\n\"];\n}\n"
}
}

@ -0,0 +1,12 @@
contract A{
function f() public m {}
modifier m()virtual {_;}
}
contract B is A{
modifier m() override {_;}
}

@ -415,6 +415,7 @@ ALL_TESTS = [
Test("user_defined_value_type/erc20-0.8.8.sol", ["0.8.8"] + make_version(8, 10, 15)), Test("user_defined_value_type/erc20-0.8.8.sol", ["0.8.8"] + make_version(8, 10, 15)),
Test("user_defined_value_type/in_parenthesis-0.8.8.sol", ["0.8.8"] + make_version(8, 10, 15)), Test("user_defined_value_type/in_parenthesis-0.8.8.sol", ["0.8.8"] + make_version(8, 10, 15)),
Test("bytes_call.sol", ["0.8.12"]), Test("bytes_call.sol", ["0.8.12"]),
Test("modifier_identifier_path.sol", VERSIONS_08),
Test("free_functions/libraries_from_free.sol", ["0.8.12"]), Test("free_functions/libraries_from_free.sol", ["0.8.12"]),
Test("free_functions/new_operator.sol", ["0.8.12"]), Test("free_functions/new_operator.sol", ["0.8.12"]),
Test("free_functions/library_constant_function_collision.sol", ["0.8.12"]), Test("free_functions/library_constant_function_collision.sol", ["0.8.12"]),

Loading…
Cancel
Save