Algorithm Search⌘K

Definitioncore

Symbolic execution tree

Also called execution tree.

The tree of all paths of symbolic execution of a program, with a node per statement and a path condition per branch.

The symbolic execution tree of a program is the tree of all its feasible paths: the root is the start of the program, each node is a point reached by some input together with the path condition of the way there, and a node has two children where both sides of a branch are feasible. It is the object that symbolic execution explores, and that concolic testing and generational search explore one run at a time. It differs from the control flow graph in two ways: it unfolds every join and every loop, so it can be exponentially larger or infinite, and it drops the branches that no input takes.

Definition

Take a program PP in the toy IR with parameters x1,…,xkx_1, \dots, x_k and input symbols α1,…,αk\alpha_1, \dots, \alpha_k. A symbolic state is a triple (B,σ,π)(B, \sigma, \pi): a block label BB, a symbolic store σ\sigma from names to expressions over the symbols, and a path condition π\pi. The symbolic execution tree T(P)T(P) is the rooted tree defined as follows.

  1. The root is (B0,σ0,true)(B_0, \sigma_0, \mathit{true}), where B0B_0 is the entry block and σ0(xj)=αj\sigma_0(x_j) = \alpha_j.
  2. Let v=(B,σ,π)v = (B, \sigma, \pi) be a node. Run the instructions of BB on σ\sigma, as in the definition of the path condition, and add the implicit condition of each instruction that can trap. Call the result σ′\sigma' and π′\pi'.
    • Let πi\pi_i be the path condition just before an instruction that can trap, with the implicit condition cc. If πi∧¬c\pi_i \wedge \neg c is satisfiable, then vv has a trap leaf child with this condition.
    • If BB ends in ret a, vv has one return leaf child with the condition π′\pi'.
    • If BB ends in jump L, vv has one child (L,σ′,π′)(L, \sigma', \pi').
    • If BB ends in br a L1 L2, let b=σ′(a)b = \sigma'(a). The node has the child (L1,σ′,π′∧b≠0)(L_1, \sigma', \pi' \wedge b \ne 0) if this condition is satisfiable, and the child (L2,σ′,π′∧b=0)(L_2, \sigma', \pi' \wedge b = 0) if that one is satisfiable.
  3. Each edge is labeled with the condition that it adds.

A branch where both sides are feasible is a forking node, as King calls it. A branch where π′\pi' implies one side is non-forking: it has one child and it adds a condition that changes no set of inputs. King's tree has one node per statement. The tree above has one node per block visit. The two trees have the same leaves and the same forks, and one is the other with chains of straight-line steps contracted.

Basic facts. Write I(v)I(v) for the set of inputs that satisfy the path condition of vv.

  • Every node is reached by some input, because each node has a satisfiable path condition. Every input follows exactly one path from the root, and the children of a node split I(v)I(v) into disjoint parts. The page symbolic execution proves this partition property.
  • So, for a program whose runs all end, the leaves of T(P)T(P) are in one-to-one correspondence with the feasible complete paths, and the sets I(ℓ)I(\ell) of the leaves ℓ\ell partition the input space Zk\mathbb{Z}^k.
  • A node has at most b=c+2b = c + 2 children, where cc is the largest number of instructions that can trap in one block: one trap leaf per such instruction, and one or two other children.

Finiteness. The tree is finite if and only if there is a number LL such that every run of PP visits at most LL blocks.

Proof. Suppose there is such an LL. A block node vv at depth dd has a satisfiable path condition, so some input follows the path to vv, and its run visits at least d+1d + 1 blocks. So d<Ld < L. A leaf is a child of a block node, so its depth is at most LL. A tree of depth at most LL in which each node has at most bb children has at most 1+b+⋯+bL1 + b + \dots + b^L nodes, so it is finite. Conversely, suppose the tree is finite with height HH. By the partition property, the run of each input visits the blocks of one path from the root, and that path stays in the tree. So the run visits at most HH blocks; in particular it ends. □\square

