Skip to content
This repository was archived by the owner on Apr 2, 2025. It is now read-only.

Commit 8f4241e

Browse files
committed
Progress on fixing tests
1 parent 444f217 commit 8f4241e

File tree

7 files changed

+85
-48
lines changed

7 files changed

+85
-48
lines changed

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ build-simple: pykwasm
3030
build-prove: pykwasm
3131
$(KDIST) -v build wasm-semantics.kwasm-lemmas -j3
3232

33+
build-wrc20: pykwasm
34+
$(KDIST) -v build wasm-semantics.wrc20 -j3
35+
3336
.PHONY: clean
3437
clean: pykwasm
3538
$(KDIST) clean
@@ -235,7 +238,7 @@ test: test-execution test-prove
235238

236239
# Generic Test Harnesses
237240

238-
tests/%.run: tests/%
241+
tests/%.run: tests/% build-simple
239242
$(TEST) run $< > tests/$*.$(TEST_CONCRETE_BACKEND)-out
240243
$(CHECK) tests/$*.$(TEST_CONCRETE_BACKEND)-out tests/success-$(TEST_CONCRETE_BACKEND).out
241244
rm -rf tests/$*.$(TEST_CONCRETE_BACKEND)-out
@@ -255,7 +258,7 @@ tests/%.prove: tests/% build-prove
255258
$(eval SOURCE_DIR := $(shell $(KDIST) which wasm-semantics.source))
256259
$(TEST) prove $< kwasm-lemmas -I $(SOURCE_DIR)/wasm-semantics -w2e
257260

258-
tests/proofs/wrc20-spec.k.prove: tests/proofs/wrc20-spec.k
261+
tests/proofs/wrc20-spec.k.prove: tests/proofs/wrc20-spec.k build-wrc20
259262
$(eval SOURCE_DIR := $(shell $(KDIST) which wasm-semantics.source))
260263
$(TEST) prove $< wrc20 -I $(SOURCE_DIR)/wasm-semantics -w2e --haskell-backend-command "kore-exec --smt-timeout 500"
261264

pykwasm/src/pykwasm/kdist/wasm-semantics/kwasm-lemmas.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,47 @@ In this case, it's simpler (and safe) to simply discard the `#chop`, instead of
267267
rule #minSigned(ITYPE) => 0 -Int #pow1(ITYPE)
268268
```
269269

270-
Lookups
271-
-------
270+
Map Lookups
271+
-----------
272272

273273
```k
274274
rule (_MAP:Map [KEY <- VAL])[KEY] => VAL [simplification]
275275
```
276276

277+
List Operations
278+
---------------
279+
280+
These should probably be integrated into `domains.md`
281+
282+
```k
283+
rule (L1:List ListItem(X:KItem) _:List)[size(L1)] => X
284+
[simplification]
285+
286+
rule (L1:List ListItem(_:KItem) L2:List)[size(L1) <- V] =>
287+
L1:List ListItem(V) L2:List
288+
[simplification]
289+
290+
rule (ListItem(X:KItem) _:List)[0] => X
291+
[simplification]
292+
293+
rule (ListItem(_) L:List)[N:Int] => L[ N -Int 1]
294+
requires N >Int 0
295+
[simplification]
296+
297+
rule (ListItem(_) L:List)[0 <- X:KItem] => ListItem(X) L
298+
[simplification]
299+
300+
rule (ListItem(A) L:List)[N:Int <- X:KItem] => ListItem(A) (L[ N -Int 1 <- X])
301+
requires N >Int 0
302+
[simplification]
303+
304+
rule size(L1:List L2:List) =>
305+
size(L1) +Int size(L2)
306+
[simplification]
307+
308+
rule size(_:List) >=Int 0 => true [simplification, smt-lemma]
309+
```
310+
277311
Memory
278312
------
279313

pykwasm/src/pykwasm/kdist/wasm-semantics/wasm.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,7 @@ The `*_local` instructions are defined here.
572572
rule <instrs> #local.get(I) => .K ... </instrs>
573573
<valstack> VALSTACK => {LOCALS [ I ]}:>Val : VALSTACK </valstack>
574574
<locals> LOCALS </locals>
575+
requires isVal(LOCALS [ I ])
575576
576577
rule <instrs> #local.set(I) => .K ... </instrs>
577578
<valstack> VALUE : VALSTACK => VALSTACK </valstack>
@@ -623,7 +624,7 @@ The importing and exporting parts of specifications are dealt with in the respec
623624
...
624625
</globals>
625626
requires #typeMatches(TYP, VAL)
626-
627+
627628
```
628629

