3 COMP 1 5 9 3 Algorithmic Verification CEGAR and Predicate - - PowerPoint PPT Presentation

3 comp 1 5 9 3 algorithmic verification
SMART_READER_LITE
LIVE PREVIEW

3 COMP 1 5 9 3 Algorithmic Verification CEGAR and Predicate - - PowerPoint PPT Presentation

<latexit


slide-1
SLIDE 1

CEGAR Predicate Abstraction

COMP 3 9 1 5 3 Algorithmic Verification

<latexit sha1_base64="P4jUJHo6g1yopyZBD74hiv3LdI=">AIZHicjVRb9NIFD6kXEKW6l4QEhoCBalIa4JYJqVcTSF14QRaIFqanQ2D5xRpnYZjxpG6L8Cn7d/oH9EfvEmWPnRgy7juw5/ubMd75zif1Uq8w2m39fqKxcvHT5SvVq7Y9r12/cvLV6+yhLBibAwyDRifnsywy1ivHQKqvxc2pQ9n2Nn/zevtv/dIomU0n80Q5TPOnLKFYdFUhL0JfVyve2j5GKR1b1vqUqsAOD41o7TkI8zqy0WO8orfd8PcAH2826ULGySuoTsfHV2xSjtsVz63fyNeuM9t+/OxiPx38uMxgMmUD6ySkKo6KuFUln76tHVHqnhGqnOdUJRotU/mok7OfqXZLqHbLqSKDGJeJ0ruOqSw/r5xpiJqkMNWMhOW0Skha5STBUMZzeTmKVl0GAaZWxRGX6fzXdQqNPMubgmGEXIgydGeGuqoXqDeH7paiM4bWHNqa8Z5vFikJacWGV9/yGtNWkMq/dJQYZbt9FYgjNMJZO0Yhwvz9+XWerPR5EsG15hrENxHSrlTa0IYQEAhAHxBisGRrkJDR7xg8aEJK2AmMCDNkKd5HGEONzg7IC8lDEtqjZ0RvxwUa07vjzPh0QFE03YZOCnhc+IRkdxjNVxdfzPn+KsaIuZ3GIa1+wdkn1EKX0P86N/H8v+dcTpYUvuRcFOlMGXFZBgsZdWjV9G5Jv3sOyRPJCumUISsgTBOaIy6GoTWvq8u8y3W7Idk/S4Xd6oH3zj+xGeCaVp9ZjIUzeU9YE15rhLqdCal96yI7mrv8op4x50yhJ3Rvu0zBhzqOMyGsLXrH3K9gj1OmVFNdV8gnj+l28Xo8BYJ3cIFdMCKpFm7f5767majRvfyLaT+cVjPjPFz9keJ70IAW2f1p5IwrH5Bnh+5FBX3OVdHq5n6Zz2lxWZ7R0/VYsJ3MacgonoB97lfM/RAcyXkgc7jpzKvfWMoI4ZS7O2SdlnuC8Iw8M54ZzTmNWK/intf5H6JoR9NOxJ0dwgPKuUkdmuXsVM9nmnKlU45mp3WY/OeQJ6oLQtyd6SB7vtaLyvO6WZ7dfM4Rzum5B4/o7dFvlEw8c0SyJUlZyioM+yZFrfMTuSJTeM5mpgbuW+f9/GVbNo62G97zxvMP2+uv3xRfvSrcg4ewQfPyAl7DWziAQwgq/6Ilc2Vp1f+qV6rlXv5K6VC8WZNVi4qvd/AB3w9Tw=</latexit>

CEGAR and Predicate Abstraction

  • Dr. Liam O’Connor

CSE, UNSW (for now) Term 1 2020

1

slide-2
SLIDE 2

CEGAR Predicate Abstraction

Model Checking with Abstractions

Abstractions typically have a smaller state space, so it is advantageous to try to model check with abstractions rather than a concrete model. We need: To know that properties that hold for our abstractions hold for our model — true for all ϕ ∈ ACTL. To know that when our properties don’t hold for our abstractions, they don’t hold for our model — not true in general! We need to pick the abstraction based on the properties we care about, and if necessary change our abstraction on the fly based on the results we see.

2

slide-3
SLIDE 3

CEGAR Predicate Abstraction

Model Checking with Abstractions

red green yellow red ¬red Consider the following ACTL formulae: AG (red ⇒ AX ¬red) AG (red ⇒ AX AX red) AG (red ⇒ AX AX AX red) We know that if A ⊑ C then (A | = ϕ) ⇒ (C | = ϕ) for ϕ ∈ ACTL, but what about if A | = ϕ?

3

slide-4
SLIDE 4

CEGAR Predicate Abstraction

Counterexamples

Note If A | = ϕ for some ϕ ∈ ACTL, then there exists a run that serves as a counterexample to the formula ϕ. If A | = ϕ, that tells us either that C | = ϕ or that our abstraction is not precise enough — the counterexample will be spurious. Our approach: To check if our counterexample is spurious, convert it to a concrete run ∈ C.

