63
Numerical and Structural Abstractions Jan Midtgaard Week 5, Abstract Interpretation Aarhus University, Q4 - 2012

on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Numerical and Structural Abstractions

Jan Midtgaard

Week 5, Abstract Interpretation

Aarhus University, Q4 - 2012

Page 2: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Last time

2 / 57

More approximation methods for abstract interpretation:

! Partitioning

! Relational and attribute independent analysis

! Inducing, abstracting, approximating fixed points

! Widening, narrowing

! Forwards/backwards analysis

+ analysis of Plotkin’s three counter machine

Page 3: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Today

3 / 57

A catalogue of abstractions

! Toolbox abstractions

! Structural abstractions: sums, pairs/tuples, . . .

! Numerical abstractions: constants, intervals,polyhedra

! Concretization-based abstract interpretation, briefly

A retrospective on the 3 counter machine analysis, incl.constraint extraction

Page 4: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Toolbox abstractions

Page 5: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Warm up: Collapsing abstractions

5 / 57

The collapsing abstraction into a two element lattice:

!(!) = "

!(S) = # if S $= !

"(") = !

"(#) = S

%#(S);&' (()()*(((!

"%{#,"};+'

is slightly better than the completely collapsingabstraction:

!(S) = "

"(") = S%#(S);&' (()()*(((

!

"%{"};+'

Page 6: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Subset abstraction

6 / 57

Given a set C and a strict subset A , C hereof, therestriction to the subset induces a Galois connection:

%#(C);&' ((()()*((((!!

"!%#(A);&'

!,(X) = X - A

",(Y ) = Y . (C \ A)

For example, in a control-flow analysis of untypedfunctional programs one can choose to focus onfunctional values (closures) and not model numbers:

%#(Clo + Num);&' ((()()*((((!!

"!%#(Clo);&'

(Note: by a sum A+B we mean the disjoint union)

Page 7: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Elementwise abstraction

7 / 57

Let an elementwise operator @ : C ) A be given.Define

!(P ) = {@(p) | p / P}

"(Q) = {p | @(p) / Q}

Then%#(C);&' (()*((!

"%#(A);&'

In particular, if @ is onto, we have

%#(C);&' (()()*(((!

"%#(A);&'

For example, Parity is isomorphic to an elementwiseabstraction.Q: what would A and @ be in this case?

Page 8: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Structural abstractions

Page 9: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Structural?

9 / 57

How is State# constructed? It is possible toinvent State#, and then the pair of adjoinedfunctions. Another approach consists ininducing State# from the structure of State.

—Alain Deutsch, POPL’90

Page 10: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Abstracting sums as a product

10 / 57

We can abstract sums by first utilizing a simpleisomorphism:

%#(A+B);&' (()()**(((!

"%#(A)0 #(B);&0'

where

!(S) = ({a | a / S - A}, {b | b / S - B})

This isomorphism will typically enable furtherapproximation.

For example, the values of a mini-Scheme languagecould be such a disjoint sum: closure or number

Page 11: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Componentwise abstraction

11 / 57

We can abstract a Cartesian product (e.g., the outcomeof the previous isomorphism) componentwise:

%#(Ci);&' ((()*(((!i

"i%Ai;+i' i / {1, . . . , n}

%#(C1)0 . . .0 #(Cn);&0' (()*((!"%A1 0 . . .0 An;+0'

