Improve support for IdentifierPath (solidity 0.8)

pull/1227/head
Josselin Feist 3 years ago
parent fba37f2c0c
commit 672c4b312c
  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.2-compact.zip
  9. BIN
      tests/ast-parsing/compile/modifier_identifier_path.sol-0.8.3-compact.zip
  10. BIN
      tests/ast-parsing/compile/modifier_identifier_path.sol-0.8.4-compact.zip
  11. BIN
      tests/ast-parsing/compile/modifier_identifier_path.sol-0.8.5-compact.zip
  12. BIN
      tests/ast-parsing/compile/modifier_identifier_path.sol-0.8.6-compact.zip
  13. BIN
      tests/ast-parsing/compile/modifier_identifier_path.sol-0.8.7-compact.zip
  14. BIN
      tests/ast-parsing/compile/modifier_identifier_path.sol-0.8.8-compact.zip
  15. BIN
      tests/ast-parsing/compile/modifier_identifier_path.sol-0.8.9-compact.zip
  16. 10
      tests/ast-parsing/expected/modifier_identifier_path.sol-0.8.0-compact.json
  17. 10
      tests/ast-parsing/expected/modifier_identifier_path.sol-0.8.1-compact.json
  18. 10
      tests/ast-parsing/expected/modifier_identifier_path.sol-0.8.10-compact.json
  19. 10
      tests/ast-parsing/expected/modifier_identifier_path.sol-0.8.11-compact.json
  20. 10
      tests/ast-parsing/expected/modifier_identifier_path.sol-0.8.12-compact.json
  21. 10
      tests/ast-parsing/expected/modifier_identifier_path.sol-0.8.2-compact.json
  22. 10
      tests/ast-parsing/expected/modifier_identifier_path.sol-0.8.3-compact.json
  23. 10
      tests/ast-parsing/expected/modifier_identifier_path.sol-0.8.4-compact.json
  24. 10
      tests/ast-parsing/expected/modifier_identifier_path.sol-0.8.5-compact.json
  25. 10
      tests/ast-parsing/expected/modifier_identifier_path.sol-0.8.6-compact.json
  26. 10
      tests/ast-parsing/expected/modifier_identifier_path.sol-0.8.7-compact.json
  27. 10
      tests/ast-parsing/expected/modifier_identifier_path.sol-0.8.8-compact.json
  28. 10
      tests/ast-parsing/expected/modifier_identifier_path.sol-0.8.9-compact.json
  29. 12
      tests/ast-parsing/modifier_identifier_path.sol
  30. 1
      tests/test_ast_parsing.py

@ -636,7 +636,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,12 @@
contract A{
function f() public m {}
modifier m()virtual {_;}
}
contract B is A{
modifier m() override {_;}
}

@ -404,6 +404,7 @@ ALL_TESTS = [
# 0.8.9 crashes on our testcase # 0.8.9 crashes on our testcase
Test("user_defined_types.sol", ["0.8.8"] + make_version(8, 10, 12)), Test("user_defined_types.sol", ["0.8.8"] + make_version(8, 10, 12)),
Test("bytes_call.sol", ["0.8.12"]), Test("bytes_call.sol", ["0.8.12"]),
Test("modifier_identifier_path.sol", VERSIONS_08),
] ]
# create the output folder if needed # create the output folder if needed
try: try:

Loading…
Cancel
Save