Skip to content

Commit c157326

Browse files
Stevengrerv-auditortothtamas28
authored
Add simp rules for replaceAtBytes (#112)
Co-authored-by: devops <[email protected]> Co-authored-by: Tamás Tóth <[email protected]>
1 parent e2369f6 commit c157326

File tree

4 files changed

+31
-21
lines changed

4 files changed

+31
-21
lines changed

package/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.81
1+
0.1.82

pyproject.toml

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

55
[tool.poetry]
66
name = "kriscv"
7-
version = "0.1.81"
7+
version = "0.1.82"
88
description = "K tooling for the RISC-V architecture"
99
authors = [
1010
"Runtime Verification, Inc. <[email protected]>",

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,36 +51,40 @@ module BYTES-SIMPLIFICATIONS
5151
rule [bytes-update-symbolic-value]:
5252
B:Bytes [I <- V] => substrBytes(B, 0, I) +Bytes Int2Bytes(1, V, LE) +Bytes substrBytes(B, I +Int 1, lengthBytes(B) -Int I -Int 1)
5353
requires I <Int lengthBytes(B)
54-
[simplification, concrete(B, I), symbolic(V), preserves-definedness]
54+
[simplification, preserves-definedness]
5555
5656
rule [multiple-bytes-update-symbolic-value]:
5757
replaceAtBytes(B, I, V) => substrBytes(B, 0, I) +Bytes V +Bytes substrBytes(B, I +Int lengthBytes(V), lengthBytes(B))
58-
requires I +Int lengthBytes(V) <Int lengthBytes(B)
59-
[simplification, concrete(B, I), symbolic(V), preserves-definedness]
58+
requires I +Int lengthBytes(V) <=Int lengthBytes(B)
59+
[simplification, preserves-definedness]
6060
```
6161

6262

63-
## Int2Bytes Lemmas
63+
## Length Bytes Lemmas
6464

6565
```k
66-
rule [int2bytes-length]:
67-
lengthBytes(Int2Bytes(N, _:Int, _:Endianness)) => N
66+
rule [length-bytes-int2bytes]: lengthBytes(Int2Bytes(N, _:Int, _:Endianness)) => N
67+
[simplification]
68+
rule [length-bytes-substr]: lengthBytes(substrBytes(B, I, J)) => J -Int I
69+
requires 0 <=Int I andBool I <=Int J andBool J <=Int lengthBytes(B)
70+
[simplification, preserves-definedness]
71+
rule [length-bytes-concat]: lengthBytes(A +Bytes B) => lengthBytes(A) +Int lengthBytes(B)
6872
[simplification]
69-
7073
```
7174

7275
## substrBytes Lemmas
7376

7477
```k
75-
rule [substr-bytes-length]: lengthBytes(substrBytes(B, I, J)) => J -Int I
76-
requires 0 <=Int I
77-
andBool I <=Int J
78-
andBool J <=Int lengthBytes(B)
79-
[simplification, preserves-definedness]
8078
rule [substr-substr]: substrBytes(substrBytes(B, I, J), I0, J0) => substrBytes(B, I +Int I0, I +Int J0)
8179
requires 0 <=Int I andBool I <=Int J andBool J <=Int lengthBytes(B)
8280
andBool 0 <=Int I0 andBool I0 <=Int J0 andBool J0 <=Int J -Int I
8381
[simplification, preserves-definedness]
82+
rule [substr-bytes-eq-ij]: substrBytes(B, I, I) => b""
83+
requires 0 <=Int I andBool I <=Int lengthBytes(B)
84+
[simplification, preserves-definedness]
85+
rule [substr-bytes-self]: substrBytes(B, 0, J) => B
86+
requires J ==Int lengthBytes(B)
87+
[simplification, preserves-definedness]
8488
rule [substr-concat-0]: substrBytes(A +Bytes _, I, J) => substrBytes(A, I, J)
8589
requires J <=Int lengthBytes(A)
8690
[simplification, preserves-definedness]

src/tests/integration/test-data/specs/bytes-int.k

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,22 @@ module BYTES-INT
77
<instrs> #CHECK_HALT => #HALT </instrs>
88
<pc> W ( 0 ) </pc>
99
<regs>
10-
1 |-> (W(Bytes2Int (b"\x12\x34\x56\x78", LE, Unsigned) &Int 65280) => W(13312))
11-
2 |-> (W(b"\x12\x34\x56\x78" [ 1 ] <<Int 8) => W(13312))
12-
3 |-> (W(Bytes2Int (substrBytes(W0, 0, 4), LE, Unsigned ) &Int 65280) => W(W0 [ 1 ] <<Int 8))
13-
4 |-> (W(Bytes2Int(substrBytes(b"\x01\x02", 0, 1), LE, Unsigned) &Int 65280) => W(0))
14-
5 |-> (W(Bytes2Int(substrBytes(W0, 0, 1), LE, Unsigned) &Int 65280) => W(0))
15-
6 |-> (W(Bytes2Int(substrBytes( W0 +Bytes b"\x12\x34\x56\x78", 0, 4), LE, Unsigned)) => W(Bytes2Int(substrBytes( W0, 0, 4), LE, Unsigned)))
16-
7 |-> (W(Bytes2Int(substrBytes( W0 +Bytes b"\x01\x00\x00\x00", 32, 36), LE, Unsigned)) => W(1))
10+
1 |-> (W(Bytes2Int (b"\x12\x34\x56\x78", LE, Unsigned) &Int 65280) => W(13312))
11+
2 |-> (W(b"\x12\x34\x56\x78" [ 1 ] <<Int 8) => W(13312))
12+
3 |-> (W(Bytes2Int (substrBytes(W0, 0, 4), LE, Unsigned ) &Int 65280) => W(W0 [ 1 ] <<Int 8))
13+
4 |-> (W(Bytes2Int(substrBytes(b"\x01\x02", 0, 1), LE, Unsigned) &Int 65280) => W(0))
14+
5 |-> (W(Bytes2Int(substrBytes(W0, 0, 1), LE, Unsigned) &Int 65280) => W(0))
15+
6 |-> (W(Bytes2Int(substrBytes( W0 +Bytes b"\x12\x34\x56\x78", 0, 4), LE, Unsigned)) => W(Bytes2Int(substrBytes( W0, 0, 4), LE, Unsigned)))
16+
7 |-> (W(Bytes2Int(substrBytes( W0 +Bytes b"\x01\x00\x00\x00", 32, 36), LE, Unsigned)) => W(1))
17+
8 |-> (W(Bytes2Int(replaceAtBytes (W0 +Bytes W3 +Bytes b"\x00\x00\x00\x00" , 64 , b"\x02" ), LE, Unsigned)) => W(Bytes2Int ( W0:Bytes +Bytes W3:Bytes +Bytes b"\x02\x00\x00\x00" , LE , Unsigned )))
18+
9 |-> (W(Bytes2Int(replaceAtBytes (b"\x00\x00", 0, b"\x01\x02"), LE, Unsigned)) => W(513))
19+
10 |-> (W(Bytes2Int(replaceAtBytes (W1, 2, b"\x01\x02"), LE, Unsigned)) => W(Bytes2Int(substrBytes ( W1:Bytes , 0 , 2 ) +Bytes b"\x01\x02", LE, Unsigned)))
20+
11 |-> (W(Bytes2Int(substrBytes(b"\x00", 1, 1), LE, Unsigned)) => W(0))
1721
</regs>
1822
<test>
1923
<haltCond> ADDRESS ( W ( 0 ) ) </haltCond>
2024
</test>
2125
requires lengthBytes(W0) ==Int 32
26+
andBool lengthBytes(W1) ==Int 4
27+
andBool lengthBytes(W3) ==Int 32
2228
endmodule

0 commit comments

Comments
 (0)