• Stars
    star
    210
  • Rank 187,585 (Top 4 %)
  • Language
    Haskell
  • License
    BSD 3-Clause "New...
  • Created almost 8 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The symbolic execution engine powering the K Framework

The Kore Language

Kore is the "core" part of the K framework.

What is Kore all about?

In short, we need a formal semantics of K. In K, users can define formal syntax and semantics of programming languages as K definitions, and automatically obtain parsers, interpreters, compilers, and various verification tools for their languages. Therefore K is a language-independent framework.

Thanks to years of research in matching logic and reachability logic, we know that all K does can be nicely formalized as logic reasoning in matching logic. To give K a formal semantics, we only need to formally specify the underlying matching logic theories with which K does reasoning. In practice, these underlying theories are complex and often infinite, and it is tricky to specify infinite theories without a carefully designed formal specification language. And Kore is such a language.

Structure of this project

The docs directory contains a collection of documents that describe the mathematical foundation of Kore and a BNF grammar that defines the syntax of Kore language. See /docs/introduction.md for an overview of the components of Kore.

The kore project is an implementation in Haskell of a Kore parser and symbolic execution engine, for use with the K Framework as a backend.

Building

Besides git, you will need stack or cabal to build kore.

stack build kore
# or
cabal build kore

You may pass --fast to stack build or -O0 to cabal build in order to disable compiler optimizations and make build faster at the cost of slower runtime.

Using make:

make all # builds all binaries

Developing

Developers will require all the dependencies listed above, in addition to the requirements and recommendations below.

Required dependencies

For integration testing, we require:

You can install/have access to K by either:

  • using kup
  • using a pre-built binary (see the releases page in the K repository)
  • if you use Nix, see the section below
  • using the Dockerfile to run the integration tests inside a container
  • or by just building K from source

Running integration tests with Docker

Use docker.sh to run commands inside the container:

./docker/build.sh  # run once when dependencies change
./docker/run.sh make all  # build the backend
./docker/run.sh make test  # run all tests
./docker/run.sh make -C test/imp test  # run all tests in test/imp

Recommended dependencies

For setting up a development environment, we recommend:

  • direnv to make the project's tools available in shells and editors.
  • ghcup or Nix for managing required Haskell tooling
  • hlint for compliance with project guidelines.

Running Haskell Language Server

ghcup provides a straightforward way of installing the language server, if you prefer to use Nix please refer to the relevant resources on how to set up your Nix environment to build the server. Note: HLS has to be built with the project's GHC version.

Prequisite: build the project with either Stack or Cabal.

Instructions on integrating with VSCode:

  1. Install the Haskell extension
  2. Go to Extension Settings and pick GHCup in the Manage HLS dropdown
  3. (Optional) Manually set the GHCup executable path
  4. (Extra) Set Formatting Provider to fourmolu for correct formatting

Developing with Nix

To build and run nix based packages at RV, please follow these instructions to set up nix:

We are using nix flakes in all our repos. What this means at a high level is that some of the commands for building packages look a bit different.

To set up nix flakes you will need to install nix 2.4 or higher.If you are on a standard Linux distribution, such as Ubuntu, first install nix and then enable flakes by editing either ~/.config/nix/nix.conf or /etc/nix/nix.conf and adding:

experimental-features = nix-command flakes

Note that if this is your first time using Nix you will have to manually create one of the .conf files.

