From f349adb50a7ece77e3a3ed27842e08b461abafb9 Mon Sep 17 00:00:00 2001 From: Disconnect3d Date: Mon, 7 Jan 2019 17:52:17 +0100 Subject: [PATCH] Make is_human a property (#1323) * Make is_human a property * Update manticore/platforms/evm.py * Better docstring --- manticore/ethereum/detectors.py | 10 +++++----- manticore/ethereum/manticore.py | 2 +- manticore/platforms/evm.py | 13 ++++++++++++- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/manticore/ethereum/detectors.py b/manticore/ethereum/detectors.py index 5e372b61d..adfd9d935 100644 --- a/manticore/ethereum/detectors.py +++ b/manticore/ethereum/detectors.py @@ -217,7 +217,7 @@ def _context_key(self): return f'{self.name}.call_locations' def will_open_transaction_callback(self, state, tx): - if tx.is_human(): + if tx.is_human: state.context[self._context_key] = [] def will_evm_execute_instruction_callback(self, state, instruction, arguments): @@ -277,14 +277,14 @@ def _read_storage_name(self): def will_open_transaction_callback(self, state, tx): # Reset reading log on new human transactions - if tx.is_human(): + if tx.is_human: state.context[self._read_storage_name] = set() state.context['{:s}.locations'.format(self.name)] = dict() def did_close_transaction_callback(self, state, tx): world = state.platform #Check if it was an internal tx - if not tx.is_human(): + if not tx.is_human: # Check is the tx was successful if tx.result: # Check if gas was enough for a reentrancy attack @@ -482,7 +482,7 @@ def did_evm_execute_instruction_callback(self, state, instruction, arguments, re self._check_finding(state, what) elif mnemonic == 'RETURN': world = state.platform - if world.current_transaction.is_human(): + if world.current_transaction.is_human: # If an overflowded value is returned to a human offset, size = arguments data = world.current_vm.read_buffer(offset, size) @@ -528,7 +528,7 @@ def _get_retval_taints(self, state): def will_open_transaction_callback(self, state, tx): # Reset reading log on new human transactions - if tx.is_human(): + if tx.is_human: state.context[self._stack_name] = [] state.context[self._stack_name].append(set()) diff --git a/manticore/ethereum/manticore.py b/manticore/ethereum/manticore.py index 3ffa9959f..8864589f8 100644 --- a/manticore/ethereum/manticore.py +++ b/manticore/ethereum/manticore.py @@ -1175,7 +1175,7 @@ def _terminate_state_callback(self, state, state_id, e): #we initiated the Tx; we need process the outcome for now. #Fixme incomplete. - if tx.is_human(): + if tx.is_human: if tx.sort == 'CREATE': if tx.result == 'RETURN': world.set_code(tx.address, tx.return_data) diff --git a/manticore/platforms/evm.py b/manticore/platforms/evm.py index 898445457..0b739ba37 100644 --- a/manticore/platforms/evm.py +++ b/manticore/platforms/evm.py @@ -197,7 +197,18 @@ def sort(self, sort): def result(self): return self._result + @property def is_human(self): + """ + Returns whether this is a transaction made by human (in a script). + + As an example for: + contract A { function a(B b) { b.b(); } } + contract B { function b() {} } + + Calling `B.b()` makes a human transaction. + Calling `A.a(B)` makes a human transaction which makes an internal transaction (b.b()). + """ return self.depth == 0 @property @@ -1867,7 +1878,7 @@ def _close_transaction(self, result, data=None, rollback=False): # Increment the nonce if this transaction created a contract, or if it was called by a non-contract account self.increase_nonce(tx.caller) - if tx.is_human(): + if tx.is_human: for deleted_account in self._deleted_accounts: if deleted_account in self._world_state: del self._world_state[deleted_account]