Merge pull request #1579 from crytic/top-level-type-aliases

Top level type aliases
pull/1583/head
Feist Josselin 2 years ago committed by GitHub
commit cacfefd1e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      slither/core/compilation_unit.py
  2. 1
      slither/solc_parsing/slither_compilation_unit_solc.py
  3. 2
      slither/solc_parsing/solidity_types/type_parsing.py
  4. BIN
      tests/ast-parsing/compile/user_defined_value_type/top-level-0.8.8.sol-0.8.10-compact.zip
  5. BIN
      tests/ast-parsing/compile/user_defined_value_type/top-level-0.8.8.sol-0.8.11-compact.zip
  6. BIN
      tests/ast-parsing/compile/user_defined_value_type/top-level-0.8.8.sol-0.8.12-compact.zip
  7. BIN
      tests/ast-parsing/compile/user_defined_value_type/top-level-0.8.8.sol-0.8.13-compact.zip
  8. BIN
      tests/ast-parsing/compile/user_defined_value_type/top-level-0.8.8.sol-0.8.14-compact.zip
  9. BIN
      tests/ast-parsing/compile/user_defined_value_type/top-level-0.8.8.sol-0.8.15-compact.zip
  10. BIN
      tests/ast-parsing/compile/user_defined_value_type/top-level-0.8.8.sol-0.8.8-compact.zip
  11. 5
      tests/ast-parsing/expected/user_defined_value_type/top-level-0.8.8.sol-0.8.10-compact.json
  12. 5
      tests/ast-parsing/expected/user_defined_value_type/top-level-0.8.8.sol-0.8.11-compact.json
  13. 5
      tests/ast-parsing/expected/user_defined_value_type/top-level-0.8.8.sol-0.8.12-compact.json
  14. 5
      tests/ast-parsing/expected/user_defined_value_type/top-level-0.8.8.sol-0.8.13-compact.json
  15. 5
      tests/ast-parsing/expected/user_defined_value_type/top-level-0.8.8.sol-0.8.14-compact.json
  16. 5
      tests/ast-parsing/expected/user_defined_value_type/top-level-0.8.8.sol-0.8.15-compact.json
  17. 5
      tests/ast-parsing/expected/user_defined_value_type/top-level-0.8.8.sol-0.8.8-compact.json
  18. 27
      tests/ast-parsing/user_defined_value_type/top-level-0.8.8.sol
  19. 1
      tests/test_ast_parsing.py

@ -18,6 +18,7 @@ from slither.core.declarations.enum_top_level import EnumTopLevel
from slither.core.declarations.function_top_level import FunctionTopLevel from slither.core.declarations.function_top_level import FunctionTopLevel
from slither.core.declarations.using_for_top_level import UsingForTopLevel from slither.core.declarations.using_for_top_level import UsingForTopLevel
from slither.core.declarations.structure_top_level import StructureTopLevel from slither.core.declarations.structure_top_level import StructureTopLevel
from slither.core.solidity_types.type_alias import TypeAliasTopLevel
from slither.core.scope.scope import FileScope from slither.core.scope.scope import FileScope
from slither.core.variables.state_variable import StateVariable from slither.core.variables.state_variable import StateVariable
from slither.core.variables.top_level_variable import TopLevelVariable from slither.core.variables.top_level_variable import TopLevelVariable
@ -46,6 +47,7 @@ class SlitherCompilationUnit(Context):
self._pragma_directives: List[Pragma] = [] self._pragma_directives: List[Pragma] = []
self._import_directives: List[Import] = [] self._import_directives: List[Import] = []
self._custom_errors: List[CustomError] = [] self._custom_errors: List[CustomError] = []
self._user_defined_value_types: Dict[str, TypeAliasTopLevel] = {}
self._all_functions: Set[Function] = set() self._all_functions: Set[Function] = set()
self._all_modifiers: Set[Modifier] = set() self._all_modifiers: Set[Modifier] = set()
@ -215,6 +217,10 @@ class SlitherCompilationUnit(Context):
def custom_errors(self) -> List[CustomError]: def custom_errors(self) -> List[CustomError]:
return self._custom_errors return self._custom_errors
@property
def user_defined_value_types(self) -> Dict[str, TypeAliasTopLevel]:
return self._user_defined_value_types
# endregion # endregion
################################################################################### ###################################################################################
################################################################################### ###################################################################################