4

slide-5
SLIDE 5

CEGAR Predicate Abstraction

Abstract to Concrete Run

Let α be our abstraction mapping QC → QA and our run be q0q1q2 . . . . We apply the mapping in reverse, α−1, and try to find a concrete run starting from our initial state IC according to transition relation δC: S0 = IC ∩ α−1(q0) S1 = δC(S0) ∩ α−1(q1) S2 = δC(S1) ∩ α−1(q2) etc.. If there is such a run (i.e. no Si = ∅), the run is not spurious. C1 C2 C3 A1 A2 Example AG (red ⇒ AX AX red) Counterexample: A1A2A2 α−1(A1A2A2) = {C1}{C2, C3}{C2, C3} There is a run C1

δC

− → C2

δC

− → C3 ∴ Not spurious.

5

slide-6
SLIDE 6

CEGAR Predicate Abstraction

Spurious Counterexamples

C1 C2 C3 A1 A2 AG (red ⇒ AX AX AX red) Counterexample: A1A2A2A2 S0 = IC ∩ α−1(A1) = {C1} ∩ {C1} = {C1} S1 = δC(S0) ∩ α−1(A2) = {C2} ∩ {C2, C3} = {C2} S2 = δC(S1) ∩ α−1(A2) = {C3} ∩ {C2, C3} = {C3} S3 = δC(S2) ∩ α−1(A2) = {C1} ∩ {C2, C3} = ∅ There is no concrete run — this counterexample is spurious. Our abstraction is too imprecise.

6

slide-7
SLIDE 7

CEGAR Predicate Abstraction

Abstraction Refinement

Definition An abstraction mapping α generates an equivalence relation on states ≡α where q ≡α q′ ⇔ α(q) = α(q′). Consider two abstractions α : QC → QA and α′ : QC → QB. We say that α′ refines α iff ≡α′ ⊆ ≡α. Similarly, we say α′ strictly refines α iff ≡α′ ≡α Informal Notion We previously considered abstractions as grouping together concrete states into equivalence classes. We can refine abstractions by splitting those equivalence classes.

7

slide-8
SLIDE 8

CEGAR Predicate Abstraction

Abstraction Refinement

We have a spurious counterexample q1q2q3 . . . . Which classes should we split up in our new abstraction? Counterexample Guidance For each qi in our counterexample, the class of concrete states it is abstracting is α−1(qi). We will split this class into two sets:

1

Those that follow directly from the previous state: α−1(qi) ∩ δC(Si−1)

2

Those that don’t: α−1(qi) \ δC(Si−1) The resulting classes will form the new, refined abstraction of our

  • model. If both of these sets are non-empty, we split the state qi

into two states, one for each set.

8

slide-9
SLIDE 9

CEGAR Predicate Abstraction

Example

C1 C2 C3 A1 A2 AG (red ⇒ AX AX AX red) Counterexample: A1A2A2A2 S0 = IC ∩ α−1(A1) = {C1} ∩ {C1} = {C1} S1 = δC(S0) ∩ α−1(A2) = {C2} ∩ {C2, C3} = {C2} S2 = δC(S1) ∩ α−1(A2) = {C3} ∩ {C2, C3} = {C3} S3 = δC(S2) ∩ α−1(A2) = {C1} ∩ {C2, C3} = ∅ α−1(A2) = {C2, C3}. We have to split this into those that follow from S0 ({C2}) and those that don’t ({C3}).

9

slide-10
SLIDE 10

CEGAR Predicate Abstraction

After Splitting

We split A2 into A′

2 and A′ 3

C1 C2 C3 A′

1

A′

2

A′

3

We now have an abstraction that does not exhibit our spurious counterexample, but the state space has increased.

In fact, it’s impossible to refine this further, why?

10

slide-11
SLIDE 11

CEGAR Predicate Abstraction

CEGAR

This technique gives us an approach called Counterexample Guided Abstraction Refinement (CEGAR). We have a starting abstraction α0 and an ACTL formula ϕ: k := 0 αk | = ϕ? αk | = ϕ αk | = ϕ Yes Is a spurious? No, get counterexample a No k := k + 1 αk := Split(αk−1) Yes

11

slide-12
SLIDE 12

CEGAR Predicate Abstraction

C Programs

Objective: Prove that our assertion is never violated.

1

int main() {

2

int i = 0, n = 0;

3

while (i < n) {

4

i++;

5

}

6

if (i < n)

7

assert(false);

8

} ℓ2 ℓ3 ℓ4 ℓ6 ℓ7 ℓ8 Need to check reachability, but can we simplify the state space first?

12

slide-13
SLIDE 13

CEGAR Predicate Abstraction

Predicate Abstraction

Predicate Abstraction A predicate abstraction of a program is a version of the program with the same control flow graph, where all variables are replaced with boolean overapproximations. Booleans can be true, false, or * (nondeterministically true or false).

13

slide-14
SLIDE 14

CEGAR Predicate Abstraction

Basic PA

