fix constructor var not detected as candidate, separate detectors

pull/1455/head
alpharush 2 years ago
parent c23c0c41d0
commit afb7342619
  1. 3
      slither/detectors/all_detectors.py
  2. 45
      slither/detectors/variables/could_be_constant.py
  3. 44
      slither/detectors/variables/could_be_immutable.py
  4. 141
      slither/detectors/variables/possible_const_state_variables.py
  5. 123
      slither/detectors/variables/unchanged_state_variables.py
  6. 6
      slither/formatters/variables/unchanged_state_variables.py
  7. 6
      slither/tools/slither_format/slither_format.py
  8. 5
      tests/detectors/constable-states/0.4.25/const_state_variables.sol
  9. 18
      tests/detectors/constable-states/0.4.25/const_state_variables.sol.0.4.25.CouldBeConstant.json
  10. 5
      tests/detectors/constable-states/0.5.16/const_state_variables.sol
  11. 27
      tests/detectors/constable-states/0.5.16/const_state_variables.sol.0.5.16.CouldBeConstant.json
  12. 37
      tests/detectors/constable-states/0.6.11/const_state_variables.sol
  13. 169
      tests/detectors/constable-states/0.6.11/const_state_variables.sol.0.6.11.CouldBeConstant.json
  14. 28
      tests/detectors/constable-states/0.7.6/const_state_variables.sol
  15. 406
      tests/detectors/constable-states/0.7.6/const_state_variables.sol.0.7.6.CouldBeConstant.json
  16. 30
      tests/detectors/constable-states/0.8.0/const_state_variables.sol
  17. 406
      tests/detectors/constable-states/0.8.0/const_state_variables.sol.0.8.0.CouldBeConstant.json
  18. 57
      tests/detectors/immutable-states/0.4.25/immut_state_variables.sol
  19. 3
      tests/detectors/immutable-states/0.4.25/immut_state_variables.sol.0.4.25.CouldBeImmutable.json
  20. 58
      tests/detectors/immutable-states/0.5.16/immut_state_variables.sol
  21. 3
      tests/detectors/immutable-states/0.5.16/immut_state_variables.sol.0.5.16.CouldBeImmutable.json
  22. 79
      tests/detectors/immutable-states/0.6.11/immut_state_variables.sol
  23. 3
      tests/detectors/immutable-states/0.6.11/immut_state_variables.sol.0.6.11.CouldBeImmutable.json
  24. 78
      tests/detectors/immutable-states/0.7.6/immut_state_variables.sol
  25. 334
      tests/detectors/immutable-states/0.7.6/immut_state_variables.sol.0.7.6.CouldBeImmutable.json
  26. 78
      tests/detectors/immutable-states/0.8.0/immut_state_variables.sol
  27. 268
      tests/detectors/immutable-states/0.8.0/immut_state_variables.sol.0.8.0.CouldBeImmutable.json
  28. 35
      tests/test_detectors.py

@ -19,7 +19,8 @@ from .reentrancy.reentrancy_eth import ReentrancyEth
from .reentrancy.reentrancy_no_gas import ReentrancyNoGas
from .reentrancy.reentrancy_events import ReentrancyEvent
from .variables.unused_state_variables import UnusedStateVars
from .variables.possible_const_state_variables import ConstCandidateStateVars
from .variables.could_be_constant import CouldBeConstant
from .variables.could_be_immutable import CouldBeImmutable
from .statements.tx_origin import TxOrigin
from .statements.assembly import Assembly
from .operations.low_level_calls import LowLevelCalls

@ -0,0 +1,45 @@
from typing import List, Dict
from slither.utils.output import Output
from slither.core.compilation_unit import SlitherCompilationUnit
from slither.formatters.variables.unchanged_state_variables import custom_format
from slither.detectors.abstract_detector import AbstractDetector, DetectorClassification
from .unchanged_state_variables import UnchangedStateVariables
class CouldBeConstant(AbstractDetector):
"""
State variables that could be declared as constant.
Not all types for constants are implemented in Solidity as of 0.4.25.
The only supported types are value types and strings (ElementaryType).
Reference: https://solidity.readthedocs.io/en/latest/contracts.html#constant-state-variables
"""
ARGUMENT = "constable-states"
HELP = "State variables that could be declared constant"
IMPACT = DetectorClassification.OPTIMIZATION
CONFIDENCE = DetectorClassification.HIGH
WIKI = "https://github.com/crytic/slither/wiki/Detector-Documentation#state-variables-that-could-be-declared-constant"
WIKI_TITLE = "State variables that could be declared constant"
WIKI_DESCRIPTION = "State variables that are not updated following deployment should be declared constant to save gas."
WIKI_RECOMMENDATION = "Add the `constant` attribute to state variables that never change."
def _detect(self) -> List[Output]:
"""Detect state variables that could be constant"""
results = {}
unchanged_state_variables = UnchangedStateVariables(self.compilation_unit)
unchanged_state_variables.detect()
for variable in unchanged_state_variables.constant_candidates:
results[variable.canonical_name] = self.generate_result(
[variable, " should be constant \n"]
)
# Order by canonical name for deterministic results
return [results[k] for k in sorted(results)]
@staticmethod
def _format(compilation_unit: SlitherCompilationUnit, result: Dict) -> None:
custom_format(compilation_unit, result, "constant")

@ -0,0 +1,44 @@
from typing import List, Dict
from slither.utils.output import Output
from slither.core.compilation_unit import SlitherCompilationUnit
from slither.formatters.variables.unchanged_state_variables import custom_format
from slither.detectors.abstract_detector import AbstractDetector, DetectorClassification
from .unchanged_state_variables import UnchangedStateVariables
class CouldBeImmutable(AbstractDetector):
"""
State variables that could be declared immutable.
# Immutable attribute available in Solidity 0.6.5 and above
# https://blog.soliditylang.org/2020/04/06/solidity-0.6.5-release-announcement/
"""
# VULNERABLE_SOLC_VERSIONS =
ARGUMENT = "immutable-states"
HELP = "State variables that could be declared immutable"
IMPACT = DetectorClassification.OPTIMIZATION
CONFIDENCE = DetectorClassification.HIGH
WIKI = "https://github.com/crytic/slither/wiki/Detector-Documentation#state-variables-that-could-be-declared-immutable"
WIKI_TITLE = "State variables that could be declared immutable"
WIKI_DESCRIPTION = "State variables that are not updated following deployment should be declared immutable to save gas."
WIKI_RECOMMENDATION = "Add the `immutable` attribute to state variables that never change or are set only in the constructor."
def _detect(self) -> List[Output]:
"""Detect state variables that could be immutable"""
results = {}
unchanged_state_variables = UnchangedStateVariables(self.compilation_unit)
unchanged_state_variables.detect()
for variable in unchanged_state_variables.immutable_candidates:
results[variable.canonical_name] = self.generate_result(
[variable, " should be immutable \n"]
)
# Order by canonical name for deterministic results
return [results[k] for k in sorted(results)]
@staticmethod
def _format(compilation_unit: SlitherCompilationUnit, result: Dict) -> None:
custom_format(compilation_unit, result, "immutable")

