Merge pull request #837 from crytic/dev-unchecked-block

Add checked arithmetic  + unchecked block
pull/839/head
Feist Josselin 4 years ago committed by GitHub
commit ef64a127d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      slither/slithir/operations/binary.py
  2. 27
      slither/solc_parsing/declarations/function.py
  3. BIN
      tests/ast-parsing/compile/unchecked-0.4.0-legacy.zip
  4. BIN
      tests/ast-parsing/compile/unchecked-0.4.1-legacy.zip
  5. BIN
      tests/ast-parsing/compile/unchecked-0.4.10-legacy.zip
  6. BIN
      tests/ast-parsing/compile/unchecked-0.4.11-legacy.zip
  7. BIN
      tests/ast-parsing/compile/unchecked-0.4.12-compact.zip
  8. BIN
      tests/ast-parsing/compile/unchecked-0.4.12-legacy.zip
  9. BIN
      tests/ast-parsing/compile/unchecked-0.4.13-compact.zip
  10. BIN
      tests/ast-parsing/compile/unchecked-0.4.13-legacy.zip
  11. BIN
      tests/ast-parsing/compile/unchecked-0.4.14-compact.zip
  12. BIN
      tests/ast-parsing/compile/unchecked-0.4.14-legacy.zip
  13. BIN
      tests/ast-parsing/compile/unchecked-0.4.15-compact.zip
  14. BIN
      tests/ast-parsing/compile/unchecked-0.4.15-legacy.zip
  15. BIN
      tests/ast-parsing/compile/unchecked-0.4.16-compact.zip
  16. BIN
      tests/ast-parsing/compile/unchecked-0.4.16-legacy.zip
  17. BIN
      tests/ast-parsing/compile/unchecked-0.4.17-compact.zip
  18. BIN
      tests/ast-parsing/compile/unchecked-0.4.17-legacy.zip
  19. BIN
      tests/ast-parsing/compile/unchecked-0.4.18-compact.zip
  20. BIN
      tests/ast-parsing/compile/unchecked-0.4.18-legacy.zip
  21. BIN
      tests/ast-parsing/compile/unchecked-0.4.19-compact.zip
  22. BIN
      tests/ast-parsing/compile/unchecked-0.4.19-legacy.zip
  23. BIN
      tests/ast-parsing/compile/unchecked-0.4.2-legacy.zip
  24. BIN
      tests/ast-parsing/compile/unchecked-0.4.20-compact.zip
  25. BIN
      tests/ast-parsing/compile/unchecked-0.4.20-legacy.zip
  26. BIN
      tests/ast-parsing/compile/unchecked-0.4.21-compact.zip
  27. BIN
      tests/ast-parsing/compile/unchecked-0.4.21-legacy.zip
  28. BIN
      tests/ast-parsing/compile/unchecked-0.4.22-compact.zip
  29. BIN
      tests/ast-parsing/compile/unchecked-0.4.22-legacy.zip
  30. BIN
      tests/ast-parsing/compile/unchecked-0.4.23-compact.zip
  31. BIN
      tests/ast-parsing/compile/unchecked-0.4.23-legacy.zip
  32. BIN
      tests/ast-parsing/compile/unchecked-0.4.24-compact.zip
  33. BIN
      tests/ast-parsing/compile/unchecked-0.4.24-legacy.zip
  34. BIN
      tests/ast-parsing/compile/unchecked-0.4.25-compact.zip
  35. BIN
      tests/ast-parsing/compile/unchecked-0.4.25-legacy.zip
  36. BIN
      tests/ast-parsing/compile/unchecked-0.4.26-compact.zip
  37. BIN
      tests/ast-parsing/compile/unchecked-0.4.26-legacy.zip
  38. BIN
      tests/ast-parsing/compile/unchecked-0.4.3-legacy.zip
  39. BIN
      tests/ast-parsing/compile/unchecked-0.4.4-legacy.zip
  40. BIN
      tests/ast-parsing/compile/unchecked-0.4.5-legacy.zip
  41. BIN
      tests/ast-parsing/compile/unchecked-0.4.6-legacy.zip
  42. BIN
      tests/ast-parsing/compile/unchecked-0.4.7-legacy.zip
  43. BIN
      tests/ast-parsing/compile/unchecked-0.4.8-legacy.zip
  44. BIN
      tests/ast-parsing/compile/unchecked-0.4.9-legacy.zip
  45. BIN
      tests/ast-parsing/compile/unchecked-0.5.0-compact.zip
  46. BIN
      tests/ast-parsing/compile/unchecked-0.5.0-legacy.zip
  47. BIN
      tests/ast-parsing/compile/unchecked-0.5.1-compact.zip
  48. BIN
      tests/ast-parsing/compile/unchecked-0.5.1-legacy.zip
  49. BIN
      tests/ast-parsing/compile/unchecked-0.5.10-compact.zip
  50. BIN
      tests/ast-parsing/compile/unchecked-0.5.10-legacy.zip
  51. BIN
      tests/ast-parsing/compile/unchecked-0.5.11-compact.zip
  52. BIN
      tests/ast-parsing/compile/unchecked-0.5.11-legacy.zip
  53. BIN
      tests/ast-parsing/compile/unchecked-0.5.12-compact.zip
  54. BIN
      tests/ast-parsing/compile/unchecked-0.5.12-legacy.zip
  55. BIN
      tests/ast-parsing/compile/unchecked-0.5.13-compact.zip
  56. BIN
      tests/ast-parsing/compile/unchecked-0.5.13-legacy.zip
  57. BIN
      tests/ast-parsing/compile/unchecked-0.5.14-compact.zip
  58. BIN
      tests/ast-parsing/compile/unchecked-0.5.14-legacy.zip
  59. BIN
      tests/ast-parsing/compile/unchecked-0.5.15-compact.zip
  60. BIN
      tests/ast-parsing/compile/unchecked-0.5.15-legacy.zip
  61. BIN
      tests/ast-parsing/compile/unchecked-0.5.16-compact.zip
  62. BIN
      tests/ast-parsing/compile/unchecked-0.5.16-legacy.zip
  63. BIN
      tests/ast-parsing/compile/unchecked-0.5.17-compact.zip
  64. BIN
      tests/ast-parsing/compile/unchecked-0.5.17-legacy.zip
  65. BIN
      tests/ast-parsing/compile/unchecked-0.5.2-compact.zip
  66. BIN
      tests/ast-parsing/compile/unchecked-0.5.2-legacy.zip
  67. BIN
      tests/ast-parsing/compile/unchecked-0.5.3-compact.zip
  68. BIN
      tests/ast-parsing/compile/unchecked-0.5.3-legacy.zip
  69. BIN
      tests/ast-parsing/compile/unchecked-0.5.4-compact.zip
  70. BIN
      tests/ast-parsing/compile/unchecked-0.5.4-legacy.zip
  71. BIN
      tests/ast-parsing/compile/unchecked-0.5.5-compact.zip
  72. BIN
      tests/ast-parsing/compile/unchecked-0.5.5-legacy.zip
  73. BIN
      tests/ast-parsing/compile/unchecked-0.5.6-compact.zip
  74. BIN
      tests/ast-parsing/compile/unchecked-0.5.6-legacy.zip
  75. BIN
      tests/ast-parsing/compile/unchecked-0.5.7-compact.zip
  76. BIN
      tests/ast-parsing/compile/unchecked-0.5.7-legacy.zip
  77. BIN
      tests/ast-parsing/compile/unchecked-0.5.8-compact.zip
  78. BIN
      tests/ast-parsing/compile/unchecked-0.5.8-legacy.zip
  79. BIN
      tests/ast-parsing/compile/unchecked-0.5.9-compact.zip
  80. BIN
      tests/ast-parsing/compile/unchecked-0.5.9-legacy.zip
  81. BIN
      tests/ast-parsing/compile/unchecked-0.6.0-compact.zip
  82. BIN
      tests/ast-parsing/compile/unchecked-0.6.0-legacy.zip
  83. BIN
      tests/ast-parsing/compile/unchecked-0.6.1-compact.zip
  84. BIN
      tests/ast-parsing/compile/unchecked-0.6.1-legacy.zip
  85. BIN
      tests/ast-parsing/compile/unchecked-0.6.10-compact.zip
  86. BIN
      tests/ast-parsing/compile/unchecked-0.6.10-legacy.zip
  87. BIN
      tests/ast-parsing/compile/unchecked-0.6.11-compact.zip
  88. BIN
      tests/ast-parsing/compile/unchecked-0.6.11-legacy.zip
  89. BIN
      tests/ast-parsing/compile/unchecked-0.6.12-compact.zip
  90. BIN
      tests/ast-parsing/compile/unchecked-0.6.12-legacy.zip
  91. BIN
      tests/ast-parsing/compile/unchecked-0.6.2-compact.zip
  92. BIN
      tests/ast-parsing/compile/unchecked-0.6.2-legacy.zip
  93. BIN
      tests/ast-parsing/compile/unchecked-0.6.3-compact.zip
  94. BIN
      tests/ast-parsing/compile/unchecked-0.6.3-legacy.zip
  95. BIN
      tests/ast-parsing/compile/unchecked-0.6.4-compact.zip
  96. BIN
      tests/ast-parsing/compile/unchecked-0.6.4-legacy.zip
  97. BIN
      tests/ast-parsing/compile/unchecked-0.6.5-compact.zip
  98. BIN
      tests/ast-parsing/compile/unchecked-0.6.5-legacy.zip
  99. BIN
      tests/ast-parsing/compile/unchecked-0.6.6-compact.zip
  100. BIN
      tests/ast-parsing/compile/unchecked-0.6.6-legacy.zip
  101. Some files were not shown because too many files have changed in this diff Show More

