|
|
|
@ -7,18 +7,6 @@ from slither.slithir.operations import TypeConversion |
|
|
|
|
from slither.core.declarations.enum import Enum |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _uses_vulnerable_solc_version(version): |
|
|
|
|
"""Detect if used compiler version is 0.4.[0|1|2|3|4] |
|
|
|
|
Args: |
|
|
|
|
version (solc version used) |
|
|
|
|
Returns: |
|
|
|
|
Bool |
|
|
|
|
""" |
|
|
|
|
if version in ["0.4.0", "0.4.1", "0.4.2", "0.4.3", "0.4.4"]: |
|
|
|
|
return True |
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _detect_dangerous_enum_conversions(contract): |
|
|
|
|
"""Detect dangerous conversion to enum by checking IR |
|
|
|
|
Args: |
|
|
|
@ -54,11 +42,11 @@ class EnumConversion(AbstractDetector): |
|
|
|
|
```solidity |
|
|
|
|
pragma solidity 0.4.2; |
|
|
|
|
contract Test{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum E{a} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function bug(uint a) public returns(E){ |
|
|
|
|
return E(a); |
|
|
|
|
return E(a); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
``` |
|
|
|
@ -67,12 +55,11 @@ Attackers can trigger unexpected behaviour by calling `bug(1)`.""" |
|
|
|
|
|
|
|
|
|
WIKI_RECOMMENDATION = "Use a recent compiler version. If `solc` <`0.4.5` is required, check the `enum` conversion range." |
|
|
|
|
|
|
|
|
|
VULNERABLE_SOLC_VERSIONS = ["0.4.0", "0.4.1", "0.4.2", "0.4.3", "0.4.4"] |
|
|
|
|
|
|
|
|
|
def _detect(self): |
|
|
|
|
"""Detect dangerous conversion to enum""" |
|
|
|
|
results = [] |
|
|
|
|
# If solc version >= 0.4.5 then return |
|
|
|
|
if not _uses_vulnerable_solc_version(self.compilation_unit.solc_version): |
|
|
|
|
return results |
|
|
|
|
|
|
|
|
|
for c in self.compilation_unit.contracts: |
|
|
|
|
ret = _detect_dangerous_enum_conversions(c) |
|
|
|
|