Skip to content

Commit 14e6d3d

Browse files
497 Start of a lemma library (#500)
This PR adds a lemma file in a new directory to the K code, and a few lemmas that are known to be useful for proofs using the semantics. Closes #497 --------- Co-authored-by: devops <[email protected]>
1 parent 0559171 commit 14e6d3d

File tree

6 files changed

+74
-5
lines changed

6 files changed

+74
-5
lines changed

kmir/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "kmir"
7-
version = "0.3.101"
7+
version = "0.3.102"
88
description = ""
99
authors = [
1010
"Runtime Verification, Inc. <[email protected]>",

kmir/src/kmir/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from typing import Final
22

3-
VERSION: Final = '0.3.101'
3+
VERSION: Final = '0.3.102'

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
```k
44
requires "kmir-ast.md"
55
requires "rt/data.md"
6+
requires "lemmas/kmir-lemmas.md"
67
```
78

89
## Syntax of MIR in K
@@ -86,7 +87,7 @@ endmodule
8687
### Execution Control Flow
8788

8889
```k
89-
module KMIR
90+
module KMIR-CONTROL-FLOW
9091
imports KMIR-SYNTAX
9192
imports KMIR-CONFIGURATION
9293
imports MONO
@@ -618,3 +619,14 @@ Otherwise the provided message is passed to a `panic!` call, ending the program
618619
```k
619620
endmodule
620621
```
622+
623+
## Top-level Module
624+
625+
The top-level module `KMIR` includes both the control flow constructs (and transitively all modules related to runtime operations and AST) and a collection of simplification lemmas required for symbolic execution of MIR programs.
626+
627+
```k
628+
module KMIR
629+
imports KMIR-CONTROL-FLOW
630+
imports KMIR-LEMMAS
631+
632+
endmodule
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Lemmas for MIR symbolic execution
2+
3+
This file contains basic lemmas required for symbolic execution of MIR programs using `kmir`.
4+
5+
Lemmas are simpliciations of symbolic function application that aims to confirm conditions for rewrite rules to avoid spurious branching on symbolic program parts.
6+
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).
8+
Others are related to helper functions used for integer arithmetic.
9+
10+
```k
11+
requires "../rt/data.md"
12+
requires "../kmir.md"
13+
14+
module KMIR-LEMMAS
15+
imports RT-DATA-HIGH
16+
17+
imports LIST
18+
imports INT-SYMBOLIC
19+
imports BOOL
20+
```
21+
## Simplifications for lists to avoid spurious branching on error cases in control flow
22+
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).
24+
The lists used in the semantics are cons-lists, so only rules with a head element match are required.
25+
26+
```k
27+
rule N <Int size(_LIST:List) => true
28+
requires N <Int 0
29+
[simplification, symbolic(_LIST)]
30+
31+
rule N <Int size(ListItem(_) REST:List) => N -Int 1 <Int size(REST)
32+
requires 0 <Int N
33+
[simplification, symbolic(REST)]
34+
```
35+
36+
## Simplifications related to the `truncate` function
37+
38+
The `truncate` function is used in various overflow checks in integer arithmetic.
39+
Therefore, its value range should be simplified for symbolic input asserted to be in range.
40+
41+
```k
42+
rule truncate(VAL, WIDTH, Unsigned) => VAL
43+
requires VAL <Int (1 <<Int WIDTH)
44+
andBool 0 <=Int VAL
45+
[simplification]
46+
47+
rule truncate(VAL, WIDTH, Signed) => VAL
48+
requires VAL <Int (1 <<Int (WIDTH -Int 1))
49+
andBool 0 -Int (1 <<Int (WIDTH -Int 1)) <=Int VAL
50+
[simplification]
51+
52+
```
53+
54+
55+
```k
56+
endmodule
57+
```

kmir/src/kmir/kmir.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def __init__(
3636
self.llvm_library_dir = llvm_library_dir
3737

3838
class Symbols:
39-
END_PROGRAM: Final = KApply('#EndProgram_KMIR_KItem')
39+
END_PROGRAM: Final = KApply('#EndProgram_KMIR-CONTROL-FLOW_KItem')
4040

4141
@contextmanager
4242
def kcfg_explore(self, label: str | None = None) -> Iterator[KCFGExplore]:

package/version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.101
1+
0.3.102

0 commit comments

Comments
 (0)