Maps to: Stanford CS 257 Introduction to Automated Reasoning (Winter 2026), Lecture 14 · Thu 02/19/2026 · Applications: symbolic execution (Rachel Cleaveland). Reading: none listed on the course page. Basis: The Stanford slides are on Canvas. The public Iowa deck Theory Solvers III opens with the symbolic-execution pipeline that motivates string solving (Lecture 13, §1). The rest is written from:
- King (1976), symbolic execution;
- Godefroid, Klarlund and Sen (2005), DART;
- Sen, Marinov and Agha (2005), CUTE;
- Cadar et al. (2006), EXE, and Cadar, Dunbar and Engler (2008), KLEE;
- Godefroid, Levin and Molnar (2008), SAGE;
- Kuznetsov et al. (2012), state merging; Avgerinos et al. (2014), veritesting;
- the surveys by Cadar and Sen (2013) and Baldoni et al. (2018).
This lecture has no code module. The examples are worked by hand and checked with earlier lectures’ code:
- every path condition shown was solved with Lecture 12’s
solve_lia, and every model was certified;- the example programs were run in Python on the generated inputs, to confirm that each input takes the predicted path;
- the overflow example was solved with Lecture 16’s
bitvec, and the aliasing example comes from Lecture 13’s script 01.The examples and their presentation were designed for these notes and do not reflect what was said in class. Reading time: 1.5 hours
0. How to read this lecture
0.1 Learning goals
After this lecture you should be able to:
- Execute a small program symbolically by hand: keep a symbolic store and a path condition, fork at branches, and draw the execution tree.
- Turn feasible path conditions into test inputs, and explain why every such input really follows its path.
- Say which solver queries symbolic execution makes, which theories it needs (integers or bit-vectors, arrays, strings), and how tools reduce the number and cost of queries.
- Explain path explosion, and compare search strategies, bounded loop unrolling and state merging. Relate full merging to bounded model checking.
- Run concolic testing (DART) by hand, including concretization and divergence, and say what it gains and loses compared with pure symbolic execution.
0.2 Prerequisites and scope
| Assumed | Introduced here | Developed later |
|---|---|---|
| CDCL(T) and linear integer arithmetic (Lectures 10, 12) | symbolic states, path conditions, execution trees | — |
| bounded model checking (Lecture 9) | state merging as BMC of programs | — |
| arrays, strings (Lecture 13); bit-vectors (Lecture 16) | the theories of program states | theory combination (Lecture 18) |
| — | concolic testing, search strategies | program synthesis (Lecture 20) |
0.3 Map
§1 why: which input reaches this line?
§2 symbolic states and path conditions (King)
§3 test generation
§4 the solver's role: queries, theories, optimizations
§5 loops and path explosion; search strategies
§6 state merging, and bounded model checking of programs
§7 concolic testing (DART, CUTE, SAGE)
§8 memory: symbolic pointers and arrays
§9 symbolic execution in practice
§10 summary §11 common pitfalls §12 exercises §13 further reading §14 next lecture
0.4 Notation
| Symbol | Meaning |
|---|---|
| symbolic inputs: fresh constants standing for “any value” | |
| the symbolic store: program variable → term over the inputs | |
| the path condition: a formula over the inputs | |
| a symbolic state at program location | |
| feasible | is satisfiable |
1. Why symbolic execution
Testing runs a program on chosen inputs and finds bugs only on those inputs. The question that matters is the reverse one:
Which input makes the program reach this line, or violate this assertion?
Random testing struggles with it whenever the line hides behind a narrow condition. Take if x == 4660 and y == x - 17: a random 32-bit input satisfies it with probability .
Symbolic execution (King 1976) answers the question with a solver. It runs the program on symbols instead of numbers, collects the conditions under which each path is taken, and asks the solver for inputs that satisfy them. It is the left half of the pipeline of Lecture 13, §1:
code (+ assertions) → symbolic execution → one formula per path → SMT solver → a test input, or "infeasible"
Its main uses are test generation (inputs that cover every feasible path) and bug finding (inputs that violate assertions or crash the program). Every bug report comes with a concrete input that reproduces it.
2. Symbolic states and path conditions
2.1 King’s idea
Give every input a fresh symbol: gets , gets . A symbolic state has three parts:
- the current location;
- a store mapping each variable to a term over the symbols, such as ;
- a path condition : the conjunction of the branch conditions taken so far, as formulas over the symbols.
Execution rules:
| statement | effect on |
|---|---|
v = e | , where substitutes the current terms into |
if c: A else: B | fork: continue with into A, and with into B; drop a branch whose condition is unsatisfiable |
while c: A | like if c: (A; while c: A), so every iteration forks |
assert c | if is satisfiable, report a bug with its model; continue with |
return e | the path ends; its model is a test, and is the predicted result |
2.2 A worked example
This is DART’s running example, in Python:
def h(x, y):
if x != y:
if 2 * x == x + 10:
... # the error branch
return 0
Start with and . The execution tree has three leaves:
π = ⊤
X ≠ Y / \ X = Y
/ \
2X = X + 10 / \ 2X ≠ X + 10 path 3: X = Y
/ \
path 1: X ≠ Y ∧ 2X = X + 10 path 2: X ≠ Y ∧ 2X ≠ X + 10
| path | path condition | model (Lecture 12’s solve_lia) | running h on it |
|---|---|---|---|
| 1 | reaches the error branch | ||
| 2 | returns 0 | ||
| 3 | returns 0 |
Path conditions are quantifier-free formulas. Here they are in linear integer arithmetic, exactly the input language of Lectures 10–12. Each model certificate was checked by evaluation, and running h on the three inputs follows the predicted paths.
2.3 What a path condition guarantees
Soundness. Every model of drives the real program down the path. Executing the program concretely on that input takes, at each branch, the direction recorded in , and computes the values predicted. So a reported bug is a real bug, with a reproducing input. Symbolic execution is an under-approximation: it reports only behaviours that really happen.
Completeness, in principle. If every path is explored, every reachable assertion violation is found. A program has finitely many paths only without unbounded loops. So in practice symbolic execution is a bounded search, and “no bug found” means “no bug on the paths explored”. Compare model checking (Lecture 9), whose proofs (k-induction, IC3) cover all executions.
Exactness depends on the theory. Python’s int is unbounded, so linear integer arithmetic is the exact theory for +, -, and multiplication by constants. In C or Java, int is a 32-bit word, and the exact theory is bit-vectors (§4.2).
3. Test generation
One test per feasible path. Collect a model of every path condition. The classic example is triangle classification:
def triangle(a, b, c):
if a <= 0 or b <= 0 or c <= 0:
return "invalid"
if a + b <= c or a + c <= b or b + c <= a:
return "not a triangle"
if a == b and b == c:
return "equilateral"
if a == b or b == c or a == c:
return "isosceles"
return "scalene"
Each if forks once, with its whole condition as the branch formula. That gives five paths:
| path | model (solve_lia) | triangle returns |
|---|---|---|
| some side ≤ 0 | (1, 1, 0) | invalid |
| sides positive ∧ some sum ≤ third side | (2, 1, 1) | not a triangle |
| … ∧ a = b ∧ b = c | (1, 1, 1) | equilateral |
| … ∧ ¬(all equal) ∧ two equal | (2, 1, 2) | isosceles |
| … ∧ no two equal | (4, 3, 2) | scalene |
Five inputs cover every statement and every branch direction.
Finer coverage. A tool may fork on each disjunct of a <= 0 or b <= 0 or c <= 0 separately. Python’s or is short-circuiting, so each disjunct really is a separate branch. That gives more paths and more tests, one per way of reaching each return. That is condition coverage rather than branch coverage.
The oracle problem. A test input is only half a test: someone must say whether the output is right. Symbolic execution finds inputs; the checks come from:
- assertions in the code;
- crashes (division by zero, out-of-bounds access, failed sanitizer checks);
- comparing two implementations, as in Lecture 16’s popcount and Lecture 2’s adder miters.
4. The solver’s role
4.1 Which queries
Symbolic execution is a client that makes very many small queries:
- feasibility at a fork: is satisfiable? Is ?
- at an assertion: is satisfiable? If so, a model.
- at the end of a path: a model of , the test.
Most queries are conjunctions of literals over the inputs, sharing long prefixes with the previous query. That is the incremental setting that CDCL(T) supports with push/pop and learned lemmas.
4.2 Which theories
The program’s data decides the theory:
| program data | theory | lecture |
|---|---|---|
| unbounded integers (Python) | linear integer arithmetic (nonlinear: undecidable) | 12 |
| machine integers (C, Java, binaries) | bit-vectors | 16 |
| memory, arrays, maps | arrays | 13 |
| strings | strings and regular expressions | 13 |
| floating point | floating-point arithmetic (SMT-LIB FP) | — |
The theory changes the answers. Consider
if (x > 0) { if (x + 1 < 0) { /* error branch */ } }
Over the path condition is unsatisfiable, so the error branch is unreachable. On 32-bit words it is reachable: Lecture 16’s bitvec solves with (and on 8 bits), and the model is certified by evaluation. A symbolic executor that models C integers as mathematical integers would miss the overflow and report a false “unreachable”. KLEE and SAGE therefore reason in QF_BV and QF_ABV (bit-vectors plus arrays).
4.3 Making queries cheap
The KLEE paper describes optimizations that most tools now use:
- Reuse the current model. A state keeps a model of its . At a fork on , evaluate in that model: whichever side it satisfies is feasible with the same model, so only the other side needs a query. That halves the queries at forks.
- Constraint independence. Split into groups that share no variables, and send only the group that mentions ‘s variables. The others are already known to be satisfiable.
- Counterexample caching. Cache models by constraint set:
- if a cached unsatisfiable set is a subset of the query, the query is unsatisfiable;
- if a cached model satisfies the query, it is satisfiable.
- Simplification. Rewrite constraints with the known equalities (for instance substitutes everywhere), and use the word-level rewriting of Lecture 16.
These make the solver fast enough to be called at every branch. Even so, solving typically dominates the running time of symbolic executors.
5. Loops and path explosion
5.1 Loops
A loop whose bound depends on an input has one path per number of iterations:
def count(n):
i = 0
while i < n:
i = i + 1
return i
| iterations | path condition | model | count returns |
|---|---|---|---|
| 0 | 0 | ||
| 1 | 1 | ||
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | 4 |
There are infinitely many paths. Tools bound the unrolling (at most iterations per loop per path), and the guarantee becomes “no bug on paths with at most iterations”. Loop summaries go beyond the bound. A summary is a formula for the effect of any number of iterations, such as , found by pattern matching or by invariant inference, which is Lecture 9’s territory.
5.2 Path explosion
Branches multiply. Consider a sequence of independent branches:
c = 0
if a0 > 0: c += 1
if a1 > 0: c += 1
...
if a(n-1) > 0: c += 1
It has paths, every one feasible. A loop over an array with a branch in its body behaves the same way. Path explosion is the problem of symbolic execution: even a modest function has more paths than any tool can explore.
5.3 Search strategies
Since not all paths can be explored, the order matters. A symbolic executor keeps a set of pending states and chooses which to advance:
| strategy | picks | strength | weakness |
|---|---|---|---|
| depth-first | the newest state | little memory; reaches deep code | dives into one loop forever |
| breadth-first | the oldest state | fair; short paths first | huge frontier; slow to go deep |
| random path (KLEE) | a random walk from the root of the execution tree | favours states with few forks above them | no notion of progress |
| coverage-guided (KLEE) | states near uncovered code | maximizes new coverage | heuristic distance estimates |
| generational (SAGE) | negate every branch of one execution, then pick the best child | many new tests per expensive run | designed for long concolic runs |
Tools usually interleave several strategies (KLEE round-robins between random path and coverage-guided). The analogy with SAT is close: the search order is a heuristic, and like VSIDS it decides what is found in practice.
6. State merging
6.1 The idea
Two states that reach the same location can be merged into one. The merged path condition is the disjunction, and each variable’s value becomes a conditional term. After if a0 > 0: c += 1 the two states and merge into
with a fresh . That is the ite encoding of the merge, .
Merging at every join of §5.2’s program gives one state and one query instead of paths. For with the assertion c != 3, the merged formula is
solve_lia finds () in one call.
6.2 The trade-off
Merging moves the case splits from the executor into the solver. The SAT solver now explores the combinations, but with conflict learning, propagation and non-chronological backtracking (Lecture 5) instead of explicit enumeration. That is usually a large win, but not always:
- merged formulas are bigger and harder;
- the model-reuse and caching tricks of §4.3 work per path, and become less effective;
- values that were concrete on each path, such as , become symbolic ().
Kuznetsov et al. (2012) merge only when an estimate of future queries says it pays. Veritesting (Avgerinos et al. 2014) merges over short, loop-free regions and executes path by path elsewhere.
6.3 Full merging is bounded model checking
Merge at every join point, unroll every loop times, and the whole program becomes one formula:
- one fresh variable per assignment (static single assignment);
- a conditional at each join;
- the assertion negated.
This is bounded model checking of programs (CBMC, ESBMC), Lecture 9’s BMC with the program’s control flow as the transition relation. Symbolic execution and BMC are the two ends of one spectrum: one path at a time, or all paths at once.
7. Concolic testing
7.1 Concrete and symbolic together
Pure symbolic execution gets stuck when the program does something the solver cannot model:
- nonlinear arithmetic;
- a hash function;
- a library or system call whose code is not available.
Concolic testing (concrete + symbolic; DART 2005, CUTE 2005) runs the program on a concrete input and keeps the symbolic state alongside:
input := an initial input (e.g. all zeros)
repeat:
run the program concretely on input, recording at each branch the symbolic condition and the direction taken
pick a branch of this path that has not been flipped yet, and solve
(conditions before it) ∧ ¬(its condition)
the model is the next input (variables the query does not mention keep their old values)
Each run follows one concrete path, so every operation has a concrete value. When an operation is beyond the solver, concolic testing concretizes: it replaces the symbolic term by its concrete value and continues.
7.2 A worked example: concretization and divergence
def hashed(y):
return (y * y) % 50 + 7
def g(x, y):
if x == hashed(y):
if y > 100:
... # the error branch
return 1
return 0
y * y is nonlinear, so the executor concretizes hashed(y) to its value on the current input. Four runs:
| run | input | hashed(y) | path observed | next query (solved by solve_lia) | its model |
|---|---|---|---|---|---|
| 1 | (0, 0) | 7 | (y stays 0) | ||
| 2 | (7, 0) | 7 | |||
| 3 | (7, 101) | 8 | : divergence | (y stays 101) | |
| 4 | (8, 101) | 8 | — | reaches the error branch |
Running g on the four inputs gives 0, 1, 0, and the error branch.
Divergence. Run 3 was meant to take the inner branch, but the concretized value 7 was only valid for . With , hashed(y) is 8 and the run goes elsewhere. Concolic testing recovers here by negating again with the new concrete value. In general, concretization makes the method incomplete: some reachable paths may never be generated. It also makes it robust: it never stops at an unsupported operation, and every input it generates is a real execution.
What pure symbolic execution does here. It must either give up on the path (the product is not linear), or treat hashed as an uninterpreted function, which is sound for path feasibility but cannot produce a concrete without knowing . Concolic execution gets that value by running the code.
7.3 Generational search and whitebox fuzzing
SAGE (Godefroid, Levin and Molnar 2008) applies concolic testing to large x86 programs that parse files. One run is expensive (millions of instructions, long path conditions), so SAGE negates every branch of the run, not just the last. This generational search yields a whole generation of new inputs per run, ranked by how much new code they cover. Microsoft called it whitebox fuzzing and used it on file parsers. Modern hybrid fuzzers combine a fast random fuzzer with a concolic engine that is called only when the fuzzer gets stuck at a narrow condition such as the x == 4660 of §1.
8. Memory: symbolic pointers and arrays
Programs read and write memory through addresses, and an address can itself depend on the input. Lecture 13 gave the tools:
- memory is an array from addresses to values;
*p = vis a write;*qis a read.
Lecture 13’s script 01 asks whether *p = c1; *q = c2; assert(*p == c1) can fail. The answer is SAT, with the model p = q: the assertion fails exactly when the pointers alias. With assumed, it is UNSAT. Both answers are certified.
How tools handle symbolic addresses.
- Fork on the target. EXE and KLEE resolve a symbolic pointer to the memory objects it may point to and fork one state per object, which is precise but multiplies paths. Each object is then its own array, so the arrays stay small.
- One big array. Give all of memory to the solver as a single array with symbolic indices. There are fewer forks, but harder array queries, the eager-vs-lazy trade-off of Lecture 13, §4.5.
- Concretize the address (concolic): fast, but it misses the aliasing bugs above.
Out-of-bounds accesses become queries too: is satisfiable? A model is a reproducing input for the memory error.
9. Symbolic execution in practice
Tools.
- KLEE (on LLVM bitcode; it generated high-coverage tests for the GNU Coreutils and found bugs in them);
- SAGE (x86 binaries, at Microsoft);
- angr (binary analysis);
- Symbolic PathFinder (Java);
- Pex / IntelliTest (.NET).
Concolic engines also sit inside hybrid fuzzers.
What limits them, roughly in order:
- Path explosion (§5), managed by strategies, merging and summaries, never solved.
- The environment. Files, network, system calls and libraries must be modelled, or executed concretely (concolic). KLEE ships simplified models of the POSIX environment.
- The solver. Nonlinear arithmetic, floating point, hash functions and long string constraints are slow or undecidable, and the solver is called at every fork.
- Precision vs scale. Exact bit-level memory models are expensive; tools concretize, simplify and cache, each time trading completeness for speed.
Where it shines. Inputs guarded by narrow conditions: magic numbers, checksums of a few bytes, parsers with many exact cases, and equivalence checks between two implementations. Random testing and fuzzing almost never hit these; one solver query does.
The pattern of the whole course. Here too an answer comes with a certificate. A bug report is an input that reproduces the bug when the program runs, the most convincing certificate there is. What symbolic execution cannot give is the other answer: a proof that no bug exists needs the induction-style reasoning of model checking (Lecture 9) or of program verification (Lecture 15’s kernel and Lean).
10. Summary
- Symbolic execution runs a program on symbols. A state is a store of terms plus a path condition; branches fork, and an infeasible branch (unsatisfiable condition) is dropped.
- Every model of a path condition drives the real program down that path: tests and bug reports with reproducing inputs. It is an under-approximation, complete only for the paths it explores.
- The solver answers feasibility and model queries at every fork. The theory must match the program’s data: bit-vectors for machine integers (otherwise overflow paths are missed), arrays for memory, strings for text.
- Tools make queries cheap by reusing the current model, splitting independent constraints, caching and simplifying.
- Path explosion ( paths for branches; one path per loop iteration count) forces bounds, search strategies and summaries.
- State merging moves case splits into the solver. Full merging is bounded model checking of programs.
- Concolic testing runs concretely and solves for the next input, concretizing what the solver cannot handle. It is robust and practical, but incomplete (divergence).
11. Common pitfalls
- Mathematical integers for machine code. is false on 32 bits; use bit-vectors for C, Java and binaries.
- “No bug found” as a proof. It only covers the paths explored, under the loop bound.
- Forgetting short-circuit semantics.
a or bis two branches in Python, C and Java; a single fork on misses condition coverage. - Ignoring the environment. Unmodelled library calls make paths infeasible in the model that are feasible in reality, or the reverse.
- Concretizing too early. Every concretized value is a constraint the solver never sees; paths that depend on it are lost.
- Merging everything. Merged formulas can be far harder than the paths they replace.
12. Exercises
1. (by hand) Execute symbolically:
def f(x, y):
z = x + y
if z > 10:
if x < 3:
return 1
return 2
return 3
Write each path condition and a model.
Answer
The store. .
The paths. Models are from solve_lia; running f on them returns 1, 2, 3.
- returns 1, e.g. .
- returns 2, e.g. .
- returns 3, e.g. .
All three are feasible, so there are three tests.
2. (infeasible paths) In if x > 5: if x < 3: ..., how many paths does the execution tree have, and which query proves one infeasible?
Answer
The forks. The outer fork gives and . The inner if sits only on the true side, where it forks into and .
The infeasible path. The query is unsatisfiable, so that branch is dropped and the inner body is dead code.
The count. Two feasible paths remain: (e.g. ) and (e.g. ).
3. (model reuse) A state with has the model . At a fork on , which side needs a solver query?
Answer
Evaluating the model. In the model, , so the false side is feasible with the same model.
The query. Only needs one. Encoded with , , , it has the model .
4. (bit-vectors) Is the error branch of if x < 200: if x + 100 < 50: ... reachable when x is an 8-bit unsigned word? And when x is an integer with ?
Answer
On 8-bit words: reachable. wraps around for , and then equals , which is below 50 exactly when .
- So reaches the branch.
- Lecture 16’s
bitvecfinds (). - With the extra constraint it reports UNSAT, certified by DRUP.
Over the integers: unreachable. is unsatisfiable (solve_lia), since forces . An executor that models the machine word as a mathematical integer would declare the branch dead.
5. (path explosion) A loop for i in range(8): if a[i] > 0: s += 1 over 8 symbolic integers, followed by assert s != 8. How many paths does pure symbolic execution explore? How many queries does full merging need?
Answer
Path by path. paths, all feasible. The tree has 255 forks, so up to 510 feasibility queries, about half of them with the model-reuse trick of §4.3.
Full merging. One formula with 8 conditional increments and , which is one query, satisfied by all .
6. (concolic) Redo the run table of §7.2 starting from the input .
Answer
Run 1. : hashed(5) . The path is ; solve .
Run 2. : hashed . The path is ; solve , e.g. .
Run 3. : hashed(101) . The run diverges; solve .
Run 4. reaches the error branch.
7. (aliasing) Write the array formula for a[i] = 1; a[j] = 2; assert a[i] == 1 and say which model violates it.
Answer
The formula. .
The violating model. It is satisfiable exactly when : then . It is Lecture 13’s aliasing example with indices instead of pointers.
8. (merging vs BMC) Explain why merging at every join point of a loop-free program produces the same formula as BMC with one time step per statement, up to renaming.
Answer
Merging. It introduces one variable per assignment along all paths, chosen by conditionals at the joins: static single assignment with φ-functions.
BMC. It introduces one copy of each variable per step, constrained by the transition relation, which is the statement’s effect under the control location.
Why they coincide. For loop-free code, both encode “some execution reaches the assertion with its negation true” as one quantifier-free formula over the inputs. The variable copies correspond one to one, and the conditionals correspond to the control-flow choices.
13. Further reading
- J. C. King, “Symbolic Execution and Program Testing”, CACM 1976.
- P. Godefroid, N. Klarlund, K. Sen, “DART: Directed Automated Random Testing”, PLDI 2005.
- K. Sen, D. Marinov, G. Agha, “CUTE: A Concolic Unit Testing Engine for C”, ESEC/FSE 2005.
- C. Cadar, V. Ganesh, P. Pawlowski, D. Dill, D. Engler, “EXE: Automatically Generating Inputs of Death”, CCS 2006.
- C. Cadar, D. Dunbar, D. Engler, “KLEE: Unassisted and Automatic Generation of High-Coverage Tests for Complex Systems Programs”, OSDI 2008.
- P. Godefroid, M. Y. Levin, D. Molnar, “Automated Whitebox Fuzz Testing”, NDSS 2008 (SAGE).
- V. Kuznetsov, J. Kinder, S. Bucur, G. Candea, “Efficient State Merging in Symbolic Execution”, PLDI 2012.
- T. Avgerinos, A. Rebert, S. K. Cha, D. Brumley, “Enhancing Symbolic Execution with Veritesting”, ICSE 2014.
- C. Cadar, K. Sen, “Symbolic Execution for Software Testing: Three Decades Later”, CACM 2013.
- R. Baldoni, E. Coppa, D. C. D’Elia, C. Demetrescu, I. Finocchi, “A Survey of Symbolic Execution Techniques”, ACM Computing Surveys 2018.
- E. Clarke, D. Kroening, F. Lerda, “A Tool for Checking ANSI-C Programs”, TACAS 2004 (CBMC).
14. Next lecture
Lecture 15: from decision procedures to proof automation in Lean (guest lecture by Leo de Moura).
- The other half of the picture. Symbolic execution finds bugs with reproducing inputs. Proof assistants prove their absence, with a small trusted kernel checking every step.
- How the course’s decision procedures fit in. SAT, congruence closure, the simplex and branch and bound become tactics that explain themselves to that kernel.