@ -88,6 +88,16 @@ class BinaryType(Enum):
raise SlithIRError("get_type: Unknown operation type {})".format(operation_type))
def can_be_checked_for_overflow(self):
return self in [
BinaryType.POWER,
BinaryType.MULTIPLICATION,
BinaryType.MODULO,
BinaryType.ADDITION,
BinaryType.SUBTRACTION,
BinaryType.DIVISION,
]
def __str__(self): # pylint: disable=too-many-branches
if self == BinaryType.POWER:
return "**"
@ -167,6 +177,8 @@ class Binary(OperationWithLValue):
@property
def type_str(self):
if self.node.scope.is_checked and self._type.can_be_checked_for_overflow():
return "(c)" + str(self._type)
return str(self._type)
def __str__(self):

@ -931,6 +931,8 @@ class FunctionSolc:
node = self._parse_for(statement, node)
elif name == "Block":
node = self._parse_block(statement, node)
elif name == "UncheckedBlock":
node = self._parse_unchecked_block(statement, node)
elif name == "InlineAssembly":
# Added with solc 0.6 - the yul code is an AST
if "AST" in statement and not self.compilation_unit.core.skip_assembly:
@ -1015,7 +1017,7 @@ class FunctionSolc:
return node
def _parse_block(self, block: Dict, node: NodeSolc):
def _parse_block(self, block: Dict, node: NodeSolc, check_arithmetic: bool = False):
"""
Return:
Node
@ -1027,7 +1029,25 @@ class FunctionSolc:
else:
statements = block[self.get_children("children")]
new_scope = Scope(node.underlying_node.scope.is_checked, False, node.underlying_node.scope)
check_arithmetic = check_arithmetic | node.underlying_node.scope.is_checked
new_scope = Scope(check_arithmetic, False, node.underlying_node.scope)
for statement in statements:
node = self._parse_statement(statement, node, new_scope)
return node
def _parse_unchecked_block(self, block: Dict, node: NodeSolc):
"""
Return:
Node
"""
assert block[self.get_key()] == "UncheckedBlock"
if self.is_compact_ast:
statements = block["statements"]
else:
statements = block[self.get_children("children")]
new_scope = Scope(False, False, node.underlying_node.scope)
for statement in statements:
node = self._parse_statement(statement, node, new_scope)
return node
@ -1048,7 +1068,8 @@ class FunctionSolc:
self._function.is_empty = True
else:
self._function.is_empty = False
self._parse_block(cfg, node)
check_arithmetic = self.compilation_unit.solc_version >= "0.8.0"
self._parse_block(cfg, node, check_arithmetic=check_arithmetic)
self._remove_incorrect_edges()
self._remove_alone_endif()

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save