Merge pull request #1774 from crytic/dev

Sync dev <> master
pull/1777/head
Feist Josselin 2 years ago committed by GitHub
commit 776dcab440
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 41
      README.md
  2. 2
      setup.py
  3. 9
      slither/core/declarations/contract.py
  4. 10
      slither/detectors/attributes/incorrect_solc.py
  5. 2
      slither/detectors/reentrancy/reentrancy_eth.py
  6. 1
      slither/solc_parsing/declarations/contract.py
  7. 6
      slither/visitors/slithir/expression_to_slithir.py
  8. 10
      tests/detectors/solc-version/0.5.16/dynamic_1.sol.0.5.16.IncorrectSolc.json
  9. 10
      tests/detectors/solc-version/0.5.16/dynamic_2.sol.0.5.16.IncorrectSolc.json
  10. 48
      tests/detectors/solc-version/0.5.16/static.sol.0.5.16.IncorrectSolc.json
  11. 10
      tests/detectors/solc-version/0.6.11/dynamic_1.sol.0.6.11.IncorrectSolc.json
  12. 10
      tests/detectors/solc-version/0.6.11/dynamic_2.sol.0.6.11.IncorrectSolc.json
  13. 48
      tests/detectors/solc-version/0.6.11/static.sol.0.6.11.IncorrectSolc.json
  14. 10
      tests/detectors/solc-version/0.7.6/dynamic_1.sol.0.7.6.IncorrectSolc.json
  15. 10
      tests/detectors/solc-version/0.7.6/dynamic_2.sol.0.7.6.IncorrectSolc.json
  16. 48
      tests/detectors/solc-version/0.7.6/static.sol.0.7.6.IncorrectSolc.json
  17. 5
      tests/function_features/abstract.sol
  18. 5
      tests/function_features/implicit_abstract.sol
  19. 2
      tests/slithir/test_ternary_expressions.py
  20. 15
      tests/test_features.py
  21. 40
      tests/test_ssa_generation.py

