Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollback to support yices again #1714

Merged
merged 33 commits into from
Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
165bb47
Rollback to support yices again
feliam May 21, 2020
c43036a
CC
feliam May 21, 2020
9cb8ae3
Test yices
feliam May 21, 2020
69337d0
Better get-value handling
feliam May 21, 2020
b4c899d
Z3/CVC4/YICES
feliam May 22, 2020
09b0374
CC
feliam May 23, 2020
0649f85
Yices/CVC4
feliam May 26, 2020
2af40be
CC
feliam May 26, 2020
57aa187
Default yices
feliam May 26, 2020
0cdbaed
Default debug level fix
feliam May 26, 2020
5c17309
Quick auto solver
feliam May 26, 2020
a92cb6e
shutil.which
feliam May 26, 2020
3d91266
CC
feliam May 26, 2020
60e020b
Default yices for testing
feliam May 27, 2020
afcd693
Remove old commented out code
feliam May 27, 2020
20f846d
Update manticore/core/smtlib/solver.py
feliam May 28, 2020
a60a6e7
Update manticore/core/smtlib/solver.py
feliam May 28, 2020
82f2f88
Merge branch 'dev-yikes' of github.com:trailofbits/manticore into dev…
feliam May 28, 2020
e4e3a65
Remove unused class
feliam May 28, 2020
af19863
Update manticore/core/smtlib/solver.py
feliam May 28, 2020
3061b7c
Update manticore/core/smtlib/solver.py
feliam May 28, 2020
38c888b
Readme hack
feliam May 28, 2020
9c27f1c
Merge branch 'dev-yikes' of github.com:trailofbits/manticore into dev…
feliam May 28, 2020
6db6e77
CC/lint
feliam May 28, 2020
3e68a85
Fix typing
feliam May 28, 2020
5a97426
z3 back to the rodeo
feliam May 29, 2020
3ddb5b6
lint
feliam Jun 2, 2020
744dfde
Merge branch 'master' into dev-yikes
feliam Jun 2, 2020
2391ca1
Fancy optimize
feliam Jun 2, 2020
07a8b40
Merge branch 'master' into dev-yikes
feliam Jun 4, 2020
05071bf
Fix lint
feliam Jun 5, 2020
8a3c6c0
Merge branch 'master' into dev-yikes
feliam Jun 9, 2020
3f11904
CC reviewed
feliam Jun 9, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 37 additions & 5 deletions manticore/core/smtlib/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
from ...utils.resources import check_memory_usage, check_disk_usage
from . import issymbolic

class SolverType(config.ConfigEnum):
"""Used as configuration constant for choosing solver flavor"""
z3 = "z3"
cvc4 = "cvc4"
yices = "yices"
auto = "auto"

logger = logging.getLogger(__name__)
consts = config.get_group("smt")
consts.add("timeout", default=240, description="Timeout, in seconds, for each Z3 invocation")
Expand All @@ -41,14 +48,18 @@
default=10000,
description="Maximum solutions to provide when solving for all values",
)
consts.add("z3_bin", default="z3", description="Z3 binary to use")
consts.add("z3_bin", default="z3", description="Z3 solver binary to use")
consts.add("cvc4_bin", default="cvc4", description="CVC4 solver binary to use")
consts.add("yices_bin", default="yices-smt2", description="Yices solver binary to use")


consts.add("defaultunsat", default=True, description="Consider solver timeouts as unsat core")
consts.add(
"optimize", default=True, description="Use smtlib command optimize to find min/max if available"
)

consts.add(
"solver", default="yices", description="Choose default smtlib2 solver (z3, yices, cvc4, race)"
"solver", default=SolverType.auto, description="Choose default smtlib2 solver (z3, yices, cvc4, race)"
)

# Regular expressions used by the solver
Expand Down Expand Up @@ -724,7 +735,7 @@ def _solver_version(self) -> Version:
class YicesSolver(SMTLIBSolver):
def __init__(self):
init = ["(set-logic QF_AUFBV)"]
command = f"yices-smt2 --timeout={consts.timeout * 1000} --incremental"
command = f"{consts.yices_bin} --timeout={consts.timeout * 1000} --incremental"
super().__init__(
command=command,
init=init,
Expand All @@ -738,7 +749,7 @@ def __init__(self):
class CVC4Solver(SMTLIBSolver):
def __init__(self):
init = ["(set-logic QF_AUFBV)", "(set-option :produce-models true)"]
command = f"cvc4 --lang=smt2 --incremental"
command = f"{consts.cvc4_bin} --lang=smt2 --incremental"
super().__init__(command=command, value_fmt=10, init=init)


Expand Down Expand Up @@ -773,5 +784,26 @@ def thread(solver):
t.join()
return result

class SelectedSolver:
choice = None

@classmethod
def instance(cls):
if consts.solver == consts.solver.auto:
if cls.choice is None:
if os.path.exists(consts.yices_bin):
cls.choice = consts.solver.yices
elif os.path.exists(consts.z3_bin):
cls.choice = consts.solver.z3
elif os.path.exists(consts.cvc4_bin):
cls.choice = consts.solver.cvc4
ekilmer marked this conversation as resolved.
Show resolved Hide resolved
else:
raise SolverException(f"No Solver not found. Install one ({const.yices_bin}, {consts.z3_bin}, {consts.cvc4_bin}).")
else:
cls.choice = consts.solver

SelectedSolver = {"cvc4": CVC4Solver, "yices": YicesSolver, "z3": Z3Solver}[cls.choice.name]
print ("Using", SelectedSolver)
return SelectedSolver.instance()


SelectedSolver = {"cvc4": CVC4Solver, "yices": YicesSolver, "z3": Z3Solver}[consts.solver]
10 changes: 10 additions & 0 deletions manticore/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@
class ConfigError(Exception):
pass

class ConfigEnum(Enum):
"""Used as configuration constant for choosing flavors"""

def title(self):
return self._name_.title()

@classmethod
def from_string(cls, name):
return cls.__members__[name]


class _Var:
def __init__(self, name: str = "", default=None, description: str = None, defined: bool = True):
Expand Down
3 changes: 2 additions & 1 deletion manticore/wasm/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

from ..core.smtlib.solver import SelectedSolver

solver = SelectedSolver.instance()


logger = logging.getLogger(__name__)
# logger.setLevel(logging.DEBUG)
Expand Down Expand Up @@ -732,6 +732,7 @@ def __setstate__(self, state):

def _eval_maybe_symbolic(constraints, expression) -> bool:
if issymbolic(expression):
solver = SelectedSolver.instance()
return solver.must_be_true(constraints, expression)
return True if expression else False

Expand Down