This is needed to expose the Nix 2.0 CLI and flakes support that are hidden behind feature-flags. (If you are on a different system like nixOS, see instructions for enabling flakes here: https://nixos.wiki/wiki/Flakes)

By default, Nix will build any project and its transitive dependencies from source, which can take a very long time. We therefore need to set up some binary caches to speed up the build process. First, install cachix

nix profile install github:cachix/cachix/v1.1

and then add the k-framework cachix cache

cachix use k-framework

Next, we need to set up the cache for our haskell infrastructure, by adding the following sections to /etc/nix/nix.conf or, if you are a trusted user, ~/.config/nix/nix.conf (if you don't know what a "trusted user" is, you probably want to do the former):

trusted-public-keys = ... hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=
substituters = ... https://cache.iog.io

i.e. if the file was originally

substituters = https://cache.nixos.org
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=

it will now read

substituters = https://cache.nixos.org https://cache.iog.io
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=

Make sure that the file wasn't overwritten, if it was add the experimental-features again.

Formatting

The CI requires all Haskell files to be formatted via fourmolu.

If using VSCode, please refer to the language server section above. If not, the easiest way to do this locally is to run

nix run .#format

This will format all the haskell files in the given folder and all sub-folders. You can cd into a particular subfolder and run the command there, or if you only want to format a specific file, you can provide it as an argument to the above command:

nix run .#format Foo.hs

Nix dev shell

We provide a development nix shell with a suitable development environment and a binary cache at runtimeverification.cachix.org. The development can be launched via nix develop and then calling stack build/test/etc.

Upgrading dependencies

When one of the package description files (kore.cabal, kore-rpc-types.cabal) changes, or when upgrading to a newer stack resolver, the dependencies need to be consolidated to avoid accidental breakage from incompatible up-stream updates. We use a cabal.project.freeze file to pin the dependencies to what the current stack resolver is using.

The script scripts/freeze-cabal-to-stack-resolver.sh should do most of that work (the existing freeze file must be removed before running it), and scripts/check-cabal-stack-sync.sh checks the result. Some manual adjustments will still be necessary for the nix builds in CI and locally to work.

In addition, any GHC or resolver upgrades must double-check the compiler-nix-name and index-state values in the flake.nix file.

Integration tests

Haskell-backend provides an integration shell for running integration tests, which compile the K framework (of a specified version) against your current version of haskell backend and brings K into scope of your current shell.

The integration shell is part of the k repository, but invoked from the local tree, adding additional tools (see nix/integration-shell.nix and ../k/flake.nix). Its haskell-backend dependency must be overridden to use the haskell-backend dependency from the current checked-out tree, and the k version will usually be the one from deps/k_release.

To use this nix shell, execute

me@somewhere:haskell-backend$ nix develop \
    github:runtimeverification/k/v$(cat deps/k_release)#kore-integration-tests \
    --override-input haskell-backend . --update-input haskell-backend
...
...(nix output)
integration-shell:me@somewhere:haskell-backend$

(This will take some time the first time you run it for a specific K framework version...)
A specific commit or version tag of the K framework github repository can be used instead of $(cat deps/k_release).

Running this command will add all of the K binaries like kompile or kast into the PATH of your current shell. This is not permanent and will only persist in your current shell window until you exit the active nix shell).

integration-shell:me@somewhere:haskell-backend$ make -C test/issue-3344 test
...
...(make output)
integration-shell:me@somewhere:haskell-backend$ exit
me@somewhere:haskell-backend$ 

More Repositories

1

verified-smart-contracts

Smart contracts which are formally verified
Solidity
717
star
2

evm-semantics

K Semantics of the Ethereum Virtual Machine (EVM)
Python
507
star
3

k

K Framework Tools 7.0
Java
447
star
4

iele-semantics

Semantics of Virtual Machine for IELE prototype blockchain
HTML
130
star
5

publications

Publications of Runtime Verification, Inc.
HTML
87
star
6

wasm-semantics

A Prototype Formal Semantics of WebAssembly in K
WebAssembly
78
star
7

kontrol

Python
49
star
8

erc20-semantics

ERC20 in K
47
star
9

javamop

Runtime verification system for Java, using AspectJ for instrumentation.
Java
44
star
10

llvm-backend

KORE to llvm translation
C++
31
star
11

deposit-contract-verification

Makefile
30
star
12

plutus-core-semantics

Haskell
27
star
13

algorand-verification

Formal verification of the Algorand consensus protocol
Coq
26
star
14

beacon-chain-spec

Formalization of the Beacon Chain Phase 0 Specification in K
TeX
20
star
15

python-semantics

The semantics of Python in K
Python
19
star
16

beacon-chain-verification

TeX
18
star
17

michelson-semantics

A K semantics of Tezos' Michelson language.
Makefile
17
star
18

casper-proofs

Coq definitions and lemmas for verification of Casper
TeX
17
star
19

solidity

Fork of the Solidity Compiler for compiling Solidity to IELE
C++
16
star
20

rv-monitor

RV-Monitor core system code
Java
15
star
21

avm-semantics

Python
15
star
22

pyk

Python tools for the K Framework
Python
13
star
23

foundry-upgradeable-contracts-examples

Example tests for exploring upgradeable contracts with Foundry
Solidity
13
star
24

kontrol-demo

Foundry blog posts' executable demos
Solidity
12
star
25

zero-to-k-tutorial

Makefile
12
star
26

simbolik-vscode

TypeScript
12
star
27

k-editor-support

Plugin files for editing K files
Java
11
star
28

erc777-semantics

Makefile
11
star
29

mpfr-java

GNU MPFR Java Bindings
Java
10
star
30

kontrol-solady

Solady formal verification with Kontrol
Solidity
10
star
31

polkadot-verification

Verification of Polkadot WASM code
WebAssembly
9
star
32

secureum-kontrol

Solidity
9
star
33

kontrol-cheatcodes

Cheatcodes library for your symbolic Kontrol tests
Solidity
9
star
34

blockchain-k-plugin

K plugin for IELE and KEVM
C++
8
star
35

bn128-ml

BN 128 elliptic curve implementation in OCAML (for Ethereum zero-knowledge proofs)
OCaml
8
star
36

knock

Nock semantics in K
Python
7
star
37

mx-semantics

Python
7
star
38

rdao-smc

A probabilistic rewriting model of Randao-based RNG schemes
TeX
7
star
39

hs-backend-booster

Accelerates K Framework's Haskell backend
Haskell
7
star
40

proof-generation

Python
6
star
41

kup

K and Semantics Distribution Tool
Python
6
star
42

kavm-demo

Python
6
star
43

rv-android

Android runtime library for the RV-Monitor environment.
Java
5
star
44

match

RV-Match issue tracker and releases
4
star
45

gitbook-kontrol

4
star
46

imp-semantics

The K semantics of IMP and associated tools
Python
4
star
47

predict

3
star
48

vlsm

Coq
3
star
49

property-db

An annotated Java API and a tool for generated documentation augmented with properties.
Java
3
star
50

k-vs-coq-language-frameworks

Coq
3
star
51

pl-tutorial

The K Programming Language Tutorial
Standard ML
3
star
52

rv-predict

Code for improved rv-predict and installer
C
2
star
53

evaluation

Evaluation results of RV tools and comparisons with other tools
Python
2
star
54

rvmatch-eclipse-plugin

Java
2
star
55

kontrol-tutorial

Solidity
2
star
56

khoon

Python
2
star
57

optimism-ci

CI Hosting Symbolic Execution for Ethereum-Optimism
2
star
58

llvmmop

MOP framework for LLVM
Java
2
star
59

CANtools

RV tools for reverse engineering the automotive CAN bus.
1
star
60

rv-toolkit-docs

HTML
1
star
61

racy-c-programs

Benchmark of C/C++ programs exhibiting races.
C++
1
star
62

test-maven-deployment

Test - Delete me
1
star
63

rv-match_testing

Shell
1
star
64

z3k

C++ type inferencer for K using libz3
C++
1
star
65

k-pldi-tutorial

Code supporting K tutorial session at PLDI 2023.
Shell
1
star
66

elrond-multisig

Starlark
1
star
67

gitbook-kevm

1
star
68

proof-checker-public

C++
1
star
69

mir-semantics

Python
1
star
70

kore-prof

Profiling utilities extracted from haskell-backend
Haskell
1
star
71

RV-Log

Frontend for feeding log files and other precomputed event traces to RV-Monitor.
Java
1
star
72

mir-semantics-compiletest

Test suite for MIR semantics
Rust
1
star
73

gitbook-home

1
star
74

riscv-gnu-toolchain-images

Docker image builds for the RISC-V GNU toolchain
Dockerfile
1
star
75

nailgun

Nailgun is a client, protocol, and server for running Java programs from the command line without incurring the JVM startup overhead.
Java
1
star
76

ercx-vscode

VSCode support for ERCx
TypeScript
1
star
77

simbolik-examples

Solidity
1
star
78

rv-install

Unified installer for all Runtime Verification Inc. products
Java
1
star