Skip to content

Fix smtchecker callback tests and add Eldarica #565

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

Merged
merged 2 commits into from
Jan 24, 2022
Merged

Conversation

leonardoalt
Copy link
Member

@leonardoalt leonardoalt commented Nov 18, 2021

Besides fixing things, the nicest thing this PR enables is to use alternative solvers much more easily in a different script, like this:
https://gist.github.com/leonardoalt/70d659eb0ec2f0e82b1fa5681d5ce3e8

smtchecker.js Outdated
return function (query) {
try {
var result = solver(query);
var result = solverFunction(query, solver);
Copy link
Member Author

Choose a reason for hiding this comment

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

This makes it possible to choose the solver from the callers side.

name: 'Eldarica',
command: 'eld',
params: '-horn -t:' + (timeout / 1000)
},
Copy link
Member Author

Choose a reason for hiding this comment

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

Just adding Eldarica for easy future use, it's currently not used for the tests.

st.skip('No SMT solver available.');
// For these tests we actually need z3/Spacer.
const z3HornSolvers = smtsolver.availableSolvers.filter(solver => solver.command === 'z3');
if (z3HornSolvers.length === 0) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Not to change things too much, we require z3 to run these tests.

Copy link
Member

Choose a reason for hiding this comment

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

I think we should make it opt-out instead of opt-in. With some equivalent of the --no-smt flag. Otherwise it's too easy for such tests to never run in CI.

@@ -167,9 +169,8 @@ tape('SMTCheckerCallback', function (t) {
if (source.includes(option)) {
let idx = source.indexOf(option);
if (source.indexOf(option, idx + 1) !== -1) {
st.skip('SMTEngine option given multiple times.');
st.end();
return;
Copy link
Member Author

Choose a reason for hiding this comment

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

This was actually making none of the actual smtcheckertests to run lol

Copy link
Member

Choose a reason for hiding this comment

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

This is the main fix, I reckon?

Copy link
Member Author

Choose a reason for hiding this comment

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

The solverFunction and solver fixes in smtsolver.js too, solvers were actually not run

settings = { modelChecker: { engine: engine } };
settings = { modelChecker: {
engine: engine,
solvers: [ 'smtlib2' ]
Copy link
Member Author

Choose a reason for hiding this comment

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

This was also wrong before, we need to force the callback to be used.

@coveralls
Copy link

coveralls commented Nov 18, 2021

Coverage Status

Coverage decreased (-0.8%) to 85.347% when pulling 40d563f on smt_fix_tests into f2fdcfb on master.

@leonardoalt leonardoalt requested a review from axic November 18, 2021 10:50
@leonardoalt leonardoalt force-pushed the smt_fix_tests branch 2 times, most recently from 5e1ea98 to 5e037da Compare November 21, 2021 20:39
@axic axic force-pushed the smt_fix_tests branch 2 times, most recently from 45ae5fe to 29d2b8b Compare January 19, 2022 17:09
@axic axic mentioned this pull request Jan 19, 2022
@leonardoalt
Copy link
Member Author

@cameel @axic I added the requested comments, plus added a piece of code I had locally that increases the output buffer of the child solver process. This is needed when a solver outputs a huge counterexample or proof.

@leonardoalt leonardoalt force-pushed the smt_fix_tests branch 5 times, most recently from 0017ffa to 8ed2597 Compare January 24, 2022 16:12
@axic
Copy link
Member

axic commented Jan 24, 2022

I'm leaning towards going in with the breaking changes, because the SMT Checker is still experimental. We can also change this code after merging to be backwards compatible before the next solc-js release.

cc @chriseth @cameel

Copy link
Member

@axic axic left a comment

Choose a reason for hiding this comment

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

Code-wise this looks good to me, but we may need to revisit keeping "backwards compatibility" before the next release (0.8.12).

solc.compile(JSON.stringify(input), { smtSolver: smt.smtSolver })
solc.compile(
JSON.stringify(input),
{ smtSolver: smtchecker.smtCallback(smtsolver.smtSolver, smtsolver.availableSolvers[0]) }
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should show an example of how to pass in a custom function as a callback?

Otherwise, if user is expected to use smtCallback(), why don't we just expect its parameters instead of a full callback?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's just way more convenient, there's 3 layers of different stuff here

Copy link
Member

Choose a reason for hiding this comment

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

Then maybe we should show both. I mean, this is the only reference doc we have for the library. Having an easy to run example is good but we should also say something about what the callback looks like. Looking quickly at README, I don't think it even mentions what args the actual callback takes. Only the args of this helper.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, makes sense. Next PR tho? :D

Copy link
Member

Choose a reason for hiding this comment

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

Fine. Let's get this one merged :)

st.skip('No SMT solver available.');
// For these tests we actually need z3/Spacer.
const z3HornSolvers = smtsolver.availableSolvers.filter(solver => solver.command === 'z3');
if (z3HornSolvers.length === 0) {
Copy link
Member

Choose a reason for hiding this comment

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

I think we should make it opt-out instead of opt-in. With some equivalent of the --no-smt flag. Otherwise it's too easy for such tests to never run in CI.

@leonardoalt
Copy link
Member Author

@cameel

I think we should make it opt-out instead of opt-in. With some equivalent of the --no-smt flag. Otherwise it's too easy for such tests to never run in CI.

The annoying part about this is that the solc-js CI tests run a bunch of old versions that have no idea about this, I think it'd look quite ugly to just disable it in all of them

@cameel
Copy link
Member

cameel commented Jan 24, 2022

The annoying part about this is that the solc-js CI tests run a bunch of old versions that have no idea about this, I think it'd look quite ugly to just disable it in all of them

Maybe we could just have it wrapped in some helper that gets a version and tells us if it supports a modern version of the SMT stuff?

In any case, that's not a huge blocker for me, could be done separately. Would be nice to have but this PR has been waiting long enough :)

Copy link
Member

@cameel cameel left a comment

Choose a reason for hiding this comment

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

I found mostly typos and added a some suggestions about overall I see nothing wrong here.

As I said in one of my comments, I'd recommend testing it against solc-js tests in the main repo before we merge to avoid breakage.

@leonardoalt
Copy link
Member Author

Updated the small things.
I would prefer to leave the --no-smt flag to a different PR to get this one merged. The tests are working with a pre-release binary.

@axic
Copy link
Member

axic commented Jan 24, 2022

Please rebase now after #587 was merged (also likely need to run yarn lint:fix).

@axic axic requested a review from cameel January 24, 2022 19:52
@cameel
Copy link
Member

cameel commented Jan 24, 2022

LGTM

@leonardoalt leonardoalt merged commit a3ab8e1 into master Jan 24, 2022
@leonardoalt leonardoalt deleted the smt_fix_tests branch January 24, 2022 20:24
tawhidnazari57

This comment was marked as spam.

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.

5 participants