Merge branch 'dev' of github.com:crytic/slither into issue-923

pull/1041/head
Jaime 3 years ago
commit b1e236eb58
  1. 2
      slither/analyses/data_dependency/data_dependency.py
  2. 5
      slither/core/scope/scope.py
  3. 4
      slither/core/variables/top_level_variable.py
  4. 2
      slither/detectors/operations/missing_zero_address_validation.py
  5. 1
      slither/printers/guidance/echidna.py
  6. 2
      slither/printers/summary/modifier_calls.py
  7. 2
      slither/slithir/utils/ssa.py
  8. 2
      slither/slithir/utils/utils.py
  9. 18
      slither/solc_parsing/expressions/find_variable.py
  10. 10
      slither/solc_parsing/slither_compilation_unit_solc.py
  11. 5
      slither/solc_parsing/solidity_types/type_parsing.py
  12. 32
      slither/solc_parsing/variables/top_level_variable.py
  13. 3
      slither/tools/properties/properties/erc20.py
  14. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.0-legacy.zip
  15. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.1-legacy.zip
  16. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.10-legacy.zip
  17. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.11-legacy.zip
  18. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.12-compact.zip
  19. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.12-legacy.zip
  20. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.13-compact.zip
  21. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.13-legacy.zip
  22. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.14-compact.zip
  23. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.14-legacy.zip
  24. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.15-compact.zip
  25. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.15-legacy.zip
  26. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.16-compact.zip
  27. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.16-legacy.zip
  28. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.17-compact.zip
  29. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.17-legacy.zip
  30. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.18-compact.zip
  31. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.18-legacy.zip
  32. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.19-compact.zip
  33. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.19-legacy.zip
  34. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.2-legacy.zip
  35. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.20-compact.zip
  36. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.20-legacy.zip
  37. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.21-compact.zip
  38. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.21-legacy.zip
  39. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.22-compact.zip
  40. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.22-legacy.zip
  41. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.23-compact.zip
  42. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.23-legacy.zip
  43. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.24-compact.zip
  44. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.24-legacy.zip
  45. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.25-compact.zip
  46. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.25-legacy.zip
  47. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.26-compact.zip
  48. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.26-legacy.zip
  49. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.3-legacy.zip
  50. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.4-legacy.zip
  51. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.5-legacy.zip
  52. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.6-legacy.zip
  53. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.7-legacy.zip
  54. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.8-legacy.zip
  55. BIN
      tests/ast-parsing/compile/top_level_variable-0.4.9-legacy.zip
  56. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.0-compact.zip
  57. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.0-legacy.zip
  58. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.1-compact.zip
  59. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.1-legacy.zip
  60. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.10-compact.zip
  61. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.10-legacy.zip
  62. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.11-compact.zip
  63. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.11-legacy.zip
  64. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.12-compact.zip
  65. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.12-legacy.zip
  66. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.13-compact.zip
  67. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.13-legacy.zip
  68. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.14-compact.zip
  69. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.14-legacy.zip
  70. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.15-compact.zip
  71. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.15-legacy.zip
  72. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.16-compact.zip
  73. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.16-legacy.zip
  74. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.17-compact.zip
  75. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.17-legacy.zip
  76. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.2-compact.zip
  77. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.2-legacy.zip
  78. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.3-compact.zip
  79. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.3-legacy.zip
  80. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.4-compact.zip
  81. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.4-legacy.zip
  82. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.5-compact.zip
  83. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.5-legacy.zip
  84. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.6-compact.zip
  85. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.6-legacy.zip
  86. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.7-compact.zip
  87. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.7-legacy.zip
  88. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.8-compact.zip
  89. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.8-legacy.zip
  90. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.9-compact.zip
  91. BIN
      tests/ast-parsing/compile/top_level_variable-0.5.9-legacy.zip
  92. BIN
      tests/ast-parsing/compile/top_level_variable-0.6.0-compact.zip
  93. BIN
      tests/ast-parsing/compile/top_level_variable-0.6.0-legacy.zip
  94. BIN
      tests/ast-parsing/compile/top_level_variable-0.6.1-compact.zip
  95. BIN
      tests/ast-parsing/compile/top_level_variable-0.6.1-legacy.zip
  96. BIN
      tests/ast-parsing/compile/top_level_variable-0.6.10-compact.zip
  97. BIN
      tests/ast-parsing/compile/top_level_variable-0.6.10-legacy.zip
  98. BIN
      tests/ast-parsing/compile/top_level_variable-0.6.11-compact.zip
  99. BIN
      tests/ast-parsing/compile/top_level_variable-0.6.11-legacy.zip
  100. BIN
      tests/ast-parsing/compile/top_level_variable-0.6.12-compact.zip
  101. Some files were not shown because too many files have changed in this diff Show More