@ -1,141 +0,0 @@
"""
Module detecting state variables that could be declared as constant
"""
from typing import Set, List, Dict
from slither.core.compilation_unit import SlitherCompilationUnit
from slither.core.solidity_types.elementary_type import ElementaryType
from slither.core.solidity_types.user_defined_type import UserDefinedType
from slither.core.variables.variable import Variable
from slither.detectors.abstract_detector import AbstractDetector, DetectorClassification
from slither.utils.output import Output
from slither.visitors.expression.export_values import ExportValues
from slither.core.declarations import Contract, Function
from slither.core.declarations.solidity_variables import SolidityFunction
from slither.core.variables.state_variable import StateVariable
from slither.formatters.variables.possible_const_state_variables import custom_format
from slither.core.expressions import CallExpression, NewContract
from slither.utils.standard_libraries import is_openzeppelin
def _is_valid_type(v: StateVariable) -> bool:
t = v.type
if isinstance(t, ElementaryType):
return True
if isinstance(t, UserDefinedType) and isinstance(t.type, Contract):
return True
return False
def _valid_candidate(v: StateVariable) -> bool:
return _is_valid_type(v) and not (v.is_constant or v.is_immutable)
def _is_constant_var(v: Variable) -> bool:
if isinstance(v, StateVariable):
return v.is_constant
return False
class ConstCandidateStateVars(AbstractDetector):
"""
State variables that could be declared as constant detector.
Not all types for constants are implemented in Solidity as of 0.4.25.
The only supported types are value types and strings (ElementaryType).
Reference: https://solidity.readthedocs.io/en/latest/contracts.html#constant-state-variables
"""
ARGUMENT = "constable-states"
HELP = "State variables that could be declared constant or immutable"
IMPACT = DetectorClassification.OPTIMIZATION
CONFIDENCE = DetectorClassification.HIGH
WIKI = "https://github.com/crytic/slither/wiki/Detector-Documentation#state-variables-that-could-be-declared-constant-or-immutable"
WIKI_TITLE = "State variables that could be declared constant or immutable"
WIKI_DESCRIPTION = "State variables that are not updated following deployment should be declared constant or immutable to save gas."
WIKI_RECOMMENDATION = (
"Add the `constant` or `immutable` attribute to state variables that never change."
)
# https://solidity.readthedocs.io/en/v0.5.2/contracts.html#constant-state-variables
valid_solidity_function = [
SolidityFunction("keccak256()"),
SolidityFunction("keccak256(bytes)"),
SolidityFunction("sha256()"),
SolidityFunction("sha256(bytes)"),
SolidityFunction("ripemd160()"),
SolidityFunction("ripemd160(bytes)"),
SolidityFunction("ecrecover(bytes32,uint8,bytes32,bytes32)"),
SolidityFunction("addmod(uint256,uint256,uint256)"),
SolidityFunction("mulmod(uint256,uint256,uint256)"),
]
def _constant_initial_expression(self, v: Variable) -> bool:
if not v.expression:
return True
# B b = new B(); b cannot be constant, so filter out and recommend it be immutable
if isinstance(v.expression, CallExpression) and isinstance(
v.expression.called, NewContract
):
return False
export = ExportValues(v.expression)
values = export.result()
if not values:
return True
return all((val in self.valid_solidity_function or _is_constant_var(val) for val in values))
def _detect(self) -> List[Output]:
"""Detect state variables that could be constant or immutable"""
results = {}
variables = []
functions = []
for c in self.compilation_unit.contracts:
if is_openzeppelin(c):
continue
variables.append(c.state_variables)
functions.append(c.all_functions_called)
valid_candidates: Set[StateVariable] = {
item for sublist in variables for item in sublist if _valid_candidate(item)
}
all_functions: List[Function] = list(
{item1 for sublist in functions for item1 in sublist if isinstance(item1, Function)}
)
variables_written = []
constructor_variables_written = []
for f in all_functions:
if f.is_constructor_variables:
constructor_variables_written.append(f.state_variables_written)
else:
variables_written.append(f.state_variables_written)
variables_written = {item for sublist in variables_written for item in sublist}
constructor_variables_written = {
item for sublist in constructor_variables_written for item in sublist
}
for v in valid_candidates:
if v not in variables_written:
if self._constant_initial_expression(v):
results[v.canonical_name] = self.generate_result([v, " should be constant \n"])
# immutable attribute available in Solidity 0.6.5 and above
# https://blog.soliditylang.org/2020/04/06/solidity-0.6.5-release-announcement/
elif (
v in constructor_variables_written
and self.compilation_unit.solc_version > "0.6.4"
):
results[v.canonical_name] = self.generate_result([v, " should be immutable \n"])
# Order by canonical name for deterministic results
return [results[k] for k in sorted(results)]
@staticmethod
def _format(compilation_unit: SlitherCompilationUnit, result: Dict) -> None:
custom_format(compilation_unit, result)

@ -0,0 +1,123 @@
"""
Module detecting state variables that could be declared as constant
"""
from typing import Set, List
from slither.core.compilation_unit import SlitherCompilationUnit
from slither.core.solidity_types.elementary_type import ElementaryType
from slither.core.solidity_types.user_defined_type import UserDefinedType
from slither.core.variables.variable import Variable
from slither.visitors.expression.export_values import ExportValues
from slither.core.declarations import Contract, Function
from slither.core.declarations.solidity_variables import SolidityFunction
from slither.core.variables.state_variable import StateVariable
from slither.core.expressions import CallExpression, NewContract
def _is_valid_type(v: StateVariable) -> bool:
t = v.type
if isinstance(t, ElementaryType):
return True
if isinstance(t, UserDefinedType) and isinstance(t.type, Contract):
return True
return False
def _valid_candidate(v: StateVariable) -> bool:
return _is_valid_type(v) and not (v.is_constant or v.is_immutable)
def _is_constant_var(v: Variable) -> bool:
if isinstance(v, StateVariable):
return v.is_constant
return False
# https://solidity.readthedocs.io/en/v0.5.2/contracts.html#constant-state-variables
valid_solidity_function = [
SolidityFunction("keccak256()"),
SolidityFunction("keccak256(bytes)"),
SolidityFunction("sha256()"),
SolidityFunction("sha256(bytes)"),
SolidityFunction("ripemd160()"),
SolidityFunction("ripemd160(bytes)"),
SolidityFunction("ecrecover(bytes32,uint8,bytes32,bytes32)"),
SolidityFunction("addmod(uint256,uint256,uint256)"),
SolidityFunction("mulmod(uint256,uint256,uint256)"),
]
def _constant_initial_expression(v: Variable) -> bool:
if not v.expression:
return True
# B b = new B(); b cannot be constant, so filter out and recommend it be immutable
if isinstance(v.expression, CallExpression) and isinstance(v.expression.called, NewContract):
return False
export = ExportValues(v.expression)
values = export.result()
if not values:
return True
return all((val in valid_solidity_function or _is_constant_var(val) for val in values))
class UnchangedStateVariables:
"""
Find state variables that could be declared as constant or immutable (not written after deployment).
"""
def __init__(self, compilation_unit: SlitherCompilationUnit):
self.compilation_unit = compilation_unit
self._constant_candidates: List[StateVariable] = []
self._immutable_candidates: List[StateVariable] = []
@property
def immutable_candidates(self) -> List[StateVariable]:
"""Return the immutable candidates"""
return self._immutable_candidates
@property
def constant_candidates(self) -> List[StateVariable]:
"""Return the constant candidates"""
return self._constant_candidates
def detect(self):
"""Detect state variables that could be constant or immutable"""
for c in self.compilation_unit.contracts_derived:
variables = []
functions = []
variables.append(c.state_variables)
functions.append(c.all_functions_called)
valid_candidates: Set[StateVariable] = {
item for sublist in variables for item in sublist if _valid_candidate(item)
}
all_functions: List[Function] = list(
{item1 for sublist in functions for item1 in sublist if isinstance(item1, Function)}
)
variables_written = []
constructor_variables_written = []
variables_initialized = []
for f in all_functions:
if f.is_constructor_variables:
variables_initialized.extend(f.state_variables_written)
elif f.is_constructor:
constructor_variables_written.extend(f.state_variables_written)
else:
variables_written.extend(f.state_variables_written)
for v in valid_candidates:
if v not in variables_written:
if _constant_initial_expression(v) and v not in constructor_variables_written:
self.constant_candidates.append(v)
elif (
v in constructor_variables_written or v in variables_initialized
) and self.compilation_unit.solc_version >= "0.6.5":
self.immutable_candidates.append(v)

@ -5,7 +5,7 @@ from slither.formatters.exceptions import FormatError, FormatImpossible
from slither.formatters.utils.patches import create_patch
def custom_format(compilation_unit: SlitherCompilationUnit, result):
def custom_format(compilation_unit: SlitherCompilationUnit, result, attribute: str) -> None:
elements = result["elements"]
for element in elements:
@ -15,14 +15,14 @@ def custom_format(compilation_unit: SlitherCompilationUnit, result):
contract = scope.get_contract_from_name(contract_name)
var = contract.get_state_variable_from_name(element["name"])
if not var.expression:
raise FormatImpossible(f"{var.name} is uninitialized and cannot become constant.")
raise FormatImpossible(f"{var.name} is uninitialized and cannot become {attribute}.")
_patch(
compilation_unit,
result,
element["source_mapping"]["filename_absolute"],
element["name"],
"constant " + element["name"],
f"{attribute} " + element["name"],
element["source_mapping"]["start"],
element["source_mapping"]["start"] + element["source_mapping"]["length"],
)

@ -9,7 +9,8 @@ from slither.detectors.attributes.incorrect_solc import IncorrectSolc
from slither.detectors.attributes.constant_pragma import ConstantPragma
from slither.detectors.naming_convention.naming_convention import NamingConvention
from slither.detectors.functions.external_function import ExternalFunction
from slither.detectors.variables.possible_const_state_variables import ConstCandidateStateVars
from slither.detectors.variables.could_be_constant import CouldBeConstant
from slither.detectors.variables.could_be_immutable import CouldBeImmutable
from slither.detectors.attributes.const_functions_asm import ConstantFunctionsAsm
from slither.detectors.attributes.const_functions_state import ConstantFunctionsState
from slither.utils.colors import yellow
@ -23,7 +24,8 @@ all_detectors: Dict[str, Type[AbstractDetector]] = {
"pragma": ConstantPragma,
"naming-convention": NamingConvention,
"external-function": ExternalFunction,
"constable-states": ConstCandidateStateVars,
"constable-states": CouldBeConstant,
"immutable-states": CouldBeImmutable,
"constant-function-asm": ConstantFunctionsAsm,
"constant-functions-state": ConstantFunctionsState,
}

