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

feat: cache unsat queries using unsat core #311

Merged
merged 22 commits into from
Jun 25, 2024
Merged

feat: cache unsat queries using unsat core #311

merged 22 commits into from
Jun 25, 2024

Conversation

daejunpark
Copy link
Collaborator

@daejunpark daejunpark commented Jun 24, 2024

this pr implements a solver caching feature by utilizing the unsat core.

the key idea: when a query contains a known unsat core, it is also unsat, thus no need to run the smt solver.

when --cache-solver is enabled, the smt solver is asked to compute the unsat core for unsat queries. subsequent queries are then compared with the previously computed unsat cores before being sent to the solver, allowing us to skip solving if they have already been known as unsat.

caching is particularly beneficial when there are many similar paths. since similar paths may share the same unsat core, they can be discharged after only a single solving, rather than repeating the same solving process.

for example, in the snekmate erc721 test, the runtime reduces from 477.48s to 295.95s:

  • without caching:
# of potential paths involving assertion violations: 130 / 238  (--solver-threads 8)
[PASS] testHalmosAssertNoBackdoor(...) (paths: 238, time: 477.48s (paths: 166.15s, models: 311.33s), bounds: [])
  • with caching:
# of potential paths involving assertion violations: 127 / 234  (--solver-threads 8)
[PASS] testHalmosAssertNoBackdoor(...) (paths: 234, time: 295.95s (paths: 208.52s, models: 87.43s), bounds: [])

note: computing unsat cores incurs a performance overhead, so caching may not be beneficial for small tests.

@daejunpark daejunpark force-pushed the feat/unsat-core branch 3 times, most recently from 79718a1 to 0f76f96 Compare June 24, 2024 09:49
@daejunpark daejunpark merged commit 96aa5ec into main Jun 25, 2024
53 checks passed
@daejunpark daejunpark deleted the feat/unsat-core branch June 25, 2024 18:09
@daejunpark daejunpark requested a review from karmacoma-eth June 25, 2024 18:09
with open(dump_filename, "w") as f:
if args.verbose >= 1:
print(f"Writing SMT query to {dump_filename}")
if args.cache_solver:
f.write("(set-option :produce-unsat-cores true)\n")
Copy link
Collaborator

Choose a reason for hiding this comment

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

is that a z3 specific option?

Copy link
Collaborator

Choose a reason for hiding this comment

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

TIL: no it's not!

@karmacoma-eth
Copy link
Collaborator

this is actually very impressive, hot damn

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