Skip to content

Commit

Permalink
adjust halmos_var_pattern to support p_ prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
karmacoma-eth committed Jan 9, 2025
1 parent 9a5d5ea commit af18025
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 17 deletions.
16 changes: 8 additions & 8 deletions src/halmos/solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ class ModelVariable:
# Regular expression for capturing halmos variables
halmos_var_pattern = re.compile(
r"""
\(\s*define-fun\s+ # Match "(define-fun"
\|?(halmos_[^ |]+)\|?\s+ # Capture the full variable name, optionally wrapped in "|"
\(\)\s+\(_\s+([^ ]+)\s+ # Capture the SMTLIB type (e.g., "BitVec 256")
(\d+)\)\s+ # Capture the bit-width or type argument
( # Group for the value
\#b[01]+ # Binary value (e.g., "#b1010")
|\#x[0-9a-fA-F]+ # Hexadecimal value (e.g., "#xFF")
|\(_\s+bv\d+\s+\d+\) # Decimal value (e.g., "(_ bv42 256)")
\(\s*define-fun\s+ # Match "(define-fun"
\|?((?:halmos_|p_)[^ |]+)\|?\s+ # Capture either halmos_* or p_*, optionally wrapped in "|"
\(\)\s+\(_\s+([^ ]+)\s+ # Capture the SMTLIB type (e.g., "BitVec 256")
(\d+)\)\s+ # Capture the bit-width or type argument
( # Group for the value
\#b[01]+ # Binary value (e.g., "#b1010")
|\#x[0-9a-fA-F]+ # Hexadecimal value (e.g., "#xFF")
|\(_\s+bv\d+\s+\d+\) # Decimal value (e.g., "(_ bv42 256)")
)
""",
re.VERBOSE,
Expand Down
43 changes: 34 additions & 9 deletions tests/test_solve.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import pytest

from halmos.solve import ModelVariable, parse_model_str


def test_smtlib_z3_bv_output():
full_name = "halmos_y_uint256_043cfd7_01"
@pytest.mark.parametrize(
"full_name",
[
"halmos_y_uint256_043cfd7_01",
"p_y_uint256_043cfd7_01",
],
)
def test_smtlib_z3_bv_output(full_name):
smtlib_str = f"""
(define-fun {full_name} () (_ BitVec 256)
#x0000000000000000000000000000000000000000000000000000000000000000)
Expand All @@ -21,8 +29,14 @@ def test_smtlib_z3_bv_output():

# note that yices only produces output like this with --smt2-model-format
# otherwise we get something like (= x #b00000100)
def test_smtlib_yices_binary_output():
full_name = "halmos_z_uint256_cabf047_02"
@pytest.mark.parametrize(
"full_name",
[
"halmos_z_uint256_cabf047_02",
"p_z_uint256_cabf047_02",
],
)
def test_smtlib_yices_binary_output(full_name):
smtlib_str = f"""
(define-fun
{full_name}
Expand All @@ -41,8 +55,14 @@ def test_smtlib_yices_binary_output():
)


def test_smtlib_yices_decimal_output():
full_name = "halmos_z_uint256_11ce021_08"
@pytest.mark.parametrize(
"full_name",
[
"halmos_z_uint256_11ce021_08",
"p_z_uint256_11ce021_08",
],
)
def test_smtlib_yices_decimal_output(full_name):
val = 57896044618658097711785492504343953926634992332820282019728792003956564819968
smtlib_str = f"""
(define-fun {full_name} () (_ BitVec 256) (_ bv{val} 256))
Expand All @@ -58,9 +78,14 @@ def test_smtlib_yices_decimal_output():
)


def test_smtlib_stp_output():
full_name = "halmos_x_uint8_043cfd7_01"

@pytest.mark.parametrize(
"full_name",
[
"halmos_x_uint8_043cfd7_01",
"p_x_uint8_043cfd7_01",
],
)
def test_smtlib_stp_output(full_name):
# we should tolerate:
# - the extra (model) command
# - duplicate variable names
Expand Down

0 comments on commit af18025

Please sign in to comment.