def arbitrary_send(func: Function): if func.is_protected(): return [] ret: List[Node] = [] for node in func.nodes: for ir in node.irs: if isinstance(ir, SolidityCall): if ir.function == SolidityFunction("ecrecover(bytes32,uint8,bytes32,bytes32)"): return False if isinstance(ir, Index): if ir.variable_right == SolidityVariableComposed("msg.sender"): return False if is_dependent( ir.variable_right, SolidityVariableComposed("msg.sender"), func.contract, ): return False if isinstance(ir, (HighLevelCall, LowLevelCall, Transfer, Send)): if isinstance(ir, (HighLevelCall)): if isinstance(ir.function, Function): if ir.function.full_name == "transferFrom(address,address,uint256)": return False if ir.call_value is None: continue if ir.call_value == SolidityVariableComposed("msg.value"): continue if is_dependent( ir.call_value, SolidityVariableComposed("msg.value"), func.contract, ): continue if is_tainted(ir.destination, func.contract): ret.append(node) return ret
def compute_dependency_function(function: Function) -> None: if KEY_SSA in function.context: return function.context[KEY_SSA] = {} function.context[KEY_SSA_UNPROTECTED] = {} is_protected = function.is_protected() for node in function.nodes: for ir in node.irs_ssa: if isinstance(ir, OperationWithLValue) and ir.lvalue: if isinstance(ir.lvalue, LocalIRVariable) and ir.lvalue.is_storage: continue if isinstance(ir.lvalue, ReferenceVariable): lvalue = ir.lvalue.points_to if lvalue: add_dependency(lvalue, function, ir, is_protected) add_dependency(ir.lvalue, function, ir, is_protected) function.context[KEY_NON_SSA] = convert_to_non_ssa( function.context[KEY_SSA]) function.context[KEY_NON_SSA_UNPROTECTED] = convert_to_non_ssa( function.context[KEY_SSA_UNPROTECTED])