The condition "every run ends" is weaker than "the tree is finite". By the infinity lemma (König's lemma), an infinite tree in which each node has finitely many children has an infinite path from the root. Each finite prefix of that path is feasible, but no single input may follow the whole path. The loop example below shows this.

Decidability. For the toy IR over unbounded integers, whether T(P)T(P) is finite is undecidable. Take a two-counter machine, which is a register machine with two counters, and translate it into a toy IR program that ignores its parameters. Each test of a counter is a branch on known values, so it is non-forking, and T(P)T(P) is a single chain that copies the run of the machine. The tree is finite exactly when the machine halts, and the halting problem for two-counter machines is undecidable. Even the one-child case needs a solver when the branches are on symbols: deciding whether a node has a given child is the feasibility of a path condition, which is decidable only in decidable theories (see path condition).

Examples and non-examples

A join with an infeasible combination. The parameter is xx, with the symbol α\alpha.

entry:
  t = x < 5
  br t a b
a:
  y = x + 1
  jump join
b:
  y = x - 1
  jump join
join:
  u = 10 < y
  br u c d
c:
  ret 1
d:
  ret 0

The CFG has 6 blocks, 6 edges and 4 complete paths. The tree has these nodes, written by block, with the store of yy and the path condition:

  • entry, π=true\pi = \mathit{true}. Forking: both α<5\alpha < 5 and α≥5\alpha \ge 5 are satisfiable.
    • a, π=α<5\pi = \alpha < 5. One child.
      • join, y=α+1y = \alpha + 1, π=α<5\pi = \alpha < 5. Non-forking: α<5∧10<α+1\alpha < 5 \wedge 10 < \alpha + 1 is unsatisfiable, so only the side to d exists.
        • d, π=α<5∧α+1≤10\pi = \alpha < 5 \wedge \alpha + 1 \le 10, which is α<5\alpha < 5. Return leaf.
    • b, π=α≥5\pi = \alpha \ge 5. One child.
      • join, y=α−1y = \alpha - 1, π=α≥5\pi = \alpha \ge 5. Forking.
        • c, π=α≥5∧10<α−1\pi = \alpha \ge 5 \wedge 10 < \alpha - 1, which is α≥12\alpha \ge 12. Return leaf.
        • d, π=α≥5∧α−1≤10\pi = \alpha \ge 5 \wedge \alpha - 1 \le 10, which is 5≤α≤115 \le \alpha \le 11. Return leaf.

The tree has 3 leaves, one for each feasible path. The block join appears twice, with two different stores: the tree copies the code after a join once per incoming path. The three leaf conditions α<5\alpha < 5, 5≤α≤115 \le \alpha \le 11 and α≥12\alpha \ge 12 split the integers into three parts. For xx in −30-30 to 3030, they hold for 35, 7 and 19 values.

Exponential size. Put kk tests one after another, each on its own parameter: t1 = x1 < 0; br t1 ... with both arms joining before the next test. The CFG has 3k+13k + 1 blocks. Every combination of sides is feasible, so the tree has 2k2^k leaves and 2k−12^k - 1 forking nodes. This is the path explosion problem in its simplest form.

An infinite tree in which every run ends. The parameter is nn, with the symbol ν\nu.

entry:
  i = 0
  jump head
head:
  t = i < n
  br t body exit
body:
  i = i + 1
  jump head
exit:
  ret i

The jj-th visit of head has σ(i)=j−1\sigma(i) = j - 1 and the path condition 0<ν∧⋯∧j−2<ν0 < \nu \wedge \dots \wedge j - 2 < \nu, so both sides are feasible and the node forks: the exit side gives a leaf with ν=j−1\nu = j - 1 (or ν≤0\nu \le 0 for j=1j = 1), and the body side goes on. The tree has infinitely many leaves and one infinite path, the path that always enters the body. Each prefix of the infinite path is followed by large values of ν\nu, but no integer ν\nu satisfies j<νj < \nu for all jj. So every run ends, and the tree is still infinite. This agrees with the finiteness criterion: the run on nn visits 2n+32n + 3 blocks for n≥0n \ge 0, and that number has no bound. Tools cut such a tree at a depth bound and give up any claim about the part below it.

Non-examples.

  • The control flow graph. The CFG has one node per block and shares the code after a join. It has paths that no input takes, such as entry, a, join, c above. The tree has neither property.
  • The tree of one run. A concolic tool records the path of one concrete run with its path condition. That is one root-to-leaf path of the tree, not the tree. The tree is the union of all such paths, which the tool never stores in full.
  • A merged state graph. A tool that merges the two join states into one state with the store y=ite(α<5,α+1,α−1)y = \mathrm{ite}(\alpha < 5, \alpha + 1, \alpha - 1) and the path condition true builds a directed acyclic graph, not a tree. It has fewer nodes and harder formulas. See path explosion for state merging.
  • Path condition. The label of a node is a path condition, and the leaves are the feasible complete paths.
  • Execution tree in testing tools. Concolic testing explores this tree by depth-first search, one run per leaf. Generational search explores it by expanding all branches of a run at once.
  • Unrolled formula. Bounded model checking encodes the tree up to a depth LL as one formula, with one copy of each variable per step, instead of one formula per leaf.
  • Computation tree. In model checking, the computation tree of a transition system unfolds the concrete states, one tree per start state. The symbolic execution tree is one tree for all inputs, with sets of inputs at the nodes.

References

  1. James C. King, Symbolic execution and program testing, Communications of the ACM 19(7), 1976, pp. 385 to 394, the section on the execution tree (forking and non-forking IF statements, the properties of the tree)
  2. Roberto Baldoni, Emilio Coppa, Daniele Cono D'Elia, Camil Demetrescu and Irene Finocchi, A survey of symbolic execution techniques, ACM Computing Surveys 51(3), 2018, Article 50, Section 1 (the symbolic execution tree of the running example) and Section 2 (the symbolic execution engine and its states)
  3. Cristian Cadar and Koushik Sen, Symbolic execution for software testing, three decades later, Communications of the ACM 56(2), 2013, pp. 82 to 90, the section on classical symbolic execution and its execution tree
  4. Donald E. Knuth, The Art of Computer Programming, Volume 1, third edition, Section 2.3.4.3 (the infinity lemma)

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/6MEYWW/text.yaml