Skip to content
This repository was archived by the owner on Mar 23, 2023. It is now read-only.

Commit 04c38ee

Browse files
committed
Merge remote-tracking branch 'origin/master' into balance-verification
2 parents ed3f06e + ffdd31e commit 04c38ee

5 files changed

Lines changed: 64 additions & 88 deletions

File tree

Makefile

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ export LUA_PATH
2121

2222
.PHONY: all clean \
2323
deps haskell-deps \
24-
defn defn-llvm defn-java defn-haskell \
24+
defn defn-llvm defn-haskell \
2525
definition-deps wasm-definitions eei-definitions \
26-
build build-llvm build-java build-haskell \
27-
test test-execution test-simple test-prove test-klab-prove \
26+
build build-llvm build-haskell \
27+
test test-execution test-simple test-prove \
2828
media presentations reports
2929

3030
all: build
@@ -52,12 +52,10 @@ deps: $(wasm_submodule)/make.timestamp $(eei_submodule)/make.timestamp definitio
5252
definition-deps: wasm-definitions eei-definitions
5353

5454
wasm-definitions:
55-
$(wasm_make) -B defn-java
5655
$(wasm_make) -B defn-llvm
5756
$(wasm_make) -B defn-haskell
5857

5958
eei-definitions: $(eei_source_files)
60-
$(eei_make) -B defn-java
6159
$(eei_make) -B defn-llvm
6260
$(eei_make) -B defn-haskell
6361

@@ -77,10 +75,6 @@ llvm_dir:=$(defn_dir)/llvm
7775
llvm_defn:=$(patsubst %, $(llvm_dir)/%, $(all_k_files))
7876
llvm_kompiled:=$(llvm_dir)/ewasm-test-kompiled/interpreter
7977

80-
java_dir:=$(defn_dir)/java
81-
java_defn:=$(patsubst %, $(java_dir)/%, $(all_k_files))
82-
java_kompiled:=$(java_dir)/ewasm-test-kompiled/compiled.txt
83-
8478
haskell_dir:=$(defn_dir)/haskell
8579
haskell_defn:=$(patsubst %, $(haskell_dir)/%, $(all_k_files))
8680
haskell_kompiled:=$(haskell_dir)/ewasm-test-kompiled/definition.kore
@@ -90,21 +84,15 @@ syntax_module=EWASM-TEST-SYNTAX
9084

9185
# Tangle definition from *.md files
9286

93-
defn: defn-llvm defn-java defn-haskell
87+
defn: defn-llvm defn-haskell
9488
defn-llvm: $(llvm_defn)
95-
defn-java: $(java_defn)
9689
defn-haskell: $(haskell_defn)
9790

9891
$(llvm_dir)/%.k: %.md $(tangler)
9992
@echo "== tangle: $@"
10093
mkdir -p $(dir $@)
10194
pandoc --from markdown --to $(tangler) --metadata=code:.k $< > $@
10295

103-
$(java_dir)/%.k: %.md $(tangler)
104-
@echo "== tangle: $@"
105-
mkdir -p $(dir $@)
106-
pandoc --from markdown --to $(tangler) --metadata=code:.k $< > $@
107-
10896
$(haskell_dir)/%.k: %.md $(tangler)
10997
@echo "== tangle: $@"
11098
mkdir -p $(dir $@)
@@ -114,9 +102,8 @@ $(haskell_dir)/%.k: %.md $(tangler)
114102

115103
KOMPILE_OPTS :=
116104

117-
build: build-llvm build-java build-haskell
105+
build: build-llvm build-haskell
118106
build-llvm: $(llvm_kompiled)
119-
build-java: $(java_kompiled)
120107
build-haskell: $(haskell_kompiled)
121108

122109
$(llvm_kompiled): $(llvm_defn)
@@ -127,14 +114,6 @@ $(llvm_kompiled): $(llvm_defn)
127114
--syntax-module $(syntax_module) $< \
128115
$(KOMPILE_OPTS)
129116

130-
$(java_kompiled): $(java_defn)
131-
@echo "== kompile: $@"
132-
$(k_bin)/kompile --backend java \
133-
--directory $(java_dir) -I $(java_dir) \
134-
--main-module $(main_module) \
135-
--syntax-module $(syntax_module) $< \
136-
$(KOMPILE_OPTS)
137-
138117
$(haskell_kompiled): $(haskell_defn)
139118
@echo "== kompile: $@"
140119
$(k_bin)/kompile --backend haskell \
@@ -150,6 +129,7 @@ TEST_CONCRETE_BACKEND:=llvm
150129
TEST_SYMBOLIC_BACKEND:=haskell
151130
TEST:=./kewasm
152131
KPROVE_MODULE:=KEWASM-LEMMAS
132+
KPROVE_OPTS:=
153133
CHECK:=git --no-pager diff --no-index --ignore-all-space
154134

155135
tests/proofs/wrc20-do-balance-spec.k.prove: KPROVE_MODULE=VERIFICATION
@@ -177,10 +157,7 @@ tests/%.parse: tests/%
177157
rm -rf $@-out
178158

