Skip to content

Commit 9664ef8

Browse files
committed
Read symbolic value at symbolic address
1 parent 36f61a0 commit 9664ef8

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,23 @@ For symbolic execution, we need to tackle the patterns of `#bytes(B +Bytes _) _`
2828
requires I >Int 0 andBool I <Int lengthBytes(B) [simplification(45), preserves-definedness]
2929
rule dropFront(I, #bytes(B +Bytes BS) EF) => dropFront(I -Int lengthBytes(B), #bytes(BS) EF)
3030
requires I >=Int lengthBytes(B) [simplification(45), preserves-definedness]
31+
32+
// pickFront and dropFront for #WB
33+
rule pickFront(PICK, #WB(_, _, _, _, B:SparseBytes)) => pickFront(PICK, B)
34+
// omit this condition to make it easy to simplify: requires 0 =/=Int I
35+
[simplification(45)]
36+
rule pickFront(PICK, #WB(_, I, V, NUM, B:SparseBytes)) => Int2Bytes(minInt(PICK, NUM), V, LE) +Bytes pickFront(maxInt(0, PICK -Int NUM), B >>SparseBytes minInt(PICK, NUM))
37+
requires 0 ==Int I [simplification(40)]
38+
rule dropFront(DROP, #WB(FLAG, I, V, NUM, B:SparseBytes)) => #WB(FLAG, I -Int DROP, V, NUM, dropFront(DROP, B))
39+
[simplification(45)]
40+
41+
42+
syntax SparseBytes ::= SparseBytes ">>SparseBytes" Int [function, total]
43+
// It's not correct, but just make this function total
44+
rule B >>SparseBytes _ => B [concrete]
45+
rule #WB(FLAG, I, V, NUM, B:SparseBytes) >>SparseBytes SHIFT => #WB(FLAG, I, (V &Int (2 ^Int (NUM *Int 8)) -Int 1) >>Int (SHIFT *Int 8), NUM, B >>SparseBytes SHIFT)
46+
requires SHIFT >=Int 0 [simplification(45), preserves-definedness]
47+
rule B:SparseBytes >>SparseBytes _ => B [simplification]
3148
```
3249

3350
## writeBytes
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
module READ-SYMBOLIC-INDEX-VALUE
2+
imports RISCV
3+
4+
claim [id]:
5+
<instrs> #CHECK_HALT => #HALT </instrs>
6+
<regs>
7+
// read from #bytes
8+
1 |-> (readBytes(4, 4,
9+
#WB(true, I1, V0, 2,
10+
#WB(true, I1, V1, 4,
11+
#WB(true, I0, V2, 4,
12+
#WB(true, I2, V3, 4,
13+
#bytes (b"\x00\x00\x00\x00" +Bytes Int2Bytes(4, V4, LE) +Bytes b"\x00\x00\x00\x00\x00\x00\x00\x00") .SparseBytes)))))
14+
=> V4)
15+
// read I2 with same number of bytes
16+
2 |-> (readBytes(I2, 4,
17+
#WB(true, I1, V0, 2,
18+
#WB(true, I1, V1, 4,
19+
#WB(true, I0, V2, 4,
20+
#WB(true, I2, V3, 4,
21+
#bytes (Int2Bytes(4, V4, LE) +Bytes b"\x00\x00\x00\x00\x00\x00\x00\x00") .SparseBytes)))))
22+
=> V3)
23+
// read I2 with smaller number of bytes
24+
3 |-> (readBytes(I2, 2,
25+
#WB(true, I1, V0, 2,
26+
#WB(true, I1, V1, 4,
27+
#WB(true, I0, V2, 4,
28+
#WB(true, I2, V3, 4,
29+
#bytes (Int2Bytes(4, V4, LE) +Bytes b"\x00\x00\x00\x00\x00\x00\x00\x00") .SparseBytes)))))
30+
=> V3 &Int 65535)
31+
// DISALLOWED: read with more number of bytes (8 bytes, but only 4 stored)
32+
// read I1 with 2 bytes
33+
4 |-> (readBytes(I1, 2,
34+
#WB(true, I1, V0, 2,
35+
#WB(true, I1, V1, 4,
36+
#WB(true, I0, V2, 4,
37+
#WB(true, I2, V3, 4,
38+
#bytes (Int2Bytes(4, V4, LE) +Bytes b"\x00\x00\x00\x00\x00\x00\x00\x00") .SparseBytes)))))
39+
=> V0 &Int 65535)
40+
// read I1 with 4 bytes
41+
5 |-> (readBytes(I1, 4,
42+
#WB(true, I1, V0, 2,
43+
#WB(true, I1, V1, 4,
44+
#WB(true, I0, V2, 4,
45+
#WB(true, I2, V3, 4,
46+
#bytes (Int2Bytes(4, V4, LE) +Bytes b"\x00\x00\x00\x00\x00\x00\x00\x00") .SparseBytes)))))
47+
=> Bytes2Int(Int2Bytes(2, V0, LE) +Bytes Int2Bytes(2, V1 >>Int 16, LE), LE, Unsigned))
48+
</regs>
49+
<pc> 0 </pc>
50+
<haltCond> ADDRESS ( 0 ) </haltCond>
51+
// index not equal to 0
52+
requires 4 =/=Int I0 andBool 4 =/=Int I1 andBool 4 =/=Int I2
53+
// different indices
54+
andBool I0 =/=Int I1 andBool I0 =/=Int I2 andBool I1 =/=Int I2
55+
// values are within range
56+
andBool 0 <=Int V0 andBool V0 <=Int 65535
57+
andBool 0 <=Int V1 andBool V1 <=Int 4294967295
58+
andBool 0 <=Int V2 andBool V2 <=Int 4294967295
59+
andBool 0 <=Int V3 andBool V3 <=Int 4294967295
60+
andBool 0 <=Int V4 andBool V4 <=Int 4294967295
61+
endmodule
62+

0 commit comments

Comments
 (0)