@ -14,6 +14,7 @@ from slither.core.declarations import (
Structure,
)
from slither.core.declarations.solidity_import_placeholder import SolidityImportPlaceHolder
from slither.core.variables.top_level_variable import TopLevelVariable
from slither.core.variables.variable import Variable
from slither.slithir.operations import Index, OperationWithLValue, InternalCall
from slither.slithir.variables import (
@ -410,6 +411,7 @@ def convert_variable_to_non_ssa(v):
Function,
Type,
SolidityImportPlaceHolder,
TopLevelVariable,
),
)
return v

@ -6,6 +6,7 @@ from slither.core.declarations.custom_error_top_level import CustomErrorTopLevel
from slither.core.declarations.enum_top_level import EnumTopLevel
from slither.core.declarations.function_top_level import FunctionTopLevel
from slither.core.declarations.structure_top_level import StructureTopLevel
from slither.core.variables.top_level_variable import TopLevelVariable
from slither.slithir.variables import Constant
@ -36,6 +37,7 @@ class FileScope:
self.imports: Set[Import] = set()
self.pragmas: Set[Pragma] = set()
self.structures: Dict[str, StructureTopLevel] = {}
self.variables: Dict[str, TopLevelVariable] = {}
def add_accesible_scopes(self) -> bool:
"""
@ -69,6 +71,9 @@ class FileScope:
if not _dict_contain(new_scope.structures, self.structures):
self.structures.update(new_scope.structures)
learn_something = True
if not _dict_contain(new_scope.variables, self.variables):
self.variables.update(new_scope.variables)
learn_something = True
return learn_something

@ -5,12 +5,14 @@ from slither.core.variables.variable import Variable
if TYPE_CHECKING:
from slither.core.cfg.node import Node
from slither.core.scope.scope import FileScope
class TopLevelVariable(TopLevel, Variable):
def __init__(self):
def __init__(self, scope: "FileScope"):
super().__init__()
self._node_initialization: Optional["Node"] = None
self.file_scope = scope
# endregion
###################################################################################

@ -40,7 +40,7 @@ contract C {
}
}
```
Bob calls `updateOwner` without specifying the `newOwner`, soBob loses ownership of the contract.
Bob calls `updateOwner` without specifying the `newOwner`, so Bob loses ownership of the contract.
"""
# endregion wiki_exploit_scenario

@ -391,6 +391,7 @@ class Echidna(AbstractPrinter):
"have_external_calls": external_calls,
"call_a_parameter": call_parameters,
"use_balance": use_balance,
"solc_versions": [unit.solc_version for unit in self.slither.compilation_units],
}
self.info(json.dumps(d, indent=4))

@ -38,6 +38,8 @@ class Modifiers(AbstractPrinter):
table.add_row([function.name, [m.name for m in set(modifiers)]])
txt += "\n" + str(table)
self.info(txt)
all_txt += txt
all_tables.append((contract.name, table))
res = self.generate_output(all_txt)
for name, table in all_tables:

