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

Removed use of global solver from Memory #2414

Merged
merged 2 commits into from
Mar 26, 2021
Merged

Conversation

ggrieco-tob
Copy link
Contributor

@ggrieco-tob ggrieco-tob commented Mar 26, 2021

The Memory class had a global solver hard-coded that resulted in z3 (or the solver the user has installed) always used when a native binary was executed. This PR should fix that.

@ekilmer
Copy link
Contributor

ekilmer commented Mar 26, 2021

global solver hard-coded that resulted in z3

I just run the following locally with yices installed through my system and SelectedSolver.instance() returns YicesSolver

$ python
Python 3.6.13 (default, Feb 22 2021, 12:20:57)
[GCC 10.2.1 20201125 (Red Hat 10.2.1-9)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from manticore.core.smtlib import SelectedSolver
>>> solver = SelectedSolver.instance()
>>> solver
<manticore.core.smtlib.solver.YicesSolver object at 0x7f51d999ee48>

I also tried inspecting the global solver itself and still got YicesSolver

$ python
Python 3.6.13 (default, Feb 22 2021, 12:20:57)
[GCC 10.2.1 20201125 (Red Hat 10.2.1-9)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from manticore.native.memory import solver
>>> solver
<manticore.core.smtlib.solver.YicesSolver object at 0x7fa727dbc780>

Am I missing something?

@ggrieco-tob
Copy link
Contributor Author

If you apply this patch:

diff --git a/manticore/core/smtlib/solver.py b/manticore/core/smtlib/solver.py
index 7e61217..208cfd3 100644
--- a/manticore/core/smtlib/solver.py
+++ b/manticore/core/smtlib/solver.py
@@ -761,4 +761,5 @@ class SelectedSolver:
             cls.choice = consts.solver
 
         SelectedSolver = {"cvc4": CVC4Solver, "yices": YicesSolver, "z3": Z3Solver}[cls.choice.name]
+        print("Calling instance() with cls.choice =", cls.choice)
         return SelectedSolver.instance()

you can see that running anything using the manticore cli will print Calling instance() with cls.choice = SolverType.z3 then it will use any other solver you specify (for instance, using --smt.solver cvc4 will still print that line).

@ekilmer
Copy link
Contributor

ekilmer commented Mar 26, 2021

Ahh, okay, yes I see that now.

I think there's a bigger issue with the CLI options not getting parsed correctly. I'm currently looking into it.

Edit: Maybe not.

Copy link
Contributor

@ekilmer ekilmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay! I think I finally understand what's going on here...

The global solver instance is initialized incorrectly because it calls SelectedSolver.instance() before we've parsed the command line flags, due to execution upon import, and so if someone chooses to use a particular solver, it will be ignored for these global instances.

Thank you!

manticore/native/memory.py Show resolved Hide resolved
Copy link
Contributor

@ekilmer ekilmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!!

@ggrieco-tob
Copy link
Contributor Author

This looks ready to merge, but again I can't do it since one check (CI / upload) was skipped. Can you merge it @ekilmer ?

@ekilmer ekilmer merged commit 9bfb3ac into master Mar 26, 2021
@ekilmer ekilmer deleted the dev-no-global-solver branch March 26, 2021 21:42
ekilmer added a commit that referenced this pull request Apr 7, 2021
* master:
  Removed use of global solver from Native Memory (#2414)
  Support to use boolector as the SMT solver (#2410)
  Update CI and suggest to use pip3 instead of pip (#2409)
  Expressions use keyword-only arguments for init (#2395)
  Use Slots on all Expression objects (#2394)
  Allow double-adding exact same config option (#2397)
  Don't run OSX tests on PR
  Attempt to Fix solc Installation MacOS (#2392)
  Syscall specific hooks (#2389)
  TUI Support Infrastructure (#1620)
  Fix coveralls upload (#2387)
  docs: fix simple typo, straigth -> straight (#2381)
  Attempt to allow symbolic balances from the start (#1818)
  Fix state.cpu.PC member (#1825)
  Bump black and mypy (#1824)
ekilmer added a commit that referenced this pull request Apr 10, 2021
* master: (22 commits)
  Fix the generation of EVM tests (#2426)
  Disabled EVM events in testcases by default (#2417)
  added proper timeouts for cvc4 and boolector (#2418)
  Removed use of global solver from Native Memory (#2414)
  Support to use boolector as the SMT solver (#2410)
  Update CI and suggest to use pip3 instead of pip (#2409)
  Expressions use keyword-only arguments for init (#2395)
  Use Slots on all Expression objects (#2394)
  Allow double-adding exact same config option (#2397)
  Don't run OSX tests on PR
  Attempt to Fix solc Installation MacOS (#2392)
  Syscall specific hooks (#2389)
  TUI Support Infrastructure (#1620)
  Fix coveralls upload (#2387)
  docs: fix simple typo, straigth -> straight (#2381)
  Attempt to allow symbolic balances from the start (#1818)
  Fix state.cpu.PC member (#1825)
  Bump black and mypy (#1824)
  Manticore 0.3.5 (#1808)
  Fix yices timeout argument (#1817)
  ...
ekilmer added a commit that referenced this pull request Jul 27, 2021
* master: (35 commits)
  Track last_pc in StateDescriptors (#2471)
  Expose Result Register for Native CPU (#2470)
  Install pinned version of truffle to fix CI (#2467)
  Use fixed owner and attacker accounts in multi_tx_analysis (#2464)
  Manticore 0.3.6 (#2456)
  Fix IntrospectionAPIPlugin Name (#2459)
  Portfolio of parallel solvers (#2420)
  Replace Quick mode with Thorough mode (#2457)
  Fix incorrect comparison for symbolic file wildcards (#2454)
  Reduce the number of calls to the SMT solver in EVM (#2411)
  Fixes to Unicorn emulation - start/stop/resume (#1796)
  Add support for multiple compilation units (#2444)
  Basic solver stats (#2415)
  Fix the generation of EVM tests (#2426)
  Disabled EVM events in testcases by default (#2417)
  added proper timeouts for cvc4 and boolector (#2418)
  Removed use of global solver from Native Memory (#2414)
  Support to use boolector as the SMT solver (#2410)
  Update CI and suggest to use pip3 instead of pip (#2409)
  Expressions use keyword-only arguments for init (#2395)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants