Skip to content

Commit a0dc06d

Browse files
authored
Organize repository, move sources into subdirectories (#1433)
* *.md => include/*.md: move k sources into src directory * Makefile: do not include test-suite specific lemma suites in package * Makefile, include/{. => kframework}/*.md: add subdirectory * Makefile, {tests/specs/ => include/kframework/lemmas}: move lemmas into include directory * Makefile: use relative path for PLUGIN_SUBMODULE * Makefile: include plugin in kframework directory directly * Makefile, cmake/: adjust for new directory structure of K imports * include/serialization: adjust import of krypto * tests/specs: adjust lemmas include * Makefile, kevm: remove now uneeded -I option for plugin * Makefile, kevm => bin/kevm: move script into subdirectory * flake.nix: adjust path for kevm * tests/erc20/verification: correct lemmas import * include/{buf, abi}: move definition of ceil32 * include/lemmas: lower dependency from EDSL => BUF for LEMMAS module * tests/lemmas-spec: adjust lemmas-spec to include EDSL * Makefile: correct path of optimizations module * Makefile: correct Foundry build * .github/test-pr: build foundry definition ahead of time * tests/specs/opcodes: adjust requires * tests/specs/benchmarks: adjust requires * tests/specs/benchmarks/verification: correct module import * package/nix/kevm.patch: correct patch * tests/specs/benchmarks: add lemma module back in for verification * tests/specs/benchmarks: simplify imports * tests/specs/functional/lemmas-spec: adjust imports
1 parent 56d7e1b commit a0dc06d

36 files changed

+92
-90
lines changed

.github/workflows/test-pr.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ jobs:
106106
tag: kevm-ci-foundry-${{ github.sha }}
107107
- name: 'Build kevm-pyk'
108108
run: docker exec -t kevm-ci-foundry-${GITHUB_SHA} /bin/bash -c 'make kevm-pyk venv -j2'
109+
- name: 'Build Foundry'
110+
run: docker exec -t kevm-ci-foundry-${GITHUB_SHA} /bin/bash -c 'make build-foundry -j2'
109111
- name: 'Test Foundry'
110112
run: docker exec -t kevm-ci-foundry-${GITHUB_SHA} /bin/bash -c 'make test-foundry -j2 FOUNDRY_PAR=4'
111113
- name: 'Tear down Docker'

Makefile

Lines changed: 52 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ export C_INCLUDE_PATH
4040
export CPLUS_INCLUDE_PATH
4141
export PATH
4242

43-
PLUGIN_SUBMODULE := $(abspath $(DEPS_DIR)/plugin)
43+
PLUGIN_SUBMODULE := $(DEPS_DIR)/plugin
4444
PLUGIN_SOURCE := $(KEVM_INCLUDE)/kframework/blockchain-k-plugin/krypto.md
45-
export PLUGIN_SUBMODULE
45+
PLUGIN_FULL_PATH := $(abspath ${PLUGIN_SUBMODULE})
46+
export PLUGIN_FULL_PATH
4647

4748

4849
.PHONY: all clean distclean \
@@ -147,17 +148,18 @@ k-deps:
147148
&& mvn --batch-mode package -DskipTests -Dllvm.backend.prefix=$(INSTALL_LIB)/kframework -Dllvm.backend.destdir=$(CURDIR)/$(BUILD_DIR) -Dproject.build.type=$(K_BUILD_TYPE) $(K_MVN_ARGS) \
148149
&& DESTDIR=$(CURDIR)/$(BUILD_DIR) PREFIX=$(INSTALL_LIB)/kframework package/package
149150

151+
plugin_k_include := $(KEVM_INCLUDE)/kframework/plugin
150152
plugin_include := $(KEVM_LIB)/blockchain-k-plugin/include
151153
plugin_k := krypto.md
152154
plugin_c := plugin_util.cpp crypto.cpp blake2.cpp plugin_util.h blake2.h
153-
plugin_includes := $(patsubst %, $(plugin_include)/kframework/%, $(plugin_k))
154-
plugin_c_includes := $(patsubst %, $(plugin_include)/c/%, $(plugin_c))
155+
plugin_includes := $(patsubst %, $(plugin_k_include)/%, $(plugin_k))
156+
plugin_c_includes := $(patsubst %, $(plugin_include)/c/%, $(plugin_c))
155157

156158
$(plugin_include)/c/%: $(PLUGIN_SUBMODULE)/plugin-c/%
157159
@mkdir -p $(dir $@)
158160
install $< $@
159161

160-
$(plugin_include)/kframework/%: $(PLUGIN_SUBMODULE)/plugin/%
162+
$(plugin_k_include)/%: $(PLUGIN_SUBMODULE)/plugin/%
161163
@mkdir -p $(dir $@)
162164
install $< $@
163165

@@ -168,48 +170,40 @@ plugin-deps: $(plugin_includes) $(plugin_c_includes)
168170

169171
KOMPILE := $(KEVM) kompile
170172

171-
kevm_files := abi.md \
172-
asm.md \
173-
buf.md \
174-
data.md \
175-
driver.md \
176-
edsl.md \
177-
evm.md \
178-
evm-types.md \
179-
evm-node.md \
180-
foundry.md \
181-
hashed-locations.md \
182-
infinite-gas.md \
183-
json-rpc.md \
184-
network.md \
185-
optimizations.md \
186-
serialization.md \
187-
state-utils.md \
188-
word.md
189-
190-
kevm_lemmas := lemmas.k \
191-
int-simplification.k \
192-
erc20/evm-symbolic.k \
193-
mcd/bin_runtime.k \
194-
mcd/storage.k \
195-
mcd/verification.k \
196-
mcd/word-pack.k
197-
198-
lemma_includes := $(patsubst %, $(KEVM_INCLUDE)/kframework/lemmas/%, $(kevm_lemmas))
173+
kevm_files := abi.md \
174+
asm.md \
175+
buf.md \
176+
data.md \
177+
driver.md \
178+
edsl.md \
179+
evm.md \
180+
evm-types.md \
181+
evm-node.md \
182+
foundry.md \
183+
hashed-locations.md \
184+
infinite-gas.md \
185+
json-rpc.md \
186+
network.md \
187+
optimizations.md \
188+
serialization.md \
189+
state-utils.md \
190+
word.md \
191+
lemmas/lemmas.k \
192+
lemmas/int-simplification.k
199193

200194
kevm_includes := $(patsubst %, $(KEVM_INCLUDE)/kframework/%, $(kevm_files))
201195

202-
includes := $(kevm_includes) $(lemma_includes) $(plugin_includes) $(plugin_c_includes)
196+
includes := $(kevm_includes) $(plugin_includes) $(plugin_c_includes)
203197

204-
$(KEVM_INCLUDE)/kframework/%.md: %.md
198+
$(KEVM_INCLUDE)/%: include/%
205199
@mkdir -p $(dir $@)
206200
install $< $@
207201

208202
$(KEVM_INCLUDE)/kframework/lemmas/%.k: tests/specs/%.k
209203
@mkdir -p $(dir $@)
210204
install $< $@
211205

212-
KOMPILE_OPTS = -I $(INSTALL_INCLUDE)/kframework -I $(INSTALL_LIB)/blockchain-k-plugin/include/kframework
206+
KOMPILE_OPTS = -I $(INSTALL_INCLUDE)/kframework
213207

214208
ifneq (,$(RELEASE))
215209
KOMPILE_OPTS += -O2
@@ -230,10 +224,11 @@ $(KEVM_LIB)/$(haskell_kompiled): $(libsecp256k1_out)
230224
endif
231225

232226
$(KEVM_LIB)/$(haskell_kompiled): $(kevm_includes) $(plugin_includes) $(KEVM_BIN)/kevm
233-
$(KOMPILE) --backend haskell \
234-
$(haskell_main_file) $(HASKELL_KOMPILE_OPTS) \
235-
--main-module $(haskell_main_module) \
236-
--syntax-module $(haskell_syntax_module) \
227+
$(KOMPILE) --backend haskell \
228+
$(KEVM_INCLUDE)/kframework/$(haskell_main_file) \
229+
$(HASKELL_KOMPILE_OPTS) \
230+
--main-module $(haskell_main_module) \
231+
--syntax-module $(haskell_syntax_module) \
237232
$(KOMPILE_OPTS) $(KEVM_OPTS)
238233

239234
# Standalone
@@ -250,10 +245,10 @@ $(KEVM_LIB)/$(llvm_kompiled): $(libcryptopp_out)
250245
endif
251246

252247
$(KEVM_LIB)/$(llvm_kompiled): $(kevm_includes) $(plugin_includes) $(plugin_c_includes) $(libff_out) $(KEVM_BIN)/kevm
253-
$(KOMPILE) --backend llvm \
254-
$(llvm_main_file) \
255-
--main-module $(llvm_main_module) \
256-
--syntax-module $(llvm_syntax_module) \
248+
$(KOMPILE) --backend llvm \
249+
$(KEVM_INCLUDE)/kframework/$(llvm_main_file) \
250+
--main-module $(llvm_main_module) \
251+
--syntax-module $(llvm_syntax_module) \
257252
$(KOMPILE_OPTS) $(KEVM_OPTS)
258253

259254
# Node
@@ -268,10 +263,10 @@ node_kompiled := $(node_dir)/build/kevm-vm
268263
export node_dir
269264

270265
$(KEVM_LIB)/$(node_kore): $(kevm_includes) $(plugin_includes) $(plugin_c_includes) $(libff_out) $(KEVM_BIN)/kevm
271-
$(KOMPILE) --backend node \
272-
$(node_main_file) \
273-
--main-module $(node_main_module) \
274-
--syntax-module $(node_syntax_module) \
266+
$(KOMPILE) --backend node \
267+
$(KEVM_INCLUDE)/kframework/$(node_main_file) \
268+
--main-module $(node_main_module) \
269+
--syntax-module $(node_syntax_module) \
275270
$(KOMPILE_OPTS) $(KEVM_OPTS)
276271

277272
$(KEVM_LIB)/$(node_kompiled): $(KEVM_LIB)/$(node_kore) $(protobuf_out) $(libff_out)
@@ -293,10 +288,11 @@ $(KEVM_LIB)/$(foundry_kompiled): $(libsecp256k1_out)
293288
endif
294289

295290
$(KEVM_LIB)/$(foundry_kompiled): $(kevm_includes) $(plugin_includes) $(lemma_includes) $(KEVM_BIN)/kevm
296-
$(KOMPILE) --backend foundry \
297-
$(foundry_main_file) $(HASKELL_KOMPILE_OPTS) \
298-
--main-module $(foundry_main_module) \
299-
--syntax-module $(foundry_syntax_module) \
291+
$(KOMPILE) --backend foundry \
292+
$(KEVM_INCLUDE)/kframework/$(foundry_main_file) \
293+
--main-module $(foundry_main_module) \
294+
--syntax-module $(foundry_syntax_module) \
295+
$(HASKELL_KOMPILE_OPTS) \
300296
$(KOMPILE_OPTS) $(KEVM_OPTS)
301297

302298
# Installing
@@ -314,7 +310,7 @@ install_libs := $(haskell_kompiled) \
314310
release.md \
315311
version
316312

317-
$(KEVM_BIN)/kevm: kevm
313+
$(KEVM_BIN)/%: bin/%
318314
@mkdir -p $(dir $@)
319315
install $< $@
320316

@@ -341,7 +337,7 @@ build: $(patsubst %, $(KEVM_BIN)/%, $(install_bins)) $(patsubst %, $(KEVM_LIB)/%
341337
build-llvm: $(KEVM_LIB)/$(llvm_kompiled) $(KEVM_LIB)/kore-json.py
342338
build-haskell: $(KEVM_LIB)/$(haskell_kompiled) $(KEVM_LIB)/kore-json.py
343339
build-node: $(KEVM_LIB)/$(node_kompiled)
344-
build-kevm: $(KEVM_BIN)/kevm $(kevm_includes) $(lemma_includes) $(plugin_includes)
340+
build-kevm: $(KEVM_BIN)/kevm $(kevm_includes) $(plugin_includes)
345341
build-foundry: $(KEVM_LIB)/$(foundry_kompiled) $(KEVM_LIB)/kore-json.py
346342

347343
all_bin_sources := $(shell find $(KEVM_BIN) -type f | sed 's|^$(KEVM_BIN)/||')
@@ -543,7 +539,7 @@ tests/specs/%.prove: tests/specs/% tests/specs/$$(firstword $$(subst /, ,$$*))/$
543539
$(KEVM) prove $< $(KEVM_OPTS) --backend $(TEST_SYMBOLIC_BACKEND) $(KPROVE_OPTS) \
544540
--definition tests/specs/$(firstword $(subst /, ,$*))/$(KPROVE_FILE)/$(TEST_SYMBOLIC_BACKEND)
545541

546-
tests/specs/%/timestamp: tests/specs/$$(firstword $$(subst /, ,$$*))/$$(KPROVE_FILE).$$(KPROVE_EXT) tests/specs/concrete-rules.txt $(kevm_includes) $(lemma_includes) $(plugin_includes) $(KEVM_BIN)/kevm
542+
tests/specs/%/timestamp: tests/specs/$$(firstword $$(subst /, ,$$*))/$$(KPROVE_FILE).$$(KPROVE_EXT) tests/specs/concrete-rules.txt $(kevm_includes) $(plugin_includes) $(KEVM_BIN)/kevm
547543
$(KOMPILE) --backend $(word 3, $(subst /, , $*)) $< \
548544
--definition tests/specs/$(firstword $(subst /, ,$*))/$(KPROVE_FILE)/$(word 3, $(subst /, , $*)) \
549545
--main-module $(KPROVE_MODULE) \
@@ -664,7 +660,7 @@ test-klab-prove: KPROVE_OPTS += --debugger
664660
test-klab-prove: $(smoke_tests_prove:=.prove)
665661

666662
# to generate optimizations.md, run: ./optimizer/optimize.sh &> output
667-
tests/specs/opcodes/evm-optimizations-spec.md: optimizations.md
663+
tests/specs/opcodes/evm-optimizations-spec.md: include/kframework/optimizations.md
668664
cat $< | sed 's/^rule/claim/' | sed 's/EVM-OPTIMIZATIONS/EVM-OPTIMIZATIONS-SPEC/' | grep -v 'priority(40)' > $@
669665

670666
# Parse Tests

kevm renamed to bin/kevm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ run_kevm_pyk() {
5555
case "${pyk_command}" in
5656
kompile|run|prove|solc-to-k|foundry-kompile|foundry-prove)
5757
pyk_args=(--definition "${backend_dir}")
58-
pyk_args+=(-I "${INSTALL_INCLUDE}/kframework" -I "${plugin_include}/kframework")
58+
pyk_args+=(-I "${INSTALL_INCLUDE}/kframework")
5959
;;
6060
esac
6161
! ${verbose} || pyk_args+=(--verbose)
@@ -73,7 +73,7 @@ run_kompile() {
7373

7474
kompile_opts=( "${run_file}" --emit-json )
7575
${pyk} || kompile_opts+=( --output-definition "${backend_dir}" )
76-
${pyk} || kompile_opts+=( -I "${INSTALL_INCLUDE}/kframework" -I "${plugin_include}/kframework" )
76+
${pyk} || kompile_opts+=( -I "${INSTALL_INCLUDE}/kframework" )
7777
${pyk} || kompile_opts+=( --hook-namespaces "JSON KRYPTO BLOCKCHAIN" )
7878
${pyk} || ! ${debug} || kompile_opts+=( --debug )
7979

@@ -190,7 +190,7 @@ run_prove() {
190190
proof_args=("${run_file}")
191191
if ! ${pyk}; then
192192
proof_args+=(--definition "${backend_dir}")
193-
proof_args+=( -I "${INSTALL_INCLUDE}/kframework" -I "${plugin_include}/kframework" )
193+
proof_args+=( -I "${INSTALL_INCLUDE}/kframework" )
194194
! ${debug} || proof_args+=(--debug)
195195
fi
196196

cmake/node/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ add_executable(kevm-vm
5050
$ENV{NODE_DIR}/vm/kevm/semantics.cpp
5151
$ENV{NODE_DIR}/plugin-c/blockchain.cpp
5252
$ENV{NODE_DIR}/plugin-c/world.cpp
53-
$ENV{PLUGIN_SUBMODULE}/plugin-c/blake2.cpp
54-
$ENV{PLUGIN_SUBMODULE}/plugin-c/crypto.cpp
55-
$ENV{PLUGIN_SUBMODULE}/plugin-c/plugin_util.cpp
53+
$ENV{PLUGIN_FULL_PATH}/plugin-c/blake2.cpp
54+
$ENV{PLUGIN_FULL_PATH}/plugin-c/crypto.cpp
55+
$ENV{PLUGIN_FULL_PATH}/plugin-c/plugin_util.cpp
5656
$ENV{LOCAL_LIB}/proto/proto/msg.pb.cc)
5757

5858
if(UNIX AND NOT APPLE)
@@ -65,7 +65,7 @@ if (APPLE)
6565
endif()
6666

6767
target_include_directories(kevm-vm
68-
PUBLIC $ENV{PLUGIN_SUBMODULE}/plugin-c
68+
PUBLIC $ENV{PLUGIN_FULL_PATH}/plugin-c
6969
PUBLIC $ENV{LOCAL_LIB}/proto
7070
PUBLIC $ENV{NODE_DIR}/plugin-c
7171
PUBLIC $ENV{NODE_DIR}/vm

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
postPatch = ''
9090
substituteInPlace ./cmake/node/CMakeLists.txt \
9191
--replace 'set(K_LIB ''${K_BIN}/../lib)' 'set(K_LIB ${k}/lib)'
92-
substituteInPlace ./kevm \
92+
substituteInPlace ./bin/kevm \
9393
--replace 'execute python3 -m kevm_pyk' 'execute ${final.kevm-pyk}/bin/kevm-pyk'
9494
'';
9595

abi.md renamed to include/kframework/abi.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,6 @@ where `F1 : F2 : F3 : F4` is the (two's complement) byte-array representation of
385385
386386
rule #getValue( #bytes4( X )) => X requires #rangeUInt(32, X)
387387
rule #getValue(#bytes32( X )) => X requires #rangeUInt(256, X)
388-
389-
syntax Int ::= #ceil32 ( Int ) [macro]
390-
// --------------------------------------
391-
rule #ceil32(N) => (N up/Int 32) *Int 32
392388
```
393389

394390
### ABI Event Logs
File renamed without changes.

buf.md renamed to include/kframework/buf.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ Claims should always use `#bufStrict` in LHS and `#buf` in RHS.
2525
syntax ByteArray ::= #bufStrict ( Int , Int ) [function]
2626
syntax ByteArray ::= #buf ( Int , Int ) [function, functional, smtlib(buf)]
2727
28+
syntax Int ::= #ceil32 ( Int ) [macro]
29+
// --------------------------------------
30+
rule #ceil32(N) => (N up/Int 32) *Int 32
31+
2832
endmodule
2933
3034
module BUF
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/specs/lemmas.k renamed to include/kframework/lemmas/lemmas.k

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
requires "evm.md"
2-
requires "edsl.md"
2+
requires "buf.md"
33
requires "int-simplification.k"
44

55
module LEMMAS [symbolic]
@@ -83,21 +83,21 @@ module LEMMAS [symbolic]
8383

8484
// #range
8585

86-
rule #range(_, _, K) =>
87-
.ByteArray
86+
rule #range(_, _, K) =>
87+
.ByteArray
8888
requires K <=Int 0 [simplification]
8989

90-
rule #range(M [ N := BUF:ByteArray ], L, K) =>
91-
#let W = minInt(K, N -Int L) #in #range(M, L, W) ++ #range(M [ N := BUF ], N, K -Int W)
90+
rule #range(M [ N := BUF:ByteArray ], L, K) =>
91+
#let W = minInt(K, N -Int L) #in #range(M, L, W) ++ #range(M [ N := BUF ], N, K -Int W)
9292
requires 0 <Int K andBool L <Int N [simplification]
9393

94-
rule #range(M [ N := BUF:ByteArray ], L, K) =>
94+
rule #range(M [ N := BUF:ByteArray ], L, K) =>
9595
#let S = L -Int N #in
9696
#let W = minInt(K, #sizeByteArray(BUF) -Int S) #in
9797
BUF [ S .. W ] ++ #range(M, N +Int #sizeByteArray(BUF), K -Int W)
9898
requires 0 <Int K andBool N <=Int L andBool L <=Int N +Int #sizeByteArray(BUF) [simplification]
9999

100-
rule #range(M [ N := BUF:ByteArray ], L, K) => #range(M, L, K)
100+
rule #range(M [ N := BUF:ByteArray ], L, K) => #range(M, L, K)
101101
requires 0 <Int K andBool N +Int #sizeByteArray(BUF) <=Int L [simplification]
102102

103103
rule #range( M [ N1 := BUF1:ByteArray ] [ N2 := BUF2:ByteArray ], L, K ) =>
@@ -151,7 +151,7 @@ endmodule
151151

152152
module LEMMAS-JAVA [symbolic, kast]
153153
imports EVM
154-
imports EDSL
154+
imports BUF
155155
imports K-REFLECTION
156156

157157
// ########################
@@ -273,7 +273,7 @@ endmodule
273273
module LEMMAS-HASKELL [symbolic, kore]
274274
imports INT-SYMBOLIC
275275
imports EVM
276-
imports EDSL
276+
imports BUF
277277

278278
// ########################
279279
// Word Reasoning
@@ -405,7 +405,7 @@ module LEMMAS-HASKELL [symbolic, kore]
405405
rule BA:ByteArray ==K #buf(32, DATA) => #buf(32, DATA) ==K BA [simplification, concrete(BA)]
406406
rule #buf(32, DATA) ==K BA:ByteArray => DATA ==Int #asInteger(BA) requires #sizeByteArray(BA) <=Int 32 [simplification, concrete(BA)]
407407

408-
rule #range(M, N1 +Int N2, K) => #range(#range(M, N2, #sizeByteArray(M) -Int N2), N1, K)
408+
rule #range(M, N1 +Int N2, K) => #range(#range(M, N2, #sizeByteArray(M) -Int N2), N1, K)
409409
requires 0 <=Int N1 andBool 0 <=Int N2
410410
[simplification, concrete(N2), concrete(M)]
411411

File renamed without changes.
File renamed without changes.

serialization.md renamed to include/kframework/serialization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Parsing/Unparsing
22
=================
33

44
```k
5-
requires "krypto.md"
5+
requires "plugin/krypto.md"
66
requires "evm-types.md"
77
requires "json-rpc.md"
88
```
File renamed without changes.
File renamed without changes.

package/nix/kevm.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
diff --git a/kevm b/kevm
22
index b77303c..9770f29 100755
3-
--- a/kevm
4-
+++ b/kevm
3+
--- a/bin/kevm
4+
+++ b/bin/kevm
55
@@ -96,9 +96,6 @@ run_kompile() {
66
if [[ "$(uname -s)" == 'Linux' ]]; then
77
kompile_opts+=( -ccopt -lprocps )

0 commit comments

Comments
 (0)