Add dynamic timeout presets

dynamic_timeout_presets
Bernhard Mueller 6 years ago
parent 770b964340
commit 68041ef123
  1. 7
      mythril/exceptions.py
  2. 16
      mythril/interfaces/cli.py
  3. 17
      mythril/support/dynamic_timeout.py

@ -39,3 +39,10 @@ class AddressNotFoundError(MythrilBaseException):
found.""" found."""
pass pass
class UnsupportedModeError(MythrilBaseException):
"""A Mythril exception denoting an unsupported dynamic timeout mode
constraints."""
pass

@ -15,6 +15,7 @@ import coloredlogs
import traceback import traceback
import mythril.support.signatures as sigs import mythril.support.signatures as sigs
from mythril.support import dynamic_timeout
from mythril.exceptions import AddressNotFoundError, CriticalError from mythril.exceptions import AddressNotFoundError, CriticalError
from mythril.mythril import ( from mythril.mythril import (
MythrilAnalyzer, MythrilAnalyzer,
@ -217,6 +218,11 @@ def create_parser(parser: argparse.ArgumentParser) -> None:
default=86400, default=86400,
help="The amount of seconds to spend on symbolic execution", help="The amount of seconds to spend on symbolic execution",
) )
options.add_argument(
"--dynamic-timeout",
choices=["fast", "deep"],
help="Choose timeout dynamically for fast or extensive analysis",
)
options.add_argument( options.add_argument(
"--create-timeout", "--create-timeout",
type=int, type=int,
@ -401,12 +407,20 @@ def execute_command(
print(storage) print(storage)
return return
if args.dynamic_timeout:
timeout = dynamic_timeout.get_timeout(
len(disassembler.contracts[0].creation_code), args.dynamic_timeout
)
else:
timeout = args.execution_timeout
log.debug("Set dynamic execution timeout: {}".format(timeout))
analyzer = MythrilAnalyzer( analyzer = MythrilAnalyzer(
strategy=args.strategy, strategy=args.strategy,
disassembler=disassembler, disassembler=disassembler,
address=address, address=address,
max_depth=args.max_depth, max_depth=args.max_depth,
execution_timeout=args.execution_timeout, execution_timeout=timeout,
create_timeout=args.create_timeout, create_timeout=args.create_timeout,
enable_iprof=args.enable_iprof, enable_iprof=args.enable_iprof,
onchain_storage_access=not args.no_onchain_storage_access, onchain_storage_access=not args.no_onchain_storage_access,

@ -0,0 +1,17 @@
from math import exp
from mythril.exceptions import UnsupportedModeError
def get_timeout(bytecode_length: int, mode: str) -> int:
"""
Returns a dynamically calculated timeout based on the length of the bytecode string.
:param bytecode_length: Length of the bytecode: len("0x....")
:param mode: Preset mode (fast or deep)
"""
if mode == "fast":
return int(min(120, 15 * exp(bytecode_length / 6000)))
elif mode == "deep":
return int(min(3600, 30 * exp(bytecode_length / 3000)))
raise UnsupportedModeError
Loading…
Cancel
Save