pull/1378/head
Josselin Feist 2 years ago
parent aa68cacdce
commit 6571ada9a2
  1. 6
      slither/core/solidity_types/elementary_type.py
  2. 8
      slither/detectors/naming_convention/naming_convention.py
  3. 2
      slither/detectors/statements/type_based_tautology.py
  4. 4
      slither/slithir/convert.py
  5. 2
      slither/visitors/expression/constants_folding.py

@ -43,8 +43,8 @@ Int = [
"int256", "int256",
] ]
Max_Int = {k: 2 ** (8 * i - 1) - 1 if i > 0 else 2 ** 255 - 1 for i, k in enumerate(Int)} Max_Int = {k: 2 ** (8 * i - 1) - 1 if i > 0 else 2**255 - 1 for i, k in enumerate(Int)}
Min_Int = {k: -(2 ** (8 * i - 1)) if i > 0 else -(2 ** 255) for i, k in enumerate(Int)} Min_Int = {k: -(2 ** (8 * i - 1)) if i > 0 else -(2**255) for i, k in enumerate(Int)}
Uint = [ Uint = [
"uint", "uint",
@ -82,7 +82,7 @@ Uint = [
"uint256", "uint256",
] ]
Max_Uint = {k: 2 ** (8 * i) - 1 if i > 0 else 2 ** 256 - 1 for i, k in enumerate(Uint)} Max_Uint = {k: 2 ** (8 * i) - 1 if i > 0 else 2**256 - 1 for i, k in enumerate(Uint)}
Min_Uint = {k: 0 for k in Uint} Min_Uint = {k: 0 for k in Uint}

@ -89,14 +89,10 @@ Solidity defines a [naming convention](https://solidity.readthedocs.io/en/v0.4.2
if func.is_constructor: if func.is_constructor:
continue continue
if not self.is_mixed_case(func.name): if not self.is_mixed_case(func.name):
if ( if func.visibility in [
func.visibility
in [
"internal", "internal",
"private", "private",
] ] and self.is_mixed_case_with_underscore(func.name):
and self.is_mixed_case_with_underscore(func.name)
):
continue continue
if func.name.startswith(("echidna_", "crytic_")): if func.name.startswith(("echidna_", "crytic_")):
continue continue

@ -11,7 +11,7 @@ from slither.core.solidity_types.elementary_type import Int, Uint
def typeRange(t): def typeRange(t):
bits = int(t.split("int")[1]) bits = int(t.split("int")[1])
if t in Uint: if t in Uint:
return 0, (2 ** bits) - 1 return 0, (2**bits) - 1
if t in Int: if t in Int:
v = (2 ** (bits - 1)) - 1 v = (2 ** (bits - 1)) - 1
return -v, v return -v, v

@ -172,10 +172,10 @@ def _fits_under_integer(val: int, can_be_int: bool, can_be_uint) -> List[str]:
assert can_be_int | can_be_uint assert can_be_int | can_be_uint
while n <= 256: while n <= 256:
if can_be_uint: if can_be_uint:
if val <= 2 ** n - 1: if val <= 2**n - 1:
ret.append(f"uint{n}") ret.append(f"uint{n}")
if can_be_int: if can_be_int:
if val <= (2 ** n) / 2 - 1: if val <= (2**n) / 2 - 1:
ret.append(f"int{n}") ret.append(f"int{n}")
n = n + 8 n = n + 8
return ret return ret

@ -43,7 +43,7 @@ class ConstantFolding(ExpressionVisitor):
left = get_val(expression.expression_left) left = get_val(expression.expression_left)
right = get_val(expression.expression_right) right = get_val(expression.expression_right)
if expression.type == BinaryOperationType.POWER: if expression.type == BinaryOperationType.POWER:
set_val(expression, left ** right) set_val(expression, left**right)
elif expression.type == BinaryOperationType.MULTIPLICATION: elif expression.type == BinaryOperationType.MULTIPLICATION:
set_val(expression, left * right) set_val(expression, left * right)
elif expression.type == BinaryOperationType.DIVISION: elif expression.type == BinaryOperationType.DIVISION:

Loading…
Cancel
Save