@ -13,6 +13,7 @@ from slither.core.declarations.solidity_import_placeholder import SolidityImport
from slither.core.solidity_types.type import Type
from slither.core.variables.local_variable import LocalVariable
from slither.core.variables.state_variable import StateVariable
from slither.core.variables.top_level_variable import TopLevelVariable
from slither.slithir.operations import (
Assignment,
Binary,
@ -617,6 +618,7 @@ def get(
Function,
Type,
SolidityImportPlaceHolder,
TopLevelVariable,
),
) # type for abi.decode(.., t)
return variable

@ -2,6 +2,7 @@ from slither.core.variables.local_variable import LocalVariable
from slither.core.variables.state_variable import StateVariable
from slither.core.declarations.solidity_variables import SolidityVariable
from slither.core.variables.top_level_variable import TopLevelVariable
from slither.slithir.variables.temporary import TemporaryVariable
from slither.slithir.variables.constant import Constant
@ -15,6 +16,7 @@ def is_valid_rvalue(v):
(
StateVariable,
LocalVariable,
TopLevelVariable,
TemporaryVariable,
Constant,
SolidityVariable,

@ -19,6 +19,7 @@ from slither.core.solidity_types import (
FunctionType,
MappingType,
)
from slither.core.variables.top_level_variable import TopLevelVariable
from slither.core.variables.variable import Variable
from slither.exceptions import SlitherError
from slither.solc_parsing.declarations.caller_context import CallerContextExpression
@ -98,7 +99,9 @@ def _find_variable_in_function_parser(
def _find_top_level(
var_name: str, scope: "FileScope"
) -> Tuple[Optional[Union[Enum, Structure, SolidityImportPlaceHolder, CustomError]], bool]:
) -> Tuple[
Optional[Union[Enum, Structure, SolidityImportPlaceHolder, CustomError, TopLevelVariable]], bool
]:
"""
Return the top level variable use, and a boolean indicating if the variable returning was cretead
If the variable was created, it has no source_mapping
@ -126,6 +129,9 @@ def _find_top_level(
if custom_error.solidity_signature == var_name:
return custom_error, False
if var_name in scope.variables:
return scope.variables[var_name], False
return None, False
@ -210,6 +216,8 @@ def _find_variable_init(
) -> Tuple[List[Contract], List["Function"], FileScope,]:
from slither.solc_parsing.declarations.contract import ContractSolc
from slither.solc_parsing.declarations.function import FunctionSolc
from slither.solc_parsing.declarations.structure_top_level import StructureTopLevelSolc
from slither.solc_parsing.variables.top_level_variable import TopLevelVariableSolc
direct_contracts: List[Contract]
direct_functions_parser: List[Function]
@ -244,6 +252,14 @@ def _find_variable_init(
else:
assert isinstance(underlying_function, FunctionContract)
scope = underlying_function.contract.file_scope
elif isinstance(caller_context, StructureTopLevelSolc):
direct_contracts = []
direct_functions_parser = []
scope = caller_context.underlying_structure.file_scope
elif isinstance(caller_context, TopLevelVariableSolc):
direct_contracts = []
direct_functions_parser = []
scope = caller_context.underlying_variable.file_scope
else:
raise SlitherError(
f"{type(caller_context)} ({caller_context} is not valid for find_variable"

@ -239,12 +239,13 @@ class SlitherCompilationUnitSolc:
self._parse_enum(top_level_data, filename)
elif top_level_data[self.get_key()] == "VariableDeclaration":
var = TopLevelVariable()
var_parser = TopLevelVariableSolc(var, top_level_data)
var = TopLevelVariable(scope)
var_parser = TopLevelVariableSolc(var, top_level_data, self)
var.set_offset(top_level_data["src"], self._compilation_unit)
self._compilation_unit.variables_top_level.append(var)
self._variables_top_level_parser.append(var_parser)
scope.variables[var.name] = var
elif top_level_data[self.get_key()] == "FunctionDefinition":
scope = self.compilation_unit.get_scope(filename)
func = FunctionTopLevel(self._compilation_unit, scope)
@ -495,6 +496,7 @@ Please rename it, this name is reserved for Slither's internals"""
for lib in libraries:
self._analyze_struct_events(lib)
self._analyze_top_level_variables()
self._analyze_top_level_structures()
# Start with the contracts without inheritance
@ -580,9 +582,9 @@ Please rename it, this name is reserved for Slither's internals"""
def _analyze_top_level_variables(self):
try:
for var in self._variables_top_level_parser:
var.analyze(self)
var.analyze(var)
except (VariableNotFound, KeyError) as e:
raise SlitherException(f"Missing struct {e} during top level structure analyze") from e
raise SlitherException(f"Missing {e} during variable analyze") from e
def _analyze_params_top_level_function(self):
for func_parser in self._functions_top_level_parser:

@ -220,6 +220,7 @@ def parse_type(
from slither.solc_parsing.declarations.custom_error import CustomErrorSolc
from slither.solc_parsing.declarations.structure_top_level import StructureTopLevelSolc
from slither.solc_parsing.slither_compilation_unit_solc import SlitherCompilationUnitSolc
from slither.solc_parsing.variables.top_level_variable import TopLevelVariableSolc
sl: "SlitherCompilationUnit"
# Note: for convenicence top level functions use the same parser than function in contract
@ -245,9 +246,11 @@ def parse_type(
all_enums += enums_direct_access
contracts = sl.contracts
functions = []
elif isinstance(caller_context, (StructureTopLevelSolc, CustomErrorSolc)):
elif isinstance(caller_context, (StructureTopLevelSolc, CustomErrorSolc, TopLevelVariableSolc)):
if isinstance(caller_context, StructureTopLevelSolc):
scope = caller_context.underlying_structure.file_scope
elif isinstance(caller_context, TopLevelVariableSolc):
scope = caller_context.underlying_variable.file_scope
else:
assert isinstance(caller_context, CustomErrorSolc)
custom_error = caller_context.underlying_custom_error

@ -1,12 +1,38 @@
from typing import Dict
from typing import Dict, TYPE_CHECKING
from slither.core.variables.top_level_variable import TopLevelVariable
from slither.solc_parsing.variables.variable_declaration import VariableDeclarationSolc
from slither.solc_parsing.declarations.caller_context import CallerContextExpression
if TYPE_CHECKING:
from slither.solc_parsing.slither_compilation_unit_solc import SlitherCompilationUnitSolc
from slither.core.compilation_unit import SlitherCompilationUnit
class TopLevelVariableSolc(VariableDeclarationSolc):
def __init__(self, variable: TopLevelVariable, variable_data: Dict):
class TopLevelVariableSolc(VariableDeclarationSolc, CallerContextExpression):
def __init__(
self,
variable: TopLevelVariable,
variable_data: Dict,
slither_parser: "SlitherCompilationUnitSolc",
):
super().__init__(variable, variable_data)
self._slither_parser = slither_parser
@property
def is_compact_ast(self) -> bool:
return self._slither_parser.is_compact_ast
@property
def compilation_unit(self) -> "SlitherCompilationUnit":
return self._slither_parser.compilation_unit
def get_key(self) -> str:
return self._slither_parser.get_key()
@property
def slither_parser(self) -> "SlitherCompilationUnitSolc":
return self._slither_parser
@property
def underlying_variable(self) -> TopLevelVariable:

@ -78,6 +78,7 @@ def generate_erc20(
if contract.compilation_unit.core.crytic_compile.type not in [
PlatformType.TRUFFLE,
PlatformType.SOLC,
PlatformType.BUILDER,
]:
logging.error(
f"{contract.compilation_unit.core.crytic_compile.type} not yet supported by slither-prop"
@ -162,7 +163,7 @@ def _initialization_recommendation(type_property: str) -> str:
# TODO: move this to crytic-compile
def _platform_to_output_dir(platform: AbstractPlatform) -> Path:
if platform.TYPE == PlatformType.TRUFFLE:
if platform.TYPE in [PlatformType.TRUFFLE, platform.TYPE == PlatformType.BUILDER]:
return Path(platform.target, "contracts", "crytic")
if platform.TYPE == PlatformType.SOLC:
return Path(platform.target).parent

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

Loading…
Cancel
Save