179159
tests/%.prove: tests/%
180-
$(TEST) prove --backend $(TEST_SYMBOLIC_BACKEND) $< --format-failures --def-module $(KPROVE_MODULE)
181-
182-
tests/%.klab-prove: tests/%
183-
$(TEST) klab-prove --backend $(TEST_SYMBOLIC_BACKEND) $< --format-failures --def-module $(KPROVE_MODULE)
160+
$(TEST) prove --backend $(TEST_SYMBOLIC_BACKEND) $(filter --repl, $(KPROVE_OPTS)) $< --format-failures --def-module $(KPROVE_MODULE) $(filter-out --repl, $(KPROVE_OPTS))
184161

185162
### Execution Tests
186163

@@ -197,6 +174,3 @@ quick_proof_tests:=$(filter-out $(slow_proof_tests), $(proof_tests))
197174

198175
test-prove: $(proof_tests:=.prove)
199176

200-
### KLab interactive
201-
202-
test-klab-prove: $(quick_proof_tests:=.klab-prove)

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,33 @@ K Semantics of Ewasm
1010

1111
Prototype semantics of [Ewasm](https://github.com/ewasm/design) in the K framework.
1212

13-
```
13+
```sh
1414
git submodule update --init --recursive
1515
make deps
1616
make build
1717
```
1818

19+
# Proving
20+
21+
Run existing proofs using `make` rules.
22+
23+
```sh
24+
make tests/proofs/example-spec.k.prove
25+
make tests/proofs/example-spec.k.repl
26+
```
27+
28+
You can run the prover on your own specification, with a lemmas module of your choice.
29+
30+
```sh
31+
./kewasm prove <path>/<to>/<spec> -m <LEMMAS-MODULE> # Runs the prover on the given spec, using LEMMAS-MODULE as the top-level sematics module.
32+
```
33+
34+
You can add the `--repl` flag to run the proof in an interactive REPL, where you can step through the proof and explore its branches.
35+
36+
```sh
37+
./kewasm prove <path>/<to>/<spec> -m <LEMMAS-MODULE> # Runs the prover on the given spec, using LEMMAS-MODULE as the top-level sematics module.
38+
```
39+
1940
# Structure
2041

2142
This project makes use of the K framework [EEI](https://github.com/kframework/eei-semantics) and [Wasm](https://github.com/kframework/wasm-semantics) semantics.

deps/wasm-semantics

kast.kscript

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
alias kclaim x = claim x | kast -i kore -o pretty -d .build/defn/haskell /dev/stdin
2+
alias kaxiom x = axiom x | kast -i kore -o pretty -d .build/defn/haskell /dev/stdin
3+
alias konfig = config | kast -i kore -o pretty -d .build/defn/haskell /dev/stdin
4+
alias konfig-n x = config x | kast -i kore -o pretty -d .build/defn/haskell /dev/stdin
5+
alias ktry x = try x | kast -i kore -o pretty -d .build/defn/haskell /dev/stdin
6+
alias ktryf x = tryf x | kast -i kore -o pretty -d .build/defn/haskell /dev/stdin
7+
alias krule = rule | kast -i kore -o pretty -d .build/defn/haskell /dev/stdin
8+
alias krule-n x = rule x | kast -i kore -o pretty -d .build/defn/haskell /dev/stdin

kewasm

Lines changed: 26 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ wasm_dir="${WASM_DIR:-$ewasm_dir/deps/wasm-semantics}"
88
build_dir="$ewasm_dir/.build"
99
defn_dir="$build_dir/defn"
1010
lib_dir="$build_dir/local/lib"
11+
haskell_backend_dir="$wasm_dir/deps/k/haskell-backend/src/main/native/haskell-backend"
1112
k_release_dir="${K_RELEASE:-$wasm_dir/deps/k/k-distribution/target/release/k}"
1213

1314
export PATH="$k_release_dir/lib/native/linux:$k_release_dir/lib/native/linux64:$k_release_dir/bin/:$PATH"
@@ -17,10 +18,6 @@ test_logs="$build_dir/logs"
1718
mkdir -p "$test_logs"
1819
test_log="$test_logs/tests.log"
1920

20-
KLAB_OUT="${KLAB_OUT:-$build_dir/klab}"
21-
KLAB_NODE_STACK_SIZE="${KLAB_NODE_STACK_SIZE:-30000}"
22-
export KLAB_OUT
23-
2421
# Utilities
2522
# ---------
2623

@@ -53,60 +50,31 @@ run_kast() {
5350

5451
run_prove() {
5552
export K_OPTS=-Xmx8G
56-
kprove --directory "$backend_dir" "$run_file" "$@"
57-
}
58-
59-
run_klab() {
60-
local run_mode klab_log
61-
62-
run_mode="$1" ; shift
63-
klab_log="$(basename "${run_file%-spec.k}")"
64-
65-
"$0" "$run_mode" --backend java "$run_file" \
66-
--state-log --state-log-path "$KLAB_OUT/data" --state-log-id "$klab_log" \
67-
--state-log-events OPEN,EXECINIT,SEARCHINIT,REACHINIT,REACHTARGET,REACHPROVED,NODE,RULE,SRULE,RULEATTEMPT,IMPLICATION,Z3QUERY,Z3RESULT,CLOSE \
68-
--output-flatten "_Map_ #And" \
69-
--output-tokenize "listStmt listValTypes <_>_ i32_WASM-DATA i64_WASM-DATA _:__WASM-DATA" \
70-
--no-alpha-renaming --restore-original-names --no-sort-collections \
71-
--output json \
72-
"$@"
73-
}
74-
75-
view_klab() {
76-
local klab_log
77-
78-
klab_log="$(basename "${run_file%-spec.k}")"
79-
80-
# klab often runs out of stack space when running long-running KWasm programs
81-
# klab debug "$klab_log"
82-
node --stack-size=$KLAB_NODE_STACK_SIZE $(dirname $(which klab))/../libexec/klab-debug "$klab_log"
53+
haskell_backend_command="$k_release_dir/bin/kore-exec"
54+
if $repl; then
55+
haskell_backend_command="$k_release_dir/bin/kore-repl --repl-script $ewasm_dir/kast.kscript"
56+
fi
57+
kprove --directory "$backend_dir" "$run_file" "$@" --haskell-backend-command "$haskell_backend_command"
8358
}
8459

8560
# Main
8661
# ----
8762

8863
usage() {
8964
echo "
90-
usage: $0 run [--backend (llvm|java|haskell)] <pgm> <K args>*
91-
$0 kast [--backend (llvm|java)] <pgm> <output format> <K args>*
92-
$0 prove [--backend (java|haskell)] <spec> <K args>* -m <def_module>
93-
$0 klab-run <pgm> <K arg>*
94-
$0 klab-prove <spec> <K arg>* -m <def_module>
95-
$0 klab-view [<pgm>|<spec>]
65+
usage: $0 run [--backend (llvm|haskell)] <pgm> <K args>*
66+
$0 kast [--backend (llvm)] <pgm> <output format> <K args>*
67+
$0 prove [--backend (haskell)] [--repl] <spec> <K args>* -m <def_module>
9668
9769
$0 run : Run a single WebAssembly program
9870
$0 kast : Parse a single WebAssembly program and output it in supported format
9971
$0 prove : Run a WebAssembly K proof
100-
$0 klab-(run|prove) : Run or prove a spec and dump StateLogs which KLab can read
101-
$0 klab-view : Launch KLab on the StateLog associated with the given program/spec.
10272
103-
Note: <pgm> is a path to a file containing a WebAssembly program.
73+
Note: <pgm> is a path to a file containing a EWasm program.
10474
<spec> is a K specification to be proved.
10575
<K args> are any arguments you want to pass to K when executing/proving.
10676
<output format> is the format for Kast to output the term in.
10777
<def_module> is the module to take as axioms for verification.
108-
109-
KLab: Make sure that the 'klab/bin' directory is on your PATH to use this option.
11078
"
11179
}
11280

@@ -126,25 +94,30 @@ run_command="$1"; shift
12694
[[ ! -z ${1:-} ]] || usage_fatal "Must supply a file to work on."
12795

12896
backend="llvm"
97+
repl=false
12998
[[ ! "$run_command" == 'prove' ]] || backend='haskell'
130-
[[ ! "$run_command" =~ klab* ]] || backend='java'
131-
if [[ $# -gt 1 ]] && [[ $1 == '--backend' ]] || [[ $1 == '--definition' ]]; then
132-
backend="${2#wasm-}"
133-
shift 2
134-
fi
99+
args=()
100+
while [[ $# -gt 0 ]]; do
101+
arg="$1"
102+
case $arg in
103+
--backend) args+=("$arg" "$2") ; backend="$2" ; shift 2 ;;
104+
--repl) args+=("$arg") ; repl=true ; shift ;;
105+
*) break ;;
106+
esac
107+
done
108+
109+
! $repl || [[ "$backend" == "haskell" ]] || fatal "REPL option only available for Haskell backend."
110+
135111
backend_dir="$defn_dir/$backend"
136-
[[ ! "$backend" == "llvm" ]] || eval $(opam config env)
137112

138113
# get the run file
139114
[[ ! -z ${1:-} ]] || usage_fatal "Must supply a file to run on."
140115
run_file="$1" ; shift
141116
[[ -f "$run_file" ]] || fatal "File does not exist: $run_file"
142117

143118
case "$run_command-$backend" in
144-
run-@(llvm|java|haskell) ) run_krun "$@" ;;
145-
kast-@(llvm|java) ) run_kast "$@" ;;
146-
prove-@(java|haskell) ) run_prove "$@" ;;
147-
klab-@(run|prove)-java ) run_klab "${run_command#klab-}" "$@" ;;
148-
klab-view-java ) view_klab "$@" ;;
119+
run-@(llvm|haskell) ) run_krun "$@" ;;
120+
kast-llvm ) run_kast "$@" ;;
121+
prove-haskell ) run_prove "$@" ;;
149122
*) usage_fatal "Unknown command on '$backend' backend: $run_command" ;;
150123
esac

0 commit comments

Comments
 (0)