Skip to content

Commit

Permalink
Merge pull request #1579 from crytic/top-level-type-aliases
Browse files Browse the repository at this point in the history
Top level type aliases
  • Loading branch information
montyly authored Jan 11, 2023
2 parents b8ee314 + 4206739 commit cacfefd
Show file tree
Hide file tree
Showing 19 changed files with 71 additions and 1 deletion.
6 changes: 6 additions & 0 deletions slither/core/compilation_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from slither.core.declarations.function_top_level import FunctionTopLevel
from slither.core.declarations.using_for_top_level import UsingForTopLevel
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.variables.state_variable import StateVariable
from slither.core.variables.top_level_variable import TopLevelVariable
Expand Down Expand Up @@ -46,6 +47,7 @@ def __init__(self, core: "SlitherCore", crytic_compilation_unit: CompilationUnit
self._pragma_directives: List[Pragma] = []
self._import_directives: List[Import] = []
self._custom_errors: List[CustomError] = []
self._user_defined_value_types: Dict[str, TypeAliasTopLevel] = {}

self._all_functions: Set[Function] = set()
self._all_modifiers: Set[Modifier] = set()
Expand Down Expand Up @@ -215,6 +217,10 @@ def using_for_top_level(self) -> List[UsingForTopLevel]:
def custom_errors(self) -> List[CustomError]:
return self._custom_errors

@property
def user_defined_value_types(self) -> Dict[str, TypeAliasTopLevel]:
return self._user_defined_value_types

# endregion
###################################################################################
###################################################################################
Expand Down
1 change: 1 addition & 0 deletions slither/solc_parsing/slither_compilation_unit_solc.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ def parse_top_level_from_loaded_json(

user_defined_type = TypeAliasTopLevel(original_type, alias, scope)
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

else:
Expand Down
2 changes: 1 addition & 1 deletion slither/solc_parsing/solidity_types/type_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def parse_type(
sl = caller_context.compilation_unit
next_context = caller_context
renaming = {}
user_defined_types = {}
user_defined_types = sl.user_defined_value_types
else:
assert isinstance(caller_context, FunctionSolc)
sl = caller_context.underlying_function.compilation_unit
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
27 changes: 27 additions & 0 deletions tests/ast-parsing/user_defined_value_type/top-level-0.8.8.sol
Original file line number Diff line number Diff line change
@@ -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_)
}
}
}
1 change: 1 addition & 0 deletions tests/test_ast_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ def make_version(minor: int, patch_min: int, patch_max: int) -> List[str]:
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/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("bytes_call.sol", ["0.8.12"]),
Test("modifier_identifier_path.sol", VERSIONS_08),
Expand Down

0 comments on commit cacfefd

Please sign in to comment.