To start with, let’s try using i < n as our only predicate:

1

int main() {

2

int i = 0, n = 0;

3

while (i < n) {

4

i++;

5

}

6

if (i < n)

7

assert(false);

8

}

1

int main() {

2

int b = false;

3

while (b) {

4

b = b?*:false;

5

}

6

if (b)

7

assert(false);

8

} we want our boolean program to be an abstraction. Requirement If a location is not reachable in the abstraction, it is not reachable in the concrete program.

14

slide-15
SLIDE 15

CEGAR Predicate Abstraction

Harder PA

Now let’s try using i < 2 and n >= 3 as our only predicates:

1

int main() {

2

int i = 0, n = 0;

3

while (i < n) {

4

i++;

5

}

6

if (i < n)

7

assert(false);

8

}

1

int main() {

2

int b1 = true, b2 = false;

3

while (??) {

4

b1 = b1?*:false;

5

}

6

if (??)

7

assert(false);

8

} What do we use for the ?? It must overapproximate i < n.

15

slide-16
SLIDE 16

CEGAR Predicate Abstraction

Abstract Condition

1 2 3 4 5 1 2 3 4 5 i n i < n n >= 3 i < 2 The only overapproximation is ¬(i < 2 ∧ n ≥ 3) i.e. !(b1 && b2)

16

slide-17
SLIDE 17

CEGAR Predicate Abstraction

Harder PA

1

int main() {

2

int i = 0, n = 0;

3

while (i < n) {

4

i++;

5

}

6

if (i < n)

7

assert(false);

8

}

1

int main() {

2

int b1 = true, b2 = false;

3

while (!(b1 && b2)){

4

b1 = b1?*:false;

5

}

6

if (!(b1 && b2))

7

assert(false);

8

}

17

slide-18
SLIDE 18

CEGAR Predicate Abstraction

No Predicates

The abstraction with no predicates has all states reachable:

1

int main() {

2

int i = 0, n = 0;

3

while (i < n) {

4

i++;

5

}

6

if (i < n)

7

assert(false);

8

}

1

int main() {

2

;;

3

while (*){

4

;;

5

}

6

if (*)

7

assert(false);

8

} How do we find out what predicates to add? Use CEGAR! Example (Abstract Counterexample) Lines 3 → 6 → 7.Looking at the concrete program, this path would require i >= n (to move from line 3 to 6) and i < n (to move from line 6 to 7). Both can’t be true simultaneously. This path is spurious.

18

slide-19
SLIDE 19

CEGAR Predicate Abstraction

Interpolants

Craig’s Interpolation Theorem If we have two predicates P(x) and Q(y) such are contradictory (i.e. ¬(P(x) ∧ Q(y))), then there exists a predicate I(x ∩ y) which: is implied by P(x), i.e. P(x) ⇒ I(x ∩ y), and contradicts Q(y) i.e. ¬(I(x ∩ y) ∧ Q(y)). Crucially, the interpolant I(x ∩ y) only ranges over variables common to both predicates. Example (i = 1) and i ≤ 0:i > 0 (i ≤ 2 ∧ k = i + 1) and k > 5: k ≤ 4 (i ≥ n) and i < n:i ≥ n

19

slide-20
SLIDE 20

CEGAR Predicate Abstraction

Path Interpolant

Sequence of program locations ℓ1ℓ2ℓ3 . . . ℓk Sequence of predicates π1π2π3 . . . πk π1 ∧ π2 ∧ π3 . . . πk Non-spurious case SAT Spurious case UNSAT There exists interpolants I1I2I3 . . . Ik−1

20

slide-21
SLIDE 21

CEGAR Predicate Abstraction

CEGAR for C Programs

Let P be our program, α be our predicate set, and Pα be the predicate abstraction of P using α. The location ℓ ∈ P is our bad state we want to avoid (assertion failure). α := ∅ Can reach ℓ in Pα? Program is safe Program is unsafe No Is a spurious? Yes, get witness path a No α := α ∪ Interpolants(a) Yes

21

slide-22
SLIDE 22

CEGAR Predicate Abstraction

Termination

On finite automata Finite number of states Each CEGAR loop increases the number of states in the abstraction, but the number can’t exceed the number of concrete states. On C programs (Effectively) infinite amount of states ∴ No guarantee of termination When it terminates it is both sound (in that it always finds errors if they exist) and complete (it will not provide spurious errors).

22

slide-23
SLIDE 23

CEGAR Predicate Abstraction

Bibliography

CEGAR is used in SLAM/SDV (Microsoft), BLAST (Berkeley) and CBMC (Oxford).

  • E. Clarke, O. Grumberg, S. Jha, Y. Lu, and H. Veith.

Counterexample-guided Abstraction Refinement. In Computer Aided Verification, pages 154-169, 2000 Thomas A. Henzinger, Ranjit Jhala, Rupak Majumdar and Gregoire Sutre, Software Verification with BLAST. In SPIN Workshop 2003, LNCS 2648, pages 235-239.

23