Merge pull request #1455 from crytic/detect/add-immutable-opti

add immutable-states detector
pull/1573/head
Feist Josselin 2 years ago committed by GitHub
commit 45c5ed99f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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. 125
      slither/detectors/variables/possible_const_state_variables.py
  5. 125
      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. 224
      tests/detectors/constable-states/0.4.25/const_state_variables.sol.0.4.25.CouldBeConstant.json
  10. 6
      tests/detectors/constable-states/0.5.16/const_state_variables.sol
  11. 276
      tests/detectors/constable-states/0.5.16/const_state_variables.sol.0.5.16.CouldBeConstant.json
  12. 39
      tests/detectors/constable-states/0.6.11/const_state_variables.sol
  13. 307
      tests/detectors/constable-states/0.6.11/const_state_variables.sol.0.6.11.CouldBeConstant.json
  14. 38
      tests/detectors/constable-states/0.7.6/const_state_variables.sol
  15. 304
      tests/detectors/constable-states/0.7.6/const_state_variables.sol.0.7.6.CouldBeConstant.json
  16. 78
      tests/detectors/constable-states/0.8.0/const_state_variables.sol
  17. 454
      tests/detectors/constable-states/0.8.0/const_state_variables.sol.0.8.0.CouldBeConstant.json
  18. 7
      tests/detectors/constable-states/0.8.0/immutable.sol
  19. 57
      tests/detectors/immutable-states/0.4.25/immut_state_variables.sol
  20. 0
      tests/detectors/immutable-states/0.4.25/immut_state_variables.sol.0.4.25.CouldBeImmutable.json
  21. 58
      tests/detectors/immutable-states/0.5.16/immut_state_variables.sol
  22. 3
      tests/detectors/immutable-states/0.5.16/immut_state_variables.sol.0.5.16.CouldBeImmutable.json
  23. 79
      tests/detectors/immutable-states/0.6.11/immut_state_variables.sol
  24. 339
      tests/detectors/immutable-states/0.6.11/immut_state_variables.sol.0.6.11.CouldBeImmutable.json
  25. 78
      tests/detectors/immutable-states/0.7.6/immut_state_variables.sol
  26. 334
      tests/detectors/immutable-states/0.7.6/immut_state_variables.sol.0.7.6.CouldBeImmutable.json
  27. 78
      tests/detectors/immutable-states/0.8.0/immut_state_variables.sol
  28. 268
      tests/detectors/immutable-states/0.8.0/immut_state_variables.sol.0.8.0.CouldBeImmutable.json
  29. 37
      tests/test_detectors.py

@ -19,7 +19,8 @@ from .reentrancy.reentrancy_eth import ReentrancyEth
from .reentrancy.reentrancy_no_gas import ReentrancyNoGas from .reentrancy.reentrancy_no_gas import ReentrancyNoGas
from .reentrancy.reentrancy_events import ReentrancyEvent from .reentrancy.reentrancy_events import ReentrancyEvent
from .variables.unused_state_variables import UnusedStateVars 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.tx_origin import TxOrigin
from .statements.assembly import Assembly from .statements.assembly import Assembly
from .operations.low_level_calls import LowLevelCalls 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,125 +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
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"
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 = "Constant state variables should be declared constant to save gas."
WIKI_RECOMMENDATION = "Add the `constant` attributes 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
export = ExportValues(v.expression)
values = export.result()
if not values:
return True
if all((val in self.valid_solidity_function or _is_constant_var(val) for val in values)):
return True
return False
def _detect(self) -> List[Output]:
"""Detect state variables that could be const"""
results = []
all_variables_l = [c.state_variables for c in self.compilation_unit.contracts]
all_variables: Set[StateVariable] = {
item for sublist in all_variables_l for item in sublist
}
all_non_constant_elementary_variables = {v for v in all_variables if _valid_candidate(v)}
all_functions_nested = [c.all_functions_called for c in self.compilation_unit.contracts]
all_functions = list(
{
item1
for sublist in all_functions_nested
for item1 in sublist
if isinstance(item1, Function)
}
)
all_variables_written = [
f.state_variables_written for f in all_functions if not f.is_constructor_variables
]
all_variables_written = {item for sublist in all_variables_written for item in sublist}
constable_variables: List[Variable] = [
v
for v in all_non_constant_elementary_variables
if (v not in all_variables_written) and self._constant_initial_expression(v)
]
# Order for deterministic results
constable_variables = sorted(constable_variables, key=lambda x: x.canonical_name)
# Create a result for each finding
for v in constable_variables:
info = [v, " should be constant\n"]
json = self.generate_result(info)
results.append(json)
return results
@staticmethod
def _format(compilation_unit: SlitherCompilationUnit, result: Dict) -> None:
custom_format(compilation_unit, result)

