Skip to content

Commit

Permalink
Make is_human a property (#1323)
Browse files Browse the repository at this point in the history
* Make is_human a property

* Update manticore/platforms/evm.py

* Better docstring
  • Loading branch information
disconnect3d committed Jan 7, 2019
1 parent b7f9a46 commit f349adb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
10 changes: 5 additions & 5 deletions manticore/ethereum/detectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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())

Expand Down
2 changes: 1 addition & 1 deletion manticore/ethereum/manticore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 12 additions & 1 deletion manticore/platforms/evm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit f349adb

Please sign in to comment.