Skip to content

Commit ffd9552

Browse files
authored
kevm: add search command (#412)
* kevm: add search command * Jenkinsfile, Makefile, tests/interactive: add example search commands * Makefile, tests/interactive/search: more tests, simpler interface * kevm: correct documentation
1 parent 160f2f8 commit ffd9552

11 files changed

+702
-2
lines changed

Jenkinsfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ pipeline {
130130
'''
131131
}
132132
}
133+
stage('Haskell Search') {
134+
steps {
135+
sh '''
136+
make test-interactive-search TEST_SYMBOLIC_BACKEND=haskell -j4
137+
'''
138+
}
139+
}
133140
stage('KEVM help') {
134141
steps {
135142
sh '''

Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export LUA_PATH
4141
test test-all test-conformance test-slow-conformance test-all-conformance \
4242
test-vm test-slow-vm test-all-vm test-bchain test-slow-bchain test-all-bchain \
4343
test-proof test-klab-prove test-parse test-failure \
44-
test-interactive test-interactive-help test-interactive-run test-interactive-prove \
44+
test-interactive test-interactive-help test-interactive-run test-interactive-prove test-interactive-search \
4545
media media-pdf sphinx metropolis-theme
4646
.SECONDARY:
4747

@@ -383,6 +383,11 @@ tests/%.parse: tests/%
383383
tests/%.prove: tests/%
384384
$(TEST) prove --backend $(TEST_SYMBOLIC_BACKEND) $< --format-failures --def-module $(KPROVE_MODULE)
385385

386+
tests/%.search: tests/%
387+
$(TEST) search --backend $(TEST_SYMBOLIC_BACKEND) $< "<statusCode> EVMC_INVALID_INSTRUCTION </statusCode>" > $@-out
388+
$(CHECK) $@-expected $@-out
389+
rm -rf $@-out
390+
386391
tests/%.klab-prove: tests/%
387392
$(TEST) klab-prove --backend $(TEST_SYMBOLIC_BACKEND) $< --format-failures --def-module $(KPROVE_MODULE)
388393

@@ -451,11 +456,14 @@ test-failure: $(failure_tests:=.run-expected)
451456

452457
# Interactive Tests
453458

454-
test-interactive: test-interactive-run test-interactive-prove test-interactive-help
459+
test-interactive: test-interactive-run test-interactive-prove test-interactive-search test-interactive-help
455460

456461
test-interactive-run: $(smoke_tests_run:=.run-interactive)
457462
test-interactive-prove: $(smoke_tests_prove:=.prove)
458463

464+
search_tests:=$(wildcard tests/interactive/search/*.evm)
465+
test-interactive-search: $(search_tests:=.search)
466+
459467
test-interactive-help:
460468
$(TEST) help
461469

kevm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ run_prove() {
6060
kprove --directory "$backend_dir" "$run_file" "$@"
6161
}
6262

63+
run_search() {
64+
local search_pattern
65+
search_pattern="$1" ; shift
66+
export K_OPTS=-Xmx8G
67+
run_krun --search --pattern "$search_pattern" "$@"
68+
}
69+
6370
run_klab() {
6471
local run_mode klab_log
6572

@@ -132,6 +139,7 @@ if [[ "$run_command" == 'help' ]]; then
132139
$0 interpret [--backend (ocaml|llvm)] <pgm> <interpreter arg>*
133140
$0 kast [--backend (ocaml|java)] <pgm> <output format> <K arg>*
134141
$0 prove [--backend (java|haskell)] <spec> <K arg>* -m <def_module>
142+
$0 search [--backend (java|haskell)] <pgm> <pattern> <K arg>*
135143
$0 klab-run <pgm> <K arg>*
136144
$0 klab-prove <spec> <K arg>* -m <def_module>
137145
$0 klab-view <spec>
@@ -140,6 +148,7 @@ if [[ "$run_command" == 'help' ]]; then
140148
$0 interpret : Run JSON EVM programs without K Frontend (external parser)
141149
$0 kast : Parse an EVM program and output it in a supported format
142150
$0 prove : Run an EVM K proof
151+
$0 search : Search for a K pattern in an EVM program execution
143152
$0 klab-(run|prove) : Run program or prove spec and dump StateLogs which KLab can read
144153
$0 klab-view : View the statelog associated with a given program or spec
145154
@@ -148,6 +157,7 @@ if [[ "$run_command" == 'help' ]]; then
148157
<K arg> is an argument you want to pass to K.
149158
<interpreter arg> is an argument you want to pass to the derived interpreter.
150159
<output format> is the format for Kast to output the term in.
160+
<pattern> is the configuration pattern to search for.
151161
<def_module> is the module to take as axioms when doing verification.
152162
153163
klab-view: Make sure that the 'klab/bin' directory is on your PATH to use this option.
@@ -179,6 +189,7 @@ case "$run_command-$backend" in
179189
kast-@(ocaml|java|llvm|haskell) ) run_kast "$@" ;;
180190
interpret-@(ocaml|llvm) ) run_interpret "$@" ;;
181191
prove-@(java|haskell) ) run_prove "$@" ;;
192+
search-@(java|haskell) ) run_search "$@" ;;
182193
klab-@(run|prove)-java ) run_klab "${run_command#klab-}" "$@" ;;
183194
klab-view-java ) view_klab "$@" ;;
184195
*) $0 help ; fatal "Unknown command on backend: $run_command $backend" ;;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
load "exec" : { "gas" : 10000
2+
,"code" : PUSH(1, 3) ; PUSH(1, 4) ; ADD
3+
; PUSH(1, 8) ; EQ
4+
; PUSH(1, 12) ; JUMPI // jumpi("end")
5+
; INVALID
6+
; JUMPDEST // jumpdest("end")
7+
; STOP
8+
; .OpCodes
9+
}
10+
11+
start
12+
13+
.EthereumSimulation

0 commit comments

Comments
 (0)