Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions slither/detectors/statements/incorrect_strict_equality.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ def is_any_tainted(
is_dependent_ssa(var, taint, function.contract) for var in variables for taint in taints
)

@staticmethod
def is_side_effect_free_view_or_pure(func: Function) -> bool:
if not (func.view or func.pure):
return False

return not any(
not (caller.view or caller.pure) for caller in func.all_reachable_from_functions
)

def taint_balance_equalities(
self, functions: list[FunctionContract | Any]
) -> list[LocalIRVariable | TemporaryVariableSSA | Any]:
Expand Down Expand Up @@ -148,6 +157,8 @@ def tainted_equality_nodes(
# Disable the detector on top level function until we have good taint on those
if isinstance(func, FunctionTopLevel):
continue
if self.is_side_effect_free_view_or_pure(func):
continue
for node in func.nodes:
for ir in node.irs_ssa:
# Filter to only tainted equality (==) comparisons
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ViewPureStrictEquality._isDeadline() (tests/e2e/detectors/test_data/incorrect-equality/0.8.35/incorrect_equality_view_pure.sol#23-25) uses a dangerous strict equality:
- block.timestamp == deadline (tests/e2e/detectors/test_data/incorrect-equality/0.8.35/incorrect_equality_view_pure.sol#24)

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
contract ViewPureStrictEquality {
uint256 public immutable deployBlock;
uint256 public deadline;
uint256 public releases;

constructor(uint256 deadline_) {
deployBlock = block.number;
deadline = deadline_;
}

function isDeployBlockExternal() external view returns (bool) {
return block.number == deployBlock;
}

function isDeployBlockPublic() public view returns (bool) {
return block.number == deployBlock;
}

function isZeroPure(uint256 value) public pure returns (bool) {
return value == 0;
}

function _isDeadline() internal view returns (bool) {
return block.timestamp == deadline;
}

function releaseIfDeadline() external {
if (_isDeadline()) {
releases += 1;
}
}
}
Binary file not shown.
5 changes: 5 additions & 0 deletions tests/e2e/detectors/test_detectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,11 @@ def id_test(test_item: Test):
"incorrect_equality.sol",
"0.7.6",
),
Test(
all_detectors.IncorrectStrictEquality,
"incorrect_equality_view_pure.sol",
"0.8.35",
),
Test(
all_detectors.TooManyDigits,
"too_many_digits.sol",
Expand Down