do not consider string types as immut cand.

pull/1639/head
alpharush 2 years ago
parent 2caf510909
commit 21a0ba882e
  1. 7
      slither/detectors/variables/unchanged_state_variables.py
  2. 4
      tests/detectors/immutable-states/0.4.25/immut_state_variables.sol
  3. 4
      tests/detectors/immutable-states/0.5.16/immut_state_variables.sol
  4. 4
      tests/detectors/immutable-states/0.6.11/immut_state_variables.sol
  5. 4
      tests/detectors/immutable-states/0.7.6/immut_state_variables.sol
  6. 4
      tests/detectors/immutable-states/0.8.0/immut_state_variables.sol
  7. 24
      tests/detectors/immutable-states/0.8.0/immut_state_variables.sol.0.8.0.CouldBeImmutable.json

@ -118,8 +118,9 @@ class UnchangedStateVariables:
self.constant_candidates.append(v) self.constant_candidates.append(v)
elif ( elif (
v in constructor_variables_written or v in variables_initialized v.type != ElementaryType("string")
) and version.parse(self.compilation_unit.solc_version) >= version.parse( and version.parse(self.compilation_unit.solc_version)
"0.6.5" >= version.parse("0.6.5")
and (v in constructor_variables_written or v in variables_initialized)
): ):
self.immutable_candidates.append(v) self.immutable_candidates.append(v)

@ -45,9 +45,11 @@ contract MyConc{
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; uint not_constant_5;
string cannote_be_immutable;
constructor(uint b) public { constructor(uint b, string memory c) public {
not_constant_5 = b; not_constant_5 = b;
cannote_be_immutable = c;
} }
function getNumber() public returns(uint){ function getNumber() public returns(uint){

@ -46,9 +46,11 @@ contract MyConc{
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; uint not_constant_5;
string cannote_be_immutable;
constructor(uint b) public { constructor(uint b, string memory c) public {
not_constant_5 = b; not_constant_5 = b;
cannote_be_immutable = c;
} }
function getNumber() public returns(uint){ function getNumber() public returns(uint){

@ -67,9 +67,11 @@ contract Good {
uint immutable should_be_immutable_3 = 10 + block.number; uint immutable should_be_immutable_3 = 10 + block.number;
B immutable should_be_immutable_4 = new B(); B immutable should_be_immutable_4 = new B();
uint immutable should_be_immutable_5; uint immutable should_be_immutable_5;
string cannote_be_immutable;
constructor(uint b) public { constructor(uint b, string memory c) public {
should_be_immutable_5 = b; should_be_immutable_5 = b;
cannote_be_immutable = c;
} }
function getNumber() public returns(uint){ function getNumber() public returns(uint){

@ -66,9 +66,11 @@ contract Good {
uint immutable should_be_immutable_3 = 10 + block.number; uint immutable should_be_immutable_3 = 10 + block.number;
B immutable should_be_immutable_4 = new B(); B immutable should_be_immutable_4 = new B();
uint immutable should_be_immutable_5; uint immutable should_be_immutable_5;
string cannote_be_immutable;
constructor(uint b) { constructor(uint b, string memory c) {
should_be_immutable_5 = b; should_be_immutable_5 = b;
cannote_be_immutable = c;
} }
function getNumber() public returns(uint){ function getNumber() public returns(uint){

@ -44,9 +44,11 @@ contract Bad {
uint should_be_immutable_2 = getNumber(); uint should_be_immutable_2 = getNumber();
uint should_be_immutable_3 = 10 + block.number; uint should_be_immutable_3 = 10 + block.number;
uint should_be_immutable_5; uint should_be_immutable_5;
string cannote_be_immutable;
constructor(uint b) { constructor(uint b, string memory c) {
should_be_immutable_5 = b; should_be_immutable_5 = b;
cannote_be_immutable = c;
} }
function getNumber() public returns(uint){ function getNumber() public returns(uint){

@ -24,7 +24,7 @@
"name": "Bad", "name": "Bad",
"source_mapping": { "source_mapping": {
"start": 718, "start": 718,
"length": 493, "length": 577,
"filename_relative": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol", "filename_relative": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol", "filename_short": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
@ -49,7 +49,9 @@
53, 53,
54, 54,
55, 55,
56 56,
57,
58
], ],
"starting_column": 1, "starting_column": 1,
"ending_column": 2 "ending_column": 2
@ -90,7 +92,7 @@
"name": "Bad", "name": "Bad",
"source_mapping": { "source_mapping": {
"start": 718, "start": 718,
"length": 493, "length": 577,
"filename_relative": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol", "filename_relative": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol", "filename_short": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
@ -115,7 +117,9 @@
53, 53,
54, 54,
55, 55,
56 56,
57,
58
], ],
"starting_column": 1, "starting_column": 1,
"ending_column": 2 "ending_column": 2
@ -156,7 +160,7 @@
"name": "Bad", "name": "Bad",
"source_mapping": { "source_mapping": {
"start": 718, "start": 718,
"length": 493, "length": 577,
"filename_relative": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol", "filename_relative": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol", "filename_short": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
@ -181,7 +185,9 @@
53, 53,
54, 54,
55, 55,
56 56,
57,
58
], ],
"starting_column": 1, "starting_column": 1,
"ending_column": 2 "ending_column": 2
@ -222,7 +228,7 @@
"name": "Bad", "name": "Bad",
"source_mapping": { "source_mapping": {
"start": 718, "start": 718,
"length": 493, "length": 577,
"filename_relative": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol", "filename_relative": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH", "filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol", "filename_short": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
@ -247,7 +253,9 @@
53, 53,
54, 54,
55, 55,
56 56,
57,
58
], ],
"starting_column": 1, "starting_column": 1,
"ending_column": 2 "ending_column": 2

Loading…
Cancel
Save