with!(%X1, . . ., Xn') = %!1(X1), . . ., !n(Xn)'

"(%x1, . . ., xn') = %"1(x1), . . ., "n(xn)'

and writing +0 for componentwise inclusion.

For example, last week we used the “triple version” forabstracting the 3 Counter Machine memory.

Page 12: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Abstracting pairs, coarsely

12 / 57

We can approximate a set-of-pairs by an abstract pair:

%#(C1);&' ((()*(((!1

"1%A1;11' %#(C2);&' ((()*(((!2

"2%A2;12'

%#(C1 0 C2);&' (()*((!"%A1 0 A2;10'

where

!(S) = %!1({a | (a, b) / S}), !2({b | (a, b) / S})'

For example, we used this approach to abstract thethree memory registers of the 3CM.

Page 13: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Abstracting pairs, better

13 / 57

Utilizing the well-known isomorphism

%#(C1 0 C2);&' (()()**(((!

"%C1 ) #(C2); &̇'

we can approximate the set-of-pairs as a functionbetween abstract domains:

%#(C1);&' ((()*(((!1

"1%A1;11' %#(C2);&' ((()*(((!2

"2%A2;12'

%#(C1 0 C2);&' (()*((!"%A1 ) A2; 1̇2'

where

!(S) =˙!{[!1({a}) 2) !2({b})] | %a, b' / S}

Page 14: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Abstracting pairs, relationally

14 / 57

Finally we can go all-in and approximate the set-of-pairsas an abstract set-of-pairs:

%#(C1);&' ((()*(((!1

"1%A1;11' %#(C2);&' ((()*(((!2

"2%A2;12'

%#(C1 0 C2);&' (()*((!"%#(A1 0 A2)/3;&'

where !(S) = {%!1({a}), !2({b})' | %a, b' / S}

Note: this requires a domain reduction, equating allelements with the same meaning, e.g., in #(Par 0 Par),{%#, even'} 3 {%odd , even', %even, even'}.

Perhaps a fun project abstracting the 3CM in thismanner?

Page 15: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Comparing the three pair abstractions

15 / 57

Suppose we abstract the signs of the following set

S = {%(1, (1', %0, 0', %1, 1', %(1, 1'}

coarsely: better: relationally:

1(1(2

1

(1

(2

••

1(1(2

1

(1

(2

••

1(1(2

1

(1

(2

••

!(S) = %#, #'

!(S) = [neg 2) #,

0 2) 0,

pos 2) pos ]

!(S) =

{%neg , neg', %0, 0',

%pos , pos', %neg , pos'}

Page 16: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Abstracting monotone functions

16 / 57

Similar to the ’better abstraction’ of pairs, we canapproximate monotone functions by monotone abstractfunctions:

%C1;&1' ((()*(((!1

"1%A1;11' %C2;&2' ((()*(((!2

"2%A2;12'

%C1m() C2; &̇2' (()*((!

"%A1

m() A2; 1̇2'

where Xm() Y are the monotone functions from X to Y

and!(f) = !2 4 f 4 "1"(g) = "2 4 g 4 !1

Page 17: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Abstracting sequences

17 / 57

We can abstract a set of sequences (rather crudely) bycollapsing their elements:

%#(C);&' (()*((!"%A;1'

%#(C5);&' ((()*(((!"

""

%A;1'

where

!5(S) = !({x | x / s 6 s / S})

Page 18: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Numerical abstractions

Page 19: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Numerical abstractions

19 / 57

We’ve already come across a few numerical abstractdomains: parity, signs, intervals, . . .

All of these were attribute independent (ornon-relational): they don’t express relations between(the values of) variables.

Let’s recap what we have seen and supplement withsome new ones, both non-relational and relational.

Page 20: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

What is a numerical abstract domain?

20 / 57

A computer-representable property, with! top and bottom: #, "

! join, meet, and comparison operators: 7, 8, and +

! widening and narrowing operators (optional, fordomains with infinite strictly incr./decr. chains)

! some primitive operations: +,-,*,/

! other basic operations: test, assignment

! with matching backwards operations (optional, for(forwards/) backwards analysis)

! a "-function mapping elements to their meaning(mathematical, not necessarily computable)

Page 21: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

The parity domain

21 / 57

Par = {#, odd , even,"}

%#(N0);&' (()()*(((!

"%Par ;+'

#

"

odd even

where

"(") = !

"(odd) = {n / N0 | n mod 2 = 1}

"(even) = {n / N0 | n mod 2 = 0}

"(#) = N0

Page 22: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

A simple sign domain

22 / 57

Sign = {#, ˙pos , ˙neg , 0,"}

%#(Z);&' (()()*(((!

"%Sign;+'

#

0

˙neg ˙pos

"where

"(") = !

"(0) = {0}

"( ˙pos) = {n / Z | n 9 0}

"( ˙neg) = {n / Z | n 1 0}

"(#) = Z

Page 23: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Another simple sign domain

23 / 57

Sign = {#, pos , neg , 0,"}

%#(Z);&' (()()*(((!

"%Sign;+'

#

0neg pos

"where

"(") = !

"(0) = {0}

"(pos) = {n / Z | n > 0}

"(neg) = {n / Z | n < 0}

"(#) = Z

Page 24: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

The improved sign domain

24 / 57

Sign = {#, $= 0, ˙pos , ˙neg , pos , neg , 0,"}

%#(Z);&' (()()*(((!

"%Sign;+'

#

$= 0

0

˙neg ˙pos

neg pos

"where

"(") = !

"(0) = {0}

"(pos) = {n / Z | n > 0}

"(neg) = {n / Z | n < 0}

"( ˙pos) = {n / Z | n 9 0}

"( ˙neg) = {n / Z | n 1 0}

"( $= 0) = {n / Z | n $= 0}

"(#) = Z

Page 25: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

The constant propagation domain (Kildall:73)

25 / 57

Const = Z . {#,"}

%#(Z);&' (()()*(((!

"%Const ;+'

#

. . . (2(1 0 1 2 . . .

"where

"(#) = Z

"(n) = {n}

"(") = !

!({n1, n2, . . . }) = #

!({n}) = n

!(!) = "

Page 26: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Simple congruences (Granger’89)

26 / 57

Cong = {"} . {a+ bZ | a, b / Z :

(b = 0) : (0 1 a < b)}

%#(Z);&' (()()*(((!

"

%Cong ;+'

"(") = !

"(a+ bZ) = {a+ bz | z / Z}

0+1Z

/ | \

0+2Z 1+2Z 1+3Z ...

/ \ \ /

... ... 1+6Z

... ... ...

... 0+0Z 1+0Z 2+0Z ...

\ \ | / /

bot

Ordering:

" + (a+ bZ)

(a+ bZ) + (a! + b!Z) ;< (b! | gcd(|a( a!|, b))

x 3 a mod b

Page 27: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Simple congruences, continued

27 / 57

Join: " 7 (a+ bZ) = a+ bZ

(a+ bZ) 7 " = a+ bZ

(a+ bZ) 7 (a= + b=Z) = (min(a, a=) + gcd(|a( a=|, b, b=)Z)

Note: there are no infinite, strictly increasing chains.However there are infinite, strictly decreasing chains:

0 + 1Z " 1 + 2Z " 1 + 6Z " 1 + 12Z " . . .

hence we may need a narrowing. . .

Page 28: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Simple congruences, continued

27 / 57

Join: " 7 (a+ bZ) = a+ bZ

(a+ bZ) 7 " = a+ bZ

(a+ bZ) 7 (a= + b=Z) = (min(a, a=) + gcd(|a( a=|, b, b=)Z)

Note: there are no infinite, strictly increasing chains.However there are infinite, strictly decreasing chains:

0 + 1Z " 1 + 2Z " 1 + 6Z " 1 + 12Z " . . .

hence we may need a narrowing. . .

Q: what do the elements 0 + 2Z and 1 + 2Z representtogether with " and 0 + 1Z?

Page 29: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Simple congruences, continued

27 / 57

Join: " 7 (a+ bZ) = a+ bZ

(a+ bZ) 7 " = a+ bZ

(a+ bZ) 7 (a= + b=Z) = (min(a, a=) + gcd(|a( a=|, b, b=)Z)

Note: there are no infinite, strictly increasing chains.However there are infinite, strictly decreasing chains:

0 + 1Z " 1 + 2Z " 1 + 6Z " 1 + 12Z " . . .

hence we may need a narrowing. . .

Q: what do the elements 0 + 2Z and 1 + 2Z representtogether with " and 0 + 1Z?

Q: what about . . . , 0 + 0Z, 1 + 0Z, 2 + 0Z, 3 + 0Z, . . .together with " and 0 + 1Z?

Page 30: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Simple congruence operations

28 / 57

The arithmetic operators over congruences, e.g.,addition:

(a+ bZ) +" = "

"+ (a+ bZ) = "

(a+ bZ) + (c+ dZ) = ((a+ c) mod gcd(b, d)) + gcd(b, d)Z

and multiplication:

(a+ bZ) 5 " = "

" 5 (a+ bZ) = "

(a+ bZ) 5 (c+ dZ) = (ac mod gcd(ad, bc, bd))

+ gcd(ad, bc, bd)Z

Page 31: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Intervals (Moore’66, Cousot-Cousot’76)

29 / 57

Interval = {"} . {[l, u] | l / Z . {(>}

6 u / Z . {+>} 6 l 1 u}

%#(Z);&' (()()*(((!

"

%Interval ;+'

[!","]...

. . . [!2,!2] [!1,!1] [0, 0] [1, 1] [2, 2] . .

. . . [!2,!1] [!1, 0] [0, 1] [1, 2] . . .

. . . [!2, 0] [!1, 1] [0, 2] . . .

. . . [!2, 1] [!1, 2] . . .

. . . [!2, 2] . . .

. . . . . .

#

"(") = !

"([a, b]) = {n / Z | a 1 n 1 b}

!(!) = "

!(S) = [minS,maxS]

Note: intervals over R also work, however over Q theresulting domain is not complete.

Page 32: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Intervals, continued (2/3)

30 / 57

Least upper bounds:

X 7 " = X

" 7 Y = Y

[a, b] 7 [c, d] = [min(a, c),max(b, d)]

Greatest lower bounds:

X 8 " = "

" 8 Y = "

[a, b] 8 [c, d] =

"

[max(a, c),min(b, d)] if max(a, c) 1 min(b, d)

" otherwise

Page 33: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Intervals, continued (3/3)

31 / 57

Interval addition:

"+X = "

X +" = "

[a, b] + [c, d] = [a+ c, b+ d]

Widening and narrowing:

"# I = I I #" = I

[a, b]#[c, d] =

#"

(> c < a

a c 9 a,

"

+> d > b

b d 1 b

$

"$ I = " I $" = "

[a, b]$[c, d] =

#"

c a = (>

a otherwise,

"

d b = +>

b otherwise

$

Page 34: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Interval widening example

32 / 57

Widening with " yields identity:

!#[1, 100] = [1, 100]

Increasing upper bounds expand to>:

[1, 100]#[1, 101] = [1,>]

Decreasing lower bounds expand to (>:

[1,>]#[0, 102] = [(>,>]

Page 35: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Convex Polyhedra

Page 36: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Convex Polyhedra (1/2)

34 / 57

We can use inequalities to describe the relationshipbetween numerical variables of a program, e.g.:

y 9 1 6 x+ y 9 3 6 ( x+ y 1 1

for two variables x and y.

The inequalities representa convex polyhedron.

These form the abstractvalues of the polyhedradomain, which is a rela-tional abstract domain.

y ^ /

| /

3 | /

| /

2 | \

| \

1 | ---------------

|

0 +--------------------->

0 1 2 3 4 5 6 ... x

Page 37: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Representation (implementation)

35 / 57

Convex polyhedra are represented using doubledescription (with variables X = {x1, . . . , xn}):

! a system of inequalities (A,B) where A is an m0 nmatrix, B is an m vector, and"(A,B) = {X | AX 9 B}

! a system of generators (V,R) of vertices and rayswhere V = {V1, . . . , Vk}, R = {R1, . . . , Rl}, and

"(V,R) = {!ki=1$iVi + !l

i=1µiRi | $i 9 0 6

µi 9 0 6 !ki=1$i = 1}

An domain implementation will typically translate backand forth between the two, trying to minimize thenumber of conversions.

Page 38: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Representation example

36 / 57

For example, we can represent

y 9 1 6 x+ y 9 3 6 ( x+ y 1 1

as a system of inequalities: AX 9 B%

&

0 11 11 (1

'

(

)

xy

*

9

%

&

13(1

'

(

as a system of generators:

V = {V0 : (2, 1), V1 : (1, 2)}

R = {R0 : (1, 0), R1 : (1, 1)}

y ^ /

| _

3 | /| R1

|V1/

2 | \

| \ R0

1 | x-> - - - - - -

| V0

0 +--------------------->

0 1 2 3 4 5 6 ... x

Page 39: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Convex Polyhedra (2/2)

37 / 57

Operations, some of which are easier on onerepresentation, rather than the other:

7 – returns a convex hull, which is anover-approximation of the union of two polyhedra.

Easily expressed as a union of the correspondinggenerators.

8 – returns the polyhedron representing the intersectionof two polyhedra.

Easily expressed as the conjunction of the twoconstraint systems.

Page 40: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

But there is a catch

38 / 57

The polyhedra lattice is not complete: there existsstrictly infinite chains for which the limit is not in thedomain. Example: a disk.

Hence for some sets, e.g., a disk, there is no bestabstraction.

As a consequence the abstraction to polyhedra is not aGalois connection.

A possible relaxation is to consider only concretizationfunctions. . .

Page 41: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Concretization-based abstract interpretation

39 / 57

Proposition. Assume %C;+,7' is a poset, F : C ) C isa continuous function, "c / C such that "c + F ("c),and

+

n/N Fn("c) exists.

Assume A is a set, " : A) C is a function, 1 is apreorder, defined as: c 1 c= ;< "(c) + "(c=), "a / Asuch that "c + "("a), G : A) A is a monotone functionsuch that F 4 " + " 4 G and # is a widening operator.

Then the upward iteration sequence with widening isultimately stationary with limit a, such that lfpF + "(a)and G(a) 1 a.

As an alternative, Miné suggests a framework based onpartial Galois connections, in which ! is a partialfunction.

Page 42: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Want more abstractions?

40 / 57

There are many more numerical abstractions, see, e.g.,Miné’s thesis or this link:

http://bugseng.com/products/ppl/abstractions

The Two Variables per Inequality (TVPI) domain is arestricted form of polyhedra, only expressing relationsbetween two variables: aijxi + bijxj 1 cij

Miné’s Octagon domain is another restricted form ofpolyhedra, also expressing relations between twovariables: ±xi ± xj 1 cij

Q: what do we get by restricting to one variable perinequality?

Page 43: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Numerical domains, botanically

41 / 57

ATTRIBUTE INDEPENDENT DOMAINS (NON-RELATIONAL):

Parity, Sign, Constants, Simple Congruences,Intervals, . . .

RELATIONAL DOMAINS:

Polyhedra, Octagons, TVPI, . . .

Page 44: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

A few connections between numericalabstractions

Page 45: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

From intervals to a constant/sign combination

43 / 57

["#,#]...

. . . ["2,"2] ["1,"1] [0, 0] [1, 1] [2, 2] . . .

. . . ["2,"1] ["1, 0] [0, 1] [1, 2] . . .

. . . ["2, 0] ["1, 1] [0, 2] . . .

. . . ["2, 1] ["1, 2] . . .

. . . ["2, 2] . . .

. . . . . .

$

(()()*(((!

"

#neg pos

. . . (2 (1 0 1 2 . . .

"where

!(") = "

!([a, a]) = a

!([a, b]) =

,

-

.

-

/

pos if a 9 0

neg if b 1 0

# otherwise

Page 46: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

From the constant/sign combination to . . .

44 / 57

This domain can (naturally) be abstracted to bothconstants: #

neg pos

. . . (2(1 0 1 2 . . .

"

(()()*(((!

"

#

. . . (2(1 0 1 2 . . .

"

and signs:

#neg pos

. . . (2(1 0 1 2 . . .

"

(()()*(((!

"

#

0

˙neg ˙pos

"

Page 47: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

From the constant/sign combination to . . .

45 / 57

Both can be abstracted into a simple two-point domain:

#

0

˙neg ˙pos

"

(()()*(((!

" #

"

and all the way down to a one-point lattice:

#

"(()()*(((

!

"

"

Page 48: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Connection summary

46 / 57

To summarize:

Interval ConstSign

Const

Sign

TopBot "

A nice lattice of lattices! %̈

Page 49: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

The 3 counter machine analysis, revisited

Page 50: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

The 3 counter machine analysis, revisited

48 / 57

We arrived at an abstract transition function T, but theanalysis is the least fixed point lfp of T.

Q: Which fixed point theorem(s) of the three from lasttime are we using?

Page 51: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Design choices of the analysis

49 / 57

The resulting analysis associates an abstract memory toeach program point:

#(PC 0 N0 0 N0 0 N0) (()*((!

"

PC ) (Parity 0 Parity 0 Parity)

Page 52: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Design choices of the analysis

49 / 57

The resulting analysis associates an abstract memory toeach program point:

#(PC 0 N0 0 N0 0 N0) (()*((!

"

PC ) (Parity 0 Parity 0 Parity)

Alternatively we could have abstracted the componentsseparately as follows:

#(PC 0 N0 0 N0 0 N0) (()*((!

"

#(PC )0 (Parity 0 Parity 0 Parity)

Page 53: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Design choices of the analysis

49 / 57

The resulting analysis associates an abstract memory toeach program point:

#(PC 0 N0 0 N0 0 N0) (()*((!

"

PC ) (Parity 0 Parity 0 Parity)

Alternatively we could have abstracted the componentsseparately as follows:

#(PC 0 N0 0 N0 0 N0) (()*((!

"

#(PC )0 (Parity 0 Parity 0 Parity)

Q: how would you characterize the first analysis usingstatic analysis terminology?

Page 54: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Design choices of the analysis

49 / 57

The resulting analysis associates an abstract memory toeach program point:

#(PC 0 N0 0 N0 0 N0) (()*((!

"

PC ) (Parity 0 Parity 0 Parity)

Alternatively we could have abstracted the componentsseparately as follows:

#(PC 0 N0 0 N0 0 N0) (()*((!

"

#(PC )0 (Parity 0 Parity 0 Parity)

Q: how would you characterize the first analysis usingstatic analysis terminology?

Q: how would you characterize the second?

Page 55: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Alternative 3 counter machine analyses?

50 / 57

Q: What changes if we want to switch to a differentnumerical abstraction (intervals, congruences, . . . )?

or rather,

Q: which assumptions about Parity did we rely on?

Page 56: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Alternative 3 counter machine analyses?

50 / 57

Q: What changes if we want to switch to a differentnumerical abstraction (intervals, congruences, . . . )?

or rather,

Q: which assumptions about Parity did we rely on?

!(N0 $ N0 $ N0) !%&! !(N0)$ !(N0)$ !(N0)

!(N0) !%!%&!! Par !(N0) !%!%&!! Par !(N0) !%!%&!! Par

!(N0)$ !(N0)$ !(N0) !%&! Par $ Par $ Par

!(N0 $ N0 $ N0) !%&! Par $ Par $ Par

PC % !(N0 $ N0 $ N0) !%&! PC % Par $ Par $ Par

Page 57: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

From fixed points to constraints

51 / 57

Recall: a fixed point of T satisfies: T (S#) = S#

and a post-fixed point satisfies: T (S#) + S#

Any post-fixed point of T is a sound approximation oflfpT

In our case, T is defined as a big (pointwise) join:

T (S#) = X1 7̇X2 7̇ . . . 7̇Xn +̇S#

which is equivalent to:

X1 +̇S# 6 X2 +̇S# 6 . . . 6 Xn +̇S#

Page 58: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Extracting 3 counter machine constraints (1/4)

52 / 57

T(S#) = ( <bot,bot,bot>. [1 -> <top, even, even> ] )

U.

U. ( <bot,bot,bot>. [pc+1 -> [x++]#(S#(pc))] )

pc in Dom(S#)

P_pc = inc x

(...and for y and z)

U.

U. ( <bot,bot,bot>. [pc+1 -> [x--]#(S#(pc))] )

pc in Dom(S#)

P_pc = dec x

(...and for y and z)

U.

U. ( <bot,bot,bot>. [pc’ -> [x==0]#(S#(pc))] )

pc in Dom(S#) U. ( <bot,bot,bot>. [pc’’ -> [x<>0]#(S#(pc))] )

P_pc = zero x pc’ else pc’’

(...and for y and z)

C. S#

Page 59: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Extracting 3 counter machine constraints (2/4)

53 / 57

( <bot,bot,bot>. [1 -> <top, even, even> ] ) C. S#

/\

U. ( <bot,bot,bot>. [pc+1 -> [x++]#(S#(pc))] ) C. S#

pc in Dom(S#)

P_pc = inc x

(...and for y and z)

/\

U. ( <bot,bot,bot>. [pc+1 -> [x--]#(S#(pc))] ) C. S#

pc in Dom(S#)

P_pc = dec x

(...and for y and z)

/\

U. ( <bot,bot,bot>. [pc’ -> [x==0]#(S#(pc))] ) C. S#

pc in Dom(S#) U. ( <bot,bot,bot>. [pc’’ -> [x<>0]#(S#(pc))] )

P_pc = zero x pc’ else pc’’

(...and for y and z)

Page 60: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Extracting 3 counter machine constraints (3/4)

54 / 57

<top, even, even> C S#(1)

/\

for all pc in Dom(S#), such that P_pc = inc x :

[x++]#(S#(pc)) C S#(pc+1)

(...and for y and z)

/\

for all pc in Dom(S#), such that P_pc = dec x :

[x--]#(S#(pc)) C S#(pc+1)

(...and for y and z)

/\

for all pc in Dom(S#), such that P_pc = zero x pc’ else pc’’ :

[x==0]#(S#(pc)) C S#(pc’)

/\ [x<>0]#(S#(pc)) C S#(pc’’)

(...and for y and z)

. . . not that far from the constraint-based analyses of ’dOvs’ and ’Static Analysis’.

Page 61: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Extracting 3 counter machine constraints (4/4)

55 / 57

<top, even, even> C S#(1)

/\

for all "inc x" instructions in P with program counter pc :

[x++]#(S#(pc)) C S#(pc+1)

(...and for y and z)

/\

for all "dec x" instructions in P with program counter pc :

[x--]#(S#(pc)) C S#(pc+1)

(...and for y and z)

/\

for all "zero x pc’ else pc’’" instructions in P with program counter pc

[x==0]#(S#(pc)) C S#(pc’)

/\ [x<>0]#(S#(pc)) C S#(pc’’)

(...and for y and z)

. . . not that far from the constraint-based analyses of ’dOvs’ and ’Static Analysis’.

Page 62: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Summary

Page 63: on 2012lim.univ-reunion.fr/staff/fred/Enseignement/Verif-M2/AbsInt-Jan... · y 57 s s: % ℘ ( C 1); ⊆’ −→− α 1 γ 1 % A 1; ≤ 1 ’%℘ ( C 2); ⊆’ −→− α 2

Summary

57 / 57

A catalogue of abstractions

! Toolbox abstractions

! Structural abstractions: sums, pairs/tuples, . . .

! Numerical abstractions: constants, intervals,congruences, polyhedra, . . .

! Concretization-based abstract interpretation, briefly

A retrospective on the 3 counter machine analysis, incl.constraint extraction