Merge branch 'dev' into loc-printer

pull/1882/head
devtooligan 1 year ago committed by GitHub
commit 1a1fc0e1a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      slither/solc_parsing/slither_compilation_unit_solc.py
  2. 2
      tests/unit/core/test_data/inheritance_resolution_error/contract_with_duplicate_names.sol
  3. 1
      tests/unit/core/test_data/inheritance_resolution_error/import.sol
  4. 18
      tests/unit/core/test_error_messages.py

@ -33,6 +33,10 @@ logger = logging.getLogger("SlitherSolcParsing")
logger.setLevel(logging.INFO)
class InheritanceResolutionError(SlitherException):
pass
def _handle_import_aliases(
symbol_aliases: Dict, import_directive: Import, scope: FileScope
) -> None:
@ -194,6 +198,13 @@ class SlitherCompilationUnitSolc(CallerContextExpression):
# 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
@ -432,7 +443,12 @@ Please rename it, this name is reserved for Slither's internals"""
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])

@ -0,0 +1,2 @@
import {ERC20 as ERC20_1} from "./import.sol";
contract ERC20 is ERC20_1 {}

@ -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,
)
Loading…
Cancel
Save