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

Question regarding BV logic in SMT files #205

Closed
rod-chapman opened this issue Feb 27, 2024 · 14 comments
Closed

Question regarding BV logic in SMT files #205

rod-chapman opened this issue Feb 27, 2024 · 14 comments

Comments

@rod-chapman
Copy link

I have many SMT2.6 files, all of which use the "BV" logic for BitVectors, and (in particular) use the "bv2nat" function that is supported by Z3, CVC4 and CVC5.

Dolmen appears to reject this - e.g.

204 |   (ite (bvsge x (_ bv0 16)) (bv2nat x) (- (- 65536 (bv2nat x)))))
                                   ^^^^^^
Error Unbound identifier: `bv2nat`

Any workaround for this?

@Gbury
Copy link
Owner

Gbury commented Feb 27, 2024

Unfortunately, there is no current workaround, but I'm planning to work on one in the coming days.

For a bit of context: although supported by Z3, CVC4 and CVC5, bv2nat is not part of the official standard defined by the smtlib. More specifically, the theory for BV internally defines bv2nat but only so that it can be used in its semantic specification.

Until now, dolmen has strived to implement the standard, at least as a first goal, so that it could be used to check conformity against that standard. However, it appears that it's not sufficient anymore, so I'm planning to add a notion of typing extensions: these extensions would be enabled by cli flags and effectively add new functions to the typing builtins (similar to how the parsing extensions work, see #190 ).

@rod-chapman
Copy link
Author

Understood. I'm trying to get a non-trivial program verification benchmark into the SMTComp suite. The code is cryptographic, so it has modular arithmetic and BV stuff all over the place...

@Gbury
Copy link
Owner

Gbury commented Feb 27, 2024

I should have an experimental version of dolmen that can accept bv2nat by the end of the week.

@Gbury
Copy link
Owner

Gbury commented Feb 28, 2024

Just to make sure, what would be the expected signature of the bv2nat function ?

@rod-chapman
Copy link
Author

Not sure.... how is it declared in Z3, CVC4 and CVC5?

@bclement-ocp
Copy link
Contributor

As far as I could tell when implementing these functions for Alt-Ergo, they use a family of function symbols of the form (bv2nat (_ BitVec n) Int) for all n > 0, and indexed function symbols ((_ int2bv n) Int (_ BitVec n)) for n > 0.

(I believe Z3 also supports nat2bv but CVC5 only supports int2bv because the developers didn't like nat2bv allowing negative arguments)

@hansjoergschurr
Copy link
Contributor

In the cvc5 AletheLF proof signatures bv2nat and int2nat have the following signatures. This is roughly SMT-LIB 3 syntax.

(declare-const int2bv (->
  (! Int :var w)
  Int (BitVec w))
)

(declare-const bv2nat (->
  (! Int :var m :implicit)
  (BitVec m) Int)
)

@Gbury
Copy link
Owner

Gbury commented Mar 1, 2024

#208 adds a way for dolmen to accept the bv2nat and int2bv functions.

@rod-chapman
Copy link
Author

Is this merged now?

@Gbury
Copy link
Owner

Gbury commented Mar 6, 2024

Apologies for the delay, yes it has been merged.

@Gbury
Copy link
Owner

Gbury commented Mar 6, 2024

Solved by #208

One can now use the --ext=bvconv option of the dolmen binary to allow bv2nat and int2bv.

@Gbury Gbury closed this as completed Mar 6, 2024
@rod-chapman
Copy link
Author

OK... now need to update the GitHub action associated with the smtcomp benchmark_submission repo so it will run the new binary with that option. Any idea how to do that?

@Gbury
Copy link
Owner

Gbury commented Mar 6, 2024

I had a look at the smt-comp repo, and its github actions will need a bit more code than currently to use the dev version of dolmen (since there is no release including PR#208 yet). You basically need two changes:

  • First, the github action downloads the release binary for version 0.9, see these lines. Instead, you'll need to build the latest dev version of dolmen (or wait until I make a new release including the bvconv extension). To do that, build steps along these lines should be work (though I have not tested these):
# Setup ocaml/opam
    - name: Setup ocaml/opam
      uses: avsm/setup-ocaml@v2
      with:
        ocaml-compiler: ocaml-base-compiler.4.14.0
# Run opam udpate to get an up-to-date repo
    - name: Update opam repo
      run: opam update
# Install dev version of dolmen
   - name: Install dolmen
     run: opam pin --dev-repo dolmen dolmen_type dolmen_loop dolmen_model dolmen_bin
# Copy the dolmen binary
   - name: Copy the dolmen binary
     run: cp `opam exec -- which dolmen` ./dolmen-linux-amd64

Alternatively, I could try and see how to setup a github actions file that would build and upload a nightly release of dolmen (that wya, only the download url for the dolmen binary would need to change), but last time I looked, it was quite a bit of work.

  • Second, you'll need to add the adequate extension on this line. Just adding --ext=bvconv should be enough.

@rod-chapman
Copy link
Author

I think it's best for us to wait for the next formal binary release. Many thanks for all your efforts.

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

No branches or pull requests

4 participants