@ -0,0 +1,125 @@
"""
Module detecting state variables that could be declared as constant
"""
from typing import Set, List
from packaging import version
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 version.parse(self.compilation_unit.solc_version) >= version.parse(
"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 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"] elements = result["elements"]
for element in elements: for element in elements:
@ -15,14 +15,14 @@ def custom_format(compilation_unit: SlitherCompilationUnit, result):
contract = scope.get_contract_from_name(contract_name) contract = scope.get_contract_from_name(contract_name)
var = contract.get_state_variable_from_name(element["name"]) var = contract.get_state_variable_from_name(element["name"])
if not var.expression: 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( _patch(
compilation_unit, compilation_unit,
result, result,
element["source_mapping"]["filename_absolute"], element["source_mapping"]["filename_absolute"],
element["name"], element["name"],
"constant " + element["name"], f"{attribute} " + element["name"],
element["source_mapping"]["start"], element["source_mapping"]["start"],
element["source_mapping"]["start"] + element["source_mapping"]["length"], 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.attributes.constant_pragma import ConstantPragma
from slither.detectors.naming_convention.naming_convention import NamingConvention from slither.detectors.naming_convention.naming_convention import NamingConvention
from slither.detectors.functions.external_function import ExternalFunction 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_asm import ConstantFunctionsAsm
from slither.detectors.attributes.const_functions_state import ConstantFunctionsState from slither.detectors.attributes.const_functions_state import ConstantFunctionsState
from slither.utils.colors import yellow from slither.utils.colors import yellow
@ -23,7 +24,8 @@ all_detectors: Dict[str, Type[AbstractDetector]] = {
"pragma": ConstantPragma, "pragma": ConstantPragma,
"naming-convention": NamingConvention, "naming-convention": NamingConvention,
"external-function": ExternalFunction, "external-function": ExternalFunction,
"constable-states": ConstCandidateStateVars, "constable-states": CouldBeConstant,
"immutable-states": CouldBeImmutable,
"constant-function-asm": ConstantFunctionsAsm, "constant-function-asm": ConstantFunctionsAsm,
"constant-functions-state": ConstantFunctionsState, "constant-functions-state": ConstantFunctionsState,
} }

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

@ -4,19 +4,19 @@
"elements": [ "elements": [
{ {
"type": "variable", "type": "variable",
"name": "myFriendsAddress", "name": "text2",
"source_mapping": { "source_mapping": {
"start": 132, "start": 333,
"length": 76, "length": 20,
"filename_relative": "tests/detectors/constable-states/0.4.25/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.4.25/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.4.25/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.4.25/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
7 14
], ],
"starting_column": 5, "starting_column": 5,
"ending_column": 81 "ending_column": 25
}, },
"type_specific_fields": { "type_specific_fields": {
"parent": { "parent": {
@ -56,10 +56,10 @@
} }
} }
], ],
"description": "A.myFriendsAddress (tests/detectors/constable-states/0.4.25/const_state_variables.sol#7) should be constant\n", "description": "A.text2 (tests/detectors/constable-states/0.4.25/const_state_variables.sol#14) should be constant \n",
"markdown": "[A.myFriendsAddress](tests/detectors/constable-states/0.4.25/const_state_variables.sol#L7) should be constant\n", "markdown": "[A.text2](tests/detectors/constable-states/0.4.25/const_state_variables.sol#L14) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.4.25/const_state_variables.sol#L7", "first_markdown_element": "tests/detectors/constable-states/0.4.25/const_state_variables.sol#L14",
"id": "1454db80653b732bf6acbe54ff0ae4707002207a2a8216708c12d61c88a43e5f", "id": "2f06e04545cea7e7a8998c65d5419f335bf2579a6ce6a832eac9c87392fd5c1a",
"check": "constable-states", "check": "constable-states",
"impact": "Optimization", "impact": "Optimization",
"confidence": "High" "confidence": "High"
@ -68,19 +68,79 @@
"elements": [ "elements": [
{ {
"type": "variable", "type": "variable",
"name": "test", "name": "mySistersAddress",
"source_mapping": { "source_mapping": {
"start": 237, "start": 496,
"length": 20, "length": 76,
"filename_relative": "tests/detectors/constable-states/0.4.25/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.4.25/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.4.25/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.4.25/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
10 26
], ],
"starting_column": 5, "starting_column": 5,
"ending_column": 25 "ending_column": 81
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "B",
"source_mapping": {
"start": 473,
"length": 271,
"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",
"is_dependency": false,
"lines": [
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37
],
"starting_column": 1,
"ending_column": 2
}
}
}
}
],
"description": "B.mySistersAddress (tests/detectors/constable-states/0.4.25/const_state_variables.sol#26) should be constant \n",
"markdown": "[B.mySistersAddress](tests/detectors/constable-states/0.4.25/const_state_variables.sol#L26) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.4.25/const_state_variables.sol#L26",
"id": "3b5bff93954a48a79387e7981e8c45d78edc575a0988a10f1c7f439b9f930539",
"check": "constable-states",
"impact": "Optimization",
"confidence": "High"
},
{
"elements": [
{
"type": "variable",
"name": "myFriendsAddress",
"source_mapping": {
"start": 132,
"length": 76,
"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",
"is_dependency": false,
"lines": [
7
],
"starting_column": 5,
"ending_column": 81
}, },
"type_specific_fields": { "type_specific_fields": {
"parent": { "parent": {
@ -120,10 +180,10 @@
} }
} }
], ],
"description": "A.test (tests/detectors/constable-states/0.4.25/const_state_variables.sol#10) should be constant\n", "description": "A.myFriendsAddress (tests/detectors/constable-states/0.4.25/const_state_variables.sol#7) should be constant \n",
"markdown": "[A.test](tests/detectors/constable-states/0.4.25/const_state_variables.sol#L10) should be constant\n", "markdown": "[A.myFriendsAddress](tests/detectors/constable-states/0.4.25/const_state_variables.sol#L7) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.4.25/const_state_variables.sol#L10", "first_markdown_element": "tests/detectors/constable-states/0.4.25/const_state_variables.sol#L7",
"id": "5d9e3fb413322b71a93e90f7e89bd8c83cd4884d577d039598c681fe9db38b1d", "id": "52fd72f6870c4b504d1bcf9fb44249658e2077474d66208a33a47d2668b8db49",
"check": "constable-states", "check": "constable-states",
"impact": "Optimization", "impact": "Optimization",
"confidence": "High" "confidence": "High"
@ -132,19 +192,19 @@
"elements": [ "elements": [
{ {
"type": "variable", "type": "variable",
"name": "should_be_constant_2", "name": "should_be_constant",
"source_mapping": { "source_mapping": {
"start": 841, "start": 793,
"length": 33, "length": 42,
"filename_relative": "tests/detectors/constable-states/0.4.25/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.4.25/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.4.25/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.4.25/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
43 42
], ],
"starting_column": 5, "starting_column": 5,
"ending_column": 38 "ending_column": 47
}, },
"type_specific_fields": { "type_specific_fields": {
"parent": { "parent": {
@ -152,7 +212,7 @@
"name": "MyConc", "name": "MyConc",
"source_mapping": { "source_mapping": {
"start": 746, "start": 746,
"length": 342, "length": 423,
"filename_relative": "tests/detectors/constable-states/0.4.25/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.4.25/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.4.25/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.4.25/const_state_variables.sol",
@ -171,7 +231,12 @@
49, 49,
50, 50,
51, 51,
52 52,
53,
54,
55,
56,
57
], ],
"starting_column": 1, "starting_column": 1,
"ending_column": 2 "ending_column": 2
@ -180,70 +245,10 @@
} }
} }
], ],
"description": "MyConc.should_be_constant_2 (tests/detectors/constable-states/0.4.25/const_state_variables.sol#43) should be constant\n", "description": "MyConc.should_be_constant (tests/detectors/constable-states/0.4.25/const_state_variables.sol#42) should be constant \n",
"markdown": "[MyConc.should_be_constant_2](tests/detectors/constable-states/0.4.25/const_state_variables.sol#L43) should be constant\n", "markdown": "[MyConc.should_be_constant](tests/detectors/constable-states/0.4.25/const_state_variables.sol#L42) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.4.25/const_state_variables.sol#L43", "first_markdown_element": "tests/detectors/constable-states/0.4.25/const_state_variables.sol#L42",
"id": "9a48a4122de1a6a4774a9f1e0d4917bd0fa08f17b4af41b86ba07689e51bf711", "id": "8d08797efc8230b480ec669c7e2bf53c3b3d16bc59bf7770934b34fd892934f8",
"check": "constable-states",
"impact": "Optimization",
"confidence": "High"
},
{
"elements": [
{
"type": "variable",
"name": "mySistersAddress",
"source_mapping": {
"start": 496,
"length": 76,
"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",
"is_dependency": false,
"lines": [
26
],
"starting_column": 5,
"ending_column": 81
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "B",
"source_mapping": {
"start": 473,
"length": 271,
"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",
"is_dependency": false,
"lines": [
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37
],
"starting_column": 1,
"ending_column": 2
}
}
}
}
],
"description": "B.mySistersAddress (tests/detectors/constable-states/0.4.25/const_state_variables.sol#26) should be constant\n",
"markdown": "[B.mySistersAddress](tests/detectors/constable-states/0.4.25/const_state_variables.sol#L26) should be constant\n",
"first_markdown_element": "tests/detectors/constable-states/0.4.25/const_state_variables.sol#L26",
"id": "bee93a722c8eae4a48aade67d8ef537d84c106f48fc9eb738c795fce10d3bc63",
"check": "constable-states", "check": "constable-states",
"impact": "Optimization", "impact": "Optimization",
"confidence": "High" "confidence": "High"
@ -252,19 +257,19 @@
"elements": [ "elements": [
{ {
"type": "variable", "type": "variable",
"name": "should_be_constant", "name": "should_be_constant_2",
"source_mapping": { "source_mapping": {
"start": 793, "start": 841,
"length": 42, "length": 33,
"filename_relative": "tests/detectors/constable-states/0.4.25/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.4.25/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.4.25/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.4.25/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
42 43
], ],
"starting_column": 5, "starting_column": 5,
"ending_column": 47 "ending_column": 38
}, },
"type_specific_fields": { "type_specific_fields": {
"parent": { "parent": {
@ -272,7 +277,7 @@
"name": "MyConc", "name": "MyConc",
"source_mapping": { "source_mapping": {
"start": 746, "start": 746,
"length": 342, "length": 423,
"filename_relative": "tests/detectors/constable-states/0.4.25/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.4.25/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.4.25/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.4.25/const_state_variables.sol",
@ -291,7 +296,12 @@
49, 49,
50, 50,
51, 51,
52 52,
53,
54,
55,
56,
57
], ],
"starting_column": 1, "starting_column": 1,
"ending_column": 2 "ending_column": 2
@ -300,10 +310,10 @@
} }
} }
], ],
"description": "MyConc.should_be_constant (tests/detectors/constable-states/0.4.25/const_state_variables.sol#42) should be constant\n", "description": "MyConc.should_be_constant_2 (tests/detectors/constable-states/0.4.25/const_state_variables.sol#43) should be constant \n",
"markdown": "[MyConc.should_be_constant](tests/detectors/constable-states/0.4.25/const_state_variables.sol#L42) should be constant\n", "markdown": "[MyConc.should_be_constant_2](tests/detectors/constable-states/0.4.25/const_state_variables.sol#L43) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.4.25/const_state_variables.sol#L42", "first_markdown_element": "tests/detectors/constable-states/0.4.25/const_state_variables.sol#L43",
"id": "cbcafa2a3efba4d21ac1b51b4b823e5082d556bc3d6cf3fd2ab3188f9f218fc1", "id": "d08c6d1e331083b42c45c222691dd1e6d880814c66d114971875337ca61ba9c9",
"check": "constable-states", "check": "constable-states",
"impact": "Optimization", "impact": "Optimization",
"confidence": "High" "confidence": "High"
@ -312,16 +322,16 @@
"elements": [ "elements": [
{ {
"type": "variable", "type": "variable",
"name": "text2", "name": "test",
"source_mapping": { "source_mapping": {
"start": 333, "start": 237,
"length": 20, "length": 20,
"filename_relative": "tests/detectors/constable-states/0.4.25/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.4.25/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.4.25/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.4.25/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
14 10
], ],
"starting_column": 5, "starting_column": 5,
"ending_column": 25 "ending_column": 25
@ -364,10 +374,10 @@
} }
} }
], ],
"description": "A.text2 (tests/detectors/constable-states/0.4.25/const_state_variables.sol#14) should be constant\n", "description": "A.test (tests/detectors/constable-states/0.4.25/const_state_variables.sol#10) should be constant \n",
"markdown": "[A.text2](tests/detectors/constable-states/0.4.25/const_state_variables.sol#L14) should be constant\n", "markdown": "[A.test](tests/detectors/constable-states/0.4.25/const_state_variables.sol#L10) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.4.25/const_state_variables.sol#L14", "first_markdown_element": "tests/detectors/constable-states/0.4.25/const_state_variables.sol#L10",
"id": "df11e6201c4558a8c5cd90b55b134b9ca8f07203b2264d3aa93bd7745e8cb4ba", "id": "e407a1b57b4d25949ef7c4e6d97197605857099a94774a9c7a848d7dd3463668",
"check": "constable-states", "check": "constable-states",
"impact": "Optimization", "impact": "Optimization",
"confidence": "High" "confidence": "High"

