Skip to content

Commit 76ed852

Browse files
Add new simp rules for integer operations and Bool2Word (#153)
These rules are used for zkevm-harness project's `MSTORE` termination proof. --------- Co-authored-by: devops <devops@runtimeverification.com>
1 parent d1a4173 commit 76ed852

7 files changed

Lines changed: 50 additions & 3 deletions

File tree

package/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.116
1+
0.1.117

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "kriscv"
7-
version = "0.1.116"
7+
version = "0.1.117"
88
description = "K tooling for the RISC-V architecture"
99
readme = "README.md"
1010
requires-python = "~=3.10"

src/kriscv/kdist/riscv-semantics/lemmas/bytes-simplifications.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,13 @@ module BYTES-SIMPLIFICATIONS [symbolic]
183183
[simplification]
184184
```
185185

186+
## Additional Bytes Simplifications
187+
188+
```k
189+
rule [bytes2int-pad-trailing-zeros]: Bytes2Int (B:Bytes +Bytes b"\x00\x00\x00" , LE , Unsigned ) => Bytes2Int (B, LE, Unsigned)
190+
[simplification(45)]
191+
```
192+
186193
```k
187194
endmodule
188195
```

src/kriscv/kdist/riscv-semantics/lemmas/int-simplifications.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,26 @@ module INT-SIMPLIFICATIONS [symbolic]
5454

5555
```k
5656
rule [int-and-ineq]: 0 <=Int A &Int B => true requires 0 <=Int A andBool 0 <=Int B [simplification]
57+
rule [int-and-ineq-4294967295]: 0 <=Int _ &Int 4294967295 => true [simplification(45)]
58+
rule [int-and-ineq-65535]: 0 <=Int _ &Int 65535 => true [simplification(45)]
59+
rule [int-and-ineq-255]: 0 <=Int _ &Int 255 => true [simplification(45)]
60+
rule [int-or-gt]: 0 <Int A |Int B => true requires 0 <Int A orBool 0 <Int B [simplification]
5761
rule [int-rhs-ineq]: 0 <=Int A >>Int B => true requires 0 <=Int A andBool 0 <=Int B [simplification]
5862
rule [int-add-ineq]: A <=Int A +Int B => true requires 0 <=Int B [simplification]
5963
rule [int-add-ineq-0]: 0 <=Int A +Int B => true requires 0 <=Int A andBool 0 <=Int B [simplification]
6064
rule [int-add-ineq-4294967295]: X &Int 4294967295 <Int A => 4294967295 <Int X
6165
requires 0 <=Int A andBool A <=Int X [simplification]
6266
```
6367

68+
## Additional Int Simplifications
69+
70+
```k
71+
rule [int-add-ineq-pos-1]: 0 <Int A +Int B => true
72+
requires 0 <=Int A andBool 0 <Int B [simplification(45)]
73+
rule [int-add-ineq-pos-2]: 0 <Int A +Int B => true
74+
requires 0 <Int A andBool 0 <=Int B [simplification]
75+
```
76+
6477
## Int Expression Simplifications for Bytes
6578

6679
### Shift Left for Bytes

src/kriscv/kdist/riscv-semantics/lemmas/word-simplifications.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ module WORD-SIMPLIFICATIONS
1919

2020
```k
2121
rule [bool2word-non-neg]: 0 <=Int Bool2Word(_) => true [simplification]
22+
rule [bool2word-eq-0]: Bool2Word(B) ==Int 0 => notBool B [simplification]
23+
rule [bool2word-eq-1]: Bool2Word(B) ==Int 1 => B [simplification]
24+
25+
26+
rule [int-bool2word-or-ineq]: 0 <Int (0 -Int Bool2Word(4294967295 <Int X)) &Int 4294967295 |Int X &Int 4294967295 => true
27+
requires 0 <Int X [simplification(45)]
2228
```
2329

2430
```k
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module BYTE-OFFSET-BOUNDS-CHECK
2+
imports RISCV
3+
4+
claim [id]:
5+
<instrs> #CHECK_HALT => #HALT </instrs>
6+
<pc> 0 </pc>
7+
<regs>
8+
1 |-> (Bool2Word(0 <Int (0 -Int Bool2Word(4294967295 <Int X)) &Int 4294967295 |Int X &Int 4294967295) => 1)
9+
2 |-> (Bool2Word(0 <=Int Bytes2Int ( OFFSET:Bytes +Bytes b"\x00\x00\x00" , LE , Unsigned )) => 1)
10+
3 |-> (Bool2Word(0 <Int Bytes2Int ( OFFSET:Bytes +Bytes b"\x00\x00\x00" , LE , Unsigned ) +Int 32) => 1)
11+
4 |-> (Bool2Word(0 <Int 0 -Int Bool2Word ( 4294967295 <Int Bytes2Int ( OFFSET:Bytes +Bytes b"\x00\x00\x00" , LE , Unsigned ) +Int 32 ) &Int 4294967295 |Int Bytes2Int ( OFFSET:Bytes +Bytes b"\x00\x00\x00" , LE , Unsigned ) +Int 32 &Int 4294967295) => 1)
12+
// 5 |-> (Bool2Word(4294967295 <Int Bytes2Int ( OFFSET:Bytes +Bytes b"\x00\x00\x00" , LE , Unsigned ) +Int 32) => 0)
13+
6 |-> (Bool2Word(Y <=Int Z) => 0)
14+
7 |-> (Bool2Word(Z <=Int 4294967295) => 1)
15+
</regs>
16+
<haltCond> ADDRESS ( 0 ) </haltCond>
17+
requires 0 <Int X
18+
andBool lengthBytes(OFFSET) ==Int 1
19+
andBool notBool (Y <=Int Z)
20+
andBool notBool (Bool2Word(Z <=Int 4294967295) ==Int 0)
21+
endmodule

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)