@ -336,6 +336,7 @@ class SlitherCompilationUnitSolc(CallerContextExpression):
user_defined_type = TypeAliasTopLevel(original_type, alias, scope) user_defined_type = TypeAliasTopLevel(original_type, alias, scope)
user_defined_type.set_offset(top_level_data["src"], self._compilation_unit) user_defined_type.set_offset(top_level_data["src"], self._compilation_unit)
self._compilation_unit.user_defined_value_types[alias] = user_defined_type
scope.user_defined_types[alias] = user_defined_type scope.user_defined_types[alias] = user_defined_type
else: else:

@ -243,7 +243,7 @@ def parse_type(
sl = caller_context.compilation_unit sl = caller_context.compilation_unit
next_context = caller_context next_context = caller_context
renaming = {} renaming = {}
user_defined_types = {} user_defined_types = sl.user_defined_value_types
else: else:
assert isinstance(caller_context, FunctionSolc) assert isinstance(caller_context, FunctionSolc)
sl = caller_context.underlying_function.compilation_unit sl = caller_context.underlying_function.compilation_unit

@ -0,0 +1,5 @@
{
"Test": {
"set(StackTop,uint256)": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: INLINE ASM 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n}\n"
}
}

@ -0,0 +1,5 @@
{
"Test": {
"set(StackTop,uint256)": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: INLINE ASM 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n}\n"
}
}

@ -0,0 +1,5 @@
{
"Test": {
"set(StackTop,uint256)": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: INLINE ASM 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n}\n"
}
}

@ -0,0 +1,5 @@
{
"Test": {
"set(StackTop,uint256)": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: INLINE ASM 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n}\n"
}
}

@ -0,0 +1,5 @@
{
"Test": {
"set(StackTop,uint256)": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: INLINE ASM 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n}\n"
}
}

@ -0,0 +1,5 @@
{
"Test": {
"set(StackTop,uint256)": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: INLINE ASM 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n}\n"
}
}

@ -0,0 +1,5 @@
{
"Test": {
"set(StackTop,uint256)": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: INLINE ASM 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n}\n"
}
}

@ -0,0 +1,27 @@
type Operand is uint256;
type StackTop is uint256;
struct StorageOpcodesRange {
uint256 pointer;
uint256 length;
}
struct IntegrityState {
// Sources first as we read it in assembly.
bytes[] sources;
StorageOpcodesRange storageOpcodesRange;
uint256 constantsLength;
uint256 contextLength;
StackTop stackBottom;
StackTop stackMaxTop;
uint256 contextScratch;
function(IntegrityState memory, Operand, StackTop)
view
returns (StackTop)[] integrityFunctionPointers;
}
contract Test {
function set(StackTop stackTop_, uint256 a_) internal pure {
assembly {
mstore(stackTop_, a_)
}
}
}

@ -419,6 +419,7 @@ ALL_TESTS = [
Test("user_defined_value_type/constant-0.8.8.sol", ["0.8.8"] + make_version(8, 10, 15)), Test("user_defined_value_type/constant-0.8.8.sol", ["0.8.8"] + make_version(8, 10, 15)),
Test("user_defined_value_type/erc20-0.8.8.sol", ["0.8.8"] + make_version(8, 10, 15)), Test("user_defined_value_type/erc20-0.8.8.sol", ["0.8.8"] + make_version(8, 10, 15)),
Test("user_defined_value_type/in_parenthesis-0.8.8.sol", ["0.8.8"] + make_version(8, 10, 15)), Test("user_defined_value_type/in_parenthesis-0.8.8.sol", ["0.8.8"] + make_version(8, 10, 15)),
Test("user_defined_value_type/top-level-0.8.8.sol", ["0.8.8"] + make_version(8, 10, 15)),
Test("user_defined_value_type/using-for-0.8.8.sol", ["0.8.8"] + make_version(8, 10, 15)), Test("user_defined_value_type/using-for-0.8.8.sol", ["0.8.8"] + make_version(8, 10, 15)),
Test("bytes_call.sol", ["0.8.12"]), Test("bytes_call.sol", ["0.8.12"]),
Test("modifier_identifier_path.sol", VERSIONS_08), Test("modifier_identifier_path.sol", VERSIONS_08),

Loading…
Cancel
Save