From 21a0ba882ee48a5142ce47921a430d02a9d714e3 Mon Sep 17 00:00:00 2001 From: alpharush <0xalpharush@protonmail.com> Date: Tue, 31 Jan 2023 18:17:01 -0600 Subject: [PATCH] do not consider string types as immut cand. --- .../variables/unchanged_state_variables.py | 7 +++--- .../0.4.25/immut_state_variables.sol | 4 +++- .../0.5.16/immut_state_variables.sol | 4 +++- .../0.6.11/immut_state_variables.sol | 4 +++- .../0.7.6/immut_state_variables.sol | 4 +++- .../0.8.0/immut_state_variables.sol | 4 +++- ..._variables.sol.0.8.0.CouldBeImmutable.json | 24 ++++++++++++------- 7 files changed, 35 insertions(+), 16 deletions(-) diff --git a/slither/detectors/variables/unchanged_state_variables.py b/slither/detectors/variables/unchanged_state_variables.py index 0dccb6d1c..3f88bf7d2 100644 --- a/slither/detectors/variables/unchanged_state_variables.py +++ b/slither/detectors/variables/unchanged_state_variables.py @@ -118,8 +118,9 @@ class UnchangedStateVariables: 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" + v.type != ElementaryType("string") + and version.parse(self.compilation_unit.solc_version) + >= version.parse("0.6.5") + and (v in constructor_variables_written or v in variables_initialized) ): self.immutable_candidates.append(v) diff --git a/tests/detectors/immutable-states/0.4.25/immut_state_variables.sol b/tests/detectors/immutable-states/0.4.25/immut_state_variables.sol index 45f8cc87a..db7f15a44 100644 --- a/tests/detectors/immutable-states/0.4.25/immut_state_variables.sol +++ b/tests/detectors/immutable-states/0.4.25/immut_state_variables.sol @@ -45,9 +45,11 @@ contract MyConc{ uint not_constant_2 = getNumber(); uint not_constant_3 = 10 + block.number; uint not_constant_5; + string cannote_be_immutable; - constructor(uint b) public { + constructor(uint b, string memory c) public { not_constant_5 = b; + cannote_be_immutable = c; } function getNumber() public returns(uint){ diff --git a/tests/detectors/immutable-states/0.5.16/immut_state_variables.sol b/tests/detectors/immutable-states/0.5.16/immut_state_variables.sol index 8fd1ca808..138f007b7 100644 --- a/tests/detectors/immutable-states/0.5.16/immut_state_variables.sol +++ b/tests/detectors/immutable-states/0.5.16/immut_state_variables.sol @@ -46,9 +46,11 @@ contract MyConc{ uint not_constant_2 = getNumber(); uint not_constant_3 = 10 + block.number; uint not_constant_5; + string cannote_be_immutable; - constructor(uint b) public { + constructor(uint b, string memory c) public { not_constant_5 = b; + cannote_be_immutable = c; } function getNumber() public returns(uint){ diff --git a/tests/detectors/immutable-states/0.6.11/immut_state_variables.sol b/tests/detectors/immutable-states/0.6.11/immut_state_variables.sol index 17548f46f..104596290 100644 --- a/tests/detectors/immutable-states/0.6.11/immut_state_variables.sol +++ b/tests/detectors/immutable-states/0.6.11/immut_state_variables.sol @@ -67,9 +67,11 @@ contract Good { uint immutable should_be_immutable_3 = 10 + block.number; B immutable should_be_immutable_4 = new B(); 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; + cannote_be_immutable = c; } function getNumber() public returns(uint){ diff --git a/tests/detectors/immutable-states/0.7.6/immut_state_variables.sol b/tests/detectors/immutable-states/0.7.6/immut_state_variables.sol index 297dd6294..8b8e6ae95 100644 --- a/tests/detectors/immutable-states/0.7.6/immut_state_variables.sol +++ b/tests/detectors/immutable-states/0.7.6/immut_state_variables.sol @@ -66,9 +66,11 @@ contract Good { uint immutable should_be_immutable_3 = 10 + block.number; B immutable should_be_immutable_4 = new B(); uint immutable should_be_immutable_5; + string cannote_be_immutable; - constructor(uint b) { + constructor(uint b, string memory c) { should_be_immutable_5 = b; + cannote_be_immutable = c; } function getNumber() public returns(uint){ diff --git a/tests/detectors/immutable-states/0.8.0/immut_state_variables.sol b/tests/detectors/immutable-states/0.8.0/immut_state_variables.sol index f405a1587..943b06ec3 100644 --- a/tests/detectors/immutable-states/0.8.0/immut_state_variables.sol +++ b/tests/detectors/immutable-states/0.8.0/immut_state_variables.sol @@ -44,9 +44,11 @@ contract Bad { uint should_be_immutable_2 = getNumber(); uint should_be_immutable_3 = 10 + block.number; uint should_be_immutable_5; + string cannote_be_immutable; - constructor(uint b) { + constructor(uint b, string memory c) { should_be_immutable_5 = b; + cannote_be_immutable = c; } function getNumber() public returns(uint){ diff --git a/tests/detectors/immutable-states/0.8.0/immut_state_variables.sol.0.8.0.CouldBeImmutable.json b/tests/detectors/immutable-states/0.8.0/immut_state_variables.sol.0.8.0.CouldBeImmutable.json index afa2e3bb2..58d26f9bc 100644 --- a/tests/detectors/immutable-states/0.8.0/immut_state_variables.sol.0.8.0.CouldBeImmutable.json +++ b/tests/detectors/immutable-states/0.8.0/immut_state_variables.sol.0.8.0.CouldBeImmutable.json @@ -24,7 +24,7 @@ "name": "Bad", "source_mapping": { "start": 718, - "length": 493, + "length": 577, "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", @@ -49,7 +49,9 @@ 53, 54, 55, - 56 + 56, + 57, + 58 ], "starting_column": 1, "ending_column": 2 @@ -90,7 +92,7 @@ "name": "Bad", "source_mapping": { "start": 718, - "length": 493, + "length": 577, "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", @@ -115,7 +117,9 @@ 53, 54, 55, - 56 + 56, + 57, + 58 ], "starting_column": 1, "ending_column": 2 @@ -156,7 +160,7 @@ "name": "Bad", "source_mapping": { "start": 718, - "length": 493, + "length": 577, "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", @@ -181,7 +185,9 @@ 53, 54, 55, - 56 + 56, + 57, + 58 ], "starting_column": 1, "ending_column": 2 @@ -222,7 +228,7 @@ "name": "Bad", "source_mapping": { "start": 718, - "length": 493, + "length": 577, "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", @@ -247,7 +253,9 @@ 53, 54, 55, - 56 + 56, + 57, + 58 ], "starting_column": 1, "ending_column": 2