Skip to content

Commit 04cb455

Browse files
authored
fix: add warnings when --width or --depth limits reached (#433)
1 parent 950bd2a commit 04cb455

File tree

4 files changed

+44
-24
lines changed

4 files changed

+44
-24
lines changed

src/halmos/__main__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ def setup(
423423
setup_timer = NamedTimer("setup")
424424
setup_timer.create_subtimer("decode")
425425

426-
sevm = SEVM(args)
426+
sevm = SEVM(args, setup_info)
427427
setup_ex = deploy_test(creation_hexcode, deployed_hexcode, sevm, args, libs, solver)
428428

429429
setup_timer.create_subtimer("run")
@@ -586,7 +586,7 @@ def run(
586586
# calldata
587587
#
588588

589-
sevm = SEVM(args)
589+
sevm = SEVM(args, fun_info)
590590
path = Path(solver)
591591
path.extend_path(setup_ex.path)
592592

@@ -742,6 +742,9 @@ def future_callback(future_model):
742742

743743
# 0 width is unlimited
744744
if args.width and idx >= args.width:
745+
warn(
746+
f"{funsig}: incomplete execution due to the specified limit: --width {args.width}"
747+
)
745748
break
746749

747750
num_execs = idx + 1

src/halmos/logs.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,6 @@
1515
logger = logging.getLogger("halmos")
1616

1717

18-
def debug(text: str) -> None:
19-
logger.debug(text)
20-
21-
22-
def info(text: str) -> None:
23-
logger.info(text)
24-
25-
26-
def warn(text: str) -> None:
27-
logger.warning(text)
28-
29-
30-
def error(text: str) -> None:
31-
logger.error(text)
32-
33-
3418
#
3519
# Logging with filtering out duplicate log messages
3620
#
@@ -51,8 +35,28 @@ def filter(self, record):
5135
logger_unique.addFilter(UniqueLoggingFilter())
5236

5337

38+
def logger_for(allow_duplicate=True) -> logging.Logger:
39+
return logger if allow_duplicate else logger_unique
40+
41+
42+
def debug(text: str, allow_duplicate=True) -> None:
43+
logger_for(allow_duplicate).debug(text)
44+
45+
46+
def info(text: str, allow_duplicate=True) -> None:
47+
logger_for(allow_duplicate).info(text)
48+
49+
50+
def warn(text: str, allow_duplicate=True) -> None:
51+
logger_for(allow_duplicate).warning(text)
52+
53+
54+
def error(text: str, allow_duplicate=True) -> None:
55+
logger_for(allow_duplicate).error(text)
56+
57+
5458
def debug_once(text: str) -> None:
55-
logger_unique.debug(text)
59+
debug(text, allow_duplicate=False)
5660

5761

5862
#
@@ -80,5 +84,5 @@ def url(self) -> str:
8084
LOOP_BOUND = ErrorCode("loop-bound")
8185

8286

83-
def warn_code(error_code: ErrorCode, msg: str):
84-
logger.warning(f"{msg}\n(see {error_code.url()})")
87+
def warn_code(error_code: ErrorCode, msg: str, allow_duplicate=True):
88+
logger_for(allow_duplicate).warning(f"{msg}\n(see {error_code.url()})")

src/halmos/sevm.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
from z3.z3util import is_expr_var
5858

5959
from .bytevec import ByteVec, Chunk, ConcreteChunk, UnwrappedBytes
60+
from .calldata import FunctionInfo
6061
from .cheatcodes import Prank, halmos_cheat_code, hevm_cheat_code
6162
from .config import Config as HalmosConfig
6263
from .console import console
@@ -1703,12 +1704,14 @@ def __len__(self) -> int:
17031704

17041705
class SEVM:
17051706
options: HalmosConfig
1707+
fun_info: FunctionInfo
17061708
storage_model: type[SomeStorage]
17071709
logs: HalmosLogs
17081710
steps: Steps
17091711

1710-
def __init__(self, options: HalmosConfig) -> None:
1712+
def __init__(self, options: HalmosConfig, fun_info: FunctionInfo) -> None:
17111713
self.options = options
1714+
self.fun_info = fun_info
17121715
self.logs = HalmosLogs()
17131716
self.steps: Steps = {}
17141717

@@ -2718,6 +2721,10 @@ def finalize(ex: Exec):
27182721
opcode = insn.opcode
27192722

27202723
if (max_depth := self.options.depth) and step_id > max_depth:
2724+
warn(
2725+
f"{self.fun_info.sig}: incomplete execution due to the specified limit: --depth {max_depth}",
2726+
allow_duplicate=False,
2727+
)
27212728
continue
27222729

27232730
# TODO: clean up

tests/test_fixtures.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22

33
from halmos.__main__ import mk_solver
4+
from halmos.calldata import FunctionInfo
45
from halmos.config import default_config
56
from halmos.sevm import SEVM
67

@@ -11,8 +12,13 @@ def args():
1112

1213

1314
@pytest.fixture
14-
def sevm(args):
15-
return SEVM(args)
15+
def fun_info():
16+
return FunctionInfo("test", "test()", "f8a8fd6d")
17+
18+
19+
@pytest.fixture
20+
def sevm(args, fun_info):
21+
return SEVM(args, fun_info)
1622

1723

1824
@pytest.fixture

0 commit comments

Comments
 (0)