Separation Logics for Pointer Programs
James Brotherston
Lorentz Center Workshop on Effective Verification of Pointer Programs
Monday 13th May, 2019
1/ 28
Separation Logics for Pointer Programs James Brotherston Lorentz - - PowerPoint PPT Presentation
Separation Logics for Pointer Programs James Brotherston Lorentz Center Workshop on Effective Verification of Pointer Programs Monday 13th May, 2019 1/ 28 Part I Introduction to separation logic 2/ 28 Introduction Verification of imperative
James Brotherston
Lorentz Center Workshop on Effective Verification of Pointer Programs
Monday 13th May, 2019
1/ 28
2/ 28
Verification of imperative programs is classically based on Hoare triples: {P} C {Q} where C is a program and P, Q are assertions in some logical language. These are read, roughly speaking, as for any state σ satisfying P, if C transforms state σ to σ′, then σ′ satisfies Q. (with some wriggle room allowing us to deal with faulting or non-termination in various ways.)
3/ 28
The so-called rule of constancy in Hoare logic, {P} C {Q} (FV (F) ∩ mod(C) = ∅) {F ∧ P} C {F ∧ Q} becomes unsound when we consider pointers. E.g., {x → 0} [x] := 2 {x → 2} {y → 0 ∧ x → 0} [x] := 2 {y → 0 ∧ x → 2} is not valid (because y could alias x).
4/ 28
Separation logic lets us abstractly describe heap memory, including data structures such as linked lists and trees. E.g., binary trees with root pointer x can be defined by: x = nil : emp ⇒ tree(x) x = nil : x → (y, z) ∗ tree(y) ∗ tree(z) ⇒ tree(x) where
5/ 28
h : Loc ⇀fin Val.
domains are disjoint, and undefined otherwise.
= A:
s, h | = emp ⇔ dom(h) = ∅ s, h | = x → t ⇔ dom(h) = {s(x)} and h(s(x)) = s(t) s, h | = A ∗ B ⇔ ∃h1, h2. h = h1 ◦ h2 and s, h1 | = A and s, h2 | = B
6/ 28
between program-and-state configurations: (C, s, h) (C′, s′, h′)
{P} C {Q} is valid if, whenever s, h | = P,
= Q.
“safe” by “safe and terminating” in condition 1!
7/ 28
The frame rule of separation logic is: {P} C {Q} (FV (F) ∩ mod(C) = ∅) {F ∗ P} C {F ∗ Q} In particular, e.g., {x → 0} [x] := 2 {x → 2} {y → 0 ∗ x → 0} [x] := 2 {y → 0 ∗ x → 2} is now fine; y cannot alias x because of separation.
8/ 28
{tree(x)} deltree(*x) { if x=nil then return; {emp} else { {x → (y, z) ∗ tree(y) ∗ tree(z)} l,r := x.left,x.right; {x → (l, r) ∗ tree(l) ∗ tree(r)} deltree(l); {x → (l, r) ∗ emp ∗ tree(r)} deltree(r); {x → (l, r) ∗ emp ∗ emp} free(x); {emp ∗ emp ∗ emp} } {emp} } {emp}
9/ 28
Soundness of the frame rule depends on the following two
Lemma (Safety monotonicity) If (C, s, h) ∗ fault and h ◦ h′ is defined then (C, s, h ◦ h′) ∗ fault. Lemma (Frame property) Suppose (C, s, h1 ◦ h2) ∗ s, h, and that (C, s, h1) ∗ fault. Then ∃h′ with (C, s, h1) ∗ s, h′ and h = h′ ◦ h2. Together, these lemmas imply the locality of all commands.
10/ 28
the following concurrent frame rule: {A1} C1 {B1} {A2} C2 {B2} {A1 ∗ A2} C1 || C2 {B1 ∗ B2} (provided FV (A1) ∩ mod(C2) = FV (A2) ∩ mod(C1) = ∅)
compositionally when run on separate resources.
resources between threads!
11/ 28
memory into two or more “read-only copies”.
the permissions at overlapping locations.
e.g. x 0.5 → d. Note that x 0.5 → d ∗ x 0.5 → d ≡ x → d .
12/ 28
We can then write program proofs with the following structure. {x → d} {x 0.5 → d ∗ x 0.5 → d} {x 0.5 → d} {x 0.5 → d} foo(); bar(); {x 0.5 → d ∗ A} {x 0.5 → d ∗ B} {x 0.5 → d ∗ x 0.5 → d ∗ A ∗ B} {x → d ∗ A ∗ B}
13/ 28
BI as an assertion language for mutable data structures. In Proc. POPL-28, 2001. (Winner of Most Influential POPL Paper 2001 award.) J.C. Reynolds. Separation logic: A logic for shared mutable data structures. In Proc. LICS-17, 2002.
A semantics for concurrent separation logic. In Theor. Comp. Sci. 375, 2007. (Joint winner of 2016 G¨
Permission accounting in separation logic. In Proc. POPL-32, 2005.
14/ 28
15/ 28
verification is heavily influenced by the precise choice of assertion language.
∗ (adjoint
structures.
constraints or to account for pointer arithmetic in programs.
16/ 28
function / constant symbols.
π ::= t = t | t = t | . . . | π ∧ π F ::= emp | x → t | Pt | F ∗ F Σ ::= ∃x. π : F | Σ ∨ Σ (where P a predicate symbol, t a tuple of terms).
user-defined (possibly with restrictions).
17/ 28
decide whether s, h | = A.
against assertions (model checking!).
18/ 28
complexity ranges from PTIME to EXPTIME depending on definition restrictions.
Model checking for symbolic-heap separation logic with inductive
19/ 28
there is a state (s, h) with s, h | = A.
disjunct can be eliminated (A ∨ false ≡ A);
proof search can be terminated as soon as one generates an unsatisfiable assertion.
20/ 28
complexity is EXPTIME-complete but can become easier (PTIME) depending on definition restrictions.
erez”, A decision procedure for satisfiability in separation logic with inductive predicates. In Proc. CSL-LICS, 2014.
becomes undecidable (one can encode Peano arithmetic). But in a restricted form of arithmetic, still decidable.
Q.L. Le, M. Tatsuta, J. Sun and W-N. Chin. A decidable fragment in separation logic with inductive predicates and arithmetic. In Proc. CAV, 2017.
21/ 28
whether A | = B, meaning s, h | = A ⇒ s, h | = B.
execution, e.g., {tree(x)} deltree(x) {emp} x → (nil, z) ∗ tree(z) | = tree(x) (| =) {x → (nil, z) ∗ tree(z)} deltree(x) {emp}
{B ∧ P} C {Q} Q | = P (| =) {B ∧ P} C {P} (while) {P} while B do C {¬B ∧ P}
22/ 28
problem is undecidable (one can encode CFG inclusion).
Ouaknine. Foundations for decision problems in separation logic with general inductive predicates. In Proc. FoSSaCS-17, 2014.
decidable (PTIME resp. ΠP
2 -hard):
Tractable reasoning in a fragment of separation logic. In Proc. CONCUR, 2011. James Brotherston, Nikos Gorogiannis and Max Kanovich. Biabduction (and related problems) in array separation logic. In
23/ 28
entailment is decidable have also been identified:
Radu Iosif and Adam Rogalewicz and Jiri Simacek. The tree width of separation logic with recursive definitions. In
Separation logic with monadic inductive definitions and implicit
A complete decision procedure for linearly compositional separation logic with data constraints. In Proc. IJCAR, 2016.
theorem proving.
24/ 28
Define list segment predicate ls by x = y : emp ⇒ ls x y x → x′ ∗ ls x′ y ⇒ ls x y Cyclic proof of ls x y ∗ ls y z ⊢ ls x z:
(Id) ls x z ⊢ ls x z (emp) emp ∗ ls x z ⊢ ls x z (†) ls x y ∗ ls y z ⊢ ls x z (Subst) ls x′ y ∗ ls y z ⊢ ls x′ z (∗/ →) x → x′ ∗ ls x′ y ∗ ls y z ⊢ x → x′ ∗ ls x′ z (ls) x → x′ ∗ ls x′ y ∗ ls y z ⊢ ls x z (Cases) (†) ls x y ∗ ls y z ⊢ ls x z
25/ 28
formulas X and Y with A ∗ X | = B ∗ Y , and A ∗ X is satisfiable.
can infer a spec for C1; C2:
{A′} C1 {A} (Frame) {A′ ∗ X} C1 {A ∗ X} (| =) {A′ ∗ X} C1 {B ∗ Y } {B} C2 {B′} (Frame) {B ∗ Y } C2 {B′ ∗ Y } (;) {A′ ∗ X} C1; C2 {B′ ∗ Y }
26/ 28
(NP-complete vs. PTIME):
The complexity of abduction for separated heap abstractions. In
entailment (NP-complete vs. ΠP
2 -hard):
James Brotherston, Nikos Gorogiannis and Max Kanovich. Biabduction (and related problems) in array separation logic. In
generally taken (based on matching “missing” parts of entailments). Note that solution quality is an important consideration.
27/ 28
28/ 28