Merge pull request #1568 from crytic/fix-usingfor-libraries

Fix using for directives in libraries
pull/1569/head
Feist Josselin 2 years ago committed by GitHub
commit 8670f1753c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      slither/solc_parsing/slither_compilation_unit_solc.py
  2. BIN
      tests/ast-parsing/compile/using-for-in-library-0.8.0.sol-0.8.15-compact.zip
  3. 8
      tests/ast-parsing/expected/using-for-in-library-0.8.0.sol-0.8.15-compact.json
  4. 14
      tests/ast-parsing/using-for-in-library-0.8.0.sol
  5. 1
      tests/test_ast_parsing.py
  6. 11
      tests/test_features.py

@ -512,7 +512,7 @@ Please rename it, this name is reserved for Slither's internals"""
self._analyze_third_part(contracts_to_be_analyzed, libraries)
[c.set_is_analyzed(False) for c in self._underlying_contract_to_parser.values()]
self._analyze_using_for(contracts_to_be_analyzed)
self._analyze_using_for(contracts_to_be_analyzed, libraries)
self._parsed = True
@ -624,9 +624,14 @@ Please rename it, this name is reserved for Slither's internals"""
else:
contracts_to_be_analyzed += [contract]
def _analyze_using_for(self, contracts_to_be_analyzed: List[ContractSolc]):
def _analyze_using_for(
self, contracts_to_be_analyzed: List[ContractSolc], libraries: List[ContractSolc]
):
self._analyze_top_level_using_for()
for lib in libraries:
lib.analyze_using_for()
while contracts_to_be_analyzed:
contract = contracts_to_be_analyzed[0]

@ -0,0 +1,8 @@
{
"A": {
"a(uint256)": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: RETURN 1\n\"];\n}\n"
},
"B": {
"b(uint256)": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: RETURN 1\n\"];\n}\n"
}
}

@ -0,0 +1,14 @@
library A {
using B for uint256;
function a(uint256 v) public view returns (uint) {
return v.b();
}
}
library B {
function b(uint256 v) public view returns (uint) {
return 1;
}
}

@ -428,6 +428,7 @@ ALL_TESTS = [
Test("using-for-2-0.8.0.sol", ["0.8.15"]),
Test("using-for-3-0.8.0.sol", ["0.8.15"]),
Test("using-for-4-0.8.0.sol", ["0.8.15"]),
Test("using-for-in-library-0.8.0.sol", ["0.8.15"]),
Test("using-for-alias-contract-0.8.0.sol", ["0.8.15"]),
Test("using-for-alias-top-level-0.8.0.sol", ["0.8.15"]),
Test("using-for-functions-list-1-0.8.0.sol", ["0.8.15"]),

@ -128,3 +128,14 @@ def test_using_for_alias_contract() -> None:
if isinstance(ir, InternalCall) and ir.function_name == "a":
return
assert False
def test_using_for_in_library() -> None:
solc_select.switch_global_version("0.8.15", always_install=True)
slither = Slither("./tests/ast-parsing/using-for-in-library-0.8.0.sol")
contract_c = slither.get_contract_from_name("A")[0]
libCall = contract_c.get_function_from_full_name("a(uint256)")
for ir in libCall.all_slithir_operations():
if isinstance(ir, LibraryCall) and ir.destination == "B" and ir.function_name == "b":
return
assert False

Loading…
Cancel
Save