Skip to content

Commit

Permalink
Handle OOG during CALL (#1675)
Browse files Browse the repository at this point in the history
  • Loading branch information
norhh authored Sep 3, 2022
1 parent 427d40e commit 73aa52d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
8 changes: 6 additions & 2 deletions mythril/analysis/module/modules/unchecked_retval.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,13 @@ def _analyze_state(self, state: GlobalState) -> list:
return issues
else:
log.debug("End of call, extracting retval")
assert state.environment.code.instruction_list[state.mstate.pc - 1][

if state.environment.code.instruction_list[state.mstate.pc - 1][
"opcode"
] in ["CALL", "DELEGATECALL", "STATICCALL", "CALLCODE"]
] not in ["CALL", "DELEGATECALL", "STATICCALL", "CALLCODE"]:
# Return is pointless with OOG. The pc does not get updated in such cases
return []

return_value = state.mstate.stack[-1]
retvals.append(
{"address": state.instruction["address"] - 1, "retval": return_value}
Expand Down
5 changes: 1 addition & 4 deletions mythril/laser/ethereum/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ def get_callee_address(
log.debug("Symbolic call encountered")

match = re.search(r"Storage\[(\d+)\]", str(simplify(symbolic_to_address)))
log.debug("CALL to: " + str(simplify(symbolic_to_address)))

if match is None or dynamic_loader is None:
return symbolic_to_address
Expand Down Expand Up @@ -190,9 +189,7 @@ def get_call_data(
]
return ConcreteCalldata(transaction_id, calldata_from_mem)
except TypeError:
log.debug(
"Unsupported symbolic memory offset %s size %s", memory_start, memory_size
)
log.debug("Unsupported symbolic memory offset and size")
return SymbolicCalldata(transaction_id)


Expand Down
3 changes: 2 additions & 1 deletion mythril/laser/ethereum/instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2010,6 +2010,7 @@ def call_(self, global_state: GlobalState) -> List[GlobalState]:
log.debug("The call is related to ether transfer between accounts")
sender = environment.active_account.address
receiver = callee_account.address

transfer_ether(global_state, sender, receiver, value)
self._write_symbolic_returndata(
global_state, memory_out_offset, memory_out_size
Expand Down Expand Up @@ -2254,11 +2255,11 @@ def delegatecall_(self, global_state: GlobalState) -> List[GlobalState]:
log.debug("The call is related to ether transfer between accounts")
sender = global_state.environment.active_account.address
receiver = callee_account.address

transfer_ether(global_state, sender, receiver, value)
self._write_symbolic_returndata(
global_state, memory_out_offset, memory_out_size
)

global_state.mstate.stack.append(
global_state.new_bitvec("retval_" + str(instr["address"]), 256)
)
Expand Down
1 change: 1 addition & 0 deletions mythril/laser/ethereum/svm.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ def execute_state(

new_global_states = []
else:

# First execute the post hook for the transaction ending instruction
self._execute_post_hook(op_code, [end_signal.global_state])

Expand Down

0 comments on commit 73aa52d

Please sign in to comment.