@ -41,10 +41,16 @@ contract MyConc{
uint constant A = 1; uint constant A = 1;
bytes32 should_be_constant = sha256('abc'); bytes32 should_be_constant = sha256('abc');
uint should_be_constant_2 = A + 1; uint should_be_constant_2 = A + 1;
B should_be_constant_3 = B(address(0));
address not_constant = msg.sender; address not_constant = msg.sender;
uint not_constant_2 = getNumber(); uint not_constant_2 = getNumber();
uint not_constant_3 = 10 + block.number; uint not_constant_3 = 10 + block.number;
uint not_constant_5;
constructor(uint b) public {
not_constant_5 = b;
}
function getNumber() public returns(uint){ function getNumber() public returns(uint){
return block.number; return block.number;
} }

@ -4,50 +4,52 @@
"elements": [ "elements": [
{ {
"type": "variable", "type": "variable",
"name": "myFriendsAddress", "name": "should_be_constant_3",
"source_mapping": { "source_mapping": {
"start": 132, "start": 880,
"length": 76, "length": 38,
"filename_relative": "tests/detectors/constable-states/0.5.16/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.5.16/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.5.16/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.5.16/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
7 44
], ],
"starting_column": 5, "starting_column": 5,
"ending_column": 81 "ending_column": 43
}, },
"type_specific_fields": { "type_specific_fields": {
"parent": { "parent": {
"type": "contract", "type": "contract",
"name": "A", "name": "MyConc",
"source_mapping": { "source_mapping": {
"start": 29, "start": 746,
"length": 441, "length": 467,
"filename_relative": "tests/detectors/constable-states/0.5.16/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.5.16/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.5.16/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.5.16/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
4, 39,
5, 40,
6, 41,
7, 42,
8, 43,
9, 44,
10, 45,
11, 46,
12, 47,
13, 48,
14, 49,
15, 50,
16, 51,
17, 52,
18, 53,
19, 54,
20, 55,
21 56,
57,
58
], ],
"starting_column": 1, "starting_column": 1,
"ending_column": 2 "ending_column": 2
@ -56,10 +58,10 @@
} }
} }
], ],
"description": "A.myFriendsAddress (tests/detectors/constable-states/0.5.16/const_state_variables.sol#7) should be constant\n", "description": "MyConc.should_be_constant_3 (tests/detectors/constable-states/0.5.16/const_state_variables.sol#44) should be constant \n",
"markdown": "[A.myFriendsAddress](tests/detectors/constable-states/0.5.16/const_state_variables.sol#L7) should be constant\n", "markdown": "[MyConc.should_be_constant_3](tests/detectors/constable-states/0.5.16/const_state_variables.sol#L44) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.5.16/const_state_variables.sol#L7", "first_markdown_element": "tests/detectors/constable-states/0.5.16/const_state_variables.sol#L44",
"id": "1454db80653b732bf6acbe54ff0ae4707002207a2a8216708c12d61c88a43e5f", "id": "29247b0a9939e854ad51bf3b2f58705156aa8b7e446e646b1832467d362b5b3e",
"check": "constable-states", "check": "constable-states",
"impact": "Optimization", "impact": "Optimization",
"confidence": "High" "confidence": "High"
@ -68,16 +70,16 @@
"elements": [ "elements": [
{ {
"type": "variable", "type": "variable",
"name": "test", "name": "text2",
"source_mapping": { "source_mapping": {
"start": 237, "start": 333,
"length": 20, "length": 20,
"filename_relative": "tests/detectors/constable-states/0.5.16/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.5.16/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.5.16/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.5.16/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
10 14
], ],
"starting_column": 5, "starting_column": 5,
"ending_column": 25 "ending_column": 25
@ -120,10 +122,10 @@
} }
} }
], ],
"description": "A.test (tests/detectors/constable-states/0.5.16/const_state_variables.sol#10) should be constant\n", "description": "A.text2 (tests/detectors/constable-states/0.5.16/const_state_variables.sol#14) should be constant \n",
"markdown": "[A.test](tests/detectors/constable-states/0.5.16/const_state_variables.sol#L10) should be constant\n", "markdown": "[A.text2](tests/detectors/constable-states/0.5.16/const_state_variables.sol#L14) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.5.16/const_state_variables.sol#L10", "first_markdown_element": "tests/detectors/constable-states/0.5.16/const_state_variables.sol#L14",
"id": "5d9e3fb413322b71a93e90f7e89bd8c83cd4884d577d039598c681fe9db38b1d", "id": "2f06e04545cea7e7a8998c65d5419f335bf2579a6ce6a832eac9c87392fd5c1a",
"check": "constable-states", "check": "constable-states",
"impact": "Optimization", "impact": "Optimization",
"confidence": "High" "confidence": "High"
@ -132,46 +134,46 @@
"elements": [ "elements": [
{ {
"type": "variable", "type": "variable",
"name": "should_be_constant_2", "name": "mySistersAddress",
"source_mapping": { "source_mapping": {
"start": 841, "start": 496,
"length": 33, "length": 76,
"filename_relative": "tests/detectors/constable-states/0.5.16/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.5.16/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.5.16/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.5.16/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
43 26
], ],
"starting_column": 5, "starting_column": 5,
"ending_column": 38 "ending_column": 81
}, },
"type_specific_fields": { "type_specific_fields": {
"parent": { "parent": {
"type": "contract", "type": "contract",
"name": "MyConc", "name": "B",
"source_mapping": { "source_mapping": {
"start": 746, "start": 473,
"length": 342, "length": 271,
"filename_relative": "tests/detectors/constable-states/0.5.16/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.5.16/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.5.16/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.5.16/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
39, 24,
40, 25,
41, 26,
42, 27,
43, 28,
44, 29,
45, 30,
46, 31,
47, 32,
48, 33,
49, 34,
50, 35,
51, 36,
52 37
], ],
"starting_column": 1, "starting_column": 1,
"ending_column": 2 "ending_column": 2
@ -180,10 +182,10 @@
} }
} }
], ],
"description": "MyConc.should_be_constant_2 (tests/detectors/constable-states/0.5.16/const_state_variables.sol#43) should be constant\n", "description": "B.mySistersAddress (tests/detectors/constable-states/0.5.16/const_state_variables.sol#26) should be constant \n",
"markdown": "[MyConc.should_be_constant_2](tests/detectors/constable-states/0.5.16/const_state_variables.sol#L43) should be constant\n", "markdown": "[B.mySistersAddress](tests/detectors/constable-states/0.5.16/const_state_variables.sol#L26) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.5.16/const_state_variables.sol#L43", "first_markdown_element": "tests/detectors/constable-states/0.5.16/const_state_variables.sol#L26",
"id": "9a48a4122de1a6a4774a9f1e0d4917bd0fa08f17b4af41b86ba07689e51bf711", "id": "3b5bff93954a48a79387e7981e8c45d78edc575a0988a10f1c7f439b9f930539",
"check": "constable-states", "check": "constable-states",
"impact": "Optimization", "impact": "Optimization",
"confidence": "High" "confidence": "High"
@ -192,16 +194,16 @@
"elements": [ "elements": [
{ {
"type": "variable", "type": "variable",
"name": "mySistersAddress", "name": "myFriendsAddress",
"source_mapping": { "source_mapping": {
"start": 496, "start": 132,
"length": 76, "length": 76,
"filename_relative": "tests/detectors/constable-states/0.5.16/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.5.16/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.5.16/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.5.16/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
26 7
], ],
"starting_column": 5, "starting_column": 5,
"ending_column": 81 "ending_column": 81
@ -209,29 +211,33 @@
"type_specific_fields": { "type_specific_fields": {
"parent": { "parent": {
"type": "contract", "type": "contract",
"name": "B", "name": "A",
"source_mapping": { "source_mapping": {
"start": 473, "start": 29,
"length": 271, "length": 441,
"filename_relative": "tests/detectors/constable-states/0.5.16/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.5.16/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.5.16/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.5.16/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
24, 4,
25, 5,
26, 6,
27, 7,
28, 8,
29, 9,
30, 10,
31, 11,
32, 12,
33, 13,
34, 14,
35, 15,
36, 16,
37 17,
18,
19,
20,
21
], ],
"starting_column": 1, "starting_column": 1,
"ending_column": 2 "ending_column": 2
@ -240,10 +246,10 @@
} }
} }
], ],
"description": "B.mySistersAddress (tests/detectors/constable-states/0.5.16/const_state_variables.sol#26) should be constant\n", "description": "A.myFriendsAddress (tests/detectors/constable-states/0.5.16/const_state_variables.sol#7) should be constant \n",
"markdown": "[B.mySistersAddress](tests/detectors/constable-states/0.5.16/const_state_variables.sol#L26) should be constant\n", "markdown": "[A.myFriendsAddress](tests/detectors/constable-states/0.5.16/const_state_variables.sol#L7) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.5.16/const_state_variables.sol#L26", "first_markdown_element": "tests/detectors/constable-states/0.5.16/const_state_variables.sol#L7",
"id": "bee93a722c8eae4a48aade67d8ef537d84c106f48fc9eb738c795fce10d3bc63", "id": "52fd72f6870c4b504d1bcf9fb44249658e2077474d66208a33a47d2668b8db49",
"check": "constable-states", "check": "constable-states",
"impact": "Optimization", "impact": "Optimization",
"confidence": "High" "confidence": "High"
@ -272,7 +278,7 @@
"name": "MyConc", "name": "MyConc",
"source_mapping": { "source_mapping": {
"start": 746, "start": 746,
"length": 342, "length": 467,
"filename_relative": "tests/detectors/constable-states/0.5.16/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.5.16/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.5.16/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.5.16/const_state_variables.sol",
@ -291,7 +297,13 @@
49, 49,
50, 50,
51, 51,
52 52,
53,
54,
55,
56,
57,
58
], ],
"starting_column": 1, "starting_column": 1,
"ending_column": 2 "ending_column": 2
@ -300,10 +312,10 @@
} }
} }
], ],
"description": "MyConc.should_be_constant (tests/detectors/constable-states/0.5.16/const_state_variables.sol#42) should be constant\n", "description": "MyConc.should_be_constant (tests/detectors/constable-states/0.5.16/const_state_variables.sol#42) should be constant \n",
"markdown": "[MyConc.should_be_constant](tests/detectors/constable-states/0.5.16/const_state_variables.sol#L42) should be constant\n", "markdown": "[MyConc.should_be_constant](tests/detectors/constable-states/0.5.16/const_state_variables.sol#L42) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.5.16/const_state_variables.sol#L42", "first_markdown_element": "tests/detectors/constable-states/0.5.16/const_state_variables.sol#L42",
"id": "cbcafa2a3efba4d21ac1b51b4b823e5082d556bc3d6cf3fd2ab3188f9f218fc1", "id": "8d08797efc8230b480ec669c7e2bf53c3b3d16bc59bf7770934b34fd892934f8",
"check": "constable-states", "check": "constable-states",
"impact": "Optimization", "impact": "Optimization",
"confidence": "High" "confidence": "High"
@ -312,16 +324,82 @@
"elements": [ "elements": [
{ {
"type": "variable", "type": "variable",
"name": "text2", "name": "should_be_constant_2",
"source_mapping": { "source_mapping": {
"start": 333, "start": 841,
"length": 33,
"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",
"is_dependency": false,
"lines": [
43
],
"starting_column": 5,
"ending_column": 38
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "MyConc",
"source_mapping": {
"start": 746,
"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",
"is_dependency": false,
"lines": [
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56,
57,
58
],
"starting_column": 1,
"ending_column": 2
}
}
}
}
],
"description": "MyConc.should_be_constant_2 (tests/detectors/constable-states/0.5.16/const_state_variables.sol#43) should be constant \n",
"markdown": "[MyConc.should_be_constant_2](tests/detectors/constable-states/0.5.16/const_state_variables.sol#L43) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.5.16/const_state_variables.sol#L43",
"id": "d08c6d1e331083b42c45c222691dd1e6d880814c66d114971875337ca61ba9c9",
"check": "constable-states",
"impact": "Optimization",
"confidence": "High"
},
{
"elements": [
{
"type": "variable",
"name": "test",
"source_mapping": {
"start": 237,
"length": 20, "length": 20,
"filename_relative": "tests/detectors/constable-states/0.5.16/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.5.16/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.5.16/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.5.16/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
14 10
], ],
"starting_column": 5, "starting_column": 5,
"ending_column": 25 "ending_column": 25
@ -364,10 +442,10 @@
} }
} }
], ],
"description": "A.text2 (tests/detectors/constable-states/0.5.16/const_state_variables.sol#14) should be constant\n", "description": "A.test (tests/detectors/constable-states/0.5.16/const_state_variables.sol#10) should be constant \n",
"markdown": "[A.text2](tests/detectors/constable-states/0.5.16/const_state_variables.sol#L14) should be constant\n", "markdown": "[A.test](tests/detectors/constable-states/0.5.16/const_state_variables.sol#L10) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.5.16/const_state_variables.sol#L14", "first_markdown_element": "tests/detectors/constable-states/0.5.16/const_state_variables.sol#L10",
"id": "df11e6201c4558a8c5cd90b55b134b9ca8f07203b2264d3aa93bd7745e8cb4ba", "id": "e407a1b57b4d25949ef7c4e6d97197605857099a94774a9c7a848d7dd3463668",
"check": "constable-states", "check": "constable-states",
"impact": "Optimization", "impact": "Optimization",
"confidence": "High" "confidence": "High"

