-
Notifications
You must be signed in to change notification settings - Fork 62
Move unsat cache to Solvers.hs
#743
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
base: main
Are you sure you want to change the base?
Conversation
44ffb79
to
b5c76f9
Compare
Can |
But we are already using it: -- Dispatch the remaining branches to the solver to check for violations
--
results <- withRunInIO $ \env -> flip mapConcurrently withQueries $ \(query, leaf) -> do
res <- env $ checkSatWithProps solvers query
when conf.debug $ putStrLn $ " SMT result: " <> show (fst res)
pure (fst res, leaf) In fact, I made |
b5c76f9
to
589331a
Compare
63c8e81
to
d5f2d0e
Compare
@gustavo-grieco Basically, this PR is meant to replace all that cache in |
b84fda4
to
e5b383c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, though I am wondering: How is this going to work? Wouldn't all SMT queries be put in the queue before the requests to add results to the cache?
Have you checked that this is working as expected?
It certainly needs to be thought through. It does work sometimes for sure, but I agree that this needs more scrutiny. I wanna see how the ordering is done in this queue. |
I actually figured out why FIFO is correct for the equivalence checker! Kinda crazy. So: So this:
Creates e.g. 5 processes. Then immediately run 5 elements from What we need is a cache task channel that is priority, and does not block :) |
This is now ready for re-review. @blishko maybe you can take a peek? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good!
I would still like to play with it a bit before we merge it.
src/EVM/SymExec.hs
Outdated
do | ||
when conf.debug $ liftIO $ putStrLn " Simplifying expression" | ||
let expr = if opts.simp then (Expr.simplify exprInter) else exprInter | ||
when conf.dumpExprs $ T.writeFile "simplified.expr" (formatExpr expr) | ||
when conf.dumpExprs $ T.writeFile "simplified-conc.expr" (formatExpr $ Expr.simplify $ mapExpr Expr.concKeccakOnePass expr) | ||
when conf.dumpExprs $ liftIO $ T.writeFile "simplified.expr" (formatExpr expr) | ||
when conf.dumpExprs $ liftIO $ T.writeFile "simplified-conc.expr" (formatExpr $ Expr.simplify $ mapExpr Expr.concKeccakOnePass expr) | ||
let flattened = flattenExpr expr | ||
when conf.debug $ do | ||
when conf.debug $ liftIO $ do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems unrelated to the main point of the PR.
To me it seems better to write liftIO
once. What is the problem with that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's annoying. the checkSatWithProps
needs the env
. But it's ugly as-is, let me try to clean it up...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, it should be cleaner now. Can you maybe re-check? It doesn't print the simplifying...
line, but that's not that useful anyway I think. Otherwise, it should be cleaner now :)
b527ee6
to
1bd6bde
Compare
Move unsat cache to Solver.hs in a central location Co-authored-by: Martin Blicha <martin.blicha@ethereum.org>
1bd6bde
to
a0d3a19
Compare
Solvers.hs
Solvers.hs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why you need STM
(TChan
) for the cache? Why the basic Chan
is not sufficient?
src/EVM/Solvers.hs
Outdated
@@ -69,6 +71,9 @@ data MultiSol = MultiSol | |||
-- | A script to be executed, a list of models to be extracted in the case of a sat result, and a channel where the result should be written | |||
data Task = TaskSingle SingleData | TaskMulti MultiData | |||
|
|||
newtype UnsatCache = UnsatCache [Prop] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be renamed, no? [Prop]
is not the unsat cache. It is more like an Entry
that should be added to unsat cache.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! Renamed it CacheEntry
, I hope that works :)
Yes! This queue needs to be nonblocking. The
We need a non-blocking read operation, so we can start solving if there is nothing in the channel. My understanding is that the other way of doing this is to use |
Right, that makes sense! |
Description
This moves the UNSAT cache to a central location, in
Solvers.hs
. This means that UNSAT cache is filled and used even during interpretation. Also, one can simply usecheckSatWithProps
and the UNSAT cache will be there and working.This also means that the unsat cache is now available to every place that calls
checkSatWithProps
, which also includesPleaseAskSMT
, i.e. it will now work also when deciding on branches.We now have a queue for the cache, and it is taken as priority before picking up any new task.
Checklist