From ce4485317795f8361c8a3975d5ed5ba1bdcbfd0c Mon Sep 17 00:00:00 2001 From: Josselin Date: Fri, 5 Jul 2019 15:25:14 +0200 Subject: [PATCH 1/2] Minor fixes Fix travis --- scripts/tests_generate_expected_json_4.sh | 2 +- slither/core/declarations/function.py | 2 +- .../possible_const_state_variables.py | 2 +- slither/solc_parsing/declarations/contract.py | 1 - ...deprecated_calls.deprecated-standards.json | 80 +++++++++++++++++++ .../deprecated_calls.deprecated-standards.txt | 4 +- utils/similarity/encode.py | 2 +- 7 files changed, 87 insertions(+), 6 deletions(-) diff --git a/scripts/tests_generate_expected_json_4.sh b/scripts/tests_generate_expected_json_4.sh index 4e1def80c..e748e4f42 100755 --- a/scripts/tests_generate_expected_json_4.sh +++ b/scripts/tests_generate_expected_json_4.sh @@ -21,7 +21,7 @@ generate_expected_json(){ } -#generate_expected_json tests/deprecated_calls.sol "deprecated-standards" +generate_expected_json tests/deprecated_calls.sol "deprecated-standards" #generate_expected_json tests/erc20_indexed.sol "erc20-indexed" #generate_expected_json tests/incorrect_erc20_interface.sol "erc20-interface" #generate_expected_json tests/incorrect_erc721_interface.sol "erc721-interface" diff --git a/slither/core/declarations/function.py b/slither/core/declarations/function.py index 631e262bf..7243a7c03 100644 --- a/slither/core/declarations/function.py +++ b/slither/core/declarations/function.py @@ -122,7 +122,7 @@ class Function(ChildContract, ChildInheritance, SourceMapping): elif self._function_type == FunctionType.FALLBACK: return 'fallback' elif self._function_type == FunctionType.CONSTRUCTOR_VARIABLES: - return 'slither_constructor_variables' + return 'slitherConstructorVariables' return self._name @property diff --git a/slither/detectors/variables/possible_const_state_variables.py b/slither/detectors/variables/possible_const_state_variables.py index f062a0c7a..9d30bcfcf 100644 --- a/slither/detectors/variables/possible_const_state_variables.py +++ b/slither/detectors/variables/possible_const_state_variables.py @@ -76,7 +76,7 @@ class ConstCandidateStateVars(AbstractDetector): all_functions = [c.all_functions_called for c in self.slither.contracts] all_functions = list(set([item for sublist in all_functions for item in sublist])) - all_variables_written = [f.state_variables_written for f in all_functions] + all_variables_written = [f.state_variables_written for f in all_functions if not f.is_constructor_variables] all_variables_written = set([item for sublist in all_variables_written for item in sublist]) constable_variables = [v for v in all_non_constant_elementary_variables diff --git a/slither/solc_parsing/declarations/contract.py b/slither/solc_parsing/declarations/contract.py index f5fba278c..e931dddb7 100644 --- a/slither/solc_parsing/declarations/contract.py +++ b/slither/solc_parsing/declarations/contract.py @@ -377,7 +377,6 @@ class ContractSolc04(Contract): node.set_offset(variable.source_mapping, self.slither) node.set_function(func) func.add_node(node) - print(variable.expression) expression = AssignmentOperation(Identifier(variable), variable.expression, AssignmentOperationType.ASSIGN, diff --git a/tests/expected_json/deprecated_calls.deprecated-standards.json b/tests/expected_json/deprecated_calls.deprecated-standards.json index c25d611b8..2b9c385d1 100644 --- a/tests/expected_json/deprecated_calls.deprecated-standards.json +++ b/tests/expected_json/deprecated_calls.deprecated-standards.json @@ -692,6 +692,86 @@ } } ] + }, + { + "check": "deprecated-standards", + "impact": "Informational", + "confidence": "High", + "description": "Deprecated standard detected @ tests/deprecated_calls.sol#2:\n\t- Usage of \"block.blockhash()\" should be replaced with \"blockhash()\"\n", + "elements": [ + { + "type": "node", + "name": "globalBlockHash = block.blockhash(0)", + "source_mapping": { + "start": 48, + "length": 44, + "filename_used": "/home/travis/build/crytic/slither/tests/deprecated_calls.sol", + "filename_relative": "tests/deprecated_calls.sol", + "filename_absolute": "/home/travis/build/crytic/slither/tests/deprecated_calls.sol", + "filename_short": "tests/deprecated_calls.sol", + "is_dependency": false, + "lines": [ + 2 + ], + "starting_column": 5, + "ending_column": 49 + }, + "type_specific_fields": { + "parent": { + "type": "function", + "name": "slitherConstructorVariables", + "source_mapping": null, + "type_specific_fields": { + "parent": { + "type": "contract", + "name": "ContractWithDeprecatedReferences", + "source_mapping": { + "start": 0, + "length": 906, + "filename_used": "/home/travis/build/crytic/slither/tests/deprecated_calls.sol", + "filename_relative": "tests/deprecated_calls.sol", + "filename_absolute": "/home/travis/build/crytic/slither/tests/deprecated_calls.sol", + "filename_short": "tests/deprecated_calls.sol", + "is_dependency": false, + "lines": [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27 + ], + "starting_column": 1, + "ending_column": null + } + }, + "signature": "slitherConstructorVariables()" + } + } + } + } + ] } ] } diff --git a/tests/expected_json/deprecated_calls.deprecated-standards.txt b/tests/expected_json/deprecated_calls.deprecated-standards.txt index 7056ea4ce..63d07a08d 100644 --- a/tests/expected_json/deprecated_calls.deprecated-standards.txt +++ b/tests/expected_json/deprecated_calls.deprecated-standards.txt @@ -13,5 +13,7 @@ Deprecated standard detected @ tests/deprecated_calls.sol#22: - Usage of "callcode" should be replaced with "delegatecall" Deprecated standard detected @ tests/deprecated_calls.sol#25: - Usage of "suicide()" should be replaced with "selfdestruct()" +Deprecated standard detected @ tests/deprecated_calls.sol#2: + - Usage of "block.blockhash()" should be replaced with "blockhash()" Reference: https://github.com/crytic/slither/wiki/Detector-Documentation#deprecated-standards -INFO:Slither:tests/deprecated_calls.sol analyzed (1 contracts), 7 result(s) found +INFO:Slither:tests/deprecated_calls.sol analyzed (1 contracts), 8 result(s) found diff --git a/utils/similarity/encode.py b/utils/similarity/encode.py index f20d316a8..06b3691ed 100644 --- a/utils/similarity/encode.py +++ b/utils/similarity/encode.py @@ -195,7 +195,7 @@ def encode_contract(cfilename, **kwargs): # Iterate over all the functions for function in contract.functions_declared: - if function.nodes == []: + if function.nodes == [] or function.is_constructor_variables: continue x = (cfilename,contract.name,function.name) From 3fff0bf5b286cdf5d3802fdf7439f26f972a9356 Mon Sep 17 00:00:00 2001 From: Josselin Date: Fri, 5 Jul 2019 15:34:59 +0200 Subject: [PATCH 2/2] Upadte etherscan travis test --- scripts/travis_test_etherscan.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/travis_test_etherscan.sh b/scripts/travis_test_etherscan.sh index c96eca12e..68b03f89f 100755 --- a/scripts/travis_test_etherscan.sh +++ b/scripts/travis_test_etherscan.sh @@ -18,7 +18,7 @@ fi slither rinkeby:0xFe05820C5A92D9bc906D4A46F662dbeba794d3b7 --solc "./solc-0.4.25" -if [ $? -ne 76 ] +if [ $? -ne 75 ] then echo "Etherscan test failed" exit -1