symex-intro

Material for an introductory presentation for symbolic execution.

git clone https://git.8pit.net/symex-intro.git

 1# An Introduction to Symbolic Execution
 2
 3Material for an introduction to [symbolic execution], a [presentation at Hackover'26][HO26].
 4
 5<!-- TODO: Reference the media.ccc.de recording here. -->
 6
 7This repository includes the files required to experiment with the live demonstration from the presentation.
 8Specifically, it includes the setup required to verify the [Base64] implementation provided by the [RIOT operating system][RIOT].
 9The original, unmodified source code is [available on GitHub][RIOT base64].
10
11## Usage
12
13Ideally, use this repository with [Guix](https://guix.gnu.org):
14
15	$ guix time-machine -C channels.scm -- shell -m manifest.scm
16
17Within the Guix shell run the following commands:
18
19	$ make sim
20
21Alternatively, you can also try to use [KLEE's Docker image]:
22
23	$ docker run --rm  -v "$(pwd):/code" -it klee/klee
24
25Within the container run:
26
27	$ cd /code
28	$ make sim
29
30## Tweaking the Example
31
32The example uses a fixed-size input buffer, defaulting to 3 bytes.
33The size can be configured through the `INPUT_SIZE` variable, for example:
34
35	$ INPUT_SIZE=2 make -B
36
37For an input size of 3 bytes, 625 execution paths should be discovered.
38On my hardware, this takes around 2 minutes.
39Depending on the size, the number of execution paths, and the time required to discover them will vary.
40
41Further, it is possible to experiment with various KLEE optimizations to speed up this example.
42A technique particularly beneficial to this example is [state merging].
43To enable state merging, invoke `make` as follows:
44
45	$ CFLAGS=-DKLEE_STATE_MERGING make -B
46
47This will merge multiple execution paths of `getsymbol` / `getcode` into a single conjugated SMT-LIB expression.
48Thereby, increasing SMT-LIB query complexity but reducing the number of execution paths.
49
50To play around with other optimizations, refer to the [KLEE documentation].
51
52## More Information
53
54The following material provides more background information:
55
56* [Symbolic Execution for Software Testing: Three Decades Later](https://doi.org/10.1145/2408776.2408795)
57* [A Survey of Symbolic Execution Techniques](https://doi.org/10.1145/3182657)
58
59Further, the [KLEE documentation] includes additional practical examples:
60
611. [Testing a Regular Expression Library]
622. [Testing GNU coreutils]
63
64[symbolic execution]: https://notes.8pit.net/notes/xg1j.html
65[HO26]: https://talks.hackover.de/ho26/talk/CKUL8T/
66[Guix]: https://guix.gnu.org
67[KLEE's Docker image]: https://hub.docker.com/r/klee/klee
68[Base64]: https://doi.org/10.17487/RFC4648
69[RIOT]: https://riot-os.org
70[RIOT base64]: https://github.com/RIOT-OS/RIOT/blob/2026.04/sys/base64/base64.c
71[state merging]: https://arxiv.org/pdf/1610.00502#page=22
72[KLEE documentation]: https://klee-se.org/releases/docs/v3.2/docs/
73[Testing a Regular Expression Library]: https://klee-se.org/tutorials/testing-regex/
74[Testing GNU coreutils]: https://klee-se.org/releases/docs/v3.2/tutorials/testing-coreutils/