Constants and arithmetic in bitvector assertions #871
Replies: 3 comments 1 reply
-
Regarding When we change this, I think we need to change a part of the tutorial we have. For example, the type signature of + in ghost code. (We currently say that it returns an After the change, we get this example, which can be confusing if not explicitly mentioned in the tutorial: proof fn test() {
assert(0xffff_ffffu32 + 1u32 == 0u32) by (bit_vector); // succeeds
assert(0xffff_ffffu32 + 1u32 == 0u32); // fails, since + returns 0x1_0000_0000int
assert(add(0xffff_ffffu32, 1u32) == 0u32); // succeeds
} (maybe tweaking macro here: https://github.com/verus-lang/verus/blob/main/source/builtin_macros/src/syntax.rs#L1726) |
Beta Was this translation helpful? Give feedback.
-
I like the idea of inlining constants into assert-by-bit_vector. On the other hand, I think automatically turning +/-/* into add/sub/mul would be confusing, because, as the hypothetical tutorial example above shows, you could have assert-by-bit-vector succeed and then the same subsequent assert fail:
I think if
|
Beta Was this translation helpful? Give feedback.
-
[Verus meeting] Constants@Chris-Hawblitzel: For constants, run the interpreter, if we get a constant out, we use the constant. Bit-width for
|
Beta Was this translation helpful? Give feedback.
-
I recently worked on improving the hardware model for the verified page table and in the process used bitvector assertions a fair bit. Generally, I was impressed by how powerful the bitvector prover is but also annoyed at some of the restrictions Verus currently has in place for bitvector assertions.
A lot of my bitvector reasoning involves various constants, e.g.:
I needed to prove a number of equalities involving these constants, for example the one below (for particular values of
l0_idx
,l1_idx
,l2_idx
,l3_idx
)Verus currently doesn't support using constants in bitvector assertions and arithmetic operators have to be written as function calls, which means we have to use the following assertion
Assertions like this are cumbersome to write and make the overall workflow with bitvector more frustrating than it has to be.
I managed to somewhat work around this by first using a normal
assert
orassume
to identify the necessary bitvector step and then "translating" it to a bitvector assertion and proving it. However, this still failed when I occasionally discovered that I had in fact written an untrue statement and needed to change it.I don't know how hard or easy it is to support the use of constants and normal arithmetic operators in bitvector assertions but it would make working with them significantly more pleasant.
Beta Was this translation helpful? Give feedback.
All reactions