Fix issues with out of index code (#1545)

pull/1547/head
Nikhil Parasaram 3 years ago committed by GitHub
parent 728d8a2dfc
commit 29738fef56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      mythril/laser/ethereum/state/global_state.py
  2. 10
      mythril/laser/plugin/plugins/coverage/coverage_plugin.py

@ -97,7 +97,7 @@ class GlobalState:
instructions = self.environment.code.instruction_list
try:
return instructions[self.mstate.pc]
except KeyError:
except IndexError:
return {"address": self.mstate.pc, "opcode": "STOP"}
@property

@ -49,7 +49,10 @@ class InstructionCoveragePlugin(LaserPlugin):
def stop_sym_exec_hook():
# Print results
for code, code_cov in self.coverage.items():
cov_percentage = sum(code_cov[1]) / float(code_cov[0]) * 100
if sum(code_cov[1]) == 0 and code_cov[0] == 0:
cov_percentage = 0
else:
cov_percentage = sum(code_cov[1]) / float(code_cov[0]) * 100
log.info(
"Achieved {:.2f}% coverage for code: {}".format(
@ -70,7 +73,10 @@ class InstructionCoveragePlugin(LaserPlugin):
number_of_instructions,
[False] * number_of_instructions,
)
if global_state.mstate.pc >= len(self.coverage[code][1]):
# Instruction beyond the instruction list are considered as STOP by EVM
# and can be ignored
return
self.coverage[code][1][global_state.mstate.pc] = True
@symbolic_vm.laser_hook("start_sym_trans")

Loading…
Cancel
Save