Skip to content

Commit b4182cd

Browse files
authored
More byte simplification (#864)
1 parent 3d763c0 commit b4182cd

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

kmir/src/kmir/kdist/mir-semantics/lemmas/kmir-lemmas.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This file contains basic lemmas required for symbolic execution of MIR programs
44

55
Lemmas are simpliciations of symbolic function application that aims to confirm conditions for rewrite rules to avoid spurious branching on symbolic program parts.
66

7-
Some of the lemmas relate to the control flow implementation in `kmir.md` and will be needed in various proofs (for instance the simplification of list size for partially-symbolic lists of locals or stack frames).
7+
Some of the lemmas relate to the control flow implementation in `kmir.md` and will be needed in various proofs (for instance the simplification of list size for partially-symbolic lists of locals or stack frames).
88
Others are related to helper functions used for integer arithmetic.
99

1010
```k
@@ -20,7 +20,7 @@ module KMIR-LEMMAS
2020
```
2121
## Simplifications for lists to avoid spurious branching on error cases in control flow
2222

23-
Rewrite rules that look up locals or stack frames require that an index into the respective `List`s in the configuration be within the bounds of the locals list/stack. Therefore, the `size` function on lists needs to be computed. The following simplifications allow for locals and stacks to have concrete values in the beginning but a symbolic rest (of unknown size).
23+
Rewrite rules that look up locals or stack frames require that an index into the respective `List`s in the configuration be within the bounds of the locals list/stack. Therefore, the `size` function on lists needs to be computed. The following simplifications allow for locals and stacks to have concrete values in the beginning but a symbolic rest (of unknown size).
2424
The lists used in the semantics are cons-lists, so only rules with a head element match are required.
2525

2626
```k
@@ -208,6 +208,25 @@ This avoids building up large expressions related to overflow checks and vacuous
208208
[simplification, preserves-definedness, symbolic]
209209
```
210210

211+
Another more general simplification relates a `NUMBER` and the bytes from its representation.
212+
If the number is initially masked at 64 bits (`&Int bitmask64`), it is guaranteed to be positive
213+
and therefore the masked value equals its bytes taken individually and multiplied.
214+
Terms like this have been observed as branching conditions in a proof that heavily uses `[u8;8] <--> u64` conversions.
215+
The simplification eliminates the vacuous branches instantly.
216+
217+
```k
218+
rule ((NUMBER &Int bitmask64) &Int bitmask8) +Int 256 *Int (
219+
((NUMBER &Int bitmask64) >>Int 8 &Int bitmask8) +Int 256 *Int (
220+
((NUMBER &Int bitmask64) >>Int 8 >>Int 8 &Int bitmask8) +Int 256 *Int (
221+
((NUMBER &Int bitmask64) >>Int 8 >>Int 8 >>Int 8 &Int bitmask8) +Int 256 *Int (
222+
((NUMBER &Int bitmask64) >>Int 8 >>Int 8 >>Int 8 >>Int 8 &Int bitmask8) +Int 256 *Int (
223+
((NUMBER &Int bitmask64) >>Int 8 >>Int 8 >>Int 8 >>Int 8 >>Int 8 &Int bitmask8) +Int 256 *Int (
224+
((NUMBER &Int bitmask64) >>Int 8 >>Int 8 >>Int 8 >>Int 8 >>Int 8 >>Int 8 &Int bitmask8) +Int 256 *Int (
225+
((NUMBER &Int bitmask64) >>Int 8 >>Int 8 >>Int 8 >>Int 8 >>Int 8 >>Int 8 >>Int 8 &Int bitmask8))))))))
226+
&Int bitmask64
227+
=> NUMBER &Int bitmask64
228+
[simplification, preserves-definedness, symbolic(NUMBER)]
229+
```
211230

212231
For the case where the (symbolic) byte values are first converted to a number, the round-trip simplification requires different matching.
213232
First, the bit-masking with `&Int 255` eliminates `Bytes2Int(Int2Bytes(1, ..) +Bytes ..)` enclosing a byte-valued variable:

0 commit comments

Comments
 (0)