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

Smtlib identifier difficulties #339

Open
philzook58 opened this issue Aug 17, 2021 · 0 comments
Open

Smtlib identifier difficulties #339

philzook58 opened this issue Aug 17, 2021 · 0 comments

Comments

@philzook58
Copy link
Contributor

philzook58 commented Aug 17, 2021

There are some slight differences between smtlib and sexplib and different notions of allowed identifiers in bap, smtlib, and sexplib that have continually made things awkward. In addition, there is in principle a possibility of name clashing of high level variables and low level variables.

The canonical example (perhaps only really) that causes this issue is the bap generated identifier like #80. A # character in smtlib identifiers must be quoted using |#80| syntax. Z3 is not entirely consistent to my understanding of how it treats the | quotes, so we sometimes have to strip them

let var_name = String.strip ~drop:(fun c -> Char.(c = '|')) (Expr.to_string z3_var) in

This however clashes with sexplib, which uses |# and #| to denote block comments. To abandon or replicate sexplib merely for this feels insane. That led to this embarassing hack
let pound_token = "MYSPECIALPOUND682" in

Here are possible suggestions both of which can be done at

let mk_z3_expr (ctx : Z3.context) ~name:(name : string) ~typ:(typ : Type.t) : Constr.z3_expr =
I believe:

  • namespace all variables with disjoint prefixes cbatvar_, highlevelvar_, realreg etc as need be. The names will still be | quoted in the presence of #, but sexplib will work. let name = "cbat_" ^ name in would basically do it
  • Replace # with a friendlier character here. Anything else. The smtlib allows for " a non-empty sequence of letters, digits and the characters + - / * = % ? ! . $ _ ˜ & ˆ < > @ that does not start with a digit"
  • Leave as is. The new feature will use sprintf injection of smtlib library functions and not use Sexp.t
  • Ask bap very nicely to use a different character for it's internally generated names. This is of course not really under our control and would probably break all sorts of stuff across the bap ecosystem. So not a very good solution.

As a possible increase of scope of this ticket, perhaps we also want a better way to namespace the init_ _orig, _mod versions of variables.

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

1 participant