@ -1,5 +1,3 @@
//pragma solidity ^0.4.24;
contract A { contract A {
@ -36,17 +34,46 @@ contract B is A {
} }
} }
contract MyConc{ contract Bad {
uint constant A = 1; uint constant A = 1;
bytes32 should_be_constant = sha256('abc'); bytes32 should_be_constant = sha256('abc');
uint should_be_constant_2 = A + 1; uint should_be_constant_2 = A + 1;
address not_constant = msg.sender; B should_be_constant_3 = B(address(0));
uint not_constant_2 = getNumber(); address should_be_immutable = msg.sender;
uint not_constant_3 = 10 + block.number; 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){ function getNumber() public returns(uint){
return block.number; 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,32 +4,34 @@
"elements": [ "elements": [
{ {
"type": "variable", "type": "variable",
"name": "myFriendsAddress", "name": "text2",
"source_mapping": { "source_mapping": {
"start": 132, "start": 305,
"length": 76, "length": 20,
"filename_relative": "tests/detectors/constable-states/0.6.11/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.6.11/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
7 12
], ],
"starting_column": 5, "starting_column": 5,
"ending_column": 81 "ending_column": 25
}, },
"type_specific_fields": { "type_specific_fields": {
"parent": { "parent": {
"type": "contract", "type": "contract",
"name": "A", "name": "A",
"source_mapping": { "source_mapping": {
"start": 29, "start": 1,
"length": 441, "length": 441,
"filename_relative": "tests/detectors/constable-states/0.6.11/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.6.11/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
2,
3,
4, 4,
5, 5,
6, 6,
@ -45,9 +47,7 @@
16, 16,
17, 17,
18, 18,
19, 19
20,
21
], ],
"starting_column": 1, "starting_column": 1,
"ending_column": 2 "ending_column": 2
@ -56,10 +56,10 @@
} }
} }
], ],
"description": "A.myFriendsAddress (tests/detectors/constable-states/0.6.11/const_state_variables.sol#7) should be constant\n", "description": "A.text2 (tests/detectors/constable-states/0.6.11/const_state_variables.sol#12) should be constant \n",
"markdown": "[A.myFriendsAddress](tests/detectors/constable-states/0.6.11/const_state_variables.sol#L7) 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#L7", "first_markdown_element": "tests/detectors/constable-states/0.6.11/const_state_variables.sol#L12",
"id": "1454db80653b732bf6acbe54ff0ae4707002207a2a8216708c12d61c88a43e5f", "id": "2f06e04545cea7e7a8998c65d5419f335bf2579a6ce6a832eac9c87392fd5c1a",
"check": "constable-states", "check": "constable-states",
"impact": "Optimization", "impact": "Optimization",
"confidence": "High" "confidence": "High"
@ -68,50 +68,53 @@
"elements": [ "elements": [
{ {
"type": "variable", "type": "variable",
"name": "test", "name": "should_be_constant_2",
"source_mapping": { "source_mapping": {
"start": 237, "start": 811,
"length": 20, "length": 33,
"filename_relative": "tests/detectors/constable-states/0.6.11/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.6.11/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
10 41
], ],
"starting_column": 5, "starting_column": 5,
"ending_column": 25 "ending_column": 38
}, },
"type_specific_fields": { "type_specific_fields": {
"parent": { "parent": {
"type": "contract", "type": "contract",
"name": "A", "name": "Bad",
"source_mapping": { "source_mapping": {
"start": 29, "start": 718,
"length": 441, "length": 539,
"filename_relative": "tests/detectors/constable-states/0.6.11/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.6.11/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
4, 37,
5, 38,
6, 39,
7, 40,
8, 41,
9, 42,
10, 43,
11, 44,
12, 45,
13, 46,
14, 47,
15, 48,
16, 49,
17, 50,
18, 51,
19, 52,
20, 53,
21 54,
55,
56,
57
], ],
"starting_column": 1, "starting_column": 1,
"ending_column": 2 "ending_column": 2
@ -120,10 +123,10 @@
} }
} }
], ],
"description": "A.test (tests/detectors/constable-states/0.6.11/const_state_variables.sol#10) should be constant\n", "description": "Bad.should_be_constant_2 (tests/detectors/constable-states/0.6.11/const_state_variables.sol#41) should be constant \n",
"markdown": "[A.test](tests/detectors/constable-states/0.6.11/const_state_variables.sol#L10) 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#L10", "first_markdown_element": "tests/detectors/constable-states/0.6.11/const_state_variables.sol#L41",
"id": "5d9e3fb413322b71a93e90f7e89bd8c83cd4884d577d039598c681fe9db38b1d", "id": "3a8b682f7960750cd8228d6cd3d0bb5d7d6f9faaf1a044de2fa7069d8e475af2",
"check": "constable-states", "check": "constable-states",
"impact": "Optimization", "impact": "Optimization",
"confidence": "High" "confidence": "High"
@ -132,46 +135,46 @@
"elements": [ "elements": [
{ {
"type": "variable", "type": "variable",
"name": "should_be_constant_2", "name": "mySistersAddress",
"source_mapping": { "source_mapping": {
"start": 841, "start": 468,
"length": 33, "length": 76,
"filename_relative": "tests/detectors/constable-states/0.6.11/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.6.11/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
43 24
], ],
"starting_column": 5, "starting_column": 5,
"ending_column": 38 "ending_column": 81
}, },
"type_specific_fields": { "type_specific_fields": {
"parent": { "parent": {
"type": "contract", "type": "contract",
"name": "MyConc", "name": "B",
"source_mapping": { "source_mapping": {
"start": 746, "start": 445,
"length": 342, "length": 271,
"filename_relative": "tests/detectors/constable-states/0.6.11/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.6.11/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
39, 22,
40, 23,
41, 24,
42, 25,
43, 26,
44, 27,
45, 28,
46, 29,
47, 30,
48, 31,
49, 32,
50, 33,
51, 34,
52 35
], ],
"starting_column": 1, "starting_column": 1,
"ending_column": 2 "ending_column": 2
@ -180,10 +183,10 @@
} }
} }
], ],
"description": "MyConc.should_be_constant_2 (tests/detectors/constable-states/0.6.11/const_state_variables.sol#43) should be constant\n", "description": "B.mySistersAddress (tests/detectors/constable-states/0.6.11/const_state_variables.sol#24) should be constant \n",
"markdown": "[MyConc.should_be_constant_2](tests/detectors/constable-states/0.6.11/const_state_variables.sol#L43) should be constant\n", "markdown": "[B.mySistersAddress](tests/detectors/constable-states/0.6.11/const_state_variables.sol#L24) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.6.11/const_state_variables.sol#L43", "first_markdown_element": "tests/detectors/constable-states/0.6.11/const_state_variables.sol#L24",
"id": "9a48a4122de1a6a4774a9f1e0d4917bd0fa08f17b4af41b86ba07689e51bf711", "id": "3b5bff93954a48a79387e7981e8c45d78edc575a0988a10f1c7f439b9f930539",
"check": "constable-states", "check": "constable-states",
"impact": "Optimization", "impact": "Optimization",
"confidence": "High" "confidence": "High"
@ -192,16 +195,16 @@
"elements": [ "elements": [
{ {
"type": "variable", "type": "variable",
"name": "mySistersAddress", "name": "myFriendsAddress",
"source_mapping": { "source_mapping": {
"start": 496, "start": 104,
"length": 76, "length": 76,
"filename_relative": "tests/detectors/constable-states/0.6.11/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.6.11/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
26 5
], ],
"starting_column": 5, "starting_column": 5,
"ending_column": 81 "ending_column": 81
@ -209,29 +212,33 @@
"type_specific_fields": { "type_specific_fields": {
"parent": { "parent": {
"type": "contract", "type": "contract",
"name": "B", "name": "A",
"source_mapping": { "source_mapping": {
"start": 473, "start": 1,
"length": 271, "length": 441,
"filename_relative": "tests/detectors/constable-states/0.6.11/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.6.11/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
24, 2,
25, 3,
26, 4,
27, 5,
28, 6,
29, 7,
30, 8,
31, 9,
32, 10,
33, 11,
34, 12,
35, 13,
36, 14,
37 15,
16,
17,
18,
19
], ],
"starting_column": 1, "starting_column": 1,
"ending_column": 2 "ending_column": 2
@ -240,10 +247,10 @@
} }
} }
], ],
"description": "B.mySistersAddress (tests/detectors/constable-states/0.6.11/const_state_variables.sol#26) should be constant\n", "description": "A.myFriendsAddress (tests/detectors/constable-states/0.6.11/const_state_variables.sol#5) should be constant \n",
"markdown": "[B.mySistersAddress](tests/detectors/constable-states/0.6.11/const_state_variables.sol#L26) should be constant\n", "markdown": "[A.myFriendsAddress](tests/detectors/constable-states/0.6.11/const_state_variables.sol#L5) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.6.11/const_state_variables.sol#L26", "first_markdown_element": "tests/detectors/constable-states/0.6.11/const_state_variables.sol#L5",
"id": "bee93a722c8eae4a48aade67d8ef537d84c106f48fc9eb738c795fce10d3bc63", "id": "52fd72f6870c4b504d1bcf9fb44249658e2077474d66208a33a47d2668b8db49",
"check": "constable-states", "check": "constable-states",
"impact": "Optimization", "impact": "Optimization",
"confidence": "High" "confidence": "High"
@ -254,14 +261,14 @@
"type": "variable", "type": "variable",
"name": "should_be_constant", "name": "should_be_constant",
"source_mapping": { "source_mapping": {
"start": 793, "start": 763,
"length": 42, "length": 42,
"filename_relative": "tests/detectors/constable-states/0.6.11/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.6.11/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
42 40
], ],
"starting_column": 5, "starting_column": 5,
"ending_column": 47 "ending_column": 47
@ -269,15 +276,84 @@
"type_specific_fields": { "type_specific_fields": {
"parent": { "parent": {
"type": "contract", "type": "contract",
"name": "MyConc", "name": "Bad",
"source_mapping": {
"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": [
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
}
}
}
}
],
"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": "87097c03d57b72ad7c15336eb44e5a30054c50f8daff32e08bc4fbd97852961c",
"check": "constable-states",
"impact": "Optimization",
"confidence": "High"
},
{
"elements": [
{
"type": "variable",
"name": "should_be_constant_3",
"source_mapping": {
"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": [
42
],
"starting_column": 5,
"ending_column": 43
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "Bad",
"source_mapping": { "source_mapping": {
"start": 746, "start": 718,
"length": 342, "length": 539,
"filename_relative": "tests/detectors/constable-states/0.6.11/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.6.11/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
37,
38,
39, 39,
40, 40,
41, 41,
@ -291,7 +367,12 @@
49, 49,
50, 50,
51, 51,
52 52,
53,
54,
55,
56,
57
], ],
"starting_column": 1, "starting_column": 1,
"ending_column": 2 "ending_column": 2
@ -300,10 +381,10 @@
} }
} }
], ],
"description": "MyConc.should_be_constant (tests/detectors/constable-states/0.6.11/const_state_variables.sol#42) should be constant\n", "description": "Bad.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](tests/detectors/constable-states/0.6.11/const_state_variables.sol#L42) 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", "first_markdown_element": "tests/detectors/constable-states/0.6.11/const_state_variables.sol#L42",
"id": "cbcafa2a3efba4d21ac1b51b4b823e5082d556bc3d6cf3fd2ab3188f9f218fc1", "id": "8e991c1370b1adb10f01f2d7e48f341dee92a98b91b56ccb291d9149d2da97d0",
"check": "constable-states", "check": "constable-states",
"impact": "Optimization", "impact": "Optimization",
"confidence": "High" "confidence": "High"
@ -312,16 +393,16 @@
"elements": [ "elements": [
{ {
"type": "variable", "type": "variable",
"name": "text2", "name": "test",
"source_mapping": { "source_mapping": {
"start": 333, "start": 209,
"length": 20, "length": 20,
"filename_relative": "tests/detectors/constable-states/0.6.11/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.6.11/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
14 8
], ],
"starting_column": 5, "starting_column": 5,
"ending_column": 25 "ending_column": 25
@ -331,13 +412,15 @@
"type": "contract", "type": "contract",
"name": "A", "name": "A",
"source_mapping": { "source_mapping": {
"start": 29, "start": 1,
"length": 441, "length": 441,
"filename_relative": "tests/detectors/constable-states/0.6.11/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.6.11/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.6.11/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
2,
3,
4, 4,
5, 5,
6, 6,
@ -353,9 +436,7 @@
16, 16,
17, 17,
18, 18,
19, 19
20,
21
], ],
"starting_column": 1, "starting_column": 1,
"ending_column": 2 "ending_column": 2
@ -364,10 +445,10 @@
} }
} }
], ],
"description": "A.text2 (tests/detectors/constable-states/0.6.11/const_state_variables.sol#14) should be constant\n", "description": "A.test (tests/detectors/constable-states/0.6.11/const_state_variables.sol#8) should be constant \n",
"markdown": "[A.text2](tests/detectors/constable-states/0.6.11/const_state_variables.sol#L14) should be constant\n", "markdown": "[A.test](tests/detectors/constable-states/0.6.11/const_state_variables.sol#L8) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.6.11/const_state_variables.sol#L14", "first_markdown_element": "tests/detectors/constable-states/0.6.11/const_state_variables.sol#L8",
"id": "df11e6201c4558a8c5cd90b55b134b9ca8f07203b2264d3aa93bd7745e8cb4ba", "id": "e407a1b57b4d25949ef7c4e6d97197605857099a94774a9c7a848d7dd3463668",
"check": "constable-states", "check": "constable-states",
"impact": "Optimization", "impact": "Optimization",
"confidence": "High" "confidence": "High"

@ -1,5 +1,3 @@
//pragma solidity ^0.4.24;
contract A { contract A {
@ -36,15 +34,43 @@ contract B is A {
} }
} }
contract MyConc{ contract Bad {
uint constant A = 1; uint constant A = 1;
bytes32 should_be_constant = sha256('abc'); bytes32 should_be_constant = sha256('abc');
uint should_be_constant_2 = A + 1; uint should_be_constant_2 = A + 1;
address not_constant = msg.sender; B should_be_constant_3 = B(address(0));
uint not_constant_2 = getNumber(); address should_be_immutable = msg.sender;
uint not_constant_3 = 10 + block.number; 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){ function getNumber() public returns(uint){
return block.number; return block.number;
} }

@ -4,32 +4,34 @@
"elements": [ "elements": [
{ {
"type": "variable", "type": "variable",
"name": "myFriendsAddress", "name": "text2",
"source_mapping": { "source_mapping": {
"start": 132, "start": 305,
"length": 76, "length": 20,
"filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
7 12
], ],
"starting_column": 5, "starting_column": 5,
"ending_column": 81 "ending_column": 25
}, },
"type_specific_fields": { "type_specific_fields": {
"parent": { "parent": {
"type": "contract", "type": "contract",
"name": "A", "name": "A",
"source_mapping": { "source_mapping": {
"start": 29, "start": 1,
"length": 441, "length": 441,
"filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
2,
3,
4, 4,
5, 5,
6, 6,
@ -45,9 +47,7 @@
16, 16,
17, 17,
18, 18,
19, 19
20,
21
], ],
"starting_column": 1, "starting_column": 1,
"ending_column": 2 "ending_column": 2
@ -56,10 +56,10 @@
} }
} }
], ],
"description": "A.myFriendsAddress (tests/detectors/constable-states/0.7.6/const_state_variables.sol#7) should be constant\n", "description": "A.text2 (tests/detectors/constable-states/0.7.6/const_state_variables.sol#12) should be constant \n",
"markdown": "[A.myFriendsAddress](tests/detectors/constable-states/0.7.6/const_state_variables.sol#L7) should be constant\n", "markdown": "[A.text2](tests/detectors/constable-states/0.7.6/const_state_variables.sol#L12) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.7.6/const_state_variables.sol#L7", "first_markdown_element": "tests/detectors/constable-states/0.7.6/const_state_variables.sol#L12",
"id": "1454db80653b732bf6acbe54ff0ae4707002207a2a8216708c12d61c88a43e5f", "id": "2f06e04545cea7e7a8998c65d5419f335bf2579a6ce6a832eac9c87392fd5c1a",
"check": "constable-states", "check": "constable-states",
"impact": "Optimization", "impact": "Optimization",
"confidence": "High" "confidence": "High"
@ -68,50 +68,52 @@
"elements": [ "elements": [
{ {
"type": "variable", "type": "variable",
"name": "test", "name": "should_be_constant_2",
"source_mapping": { "source_mapping": {
"start": 237, "start": 811,
"length": 20, "length": 33,
"filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
10 41
], ],
"starting_column": 5, "starting_column": 5,
"ending_column": 25 "ending_column": 38
}, },
"type_specific_fields": { "type_specific_fields": {
"parent": { "parent": {
"type": "contract", "type": "contract",
"name": "A", "name": "Bad",
"source_mapping": { "source_mapping": {
"start": 29, "start": 718,
"length": 441, "length": 531,
"filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
4, 37,
5, 38,
6, 39,
7, 40,
8, 41,
9, 42,
10, 43,
11, 44,
12, 45,
13, 46,
14, 47,
15, 48,
16, 49,
17, 50,
18, 51,
19, 52,
20, 53,
21 54,
55,
56
], ],
"starting_column": 1, "starting_column": 1,
"ending_column": 2 "ending_column": 2
@ -120,10 +122,10 @@
} }
} }
], ],
"description": "A.test (tests/detectors/constable-states/0.7.6/const_state_variables.sol#10) should be constant\n", "description": "Bad.should_be_constant_2 (tests/detectors/constable-states/0.7.6/const_state_variables.sol#41) should be constant \n",
"markdown": "[A.test](tests/detectors/constable-states/0.7.6/const_state_variables.sol#L10) 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#L10", "first_markdown_element": "tests/detectors/constable-states/0.7.6/const_state_variables.sol#L41",
"id": "5d9e3fb413322b71a93e90f7e89bd8c83cd4884d577d039598c681fe9db38b1d", "id": "3a8b682f7960750cd8228d6cd3d0bb5d7d6f9faaf1a044de2fa7069d8e475af2",
"check": "constable-states", "check": "constable-states",
"impact": "Optimization", "impact": "Optimization",
"confidence": "High" "confidence": "High"
@ -132,46 +134,46 @@
"elements": [ "elements": [
{ {
"type": "variable", "type": "variable",
"name": "should_be_constant_2", "name": "mySistersAddress",
"source_mapping": { "source_mapping": {
"start": 841, "start": 468,
"length": 33, "length": 76,
"filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
43 24
], ],
"starting_column": 5, "starting_column": 5,
"ending_column": 38 "ending_column": 81
}, },
"type_specific_fields": { "type_specific_fields": {
"parent": { "parent": {
"type": "contract", "type": "contract",
"name": "MyConc", "name": "B",
"source_mapping": { "source_mapping": {
"start": 746, "start": 445,
"length": 342, "length": 271,
"filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
39, 22,
40, 23,
41, 24,
42, 25,
43, 26,
44, 27,
45, 28,
46, 29,
47, 30,
48, 31,
49, 32,
50, 33,
51, 34,
52 35
], ],
"starting_column": 1, "starting_column": 1,
"ending_column": 2 "ending_column": 2
@ -180,10 +182,10 @@
} }
} }
], ],
"description": "MyConc.should_be_constant_2 (tests/detectors/constable-states/0.7.6/const_state_variables.sol#43) should be constant\n", "description": "B.mySistersAddress (tests/detectors/constable-states/0.7.6/const_state_variables.sol#24) should be constant \n",
"markdown": "[MyConc.should_be_constant_2](tests/detectors/constable-states/0.7.6/const_state_variables.sol#L43) 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#L43", "first_markdown_element": "tests/detectors/constable-states/0.7.6/const_state_variables.sol#L24",
"id": "9a48a4122de1a6a4774a9f1e0d4917bd0fa08f17b4af41b86ba07689e51bf711", "id": "3b5bff93954a48a79387e7981e8c45d78edc575a0988a10f1c7f439b9f930539",
"check": "constable-states", "check": "constable-states",
"impact": "Optimization", "impact": "Optimization",
"confidence": "High" "confidence": "High"
@ -192,16 +194,16 @@
"elements": [ "elements": [
{ {
"type": "variable", "type": "variable",
"name": "mySistersAddress", "name": "myFriendsAddress",
"source_mapping": { "source_mapping": {
"start": 496, "start": 104,
"length": 76, "length": 76,
"filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
26 5
], ],
"starting_column": 5, "starting_column": 5,
"ending_column": 81 "ending_column": 81
@ -209,29 +211,33 @@
"type_specific_fields": { "type_specific_fields": {
"parent": { "parent": {
"type": "contract", "type": "contract",
"name": "B", "name": "A",
"source_mapping": { "source_mapping": {
"start": 473, "start": 1,
"length": 271, "length": 441,
"filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
24, 2,
25, 3,
26, 4,
27, 5,
28, 6,
29, 7,
30, 8,
31, 9,
32, 10,
33, 11,
34, 12,
35, 13,
36, 14,
37 15,
16,
17,
18,
19
], ],
"starting_column": 1, "starting_column": 1,
"ending_column": 2 "ending_column": 2
@ -240,10 +246,10 @@
} }
} }
], ],
"description": "B.mySistersAddress (tests/detectors/constable-states/0.7.6/const_state_variables.sol#26) should be constant\n", "description": "A.myFriendsAddress (tests/detectors/constable-states/0.7.6/const_state_variables.sol#5) should be constant \n",
"markdown": "[B.mySistersAddress](tests/detectors/constable-states/0.7.6/const_state_variables.sol#L26) should be constant\n", "markdown": "[A.myFriendsAddress](tests/detectors/constable-states/0.7.6/const_state_variables.sol#L5) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.7.6/const_state_variables.sol#L26", "first_markdown_element": "tests/detectors/constable-states/0.7.6/const_state_variables.sol#L5",
"id": "bee93a722c8eae4a48aade67d8ef537d84c106f48fc9eb738c795fce10d3bc63", "id": "52fd72f6870c4b504d1bcf9fb44249658e2077474d66208a33a47d2668b8db49",
"check": "constable-states", "check": "constable-states",
"impact": "Optimization", "impact": "Optimization",
"confidence": "High" "confidence": "High"
@ -254,14 +260,14 @@
"type": "variable", "type": "variable",
"name": "should_be_constant", "name": "should_be_constant",
"source_mapping": { "source_mapping": {
"start": 793, "start": 763,
"length": 42, "length": 42,
"filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
42 40
], ],
"starting_column": 5, "starting_column": 5,
"ending_column": 47 "ending_column": 47
@ -269,15 +275,83 @@
"type_specific_fields": { "type_specific_fields": {
"parent": { "parent": {
"type": "contract", "type": "contract",
"name": "MyConc", "name": "Bad",
"source_mapping": {
"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": [
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_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": "87097c03d57b72ad7c15336eb44e5a30054c50f8daff32e08bc4fbd97852961c",
"check": "constable-states",
"impact": "Optimization",
"confidence": "High"
},
{
"elements": [
{
"type": "variable",
"name": "should_be_constant_3",
"source_mapping": {
"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": [
42
],
"starting_column": 5,
"ending_column": 43
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "Bad",
"source_mapping": { "source_mapping": {
"start": 746, "start": 718,
"length": 342, "length": 531,
"filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
37,
38,
39, 39,
40, 40,
41, 41,
@ -291,7 +365,11 @@
49, 49,
50, 50,
51, 51,
52 52,
53,
54,
55,
56
], ],
"starting_column": 1, "starting_column": 1,
"ending_column": 2 "ending_column": 2
@ -300,10 +378,10 @@
} }
} }
], ],
"description": "MyConc.should_be_constant (tests/detectors/constable-states/0.7.6/const_state_variables.sol#42) should be constant\n", "description": "Bad.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](tests/detectors/constable-states/0.7.6/const_state_variables.sol#L42) 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", "first_markdown_element": "tests/detectors/constable-states/0.7.6/const_state_variables.sol#L42",
"id": "cbcafa2a3efba4d21ac1b51b4b823e5082d556bc3d6cf3fd2ab3188f9f218fc1", "id": "8e991c1370b1adb10f01f2d7e48f341dee92a98b91b56ccb291d9149d2da97d0",
"check": "constable-states", "check": "constable-states",
"impact": "Optimization", "impact": "Optimization",
"confidence": "High" "confidence": "High"
@ -312,16 +390,16 @@
"elements": [ "elements": [
{ {
"type": "variable", "type": "variable",
"name": "text2", "name": "test",
"source_mapping": { "source_mapping": {
"start": 333, "start": 209,
"length": 20, "length": 20,
"filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
14 8
], ],
"starting_column": 5, "starting_column": 5,
"ending_column": 25 "ending_column": 25
@ -331,13 +409,15 @@
"type": "contract", "type": "contract",
"name": "A", "name": "A",
"source_mapping": { "source_mapping": {
"start": 29, "start": 1,
"length": 441, "length": 441,
"filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol", "filename_relative": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol", "filename_short": "tests/detectors/constable-states/0.7.6/const_state_variables.sol",
"is_dependency": false, "is_dependency": false,
"lines": [ "lines": [
2,
3,
4, 4,
5, 5,
6, 6,
@ -353,9 +433,7 @@
16, 16,
17, 17,
18, 18,
19, 19
20,
21
], ],
"starting_column": 1, "starting_column": 1,
"ending_column": 2 "ending_column": 2
@ -364,10 +442,10 @@
} }
} }
], ],
"description": "A.text2 (tests/detectors/constable-states/0.7.6/const_state_variables.sol#14) should be constant\n", "description": "A.test (tests/detectors/constable-states/0.7.6/const_state_variables.sol#8) should be constant \n",
"markdown": "[A.text2](tests/detectors/constable-states/0.7.6/const_state_variables.sol#L14) should be constant\n", "markdown": "[A.test](tests/detectors/constable-states/0.7.6/const_state_variables.sol#L8) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.7.6/const_state_variables.sol#L14", "first_markdown_element": "tests/detectors/constable-states/0.7.6/const_state_variables.sol#L8",
"id": "df11e6201c4558a8c5cd90b55b134b9ca8f07203b2264d3aa93bd7745e8cb4ba", "id": "e407a1b57b4d25949ef7c4e6d97197605857099a94774a9c7a848d7dd3463668",
"check": "constable-states", "check": "constable-states",
"impact": "Optimization", "impact": "Optimization",
"confidence": "High" "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,454 @@
[
[
{
"elements": [
{
"type": "variable",
"name": "text2",
"source_mapping": {
"start": 305,
"length": 20,
"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": [
12
],
"starting_column": 5,
"ending_column": 25
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "A",
"source_mapping": {
"start": 1,
"length": 441,
"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": [
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19
],
"starting_column": 1,
"ending_column": 2
}
}
}
}
],
"description": "A.text2 (tests/detectors/constable-states/0.8.0/const_state_variables.sol#12) should be constant \n",
"markdown": "[A.text2](tests/detectors/constable-states/0.8.0/const_state_variables.sol#L12) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.8.0/const_state_variables.sol#L12",
"id": "2f06e04545cea7e7a8998c65d5419f335bf2579a6ce6a832eac9c87392fd5c1a",
"check": "constable-states",
"impact": "Optimization",
"confidence": "High"
},
{
"elements": [
{
"type": "variable",
"name": "should_be_constant_2",
"source_mapping": {
"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": [
41
],
"starting_column": 5,
"ending_column": 38
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "Bad",
"source_mapping": {
"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": [
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_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"
},
{
"elements": [
{
"type": "variable",
"name": "mySistersAddress",
"source_mapping": {
"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": [
24
],
"starting_column": 5,
"ending_column": 81
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "B",
"source_mapping": {
"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": [
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35
],
"starting_column": 1,
"ending_column": 2
}
}
}
}
],
"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"
},
{
"elements": [
{
"type": "variable",
"name": "myFriendsAddress",
"source_mapping": {
"start": 104,
"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": [
5
],
"starting_column": 5,
"ending_column": 81
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "A",
"source_mapping": {
"start": 1,
"length": 441,
"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": [
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19
],
"starting_column": 1,
"ending_column": 2
}
}
}
}
],
"description": "A.myFriendsAddress (tests/detectors/constable-states/0.8.0/const_state_variables.sol#5) should be constant \n",
"markdown": "[A.myFriendsAddress](tests/detectors/constable-states/0.8.0/const_state_variables.sol#L5) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.8.0/const_state_variables.sol#L5",
"id": "52fd72f6870c4b504d1bcf9fb44249658e2077474d66208a33a47d2668b8db49",
"check": "constable-states",
"impact": "Optimization",
"confidence": "High"
},
{
"elements": [
{
"type": "variable",
"name": "should_be_constant",
"source_mapping": {
"start": 763,
"length": 42,
"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": [
40
],
"starting_column": 5,
"ending_column": 47
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "Bad",
"source_mapping": {
"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": [
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_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": "87097c03d57b72ad7c15336eb44e5a30054c50f8daff32e08bc4fbd97852961c",
"check": "constable-states",
"impact": "Optimization",
"confidence": "High"
},
{
"elements": [
{
"type": "variable",
"name": "should_be_constant_3",
"source_mapping": {
"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": [
42
],
"starting_column": 5,
"ending_column": 43
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "Bad",
"source_mapping": {
"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": [
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_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"
},
{
"elements": [
{
"type": "variable",
"name": "test",
"source_mapping": {
"start": 209,
"length": 20,
"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": [
8
],
"starting_column": 5,
"ending_column": 25
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "A",
"source_mapping": {
"start": 1,
"length": 441,
"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": [
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19
],
"starting_column": 1,
"ending_column": 2
}
}
}
}
],
"description": "A.test (tests/detectors/constable-states/0.8.0/const_state_variables.sol#8) should be constant \n",
"markdown": "[A.test](tests/detectors/constable-states/0.8.0/const_state_variables.sol#L8) should be constant \n",
"first_markdown_element": "tests/detectors/constable-states/0.8.0/const_state_variables.sol#L8",
"id": "e407a1b57b4d25949ef7c4e6d97197605857099a94774a9c7a848d7dd3463668",
"check": "constable-states",
"impact": "Optimization",
"confidence": "High"
}
]
]

@ -1,7 +0,0 @@
contract C{
uint immutable v;
constructor() public{
v = 0;
}
}

@ -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,339 @@
[
[
{
"elements": [
{
"type": "variable",
"name": "should_be_immutable_5",
"source_mapping": {
"start": 1077,
"length": 26,
"filename_relative": "tests/detectors/immutable-states/0.6.11/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.6.11/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": 539,
"filename_relative": "tests/detectors/immutable-states/0.6.11/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.6.11/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,
57
],
"starting_column": 1,
"ending_column": 2
}
}
}
}
],
"description": "Bad.should_be_immutable_5 (tests/detectors/immutable-states/0.6.11/immut_state_variables.sol#47) should be immutable \n",
"markdown": "[Bad.should_be_immutable_5](tests/detectors/immutable-states/0.6.11/immut_state_variables.sol#L47) should be immutable \n",
"first_markdown_element": "tests/detectors/immutable-states/0.6.11/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.6.11/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.6.11/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": 539,
"filename_relative": "tests/detectors/immutable-states/0.6.11/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.6.11/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,
57
],
"starting_column": 1,
"ending_column": 2
}
}
}
}
],
"description": "Bad.should_be_immutable_2 (tests/detectors/immutable-states/0.6.11/immut_state_variables.sol#44) should be immutable \n",
"markdown": "[Bad.should_be_immutable_2](tests/detectors/immutable-states/0.6.11/immut_state_variables.sol#L44) should be immutable \n",
"first_markdown_element": "tests/detectors/immutable-states/0.6.11/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.6.11/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.6.11/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": 539,
"filename_relative": "tests/detectors/immutable-states/0.6.11/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.6.11/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,
57
],
"starting_column": 1,
"ending_column": 2
}
}
}
}
],
"description": "Bad.should_be_immutable_4 (tests/detectors/immutable-states/0.6.11/immut_state_variables.sol#46) should be immutable \n",
"markdown": "[Bad.should_be_immutable_4](tests/detectors/immutable-states/0.6.11/immut_state_variables.sol#L46) should be immutable \n",
"first_markdown_element": "tests/detectors/immutable-states/0.6.11/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.6.11/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.6.11/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": 539,
"filename_relative": "tests/detectors/immutable-states/0.6.11/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.6.11/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,
57
],
"starting_column": 1,
"ending_column": 2
}
}
}
}
],
"description": "Bad.should_be_immutable (tests/detectors/immutable-states/0.6.11/immut_state_variables.sol#43) should be immutable \n",
"markdown": "[Bad.should_be_immutable](tests/detectors/immutable-states/0.6.11/immut_state_variables.sol#L43) should be immutable \n",
"first_markdown_element": "tests/detectors/immutable-states/0.6.11/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.6.11/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.6.11/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": 539,
"filename_relative": "tests/detectors/immutable-states/0.6.11/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.6.11/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,
57
],
"starting_column": 1,
"ending_column": 2
}
}
}
}
],
"description": "Bad.should_be_immutable_3 (tests/detectors/immutable-states/0.6.11/immut_state_variables.sol#45) should be immutable \n",
"markdown": "[Bad.should_be_immutable_3](tests/detectors/immutable-states/0.6.11/immut_state_variables.sol#L45) should be immutable \n",
"first_markdown_element": "tests/detectors/immutable-states/0.6.11/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;
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,28 +480,53 @@ ALL_TEST_OBJECTS = [
"0.7.6", "0.7.6",
), ),
Test( Test(
all_detectors.ConstCandidateStateVars, all_detectors.CouldBeConstant,
"const_state_variables.sol", "const_state_variables.sol",
"0.4.25", "0.4.25",
), ),
Test( Test(
all_detectors.ConstCandidateStateVars, all_detectors.CouldBeConstant,
"const_state_variables.sol", "const_state_variables.sol",
"0.5.16", "0.5.16",
), ),
Test( Test(
all_detectors.ConstCandidateStateVars, all_detectors.CouldBeConstant,
"const_state_variables.sol", "const_state_variables.sol",
"0.6.11", "0.6.11",
), ),
Test( Test(
all_detectors.ConstCandidateStateVars, all_detectors.CouldBeConstant,
"const_state_variables.sol", "const_state_variables.sol",
"0.7.6", "0.7.6",
), ),
Test( Test(
all_detectors.ConstCandidateStateVars, all_detectors.CouldBeConstant,
"immutable.sol", "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", "0.8.0",
), ),
Test( Test(

Loading…
Cancel
Save