@ -151,26 +151,27 @@ Num | Detector | What it Detects | Impact | Confidence
61 | `assembly` | [Assembly usage](https://github.com/crytic/slither/wiki/Detector-Documentation#assembly-usage) | Informational | High 61 | `assembly` | [Assembly usage](https://github.com/crytic/slither/wiki/Detector-Documentation#assembly-usage) | Informational | High
62 | `assert-state-change` | [Assert state change](https://github.com/crytic/slither/wiki/Detector-Documentation#assert-state-change) | Informational | High 62 | `assert-state-change` | [Assert state change](https://github.com/crytic/slither/wiki/Detector-Documentation#assert-state-change) | Informational | High
63 | `boolean-equal` | [Comparison to boolean constant](https://github.com/crytic/slither/wiki/Detector-Documentation#boolean-equality) | Informational | High 63 | `boolean-equal` | [Comparison to boolean constant](https://github.com/crytic/slither/wiki/Detector-Documentation#boolean-equality) | Informational | High
64 | `deprecated-standards` | [Deprecated Solidity Standards](https://github.com/crytic/slither/wiki/Detector-Documentation#deprecated-standards) | Informational | High 64 | `cyclomatic-complexity` | [Detects functions with high (> 11) cyclomatic complexity](https://github.com/crytic/slither/wiki/Detector-Documentation#cyclomatic-complexity) | Informational | High
65 | `erc20-indexed` | [Un-indexed ERC20 event parameters](https://github.com/crytic/slither/wiki/Detector-Documentation#unindexed-erc20-event-parameters) | Informational | High 65 | `deprecated-standards` | [Deprecated Solidity Standards](https://github.com/crytic/slither/wiki/Detector-Documentation#deprecated-standards) | Informational | High
66 | `function-init-state` | [Function initializing state variables](https://github.com/crytic/slither/wiki/Detector-Documentation#function-initializing-state) | Informational | High 66 | `erc20-indexed` | [Un-indexed ERC20 event parameters](https://github.com/crytic/slither/wiki/Detector-Documentation#unindexed-erc20-event-parameters) | Informational | High
67 | `low-level-calls` | [Low level calls](https://github.com/crytic/slither/wiki/Detector-Documentation#low-level-calls) | Informational | High 67 | `function-init-state` | [Function initializing state variables](https://github.com/crytic/slither/wiki/Detector-Documentation#function-initializing-state) | Informational | High
68 | `missing-inheritance` | [Missing inheritance](https://github.com/crytic/slither/wiki/Detector-Documentation#missing-inheritance) | Informational | High 68 | `low-level-calls` | [Low level calls](https://github.com/crytic/slither/wiki/Detector-Documentation#low-level-calls) | Informational | High
69 | `naming-convention` | [Conformity to Solidity naming conventions](https://github.com/crytic/slither/wiki/Detector-Documentation#conformance-to-solidity-naming-conventions) | Informational | High 69 | `missing-inheritance` | [Missing inheritance](https://github.com/crytic/slither/wiki/Detector-Documentation#missing-inheritance) | Informational | High
70 | `pragma` | [If different pragma directives are used](https://github.com/crytic/slither/wiki/Detector-Documentation#different-pragma-directives-are-used) | Informational | High 70 | `naming-convention` | [Conformity to Solidity naming conventions](https://github.com/crytic/slither/wiki/Detector-Documentation#conformance-to-solidity-naming-conventions) | Informational | High
71 | `redundant-statements` | [Redundant statements](https://github.com/crytic/slither/wiki/Detector-Documentation#redundant-statements) | Informational | High 71 | `pragma` | [If different pragma directives are used](https://github.com/crytic/slither/wiki/Detector-Documentation#different-pragma-directives-are-used) | Informational | High
72 | `solc-version` | [Incorrect Solidity version](https://github.com/crytic/slither/wiki/Detector-Documentation#incorrect-versions-of-solidity) | Informational | High 72 | `redundant-statements` | [Redundant statements](https://github.com/crytic/slither/wiki/Detector-Documentation#redundant-statements) | Informational | High
73 | `unimplemented-functions` | [Unimplemented functions](https://github.com/crytic/slither/wiki/Detector-Documentation#unimplemented-functions) | Informational | High 73 | `solc-version` | [Incorrect Solidity version](https://github.com/crytic/slither/wiki/Detector-Documentation#incorrect-versions-of-solidity) | Informational | High
74 | `unused-state` | [Unused state variables](https://github.com/crytic/slither/wiki/Detector-Documentation#unused-state-variable) | Informational | High 74 | `unimplemented-functions` | [Unimplemented functions](https://github.com/crytic/slither/wiki/Detector-Documentation#unimplemented-functions) | Informational | High
75 | `costly-loop` | [Costly operations in a loop](https://github.com/crytic/slither/wiki/Detector-Documentation#costly-operations-inside-a-loop) | Informational | Medium 75 | `unused-state` | [Unused state variables](https://github.com/crytic/slither/wiki/Detector-Documentation#unused-state-variable) | Informational | High
76 | `dead-code` | [Functions that are not used](https://github.com/crytic/slither/wiki/Detector-Documentation#dead-code) | Informational | Medium 76 | `costly-loop` | [Costly operations in a loop](https://github.com/crytic/slither/wiki/Detector-Documentation#costly-operations-inside-a-loop) | Informational | Medium
77 | `reentrancy-unlimited-gas` | [Reentrancy vulnerabilities through send and transfer](https://github.com/crytic/slither/wiki/Detector-Documentation#reentrancy-vulnerabilities-4) | Informational | Medium 77 | `dead-code` | [Functions that are not used](https://github.com/crytic/slither/wiki/Detector-Documentation#dead-code) | Informational | Medium
78 | `similar-names` | [Variable names are too similar](https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-too-similar) | Informational | Medium 78 | `reentrancy-unlimited-gas` | [Reentrancy vulnerabilities through send and transfer](https://github.com/crytic/slither/wiki/Detector-Documentation#reentrancy-vulnerabilities-4) | Informational | Medium
79 | `too-many-digits` | [Conformance to numeric notation best practices](https://github.com/crytic/slither/wiki/Detector-Documentation#too-many-digits) | Informational | Medium 79 | `similar-names` | [Variable names are too similar](https://github.com/crytic/slither/wiki/Detector-Documentation#variable-names-too-similar) | Informational | Medium
80 | `constable-states` | [State variables that could be declared constant](https://github.com/crytic/slither/wiki/Detector-Documentation#state-variables-that-could-be-declared-constant) | Optimization | High 80 | `too-many-digits` | [Conformance to numeric notation best practices](https://github.com/crytic/slither/wiki/Detector-Documentation#too-many-digits) | Informational | Medium
81 | `external-function` | [Public function that could be declared external](https://github.com/crytic/slither/wiki/Detector-Documentation#public-function-that-could-be-declared-external) | Optimization | High 81 | `constable-states` | [State variables that could be declared constant](https://github.com/crytic/slither/wiki/Detector-Documentation#state-variables-that-could-be-declared-constant) | Optimization | High
82 | `immutable-states` | [State variables that could be declared immutable](https://github.com/crytic/slither/wiki/Detector-Documentation#state-variables-that-could-be-declared-immutable) | Optimization | High 82 | `external-function` | [Public function that could be declared external](https://github.com/crytic/slither/wiki/Detector-Documentation#public-function-that-could-be-declared-external) | Optimization | High
83 | `var-read-using-this` | [Contract reads its own variable using `this`](https://github.com/crytic/slither/wiki/Vulnerabilities-Description#public-variable-read-in-external-context) | Optimization | High 83 | `immutable-states` | [State variables that could be declared immutable](https://github.com/crytic/slither/wiki/Detector-Documentation#state-variables-that-could-be-declared-immutable) | Optimization | High
84 | `var-read-using-this` | [Contract reads its own variable using `this`](https://github.com/crytic/slither/wiki/Vulnerabilities-Description#public-variable-read-in-external-context) | Optimization | High
For more information, see For more information, see
- The [Detector Documentation](https://github.com/crytic/slither/wiki/Detector-Documentation) for details on each detector - The [Detector Documentation](https://github.com/crytic/slither/wiki/Detector-Documentation) for details on each detector

@ -17,6 +17,7 @@ setup(
"pycryptodome>=3.4.6", "pycryptodome>=3.4.6",
# "crytic-compile>=0.3.0", # "crytic-compile>=0.3.0",
"crytic-compile@git+https://github.com/crytic/crytic-compile.git@master#egg=crytic-compile", "crytic-compile@git+https://github.com/crytic/crytic-compile.git@master#egg=crytic-compile",
"web3>=6.0.0",
], ],
extras_require={ extras_require={
"dev": [ "dev": [
@ -29,7 +30,6 @@ setup(
"numpy", "numpy",
"openai", "openai",
"pdoc", "pdoc",
"web3>=6.0.0",
], ],
}, },
license="AGPL-3.0", license="AGPL-3.0",

@ -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
################################################################################### ###################################################################################
################################################################################### ###################################################################################

@ -43,10 +43,7 @@ We also recommend avoiding complex `pragma` statement."""
# region wiki_recommendation # region wiki_recommendation
WIKI_RECOMMENDATION = """ WIKI_RECOMMENDATION = """
Deploy with any of the following Solidity versions: Deploy with any of the following Solidity versions:
- 0.5.16 - 0.5.17 - 0.8.18
- 0.6.11 - 0.6.12
- 0.7.5 - 0.7.6
- 0.8.16
The recommendations take into account: The recommendations take into account:
- Risks related to recent releases - Risks related to recent releases
@ -62,13 +59,14 @@ Consider using the latest version of Solidity for testing."""
OLD_VERSION_TXT = "allows old versions" OLD_VERSION_TXT = "allows old versions"
LESS_THAN_TXT = "uses lesser than" LESS_THAN_TXT = "uses lesser than"
TOO_RECENT_VERSION_TXT = "necessitates a version too recent to be trusted. Consider deploying with 0.6.12/0.7.6/0.8.16"
BUGGY_VERSION_TXT = ( BUGGY_VERSION_TXT = (
"is known to contain severe issues (https://solidity.readthedocs.io/en/latest/bugs.html)" "is known to contain severe issues (https://solidity.readthedocs.io/en/latest/bugs.html)"
) )
# Indicates the allowed versions. Must be formatted in increasing order. # Indicates the allowed versions. Must be formatted in increasing order.
ALLOWED_VERSIONS = ["0.5.16", "0.5.17", "0.6.11", "0.6.12", "0.7.5", "0.7.6", "0.8.16"] ALLOWED_VERSIONS = ["0.8.18"]
TOO_RECENT_VERSION_TXT = f"necessitates a version too recent to be trusted. Consider deploying with {'/'.join(ALLOWED_VERSIONS)}."
# Indicates the versions that should not be used. # Indicates the versions that should not be used.
BUGGY_VERSIONS = [ BUGGY_VERSIONS = [

@ -38,7 +38,7 @@ Do not report reentrancies that don't involve Ether (see `reentrancy-no-eth`)"""
```solidity ```solidity
function withdrawBalance(){ function withdrawBalance(){
// send userBalance[msg.sender] Ether to msg.sender // send userBalance[msg.sender] Ether to msg.sender
// if mgs.sender is a contract, it will call its fallback function // if msg.sender is a contract, it will call its fallback function
if( ! (msg.sender.call.value(userBalance[msg.sender])() ) ){ if( ! (msg.sender.call.value(userBalance[msg.sender])() ) ){
throw; throw;
} }

@ -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"]

@ -220,6 +220,12 @@ class ExpressionToSlithIR(ExpressionVisitor):
operation.set_expression(expression) operation.set_expression(expression)
self._result.append(operation) self._result.append(operation)
set_val(expression, left) set_val(expression, left)
elif isinstance(left.type, ArrayType):
# Special case for init of array, when the right has only one element
operation = InitArray([right], left)
operation.set_expression(expression)
self._result.append(operation)
set_val(expression, left)
else: else:
operation = convert_assignment( operation = convert_assignment(
left, right, expression.type, expression.expression_return_type left, right, expression.type, expression.expression_return_type

@ -1,5 +1,15 @@
[ [
[ [
{
"elements": [],
"description": "solc-0.5.16 is not recommended for deployment\n",
"markdown": "solc-0.5.16 is not recommended for deployment\n",
"first_markdown_element": "",
"id": "94ddf430efb860e471a768a108c851848fa998e8a2c489c6fb23ed71d3ef4b09",
"check": "solc-version",
"impact": "Informational",
"confidence": "High"
},
{ {
"elements": [ "elements": [
{ {

@ -38,6 +38,16 @@
"check": "solc-version", "check": "solc-version",
"impact": "Informational", "impact": "Informational",
"confidence": "High" "confidence": "High"
},
{
"elements": [],
"description": "solc-0.5.16 is not recommended for deployment\n",
"markdown": "solc-0.5.16 is not recommended for deployment\n",
"first_markdown_element": "",
"id": "94ddf430efb860e471a768a108c851848fa998e8a2c489c6fb23ed71d3ef4b09",
"check": "solc-version",
"impact": "Informational",
"confidence": "High"
} }
] ]
] ]

@ -1,3 +1,49 @@
[ [
[] [
{
"elements": [
{
"type": "pragma",
"name": "0.5.16",
"source_mapping": {
"start": 0,
"length": 23,
"filename_relative": "tests/detectors/solc-version/0.5.16/static.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/solc-version/0.5.16/static.sol",
"is_dependency": false,
"lines": [
1
],
"starting_column": 1,
"ending_column": 24
},
"type_specific_fields": {
"directive": [
"solidity",
"0.5",
".16"
]
}
}
],
"description": "Pragma version0.5.16 (tests/detectors/solc-version/0.5.16/static.sol#1) allows old versions\n",
"markdown": "Pragma version[0.5.16](tests/detectors/solc-version/0.5.16/static.sol#L1) allows old versions\n",
"first_markdown_element": "tests/detectors/solc-version/0.5.16/static.sol#L1",
"id": "2407d991de90e57d2f6b6bdbc61bb939845a5c0bb2d82910ed4c49abff2ab6e3",
"check": "solc-version",
"impact": "Informational",
"confidence": "High"
},
{
"elements": [],
"description": "solc-0.5.16 is not recommended for deployment\n",
"markdown": "solc-0.5.16 is not recommended for deployment\n",
"first_markdown_element": "",
"id": "94ddf430efb860e471a768a108c851848fa998e8a2c489c6fb23ed71d3ef4b09",
"check": "solc-version",
"impact": "Informational",
"confidence": "High"
}
]
] ]

@ -35,6 +35,16 @@
"check": "solc-version", "check": "solc-version",
"impact": "Informational", "impact": "Informational",
"confidence": "High" "confidence": "High"
},
{
"elements": [],
"description": "solc-0.6.11 is not recommended for deployment\n",
"markdown": "solc-0.6.11 is not recommended for deployment\n",
"first_markdown_element": "",
"id": "bafd522d637977886f038e619ad47c1987efedc6c4c24515e6e27b23585535bd",
"check": "solc-version",
"impact": "Informational",
"confidence": "High"
} }
] ]
] ]

@ -38,6 +38,16 @@
"check": "solc-version", "check": "solc-version",
"impact": "Informational", "impact": "Informational",
"confidence": "High" "confidence": "High"
},
{
"elements": [],
"description": "solc-0.6.11 is not recommended for deployment\n",
"markdown": "solc-0.6.11 is not recommended for deployment\n",
"first_markdown_element": "",
"id": "bafd522d637977886f038e619ad47c1987efedc6c4c24515e6e27b23585535bd",
"check": "solc-version",
"impact": "Informational",
"confidence": "High"
} }
] ]
] ]

@ -1,3 +1,49 @@
[ [
[] [
{
"elements": [
{
"type": "pragma",
"name": "0.6.11",
"source_mapping": {
"start": 0,
"length": 23,
"filename_relative": "tests/detectors/solc-version/0.6.11/static.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/solc-version/0.6.11/static.sol",
"is_dependency": false,
"lines": [
1
],
"starting_column": 1,
"ending_column": 24
},
"type_specific_fields": {
"directive": [
"solidity",
"0.6",
".11"
]
}
}
],
"description": "Pragma version0.6.11 (tests/detectors/solc-version/0.6.11/static.sol#1) allows old versions\n",
"markdown": "Pragma version[0.6.11](tests/detectors/solc-version/0.6.11/static.sol#L1) allows old versions\n",
"first_markdown_element": "tests/detectors/solc-version/0.6.11/static.sol#L1",
"id": "ad7b24eed22ac098a57ae02ade0ccffb4cb094e851effe93cad1d0a65b489816",
"check": "solc-version",
"impact": "Informational",
"confidence": "High"
},
{
"elements": [],
"description": "solc-0.6.11 is not recommended for deployment\n",
"markdown": "solc-0.6.11 is not recommended for deployment\n",
"first_markdown_element": "",
"id": "bafd522d637977886f038e619ad47c1987efedc6c4c24515e6e27b23585535bd",
"check": "solc-version",
"impact": "Informational",
"confidence": "High"
}
]
] ]

@ -1,5 +1,15 @@
[ [
[ [
{
"elements": [],
"description": "solc-0.7.6 is not recommended for deployment\n",
"markdown": "solc-0.7.6 is not recommended for deployment\n",
"first_markdown_element": "",
"id": "ddb8ee36d9dd69b14eab702506268f8f9ef3283777d042e197277e29407b386e",
"check": "solc-version",
"impact": "Informational",
"confidence": "High"
},
{ {
"elements": [ "elements": [
{ {

@ -38,6 +38,16 @@
"check": "solc-version", "check": "solc-version",
"impact": "Informational", "impact": "Informational",
"confidence": "High" "confidence": "High"
},
{
"elements": [],
"description": "solc-0.7.6 is not recommended for deployment\n",
"markdown": "solc-0.7.6 is not recommended for deployment\n",
"first_markdown_element": "",
"id": "ddb8ee36d9dd69b14eab702506268f8f9ef3283777d042e197277e29407b386e",
"check": "solc-version",
"impact": "Informational",
"confidence": "High"
} }
] ]
] ]

@ -1,3 +1,49 @@
[ [
[] [
{
"elements": [],
"description": "solc-0.7.6 is not recommended for deployment\n",
"markdown": "solc-0.7.6 is not recommended for deployment\n",
"first_markdown_element": "",
"id": "ddb8ee36d9dd69b14eab702506268f8f9ef3283777d042e197277e29407b386e",
"check": "solc-version",
"impact": "Informational",
"confidence": "High"
},
{
"elements": [
{
"type": "pragma",
"name": "0.7.6",
"source_mapping": {
"start": 0,
"length": 22,
"filename_relative": "tests/detectors/solc-version/0.7.6/static.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/solc-version/0.7.6/static.sol",
"is_dependency": false,
"lines": [
1
],
"starting_column": 1,
"ending_column": 23
},
"type_specific_fields": {
"directive": [
"solidity",
"0.7",
".6"
]
}
}
],
"description": "Pragma version0.7.6 (tests/detectors/solc-version/0.7.6/static.sol#1) allows old versions\n",
"markdown": "Pragma version[0.7.6](tests/detectors/solc-version/0.7.6/static.sol#L1) allows old versions\n",
"first_markdown_element": "tests/detectors/solc-version/0.7.6/static.sol#L1",
"id": "e7a5c0ee3d0af7a59907908f88499f79435e302745284c6279167a1cc209b4ed",
"check": "solc-version",
"impact": "Informational",
"confidence": "High"
}
]
] ]

@ -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

@ -27,6 +27,7 @@ from slither.slithir.operations import (
BinaryType, BinaryType,
InternalCall, InternalCall,
Index, Index,
InitArray,
) )
from slither.slithir.utils.ssa import is_used_later from slither.slithir.utils.ssa import is_used_later
from slither.slithir.variables import ( from slither.slithir.variables import (
@ -796,20 +797,20 @@ def test_memory_array():
uint val1; uint val1;
uint val2; uint val2;
} }
function test_array() internal { function test_array() internal {
A[] memory a= new A[](4); A[] memory a= new A[](4);
// Create REF_0 -> a_1[2] // Create REF_0 -> a_1[2]
accept_array_entry(a[2]); accept_array_entry(a[2]);
// Create REF_1 -> a_1[3] // Create REF_1 -> a_1[3]
accept_array_entry(a[3]); accept_array_entry(a[3]);
A memory alocal; A memory alocal;
accept_array_entry(alocal); accept_array_entry(alocal);
} }
// val_1 = ϕ(val_0, REF_0, REF_1, alocal_1) // val_1 = ϕ(val_0, REF_0, REF_1, alocal_1)
// val_0 is an unknown external value // val_0 is an unknown external value
function accept_array_entry(A memory val) public returns (uint) { function accept_array_entry(A memory val) public returns (uint) {
@ -818,9 +819,9 @@ def test_memory_array():
// Create REF_2 -> val_1.val1 // Create REF_2 -> val_1.val1
return b(val.val1); return b(val.val1);
} }
function b(uint arg) public returns (uint){ function b(uint arg) public returns (uint){
// arg_1 = ϕ(arg_0, zero_1, REF_2) // arg_1 = ϕ(arg_0, zero_1, REF_2)
return arg + 1; return arg + 1;
} }
}""" }"""
@ -862,12 +863,12 @@ def test_storage_array():
uint val1; uint val1;
uint val2; uint val2;
} }
// NOTE(hbrodin): a is never written, should only become a_0. Same for astorage (astorage_0). Phi-nodes at entry // NOTE(hbrodin): a is never written, should only become a_0. Same for astorage (astorage_0). Phi-nodes at entry
// should only add new versions of a state variable if it is actually written. // should only add new versions of a state variable if it is actually written.
A[] a; A[] a;
A astorage; A astorage;
function test_array() internal { function test_array() internal {
accept_array_entry(a[2]); accept_array_entry(a[2]);
accept_array_entry(a[3]); accept_array_entry(a[3]);
@ -877,7 +878,7 @@ def test_storage_array():
function accept_array_entry(A storage val) internal returns (uint) { function accept_array_entry(A storage val) internal returns (uint) {
// val is either a[2], a[3] or astorage_0. Ideally this could be identified. // val is either a[2], a[3] or astorage_0. Ideally this could be identified.
uint five = 5; uint five = 5;
// NOTE(hbrodin): If the following line is enabled, there would ideally be a phi-node representing writes // NOTE(hbrodin): If the following line is enabled, there would ideally be a phi-node representing writes
// to either a or astorage. // to either a or astorage.
//val.val2 = 4; //val.val2 = 4;
@ -1059,3 +1060,20 @@ def test_issue_473():
# return is for second phi # return is for second phi
assert len(return_value.values) == 1 assert len(return_value.values) == 1
assert second_phi.lvalue in return_value.values assert second_phi.lvalue in return_value.values
def test_issue_1748():
source = """
contract Contract {
uint[] arr;
function foo(uint i) public {
arr = [1];
}
}
"""
with slither_from_source(source) as slither:
c = slither.get_contract_from_name("Contract")[0]
f = c.functions[0]
operations = f.slithir_operations
assign_op = operations[0]
assert isinstance(assign_op, InitArray)

Loading…
Cancel
Save