From feafd9bbc65e57e2b4c08518de2b9b89870caf5b Mon Sep 17 00:00:00 2001 From: Josselin Feist Date: Tue, 3 Jan 2023 14:20:21 +0100 Subject: [PATCH 01/19] Improvements --- slither/tools/documentation/__main__.py | 158 ++++++++++++++---------- 1 file changed, 93 insertions(+), 65 deletions(-) diff --git a/slither/tools/documentation/__main__.py b/slither/tools/documentation/__main__.py index ea45ed8e1..1f2280de7 100644 --- a/slither/tools/documentation/__main__.py +++ b/slither/tools/documentation/__main__.py @@ -36,7 +36,12 @@ def parse_args() -> argparse.Namespace: default=False, ) - parser.add_argument("--retry", help="Retry failed query (default 1). Each retry increases the temperature by 0.1", action="store", default=1) + parser.add_argument( + "--retry", + help="Retry failed query (default 1). Each retry increases the temperature by 0.1", + action="store", + default=1, + ) # Add default arguments from crytic-compile cryticparser.init(parser) @@ -122,7 +127,75 @@ def _handle_codex( return None -# pylint: disable=too-many-locals +# pylint: disable=too-many-locals,too-many-arguments +def _handle_function( + function: Function, + overwrite: bool, + all_patches: Dict, + logging_file: Optional[str], + slither: Slither, + retry: int, + force: bool, +) -> bool: + if ( + function.source_mapping.is_dependency + or function.has_documentation + or function.is_constructor_variables + ): + return overwrite + prompt = "Create a natpsec documentation for this solidity code with only notice and dev.\n" + src_mapping = function.source_mapping + content = function.compilation_unit.core.source_code[src_mapping.filename.absolute] + start = src_mapping.start + end = src_mapping.start + src_mapping.length + prompt += content[start:end] + + use_tab = _use_tab(content[start - 1]) + if use_tab is None and src_mapping.starting_column > 1: + logger.info(f"Non standard space indentation found {content[start - 1:end]}") + if overwrite: + logger.info("Disable overwrite to avoid mistakes") + overwrite = False + + openai = codex.openai_module() # type: ignore + if openai is None: + raise ImportError + + if logging_file: + codex.log_codex(logging_file, "Q: " + prompt) + + tentative = 0 + answer_processed: Optional[str] = None + while tentative < retry: + tentative += 1 + + answer = openai.Completion.create( # type: ignore + prompt=prompt, + model=slither.codex_model, + temperature=min(slither.codex_temperature + tentative * 0.1, 1), + max_tokens=slither.codex_max_tokens, + ) + + if logging_file: + codex.log_codex(logging_file, "A: " + str(answer)) + + answer_processed = _handle_codex(answer, src_mapping.starting_column, use_tab, force) + if answer_processed: + break + + logger.info( + f"Codex could not generate a well formatted answer for {function.canonical_name}" + ) + logger.info(answer) + + if not answer_processed: + return overwrite + + create_patch(all_patches, src_mapping.filename.absolute, start, start, "", answer_processed) + + return overwrite + + def _handle_compilation_unit( slither: Slither, compilation_unit: SlitherCompilationUnit, @@ -130,8 +203,11 @@ def _handle_compilation_unit( force: bool, retry: int, ) -> None: - - logging_file = str(uuid.uuid4()) + logging_file: Optional[str] + if slither.codex_log: + logging_file = str(uuid.uuid4()) + else: + logging_file = None for scope in compilation_unit.scopes.values(): @@ -153,63 +229,8 @@ def _handle_compilation_unit( all_patches: Dict = {} for function in functions_target: - - if function.source_mapping.is_dependency or function.has_documentation or function.is_constructor_variables: - continue - prompt = ( - "Create a natpsec documentation for this solidity code with only notice and dev.\n" - ) - src_mapping = function.source_mapping - content = compilation_unit.core.source_code[src_mapping.filename.absolute] - start = src_mapping.start - end = src_mapping.start + src_mapping.length - prompt += content[start:end] - - use_tab = _use_tab(content[start - 1]) - if use_tab is None and src_mapping.starting_column > 1: - logger.info(f"Non standard space indentation found {content[start-1:end]}") - if overwrite: - logger.info("Disable overwrite to avoid mistakes") - overwrite = False - - openai = codex.openai_module() # type: ignore - if openai is None: - return - - if slither.codex_log: - codex.log_codex(logging_file, "Q: " + prompt) - - tentative = 0 - answer_processed: Optional[str] = None - while tentative < retry: - tentative += 1 - - answer = openai.Completion.create( # type: ignore - prompt=prompt, - model=slither.codex_model, - temperature=min(slither.codex_temperature + tentative*0.1, 1), - max_tokens=slither.codex_max_tokens, - ) - - if slither.codex_log: - codex.log_codex(logging_file, "A: " + str(answer)) - - answer_processed = _handle_codex( - answer, src_mapping.starting_column, use_tab, force - ) - if answer_processed: - break - - logger.info( - f"Codex could not generate a well formatted answer for {function.canonical_name}" - ) - logger.info(answer) - - if not answer_processed: - continue - - create_patch( - all_patches, src_mapping.filename.absolute, start, start, "", answer_processed + overwrite = _handle_function( + function, overwrite, all_patches, logging_file, slither, retry, force ) # all_patches["patches"] should have only 1 file @@ -242,10 +263,17 @@ def main() -> None: logger.info("Be aware of OpenAI ToS: https://openai.com/api/policies/terms/") slither = Slither(args.project, **vars(args)) - for compilation_unit in slither.compilation_units: - _handle_compilation_unit( - slither, compilation_unit, args.overwrite, args.force_answer_parsing, int(args.retry) - ) + try: + for compilation_unit in slither.compilation_units: + _handle_compilation_unit( + slither, + compilation_unit, + args.overwrite, + args.force_answer_parsing, + int(args.retry), + ) + except ImportError: + pass if __name__ == "__main__": From 04949548e9b05535a76f740e0099d4667fee2dec Mon Sep 17 00:00:00 2001 From: Josselin Feist Date: Tue, 3 Jan 2023 16:02:54 +0100 Subject: [PATCH 02/19] Minor --- slither/tools/documentation/README.md | 6 +++--- slither/tools/documentation/__main__.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/slither/tools/documentation/README.md b/slither/tools/documentation/README.md index 2ed90692c..5e70b3a49 100644 --- a/slither/tools/documentation/README.md +++ b/slither/tools/documentation/README.md @@ -1,6 +1,6 @@ -# Demo +# slither-documentation -This directory contains an example of Slither utility. +`slither-documentation` uses [codex](https://beta.openai.com) to generate natspec documenation. -See the [utility documentation](https://github.com/crytic/slither/wiki/Adding-a-new-utility) +This tool is experimental. See https://github.com/montyly/solmate/pull/1 for an example of usage. diff --git a/slither/tools/documentation/__main__.py b/slither/tools/documentation/__main__.py index 1f2280de7..8e545fb09 100644 --- a/slither/tools/documentation/__main__.py +++ b/slither/tools/documentation/__main__.py @@ -211,7 +211,7 @@ def _handle_compilation_unit( for scope in compilation_unit.scopes.values(): - # TODO remove hardcoded filtering + # Dont send tests file if ( ".t.sol" in scope.filename.absolute or "mock" in scope.filename.absolute.lower() From 656f2145ae7fc268a54da5098bbed0179cab5aff Mon Sep 17 00:00:00 2001 From: pavan-nambi Date: Tue, 3 Jan 2023 21:02:49 +0530 Subject: [PATCH 03/19] chore(CI):removing solc-select install all lines --- .github/workflows/IR.yml | 1 - .github/workflows/ci.yml | 1 - .github/workflows/detectors.yml | 1 - .github/workflows/features.yml | 1 - 4 files changed, 4 deletions(-) diff --git a/.github/workflows/IR.yml b/.github/workflows/IR.yml index 434cef75b..b1d11478f 100644 --- a/.github/workflows/IR.yml +++ b/.github/workflows/IR.yml @@ -34,7 +34,6 @@ jobs: - name: Install dependencies run: | pip install ".[dev]" - solc-select install all solc-select use 0.8.11 - name: Test with pytest diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1ae5326a8..7338d248c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,7 +55,6 @@ jobs: - name: Install dependencies run: | pip install ".[dev]" - solc-select install all solc-select use 0.5.1 pip install typing_extensions==4.1.1 pip install importlib_metadata==4.8.3 diff --git a/.github/workflows/detectors.yml b/.github/workflows/detectors.yml index 8f3b45d15..c85e8d26b 100644 --- a/.github/workflows/detectors.yml +++ b/.github/workflows/detectors.yml @@ -35,7 +35,6 @@ jobs: run: | pip install ".[dev]" - solc-select install all solc-select use 0.7.3 - name: Test with pytest run: | diff --git a/.github/workflows/features.yml b/.github/workflows/features.yml index 49db14793..14150388a 100644 --- a/.github/workflows/features.yml +++ b/.github/workflows/features.yml @@ -35,7 +35,6 @@ jobs: run: | pip install ".[dev]" - solc-select install all solc-select use 0.8.0 cd tests/test_node_modules/ From df896e80f2814befab085a34072374dc6ebe9ebf Mon Sep 17 00:00:00 2001 From: alpharush <0xalpharush@protonmail.com> Date: Tue, 3 Jan 2023 09:40:26 -0600 Subject: [PATCH 04/19] better error handling of malformed symbol alias AST node for solc <0.6.0 --- .../slither_compilation_unit_solc.py | 27 +++++++++++-------- .../import_aliases_issue_1319/import.sol | 1 + .../import_aliases_issue_1319/test.sol | 9 +++++++ .../import_aliases_issue_1319/test_fail.sol | 9 +++++++ 4 files changed, 35 insertions(+), 11 deletions(-) create mode 100644 tests/ast-parsing/complex_imports/import_aliases_issue_1319/import.sol create mode 100644 tests/ast-parsing/complex_imports/import_aliases_issue_1319/test.sol create mode 100644 tests/ast-parsing/complex_imports/import_aliases_issue_1319/test_fail.sol diff --git a/slither/solc_parsing/slither_compilation_unit_solc.py b/slither/solc_parsing/slither_compilation_unit_solc.py index d12bda1b4..5c93d5f1d 100644 --- a/slither/solc_parsing/slither_compilation_unit_solc.py +++ b/slither/solc_parsing/slither_compilation_unit_solc.py @@ -45,16 +45,22 @@ def _handle_import_aliases( """ for symbol_alias in symbol_aliases: - if ( - "foreign" in symbol_alias - and "name" in symbol_alias["foreign"] - and "local" in symbol_alias - ): - original_name = symbol_alias["foreign"]["name"] - local_name = symbol_alias["local"] - import_directive.renaming[local_name] = original_name - # Assuming that two imports cannot collide in renaming - scope.renaming[local_name] = original_name + if "foreign" in symbol_alias and "local" in symbol_alias: + if isinstance(symbol_alias["foreign"], dict) and "name" in symbol_alias["foreign"]: + + original_name = symbol_alias["foreign"]["name"] + local_name = symbol_alias["local"] + import_directive.renaming[local_name] = original_name + # Assuming that two imports cannot collide in renaming + scope.renaming[local_name] = original_name + + # This path should only be hit for the malformed AST of solc 0.5.12 where + # the foreign identifier cannot be found but is required to resolve the alias. + # see https://github.com/crytic/slither/issues/1319 + if symbol_alias["local"]: + raise SlitherException( + "Cannot resolve local alias for import directive due to malformed AST. Please upgrade to solc 0.6.0 or higher." + ) class SlitherCompilationUnitSolc: @@ -389,7 +395,6 @@ Please rename it, this name is reserved for Slither's internals""" ) self._contracts_by_id[contract.id] = contract self._compilation_unit.contracts.append(contract) - # Update of the inheritance for contract_parser in self._underlying_contract_to_parser.values(): # remove the first elem in linearizedBaseContracts as it is the contract itself diff --git a/tests/ast-parsing/complex_imports/import_aliases_issue_1319/import.sol b/tests/ast-parsing/complex_imports/import_aliases_issue_1319/import.sol new file mode 100644 index 000000000..7cfff4bfa --- /dev/null +++ b/tests/ast-parsing/complex_imports/import_aliases_issue_1319/import.sol @@ -0,0 +1 @@ +contract A {} \ No newline at end of file diff --git a/tests/ast-parsing/complex_imports/import_aliases_issue_1319/test.sol b/tests/ast-parsing/complex_imports/import_aliases_issue_1319/test.sol new file mode 100644 index 000000000..7c5bf1eee --- /dev/null +++ b/tests/ast-parsing/complex_imports/import_aliases_issue_1319/test.sol @@ -0,0 +1,9 @@ +pragma solidity 0.5.12; + +import {A} from "./import.sol"; + +contract Z is A { + function test() public pure returns (uint) { + return 1; + } +} \ No newline at end of file diff --git a/tests/ast-parsing/complex_imports/import_aliases_issue_1319/test_fail.sol b/tests/ast-parsing/complex_imports/import_aliases_issue_1319/test_fail.sol new file mode 100644 index 000000000..eb2ab8af0 --- /dev/null +++ b/tests/ast-parsing/complex_imports/import_aliases_issue_1319/test_fail.sol @@ -0,0 +1,9 @@ +pragma solidity 0.5.12; + +import {A as X, A as Y} from "./import.sol"; + +contract Z is X { + function test() public pure returns (uint) { + return 1; + } +} \ No newline at end of file From f92cb37a400f9ddf72f4d48ebfc5a786de5236fc Mon Sep 17 00:00:00 2001 From: alpharush <0xalpharush@protonmail.com> Date: Tue, 3 Jan 2023 09:49:50 -0600 Subject: [PATCH 05/19] only check for local alias if foreign isn't dict --- slither/solc_parsing/slither_compilation_unit_solc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/slither/solc_parsing/slither_compilation_unit_solc.py b/slither/solc_parsing/slither_compilation_unit_solc.py index 5c93d5f1d..05dc4113b 100644 --- a/slither/solc_parsing/slither_compilation_unit_solc.py +++ b/slither/solc_parsing/slither_compilation_unit_solc.py @@ -57,7 +57,7 @@ def _handle_import_aliases( # This path should only be hit for the malformed AST of solc 0.5.12 where # the foreign identifier cannot be found but is required to resolve the alias. # see https://github.com/crytic/slither/issues/1319 - if symbol_alias["local"]: + elif symbol_alias["local"]: raise SlitherException( "Cannot resolve local alias for import directive due to malformed AST. Please upgrade to solc 0.6.0 or higher." ) @@ -395,6 +395,7 @@ Please rename it, this name is reserved for Slither's internals""" ) self._contracts_by_id[contract.id] = contract self._compilation_unit.contracts.append(contract) + # Update of the inheritance for contract_parser in self._underlying_contract_to_parser.values(): # remove the first elem in linearizedBaseContracts as it is the contract itself From 1b6acfa9a40f712d6d2cda44496c13c858968370 Mon Sep 17 00:00:00 2001 From: alpharush <0xalpharush@protonmail.com> Date: Tue, 3 Jan 2023 09:50:30 -0600 Subject: [PATCH 06/19] format --- slither/solc_parsing/slither_compilation_unit_solc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slither/solc_parsing/slither_compilation_unit_solc.py b/slither/solc_parsing/slither_compilation_unit_solc.py index 05dc4113b..930f60ff9 100644 --- a/slither/solc_parsing/slither_compilation_unit_solc.py +++ b/slither/solc_parsing/slither_compilation_unit_solc.py @@ -395,7 +395,7 @@ Please rename it, this name is reserved for Slither's internals""" ) self._contracts_by_id[contract.id] = contract self._compilation_unit.contracts.append(contract) - + # Update of the inheritance for contract_parser in self._underlying_contract_to_parser.values(): # remove the first elem in linearizedBaseContracts as it is the contract itself From 3e67fff11768e6c39f8f82cc65ef1c0f883723ff Mon Sep 17 00:00:00 2001 From: pavan-nambi Date: Tue, 3 Jan 2023 21:21:03 +0530 Subject: [PATCH 07/19] update(#1546) --- .github/workflows/IR.yml | 2 +- .github/workflows/ci.yml | 2 +- .github/workflows/detectors.yml | 2 +- .github/workflows/features.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/IR.yml b/.github/workflows/IR.yml index b1d11478f..29e6ba2a0 100644 --- a/.github/workflows/IR.yml +++ b/.github/workflows/IR.yml @@ -34,7 +34,7 @@ jobs: - name: Install dependencies run: | pip install ".[dev]" - solc-select use 0.8.11 + solc-select use 0.8.11--always-install - name: Test with pytest run: | diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7338d248c..ff038574a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,7 +55,7 @@ jobs: - name: Install dependencies run: | pip install ".[dev]" - solc-select use 0.5.1 + solc-select use 0.5.1--always-install pip install typing_extensions==4.1.1 pip install importlib_metadata==4.8.3 diff --git a/.github/workflows/detectors.yml b/.github/workflows/detectors.yml index c85e8d26b..ff568a046 100644 --- a/.github/workflows/detectors.yml +++ b/.github/workflows/detectors.yml @@ -35,7 +35,7 @@ jobs: run: | pip install ".[dev]" - solc-select use 0.7.3 + solc-select use 0.7.3--always-install - name: Test with pytest run: | pytest tests/test_detectors.py diff --git a/.github/workflows/features.yml b/.github/workflows/features.yml index 14150388a..dada1e141 100644 --- a/.github/workflows/features.yml +++ b/.github/workflows/features.yml @@ -35,7 +35,7 @@ jobs: run: | pip install ".[dev]" - solc-select use 0.8.0 + solc-select use 0.8.0--always-install cd tests/test_node_modules/ npm install hardhat From 41806075a6d258fdfedae91f8263bf27c6231aa7 Mon Sep 17 00:00:00 2001 From: pavan-nambi Date: Tue, 3 Jan 2023 21:42:30 +0530 Subject: [PATCH 08/19] update2(#1546) --- .github/workflows/IR.yml | 2 +- .github/workflows/ci.yml | 2 +- .github/workflows/detectors.yml | 2 +- .github/workflows/features.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/IR.yml b/.github/workflows/IR.yml index 29e6ba2a0..c5187da65 100644 --- a/.github/workflows/IR.yml +++ b/.github/workflows/IR.yml @@ -34,7 +34,7 @@ jobs: - name: Install dependencies run: | pip install ".[dev]" - solc-select use 0.8.11--always-install + solc-select use 0.8.11 --always-install - name: Test with pytest run: | diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ff038574a..3378cd420 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,7 +55,7 @@ jobs: - name: Install dependencies run: | pip install ".[dev]" - solc-select use 0.5.1--always-install + solc-select use 0.5.1 --always-install pip install typing_extensions==4.1.1 pip install importlib_metadata==4.8.3 diff --git a/.github/workflows/detectors.yml b/.github/workflows/detectors.yml index ff568a046..15aa8a5dd 100644 --- a/.github/workflows/detectors.yml +++ b/.github/workflows/detectors.yml @@ -35,7 +35,7 @@ jobs: run: | pip install ".[dev]" - solc-select use 0.7.3--always-install + solc-select use 0.7.3 --always-install - name: Test with pytest run: | pytest tests/test_detectors.py diff --git a/.github/workflows/features.yml b/.github/workflows/features.yml index dada1e141..5007fd7bf 100644 --- a/.github/workflows/features.yml +++ b/.github/workflows/features.yml @@ -35,7 +35,7 @@ jobs: run: | pip install ".[dev]" - solc-select use 0.8.0--always-install + solc-select use 0.8.0 --always-install cd tests/test_node_modules/ npm install hardhat From bd3e4504b8233bf2cfda0e3daca07d71a445b1e9 Mon Sep 17 00:00:00 2001 From: Josselin Feist Date: Wed, 4 Jan 2023 12:13:33 +0100 Subject: [PATCH 09/19] Fix markdown@ --- slither/tools/documentation/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/slither/tools/documentation/README.md b/slither/tools/documentation/README.md index 5e70b3a49..b4b3e6a76 100644 --- a/slither/tools/documentation/README.md +++ b/slither/tools/documentation/README.md @@ -2,5 +2,4 @@ `slither-documentation` uses [codex](https://beta.openai.com) to generate natspec documenation. -This tool is experimental. See https://github.com/montyly/solmate/pull/1 for an example of usage. - +This tool is experimental. See [solmate documentation](https://github.com/montyly/solmate/pull/1) for an example of usage. From 23d77e23fd0b7d89504d0b6ff291a0b50f370101 Mon Sep 17 00:00:00 2001 From: pavan-nambi Date: Wed, 4 Jan 2023 19:07:55 +0530 Subject: [PATCH 10/19] refractor(ver-in-path_filterin) --- scripts/ci_test_path_filtering.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ci_test_path_filtering.sh b/scripts/ci_test_path_filtering.sh index fb2a18842..838ecfa1d 100644 --- a/scripts/ci_test_path_filtering.sh +++ b/scripts/ci_test_path_filtering.sh @@ -2,7 +2,7 @@ ### Test path filtering across POSIX and Windows -solc-select use 0.8.0 +solc-select use 0.5.0 slither "tests/test_path_filtering/test_path_filtering.sol" --config "tests/test_path_filtering/slither.config.json" > "output.txt" 2>&1 if ! grep -q "0 result(s) found" "output.txt" From 8388597e77708e200ba3916db6feb668ad823212 Mon Sep 17 00:00:00 2001 From: pavan-nambi Date: Wed, 4 Jan 2023 19:30:26 +0530 Subject: [PATCH 11/19] Revert "refractor(ver-in-path_filterin)" This reverts commit 23d77e23fd0b7d89504d0b6ff291a0b50f370101. --- scripts/ci_test_path_filtering.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ci_test_path_filtering.sh b/scripts/ci_test_path_filtering.sh index 838ecfa1d..fb2a18842 100644 --- a/scripts/ci_test_path_filtering.sh +++ b/scripts/ci_test_path_filtering.sh @@ -2,7 +2,7 @@ ### Test path filtering across POSIX and Windows -solc-select use 0.5.0 +solc-select use 0.8.0 slither "tests/test_path_filtering/test_path_filtering.sol" --config "tests/test_path_filtering/slither.config.json" > "output.txt" 2>&1 if ! grep -q "0 result(s) found" "output.txt" From 9015e739c2e60b5c4df8889b7fb13970ff77e2c1 Mon Sep 17 00:00:00 2001 From: pavan-nambi Date: Wed, 4 Jan 2023 20:05:16 +0530 Subject: [PATCH 12/19] update(adding-more-installations) --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3378cd420..73cba44b2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,6 +55,8 @@ jobs: - name: Install dependencies run: | pip install ".[dev]" + solc-select use 0.4.25 --always-install + solc-select use 0.8.0 --always-install solc-select use 0.5.1 --always-install pip install typing_extensions==4.1.1 pip install importlib_metadata==4.8.3 From 10085c1c1228e4eefc22b2a8c3f1df4194131ca4 Mon Sep 17 00:00:00 2001 From: alpharush <0xalpharush@protonmail.com> Date: Thu, 5 Jan 2023 07:21:54 -0600 Subject: [PATCH 13/19] add tests --- .../test.sol-0.5.12-compact.zip | Bin 0 -> 1931 bytes .../test.sol-0.5.12-legacy.zip | Bin 0 -> 1857 bytes .../test.sol-0.5.12-compact.json | 6 ++++++ .../test.sol-0.5.12-legacy.json | 6 ++++++ tests/test_ast_parsing.py | 1 + 5 files changed, 13 insertions(+) create mode 100644 tests/ast-parsing/compile/complex_imports/import_aliases_issue_1319/test.sol-0.5.12-compact.zip create mode 100644 tests/ast-parsing/compile/complex_imports/import_aliases_issue_1319/test.sol-0.5.12-legacy.zip create mode 100644 tests/ast-parsing/expected/complex_imports/import_aliases_issue_1319/test.sol-0.5.12-compact.json create mode 100644 tests/ast-parsing/expected/complex_imports/import_aliases_issue_1319/test.sol-0.5.12-legacy.json diff --git a/tests/ast-parsing/compile/complex_imports/import_aliases_issue_1319/test.sol-0.5.12-compact.zip b/tests/ast-parsing/compile/complex_imports/import_aliases_issue_1319/test.sol-0.5.12-compact.zip new file mode 100644 index 0000000000000000000000000000000000000000..f1b13305654d3104c79b9fbcebc2e89f2ae02147 GIT binary patch literal 1931 zcmaLY`#;l*0|xMqWpc}9xh1z^O=YaZv@vpRB6C+%7NQL`GY7Rqt!X$eaY~yc8cSIv z)IyOMri;w2%fw2}Wi%l~PUrjk_dL%J&+GXM-o9SzpL0`Ql9ASl3~^96_>*f3{n9N@{G2mSmSxcm=n#0K4DPOeh%vv z22*~ojmUakw`-rr#Fie-O0$aZ5@jOEzELZVZn^q)baS>53#lIT6^}4<$bKsKiLnI`5Nc`#iN{~y^uP|`(Cy6Y1H*! zLa`z{oLS}EV_AmDJodUZ>gD9hrIc`l20U&QeMPvW+ENw_R|!*aqPcEpQgW$!o^>rB zI?+-MXa~2_ILCHh3^pFUqZG75m-;x^=-h|KXb7zt2@-~SKvGE_e<~L8JAceO??>We zOxoKtauX`;+c%Ooy$xN!cp@fS@uA%9eUIJigOUyYDh=h<*P{e6yTb&y$B!h5pQb9W z8_SCHGUiNpN79XMus&`=MbP|$B(uH&h!y(Zt7+77YZ(LpMVg+yoR> zlaY|aLzS1IL6O9HpUT7W;#ld8t0tN4IAM*lDr9>UQ*P z@Ro}O%tb~@!}7_2Sx}EO0>y+HHnYx$rul+EVZw1HbWz^XBzXDoSaT-U?gIby zEzn9rLl0V@RTJ>XYU1*Z3nVhZpo>dc-;FpiKWng57c|GY@@4qmyAnZMHwjtt>v?x? zy)5O%UicjRd1=2@t&`s$(GB0Y-v>WWHo*EiRV-0JG>#YG2E(|2XI>JT3fk0GYa?y) z!Ed0W_-9jU%m|)IM!L5(n#V-yVZpa^MZBg?H)+dF$qRGc_aXcoxit{iXTX79ei7yA z;lDVgvoRbxI~Mq1z+vf!NS4=-(%FPj@u%)&Io0?v1og(#p`i!+UbL zliOLKg}kem`S0aoN8nG^dlf{u1~ehky>>qKLIwrm=5CIZF67SdAAn|h3lHBOPK zeS=CH1|p;{S6)d#{M*va)mFvxaf{LQ-z&7$k*cVJYXqBHb|H_nWMFfFonl9OEXK6N z{!MrBX~J^&!1&YJhs$x#*6j1f#pUNjky#FT9wBpNJ^GfQLq_nJB~Yq`^X!fM)R-)} z@f_>5sBSis8XaI+IC{ZG527|HI+WJ-(;l(oTEEkB9uDy$^piQyyZ@;7;PN~EA(~yhJpy~ z*#%8O@^iG1Rkfe0N6|Vbq{N8_euk~S*qAoWi?33Y`rTMYB^DTJPt<4Ln5M4Nwp6Or z)IjpSw3R>AiR#t!)aFHh6m3$(I0r?$`Q9fg#tNO5BA!Iv2aO44b=z z+1wnSJz9&(o8`jGd$OBXE>W&0$iF^3HvdK^^~`js zx2VTe6<{r@kL%3cX$@~CXX$UuI{vojPw^!y_a;Pw?a=l_t3`KjSmVqqU2=;;X@Nu3 zuX7dBKzFt$Fvi)1yd56@QQZHfRbxI^A5^D1QxO{Ov_!a@>W+2Ydb{5){`^ojt*F>E zZI;j&T3TZ2>aNE^h@do*ktj_sp`@kHTcp$%+?5RFa}lXH#|3;u+HT%ZG`Sy=aFWvfj5-$9?OfY}vU+rkal5c!m@ED0GAhq9B8s2vvD^M)!E) zt+MR2(yB}_N&;0#B+6lIk=wFy=*3>rjBuEfzoX(q>k_~>hY{UWXezmkJ0o7PY$@ai z%*Hy~<*W#NilbWCb3&Eb6CwWmi&f;{>m>);v+n<6`P<9?C0*{{`7b(sy}-Yb1pv9< M_58g%*Z=$e0jWoo0ssI2 literal 0 HcmV?d00001 diff --git a/tests/ast-parsing/compile/complex_imports/import_aliases_issue_1319/test.sol-0.5.12-legacy.zip b/tests/ast-parsing/compile/complex_imports/import_aliases_issue_1319/test.sol-0.5.12-legacy.zip new file mode 100644 index 0000000000000000000000000000000000000000..3f457a34d429fcb217e4c6f8d6d4fe219e25014d GIT binary patch literal 1857 zcmaLY_dnYS0|)T0*gI{xRt2#VL}OG-#U|7$>a5x{_6}+m7c17GCqmRyYWEWJ;jw~H zT6I<(S5c!zt=Otnj1t2jh88vuxi0RRL5 zfN%^p9ElAMaK%K01c!yYx`%oC_(o!oe%Rn3P8L?c82}OiKr=nv`}W!G(6Y(VRupf^ z>mXn09?_KShc~svX0Y8qDeW8ar&JcW*v-TO;Lu&cbrQJ0a#aVXlClYT{yNFXzy;1l z7gWp`Yf&=3zbQU`rAn&uaGlFH7}Y5dkb*q_ur$9rv>_i^JEhrtGRx0Zjw0LIp|XfuZMJD4 ze(lItVaJM1=9T!j9kYw8`n_q&JCtXH{Ipyr+FXNfgPOvj=)6|D_@c4Ht0KlVOr4>P zW-?wtdBUq4{hDPtuQKyJGD_&Ot#=uLa>YsZq#8gv1xl^DJ&N9JJtCMlK64|gU}-K1 z6NlztYxj(-j)9IK)*z0xZw*tNpIm)4?sW!U!TgS4tCae;t`4uzF~0k{T0?KJ;`E8J z9*4g99+Ol!PeU#W%n|i&ZK@BZ>PsfNo8)!HwezmI&xEL&I+S+J5xk1+m4ksZl@-!9 zPKV9bSu*ujP_u(&wGwhNhO|3o=1oU>T_DyYY-s&2l;oxc%nrU}Z|M%wHmi=n(ds$v zn&b^HP@o=uO*8WbP{vUs4~Un(G_whb#>JM@i}>0feCYQU#O%GCJ^leQ#(V~53^lcQaDjM4{DY*xnDD1o{=5vgLZ`LZ)WSpjWTNI! zsp@gwHw`~7&K*j#ESJpsp;{dfwla~;t}$X|9o`>K^<^s8EI-ItlIR1TF z$uz3<`(s_*$t4>EsCVsNQP$=Mkp z91DG{;@;O2ns+r1ZS5E>ZD~*;dzwsc(g~qLBU)Z`bjmN8D29;eI&a_6Us*f773beu zdjxYzbj1w1HuIZBLp};ze!g2_5DlF4Sk|2LoR36?WbM^&i28lGRR1)t@arjI9brz| zfZOIa%}4o4c`1K~7=*~C@4 z1UM}CXw~7C491Iczk`UYX1xV01XtLYdA0;a!+Xo{W()Rf=pDPix&o1UXezzz%QeOY zL!kOUYG!BE8$+9y9{0T%Ym&rF|AepSWuSaG(oE^?bLzQdK5WuNlg%Rd>*(5I7lfpw{o$_9 zEu&6Xas-&1`1HK%FUMVG5_t!$;mWi-%-=Y-DaP7#sR26m0OrF{%t%fgKiRyse)}06 zO5Tqsv%WzxTg|WabRnsSVReepQZc#jk0tEdQ|!ahhPC4Ix?%2Ox-%8u+=ZhI{To%@XjhMJq$OmL2Qc~6g3b?{qef#ZZD?~?k_wFY zMilEaY$1`Z_h1XX@A24&;)3uCXc}tjJioFibH>QGI9*^p2uo#D?HKnCr9dGdN4t`u z2rbgRwU6o7tGFlXII0IhJW=9 zg4jD8-tB(YJ?&jV literal 0 HcmV?d00001 diff --git a/tests/ast-parsing/expected/complex_imports/import_aliases_issue_1319/test.sol-0.5.12-compact.json b/tests/ast-parsing/expected/complex_imports/import_aliases_issue_1319/test.sol-0.5.12-compact.json new file mode 100644 index 000000000..4132f73d9 --- /dev/null +++ b/tests/ast-parsing/expected/complex_imports/import_aliases_issue_1319/test.sol-0.5.12-compact.json @@ -0,0 +1,6 @@ +{ + "A": {}, + "Z": { + "test()": "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/expected/complex_imports/import_aliases_issue_1319/test.sol-0.5.12-legacy.json b/tests/ast-parsing/expected/complex_imports/import_aliases_issue_1319/test.sol-0.5.12-legacy.json new file mode 100644 index 000000000..4132f73d9 --- /dev/null +++ b/tests/ast-parsing/expected/complex_imports/import_aliases_issue_1319/test.sol-0.5.12-legacy.json @@ -0,0 +1,6 @@ +{ + "A": {}, + "Z": { + "test()": "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/test_ast_parsing.py b/tests/test_ast_parsing.py index e96a129b8..5f1f6f58c 100644 --- a/tests/test_ast_parsing.py +++ b/tests/test_ast_parsing.py @@ -425,6 +425,7 @@ ALL_TESTS = [ Test("free_functions/library_constant_function_collision.sol", ["0.8.12"]), Test("ternary-with-max.sol", ["0.8.15"]), Test("library_event-0.8.16.sol", ["0.8.16"]), + Test("complex_imports/import_aliases_issue_1319/test.sol", ["0.5.12"]), ] # create the output folder if needed try: From d1b875d85e7e3660bd5fcc2d90ed68c6f1c8f479 Mon Sep 17 00:00:00 2001 From: pavan-nambi Date: Fri, 6 Jan 2023 02:25:17 +0530 Subject: [PATCH 14/19] update --- .github/workflows/IR.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/IR.yml b/.github/workflows/IR.yml index c5187da65..891de2bfb 100644 --- a/.github/workflows/IR.yml +++ b/.github/workflows/IR.yml @@ -34,8 +34,14 @@ jobs: - name: Install dependencies run: | pip install ".[dev]" + solc-select install 0.5.0 solc-select use 0.8.11 --always-install + - name: Install old solc + if: matrix.os == 'ubuntu-latest' + run: solc-select install 0.4.0 + + - name: Test with pytest run: | - pytest tests/test_ssa_generation.py + pytest tests/test_ssa_generation.py \ No newline at end of file From 1c12f2a7fcf9bf809b4be7a3b60917ee422730af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= Date: Fri, 6 Jan 2023 11:08:24 -0300 Subject: [PATCH 15/19] tests: source_unit: add missing foundry submodule --- .gitmodules | 4 ++++ 1 file changed, 4 insertions(+) create mode 100755 .gitmodules diff --git a/.gitmodules b/.gitmodules new file mode 100755 index 000000000..f2ce479c6 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "tests/source_unit/lib/forge-std"] + path = tests/source_unit/lib/forge-std + url = https://github.com/foundry-rs/forge-std + branch = v1.2.0 From d875eff4153d6249189f4e31ee46af3f5ff23bde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= Date: Fri, 6 Jan 2023 12:34:15 -0300 Subject: [PATCH 16/19] Revert "tests: source_unit: add missing foundry submodule" This reverts commit 1c12f2a7fcf9bf809b4be7a3b60917ee422730af. --- .gitmodules | 4 ---- 1 file changed, 4 deletions(-) delete mode 100755 .gitmodules diff --git a/.gitmodules b/.gitmodules deleted file mode 100755 index f2ce479c6..000000000 --- a/.gitmodules +++ /dev/null @@ -1,4 +0,0 @@ -[submodule "tests/source_unit/lib/forge-std"] - path = tests/source_unit/lib/forge-std - url = https://github.com/foundry-rs/forge-std - branch = v1.2.0 From 55c24280cf6ee2c881dbeb06a726e3a8dfa772ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= Date: Fri, 6 Jan 2023 12:36:57 -0300 Subject: [PATCH 17/19] tests: source_unit: remove submodule --- tests/source_unit/README.md | 3 +++ tests/source_unit/lib/forge-std | 1 - tests/test_source_unit.py | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 tests/source_unit/README.md delete mode 160000 tests/source_unit/lib/forge-std diff --git a/tests/source_unit/README.md b/tests/source_unit/README.md new file mode 100644 index 000000000..9cf3657e0 --- /dev/null +++ b/tests/source_unit/README.md @@ -0,0 +1,3 @@ +# README + +Before using this project, run `forge init --no-git --no-commit --force` to initialize submodules diff --git a/tests/source_unit/lib/forge-std b/tests/source_unit/lib/forge-std deleted file mode 160000 index eb980e1d4..000000000 --- a/tests/source_unit/lib/forge-std +++ /dev/null @@ -1 +0,0 @@ -Subproject commit eb980e1d4f0e8173ec27da77297ae411840c8ccb diff --git a/tests/test_source_unit.py b/tests/test_source_unit.py index 7b653599e..f979a41ec 100644 --- a/tests/test_source_unit.py +++ b/tests/test_source_unit.py @@ -1,5 +1,7 @@ from slither import Slither +# NB: read tests/source_unit/README.md before using this test + def test_contract_info() -> None: slither = Slither("./tests/source_unit") From 024729aa2f54a12ea09b0ff8d1bb137da2de1646 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= Date: Fri, 6 Jan 2023 15:20:21 -0300 Subject: [PATCH 18/19] ci: fix Docker build This fixes some issues with the Docker build process * missing `git` in wheel build process - pip requires Git to pull dependencies expressed as `foo @ git+https://...`. * pip upgrade before building - it was disabled with an extra `echo` Thanks to @ahpaleus for reporting this! * final image installation - pip insists on rebuilding git-referenced dependencies, so this installs the wheels directly with `--no-deps` to get the desired behavior. --- Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 71bb9f57f..d0a7d67be 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,7 @@ FROM ubuntu:jammy AS python-wheels RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ gcc \ + git \ python3-dev \ python3-pip \ && rm -rf /var/lib/apt/lists/* @@ -9,7 +10,7 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-ins COPY . /slither RUN cd /slither && \ - echo pip3 install --no-cache-dir --upgrade pip && \ + pip3 install --no-cache-dir --upgrade pip && \ pip3 wheel -w /wheels . solc-select pip setuptools wheel @@ -44,7 +45,7 @@ ENV PATH="/home/slither/.local/bin:${PATH}" # no-index ensures we install the freshly-built wheels RUN --mount=type=bind,target=/mnt,source=/wheels,from=python-wheels \ - pip3 install --user --no-cache-dir --upgrade --no-index --find-links /mnt pip slither-analyzer solc-select + pip3 install --user --no-cache-dir --upgrade --no-index --find-links /mnt --no-deps /mnt/*.whl RUN solc-select install 0.4.25 && solc-select use 0.4.25 From 48c75485dce51a84a319a9595129f77b2eeafb3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= Date: Fri, 6 Jan 2023 15:33:48 -0300 Subject: [PATCH 19/19] tests: source_unit: add skipif for requirements --- tests/test_source_unit.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/test_source_unit.py b/tests/test_source_unit.py index f979a41ec..73c165016 100644 --- a/tests/test_source_unit.py +++ b/tests/test_source_unit.py @@ -1,8 +1,18 @@ +from pathlib import Path +import shutil + +import pytest from slither import Slither -# NB: read tests/source_unit/README.md before using this test +# NB: read tests/source_unit/README.md for setup before using this test + +foundry_available = shutil.which("forge") is not None +project_ready = Path("./tests/source_unit/lib/forge-std").exists() +@pytest.mark.skipif( + not foundry_available or not project_ready, reason="requires Foundry and project setup" +) def test_contract_info() -> None: slither = Slither("./tests/source_unit")