Skip to content

Commit

Permalink
Merge branch 'dev' into ck-printer
Browse files Browse the repository at this point in the history
  • Loading branch information
devtooligan authored Jun 15, 2023
2 parents 14c9761 + ccad542 commit d759a86
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
18 changes: 17 additions & 1 deletion slither/solc_parsing/slither_compilation_unit_solc.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
logger.setLevel(logging.INFO)


class InheritanceResolutionError(SlitherException):
pass


def _handle_import_aliases(
symbol_aliases: Dict, import_directive: Import, scope: FileScope
) -> None:
Expand Down Expand Up @@ -194,6 +198,13 @@ def _parse_enum(self, top_level_data: Dict, filename: str) -> None:

# pylint: disable=too-many-branches,too-many-statements,too-many-locals
def parse_top_level_from_loaded_json(self, data_loaded: Dict, filename: str) -> None:
if not data_loaded or data_loaded is None:
logger.error(
"crytic-compile returned an empty AST. "
"If you are trying to analyze a contract from etherscan or similar make sure it has source code available."
)
return

if "nodeType" in data_loaded:
self._is_compact_ast = True

Expand Down Expand Up @@ -432,7 +443,12 @@ def parse_contracts(self) -> None: # pylint: disable=too-many-statements,too-ma
target = contract_parser.underlying_contract.file_scope.get_contract_from_name(
contract_name
)
assert target
if target == contract_parser.underlying_contract:
raise InheritanceResolutionError(
"Could not resolve contract inheritance. This is likely caused by an import renaming that collides with existing names (see https://github.com/crytic/slither/issues/1758)."
f"\n Try changing `contract {target}` ({target.source_mapping}) to a unique name."
)
assert target, f"Contract {contract_name} not found"
ancestors.append(target)
elif i in self._contracts_by_id:
ancestors.append(self._contracts_by_id[i])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import {ERC20 as ERC20_1} from "./import.sol";
contract ERC20 is ERC20_1 {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
contract ERC20 {}
18 changes: 18 additions & 0 deletions tests/unit/core/test_error_messages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from pathlib import Path
import pytest


from slither import Slither
from slither.solc_parsing.slither_compilation_unit_solc import InheritanceResolutionError

TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data"
INHERITANCE_ERROR_ROOT = Path(TEST_DATA_DIR, "inheritance_resolution_error")


def test_inheritance_resolution_error(solc_binary_path) -> None:
with pytest.raises(InheritanceResolutionError):
solc_path = solc_binary_path("0.8.0")
Slither(
Path(INHERITANCE_ERROR_ROOT, "contract_with_duplicate_names.sol").as_posix(),
solc=solc_path,
)

0 comments on commit d759a86

Please sign in to comment.