Surprising order-dependence with ghost state #1984
Labels
type: bug
Issues reporting bugs or unexpected/unwanted behavior
unsoundness
Issues that can lead to unsoundness or false verification
Milestone
Consider this example, courtesy of @qsctr:
This looks plausible, but if you run it, SAW will fail to verify
get2_spec
:This counterexample is bewildering. How can
get::ghost
be4294967253
whenget
's preconditions requireget::ghost
to be42
? It gets even weirder when you realize that if you make this small change toget_spec
:Then verification succeeds! This flies in the face of usual SAW conventions, where the order of preconditions should not matter.
The reason that this happens is somewhat technical. Currently, SAW happens to process each precondition in a spec from top to bottom. Processing a precondition like
llvm_precond {{ x == g }}
extends a variable substitution that SAW maintains such thatg
will map tox
. Therefore, if you process thellvm_ghost_value ghost g
afterwards, then SAW will mapg
tox
, making it as though you had writtenllvm_ghost_value ghost x
. SAW knows how to link this back to the argument to theget
function, and all is well.If the two preconditions are written in the opposite order, however, then when SAW processes
llvm_ghost_value ghost g
first, it has no idea thatg
is related tox
in any way. As such, it will allowg
to be any value whatsoever, and indeed, symbolic execution will happily pick4294967253
as its value. Bad bad bad!Really, we should always run
llvm_ghost_value
preconditions after all other preconditions, as running the other preconditions may introduce important variable equalities that are essential to making compositional overrides (such asget
) apply successfully. This special-casing ofllvm_ghost_value
makes sense if you think of ghost values as a type of argument to the function, and indeed, we already special-case the handling of ordinary function arguments (viallvm_execute_func
).Although the example above uses the LLVM backend, there is nothing inherently LLVM-specific about it, and the bug will also apply to the JVM and MIR backends after #1958 lands.
The text was updated successfully, but these errors were encountered: