def test_delegate_call(sym_mock, concrete_mock, curr_instruction): # arrange # sym_mock = mocker.patch.object(delegatecall, "_symbolic_call") # concrete_mock = mocker.patch.object(delegatecall, "_concrete_call") sym_mock.return_value = [] concrete_mock.return_value = [] curr_instruction.return_value = {"address": "0x10"} active_account = Account("0x10") active_account.code = Disassembly("00") environment = Environment(active_account, None, None, None, None, None) state = GlobalState(None, environment, Node) state.mstate.memory = ["placeholder", "calldata_bling_0"] state.mstate.stack = [1, 2, 3] assert state.get_current_instruction() == {"address": "0x10"} node = Node("example") node.contract_name = "the contract name" node.function_name = "fallback" to = Variable("storage_1", VarType.SYMBOLIC) call = Call(node, state, None, "DELEGATECALL", to, None) statespace = MagicMock() statespace.calls = [call] # act execute(statespace) # assert assert concrete_mock.call_count == 1 assert sym_mock.call_count == 1
def execute_state(record: TaintRecord, state: GlobalState) -> TaintRecord: assert len(state.mstate.stack) == len(record.stack) """ Runs taint analysis on a state """ record.add_state(state) new_record = record.clone() # Apply Change op = state.get_current_instruction()["opcode"] if op in TaintRunner.stack_taint_table.keys(): mutator = TaintRunner.stack_taint_table[op] TaintRunner.mutate_stack(new_record, mutator) elif op.startswith("PUSH"): TaintRunner.mutate_push(op, new_record) elif op.startswith("DUP"): TaintRunner.mutate_dup(op, new_record) elif op.startswith("SWAP"): TaintRunner.mutate_swap(op, new_record) elif op is "MLOAD": TaintRunner.mutate_mload(new_record, state.mstate.stack[-1]) elif op.startswith("MSTORE"): TaintRunner.mutate_mstore(new_record, state.mstate.stack[-1]) elif op is "SLOAD": TaintRunner.mutate_sload(new_record, state.mstate.stack[-1]) elif op is "SSTORE": TaintRunner.mutate_sstore(new_record, state.mstate.stack[-1]) elif op.startswith("LOG"): TaintRunner.mutate_log(new_record, op) elif op in ("CALL", "CALLCODE", "DELEGATECALL", "STATICCALL"): TaintRunner.mutate_call(new_record, op) else: logging.debug("Unknown operation encountered: {}".format(op)) return new_record