@ -44,6 +44,11 @@ contract MyConc{
address not_constant = msg.sender;
uint not_constant_2 = getNumber();
uint not_constant_3 = 10 + block.number;
uint not_constant_5;
constructor(uint b) public {
not_constant_5 = b;
}
function getNumber() public returns(uint){
return block.number;

@ -212,7 +212,7 @@
"name": "MyConc",
"source_mapping": {
"start": 746,
"length": 342,
"length": 416,
"filename_relative": "tests/detectors/constable-states/0.4.25/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.4.25/const_state_variables.sol",
@ -231,7 +231,12 @@
49,
50,
51,
52
52,
53,
54,
55,
56,
57
],
"starting_column": 1,
"ending_column": 2
@ -272,7 +277,7 @@
"name": "MyConc",
"source_mapping": {
"start": 746,
"length": 342,
"length": 416,
"filename_relative": "tests/detectors/constable-states/0.4.25/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.4.25/const_state_variables.sol",
@ -291,7 +296,12 @@
49,
50,
51,
52
52,
53,
54,
55,
56,
57
],
"starting_column": 1,
"ending_column": 2

@ -45,6 +45,11 @@ contract MyConc{
address not_constant = msg.sender;
uint not_constant_2 = getNumber();
uint not_constant_3 = 10 + block.number;
uint not_constant_5;
constructor(uint b) public {
not_constant_5 = b;
}
function getNumber() public returns(uint){
return block.number;

@ -24,7 +24,7 @@
"name": "MyConc",
"source_mapping": {
"start": 746,
"length": 386,
"length": 467,
"filename_relative": "tests/detectors/constable-states/0.5.16/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.5.16/const_state_variables.sol",
@ -44,7 +44,12 @@
50,
51,
52,
53
53,
54,
55,
56,
57,
58
],
"starting_column": 1,
"ending_column": 2
@ -273,7 +278,7 @@
"name": "MyConc",
"source_mapping": {
"start": 746,
"length": 386,
"length": 467,
"filename_relative": "tests/detectors/constable-states/0.5.16/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.5.16/const_state_variables.sol",
@ -293,7 +298,12 @@
50,
51,
52,
53
53,
54,
55,
56,
57,
58
],
"starting_column": 1,
"ending_column": 2
@ -334,7 +344,7 @@
"name": "MyConc",
"source_mapping": {
"start": 746,
"length": 386,
"length": 467,
"filename_relative": "tests/detectors/constable-states/0.5.16/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.5.16/const_state_variables.sol",
@ -354,7 +364,12 @@
50,
51,
52,
53
53,
54,
55,
56,
57,
58
],
"starting_column": 1,
"ending_column": 2

@ -34,16 +34,43 @@ contract B is A {
}
}
contract MyConc {
contract Bad {
uint constant A = 1;
bytes32 should_be_constant = sha256('abc');
uint should_be_constant_2 = A + 1;
B should_be_constant_3 = B(address(0));
address not_constant = msg.sender;
uint not_constant_2 = getNumber();
uint not_constant_3 = 10 + block.number;
B not_constant_4 = new B();
address should_be_immutable = msg.sender;
uint should_be_immutable_2 = getNumber();
uint should_be_immutable_3 = 10 + block.number;
B should_be_immutable_4 = new B();
uint should_be_immutable_5;
constructor(uint b) public {
should_be_immutable_5 = b;
}
function getNumber() public returns(uint){
return block.number;
}
}
contract Good {
uint constant A = 1;
bytes32 constant should_be_constant = sha256('abc');
uint constant should_be_constant_2 = A + 1;
B constant should_be_constant_3 = B(address(0));
address immutable should_be_immutable = msg.sender;
uint immutable should_be_immutable_2 = getNumber();
uint immutable should_be_immutable_3 = 10 + block.number;
B immutable should_be_immutable_4 = new B();
uint immutable should_be_immutable_5;
constructor(uint b) public {
should_be_immutable_5 = b;
}
function getNumber() public returns(uint){
return block.number;

@ -4,48 +4,50 @@
"elements": [
{
"type": "variable",
"name": "should_be_constant_3",
"name": "text2",
"source_mapping": {
"start": 853,
"length": 38,
"start": 305,
"length": 20,
"filename_relative": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"is_dependency": false,
"lines": [
42
12
],
"starting_column": 5,
"ending_column": 43
"ending_column": 25
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "MyConc",
"name": "A",
"source_mapping": {
"start": 718,
"length": 415,
"start": 1,
"length": 441,
"filename_relative": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"is_dependency": false,
"lines": [
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19
],
"starting_column": 1,
"ending_column": 2
@ -54,10 +56,10 @@
}
}
],
"description": "MyConc.should_be_constant_3 (tests/detectors/constable-states/0.6.11/const_state_variables.sol#42) should be constant \n",
"markdown": "[MyConc.should_be_constant_3](tests/detectors/constable-states/0.6.11/const_state_variables.sol#L42) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.6.11/const_state_variables.sol#L42",
"id": "29247b0a9939e854ad51bf3b2f58705156aa8b7e446e646b1832467d362b5b3e",
"description": "A.text2 (tests/detectors/constable-states/0.6.11/const_state_variables.sol#12) should be constant \n",
"markdown": "[A.text2](tests/detectors/constable-states/0.6.11/const_state_variables.sol#L12) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.6.11/const_state_variables.sol#L12",
"id": "2f06e04545cea7e7a8998c65d5419f335bf2579a6ce6a832eac9c87392fd5c1a",
"check": "constable-states",
"impact": "Optimization",
"confidence": "High"
@ -66,50 +68,53 @@
"elements": [
{
"type": "variable",
"name": "text2",
"name": "should_be_constant_2",
"source_mapping": {
"start": 305,
"length": 20,
"start": 811,
"length": 33,
"filename_relative": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"is_dependency": false,
"lines": [
12
41
],
"starting_column": 5,
"ending_column": 25
"ending_column": 38
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "A",
"name": "Bad",
"source_mapping": {
"start": 1,
"length": 441,
"start": 718,
"length": 539,
"filename_relative": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"is_dependency": false,
"lines": [
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56,
57
],
"starting_column": 1,
"ending_column": 2
@ -118,10 +123,10 @@
}
}
],
"description": "A.text2 (tests/detectors/constable-states/0.6.11/const_state_variables.sol#12) should be constant \n",
"markdown": "[A.text2](tests/detectors/constable-states/0.6.11/const_state_variables.sol#L12) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.6.11/const_state_variables.sol#L12",
"id": "2f06e04545cea7e7a8998c65d5419f335bf2579a6ce6a832eac9c87392fd5c1a",
"description": "Bad.should_be_constant_2 (tests/detectors/constable-states/0.6.11/const_state_variables.sol#41) should be constant \n",
"markdown": "[Bad.should_be_constant_2](tests/detectors/constable-states/0.6.11/const_state_variables.sol#L41) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.6.11/const_state_variables.sol#L41",
"id": "3a8b682f7960750cd8228d6cd3d0bb5d7d6f9faaf1a044de2fa7069d8e475af2",
"check": "constable-states",
"impact": "Optimization",
"confidence": "High"
@ -256,7 +261,7 @@
"type": "variable",
"name": "should_be_constant",
"source_mapping": {
"start": 766,
"start": 763,
"length": 42,
"filename_relative": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
@ -271,10 +276,10 @@
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "MyConc",
"name": "Bad",
"source_mapping": {
"start": 718,
"length": 415,
"length": 539,
"filename_relative": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
@ -295,7 +300,12 @@
49,
50,
51,
52
52,
53,
54,
55,
56,
57
],
"starting_column": 1,
"ending_column": 2
@ -304,10 +314,10 @@
}
}
],
"description": "MyConc.should_be_constant (tests/detectors/constable-states/0.6.11/const_state_variables.sol#40) should be constant \n",
"markdown": "[MyConc.should_be_constant](tests/detectors/constable-states/0.6.11/const_state_variables.sol#L40) should be constant \n",
"description": "Bad.should_be_constant (tests/detectors/constable-states/0.6.11/const_state_variables.sol#40) should be constant \n",
"markdown": "[Bad.should_be_constant](tests/detectors/constable-states/0.6.11/const_state_variables.sol#L40) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.6.11/const_state_variables.sol#L40",
"id": "8d08797efc8230b480ec669c7e2bf53c3b3d16bc59bf7770934b34fd892934f8",
"id": "87097c03d57b72ad7c15336eb44e5a30054c50f8daff32e08bc4fbd97852961c",
"check": "constable-states",
"impact": "Optimization",
"confidence": "High"
@ -316,27 +326,27 @@
"elements": [
{
"type": "variable",
"name": "should_be_constant_2",
"name": "should_be_constant_3",
"source_mapping": {
"start": 814,
"length": 33,
"start": 850,
"length": 38,
"filename_relative": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"is_dependency": false,
"lines": [
41
42
],
"starting_column": 5,
"ending_column": 38
"ending_column": 43
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "MyConc",
"name": "Bad",
"source_mapping": {
"start": 718,
"length": 415,
"length": 539,
"filename_relative": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
@ -357,7 +367,12 @@
49,
50,
51,
52
52,
53,
54,
55,
56,
57
],
"starting_column": 1,
"ending_column": 2
@ -366,10 +381,10 @@
}
}
],
"description": "MyConc.should_be_constant_2 (tests/detectors/constable-states/0.6.11/const_state_variables.sol#41) should be constant \n",
"markdown": "[MyConc.should_be_constant_2](tests/detectors/constable-states/0.6.11/const_state_variables.sol#L41) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.6.11/const_state_variables.sol#L41",
"id": "d08c6d1e331083b42c45c222691dd1e6d880814c66d114971875337ca61ba9c9",
"description": "Bad.should_be_constant_3 (tests/detectors/constable-states/0.6.11/const_state_variables.sol#42) should be constant \n",
"markdown": "[Bad.should_be_constant_3](tests/detectors/constable-states/0.6.11/const_state_variables.sol#L42) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.6.11/const_state_variables.sol#L42",
"id": "8e991c1370b1adb10f01f2d7e48f341dee92a98b91b56ccb291d9149d2da97d0",
"check": "constable-states",
"impact": "Optimization",
"confidence": "High"

@ -34,7 +34,7 @@ contract B is A {
}
}
contract MyConc {
contract Bad {
uint constant A = 1;
bytes32 should_be_constant = sha256('abc');
@ -44,6 +44,32 @@ contract MyConc {
uint should_be_immutable_2 = getNumber();
uint should_be_immutable_3 = 10 + block.number;
B should_be_immutable_4 = new B();
uint should_be_immutable_5;
constructor(uint b) {
should_be_immutable_5 = b;
}
function getNumber() public returns(uint){
return block.number;
}
}
contract Good {
uint constant A = 1;
bytes32 constant should_be_constant = sha256('abc');
uint constant should_be_constant_2 = A + 1;
B constant should_be_constant_3 = B(address(0));
address immutable should_be_immutable = msg.sender;
uint immutable should_be_immutable_2 = getNumber();
uint immutable should_be_immutable_3 = 10 + block.number;
B immutable should_be_immutable_4 = new B();
uint immutable should_be_immutable_5;
constructor(uint b) {
should_be_immutable_5 = b;
}
function getNumber() public returns(uint){
return block.number;

@ -1,67 +1,5 @@
[
[
{
"elements": [
{
"type": "variable",
"name": "should_be_constant_3",
"source_mapping": {
"start": 853,
"length": 38,
"filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"is_dependency": false,
"lines": [
42
],
"starting_column": 5,
"ending_column": 43
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "MyConc",
"source_mapping": {
"start": 718,
"length": 443,
"filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"is_dependency": false,
"lines": [
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52
],
"starting_column": 1,
"ending_column": 2
}
}
}
}
],
"description": "MyConc.should_be_constant_3 (tests/detectors/constable-states/0.7.6/const_state_variables.sol#42) should be constant \n",
"markdown": "[MyConc.should_be_constant_3](tests/detectors/constable-states/0.7.6/const_state_variables.sol#L42) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.7.6/const_state_variables.sol#L42",
"id": "29247b0a9939e854ad51bf3b2f58705156aa8b7e446e646b1832467d362b5b3e",
"check": "constable-states",
"impact": "Optimization",
"confidence": "High"
},
{
"elements": [
{
@ -130,46 +68,52 @@
"elements": [
{
"type": "variable",
"name": "mySistersAddress",
"name": "should_be_constant_2",
"source_mapping": {
"start": 468,
"length": 76,
"start": 811,
"length": 33,
"filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"is_dependency": false,
"lines": [
24
41
],
"starting_column": 5,
"ending_column": 81
"ending_column": 38
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "B",
"name": "Bad",
"source_mapping": {
"start": 445,
"length": 271,
"start": 718,
"length": 531,
"filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"is_dependency": false,
"lines": [
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56
],
"starting_column": 1,
"ending_column": 2
@ -178,10 +122,10 @@
}
}
],
"description": "B.mySistersAddress (tests/detectors/constable-states/0.7.6/const_state_variables.sol#24) should be constant \n",
"markdown": "[B.mySistersAddress](tests/detectors/constable-states/0.7.6/const_state_variables.sol#L24) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.7.6/const_state_variables.sol#L24",
"id": "3b5bff93954a48a79387e7981e8c45d78edc575a0988a10f1c7f439b9f930539",
"description": "Bad.should_be_constant_2 (tests/detectors/constable-states/0.7.6/const_state_variables.sol#41) should be constant \n",
"markdown": "[Bad.should_be_constant_2](tests/detectors/constable-states/0.7.6/const_state_variables.sol#L41) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.7.6/const_state_variables.sol#L41",
"id": "3a8b682f7960750cd8228d6cd3d0bb5d7d6f9faaf1a044de2fa7069d8e475af2",
"check": "constable-states",
"impact": "Optimization",
"confidence": "High"
@ -190,48 +134,46 @@
"elements": [
{
"type": "variable",
"name": "should_be_immutable",
"name": "mySistersAddress",
"source_mapping": {
"start": 897,
"length": 40,
"start": 468,
"length": 76,
"filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"is_dependency": false,
"lines": [
43
24
],
"starting_column": 5,
"ending_column": 45
"ending_column": 81
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "MyConc",
"name": "B",
"source_mapping": {
"start": 718,
"length": 443,
"start": 445,
"length": 271,
"filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"is_dependency": false,
"lines": [
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35
],
"starting_column": 1,
"ending_column": 2
@ -240,10 +182,10 @@
}
}
],
"description": "MyConc.should_be_immutable (tests/detectors/constable-states/0.7.6/const_state_variables.sol#43) should be immutable \n",
"markdown": "[MyConc.should_be_immutable](tests/detectors/constable-states/0.7.6/const_state_variables.sol#L43) should be immutable \n",
"first_markdown_element": "tests/detectors/constable-states/0.7.6/const_state_variables.sol#L43",
"id": "3cabd54a4d3fa32f960965a41bb09b62052286195b47b2b7db670f87e8df21bf",
"description": "B.mySistersAddress (tests/detectors/constable-states/0.7.6/const_state_variables.sol#24) should be constant \n",
"markdown": "[B.mySistersAddress](tests/detectors/constable-states/0.7.6/const_state_variables.sol#L24) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.7.6/const_state_variables.sol#L24",
"id": "3b5bff93954a48a79387e7981e8c45d78edc575a0988a10f1c7f439b9f930539",
"check": "constable-states",
"impact": "Optimization",
"confidence": "High"
@ -318,7 +260,7 @@
"type": "variable",
"name": "should_be_constant",
"source_mapping": {
"start": 766,
"start": 763,
"length": 42,
"filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
@ -333,10 +275,10 @@
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "MyConc",
"name": "Bad",
"source_mapping": {
"start": 718,
"length": 443,
"length": 531,
"filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
@ -357,7 +299,11 @@
49,
50,
51,
52
52,
53,
54,
55,
56
],
"starting_column": 1,
"ending_column": 2
@ -366,72 +312,10 @@
}
}
],
"description": "MyConc.should_be_constant (tests/detectors/constable-states/0.7.6/const_state_variables.sol#40) should be constant \n",
"markdown": "[MyConc.should_be_constant](tests/detectors/constable-states/0.7.6/const_state_variables.sol#L40) should be constant \n",
"description": "Bad.should_be_constant (tests/detectors/constable-states/0.7.6/const_state_variables.sol#40) should be constant \n",
"markdown": "[Bad.should_be_constant](tests/detectors/constable-states/0.7.6/const_state_variables.sol#L40) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.7.6/const_state_variables.sol#L40",
"id": "8d08797efc8230b480ec669c7e2bf53c3b3d16bc59bf7770934b34fd892934f8",
"check": "constable-states",
"impact": "Optimization",
"confidence": "High"
},
{
"elements": [
{
"type": "variable",
"name": "should_be_immutable_4",
"source_mapping": {
"start": 1041,
"length": 33,
"filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"is_dependency": false,
"lines": [
46
],
"starting_column": 5,
"ending_column": 38
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "MyConc",
"source_mapping": {
"start": 718,
"length": 443,
"filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"is_dependency": false,
"lines": [
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52
],
"starting_column": 1,
"ending_column": 2
}
}
}
}
],
"description": "MyConc.should_be_immutable_4 (tests/detectors/constable-states/0.7.6/const_state_variables.sol#46) should be immutable \n",
"markdown": "[MyConc.should_be_immutable_4](tests/detectors/constable-states/0.7.6/const_state_variables.sol#L46) should be immutable \n",
"first_markdown_element": "tests/detectors/constable-states/0.7.6/const_state_variables.sol#L46",
"id": "a15e34bd516e604d7ba3e0746ad0234d0baea38da2e747648316d5d15ee9b3bc",
"id": "87097c03d57b72ad7c15336eb44e5a30054c50f8daff32e08bc4fbd97852961c",
"check": "constable-states",
"impact": "Optimization",
"confidence": "High"
@ -440,151 +324,27 @@
"elements": [
{
"type": "variable",
"name": "should_be_immutable_2",
"source_mapping": {
"start": 943,
"length": 40,
"filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"is_dependency": false,
"lines": [
44
],
"starting_column": 5,
"ending_column": 45
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "MyConc",
"source_mapping": {
"start": 718,
"length": 443,
"filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"is_dependency": false,
"lines": [
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52
],
"starting_column": 1,
"ending_column": 2
}
}
}
}
],
"description": "MyConc.should_be_immutable_2 (tests/detectors/constable-states/0.7.6/const_state_variables.sol#44) should be immutable \n",
"markdown": "[MyConc.should_be_immutable_2](tests/detectors/constable-states/0.7.6/const_state_variables.sol#L44) should be immutable \n",
"first_markdown_element": "tests/detectors/constable-states/0.7.6/const_state_variables.sol#L44",
"id": "cb6df1f1ce2f32505c81f257863ceef6d5145ee5a2835af1c6719ad695d145e2",
"check": "constable-states",
"impact": "Optimization",
"confidence": "High"
},
{
"elements": [
{
"type": "variable",
"name": "should_be_constant_2",
"source_mapping": {
"start": 814,
"length": 33,
"filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"is_dependency": false,
"lines": [
41
],
"starting_column": 5,
"ending_column": 38
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "MyConc",
"source_mapping": {
"start": 718,
"length": 443,
"filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"is_dependency": false,
"lines": [
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52
],
"starting_column": 1,
"ending_column": 2
}
}
}
}
],
"description": "MyConc.should_be_constant_2 (tests/detectors/constable-states/0.7.6/const_state_variables.sol#41) should be constant \n",
"markdown": "[MyConc.should_be_constant_2](tests/detectors/constable-states/0.7.6/const_state_variables.sol#L41) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.7.6/const_state_variables.sol#L41",
"id": "d08c6d1e331083b42c45c222691dd1e6d880814c66d114971875337ca61ba9c9",
"check": "constable-states",
"impact": "Optimization",
"confidence": "High"
},
{
"elements": [
{
"type": "variable",
"name": "should_be_immutable_3",
"name": "should_be_constant_3",
"source_mapping": {
"start": 989,
"length": 46,
"start": 850,
"length": 38,
"filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"is_dependency": false,
"lines": [
45
42
],
"starting_column": 5,
"ending_column": 51
"ending_column": 43
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "MyConc",
"name": "Bad",
"source_mapping": {
"start": 718,
"length": 443,
"length": 531,
"filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
@ -605,7 +365,11 @@
49,
50,
51,
52
52,
53,
54,
55,
56
],
"starting_column": 1,
"ending_column": 2
@ -614,10 +378,10 @@
}
}
],
"description": "MyConc.should_be_immutable_3 (tests/detectors/constable-states/0.7.6/const_state_variables.sol#45) should be immutable \n",
"markdown": "[MyConc.should_be_immutable_3](tests/detectors/constable-states/0.7.6/const_state_variables.sol#L45) should be immutable \n",
"first_markdown_element": "tests/detectors/constable-states/0.7.6/const_state_variables.sol#L45",
"id": "dc5903ef8f6ec62f53df486fa768a0d817643efe30c90c1308079eee99c316d4",
"description": "Bad.should_be_constant_3 (tests/detectors/constable-states/0.7.6/const_state_variables.sol#42) should be constant \n",
"markdown": "[Bad.should_be_constant_3](tests/detectors/constable-states/0.7.6/const_state_variables.sol#L42) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.7.6/const_state_variables.sol#L42",
"id": "8e991c1370b1adb10f01f2d7e48f341dee92a98b91b56ccb291d9149d2da97d0",
"check": "constable-states",
"impact": "Optimization",
"confidence": "High"

@ -34,7 +34,7 @@ contract B is A {
}
}
contract MyConc {
contract Bad {
uint constant A = 1;
bytes32 should_be_constant = sha256('abc');
@ -43,7 +43,33 @@ contract MyConc {
address should_be_immutable = msg.sender;
uint should_be_immutable_2 = getNumber();
uint should_be_immutable_3 = 10 + block.number;
B should_be_immutable_4 = new B();
uint should_be_immutable_5;
constructor(uint b) {
should_be_immutable_5 = b;
}
function getNumber() public returns(uint){
return block.number;
}
}
contract Good {
uint constant A = 1;
bytes32 constant should_be_constant = sha256('abc');
uint constant should_be_constant_2 = A + 1;
B constant should_be_constant_3 = B(address(0));
address immutable should_be_immutable = msg.sender;
uint immutable should_be_immutable_2 = getNumber();
uint immutable should_be_immutable_3 = 10 + block.number;
B immutable should_be_immutable_4 = new B();
uint immutable should_be_immutable_5;
constructor(uint b) {
should_be_immutable_5 = b;
}
function getNumber() public returns(uint){
return block.number;

@ -1,67 +1,5 @@
[
[
{
"elements": [
{
"type": "variable",
"name": "should_be_constant_3",
"source_mapping": {
"start": 853,
"length": 38,
"filename_relative": "tests/detectors/constable-states/0.8.0/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.8.0/const_state_variables.sol",
"is_dependency": false,
"lines": [
42
],
"starting_column": 5,
"ending_column": 43
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "MyConc",
"source_mapping": {
"start": 718,
"length": 443,
"filename_relative": "tests/detectors/constable-states/0.8.0/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.8.0/const_state_variables.sol",
"is_dependency": false,
"lines": [
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52
],
"starting_column": 1,
"ending_column": 2
}
}
}
}
],
"description": "MyConc.should_be_constant_3 (tests/detectors/constable-states/0.8.0/const_state_variables.sol#42) should be constant \n",
"markdown": "[MyConc.should_be_constant_3](tests/detectors/constable-states/0.8.0/const_state_variables.sol#L42) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.8.0/const_state_variables.sol#L42",
"id": "29247b0a9939e854ad51bf3b2f58705156aa8b7e446e646b1832467d362b5b3e",
"check": "constable-states",
"impact": "Optimization",
"confidence": "High"
},
{
"elements": [
{
@ -130,46 +68,52 @@
"elements": [
{
"type": "variable",
"name": "mySistersAddress",
"name": "should_be_constant_2",
"source_mapping": {
"start": 468,
"length": 76,
"start": 811,
"length": 33,
"filename_relative": "tests/detectors/constable-states/0.8.0/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.8.0/const_state_variables.sol",
"is_dependency": false,
"lines": [
24
41
],
"starting_column": 5,
"ending_column": 81
"ending_column": 38
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "B",
"name": "Bad",
"source_mapping": {
"start": 445,
"length": 271,
"start": 718,
"length": 493,
"filename_relative": "tests/detectors/constable-states/0.8.0/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.8.0/const_state_variables.sol",
"is_dependency": false,
"lines": [
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56
],
"starting_column": 1,
"ending_column": 2
@ -178,10 +122,10 @@
}
}
],
"description": "B.mySistersAddress (tests/detectors/constable-states/0.8.0/const_state_variables.sol#24) should be constant \n",
"markdown": "[B.mySistersAddress](tests/detectors/constable-states/0.8.0/const_state_variables.sol#L24) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.8.0/const_state_variables.sol#L24",
"id": "3b5bff93954a48a79387e7981e8c45d78edc575a0988a10f1c7f439b9f930539",
"description": "Bad.should_be_constant_2 (tests/detectors/constable-states/0.8.0/const_state_variables.sol#41) should be constant \n",
"markdown": "[Bad.should_be_constant_2](tests/detectors/constable-states/0.8.0/const_state_variables.sol#L41) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.8.0/const_state_variables.sol#L41",
"id": "3a8b682f7960750cd8228d6cd3d0bb5d7d6f9faaf1a044de2fa7069d8e475af2",
"check": "constable-states",
"impact": "Optimization",
"confidence": "High"
@ -190,48 +134,46 @@
"elements": [
{
"type": "variable",
"name": "should_be_immutable",
"name": "mySistersAddress",
"source_mapping": {
"start": 897,
"length": 40,
"start": 468,
"length": 76,
"filename_relative": "tests/detectors/constable-states/0.8.0/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.8.0/const_state_variables.sol",
"is_dependency": false,
"lines": [
43
24
],
"starting_column": 5,
"ending_column": 45
"ending_column": 81
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "MyConc",
"name": "B",
"source_mapping": {
"start": 718,
"length": 443,
"start": 445,
"length": 271,
"filename_relative": "tests/detectors/constable-states/0.8.0/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.8.0/const_state_variables.sol",
"is_dependency": false,
"lines": [
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35
],
"starting_column": 1,
"ending_column": 2
@ -240,10 +182,10 @@
}
}
],
"description": "MyConc.should_be_immutable (tests/detectors/constable-states/0.8.0/const_state_variables.sol#43) should be immutable \n",
"markdown": "[MyConc.should_be_immutable](tests/detectors/constable-states/0.8.0/const_state_variables.sol#L43) should be immutable \n",
"first_markdown_element": "tests/detectors/constable-states/0.8.0/const_state_variables.sol#L43",
"id": "3cabd54a4d3fa32f960965a41bb09b62052286195b47b2b7db670f87e8df21bf",
"description": "B.mySistersAddress (tests/detectors/constable-states/0.8.0/const_state_variables.sol#24) should be constant \n",
"markdown": "[B.mySistersAddress](tests/detectors/constable-states/0.8.0/const_state_variables.sol#L24) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.8.0/const_state_variables.sol#L24",
"id": "3b5bff93954a48a79387e7981e8c45d78edc575a0988a10f1c7f439b9f930539",
"check": "constable-states",
"impact": "Optimization",
"confidence": "High"
@ -318,7 +260,7 @@
"type": "variable",
"name": "should_be_constant",
"source_mapping": {
"start": 766,
"start": 763,
"length": 42,
"filename_relative": "tests/detectors/constable-states/0.8.0/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
@ -333,10 +275,10 @@
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "MyConc",
"name": "Bad",
"source_mapping": {
"start": 718,
"length": 443,
"length": 493,
"filename_relative": "tests/detectors/constable-states/0.8.0/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.8.0/const_state_variables.sol",
@ -357,7 +299,11 @@
49,
50,
51,
52
52,
53,
54,
55,
56
],
"starting_column": 1,
"ending_column": 2
@ -366,72 +312,10 @@
}
}
],
"description": "MyConc.should_be_constant (tests/detectors/constable-states/0.8.0/const_state_variables.sol#40) should be constant \n",
"markdown": "[MyConc.should_be_constant](tests/detectors/constable-states/0.8.0/const_state_variables.sol#L40) should be constant \n",
"description": "Bad.should_be_constant (tests/detectors/constable-states/0.8.0/const_state_variables.sol#40) should be constant \n",
"markdown": "[Bad.should_be_constant](tests/detectors/constable-states/0.8.0/const_state_variables.sol#L40) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.8.0/const_state_variables.sol#L40",
"id": "8d08797efc8230b480ec669c7e2bf53c3b3d16bc59bf7770934b34fd892934f8",
"check": "constable-states",
"impact": "Optimization",
"confidence": "High"
},
{
"elements": [
{
"type": "variable",
"name": "should_be_immutable_4",
"source_mapping": {
"start": 1041,
"length": 33,
"filename_relative": "tests/detectors/constable-states/0.8.0/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.8.0/const_state_variables.sol",
"is_dependency": false,
"lines": [
46
],
"starting_column": 5,
"ending_column": 38
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "MyConc",
"source_mapping": {
"start": 718,
"length": 443,
"filename_relative": "tests/detectors/constable-states/0.8.0/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.8.0/const_state_variables.sol",
"is_dependency": false,
"lines": [
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52
],
"starting_column": 1,
"ending_column": 2
}
}
}
}
],
"description": "MyConc.should_be_immutable_4 (tests/detectors/constable-states/0.8.0/const_state_variables.sol#46) should be immutable \n",
"markdown": "[MyConc.should_be_immutable_4](tests/detectors/constable-states/0.8.0/const_state_variables.sol#L46) should be immutable \n",
"first_markdown_element": "tests/detectors/constable-states/0.8.0/const_state_variables.sol#L46",
"id": "a15e34bd516e604d7ba3e0746ad0234d0baea38da2e747648316d5d15ee9b3bc",
"id": "87097c03d57b72ad7c15336eb44e5a30054c50f8daff32e08bc4fbd97852961c",
"check": "constable-states",
"impact": "Optimization",
"confidence": "High"
@ -440,151 +324,27 @@
"elements": [
{
"type": "variable",
"name": "should_be_immutable_2",
"source_mapping": {
"start": 943,
"length": 40,
"filename_relative": "tests/detectors/constable-states/0.8.0/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.8.0/const_state_variables.sol",
"is_dependency": false,
"lines": [
44
],
"starting_column": 5,
"ending_column": 45
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "MyConc",
"source_mapping": {
"start": 718,
"length": 443,
"filename_relative": "tests/detectors/constable-states/0.8.0/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.8.0/const_state_variables.sol",
"is_dependency": false,
"lines": [
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52
],
"starting_column": 1,
"ending_column": 2
}
}
}
}
],
"description": "MyConc.should_be_immutable_2 (tests/detectors/constable-states/0.8.0/const_state_variables.sol#44) should be immutable \n",
"markdown": "[MyConc.should_be_immutable_2](tests/detectors/constable-states/0.8.0/const_state_variables.sol#L44) should be immutable \n",
"first_markdown_element": "tests/detectors/constable-states/0.8.0/const_state_variables.sol#L44",
"id": "cb6df1f1ce2f32505c81f257863ceef6d5145ee5a2835af1c6719ad695d145e2",
"check": "constable-states",
"impact": "Optimization",
"confidence": "High"
},
{
"elements": [
{
"type": "variable",
"name": "should_be_constant_2",
"source_mapping": {
"start": 814,
"length": 33,
"filename_relative": "tests/detectors/constable-states/0.8.0/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.8.0/const_state_variables.sol",
"is_dependency": false,
"lines": [
41
],
"starting_column": 5,
"ending_column": 38
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "MyConc",
"source_mapping": {
"start": 718,
"length": 443,
"filename_relative": "tests/detectors/constable-states/0.8.0/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.8.0/const_state_variables.sol",
"is_dependency": false,
"lines": [
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52
],
"starting_column": 1,
"ending_column": 2
}
}
}
}
],
"description": "MyConc.should_be_constant_2 (tests/detectors/constable-states/0.8.0/const_state_variables.sol#41) should be constant \n",
"markdown": "[MyConc.should_be_constant_2](tests/detectors/constable-states/0.8.0/const_state_variables.sol#L41) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.8.0/const_state_variables.sol#L41",
"id": "d08c6d1e331083b42c45c222691dd1e6d880814c66d114971875337ca61ba9c9",
"check": "constable-states",
"impact": "Optimization",
"confidence": "High"
},
{
"elements": [
{
"type": "variable",
"name": "should_be_immutable_3",
"name": "should_be_constant_3",
"source_mapping": {
"start": 989,
"length": 46,
"start": 850,
"length": 38,
"filename_relative": "tests/detectors/constable-states/0.8.0/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.8.0/const_state_variables.sol",
"is_dependency": false,
"lines": [
45
42
],
"starting_column": 5,
"ending_column": 51
"ending_column": 43
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "MyConc",
"name": "Bad",
"source_mapping": {
"start": 718,
"length": 443,
"length": 493,
"filename_relative": "tests/detectors/constable-states/0.8.0/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.8.0/const_state_variables.sol",
@ -605,7 +365,11 @@
49,
50,
51,
52
52,
53,
54,
55,
56
],
"starting_column": 1,
"ending_column": 2
@ -614,10 +378,10 @@
}
}
],
"description": "MyConc.should_be_immutable_3 (tests/detectors/constable-states/0.8.0/const_state_variables.sol#45) should be immutable \n",
"markdown": "[MyConc.should_be_immutable_3](tests/detectors/constable-states/0.8.0/const_state_variables.sol#L45) should be immutable \n",
"first_markdown_element": "tests/detectors/constable-states/0.8.0/const_state_variables.sol#L45",
"id": "dc5903ef8f6ec62f53df486fa768a0d817643efe30c90c1308079eee99c316d4",
"description": "Bad.should_be_constant_3 (tests/detectors/constable-states/0.8.0/const_state_variables.sol#42) should be constant \n",
"markdown": "[Bad.should_be_constant_3](tests/detectors/constable-states/0.8.0/const_state_variables.sol#L42) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.8.0/const_state_variables.sol#L42",
"id": "8e991c1370b1adb10f01f2d7e48f341dee92a98b91b56ccb291d9149d2da97d0",
"check": "constable-states",
"impact": "Optimization",
"confidence": "High"

@ -0,0 +1,57 @@
//pragma solidity ^0.4.24;
contract A {
address constant public MY_ADDRESS = 0xE0f5206BBD039e7b0592d8918820024e2a7437b9;
address public myFriendsAddress = 0xc0ffee254729296a45a3885639AC7E10F9d54979;
uint public used;
uint public test = 5;
uint constant X = 32**22 + 8;
string constant TEXT1 = "abc";
string text2 = "xyz";
function setUsed() public {
if (msg.sender == MY_ADDRESS) {
used = test;
}
}
}
contract B is A {
address public mySistersAddress = 0x999999cf1046e68e36E1aA2E0E07105eDDD1f08E;
function () external {
used = 0;
}
function setUsed(uint a) public {
if (msg.sender == MY_ADDRESS) {
used = a;
}
}
}
contract MyConc{
uint constant A = 1;
bytes32 should_be_constant = sha256('abc');
uint should_be_constant_2 = A + 1;
address not_constant = msg.sender;
uint not_constant_2 = getNumber();
uint not_constant_3 = 10 + block.number;
uint not_constant_5;
constructor(uint b) public {
not_constant_5 = b;
}
function getNumber() public returns(uint){
return block.number;
}
}

@ -0,0 +1,58 @@
//pragma solidity ^0.4.24;
contract A {
address constant public MY_ADDRESS = 0xE0f5206BBD039e7b0592d8918820024e2a7437b9;
address public myFriendsAddress = 0xc0ffee254729296a45a3885639AC7E10F9d54979;
uint public used;
uint public test = 5;
uint constant X = 32**22 + 8;
string constant TEXT1 = "abc";
string text2 = "xyz";
function setUsed() public {
if (msg.sender == MY_ADDRESS) {
used = test;
}
}
}
contract B is A {
address public mySistersAddress = 0x999999cf1046e68e36E1aA2E0E07105eDDD1f08E;
function () external {
used = 0;
}
function setUsed(uint a) public {
if (msg.sender == MY_ADDRESS) {
used = a;
}
}
}
contract MyConc{
uint constant A = 1;
bytes32 should_be_constant = sha256('abc');
uint should_be_constant_2 = A + 1;
B should_be_constant_3 = B(address(0));
address not_constant = msg.sender;
uint not_constant_2 = getNumber();
uint not_constant_3 = 10 + block.number;
uint not_constant_5;
constructor(uint b) public {
not_constant_5 = b;
}
function getNumber() public returns(uint){
return block.number;
}
}

@ -0,0 +1,79 @@
contract A {
address constant public MY_ADDRESS = 0xE0f5206BBD039e7b0592d8918820024e2a7437b9;
address public myFriendsAddress = 0xc0ffee254729296a45a3885639AC7E10F9d54979;
uint public used;
uint public test = 5;
uint constant X = 32**22 + 8;
string constant TEXT1 = "abc";
string text2 = "xyz";
function setUsed() public {
if (msg.sender == MY_ADDRESS) {
used = test;
}
}
}
contract B is A {
address public mySistersAddress = 0x999999cf1046e68e36E1aA2E0E07105eDDD1f08E;
fallback () external {
used = 0;
}
function setUsed(uint a) public {
if (msg.sender == MY_ADDRESS) {
used = a;
}
}
}
contract Bad {
uint constant A = 1;
bytes32 should_be_constant = sha256('abc');
uint should_be_constant_2 = A + 1;
B should_be_constant_3 = B(address(0));
address should_be_immutable = msg.sender;
uint should_be_immutable_2 = getNumber();
uint should_be_immutable_3 = 10 + block.number;
B should_be_immutable_4 = new B();
uint should_be_immutable_5;
constructor(uint b) public {
should_be_immutable_5 = b;
}
function getNumber() public returns(uint){
return block.number;
}
}
contract Good {
uint constant A = 1;
bytes32 constant should_be_constant = sha256('abc');
uint constant should_be_constant_2 = A + 1;
B constant should_be_constant_3 = B(address(0));
address immutable should_be_immutable = msg.sender;
uint immutable should_be_immutable_2 = getNumber();
uint immutable should_be_immutable_3 = 10 + block.number;
B immutable should_be_immutable_4 = new B();
uint immutable should_be_immutable_5;
constructor(uint b) public {
should_be_immutable_5 = b;
}
function getNumber() public returns(uint){
return block.number;
}
}

@ -0,0 +1,78 @@
contract A {
address constant public MY_ADDRESS = 0xE0f5206BBD039e7b0592d8918820024e2a7437b9;
address public myFriendsAddress = 0xc0ffee254729296a45a3885639AC7E10F9d54979;
uint public used;
uint public test = 5;
uint constant X = 32**22 + 8;
string constant TEXT1 = "abc";
string text2 = "xyz";
function setUsed() public {
if (msg.sender == MY_ADDRESS) {
used = test;
}
}
}
contract B is A {
address public mySistersAddress = 0x999999cf1046e68e36E1aA2E0E07105eDDD1f08E;
fallback () external {
used = 0;
}
function setUsed(uint a) public {
if (msg.sender == MY_ADDRESS) {
used = a;
}
}
}
contract Bad {
uint constant A = 1;
bytes32 should_be_constant = sha256('abc');
uint should_be_constant_2 = A + 1;
B should_be_constant_3 = B(address(0));
address should_be_immutable = msg.sender;
uint should_be_immutable_2 = getNumber();
uint should_be_immutable_3 = 10 + block.number;
B should_be_immutable_4 = new B();
uint should_be_immutable_5;
constructor(uint b) {
should_be_immutable_5 = b;
}
function getNumber() public returns(uint){
return block.number;
}
}
contract Good {
uint constant A = 1;
bytes32 constant should_be_constant = sha256('abc');
uint constant should_be_constant_2 = A + 1;
B constant should_be_constant_3 = B(address(0));
address immutable should_be_immutable = msg.sender;
uint immutable should_be_immutable_2 = getNumber();
uint immutable should_be_immutable_3 = 10 + block.number;
B immutable should_be_immutable_4 = new B();
uint immutable should_be_immutable_5;
constructor(uint b) {
should_be_immutable_5 = b;
}
function getNumber() public returns(uint){
return block.number;
}
}

@ -0,0 +1,334 @@
[
[
{
"elements": [
{
"type": "variable",
"name": "should_be_immutable_5",
"source_mapping": {
"start": 1077,
"length": 26,
"filename_relative": "tests/detectors/immutable-states/0.7.6/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.7.6/immut_state_variables.sol",
"is_dependency": false,
"lines": [
47
],
"starting_column": 5,
"ending_column": 31
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "Bad",
"source_mapping": {
"start": 718,
"length": 531,
"filename_relative": "tests/detectors/immutable-states/0.7.6/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.7.6/immut_state_variables.sol",
"is_dependency": false,
"lines": [
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56
],
"starting_column": 1,
"ending_column": 2
}
}
}
}
],
"description": "Bad.should_be_immutable_5 (tests/detectors/immutable-states/0.7.6/immut_state_variables.sol#47) should be immutable \n",
"markdown": "[Bad.should_be_immutable_5](tests/detectors/immutable-states/0.7.6/immut_state_variables.sol#L47) should be immutable \n",
"first_markdown_element": "tests/detectors/immutable-states/0.7.6/immut_state_variables.sol#L47",
"id": "42d50245236163ceca90dea732165e65c2155934b149a5a1a5c51bddc0b5b02a",
"check": "immutable-states",
"impact": "Optimization",
"confidence": "High"
},
{
"elements": [
{
"type": "variable",
"name": "should_be_immutable_2",
"source_mapping": {
"start": 940,
"length": 40,
"filename_relative": "tests/detectors/immutable-states/0.7.6/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.7.6/immut_state_variables.sol",
"is_dependency": false,
"lines": [
44
],
"starting_column": 5,
"ending_column": 45
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "Bad",
"source_mapping": {
"start": 718,
"length": 531,
"filename_relative": "tests/detectors/immutable-states/0.7.6/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.7.6/immut_state_variables.sol",
"is_dependency": false,
"lines": [
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56
],
"starting_column": 1,
"ending_column": 2
}
}
}
}
],
"description": "Bad.should_be_immutable_2 (tests/detectors/immutable-states/0.7.6/immut_state_variables.sol#44) should be immutable \n",
"markdown": "[Bad.should_be_immutable_2](tests/detectors/immutable-states/0.7.6/immut_state_variables.sol#L44) should be immutable \n",
"first_markdown_element": "tests/detectors/immutable-states/0.7.6/immut_state_variables.sol#L44",
"id": "70d57aa51dda92c28444a466db8567fa783c85d484259aa5eee2ebc63f97a200",
"check": "immutable-states",
"impact": "Optimization",
"confidence": "High"
},
{
"elements": [
{
"type": "variable",
"name": "should_be_immutable_4",
"source_mapping": {
"start": 1038,
"length": 33,
"filename_relative": "tests/detectors/immutable-states/0.7.6/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.7.6/immut_state_variables.sol",
"is_dependency": false,
"lines": [
46
],
"starting_column": 5,
"ending_column": 38
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "Bad",
"source_mapping": {
"start": 718,
"length": 531,
"filename_relative": "tests/detectors/immutable-states/0.7.6/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.7.6/immut_state_variables.sol",
"is_dependency": false,
"lines": [
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56
],
"starting_column": 1,
"ending_column": 2
}
}
}
}
],
"description": "Bad.should_be_immutable_4 (tests/detectors/immutable-states/0.7.6/immut_state_variables.sol#46) should be immutable \n",
"markdown": "[Bad.should_be_immutable_4](tests/detectors/immutable-states/0.7.6/immut_state_variables.sol#L46) should be immutable \n",
"first_markdown_element": "tests/detectors/immutable-states/0.7.6/immut_state_variables.sol#L46",
"id": "a26d6df4087ac010928bc4bd18aa70ac58a28e584b1288e348d9c255473c300d",
"check": "immutable-states",
"impact": "Optimization",
"confidence": "High"
},
{
"elements": [
{
"type": "variable",
"name": "should_be_immutable",
"source_mapping": {
"start": 894,
"length": 40,
"filename_relative": "tests/detectors/immutable-states/0.7.6/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.7.6/immut_state_variables.sol",
"is_dependency": false,
"lines": [
43
],
"starting_column": 5,
"ending_column": 45
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "Bad",
"source_mapping": {
"start": 718,
"length": 531,
"filename_relative": "tests/detectors/immutable-states/0.7.6/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.7.6/immut_state_variables.sol",
"is_dependency": false,
"lines": [
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56
],
"starting_column": 1,
"ending_column": 2
}
}
}
}
],
"description": "Bad.should_be_immutable (tests/detectors/immutable-states/0.7.6/immut_state_variables.sol#43) should be immutable \n",
"markdown": "[Bad.should_be_immutable](tests/detectors/immutable-states/0.7.6/immut_state_variables.sol#L43) should be immutable \n",
"first_markdown_element": "tests/detectors/immutable-states/0.7.6/immut_state_variables.sol#L43",
"id": "b163d277f544f7f05ed4bcddda61e444be893e65ba0469688abd7b401a1db222",
"check": "immutable-states",
"impact": "Optimization",
"confidence": "High"
},
{
"elements": [
{
"type": "variable",
"name": "should_be_immutable_3",
"source_mapping": {
"start": 986,
"length": 46,
"filename_relative": "tests/detectors/immutable-states/0.7.6/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.7.6/immut_state_variables.sol",
"is_dependency": false,
"lines": [
45
],
"starting_column": 5,
"ending_column": 51
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "Bad",
"source_mapping": {
"start": 718,
"length": 531,
"filename_relative": "tests/detectors/immutable-states/0.7.6/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.7.6/immut_state_variables.sol",
"is_dependency": false,
"lines": [
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56
],
"starting_column": 1,
"ending_column": 2
}
}
}
}
],
"description": "Bad.should_be_immutable_3 (tests/detectors/immutable-states/0.7.6/immut_state_variables.sol#45) should be immutable \n",
"markdown": "[Bad.should_be_immutable_3](tests/detectors/immutable-states/0.7.6/immut_state_variables.sol#L45) should be immutable \n",
"first_markdown_element": "tests/detectors/immutable-states/0.7.6/immut_state_variables.sol#L45",
"id": "f19f7a22a6f17ffd8b5c29021226388aab7548f996b686a8e0b2bc861f72d447",
"check": "immutable-states",
"impact": "Optimization",
"confidence": "High"
}
]
]

@ -0,0 +1,78 @@
contract A {
address constant public MY_ADDRESS = 0xE0f5206BBD039e7b0592d8918820024e2a7437b9;
address public myFriendsAddress = 0xc0ffee254729296a45a3885639AC7E10F9d54979;
uint public used;
uint public test = 5;
uint constant X = 32**22 + 8;
string constant TEXT1 = "abc";
string text2 = "xyz";
function setUsed() public {
if (msg.sender == MY_ADDRESS) {
used = test;
}
}
}
contract B is A {
address public mySistersAddress = 0x999999cf1046e68e36E1aA2E0E07105eDDD1f08E;
fallback () external {
used = 0;
}
function setUsed(uint a) public {
if (msg.sender == MY_ADDRESS) {
used = a;
}
}
}
contract Bad {
uint constant A = 1;
bytes32 should_be_constant = sha256('abc');
uint should_be_constant_2 = A + 1;
B should_be_constant_3 = B(address(0));
address should_be_immutable = msg.sender;
uint should_be_immutable_2 = getNumber();
uint should_be_immutable_3 = 10 + block.number;
uint should_be_immutable_5;
constructor(uint b) {
should_be_immutable_5 = b;
}
function getNumber() public returns(uint){
return block.number;
}
}
contract Good {
uint constant A = 1;
bytes32 constant should_be_constant = sha256('abc');
uint constant should_be_constant_2 = A + 1;
B constant should_be_constant_3 = B(address(0));
address immutable should_be_immutable = msg.sender;
uint immutable should_be_immutable_2 = getNumber();
uint immutable should_be_immutable_3 = 10 + block.number;
B immutable should_be_immutable_4 = new B();
uint immutable should_be_immutable_5;
constructor(uint b) {
should_be_immutable_5 = b;
}
function getNumber() public returns(uint){
return block.number;
}
}

@ -0,0 +1,268 @@
[
[
{
"elements": [
{
"type": "variable",
"name": "should_be_immutable_5",
"source_mapping": {
"start": 1038,
"length": 26,
"filename_relative": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
"is_dependency": false,
"lines": [
46
],
"starting_column": 5,
"ending_column": 31
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "Bad",
"source_mapping": {
"start": 718,
"length": 493,
"filename_relative": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
"is_dependency": false,
"lines": [
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56
],
"starting_column": 1,
"ending_column": 2
}
}
}
}
],
"description": "Bad.should_be_immutable_5 (tests/detectors/immutable-states/0.8.0/immut_state_variables.sol#46) should be immutable \n",
"markdown": "[Bad.should_be_immutable_5](tests/detectors/immutable-states/0.8.0/immut_state_variables.sol#L46) should be immutable \n",
"first_markdown_element": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol#L46",
"id": "42d50245236163ceca90dea732165e65c2155934b149a5a1a5c51bddc0b5b02a",
"check": "immutable-states",
"impact": "Optimization",
"confidence": "High"
},
{
"elements": [
{
"type": "variable",
"name": "should_be_immutable_2",
"source_mapping": {
"start": 940,
"length": 40,
"filename_relative": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
"is_dependency": false,
"lines": [
44
],
"starting_column": 5,
"ending_column": 45
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "Bad",
"source_mapping": {
"start": 718,
"length": 493,
"filename_relative": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
"is_dependency": false,
"lines": [
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56
],
"starting_column": 1,
"ending_column": 2
}
}
}
}
],
"description": "Bad.should_be_immutable_2 (tests/detectors/immutable-states/0.8.0/immut_state_variables.sol#44) should be immutable \n",
"markdown": "[Bad.should_be_immutable_2](tests/detectors/immutable-states/0.8.0/immut_state_variables.sol#L44) should be immutable \n",
"first_markdown_element": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol#L44",
"id": "70d57aa51dda92c28444a466db8567fa783c85d484259aa5eee2ebc63f97a200",
"check": "immutable-states",
"impact": "Optimization",
"confidence": "High"
},
{
"elements": [
{
"type": "variable",
"name": "should_be_immutable",
"source_mapping": {
"start": 894,
"length": 40,
"filename_relative": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
"is_dependency": false,
"lines": [
43
],
"starting_column": 5,
"ending_column": 45
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "Bad",
"source_mapping": {
"start": 718,
"length": 493,
"filename_relative": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
"is_dependency": false,
"lines": [
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56
],
"starting_column": 1,
"ending_column": 2
}
}
}
}
],
"description": "Bad.should_be_immutable (tests/detectors/immutable-states/0.8.0/immut_state_variables.sol#43) should be immutable \n",
"markdown": "[Bad.should_be_immutable](tests/detectors/immutable-states/0.8.0/immut_state_variables.sol#L43) should be immutable \n",
"first_markdown_element": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol#L43",
"id": "b163d277f544f7f05ed4bcddda61e444be893e65ba0469688abd7b401a1db222",
"check": "immutable-states",
"impact": "Optimization",
"confidence": "High"
},
{
"elements": [
{
"type": "variable",
"name": "should_be_immutable_3",
"source_mapping": {
"start": 986,
"length": 46,
"filename_relative": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
"is_dependency": false,
"lines": [
45
],
"starting_column": 5,
"ending_column": 51
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "Bad",
"source_mapping": {
"start": 718,
"length": 493,
"filename_relative": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
"is_dependency": false,
"lines": [
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56
],
"starting_column": 1,
"ending_column": 2
}
}
}
}
],
"description": "Bad.should_be_immutable_3 (tests/detectors/immutable-states/0.8.0/immut_state_variables.sol#45) should be immutable \n",
"markdown": "[Bad.should_be_immutable_3](tests/detectors/immutable-states/0.8.0/immut_state_variables.sol#L45) should be immutable \n",
"first_markdown_element": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol#L45",
"id": "f19f7a22a6f17ffd8b5c29021226388aab7548f996b686a8e0b2bc861f72d447",
"check": "immutable-states",
"impact": "Optimization",
"confidence": "High"
}
]
]

@ -480,30 +480,55 @@ ALL_TEST_OBJECTS = [
"0.7.6",
),
Test(
all_detectors.ConstCandidateStateVars,
all_detectors.CouldBeConstant,
"const_state_variables.sol",
"0.4.25",
),
Test(
all_detectors.ConstCandidateStateVars,
all_detectors.CouldBeConstant,
"const_state_variables.sol",
"0.5.16",
),
Test(
all_detectors.ConstCandidateStateVars,
all_detectors.CouldBeConstant,
"const_state_variables.sol",
"0.6.11",
),
Test(
all_detectors.ConstCandidateStateVars,
all_detectors.CouldBeConstant,
"const_state_variables.sol",
"0.7.6",
),
Test(
all_detectors.ConstCandidateStateVars,
all_detectors.CouldBeConstant,
"const_state_variables.sol",
"0.8.0",
),
Test(
all_detectors.CouldBeImmutable,
"immut_state_variables.sol",
"0.4.25",
),
Test(
all_detectors.CouldBeImmutable,
"immut_state_variables.sol",
"0.5.16",
),
Test(
all_detectors.CouldBeImmutable,
"immut_state_variables.sol",
"0.6.11",
),
Test(
all_detectors.CouldBeImmutable,
"immut_state_variables.sol",
"0.7.6",
),
Test(
all_detectors.CouldBeImmutable,
"immut_state_variables.sol",
"0.8.0",
),
Test(
all_detectors.ExternalFunction,
"external_function.sol",

Loading…
Cancel
Save