Skip to content

Commit

Permalink
fix: add warnings when --width or --depth limits reached
Browse files Browse the repository at this point in the history
  • Loading branch information
daejunpark committed Jan 7, 2025
1 parent 950bd2a commit 4176b55
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 23 deletions.
7 changes: 5 additions & 2 deletions src/halmos/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def setup(
setup_timer = NamedTimer("setup")
setup_timer.create_subtimer("decode")

sevm = SEVM(args)
sevm = SEVM(args, setup_info)
setup_ex = deploy_test(creation_hexcode, deployed_hexcode, sevm, args, libs, solver)

setup_timer.create_subtimer("run")
Expand Down Expand Up @@ -586,7 +586,7 @@ def run(
# calldata
#

sevm = SEVM(args)
sevm = SEVM(args, fun_info)
path = Path(solver)
path.extend_path(setup_ex.path)

Expand Down Expand Up @@ -742,6 +742,9 @@ def future_callback(future_model):

# 0 width is unlimited
if args.width and idx >= args.width:
warn(
f"{funsig}: paths have not been fully explored due to: --width {args.width}"
)
break

num_execs = idx + 1
Expand Down
42 changes: 23 additions & 19 deletions src/halmos/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,6 @@
logger = logging.getLogger("halmos")


def debug(text: str) -> None:
logger.debug(text)


def info(text: str) -> None:
logger.info(text)


def warn(text: str) -> None:
logger.warning(text)


def error(text: str) -> None:
logger.error(text)


#
# Logging with filtering out duplicate log messages
#
Expand All @@ -51,8 +35,28 @@ def filter(self, record):
logger_unique.addFilter(UniqueLoggingFilter())


def logger_for(allow_duplicate=True) -> logging.Logger:
return logger if allow_duplicate else logger_unique


def debug(text: str, allow_duplicate=True) -> None:
logger_for(allow_duplicate).debug(text)


def info(text: str, allow_duplicate=True) -> None:
logger_for(allow_duplicate).info(text)


def warn(text: str, allow_duplicate=True) -> None:
logger_for(allow_duplicate).warning(text)


def error(text: str, allow_duplicate=True) -> None:
logger_for(allow_duplicate).error(text)


def debug_once(text: str) -> None:
logger_unique.debug(text)
debug(text, allow_duplicate=False)


#
Expand Down Expand Up @@ -80,5 +84,5 @@ def url(self) -> str:
LOOP_BOUND = ErrorCode("loop-bound")


def warn_code(error_code: ErrorCode, msg: str):
logger.warning(f"{msg}\n(see {error_code.url()})")
def warn_code(error_code: ErrorCode, msg: str, allow_duplicate=True):
logger_for(allow_duplicate).warning(f"{msg}\n(see {error_code.url()})")
9 changes: 8 additions & 1 deletion src/halmos/sevm.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
from z3.z3util import is_expr_var

from .bytevec import ByteVec, Chunk, ConcreteChunk, UnwrappedBytes
from .calldata import FunctionInfo
from .cheatcodes import Prank, halmos_cheat_code, hevm_cheat_code
from .config import Config as HalmosConfig
from .console import console
Expand Down Expand Up @@ -1703,12 +1704,14 @@ def __len__(self) -> int:

class SEVM:
options: HalmosConfig
fun_info: FunctionInfo
storage_model: type[SomeStorage]
logs: HalmosLogs
steps: Steps

def __init__(self, options: HalmosConfig) -> None:
def __init__(self, options: HalmosConfig, fun_info: FunctionInfo) -> None:
self.options = options
self.fun_info = fun_info
self.logs = HalmosLogs()
self.steps: Steps = {}

Expand Down Expand Up @@ -2718,6 +2721,10 @@ def finalize(ex: Exec):
opcode = insn.opcode

if (max_depth := self.options.depth) and step_id > max_depth:
warn(
f"{self.fun_info.sig}: paths have not been fully explored due to: --depth {max_depth}",
allow_duplicate=False,
)
continue

# TODO: clean up
Expand Down
2 changes: 1 addition & 1 deletion tests/test_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def args():

@pytest.fixture
def sevm(args):
return SEVM(args)
return SEVM(args, None)


@pytest.fixture
Expand Down

0 comments on commit 4176b55

Please sign in to comment.