From c548dfdcc78116dd879182c1aef99972d9d6c059 Mon Sep 17 00:00:00 2001 From: Simone Date: Sat, 7 Jan 2023 19:51:16 +0100 Subject: [PATCH] Fix analyze library using for directives --- .../slither_compilation_unit_solc.py | 7 +++++-- ...g-for-in-library-0.8.0.sol-0.8.15-compact.zip | Bin 0 -> 2831 bytes ...-for-in-library-0.8.0.sol-0.8.15-compact.json | 8 ++++++++ tests/ast-parsing/using-for-in-library-0.8.0.sol | 14 ++++++++++++++ tests/test_ast_parsing.py | 1 + tests/test_features.py | 11 +++++++++++ 6 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 tests/ast-parsing/compile/using-for-in-library-0.8.0.sol-0.8.15-compact.zip create mode 100644 tests/ast-parsing/expected/using-for-in-library-0.8.0.sol-0.8.15-compact.json create mode 100644 tests/ast-parsing/using-for-in-library-0.8.0.sol diff --git a/slither/solc_parsing/slither_compilation_unit_solc.py b/slither/solc_parsing/slither_compilation_unit_solc.py index 7bae88c5c..3d636d339 100644 --- a/slither/solc_parsing/slither_compilation_unit_solc.py +++ b/slither/solc_parsing/slither_compilation_unit_solc.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,12 @@ 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] diff --git a/tests/ast-parsing/compile/using-for-in-library-0.8.0.sol-0.8.15-compact.zip b/tests/ast-parsing/compile/using-for-in-library-0.8.0.sol-0.8.15-compact.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z9h0t9fOl0Mf2UyE(WkofDR2_m(3%Zz5@MOSztP3|NXRYN#m`VmkuvPTP|EMsJ#I7q zlfM?i;F!jZTY@p)$escR+?dm^oqiua{QQ}tOG ze&$|@a0#uw{cV~18kVFc+k-I;tpY3b{NXH~6p4(Ay-)xV50YXN1wpeti_3}oww^G9 zGSdQRp@fTeaJ>OZdQd<1sv7*s>!e(F3z>-M3itq+82HGlsL(mIz=l<@ncoPjDlCOD z(jOO#nvvr;`MRUr+*2GvX)fF72V#1SSM?mfJSyO`X;a9^%XVISJryNl@2A!@@LJet zVF~&VALcsYBO$;<%)}O;-Z~a?{ACoJk73=yd(RgM8kn+q98I) zgJ6|tj1ULGbvlAc1i5JdMTZ9r!rMK)RFbkvL7we}NNMq$IfWy+0Wv}C zzS|=v8T6U zdV*(Tvjb*ecF?d+%1sPvxv62&;u$=j78Kg^<}n;Twgs=;+CLHz;Q7&wU5_&pVRtEEo%W+PK1;k#6(KK zZ=v2jDSdb=P~)mBBwO0@DC?b|WIXKo`DzPz)byVeolxsbwUb#tHGVm#gYtAL;4ow8#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" + } +} \ No newline at end of file diff --git a/tests/ast-parsing/using-for-in-library-0.8.0.sol b/tests/ast-parsing/using-for-in-library-0.8.0.sol new file mode 100644 index 000000000..0e8f6a6b9 --- /dev/null +++ b/tests/ast-parsing/using-for-in-library-0.8.0.sol @@ -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; + } +} diff --git a/tests/test_ast_parsing.py b/tests/test_ast_parsing.py index 0d6118601..7e22ea186 100644 --- a/tests/test_ast_parsing.py +++ b/tests/test_ast_parsing.py @@ -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"]), diff --git a/tests/test_features.py b/tests/test_features.py index a5541b589..924e0b154 100644 --- a/tests/test_features.py +++ b/tests/test_features.py @@ -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