629630
The `get` and `set` instructions read and write globals.
@@ -704,7 +705,7 @@ The `get` and `set` instructions read and write globals.
704705
</tabInst>
705706
requires 0 <=Int I
706707
andBool I <Int size(TDATA)
707-
708+
708709
rule [tableGet-trap]:
709710
<instrs> #tableGet( TADDR, I) => trap ... </instrs>
710711
<tabInst>
@@ -732,7 +733,7 @@ The `get` and `set` instructions read and write globals.
732733
<tabAddrs> ... TID |-> TADDR ... </tabAddrs>
733734
...
734735
</moduleInst>
735-
736+
736737
rule [tableSet-oob]:
737738
<instrs> #tableSet(TADDR, _VAL, I) => trap ... </instrs>
738739
<tabInst>
@@ -840,7 +841,7 @@ The `get` and `set` instructions read and write globals.
840841
// ------------------------------------------------------
841842
rule [tableFill-zero]:
842843
<instrs> #tableFill(_, 0, _, _) => .K ... </instrs>
843-
844+
844845
rule [tableFill-loop]:
845846
<instrs> #tableFill(TID, N, RVAL, I)
846847
=> <i32> I
@@ -1617,7 +1618,7 @@ Element Segments
16171618
syntax Alloc ::= allocelem(RefValType, ListRef, OptionalId)
16181619
// -----------------------------------------------------
16191620
rule [elem-active]:
1620-
<instrs> #elem(TYPE:RefValType, INIT:ListRef, MODE:ElemMode, OID:OptionalId)
1621+
<instrs> #elem(TYPE:RefValType, INIT:ListRef, MODE:ElemMode, OID:OptionalId)
16211622
=> allocelem(TYPE, INIT, OID)
16221623
~> #elemAux(size(INIT), MODE)
16231624
...
@@ -1668,11 +1669,11 @@ Element Segments
16681669
syntax ListRef ::= resolveAddrs(ListInt, ListRef) [function]
16691670
// -----------------------------------------------------------
16701671
rule resolveAddrs(_, .ListRef) => .ListRef
1671-
rule resolveAddrs(FADDRS, ListItem(<TYP> I) IS)
1672-
=> ListItem(<TYP> FADDRS {{ I }} orDefault -1) resolveAddrs(FADDRS, IS)
1673-
rule resolveAddrs(FADDRS, ListItem(<TYP> null) IS)
1674-
=> ListItem(<TYP> null) resolveAddrs(FADDRS, IS)
1675-
1672+
rule resolveAddrs(FADDRS, ListItem(<TYP> I) IS)
1673+
=> ListItem(<TYP> FADDRS {{ I }} orDefault -1) resolveAddrs(FADDRS, IS)
1674+
rule resolveAddrs(FADDRS, ListItem(<TYP> null) IS)
1675+
=> ListItem(<TYP> null) resolveAddrs(FADDRS, IS)
1676+
16761677
```
16771678

16781679
Data Segments

tests/proofs/locals-spec.k

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
11
requires "kwasm-lemmas.md"
22

33
module LOCALS-SPEC
4-
imports KWASM-LEMMAS
4+
imports WASM
55

66
claim <instrs> #local.get(X) ~> #local.set(X) => .K ... </instrs>
77
<locals>
8-
X |-> _:IVal
8+
Locals:List
9+
ListItem(_:IVal)
10+
_:List
911
</locals>
12+
requires size(Locals) ==Int X
1013

1114
claim <instrs> #local.get(X) ~> #local.set(X) => .K ... </instrs>
1215
<locals>
13-
X |-> _:FVal
16+
Locals:List
17+
ListItem(_:FVal)
18+
_:List
1419
</locals>
20+
requires size(Locals) ==Int X
1521

1622
claim <instrs> #local.get(X) ~> #local.set(X) => .K ... </instrs>
1723
<locals>
18-
X |-> _:RefVal
24+
Locals:List
25+
ListItem(_:RefVal)
26+
_:List
1927
</locals>
28+
requires size(Locals) ==Int X
2029

2130
endmodule

tests/proofs/loops-spec.k

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ module LOOPS-SPEC
2929
</instrs>
3030
<valstack> _ => STACK </valstack>
3131
<locals>
32-
0 |-> < ITYPE > (I => 0)
33-
1 |-> < ITYPE > (X => X +Int ((I *Int (I +Int 1)) /Int 2))
32+
ListItem(< ITYPE > (I => 0))
33+
ListItem(< ITYPE > (X => X +Int ((I *Int (I +Int 1)) /Int 2)))
3434
</locals>
3535
requires #inUnsignedRange(ITYPE, I)
3636
andBool I >Int 0
@@ -60,8 +60,8 @@ module LOOPS-SPEC
6060
...
6161
</instrs>
6262
<locals>
63-
0 |-> < ITYPE > (N => 0)
64-
1 |-> < ITYPE > (0 => (N *Int (N +Int 1)) /Int 2)
63+
ListItem(< ITYPE > (N => 0))
64+
ListItem(< ITYPE > (0 => (N *Int (N +Int 1)) /Int 2))
6565
</locals>
6666
requires #inUnsignedRange(ITYPE, N)
6767
andBool N >Int 0

tests/proofs/memory-spec.k

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,24 @@ module MEMORY-SPEC
77
<curModIdx> CUR </curModIdx>
88
<moduleInst>
99
<modIdx> CUR </modIdx>
10-
<memAddrs> 0 |-> MEMADDR </memAddrs>
10+
<memAddrs> ListItem(MEMADDR) </memAddrs>
1111
...
1212
</moduleInst>
13-
<memInst>
14-
<mAddr> MEMADDR </mAddr>
15-
<msize> SIZE </msize>
16-
<mdata> _BM </mdata>
17-
...
18-
</memInst>
13+
<mems> MEMS1:List ListItem(memInst(_, SIZE, _)) _:List </mems>
1914
requires
20-
ADDR +Int #numBytes(i64) <=Int SIZE *Int #pageSize()
21-
andBool #inUnsignedRange(i32, ADDR)
15+
#inUnsignedRange(i32, ADDR)
16+
andBool size(MEMS1) ==Int MEMADDR
17+
andBool ADDR +Int #numBytes(i64) <=Int SIZE *Int #pageSize()
2218

2319
claim <instrs> i32.const ADDR ~> i32.const ADDR ~> #load(ITYPE:IValType, load, 0) ~> #store(ITYPE, store, 0) => .K ... </instrs>
2420
<curModIdx> CUR </curModIdx>
2521
<moduleInst>
2622
<modIdx> CUR </modIdx>
27-
<memAddrs> 0 |-> MEMADDR </memAddrs>
23+
<memAddrs> ListItem(MEMADDR) </memAddrs>
2824
...
2925
</moduleInst>
30-
<memInst>
31-
<mAddr> MEMADDR </mAddr>
32-
<msize> SIZE </msize>
33-
<mdata> _BM </mdata>
34-
...
35-
</memInst>
26+
<mems> MEMS1:List ListItem(memInst(_, SIZE, _)) _:List </mems>
3627
requires
37-
#get(#chop(<i32> ADDR)) +Int #numBytes(ITYPE) <=Int SIZE *Int #pageSize()
28+
size(MEMS1) ==Int MEMADDR
29+
andBool #get(#chop(<i32> ADDR)) +Int #numBytes(ITYPE) <=Int SIZE *Int #pageSize()
3830
endmodule

tests/proofs/wrc20-spec.k

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,26 @@ module WRC20-SPEC
1414
~> (invoke NEXTADDR) // TODO: Use `call`.
1515
~> #store(i64, store, 0)
1616
=> .K
17-
...
17+
// ...
1818
</instrs>
1919
<curModIdx> CUR </curModIdx>
2020
<moduleInst>
2121
<modIdx> CUR </modIdx>
2222
<types> #wrc20ReverseBytesTypeIdx |-> #wrc20ReverseBytesType </types>
23-
<memAddrs> 0 |-> MEMADDR </memAddrs>
24-
<funcAddrs> _ => ?_ </funcAddrs>
23+
<memAddrs> ListItem(MEMADDR) </memAddrs>
24+
<funcAddrs> FUNCADDRS => ?_ </funcAddrs>
2525
<nextFuncIdx> NEXTFUNCIDX => NEXTFUNCIDX +Int 1 </nextFuncIdx>
2626
...
2727
</moduleInst>
2828
<funcs> .Bag => ?_ </funcs>
2929
<nextFuncAddr> NEXTADDR => NEXTADDR +Int 1 </nextFuncAddr>
30-
<memInst>
31-
<mAddr> MEMADDR </mAddr>
32-
<msize> SIZE </msize>
33-
<mdata> BM => ?BM' </mdata>
34-
...
35-
</memInst>
30+
<mems> MEMS1:List ListItem(memInst(_, SIZE, BM => ?BM')) _:List </mems>
3631
// TODO: Make function out of this tricky side condition.
3732
requires ADDR +Int #numBytes(i64) <=Int SIZE *Int #pageSize()
33+
andBool NEXTFUNCIDX >=Int 0
34+
andBool NEXTFUNCIDX ==Int size(FUNCADDRS)
3835
andBool #inUnsignedRange(i32, ADDR)
36+
andBool size(MEMS1) ==Int MEMADDR
3937
ensures #getRange(BM, ADDR +Int 0, 1) ==Int #getRange(?BM', ADDR +Int 7, 1)
4038
andBool #getRange(BM, ADDR +Int 1, 1) ==Int #getRange(?BM', ADDR +Int 6, 1)
4139
andBool #getRange(BM, ADDR +Int 2, 1) ==Int #getRange(?BM', ADDR +Int 5, 1)

0 commit comments

Comments
 (0)