draperlaboratory / cbat_tools

Program analysis tools developed at Draper on the CBAT project.
MIT License
102 stars 14 forks source link

Smtlib identifier difficulties #339

Open philzook58 opened 3 years ago

philzook58 commented 3 years ago

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 https://github.com/draperlaboratory/cbat_tools/blob/176753aea3d49b6d8b9a3590b25399727a07abe0/wp/lib/bap_wp/src/z3_utils.ml#L35 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 https://github.com/draperlaboratory/cbat_tools/blob/176753aea3d49b6d8b9a3590b25399727a07abe0/wp/lib/bap_wp/src/z3_utils.ml#L263

Here are possible suggestions both of which can be done at https://github.com/draperlaboratory/cbat_tools/blob/176753aea3d49b6d8b9a3590b25399727a07abe0/wp/lib/bap_wp/src/environment.ml#L111 I believe:

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.