SLIDE 1 On the Nature of Symbolic Execution1
Frank de Boer (Joint work with Marcello Bonsangue) IFIP WG 2.2, 2019
1FM 2019
SLIDE 2
Motivation: No Formal Theory
SLIDE 3
Motivation: No Formal Theory
Master course at Leiden University
SLIDE 4
Motivation: No Formal Theory
Master course at Leiden University Tools
◮ No formal specification (of correctness/completeness)
SLIDE 5
Basic Symbolic Execution
SLIDE 6
Basic Symbolic Execution
Programming expressions
e := x | op(e1, . . . , en) where x is a simple variable of a basic type.
SLIDE 7 Basic Symbolic Execution
Programming expressions
e := x | op(e1, . . . , en) where x is a simple variable of a basic type.
Substitution σ : Var → Expr
xσ = σ(x)
= op(e1σ, . . . , enσ)
SLIDE 8 Basic Symbolic Execution
Programming expressions
e := x | op(e1, . . . , en) where x is a simple variable of a basic type.
Substitution σ : Var → Expr
xσ = σ(x)
= op(e1σ, . . . , enσ)
Symbolic configuration
S, σ, φ where
◮ S denotes the statement to be executed, ◮ σ denotes the current substitution, ◮ Boolean condition φ denotes the path condition.
SLIDE 9
Symbolic Transition System
SLIDE 10
Symbolic Transition System
Assignment
x = e; S, σ, φ → S, σ[x = eσ], φ where σ[x = e](y) = σ(y) if x and y are distinct variables, and σ[x = e](x) = e otherwise.
SLIDE 11
Symbolic Transition System
Assignment
x = e; S, σ, φ → S, σ[x = eσ], φ where σ[x = e](y) = σ(y) if x and y are distinct variables, and σ[x = e](x) = e otherwise.
Choice
◮ if B {S1}{S2}; S, σ, φ → S1; S, σ, φ ∧ Bσ ◮ if B {S1}{S2}; S, σ, φ → S2; S, σ, φ ∧ ¬Bσ
SLIDE 12
Symbolic Transition System
Assignment
x = e; S, σ, φ → S, σ[x = eσ], φ where σ[x = e](y) = σ(y) if x and y are distinct variables, and σ[x = e](x) = e otherwise.
Choice
◮ if B {S1}{S2}; S, σ, φ → S1; S, σ, φ ∧ Bσ ◮ if B {S1}{S2}; S, σ, φ → S2; S, σ, φ ∧ ¬Bσ
Iteration
◮ while B {S}; S′, σ, φ → S; while B {S}; S′, σ, φ ∧ Bσ ◮ while B {S}; S′, σ, φ → S′, σ, φ ∧ ¬Bσ
SLIDE 13
Correctness
SLIDE 14
Correctness
Concrete transitions
S, V → S′, V ′ where V : Var → Val
SLIDE 15
Correctness
Concrete transitions
S, V → S′, V ′ where V : Var → Val
Theorem
If S, id, true →∗ S′, σ, φ and V(φ) = true then S, V →∗ S′, V ◦ σ where V ◦ σ(x) = V(σ(x)).
SLIDE 16
Completeness
SLIDE 17
Completeness
Relating symbolic and concrete configurations
S, V ≃ S, σ, φ if V = V0 ◦ σ and V0(φ) = true, for some valuation V0.
SLIDE 18
Completeness
Relating symbolic and concrete configurations
S, V ≃ S, σ, φ if V = V0 ◦ σ and V0(φ) = true, for some valuation V0.
Theorem (simulation)
S, V ≃ S, σ, φ and S, V → S′, V ′ implies the existence of a corresponding symbolic transition S, σ, φ → S′, σ′, φ′ such that S′, V ′ ≃ S′, σ′, φ′.
SLIDE 19
OO
SLIDE 20
OO
Variables
◮ Global variables (main statement) ◮ Local variables (formal parameters of methods) ◮ Instance variables (class definitions)
SLIDE 21
OO
Variables
◮ Global variables (main statement) ◮ Local variables (formal parameters of methods) ◮ Instance variables (class definitions)
Programming expressions
e := x | op(e1, . . . , en) (In the main statement only global variables are used).
SLIDE 22
OO
Variables
◮ Global variables (main statement) ◮ Local variables (formal parameters of methods) ◮ Instance variables (class definitions)
Programming expressions
e := x | op(e1, . . . , en) (In the main statement only global variables are used).
Syntax of heap variables H and heap expressions E
H := x | H.y E := H | op(E1, . . . , En) , where x is a global variable.
SLIDE 23
Symbolic Heap Representation
SLIDE 24
Symbolic Heap Representation
Symbolic heap σ
σ denotes a substitution which assigns to each heap variable H a heap expression E.
SLIDE 25
Symbolic Heap Representation
Symbolic heap σ
σ denotes a substitution which assigns to each heap variable H a heap expression E.
Local environment τ
τ denotes a substitution which assigns to each formal parameter x a heap expression E.
SLIDE 26 Symbolic Heap Representation
Symbolic heap σ
σ denotes a substitution which assigns to each heap variable H a heap expression E.
Local environment τ
τ denotes a substitution which assigns to each formal parameter x a heap expression E.
Application substitution θ = τ ∪ σ
xθ = σ(x) global variable xθ = τ(x) local variable xθ = σ(τ(this).x) instance variable
= op(E1θ, . . . , Enθ)
SLIDE 27
Symbolic Heap Update
SLIDE 28
Symbolic Heap Update
Update global variable
◮ σ[x = E](x) = E ◮ σ[x = E](H) = σ(H), for any other heap variable H
SLIDE 29
Symbolic Heap Update
Update global variable
◮ σ[x = E](x) = E ◮ σ[x = E](H) = σ(H), for any other heap variable H
Update instance variable
◮ σ[H.x = E](H′.x) = if σ(H′) = σ(H) then E else σ(H′.x) fi ◮ σ[H.x = E](H′) = σ(H′), for any other heap variable H′
SLIDE 30
Symbolic Transition System
SLIDE 31
Symbolic Transition System
Assignment global variable
(⊥, x = e; S), σ, φ → (⊥, S), σ[x = eσ], φ
SLIDE 32
Symbolic Transition System
Assignment global variable
(⊥, x = e; S), σ, φ → (⊥, S), σ[x = eσ], φ
Assignment instance variable
(τ, x = e; S) · Σ, σ, φ → (τ, S) · Σ, σ[τ(this).x = eθ], φ where θ = τ ∪ σ.
SLIDE 33
Symbolic Transition System
Assignment global variable
(⊥, x = e; S), σ, φ → (⊥, S), σ[x = eσ], φ
Assignment instance variable
(τ, x = e; S) · Σ, σ, φ → (τ, S) · Σ, σ[τ(this).x = eθ], φ where θ = τ ∪ σ.
Object creation
(τ, x = new C; S) · Σ, σ, φ → (τ[x = y], S) · Σ, σ′, φ where σ′(y.z) = nil.
SLIDE 34
Symbolic Transition System (Cont’d)
SLIDE 35
Symbolic Transition System (Cont’d)
Method call
Given a method declaration m(¯ u){S}, we have (τ, y = e0.m(¯ e); S′) · Σ, σ, φ → (τ ′.S) · (τ, y =?; S′) · Σ, σ, φ′ where
◮ τ ′(¯
u) = ¯ e(τ ∪ σ)
◮ τ ′(this) = e0(τ ∪ σ)
SLIDE 36
Symbolic Transition System (Cont’d)
Method call
Given a method declaration m(¯ u){S}, we have (τ, y = e0.m(¯ e); S′) · Σ, σ, φ → (τ ′.S) · (τ, y =?; S′) · Σ, σ, φ′ where
◮ τ ′(¯
u) = ¯ e(τ ∪ σ)
◮ τ ′(this) = e0(τ ∪ σ)
Method return
(τ, return e) · (τ ′, x =?; S) · Σ, σ, φ → (τ ′[x = eθ], S) · Σ, σ, φ where θ = (τ ∪ σ).
SLIDE 37
Concrete Transition System
SLIDE 38
Concrete Transition System
Valuation
◮ V(H) = V(H′) implies V(H.x) = V(H′.x), ◮ V(x) = V(x′),
for any two distinct global variables x and x′ which do not appear in the main statement (unique name assumption).
SLIDE 39 Concrete Transition System
Valuation
◮ V(H) = V(H′) implies V(H.x) = V(H′.x), ◮ V(x) = V(x′),
for any two distinct global variables x and x′ which do not appear in the main statement (unique name assumption).
Heap update
◮ V[H.x = v](H′.x) =
v if V(H′) = V(H) V(H′.x)
◮ V[H.x = v](H′) = V(H′), for any other heap variable H′.
SLIDE 40 Concrete Transition System
Valuation
◮ V(H) = V(H′) implies V(H.x) = V(H′.x), ◮ V(x) = V(x′),
for any two distinct global variables x and x′ which do not appear in the main statement (unique name assumption).
Heap update
◮ V[H.x = v](H′.x) =
v if V(H′) = V(H) V(H′.x)
◮ V[H.x = v](H′) = V(H′), for any other heap variable H′.
Assignment instance variable
(L, x = e; S) · Σ, V → (L, S) · Σ, V[H.x = v] where V(H) = L(this) and v = (L ∪ V)(e).
SLIDE 41
Correctness
SLIDE 42
Correctness
Theorem
If (⊥, S), id, true →∗ (τ, S′) · Σ, σ, φ and V(φ) = true, where V is an initial valuation, then (⊥, S), V →∗ (V ◦ τ, S′) · V ◦ Σ, V ◦ σ where
◮ (V ◦ τ)(x) = V(τ(x)) ◮ (V ◦ σ)(H) = V(σ(H))
SLIDE 43
Conclusion
SLIDE 44
Conclusion
Extensions
◮ Arrays ◮ Multithreading (Java) ◮ Concurrent objects ◮ Concolic execution ◮ Backward symbolic execution
SLIDE 45
Conclusion
Extensions
◮ Arrays ◮ Multithreading (Java) ◮ Concurrent objects ◮ Concolic execution ◮ Backward symbolic execution
Implementation
◮ Finite representation ◮ Optimization aliasing
SLIDE 46
Conclusion
Extensions
◮ Arrays ◮ Multithreading (Java) ◮ Concurrent objects ◮ Concolic execution ◮ Backward symbolic execution
Implementation
◮ Finite representation ◮ Optimization aliasing
Related work
A generic framework for symbolic execution: A coinductive approach. By D. Lucanu, V. Rusu, and A. Arusoaie. In Journal of Symbolic Computation 80(1):125–163, Elsevier,