Merge pull request #1679 from crytic/abstract-contract

Abstract contract property
pull/1772/head
Feist Josselin 2 years ago committed by GitHub
commit d35b10be3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      slither/core/declarations/contract.py
  2. 1
      slither/solc_parsing/declarations/contract.py
  3. 5
      tests/function_features/abstract.sol
  4. 5
      tests/function_features/implicit_abstract.sol
  5. 2
      tests/slithir/test_ternary_expressions.py
  6. 15
      tests/test_features.py

@ -85,6 +85,7 @@ class Contract(SourceMapping): # pylint: disable=too-many-public-methods
self._kind: Optional[str] = None self._kind: Optional[str] = None
self._is_interface: bool = False self._is_interface: bool = False
self._is_library: bool = False self._is_library: bool = False
self._is_fully_implemented: bool = False
self._signatures: Optional[List[str]] = None self._signatures: Optional[List[str]] = None
self._signatures_declared: Optional[List[str]] = None self._signatures_declared: Optional[List[str]] = None
@ -192,6 +193,14 @@ class Contract(SourceMapping): # pylint: disable=too-many-public-methods
def comments(self, comments: str): def comments(self, comments: str):
self._comments = comments self._comments = comments
@property
def is_fully_implemented(self) -> bool:
return self._is_fully_implemented
@is_fully_implemented.setter
def is_fully_implemented(self, is_fully_implemented: bool):
self._is_fully_implemented = is_fully_implemented
# endregion # endregion
################################################################################### ###################################################################################
################################################################################### ###################################################################################

@ -164,6 +164,7 @@ class ContractSolc(CallerContextExpression):
elif attributes["contractKind"] == "library": elif attributes["contractKind"] == "library":
self._contract.is_library = True self._contract.is_library = True
self._contract.contract_kind = attributes["contractKind"] self._contract.contract_kind = attributes["contractKind"]
self._contract.is_fully_implemented = attributes["fullyImplemented"]
self._linearized_base_contracts = attributes["linearizedBaseContracts"] self._linearized_base_contracts = attributes["linearizedBaseContracts"]
# self._contract.fullyImplemented = attributes["fullyImplemented"] # self._contract.fullyImplemented = attributes["fullyImplemented"]

@ -0,0 +1,5 @@
pragma solidity ^0.8.0;
abstract contract ExplicitAbstract{
function f() virtual public;
}

@ -0,0 +1,5 @@
pragma solidity ^0.5.0;
contract ImplicitAbstract{
function f() public;
}

@ -1,3 +1,4 @@
from solc_select import solc_select
from slither import Slither from slither import Slither
from slither.core.cfg.node import NodeType from slither.core.cfg.node import NodeType
from slither.slithir.operations import Assignment from slither.slithir.operations import Assignment
@ -6,6 +7,7 @@ from slither.core.expressions import AssignmentOperation, TupleExpression
# pylint: disable=too-many-nested-blocks # pylint: disable=too-many-nested-blocks
def test_ternary_conversions() -> None: def test_ternary_conversions() -> None:
"""This tests that true and false sons define the same number of variables that the father node declares""" """This tests that true and false sons define the same number of variables that the father node declares"""
solc_select.switch_global_version("0.8.0", always_install=True)
slither = Slither("./tests/slithir/ternary_expressions.sol") slither = Slither("./tests/slithir/ternary_expressions.sol")
for contract in slither.contracts: for contract in slither.contracts:
for function in contract.functions: for function in contract.functions:

@ -202,3 +202,18 @@ def test_using_for_global_collision() -> None:
compilation = CryticCompile(standard_json) compilation = CryticCompile(standard_json)
sl = Slither(compilation) sl = Slither(compilation)
_run_all_detectors(sl) _run_all_detectors(sl)
def test_abstract_contract() -> None:
solc_select.switch_global_version("0.8.0", always_install=True)
slither = Slither("./tests/function_features/abstract.sol")
assert not slither.contracts[0].is_fully_implemented
solc_select.switch_global_version("0.5.0", always_install=True)
slither = Slither("./tests/function_features/implicit_abstract.sol")
assert not slither.contracts[0].is_fully_implemented
slither = Slither(
"./tests/function_features/implicit_abstract.sol", solc_force_legacy_json=True
)
assert not slither.contracts[0].is_fully_implemented

Loading…
Cancel
Save