|
|
@ -165,7 +165,7 @@ def convert_expression(expression: Expression, node: "Node") -> List[Any]: |
|
|
|
################################################################################### |
|
|
|
################################################################################### |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def is_value(ins: slither.slithir.operations.operation.Operation) -> bool: |
|
|
|
def is_value(ins: Operation) -> bool: |
|
|
|
if isinstance(ins, TmpCall): |
|
|
|
if isinstance(ins, TmpCall): |
|
|
|
if isinstance(ins.ori, Member): |
|
|
|
if isinstance(ins.ori, Member): |
|
|
|
if ins.ori.variable_right == "value": |
|
|
|
if ins.ori.variable_right == "value": |
|
|
@ -173,7 +173,7 @@ def is_value(ins: slither.slithir.operations.operation.Operation) -> bool: |
|
|
|
return False |
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def is_gas(ins: slither.slithir.operations.operation.Operation) -> bool: |
|
|
|
def is_gas(ins: Operation) -> bool: |
|
|
|
if isinstance(ins, TmpCall): |
|
|
|
if isinstance(ins, TmpCall): |
|
|
|
if isinstance(ins.ori, Member): |
|
|
|
if isinstance(ins.ori, Member): |
|
|
|
if ins.ori.variable_right == "gas": |
|
|
|
if ins.ori.variable_right == "gas": |
|
|
@ -293,7 +293,7 @@ def _find_function_from_parameter( |
|
|
|
return None |
|
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def is_temporary(ins: slither.slithir.operations.operation.Operation) -> bool: |
|
|
|
def is_temporary(ins: Operation) -> bool: |
|
|
|
return isinstance( |
|
|
|
return isinstance( |
|
|
|
ins, |
|
|
|
ins, |
|
|
|
(Argument, TmpNewElementaryType, TmpNewContract, TmpNewArray, TmpNewStructure), |
|
|
|
(Argument, TmpNewElementaryType, TmpNewContract, TmpNewArray, TmpNewStructure), |
|
|
@ -1153,12 +1153,8 @@ def can_be_low_level(ir: slither.slithir.operations.high_level_call.HighLevelCal |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def convert_to_low_level( |
|
|
|
def convert_to_low_level( |
|
|
|
ir: slither.slithir.operations.high_level_call.HighLevelCall, |
|
|
|
ir: HighLevelCall, |
|
|
|
) -> Union[ |
|
|
|
) -> Union[Send, LowLevelCall, Transfer,]: |
|
|
|
slither.slithir.operations.send.Send, |
|
|
|
|
|
|
|
slither.slithir.operations.low_level_call.LowLevelCall, |
|
|
|
|
|
|
|
slither.slithir.operations.transfer.Transfer, |
|
|
|
|
|
|
|
]: |
|
|
|
|
|
|
|
""" |
|
|
|
""" |
|
|
|
Convert to a transfer/send/or low level call |
|
|
|
Convert to a transfer/send/or low level call |
|
|
|
The funciton assume to receive a correct IR |
|
|
|
The funciton assume to receive a correct IR |
|
|
@ -1198,7 +1194,7 @@ def convert_to_low_level( |
|
|
|
raise SlithIRError(f"Incorrect conversion to low level {ir}") |
|
|
|
raise SlithIRError(f"Incorrect conversion to low level {ir}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def can_be_solidity_func(ir: slither.slithir.operations.high_level_call.HighLevelCall) -> bool: |
|
|
|
def can_be_solidity_func(ir: HighLevelCall) -> bool: |
|
|
|
if not isinstance(ir, HighLevelCall): |
|
|
|
if not isinstance(ir, HighLevelCall): |
|
|
|
return False |
|
|
|
return False |
|
|
|
return ir.destination.name == "abi" and ir.function_name in [ |
|
|
|
return ir.destination.name == "abi" and ir.function_name in [ |
|
|
@ -1212,8 +1208,8 @@ def can_be_solidity_func(ir: slither.slithir.operations.high_level_call.HighLeve |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def convert_to_solidity_func( |
|
|
|
def convert_to_solidity_func( |
|
|
|
ir: slither.slithir.operations.high_level_call.HighLevelCall, |
|
|
|
ir: HighLevelCall, |
|
|
|
) -> slither.slithir.operations.solidity_call.SolidityCall: |
|
|
|
) -> SolidityCall: |
|
|
|
""" |
|
|
|
""" |
|
|
|
Must be called after can_be_solidity_func |
|
|
|
Must be called after can_be_solidity_func |
|
|
|
:param ir: |
|
|
|
:param ir: |
|
|
@ -1250,8 +1246,8 @@ def convert_to_solidity_func( |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def convert_to_push_expand_arr( |
|
|
|
def convert_to_push_expand_arr( |
|
|
|
ir: slither.slithir.operations.high_level_call.HighLevelCall, node: "Node", ret: List[Any] |
|
|
|
ir: HighLevelCall, node: "Node", ret: List[Any] |
|
|
|
) -> slither.slithir.variables.temporary.TemporaryVariable: |
|
|
|
) -> TemporaryVariable: |
|
|
|
arr = ir.destination |
|
|
|
arr = ir.destination |
|
|
|
|
|
|
|
|
|
|
|
length = ReferenceVariable(node) |
|
|
|
length = ReferenceVariable(node) |
|
|
@ -1287,14 +1283,14 @@ def convert_to_push_expand_arr( |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def convert_to_push_set_val( |
|
|
|
def convert_to_push_set_val( |
|
|
|
ir: slither.slithir.operations.high_level_call.HighLevelCall, |
|
|
|
ir: HighLevelCall, |
|
|
|
node: "Node", |
|
|
|
node: "Node", |
|
|
|
length_val: slither.slithir.variables.temporary.TemporaryVariable, |
|
|
|
length_val: TemporaryVariable, |
|
|
|
ret: List[ |
|
|
|
ret: List[ |
|
|
|
Union[ |
|
|
|
Union[ |
|
|
|
slither.slithir.operations.length.Length, |
|
|
|
Length, |
|
|
|
slither.slithir.operations.assignment.Assignment, |
|
|
|
Assignment, |
|
|
|
slither.slithir.operations.binary.Binary, |
|
|
|
Binary, |
|
|
|
] |
|
|
|
] |
|
|
|
], |
|
|
|
], |
|
|
|
) -> None: |
|
|
|
) -> None: |
|
|
@ -1417,21 +1413,16 @@ def convert_to_pop(ir, node): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def look_for_library_or_top_level( |
|
|
|
def look_for_library_or_top_level( |
|
|
|
contract: slither.core.declarations.contract.Contract, |
|
|
|
contract: Contract, |
|
|
|
ir: slither.slithir.operations.high_level_call.HighLevelCall, |
|
|
|
ir: HighLevelCall, |
|
|
|
using_for, |
|
|
|
using_for, |
|
|
|
t: Union[ |
|
|
|
t: Union[ |
|
|
|
slither.core.solidity_types.user_defined_type.UserDefinedType, |
|
|
|
UserDefinedType, |
|
|
|
slither.core.solidity_types.elementary_type.ElementaryType, |
|
|
|
ElementaryType, |
|
|
|
str, |
|
|
|
str, |
|
|
|
TypeAliasTopLevel, |
|
|
|
TypeAliasTopLevel, |
|
|
|
], |
|
|
|
], |
|
|
|
) -> Optional[ |
|
|
|
) -> Optional[Union[LibraryCall, InternalCall,]]: |
|
|
|
Union[ |
|
|
|
|
|
|
|
slither.slithir.operations.library_call.LibraryCall, |
|
|
|
|
|
|
|
slither.slithir.operations.internal_call.InternalCall, |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
]: |
|
|
|
|
|
|
|
for destination in using_for[t]: |
|
|
|
for destination in using_for[t]: |
|
|
|
if isinstance(destination, FunctionTopLevel) and destination.name == ir.function_name: |
|
|
|
if isinstance(destination, FunctionTopLevel) and destination.name == ir.function_name: |
|
|
|
arguments = [ir.destination] + ir.arguments |
|
|
|
arguments = [ir.destination] + ir.arguments |
|
|
@ -1477,13 +1468,8 @@ def look_for_library_or_top_level( |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def convert_to_library_or_top_level( |
|
|
|
def convert_to_library_or_top_level( |
|
|
|
ir: slither.slithir.operations.high_level_call.HighLevelCall, node: "Node", using_for |
|
|
|
ir: HighLevelCall, node: "Node", using_for |
|
|
|
) -> Optional[ |
|
|
|
) -> Optional[Union[LibraryCall, InternalCall,]]: |
|
|
|
Union[ |
|
|
|
|
|
|
|
slither.slithir.operations.library_call.LibraryCall, |
|
|
|
|
|
|
|
slither.slithir.operations.internal_call.InternalCall, |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
]: |
|
|
|
|
|
|
|
# We use contract_declarer, because Solidity resolve the library |
|
|
|
# We use contract_declarer, because Solidity resolve the library |
|
|
|
# before resolving the inheritance. |
|
|
|
# before resolving the inheritance. |
|
|
|
# Though we could use .contract as libraries cannot be shadowed |
|
|
|
# Though we could use .contract as libraries cannot be shadowed |
|
|
@ -1504,8 +1490,8 @@ def convert_to_library_or_top_level( |
|
|
|
|
|
|
|
|
|
|
|
def get_type( |
|
|
|
def get_type( |
|
|
|
t: Union[ |
|
|
|
t: Union[ |
|
|
|
slither.core.solidity_types.user_defined_type.UserDefinedType, |
|
|
|
UserDefinedType, |
|
|
|
slither.core.solidity_types.elementary_type.ElementaryType, |
|
|
|
ElementaryType, |
|
|
|
] |
|
|
|
] |
|
|
|
) -> str: |
|
|
|
) -> str: |
|
|
|
""" |
|
|
|
""" |
|
|
@ -1526,9 +1512,7 @@ def _can_be_implicitly_converted(source: str, target: str) -> bool: |
|
|
|
return source == target |
|
|
|
return source == target |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def convert_type_library_call( |
|
|
|
def convert_type_library_call(ir: HighLevelCall, lib_contract: Contract) -> Optional[LibraryCall]: |
|
|
|
ir: HighLevelCall, lib_contract: Contract |
|
|
|
|
|
|
|
) -> Optional[slither.slithir.operations.library_call.LibraryCall]: |
|
|
|
|
|
|
|
func = None |
|
|
|
func = None |
|
|
|
candidates = [ |
|
|
|
candidates = [ |
|
|
|
f |
|
|
|
f |
|
|
@ -1739,7 +1723,7 @@ def convert_type_of_high_and_internal_level_call( |
|
|
|
################################################################################### |
|
|
|
################################################################################### |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def find_references_origin(irs: List[Any]) -> None: |
|
|
|
def find_references_origin(irs: List[Operation]) -> None: |
|
|
|
""" |
|
|
|
""" |
|
|
|
Make lvalue of each Index, Member operation |
|
|
|
Make lvalue of each Index, Member operation |
|
|
|
points to the left variable |
|
|
|
points to the left variable |
|
|
@ -1776,7 +1760,7 @@ def remove_temporary(result): |
|
|
|
return result |
|
|
|
return result |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def remove_unused(result: List[Any]) -> List[Any]: |
|
|
|
def remove_unused(result: List[Operation]) -> List[Operation]: |
|
|
|
removed = True |
|
|
|
removed = True |
|
|
|
|
|
|
|
|
|
|
|
if not result: |
|
|
|
if not result: |
|
|
@ -1823,7 +1807,7 @@ def remove_unused(result: List[Any]) -> List[Any]: |
|
|
|
################################################################################### |
|
|
|
################################################################################### |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def convert_constant_types(irs: List[Any]) -> None: |
|
|
|
def convert_constant_types(irs: List[Operation]) -> None: |
|
|
|
""" |
|
|
|
""" |
|
|
|
late conversion of uint -> type for constant (Literal) |
|
|
|
late conversion of uint -> type for constant (Literal) |
|
|
|
:param irs: |
|
|
|
:param irs: |
|
|
@ -1899,7 +1883,7 @@ def convert_constant_types(irs: List[Any]) -> None: |
|
|
|
################################################################################### |
|
|
|
################################################################################### |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def convert_delete(irs: List[Any]) -> None: |
|
|
|
def convert_delete(irs: List[Operation]) -> None: |
|
|
|
""" |
|
|
|
""" |
|
|
|
Convert the lvalue of the Delete to point to the variable removed |
|
|
|
Convert the lvalue of the Delete to point to the variable removed |
|
|
|
This can only be done after find_references_origin is called |
|
|
|
This can only be done after find_references_origin is called |
|
|
@ -1935,7 +1919,7 @@ def _find_source_mapping_references(irs: List[Operation]) -> None: |
|
|
|
################################################################################### |
|
|
|
################################################################################### |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def apply_ir_heuristics(irs: List[Operation], node: "Node") -> List[Any]: |
|
|
|
def apply_ir_heuristics(irs: List[Operation], node: "Node") -> List[Operation]: |
|
|
|
""" |
|
|
|
""" |
|
|
|
Apply a set of heuristic to improve slithIR |
|
|
|
Apply a set of heuristic to improve slithIR |
|
|
|
""" |
|
|
|
""" |
|
|
|