Isabelle: Not Only a Proof Assistant
Achim D. Brucker
achim@brucker.ch http://www.brucker.ch/
joint work with Lukas Brügger, Delphine Longuet, Yakoub Nemouchi, Frédéric Tuong, Burkhart Wolff
Proof Assistants and Related Tools - The PART Project
Technical University of Denmark, Kgs. Lyngby, Denmark
September 24, 2015
Isabelle: Not Only a Proof Assistant
Abstract
The Isabelle homepage describes Isabelle as “a generic proof assistant. It allows mathematical
formulas to be expressed in a formal language and provides tools for proving those formulas in a
logical calculus.” While this, without doubts, what most users of Isabelle are using Isabelle for,
there is much more to discover: Isabelle is also a framework for building formal methods tools.
In this talk, I will report on our experience in using Isabelle for building formal tools for high-level
specifications languages (e.g., OCL, Z) as well as using Isabelle’s core engine for new applications
domains such as generating test cases from high-level specifications.
Motivation
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 4
Motivation
This is only the tip of the iceberg
Isar
jEdit auto
define Isar
command
datatype packages own code
generators
Isabelle
kernel
tactic implementation
generate
codesledgehammer
ML Interface
Scala interface
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 5
Outline
1 Motivation
2 Isabelle tools on top of Isabelle (Add-on)
HOL-OCL 1.x
HOL-OCL 2.x
HOL-TestGen
3 Conclusion
Isabelle tools on top of Isabelle (Add-on) HOL-OCL 1.x
UML/OCL in a nutshell
UML
Visual modeling language
Object-oriented development
Industrial tool support
OMG standard
Many diagram types, e.g.,
activity diagrams
class diagrams
. . .
OCL
Textual extension of the UML
Allows for annotating UML diagrams
In the context of class–diagrams:
invariants
preconditions
postconditions
Account
balance:Integer
id:Integer
getId():Integer
getBalance():Integer
deposit(a:Integer):Boolean
withdraw(a:Integer):Boolean
accounts
1..*
context Account
inv: 0 <= id
context Account::deposit(a:Integer):Boolean
pre: 0 < a
post: balance = balance@pre+a
and id = id@pre
context Account
inv: 0 <= id
context Account::deposit(a:Integer):Boolean
pre: 0 < a
post: balance = balance@pre+a
and id = id@pre
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 7
Isabelle tools on top of Isabelle (Add-on) HOL-OCL 1.x
Developing formals tools for UML/OCL?
Turning UML/OCL into a formal method
1 A formal semantics of object-oriented data models (UML)
typed path expressions
inheritance
. . .
2 A formal semantics of object-oriented constraints (OCL)
a logic reasoning over path expressions
large libraries
three-valued logic
. . .
3 And of course, we want a tool (HOL-OCL)
a formal, machine-checked semantics for OO specifications,
an interactive proof environment for OO specifications.
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 8
Isabelle tools on top of Isabelle (Add-on) HOL-OCL 1.x
Challenges (for a shallow embedding)
Challenge 1:
Can we find a injective, type preserving mapping of
an object-oriented language (and datatypes) into HOL
e:T −→ e :: T
(including subtyping)?
Challenge 2:
Can we support verification in a modular way
(i.e., no replay of proof scripts after extending specifications)?
Challenge 3:
Can we ensure consistency of our representation?
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 9
Isabelle tools on top of Isabelle (Add-on) HOL-OCL 1.x
Representing class types
The “extensible records” approach
We assume a common superclass (O).
A tag type guarantees uniquenessby (Otag := classO).
Construct class type as tuple along inheritance hierarchy:
O
A
s:String
B
b:Integer
Advantages:
it allows for extending class types (inheritance),
subclasses are type instances of superclasses
⇒ it allows for modular proofs, i.e.,
a statement φ(x : : (α B)) proven for class B is still valid after extending class B.
However, it has a major disadvantage:
modular proofs are only supported for one extension per class
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 10
Isabelle tools on top of Isabelle (Add-on) HOL-OCL 1.x
Representing class types
The “extensible records” approach
We assume a common superclass (O).
A tag type guarantees uniquenessby (Otag := classO).
Construct class type as tuple along inheritance hierarchy:
B :=
O
A
s:String
B
b:Integer
Advantages:
it allows for extending class types (inheritance),
subclasses are type instances of superclasses
⇒ it allows for modular proofs, i.e.,
a statement φ(x : : (α B)) proven for class B is still valid after extending class B.
However, it has a major disadvantage:
modular proofs are only supported for one extension per class
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 10
Isabelle tools on top of Isabelle (Add-on) HOL-OCL 1.x
Representing class types
The “extensible records” approach
We assume a common superclass (O).
A tag type guarantees uniquenessby (Otag := classO).
Construct class type as tuple along inheritance hierarchy:
B := (Otag ×oid)
O
A
s:String
B
b:Integer
Advantages:
it allows for extending class types (inheritance),
subclasses are type instances of superclasses
⇒ it allows for modular proofs, i.e.,
a statement φ(x : : (α B)) proven for class B is still valid after extending class B.
However, it has a major disadvantage:
modular proofs are only supported for one extension per class
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 10
Isabelle tools on top of Isabelle (Add-on) HOL-OCL 1.x
Representing class types
The “extensible records” approach
We assume a common superclass (O).
A tag type guarantees uniquenessby (Otag := classO).
Construct class type as tuple along inheritance hierarchy:
B := (Otag ×oid) × (Atag ×String)
O
A
s:String
B
b:Integer
Advantages:
it allows for extending class types (inheritance),
subclasses are type instances of superclasses
⇒ it allows for modular proofs, i.e.,
a statement φ(x : : (α B)) proven for class B is still valid after extending class B.
However, it has a major disadvantage:
modular proofs are only supported for one extension per class
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 10
Isabelle tools on top of Isabelle (Add-on) HOL-OCL 1.x
Representing class types
The “extensible records” approach
We assume a common superclass (O).
A tag type guarantees uniquenessby (Otag := classO).
Construct class type as tuple along inheritance hierarchy:
B := (Otag ×oid) × (Atag ×String) × (Btag ×Integer)
O
A
s:String
B
b:Integer
Advantages:
it allows for extending class types (inheritance),
subclasses are type instances of superclasses
⇒ it allows for modular proofs, i.e.,
a statement φ(x : : (α B)) proven for class B is still valid after extending class B.
However, it has a major disadvantage:
modular proofs are only supported for one extension per class
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 10
Isabelle tools on top of Isabelle (Add-on) HOL-OCL 1.x
Representing class types
The “extensible records” approach
We assume a common superclass (O).
A tag type guarantees uniquenessby (Otag := classO).
Construct class type as tuple along inheritance hierarchy:
α B := (Otag ×oid) × (Atag ×String) × (Btag ×Integer) × α
O
A
s:String
B
b:Integer
α
Advantages:
it allows for extending class types (inheritance),
subclasses are type instances of superclasses
⇒ it allows for modular proofs, i.e.,
a statement φ(x : : (α B)) proven for class B is still valid after extending class B.
However, it has a major disadvantage:
modular proofs are only supported for one extension per class
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 10
Isabelle tools on top of Isabelle (Add-on) HOL-OCL 1.x
Idea: a general universe type
A universe type representing all classes of a class model
supports modular proofs with arbitrary extensions
provides a formalization of a extensible typed object store
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 11
Isabelle tools on top of Isabelle (Add-on) HOL-OCL 1.x
An extensible object store
O O
αO
U
(αO) = O × αO
⊥
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 12
Isabelle tools on top of Isabelle (Add-on) HOL-OCL 1.x
An extensible object store
O O
αO
U
(αO) = O × αO
⊥
A
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 12
Isabelle tools on top of Isabelle (Add-on) HOL-OCL 1.x
An extensible object store
O O
αO
U
(αO) = O × αO
⊥
A A βO
αA
U
(αO) = O × αO
⊥
U
(αA,βO)
= O × (A × αA
⊥ + βO
)⊥
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 12
Isabelle tools on top of Isabelle (Add-on) HOL-OCL 1.x
An extensible object store
O O
αO
U
(αO) = O × αO
⊥
A A βO
αA
U
(αO) = O × αO
⊥
U
(αA,βO)
= O × (A × αA
⊥ + βO
)⊥
B B βA
αB
U
(αO) = O × αO
⊥
U
(αA,βO)
= O × (A × αA
⊥ + βO
)⊥
U
(αB ,βO,βA)
= O × (A × (B × αB
⊥ + βA
)⊥ + βO
)⊥
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 12
Isabelle tools on top of Isabelle (Add-on) HOL-OCL 1.x
An extensible object store
O O
αO
U
(αO) = O × αO
⊥
A A βO
αA
U
(αO) = O × αO
⊥
U
(αA,βO)
= O × (A × αA
⊥ + βO
)⊥
B B βA
αB
U
(αO) = O × αO
⊥
U
(αA,βO)
= O × (A × αA
⊥ + βO
)⊥
U
(αB ,βO,βA)
= O × (A × (B × αB
⊥ + βA
)⊥ + βO
)⊥C C βA
αC
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 12
Isabelle tools on top of Isabelle (Add-on) HOL-OCL 1.x
An extensible object store
O O
αO
U
(αO) = O × αO
⊥
A A βO
αA
U
(αO) = O × αO
⊥
U
(αA,βO)
= O × (A × αA
⊥ + βO
)⊥
B B βA
αB
U
(αO) = O × αO
⊥
U
(αA,βO)
= O × (A × αA
⊥ + βO
)⊥
U
(αB ,βO,βA)
= O × (A × (B × αB
⊥ + βA
)⊥ + βO
)⊥C C βA
αC
U
(αO) = O × αO
⊥
U
(αA,βO)
= O × (A × αA
⊥ + βO
)⊥
U
(αB ,βO,βA)
= O × (A × (B × αB
⊥ + βA
)⊥ + βO
)⊥
U
(αB ,αC ,βO,βA)
= O × (A × (B × αB
⊥ + (C × αC
⊥ + βA
))⊥ + βO
)⊥
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 12
Isabelle tools on top of Isabelle (Add-on) HOL-OCL 1.x
An extensible object store
O O
αO
U
(αO) = O × αO
⊥
A A βO
αA
U
(αO) = O × αO
⊥
U
(αA,βO)
= O × (A × αA
⊥ + βO
)⊥
B B βA
αB
U
(αO) = O × αO
⊥
U
(αA,βO)
= O × (A × αA
⊥ + βO
)⊥
U
(αB ,βO,βA)
= O × (A × (B × αB
⊥ + βA
)⊥ + βO
)⊥C C βA
αC
U
(αO) = O × αO
⊥
U
(αA,βO)
= O × (A × αA
⊥ + βO
)⊥
U
(αB ,βO,βA)
= O × (A × (B × αB
⊥ + βA
)⊥ + βO
)⊥
U
(αB ,αC ,βO,βA)
= O × (A × (B × αB
⊥ + (C × αC
⊥ + βA
))⊥ + βO
)⊥
U3
(αB,αC,βO,βA) U2
(αB,βO,βA) U1
(αA,βO) U0
(αO)
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 12
Isabelle tools on top of Isabelle (Add-on) HOL-OCL 1.x
Merging universes
U
:
A
Ua
:
A
C
Ub
:
A B
D
U
:
A B
C D
Non-conflicting Merges
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 13
Isabelle tools on top of Isabelle (Add-on) HOL-OCL 1.x
Merging universes
U
:
A
Ua
:
A
C
Ub
:
A B
D
U
:
A B
C D
Non-conflicting Merges
U
:
A
Ua
:
A
C
Ub
:
A
B
U
:
A
BC
Conflicting Merges
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 13
Isabelle tools on top of Isabelle (Add-on) HOL-OCL 1.x
Operations accessing the object store
injections
mkO o = Inl o with type αO
O → U0
αO
projections
getO u = u with type U0
αO → αO
O
type casts
A[O] = getO ◦ mkA with type αA
A → (A × αA
⊥ + βO
) O
O[A] = getA ◦ mkO with type (A × αA
⊥ + βO
) O → αA
A
. . .
All definitions are generated automatically
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 14
Isabelle tools on top of Isabelle (Add-on) HOL-OCL 1.x
“Checking” subtyping
For each UML model, we have to show several properties:
O
A
s:String
B
b:Integer
subclasses are of the superclasses kind:
isTypeB self
isKindA self
“re-casting”:
isTypeB self
self[A][B] = ⊥ ∧ isTypeB (self[A][B][A]
)
monotonicity of invariants, . . .
All rules are derived automatically
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 15
Isabelle tools on top of Isabelle (Add-on) HOL-OCL 1.x
HOL-OCL
HOL-OCL provides:
a formal, machine-checked semantics for OO specifications,
an interactive proof environment for OO specifications.
HOL-OCL is integrated into a toolchain providing:
extended well-formedness checking,
proof-obligation generation,
methodology support for UML/OCL,
a transformation framework (including PO generation),
code generators,
support for SecureUML.
HOL-OCL is publicly available:
http://www.brucker.ch/projects/hol-ocl/.
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 16
Isabelle tools on top of Isabelle (Add-on) HOL-OCL 1.x
The HOL-OCL architecture
Standard ML (PolyML, sml/NJ)
HOL-OCL
Isabelle/HOL
susml
HOL-OCL User Interface (extended Proof General)
Repository
UML/OCL
PO-Manager
Encoder
Code-Gen.
WF-Checks
Model-Trans.
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 17
Isabelle tools on top of Isabelle (Add-on) HOL-OCL 1.x
The HOL-OCL user interface
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 18
Isabelle tools on top of Isabelle (Add-on) HOL-OCL 1.x
The HOL-OCL high-level language
The HOL-OCL proof language is an extension of Isabelle’s Isar language:
importing UML/OCL:
import_model "SimpleChair.zargo" "AbstractSimpleChair.ocl"
include_only "AbstractSimpleChair"
check well-formedness and generate proof obligations for refinement:
analyze_consistency [data_refinement] "AbstractSimpleChair"
starting a proof for a generated proof obligation:
po "AbstractSimpleChair.findRole_enabled"
generating code:
generate_code "java"
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 19
Isabelle tools on top of Isabelle (Add-on) HOL-OCL 1.x
The encoder
The model encoder is the main interface between su4sml and the Isabelle based part of
HOL-OCL. The encoder
declarers HOL types for the classifiers of the model,
encodes
type-casts,
attribute accessors, and
dynamic type and kind tests implicitly declared in the imported data model,
encodes the OCL specification, i.e.,
class invariants
operation specifications
and combines it with the core data model, and
proves (automatically) methodology and analysis independent properties of the model.
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 20
Isabelle tools on top of Isabelle (Add-on) HOL-OCL 1.x
Tactics (proof procedures)
OCL, as logic, is quite different from HOL (e.g., three-valuedness)
Major Isabelle proof procedures, like simp and auto,
cannot handle OCL efficiently.
HOL-OCL provides several UML/OCL specific proof procedures:
embedding specific tactics (e.g., unfolding a certain level)
a OCL specific context-rewriter
a OCL specific tableaux-prover
. . .
These language specific variants increase the degree of proof for OCL.
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 21
Isabelle tools on top of Isabelle (Add-on) HOL-OCL 1.x
Proof obligation generator
A framework for proof obligation generation:
Generates proof obligation in OCL plus minimal meta-language.
Only minimal meta-language necessary:
Validity: |= _, _ |= _
Meta level quantifiers: ∃_. _, ∃_. _
Meta level logical connectives: _ ∨ _, _ ∧ _, ¬_
Examples for proof obligations are:
(semantical) model consistency
Liskov’s substitution principle
refinement conditions
. . .
Can be easily extended (at runtime).
Builds, together with well-formedness checking, the basis for tool-supported methodologies.
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 22
Outline
1 Motivation
2 Isabelle tools on top of Isabelle (Add-on)
HOL-OCL 1.x
HOL-OCL 2.x
HOL-TestGen
3 Conclusion
Isabelle tools on top of Isabelle (Add-on) HOL-OCL 2.x
HOL-OCL 2.0 (Featherweight OCL)
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 24
Outline
1 Motivation
2 Isabelle tools on top of Isabelle (Add-on)
HOL-OCL 1.x
HOL-OCL 2.x
HOL-TestGen
3 Conclusion
Isabelle tools on top of Isabelle (Add-on) HOL-TestGen
How to ensure system correctness, security, and safety?
(Inductive) Verification Testing
Formal (mathematical) proof
Can show absence of all
failures relative to specification
Specification of based on
abstractions
Requires expertise in Formal
Methods
In industry:
only for highly critical systems
(regulations, certification)
Execution of test cases
Can show failures on real
system
Only shows failures for the
parts of the system
Requires less skills in Formal
Methods
In industry:
widely used
(often > 40% of dev. effort)
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 26
Isabelle tools on top of Isabelle (Add-on) HOL-TestGen
Is testing a “poor man’s verification?”
Or: Why should I test if I did a verification and vice versa?
“
Program testing can be used to show the presence of bugs,
but never to show their absence! (Dijkstra)
Assume you can choose between two aircraft for you next travel:
Aircraft A:
Fully formally verified
Total number of flights: 0
Aircraft B:
Fully tested
Total number of flights: 1 000
Which aircraft would you take for your next trip?
Which aircraft would Dijkstra take?
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 27
Isabelle tools on top of Isabelle (Add-on) HOL-TestGen
What should we do?
Vision: Use the Optimal Combination of Verification and Testing in an Integrated Approach
Infrastructure&Configuration
Application
Operating System
Hypervisor
Server Application
Runtime Container
Operating System
Backend Systems
Observation:
Both methods have their unique advantages
Recommendation:
Use a combination of verification and testing
Our Vision:
An integrated approach for test and verification
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 28
Isabelle tools on top of Isabelle (Add-on) HOL-TestGen
What should we do?
Vision: Use the Optimal Combination of Verification and Testing in an Integrated Approach
Infrastructure&Configuration
Application
Operating System
Hypervisor
Server Application
Runtime Container
Operating System
Backend Systems
Separation Properties
Safety Properties
Observation:
Both methods have their unique advantages
Recommendation:
Use a combination of verification and testing
Our Vision:
An integrated approach for test and verification
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 28
Isabelle tools on top of Isabelle (Add-on) HOL-TestGen
What should we do?
Vision: Use the Optimal Combination of Verification and Testing in an Integrated Approach
Infrastructure&Configuration
Application
Operating System
Hypervisor
Server Application
Runtime Container
Operating System
Backend Systems
Separation Properties
Safety Properties
Sep.Prop.
Spec.-basedTestingofSafetyProperties
TestServerApp.
IntegrationTest
Observation:
Both methods have their unique advantages
Recommendation:
Use a combination of verification and testing
Our Vision:
An integrated approach for test and verification
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 28
Isabelle tools on top of Isabelle (Add-on) HOL-TestGen
Implementing our vision in Isabelle: HOL-TestGen
An interactive model-based test tool
built upon the theorem prover Isabelle/HOL
specification language: HOL
unique combination of test and proof
verification environment
user controllable test-hypotheses
verified transformations
supports the complete MBT workflow
basis for domain-specific extensions
successfully used in large case-studies
freely available at:
http://www.brucker.ch/projects/hol-testgen/
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 29
Isabelle tools on top of Isabelle (Add-on) HOL-TestGen
The HOL-TestGen architecture
Execution Environment
HOL-TestGen
Isabelle/HOL
Specification
Test Generation
Test SpecificationSystem Specification
Verification and Transformation
Test Executable
System under
Test
Test Case Generation
Test Data Generation
Test Script (incl. Test
Oracle) Generation
Inductive
Verification
Verified Model
Transformation
Test Harness
Generated Test Script
and Test Oracle
Test Adapter
Scheduler
Control
Scheduler
Mapping
Seamless combination of
testing and verification
Black-box vs. white-box:
Specification-based black-box test as default
White-box and Grey-box also possible
Unit vs. sequence testing
Unit testing straight forwards
Sequence testing via monadic construction
Coverage:
Path Coverage (on the specification) as default
Scalability:
Verified test transformations can increase testability
by several orders of magnitude
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 30
Isabelle tools on top of Isabelle (Add-on) HOL-TestGen
Excursus: test hypothesis – the difference between test and proof
Idea: We introduce formal test hypothesis “on the fly”
Technically, test hypothesis are marked using the following predicate:
THYP : bool ⇒bool
THYP(x) ≡x
Two test hypotheses are common:
Regularity hypothesis: captures infinite data structures (splits), e.g., for lists
x = []
·
·
·
P a
x = [a]
·
·
·
P a b h
x = [a, b]
·
·
·
P THYP ∀x.k < size x −→ P x
P
Uniformity hypothesis: captures test data selection
“Once a system under test behaves correct for one test case, it behaves correct for all test cases”
n) [[ C1 ?x; ...; Cm ?x]] =⇒TS ?x
n+1) THYP((∃ x. C1 x ... Cm x −→TS x) −→(∀ x. C1 x ... Cm x −→TS x))
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 31
Isabelle tools on top of Isabelle (Add-on) HOL-TestGen
Test case generation: an example
theory TestPrimRec
imports Main
begin
primrec
x mem [] = False
x mem (y#S) = if y = x
then True
else x mem S
test_spec:
"x mem S =⇒prog x S"
apply(gen_testcase)
Result:
1. prog ?x1 [?x1]
2. prog ?x2 [?x2,?b2]
3. ?a3=?x3 =⇒prog ?x3 [?a3,?x3]
4. THYP(∃ x.prog x [x] −→prog x [x]
...
7. THYP(∀ S. 3 ≤size S −→x mem S −→prog x S)
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 32
Isabelle tools on top of Isabelle (Add-on) HOL-TestGen
Use case: testing firewall policies
DMZ
Internet (extern)
Intranet (intern)
000000
00
111111
11
source destination protocol port action
Internet dmz udp 25 allow
Internet dmz tcp 80 allow
dmz intranet tcp 25 allow
intranet dmz tcp 993 allow
intranet Internet udp 80 allow
any any any any deny
Our goal: Show correctness of the
configuration and
implementation
of active network components
Today: firewalls are stateless packet filters
Our approach also supports (not considered in this talk):
network address translation (NAT)
port translation, port forwarding
stateful firewalls
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 33
Isabelle tools on top of Isabelle (Add-on) HOL-TestGen
HOL model of a firewall policy
A firewall makes a decision based on single packets.
types (α,β) packet
= id ×(α::adr) src ×(α::adr) dest ×βcontent
Different address and content representations are possible.
A policy is a mapping from packets to decisions (allow, deny, . . . ):
types α→β= α βdecision
types (α,β) Policy = (α,β) packet →unit
Remark: for policies with network address translation:
types (α,β) NAT_Policy = (α,β) packet →(α,β) packet set
Policy combinators allow for defining policies:
definition
allow_all_from :: (α::adr) net ⇒(α,β) Policy where
allow_all_from src_net = {pa. src pa src_net} AU
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 34
Isabelle tools on top of Isabelle (Add-on) HOL-TestGen
The policy
source destination protocol port action
Internet dmz udp 25 allow
Internet dmz tcp 80 allow
dmz intranet tcp 25 allow
intranet dmz tcp 993 allow
intranet Internet udp 80 allow
any any any any deny
definition TestPolicy where
TestPolicy = allow_port udp 25 internet dmz ⊕
allow_port tcp 80 internet dmz ⊕
allow_port tcp 25 dmz intranet ⊕
allow_port tcp 993 intranet dmz ⊕
allow_port udp 80 intranet internet ⊕
DU
where DU is the policy that denies all traffic
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 35
Isabelle tools on top of Isabelle (Add-on) HOL-TestGen
Testing stateless firewalls
The test specification:
test_spec test: “P x =⇒FUT x = Policy x’’
FUT: Placeholder for Firewall Under Test
Predicate P restricts packets we are interested in, e.g.,
wellformed packets which cross some network boundary
Core test case generation algorithm:
compute conjunctive-normal form
find satisfying assignments for each clause (partition)
Generates test data like (simplified):
FUT(1,((8,13,12,10),6,tcp),((172,168,2,1),80,tcp),data)= (deny()
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 36
Isabelle tools on top of Isabelle (Add-on) HOL-TestGen
Problems with the direct approach
The direct approach does not scale:
R1 R2 R3 R4
Networks 3 3 4 3
Rules 12 9 13 13
TC Generation Time (sec) 26382 187 59364 1388
Test Cases 1368 264 1544 470
Reason:
Large cascades of case distinctions over input and output
=⇒ However, many of these case splits are redundant
Many combinations due to subnets
=⇒ Pre-partitioning of test space according to subnets
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 37
Isabelle tools on top of Isabelle (Add-on) HOL-TestGen
Model transformations for TCG
Idea is fundamental to model-based test case generation. E.g.:
if x < −10 then if x < 0 then P else Q else Q
if x < −10 then P else Q
lead to different test cases
The following two policies produce a different set of test cases:
AllowAll dmz internet ⊕ DenyPort dmz internet 21 ⊕ DU
AllowAll dmz internet ⊕ DU
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 38
Isabelle tools on top of Isabelle (Add-on) HOL-TestGen
A typical transformation
Remove all rules
allowing a port between two networks,
if a former rule already denies all the rules between these two networks
fun removeShadowRules2::
where
removeShadowRules2 ((AllowPortFromTo x y p)#z) =
if (DenyAllFromTo x y) ∈ (set z)
then removeShadowRules2 z
else (AllowPortFromTo x y p)#(removeShadowRules2 z)
| removeShadowRules2 (x#y) = x#(removeShadowRules2 y)
| removeShadowRules2 [] = []
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 39
Isabelle tools on top of Isabelle (Add-on) HOL-TestGen
Correctness of the normalisation
Correctness
of the normalization must hold for arbitrary input policies, satisfying certain preconditions
As HOL-TestGen is built upon the theorem prover Isabelle/HOL, we can prove formally the
correctness of such normalisations:
theorem C_eq_normalize:
assumes member DenyAll p
assumes allNetsDistinct p
shows C (list2policy (normalize p)) = C p
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 40
Isabelle tools on top of Isabelle (Add-on) HOL-TestGen
Empirical results
R1 R2 R3 R4
Not Normalized Networks 3 3 4 3
Rules 12 9 13 13
TC Generation Time (sec) 26382 187 59364 1388
Test Cases 1368 264 1544 470
Normalized Rules 14 14 24 26
Normalization (sec) 0.6 0.4 1.1 0.8
TC Generation Time (sec) 0.9 0.6 1.2 0.7
Test Cases 20 20 34 22
The normalization of policies decreases
the number of test cases and
the required test case generation time
by several orders of magnitude.
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 41
Outline
1 Motivation
2 Isabelle tools on top of Isabelle (Add-on)
HOL-OCL 1.x
HOL-OCL 2.x
HOL-TestGen
3 Conclusion
Conclusion
Conclusion
Modern interactive theorem provers can be used as
frameworks for building formal methods tools.
If you “prototype” formal methods tools, consider
to reuse the infrastructure of your theorem prover of choice
Isabelle provides a lot of features:
defining nice syntax for DSLs
defining new top-level commands
developing own tactics
generate code
. . .
There is another nice example: attend the next talk by Sebastian!
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 43
Thank you for your attention!
Any questions or remarks?
Conclusion
Related Publications I
Achim D. Brucker, Lukas Brügger, Paul Kearney, and Burkhart Wolff.
Verified firewall policy transformations for test-case generation.
In Third International Conference on Software Testing, Verification, and Validation (ICST), pages 345–354. IEEE Computer Society, 2010.
http://www.brucker.ch/bibliography/abstract/brucker.ea-firewall-2010.
Achim D. Brucker, Lukas Brügger, and Burkhart Wolff.
HOL-TestGen/FW: An environment for specification-based firewall conformance testing.
In Zhiming Liu, Jim Woodcock, and Huibiao Zhu, editors, International Colloquium on Theoretical Aspects of Computing (ICTAC), number 8049 in Lecture Notes in Computer Science,
pages 112–121. Springer-Verlag, 2013.
http://www.brucker.ch/bibliography/abstract/brucker.ea-hol-testgen-fw-2013.
Achim D. Brucker, Lukas Brügger, and Burkhart Wolff.
Formal firewall conformance testing: An application of test and proof techniques.
Software Testing, Verification & Reliability (STVR), 25(1):34–71, 2015.
http://www.brucker.ch/bibliography/abstract/brucker.ea-formal-fw-testing-2014.
Achim D. Brucker, Delphine Longuet, Frédéric Tuong, and Burkhart Wolff.
On the semantics of object-oriented data structures and path expressions.
In Jordi Cabot, Martin Gogolla, István Ráth, and Edward D. Willink, editors, Proceedings of the MoDELs 2013 OCL Workshop (OCL 2013), volume 1092 of CEUR Workshop Proceedings,
pages 23–32. ceur-ws.org, 2013.
http://www.brucker.ch/bibliography/abstract/brucker.ea-path-expressions-2013.
Achim D. Brucker, Frank Rittinger, and Burkhart Wolff.
hol-z 2.0: A proof environment for Z-specifications.
Journal of Universal Computer Science, 9(2):152–172, February 2003.
http://www.brucker.ch/bibliography/abstract/brucker.ea-hol-z-2003.
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 45
Conclusion
Related Publications II
Achim D. Brucker and Burkhart Wolff.
hol-ocl – A Formal Proof Environment for UML/OCL.
In José Fiadeiro and Paola Inverardi, editors, Fundamental Approaches to Software Engineering (FASE), number 4961 in Lecture Notes in Computer Science, pages 97–100.
Springer-Verlag, 2008.
http://www.brucker.ch/bibliography/abstract/brucker.ea-hol-ocl-2008.
Achim D. Brucker and Burkhart Wolff.
Extensible universes for object-oriented data models.
In Jan Vitek, editor, ECOOP 2008 – Object-Oriented Programming, number 5142 in Lecture Notes in Computer Science, pages 438–462. Springer-Verlag, 2008.
http://www.brucker.ch/bibliography/abstract/brucker.ea-extensible-2008.
Achim D. Brucker and Burkhart Wolff.
Semantics, calculi, and analysis for object-oriented specifications.
Acta Informatica, 46(4):255–284, July 2009.
ISSN 0001-5903.
http://www.brucker.ch/bibliography/abstract/brucker.ea-semantics-2009.
Achim D. Brucker and Burkhart Wolff.
On theorem prover-based testing.
Formal Aspects of Computing, 25(5):683–721, 2013.
ISSN 0934-5043.
http://www.brucker.ch/bibliography/abstract/brucker.ea-theorem-prover-2012.
Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 46

Isabelle: Not Only a Proof Assistant

  • 1.
    Isabelle: Not Onlya Proof Assistant Achim D. Brucker [email protected] http://www.brucker.ch/ joint work with Lukas Brügger, Delphine Longuet, Yakoub Nemouchi, Frédéric Tuong, Burkhart Wolff Proof Assistants and Related Tools - The PART Project Technical University of Denmark, Kgs. Lyngby, Denmark September 24, 2015
  • 2.
    Isabelle: Not Onlya Proof Assistant Abstract The Isabelle homepage describes Isabelle as “a generic proof assistant. It allows mathematical formulas to be expressed in a formal language and provides tools for proving those formulas in a logical calculus.” While this, without doubts, what most users of Isabelle are using Isabelle for, there is much more to discover: Isabelle is also a framework for building formal methods tools. In this talk, I will report on our experience in using Isabelle for building formal tools for high-level specifications languages (e.g., OCL, Z) as well as using Isabelle’s core engine for new applications domains such as generating test cases from high-level specifications.
  • 6.
    Motivation Achim D. BruckerIsabelle: Not Only a Proof Assistant September 24, 2015 4
  • 7.
    Motivation This is onlythe tip of the iceberg Isar jEdit auto define Isar command datatype packages own code generators Isabelle kernel tactic implementation generate codesledgehammer ML Interface Scala interface Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 5
  • 8.
    Outline 1 Motivation 2 Isabelletools on top of Isabelle (Add-on) HOL-OCL 1.x HOL-OCL 2.x HOL-TestGen 3 Conclusion
  • 9.
    Isabelle tools ontop of Isabelle (Add-on) HOL-OCL 1.x UML/OCL in a nutshell UML Visual modeling language Object-oriented development Industrial tool support OMG standard Many diagram types, e.g., activity diagrams class diagrams . . . OCL Textual extension of the UML Allows for annotating UML diagrams In the context of class–diagrams: invariants preconditions postconditions Account balance:Integer id:Integer getId():Integer getBalance():Integer deposit(a:Integer):Boolean withdraw(a:Integer):Boolean accounts 1..* context Account inv: 0 <= id context Account::deposit(a:Integer):Boolean pre: 0 < a post: balance = balance@pre+a and id = id@pre context Account inv: 0 <= id context Account::deposit(a:Integer):Boolean pre: 0 < a post: balance = balance@pre+a and id = id@pre Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 7
  • 10.
    Isabelle tools ontop of Isabelle (Add-on) HOL-OCL 1.x Developing formals tools for UML/OCL? Turning UML/OCL into a formal method 1 A formal semantics of object-oriented data models (UML) typed path expressions inheritance . . . 2 A formal semantics of object-oriented constraints (OCL) a logic reasoning over path expressions large libraries three-valued logic . . . 3 And of course, we want a tool (HOL-OCL) a formal, machine-checked semantics for OO specifications, an interactive proof environment for OO specifications. Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 8
  • 11.
    Isabelle tools ontop of Isabelle (Add-on) HOL-OCL 1.x Challenges (for a shallow embedding) Challenge 1: Can we find a injective, type preserving mapping of an object-oriented language (and datatypes) into HOL e:T −→ e :: T (including subtyping)? Challenge 2: Can we support verification in a modular way (i.e., no replay of proof scripts after extending specifications)? Challenge 3: Can we ensure consistency of our representation? Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 9
  • 12.
    Isabelle tools ontop of Isabelle (Add-on) HOL-OCL 1.x Representing class types The “extensible records” approach We assume a common superclass (O). A tag type guarantees uniquenessby (Otag := classO). Construct class type as tuple along inheritance hierarchy: O A s:String B b:Integer Advantages: it allows for extending class types (inheritance), subclasses are type instances of superclasses ⇒ it allows for modular proofs, i.e., a statement φ(x : : (α B)) proven for class B is still valid after extending class B. However, it has a major disadvantage: modular proofs are only supported for one extension per class Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 10
  • 13.
    Isabelle tools ontop of Isabelle (Add-on) HOL-OCL 1.x Representing class types The “extensible records” approach We assume a common superclass (O). A tag type guarantees uniquenessby (Otag := classO). Construct class type as tuple along inheritance hierarchy: B := O A s:String B b:Integer Advantages: it allows for extending class types (inheritance), subclasses are type instances of superclasses ⇒ it allows for modular proofs, i.e., a statement φ(x : : (α B)) proven for class B is still valid after extending class B. However, it has a major disadvantage: modular proofs are only supported for one extension per class Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 10
  • 14.
    Isabelle tools ontop of Isabelle (Add-on) HOL-OCL 1.x Representing class types The “extensible records” approach We assume a common superclass (O). A tag type guarantees uniquenessby (Otag := classO). Construct class type as tuple along inheritance hierarchy: B := (Otag ×oid) O A s:String B b:Integer Advantages: it allows for extending class types (inheritance), subclasses are type instances of superclasses ⇒ it allows for modular proofs, i.e., a statement φ(x : : (α B)) proven for class B is still valid after extending class B. However, it has a major disadvantage: modular proofs are only supported for one extension per class Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 10
  • 15.
    Isabelle tools ontop of Isabelle (Add-on) HOL-OCL 1.x Representing class types The “extensible records” approach We assume a common superclass (O). A tag type guarantees uniquenessby (Otag := classO). Construct class type as tuple along inheritance hierarchy: B := (Otag ×oid) × (Atag ×String) O A s:String B b:Integer Advantages: it allows for extending class types (inheritance), subclasses are type instances of superclasses ⇒ it allows for modular proofs, i.e., a statement φ(x : : (α B)) proven for class B is still valid after extending class B. However, it has a major disadvantage: modular proofs are only supported for one extension per class Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 10
  • 16.
    Isabelle tools ontop of Isabelle (Add-on) HOL-OCL 1.x Representing class types The “extensible records” approach We assume a common superclass (O). A tag type guarantees uniquenessby (Otag := classO). Construct class type as tuple along inheritance hierarchy: B := (Otag ×oid) × (Atag ×String) × (Btag ×Integer) O A s:String B b:Integer Advantages: it allows for extending class types (inheritance), subclasses are type instances of superclasses ⇒ it allows for modular proofs, i.e., a statement φ(x : : (α B)) proven for class B is still valid after extending class B. However, it has a major disadvantage: modular proofs are only supported for one extension per class Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 10
  • 17.
    Isabelle tools ontop of Isabelle (Add-on) HOL-OCL 1.x Representing class types The “extensible records” approach We assume a common superclass (O). A tag type guarantees uniquenessby (Otag := classO). Construct class type as tuple along inheritance hierarchy: α B := (Otag ×oid) × (Atag ×String) × (Btag ×Integer) × α O A s:String B b:Integer α Advantages: it allows for extending class types (inheritance), subclasses are type instances of superclasses ⇒ it allows for modular proofs, i.e., a statement φ(x : : (α B)) proven for class B is still valid after extending class B. However, it has a major disadvantage: modular proofs are only supported for one extension per class Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 10
  • 18.
    Isabelle tools ontop of Isabelle (Add-on) HOL-OCL 1.x Idea: a general universe type A universe type representing all classes of a class model supports modular proofs with arbitrary extensions provides a formalization of a extensible typed object store Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 11
  • 19.
    Isabelle tools ontop of Isabelle (Add-on) HOL-OCL 1.x An extensible object store O O αO U (αO) = O × αO ⊥ Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 12
  • 20.
    Isabelle tools ontop of Isabelle (Add-on) HOL-OCL 1.x An extensible object store O O αO U (αO) = O × αO ⊥ A Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 12
  • 21.
    Isabelle tools ontop of Isabelle (Add-on) HOL-OCL 1.x An extensible object store O O αO U (αO) = O × αO ⊥ A A βO αA U (αO) = O × αO ⊥ U (αA,βO) = O × (A × αA ⊥ + βO )⊥ Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 12
  • 22.
    Isabelle tools ontop of Isabelle (Add-on) HOL-OCL 1.x An extensible object store O O αO U (αO) = O × αO ⊥ A A βO αA U (αO) = O × αO ⊥ U (αA,βO) = O × (A × αA ⊥ + βO )⊥ B B βA αB U (αO) = O × αO ⊥ U (αA,βO) = O × (A × αA ⊥ + βO )⊥ U (αB ,βO,βA) = O × (A × (B × αB ⊥ + βA )⊥ + βO )⊥ Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 12
  • 23.
    Isabelle tools ontop of Isabelle (Add-on) HOL-OCL 1.x An extensible object store O O αO U (αO) = O × αO ⊥ A A βO αA U (αO) = O × αO ⊥ U (αA,βO) = O × (A × αA ⊥ + βO )⊥ B B βA αB U (αO) = O × αO ⊥ U (αA,βO) = O × (A × αA ⊥ + βO )⊥ U (αB ,βO,βA) = O × (A × (B × αB ⊥ + βA )⊥ + βO )⊥C C βA αC Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 12
  • 24.
    Isabelle tools ontop of Isabelle (Add-on) HOL-OCL 1.x An extensible object store O O αO U (αO) = O × αO ⊥ A A βO αA U (αO) = O × αO ⊥ U (αA,βO) = O × (A × αA ⊥ + βO )⊥ B B βA αB U (αO) = O × αO ⊥ U (αA,βO) = O × (A × αA ⊥ + βO )⊥ U (αB ,βO,βA) = O × (A × (B × αB ⊥ + βA )⊥ + βO )⊥C C βA αC U (αO) = O × αO ⊥ U (αA,βO) = O × (A × αA ⊥ + βO )⊥ U (αB ,βO,βA) = O × (A × (B × αB ⊥ + βA )⊥ + βO )⊥ U (αB ,αC ,βO,βA) = O × (A × (B × αB ⊥ + (C × αC ⊥ + βA ))⊥ + βO )⊥ Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 12
  • 25.
    Isabelle tools ontop of Isabelle (Add-on) HOL-OCL 1.x An extensible object store O O αO U (αO) = O × αO ⊥ A A βO αA U (αO) = O × αO ⊥ U (αA,βO) = O × (A × αA ⊥ + βO )⊥ B B βA αB U (αO) = O × αO ⊥ U (αA,βO) = O × (A × αA ⊥ + βO )⊥ U (αB ,βO,βA) = O × (A × (B × αB ⊥ + βA )⊥ + βO )⊥C C βA αC U (αO) = O × αO ⊥ U (αA,βO) = O × (A × αA ⊥ + βO )⊥ U (αB ,βO,βA) = O × (A × (B × αB ⊥ + βA )⊥ + βO )⊥ U (αB ,αC ,βO,βA) = O × (A × (B × αB ⊥ + (C × αC ⊥ + βA ))⊥ + βO )⊥ U3 (αB,αC,βO,βA) U2 (αB,βO,βA) U1 (αA,βO) U0 (αO) Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 12
  • 26.
    Isabelle tools ontop of Isabelle (Add-on) HOL-OCL 1.x Merging universes U : A Ua : A C Ub : A B D U : A B C D Non-conflicting Merges Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 13
  • 27.
    Isabelle tools ontop of Isabelle (Add-on) HOL-OCL 1.x Merging universes U : A Ua : A C Ub : A B D U : A B C D Non-conflicting Merges U : A Ua : A C Ub : A B U : A BC Conflicting Merges Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 13
  • 28.
    Isabelle tools ontop of Isabelle (Add-on) HOL-OCL 1.x Operations accessing the object store injections mkO o = Inl o with type αO O → U0 αO projections getO u = u with type U0 αO → αO O type casts A[O] = getO ◦ mkA with type αA A → (A × αA ⊥ + βO ) O O[A] = getA ◦ mkO with type (A × αA ⊥ + βO ) O → αA A . . . All definitions are generated automatically Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 14
  • 29.
    Isabelle tools ontop of Isabelle (Add-on) HOL-OCL 1.x “Checking” subtyping For each UML model, we have to show several properties: O A s:String B b:Integer subclasses are of the superclasses kind: isTypeB self isKindA self “re-casting”: isTypeB self self[A][B] = ⊥ ∧ isTypeB (self[A][B][A] ) monotonicity of invariants, . . . All rules are derived automatically Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 15
  • 30.
    Isabelle tools ontop of Isabelle (Add-on) HOL-OCL 1.x HOL-OCL HOL-OCL provides: a formal, machine-checked semantics for OO specifications, an interactive proof environment for OO specifications. HOL-OCL is integrated into a toolchain providing: extended well-formedness checking, proof-obligation generation, methodology support for UML/OCL, a transformation framework (including PO generation), code generators, support for SecureUML. HOL-OCL is publicly available: http://www.brucker.ch/projects/hol-ocl/. Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 16
  • 31.
    Isabelle tools ontop of Isabelle (Add-on) HOL-OCL 1.x The HOL-OCL architecture Standard ML (PolyML, sml/NJ) HOL-OCL Isabelle/HOL susml HOL-OCL User Interface (extended Proof General) Repository UML/OCL PO-Manager Encoder Code-Gen. WF-Checks Model-Trans. Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 17
  • 32.
    Isabelle tools ontop of Isabelle (Add-on) HOL-OCL 1.x The HOL-OCL user interface Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 18
  • 33.
    Isabelle tools ontop of Isabelle (Add-on) HOL-OCL 1.x The HOL-OCL high-level language The HOL-OCL proof language is an extension of Isabelle’s Isar language: importing UML/OCL: import_model "SimpleChair.zargo" "AbstractSimpleChair.ocl" include_only "AbstractSimpleChair" check well-formedness and generate proof obligations for refinement: analyze_consistency [data_refinement] "AbstractSimpleChair" starting a proof for a generated proof obligation: po "AbstractSimpleChair.findRole_enabled" generating code: generate_code "java" Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 19
  • 34.
    Isabelle tools ontop of Isabelle (Add-on) HOL-OCL 1.x The encoder The model encoder is the main interface between su4sml and the Isabelle based part of HOL-OCL. The encoder declarers HOL types for the classifiers of the model, encodes type-casts, attribute accessors, and dynamic type and kind tests implicitly declared in the imported data model, encodes the OCL specification, i.e., class invariants operation specifications and combines it with the core data model, and proves (automatically) methodology and analysis independent properties of the model. Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 20
  • 35.
    Isabelle tools ontop of Isabelle (Add-on) HOL-OCL 1.x Tactics (proof procedures) OCL, as logic, is quite different from HOL (e.g., three-valuedness) Major Isabelle proof procedures, like simp and auto, cannot handle OCL efficiently. HOL-OCL provides several UML/OCL specific proof procedures: embedding specific tactics (e.g., unfolding a certain level) a OCL specific context-rewriter a OCL specific tableaux-prover . . . These language specific variants increase the degree of proof for OCL. Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 21
  • 36.
    Isabelle tools ontop of Isabelle (Add-on) HOL-OCL 1.x Proof obligation generator A framework for proof obligation generation: Generates proof obligation in OCL plus minimal meta-language. Only minimal meta-language necessary: Validity: |= _, _ |= _ Meta level quantifiers: ∃_. _, ∃_. _ Meta level logical connectives: _ ∨ _, _ ∧ _, ¬_ Examples for proof obligations are: (semantical) model consistency Liskov’s substitution principle refinement conditions . . . Can be easily extended (at runtime). Builds, together with well-formedness checking, the basis for tool-supported methodologies. Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 22
  • 37.
    Outline 1 Motivation 2 Isabelletools on top of Isabelle (Add-on) HOL-OCL 1.x HOL-OCL 2.x HOL-TestGen 3 Conclusion
  • 38.
    Isabelle tools ontop of Isabelle (Add-on) HOL-OCL 2.x HOL-OCL 2.0 (Featherweight OCL) Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 24
  • 39.
    Outline 1 Motivation 2 Isabelletools on top of Isabelle (Add-on) HOL-OCL 1.x HOL-OCL 2.x HOL-TestGen 3 Conclusion
  • 40.
    Isabelle tools ontop of Isabelle (Add-on) HOL-TestGen How to ensure system correctness, security, and safety? (Inductive) Verification Testing Formal (mathematical) proof Can show absence of all failures relative to specification Specification of based on abstractions Requires expertise in Formal Methods In industry: only for highly critical systems (regulations, certification) Execution of test cases Can show failures on real system Only shows failures for the parts of the system Requires less skills in Formal Methods In industry: widely used (often > 40% of dev. effort) Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 26
  • 41.
    Isabelle tools ontop of Isabelle (Add-on) HOL-TestGen Is testing a “poor man’s verification?” Or: Why should I test if I did a verification and vice versa? “ Program testing can be used to show the presence of bugs, but never to show their absence! (Dijkstra) Assume you can choose between two aircraft for you next travel: Aircraft A: Fully formally verified Total number of flights: 0 Aircraft B: Fully tested Total number of flights: 1 000 Which aircraft would you take for your next trip? Which aircraft would Dijkstra take? Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 27
  • 42.
    Isabelle tools ontop of Isabelle (Add-on) HOL-TestGen What should we do? Vision: Use the Optimal Combination of Verification and Testing in an Integrated Approach Infrastructure&Configuration Application Operating System Hypervisor Server Application Runtime Container Operating System Backend Systems Observation: Both methods have their unique advantages Recommendation: Use a combination of verification and testing Our Vision: An integrated approach for test and verification Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 28
  • 43.
    Isabelle tools ontop of Isabelle (Add-on) HOL-TestGen What should we do? Vision: Use the Optimal Combination of Verification and Testing in an Integrated Approach Infrastructure&Configuration Application Operating System Hypervisor Server Application Runtime Container Operating System Backend Systems Separation Properties Safety Properties Observation: Both methods have their unique advantages Recommendation: Use a combination of verification and testing Our Vision: An integrated approach for test and verification Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 28
  • 44.
    Isabelle tools ontop of Isabelle (Add-on) HOL-TestGen What should we do? Vision: Use the Optimal Combination of Verification and Testing in an Integrated Approach Infrastructure&Configuration Application Operating System Hypervisor Server Application Runtime Container Operating System Backend Systems Separation Properties Safety Properties Sep.Prop. Spec.-basedTestingofSafetyProperties TestServerApp. IntegrationTest Observation: Both methods have their unique advantages Recommendation: Use a combination of verification and testing Our Vision: An integrated approach for test and verification Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 28
  • 45.
    Isabelle tools ontop of Isabelle (Add-on) HOL-TestGen Implementing our vision in Isabelle: HOL-TestGen An interactive model-based test tool built upon the theorem prover Isabelle/HOL specification language: HOL unique combination of test and proof verification environment user controllable test-hypotheses verified transformations supports the complete MBT workflow basis for domain-specific extensions successfully used in large case-studies freely available at: http://www.brucker.ch/projects/hol-testgen/ Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 29
  • 46.
    Isabelle tools ontop of Isabelle (Add-on) HOL-TestGen The HOL-TestGen architecture Execution Environment HOL-TestGen Isabelle/HOL Specification Test Generation Test SpecificationSystem Specification Verification and Transformation Test Executable System under Test Test Case Generation Test Data Generation Test Script (incl. Test Oracle) Generation Inductive Verification Verified Model Transformation Test Harness Generated Test Script and Test Oracle Test Adapter Scheduler Control Scheduler Mapping Seamless combination of testing and verification Black-box vs. white-box: Specification-based black-box test as default White-box and Grey-box also possible Unit vs. sequence testing Unit testing straight forwards Sequence testing via monadic construction Coverage: Path Coverage (on the specification) as default Scalability: Verified test transformations can increase testability by several orders of magnitude Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 30
  • 47.
    Isabelle tools ontop of Isabelle (Add-on) HOL-TestGen Excursus: test hypothesis – the difference between test and proof Idea: We introduce formal test hypothesis “on the fly” Technically, test hypothesis are marked using the following predicate: THYP : bool ⇒bool THYP(x) ≡x Two test hypotheses are common: Regularity hypothesis: captures infinite data structures (splits), e.g., for lists x = [] · · · P a x = [a] · · · P a b h x = [a, b] · · · P THYP ∀x.k < size x −→ P x P Uniformity hypothesis: captures test data selection “Once a system under test behaves correct for one test case, it behaves correct for all test cases” n) [[ C1 ?x; ...; Cm ?x]] =⇒TS ?x n+1) THYP((∃ x. C1 x ... Cm x −→TS x) −→(∀ x. C1 x ... Cm x −→TS x)) Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 31
  • 48.
    Isabelle tools ontop of Isabelle (Add-on) HOL-TestGen Test case generation: an example theory TestPrimRec imports Main begin primrec x mem [] = False x mem (y#S) = if y = x then True else x mem S test_spec: "x mem S =⇒prog x S" apply(gen_testcase) Result: 1. prog ?x1 [?x1] 2. prog ?x2 [?x2,?b2] 3. ?a3=?x3 =⇒prog ?x3 [?a3,?x3] 4. THYP(∃ x.prog x [x] −→prog x [x] ... 7. THYP(∀ S. 3 ≤size S −→x mem S −→prog x S) Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 32
  • 49.
    Isabelle tools ontop of Isabelle (Add-on) HOL-TestGen Use case: testing firewall policies DMZ Internet (extern) Intranet (intern) 000000 00 111111 11 source destination protocol port action Internet dmz udp 25 allow Internet dmz tcp 80 allow dmz intranet tcp 25 allow intranet dmz tcp 993 allow intranet Internet udp 80 allow any any any any deny Our goal: Show correctness of the configuration and implementation of active network components Today: firewalls are stateless packet filters Our approach also supports (not considered in this talk): network address translation (NAT) port translation, port forwarding stateful firewalls Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 33
  • 50.
    Isabelle tools ontop of Isabelle (Add-on) HOL-TestGen HOL model of a firewall policy A firewall makes a decision based on single packets. types (α,β) packet = id ×(α::adr) src ×(α::adr) dest ×βcontent Different address and content representations are possible. A policy is a mapping from packets to decisions (allow, deny, . . . ): types α→β= α βdecision types (α,β) Policy = (α,β) packet →unit Remark: for policies with network address translation: types (α,β) NAT_Policy = (α,β) packet →(α,β) packet set Policy combinators allow for defining policies: definition allow_all_from :: (α::adr) net ⇒(α,β) Policy where allow_all_from src_net = {pa. src pa src_net} AU Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 34
  • 51.
    Isabelle tools ontop of Isabelle (Add-on) HOL-TestGen The policy source destination protocol port action Internet dmz udp 25 allow Internet dmz tcp 80 allow dmz intranet tcp 25 allow intranet dmz tcp 993 allow intranet Internet udp 80 allow any any any any deny definition TestPolicy where TestPolicy = allow_port udp 25 internet dmz ⊕ allow_port tcp 80 internet dmz ⊕ allow_port tcp 25 dmz intranet ⊕ allow_port tcp 993 intranet dmz ⊕ allow_port udp 80 intranet internet ⊕ DU where DU is the policy that denies all traffic Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 35
  • 52.
    Isabelle tools ontop of Isabelle (Add-on) HOL-TestGen Testing stateless firewalls The test specification: test_spec test: “P x =⇒FUT x = Policy x’’ FUT: Placeholder for Firewall Under Test Predicate P restricts packets we are interested in, e.g., wellformed packets which cross some network boundary Core test case generation algorithm: compute conjunctive-normal form find satisfying assignments for each clause (partition) Generates test data like (simplified): FUT(1,((8,13,12,10),6,tcp),((172,168,2,1),80,tcp),data)= (deny() Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 36
  • 53.
    Isabelle tools ontop of Isabelle (Add-on) HOL-TestGen Problems with the direct approach The direct approach does not scale: R1 R2 R3 R4 Networks 3 3 4 3 Rules 12 9 13 13 TC Generation Time (sec) 26382 187 59364 1388 Test Cases 1368 264 1544 470 Reason: Large cascades of case distinctions over input and output =⇒ However, many of these case splits are redundant Many combinations due to subnets =⇒ Pre-partitioning of test space according to subnets Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 37
  • 54.
    Isabelle tools ontop of Isabelle (Add-on) HOL-TestGen Model transformations for TCG Idea is fundamental to model-based test case generation. E.g.: if x < −10 then if x < 0 then P else Q else Q if x < −10 then P else Q lead to different test cases The following two policies produce a different set of test cases: AllowAll dmz internet ⊕ DenyPort dmz internet 21 ⊕ DU AllowAll dmz internet ⊕ DU Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 38
  • 55.
    Isabelle tools ontop of Isabelle (Add-on) HOL-TestGen A typical transformation Remove all rules allowing a port between two networks, if a former rule already denies all the rules between these two networks fun removeShadowRules2:: where removeShadowRules2 ((AllowPortFromTo x y p)#z) = if (DenyAllFromTo x y) ∈ (set z) then removeShadowRules2 z else (AllowPortFromTo x y p)#(removeShadowRules2 z) | removeShadowRules2 (x#y) = x#(removeShadowRules2 y) | removeShadowRules2 [] = [] Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 39
  • 56.
    Isabelle tools ontop of Isabelle (Add-on) HOL-TestGen Correctness of the normalisation Correctness of the normalization must hold for arbitrary input policies, satisfying certain preconditions As HOL-TestGen is built upon the theorem prover Isabelle/HOL, we can prove formally the correctness of such normalisations: theorem C_eq_normalize: assumes member DenyAll p assumes allNetsDistinct p shows C (list2policy (normalize p)) = C p Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 40
  • 57.
    Isabelle tools ontop of Isabelle (Add-on) HOL-TestGen Empirical results R1 R2 R3 R4 Not Normalized Networks 3 3 4 3 Rules 12 9 13 13 TC Generation Time (sec) 26382 187 59364 1388 Test Cases 1368 264 1544 470 Normalized Rules 14 14 24 26 Normalization (sec) 0.6 0.4 1.1 0.8 TC Generation Time (sec) 0.9 0.6 1.2 0.7 Test Cases 20 20 34 22 The normalization of policies decreases the number of test cases and the required test case generation time by several orders of magnitude. Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 41
  • 58.
    Outline 1 Motivation 2 Isabelletools on top of Isabelle (Add-on) HOL-OCL 1.x HOL-OCL 2.x HOL-TestGen 3 Conclusion
  • 59.
    Conclusion Conclusion Modern interactive theoremprovers can be used as frameworks for building formal methods tools. If you “prototype” formal methods tools, consider to reuse the infrastructure of your theorem prover of choice Isabelle provides a lot of features: defining nice syntax for DSLs defining new top-level commands developing own tactics generate code . . . There is another nice example: attend the next talk by Sebastian! Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 43
  • 60.
    Thank you foryour attention! Any questions or remarks?
  • 61.
    Conclusion Related Publications I AchimD. Brucker, Lukas Brügger, Paul Kearney, and Burkhart Wolff. Verified firewall policy transformations for test-case generation. In Third International Conference on Software Testing, Verification, and Validation (ICST), pages 345–354. IEEE Computer Society, 2010. http://www.brucker.ch/bibliography/abstract/brucker.ea-firewall-2010. Achim D. Brucker, Lukas Brügger, and Burkhart Wolff. HOL-TestGen/FW: An environment for specification-based firewall conformance testing. In Zhiming Liu, Jim Woodcock, and Huibiao Zhu, editors, International Colloquium on Theoretical Aspects of Computing (ICTAC), number 8049 in Lecture Notes in Computer Science, pages 112–121. Springer-Verlag, 2013. http://www.brucker.ch/bibliography/abstract/brucker.ea-hol-testgen-fw-2013. Achim D. Brucker, Lukas Brügger, and Burkhart Wolff. Formal firewall conformance testing: An application of test and proof techniques. Software Testing, Verification & Reliability (STVR), 25(1):34–71, 2015. http://www.brucker.ch/bibliography/abstract/brucker.ea-formal-fw-testing-2014. Achim D. Brucker, Delphine Longuet, Frédéric Tuong, and Burkhart Wolff. On the semantics of object-oriented data structures and path expressions. In Jordi Cabot, Martin Gogolla, István Ráth, and Edward D. Willink, editors, Proceedings of the MoDELs 2013 OCL Workshop (OCL 2013), volume 1092 of CEUR Workshop Proceedings, pages 23–32. ceur-ws.org, 2013. http://www.brucker.ch/bibliography/abstract/brucker.ea-path-expressions-2013. Achim D. Brucker, Frank Rittinger, and Burkhart Wolff. hol-z 2.0: A proof environment for Z-specifications. Journal of Universal Computer Science, 9(2):152–172, February 2003. http://www.brucker.ch/bibliography/abstract/brucker.ea-hol-z-2003. Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 45
  • 62.
    Conclusion Related Publications II AchimD. Brucker and Burkhart Wolff. hol-ocl – A Formal Proof Environment for UML/OCL. In José Fiadeiro and Paola Inverardi, editors, Fundamental Approaches to Software Engineering (FASE), number 4961 in Lecture Notes in Computer Science, pages 97–100. Springer-Verlag, 2008. http://www.brucker.ch/bibliography/abstract/brucker.ea-hol-ocl-2008. Achim D. Brucker and Burkhart Wolff. Extensible universes for object-oriented data models. In Jan Vitek, editor, ECOOP 2008 – Object-Oriented Programming, number 5142 in Lecture Notes in Computer Science, pages 438–462. Springer-Verlag, 2008. http://www.brucker.ch/bibliography/abstract/brucker.ea-extensible-2008. Achim D. Brucker and Burkhart Wolff. Semantics, calculi, and analysis for object-oriented specifications. Acta Informatica, 46(4):255–284, July 2009. ISSN 0001-5903. http://www.brucker.ch/bibliography/abstract/brucker.ea-semantics-2009. Achim D. Brucker and Burkhart Wolff. On theorem prover-based testing. Formal Aspects of Computing, 25(5):683–721, 2013. ISSN 0934-5043. http://www.brucker.ch/bibliography/abstract/brucker.ea-theorem-prover-2012. Achim D. Brucker Isabelle: Not Only a Proof Assistant September 24, 2015 46