Program Analysis
Instructor: Martin Vechev
Author: Gagandeep Singh
March 12, 2015
Relational Domains
I
Interval domain only captures bounds of program variables
I
Many verification tasks require relational invariants
I
Buffer overflow, Concurrency bugs, Aliasing
I
Tradeoff between complexity and expressive power
Numerical Abstract Domains
I
Interval:
cheap but
less
expressive
I
Polyhedra:
expressive
but costly
I
Octagon:
cheaper
than
Polyhedra,
limited
expressive
power
Asymptotic Complexity
Pn
i=1
ai xi ≤ c
Polyhedra
±xi ± xj ≤ c
c ≤ xi ≤ d
Octagon
Interval
Expressive Power
Abstract Interpretation Recipe
1. come up with an abstract domain
I
select based on the type of properties you want to prove
2. define abstract semantics for the programming language w.r.t.
to the abstract domain from step 1.
I
I
we need to define the abstract transformers, that is, the effect
of statement/expression on the abstract domain
we need to prove that the abstract semantics are sound w.r.t
concrete semantics of the programming language
3. iterate abstract transformers over the abstract domain
I
until we reach a fixed point
Octagon Abstract Domain
I
Introduced in 2001 by
Antoine Miné
I
Quadratic space
complexity
I
Cubic time complexity
I
Used in Astrée
analyzer for verifying
correctness of flight
software in AirBus
I
Antoine Miné, ”The
octagon abstract
domain”, In AST in
WCRE 2001, IEEE
Octagon Abstract Domain
I
I
Supports limited set of linear inequalities between program
variables
Octagonal inequalities:
I
I
I
I
Binary: ±vj ± vi ≤ c, vi 6= vj
Unary: ±vi ≤ d
c, d ∈ R ∪ {∞}
If an inequality does not exist, then its bound is ∞
I
The inequalities limit the set of possible values taken by
program variables
I
For n variables there are 2n2 possible inequalities
Octagons
Let L be the set of Octagonal inequalities between n variables,
then an octagon is conjunction of all the inequalities in set L
x=1
=
+
y
y
+
=
x
3
x = −2
y=2
2
−
x
−
x
y
=
1
−
2
−
y
=
x
I
y = −1
Encoding of Octagons
I
I
I
I
Each octagonal
inequality can be
encoded as an element of
a matrix m
Each variable vi is
0 = v+
unfolded into v2i
i
−
0
and v2i+1
= vi
mi,j = c represents
vj0 − vi0 ≤ c
vi + vj ≤ c can be
represented as:
vj+ − vi− ≤ c and
vi+ − vj− ≤ c
+
−
+
−
+
−
+
−
v0
v0
v1
v1
v2
v2
v3
v3
+
v0
−
v0
+
v1
−
v1
0
0
0
v1 + v2 ≤ c
0
+
v2
0
c1
−
v2
c2
0
+
v3
−2v2 ≤ c1
0
−
v3
0
v1 + v2 ≤ c 2v2 ≤ c2
Octagon Abstract Domain
I
The Octagon domain: {Oo , vo , to , uo , ⊥o , >o }
I
⊥o represents bottom element that contains an unsatisfiable
set of inequalities
I
O is the set of all octagons
I
Oo = O ∪ {⊥o }
I
>o represents top element for which the bound for all
inequalities is ∞
Uniqueness of Octagons
I
An octagon can be represented by more than one set of
inequalities
I
(x ≤ 4) ∧ (y ≤ 6) and (x ≤ 4) ∧ (y ≤ 6) ∧ (x + y ≤ 10)
represent the same concrete values, thus no galois insertion
I
A unique representation of octagons is required to build galois
insertion
I
The set with maximum inequalities representing an octagon is
unique
Closure (*)
I
Closure operator produces unique octagon representation
I
Combine binary inequalities vi − vj ≤ c1 and vj − vk ≤ c2 to
obtain vi − vk ≤ c1 + c2
I
If the octagon already contains vi − vk ≤ c, then keep
vi − vk ≤ min(c, c1 + c2 )
I
This is same as applying Floyd Warshall on octagon matrix
I
Combining binary inequalities of
(x − y ≤ 4) ∧ (y − z ≤ 6) ∧ (x ≤ 5) ∧ (y ≤ 7) we get
(x − y ≤ 4) ∧ (y − z ≤ 6) ∧ (x − z ≤ 10) ∧ (x ≤ 5) ∧ (y ≤ 7)
Closure (*)
I
The previous step alone does not produce maximal set
I
Combine unary inequalities vi ≤ c1 and vj ≤ c2 to obtain
vi + vj ≤ c1 + c2
I
If the octagon already contains vi + vj ≤ c, then keep
vi + vj ≤ min(c, c1 + c2 )
I
Combining unary inequalities of
(x − y ≤ 4) ∧ (y − z ≤ 6) ∧ (x − z ≤ 10) ∧ (x ≤ 5) ∧ (y ≤ 7)
we get (x − y ≤ 4) ∧ (y − z ≤ 6) ∧ (x − z ≤ 10) ∧ (x ≤
5) ∧ (y ≤ 7) ∧ (x + y ≤ 12)
I
The set produced thus produced is maximal
Closure (*)
+
−
+
−
+
−
+
−
v0
v0
v1
v1
v2
v2
v3
v3
+
−
+
−
+
−
+
−
v0
v0
v1
v1
v2
v2
v3
v3
+
v0
0
−
v0
2
0
6
2
10
2
2
2
+
v1
24
2
0
2
10
42
12
4
−
v1
14
28
2
0
2
2
22
38
+
v2
30
38
32
2
0
38
2
2
−
v2
2
14
2
2
24
0
2
2
+
v3
24
2
2
28
2
2
0
32
−
v3
2
2
2
2
6
6
26
2
24
2
42
20
2
8
0
∗
+
v0
0
2
2
2
2
2
2
3
−
v0
2
0
2
2
3
2
2
2
+
v1
2
2
0
2
3
3
2
3
−
v1
2
2
2
0
2
2
2
3
+
v2
3
3
3
2
0
4
2
2
−
v2
2
3
2
2
4
0
2
2
+
v3
3
2
2
3
2
2
0
4
−
v3
2
2
2
2
3
3
2
0
Least Upper Bound (to )
I
The union of two octagons is not necessarily an octagon
I
to of two octagons is approximated
I
To reduce the imprecision due to approximation, closure
operator is applied on both operands before computing t
I
to can be computed by taking piecewise maximum of bounds
of corresponding inequalities
I
(x ≤ 5) ∧ (x + y ≤ 10) to (x ≤ 4) ∧ (x + y ≤ 11)
⇓
(x ≤ 5) ∧ (x + y ≤ 11)
Greatest Lower Bound (uo )
I
The intersection of two octagons is always an octagon
I
uo of two octagons can be computed by taking piecewise
minimum of bounds of corresponding inequalities
I
(x ≤ 5) ∧ (x + y ≤ 10) uo (x ≤ 4) ∧ (x + y ≤ 11)
⇓
(x ≤ 4) ∧ (x + y ≤ 10)
Order (vo )
I
The octagons are ordered by the inclusion relation
I
An octagon O1 is included inside another octagon O2 iff the
bounds of each inequality in O1 is ≤ than the corresponding
inequality in O2
I
The closed octagon is the smallest octagon as per vo among
the set of octagons abstracting same concrete values.
I
Compare closed form of O1 with O2
I
(x ≤ 5) ∧ (x + y) ≤ 10 vo (x ≤ 6) ∧ (x + y) ≤ 10
Widening (5o )
I
If the bound of an inequality keeps increasing, widening sets it
to ∞
I
(x ≤ 5) ∧ (x + y ≤ 10) 5o (x ≤ 4) ∧ (x + y ≤ 11)
⇓
(x ≤ 5) ∧ (x + y ≤ ∞)
I
Widening operator for octagon domain is tricky, it requires
first operand to not be closed
I
This is because widening increases the number of inequalities
with ∞ bounds whereas closure does the reverse
Abstract Interpretation Recipe
1. come up with an abstract domain
I
select based on the type of properties you want to prove
2. define abstract semantics for the programming language w.r.t.
to the abstract domain from step 1
I
I
we need to define the abstract transformers, that is, the effect
of statement/expression on the abstract domain
we need to prove that the abstract semantics are sound w.r.t
concrete semantics of the programming language
3. iterate abstract transformers over the abstract domain
I
until we reach a fixed point
Transformer for Assignment Statements
I
Assignment statements can be divided into two types:
I
Octagonal assignments
I
I
I
I
Non-octagonal assignments
I
I
I
I
x = 5;
x = x + 10;
x = y + 5;
x = 2y;
x = y + z;
x = y/z;
The transformer is precise for octagonal whereas approximate
for non octagonal assignments
Transformer for Octagonal Assignments
I
x=c
I
I
I
x=x+c
I
I
I
I
Add inequalities (x ≤ c) and (−x ≤ −c) to the octagon
The resulting octagon needs to be closed
Subtract c from inequalities having -ve coeffiecient for x
Add c to inequalities having +ve coeffiecient for x
The resulting octagon is closed
x=y+c
I
I
Add inequalities (x − y ≤ c) and (y − x ≤ c) to the ocatgon
The resulting octagon needs to be closed
Transformer for Non-octagonal Assignments
I
xj = e where xj − e is non octagonal
I
I
I
I
Compute bounds [a, b] for ePusing interval arithmetic
n
]xi where each xi has
For example e = [a0 , b0 ] + i=1 [ai , biP
n
bounds [ci , di ] then [a, b] = [a0 , b0 ] + i=1 [ai , bi ] × [ci , di ]
Add constraints of the form ±xi ± xj ≤ ±[a, b] ± [ci , di ] to the
octagon
The resulting octagon is not closed
Transformer for Conditional Statements
I
Conditional statements encode constraints which can be
added to the input octagon
I
The constraints can again be octagonal or non octagonal
I
The octagonal constraints are handled precisely
I
The effect of adding non-octagonal constraints is
approximated
Abstract Interpretation Recipe
1. come up with an abstract domain
I
select based on the type of properties you want to prove
2. define abstract semantics for the programming language w.r.t.
to the abstract domain from step 1.
I
I
we need to define the abstract transformers, that is, the effect
of statement/expression on the abstract domain
we need to prove that the abstract semantics are sound w.r.t
concrete semantics of the programming language
3. iterate abstract transformers over the abstract domain
I
until we reach a fixed point
Octagon Analysis Example
1
2
3
4
5
6
x =1;
y=x ;
w h i l e ( x <= m)
x=x +1;
y=y+x ;
a s s e r t ( y >= m)
I
O1 : >o
I
O2 : >o
I
O3 : >o
I
O4 : >o
I
O5 : >o
I
O6 : >o
Octagon Analysis Example
1
2
3
4
5
6
x+
O1
O2∗
+
y − m+ m−
x+ x− y
+
y − m+ m−
x+ x− y
0
∞
∞
∞
∞
∞
x+
∞
∞
x
−
2
∞
∞
y
+
∞
y
−
∞
∞
+
∞
∞
m− ∞
∞
x
−
∞
0
∞
∞
y
+
∞
∞
0
∞
y
−
∞
∞
∞
0
∞
∞
+
∞
∞
∞
∞
0
∞
m− ∞
∞
∞
∞
∞
0
m
x=1;
y=x ;
w h i l e ( x <= m)
x=x +1;
y=y+x ;
a s s e r t ( y >= m)
x=1
m
0
−2 ∞
∞
∞
∞
0
∞
∞
∞
∞
∞
0
∞
∞
∞
∞
0
∞
∞
∞
∞
0
∞
∞
∞
∞
0
Octagon Analysis Example
1
2
3
4
5
6
x =1;
y=x;
w h i l e ( x <= m)
x=x +1;
y=y+x ;
a s s e r t ( y >= m)
O2∗
+
x
0
−2 ∞
x
x+
−
+
y
y
O3
−
∞
m
+
∞
m
−
y − m+ m−
−2
0
∞
∞
∞
x
x
−
y
∞
x+
0
∞
∞
x
−
2
0
∞
0
∞
∞
∞
∞
y
+
0
∞
0
∞
∞
∞
y
−
∞
0
∞
0
∞
∞
+
∞
∞
∞
∞
0
∞
m− ∞
∞
∞
∞
∞
0
x
−
2
0
∞
∞
y
+
∞
∞
0
∞
y
−
∞
∞
∞
0
∞
∞
+
∞
∞
∞
∞
0
∞
m− ∞
∞
∞
∞
∞
0
m
+
+
y=x
m
Octagon Analysis Example
1
2
3
4
5
6
x+
O3
O3∗
+
y − m+ m−
x+ x− y
+
y − m+ m−
x+ x− y
0
−2
0
∞
∞
∞
x+
0
∞
∞
x
−
∞
∞
y
+
y
−
2
0
2
+
∞
∞
∞
m− ∞
∞
∞
∞
x
−
2
0
∞
0
y
+
0
∞
0
∞
y
−
∞
0
∞
0
∞
∞
+
∞
∞
∞
∞
0
∞
m− ∞
∞
∞
∞
∞
0
m
x =1;
y=x;
w h i l e ( x <= m)
x=x +1;
y=y+x ;
a s s e r t ( y >= m)
∗
m
−2
0
2
0
2
0
−2
0
−2 ∞
∞
∞
∞
−2 ∞
∞
0
∞
∞
∞
0
∞
∞
0
0
Octagon Analysis Example
1
2
3
4
5
6
x =1;
y=x ;
while(x ≤ m)
x=x +1;
y=y+x ;
a s s e r t ( y >= m)
O3∗
x
0
−2
x
x+
−
+
y
0
−2 ∞
y
x
−
2
0
2
y
+
0
−2
0
y−
2
0
2
∞
∞
m− ∞
∞
m
+
O4
−
+
m
+
m
−
+
y − m+ m−
−2
0
−2 ∞
+
x
x
−
y
∞
x+
0
x
−
2
0
2
y
+
0
−2
0
∞
∞
−2 ∞
∞
0
∞
∞
y−
2
0
2
∞
∞
0
∞
+
0
∞
∞
∞
∞
∞
0
∞
∞
∞
0
while(x <= m)
m
m− ∞
0
∞
∞
0
−2 ∞
∞
0
∞
∞
∞
0
∞
∞
0
Octagon Analysis Example
1
2
3
4
5
6
x+
O4
O4∗
+
y − m+ m−
x+ x− y
+
y − m+ m−
x+ x− y
0
−2
0
x
−
2
0
2
y
+
0
−2
0
y−
2
0
2
+
0
∞
∞
m
x =1;
y=x ;
while(x ≤ m)
x=x +1;
y=y+x ;
a s s e r t ( y >= m)
m− ∞
−2 ∞
0
∞
∞
0
∗
x+
0
x
−
y
+
−2
0
2
0
2
0
−2
0
−2 ∞ −2
0
∞
0
−2 ∞
∞
0
∞
∞
y−
2
0
2
0
∞
0
∞
∞
0
∞
+
0
−2
0
−2
0
−2
∞
∞
∞
0
∞
∞
∞
∞
0
m
m− ∞
−2 ∞ −2
Octagon Analysis Example
1
2
3
4
5
6
x+
O4∗
O5∗
+
y − m+ m−
x+ x− y
+
y − m+ m−
x+ x− y
0
−2
0
−2 ∞ −2
x
−
2
0
2
y
+
0
−2
0
y−
2
0
2
0
∞
0
+
0
−2
0
−2
0
−2
∞
∞
∞
∞
0
m
x =1;
y=x ;
w h i l e ( x <= m)
x=x+1;
y=y+x ;
a s s e r t ( y >= m)
m− ∞
0
∞
0
−2 ∞ −2
x=x+1
−4 −1 −3 ∞ −3
x+
0
x
−
4
0
3
y
+
1
−3
0
y−
3
−1
2
0
∞
0
+
1
−3
0
−2
0
−2
∞
∞
∞
∞
0
m
m− ∞
1
∞
1
−2 ∞ −2
Octagon Analysis Example
1
2
3
4
5
6
x =1;
y=x ;
w h i l e ( x <= m)
x=x +1;
y=y+x;
a s s e r t ( y >= m)
O5∗
+
O6
−
0
−4 −1 −3 ∞ −3
y
y
m
+
−
x
x
x+
−
+
m
x
−
4
0
3
y
+
1
−3
0
y−
3
−1
2
0
∞
0
+
1
−3
0
−2
0
−2
∞
∞
∞
∞
0
m
m− ∞
1
∞
1
−2 ∞ −2
y =y+x
x
−
y
+
y − m+ m−
−4
1
−5 ∞ −3
0
5
−1 ∞
0
−6 ∞ −4
x
0
4
x
x+
+
+
−
−1 −5
y
2
y−
5
1
6
0
∞
0
+
1
−3
2
−4
0
−2
∞
∞
∞
∞
0
m
m− ∞
Octagon Analysis Example
1
2
3
4
5
6
x =1;
y=x ;
while(x ≤ m)
x=x +1;
y=y+x ;
a s s e r t ( y >= m)
O3∗
0
−2
O6∗
0
−2 ∞
∞
∞
∞
0
0
4
−4
1
−5 ∞ −5
5
−1 ∞ −1
0
−6 ∞ −6
0
5
2
0
2
0
−2
0
−2 ∞
∞
∞
5
1
6
0
∞
to
0
O3∗
−1 −5
0
⇒
−2
1
−2 ∞
∞
∞
∞
4
0
5
0
0
−2
0
−2 ∞
∞
1
6
0
∞
∞
2
0
2
0
∞
∞
∞
∞
∞
0
∞
0
−4
1
−5
0
−4
∞
∞
∞
∞
0
∞
∞
∞
∞
∞
∞
0
∞
∞
∞
∞
∞
0
∞
∞
∞
∞
∞
0
© Copyright 2026 Paperzz