Low-Level Code and High-Level Theorems Sascha Böhme Technische Universität München, Germany Joint work with Eyad Alkassar 1 , Ernie Cohen 2 , Kurt Mehlhorn 3 and Christine Rizkallah 3 1 Universität des Saarlandes, Germany 2 European Microsoft Innovation Center, Aachen, Germany 3 Max-Planck-Institut für Informatik, Saarbrücken, Germany 1
C code 2
program C code verification 2
theorem program C code verification 2
interactive theorem theorem prover program C code verification 2
interactive theorem theorem prover program C code verification 2
Isabelle/HOL interactive theorem theorem prover program C code verification VCC 2
VCC: ◮ assertional verifier for full C ◮ first-order logic as specification language ◮ fully automatic thanks to Boogie and Z3 ◮ specification by code annotations ◮ function contracts, object invariants ◮ ghost code, ghost functions 3
VCC: ◮ assertional verifier for full C ◮ first-order logic as specification language ◮ fully automatic thanks to Boogie and Z3 ◮ specification by code annotations ◮ function contracts, object invariants ◮ ghost code, ghost functions Isabelle/HOL: ◮ interactive theorem prover for higher-order logic ◮ rich set of formalized mathematics ◮ various automated provers 3
Isabelle/HOL interactive theorem theorem prover program C code verification VCC 4
Isabelle/HOL interactive theorem theorem prover LEDA graph algorithms program C code verification VCC 4
LEDA graph algorithms 4
5
Programmers 5
Social programmers Graph 5
Pair programming Matching 5
Optimal pair programming Maximum cardinality matching 5
Definitions Matching: ◮ a graph ◮ no edge is incident to another edge 6
Definitions Matching: ◮ a graph ◮ no edge is incident to another edge Odd-set cover: ◮ labeling of nodes ◮ every edge is incident to a node labeled 1 or connects two nodes labeled i (with i ≥ 2) 6
Optimal pair programming Maximum cardinality matching 7
Certificate Odd-set cover 1 0 1 0 2 2 1 2 0 7
Theorem The maximum cardinality of a graph matching is � ⌊ n i / 2 ⌋ n 1 + i ≥ 2 where n i is the number of nodes labeled i by an odd-set cover. 8
LEDA graph algorithms 9
Isabelle/HOL interactive theorem theorem prover LEDA graph algorithms program C code verification VCC 9
LEDA graph algorithms program C code verification VCC 9
Maximum Cardinality Matching Checker C Code 10
Maximum Cardinality Matching Checker C Code Given: ◮ graph G ◮ graph M (maximum cardinality matching) ◮ labeling OSC (odd-set cover) 10
Maximum Cardinality Matching Checker C Code Given: ◮ graph G ◮ graph M (maximum cardinality matching) ◮ labeling OSC (odd-set cover) Check: ◮ M is a matching ◮ M is a subset of G ◮ OSC is an odd-set cover of G ◮ M is maximal wrt. G and OSC 10
Maximum Cardinality Matching Checker C Code Given: ◮ graph G ◮ graph M (maximum cardinality matching) ◮ labeling OSC (odd-set cover) Check: ◮ M is a matching ◮ M is a subset of G ◮ OSC is an odd-set cover of G ◮ M is maximal wrt. G and OSC Implementation: ◮ straightforward 10
Maximum Cardinality Matching Checker Specification struct graph { edge * es; unsigned n_edges, n_nodes; } 11
Maximum Cardinality Matching Checker Specification struct graph { edge * es; unsigned n_edges, n_nodes; invariant( ∀ (unsigned e; e < n_edges − → es[e].s < n_nodes ∧ es[e].t < n_nodes ∧ es[e].s � = es[e].t)) } 11
Maximum Cardinality Matching Checker Specification struct graph { edge * es; unsigned n_edges, n_nodes; invariant( ∀ (unsigned e; e < n_edges − → es[e].s < n_nodes ∧ es[e].t < n_nodes ∧ es[e].s � = es[e].t)) } spec(bool spec_is_osc(graph * G, unsigned * osc) returns(... ∧ ∀ (unsigned e; e < G->n_edges − → osc[G->es[e].s] = 1 ∨ osc[G->es[e].t] = 1 ∨ (osc[G->es[e].t] = osc[G->es[e].s] ∧ osc[G->es[e].t] > 1)));) 11
What is proved? check(G, M, osc) = true ← → |M| = n 1 + � i ≥ 2 ⌊ n i / 2 ⌋ 12
What is proved? check(G, M, osc) = true ← → |M| = n 1 + � i ≥ 2 ⌊ n i / 2 ⌋ What is missing? |M| = n 1 + � i ≥ 2 ⌊ n i / 2 ⌋ − → ( ∀ M’. is_matching(M’) ∧ is_subset(G,M’) − → |M’| ≤ |M|) 12
What is proved? check(G, M, osc) = true ← → |M| = n 1 + � i ≥ 2 ⌊ n i / 2 ⌋ What is missing? |M| = n 1 + � i ≥ 2 ⌊ n i / 2 ⌋ − → ( ∀ M’. is_matching(M’) ∧ is_subset(G,M’) − → |M’| ≤ |M|) VCC: ◮ good at low-level code verification ◮ not much support for high-level proofs 12
What is proved? check(G, M, osc) = true ← → |M| = n 1 + � i ≥ 2 ⌊ n i / 2 ⌋ What is missing? |M| = n 1 + � i ≥ 2 ⌊ n i / 2 ⌋ − → ( ∀ M’. is_matching(M’) ∧ is_subset(G,M’) − → |M’| ≤ |M|) VCC: ◮ good at low-level code verification ◮ not much support for high-level proofs Requires abstraction! 12
LEDA graph algorithms program C code verification VCC 13
Isabelle/HOL interactive theorem theorem prover LEDA graph algorithms program C code verification VCC 13
Isabelle/HOL interactive theorem theorem prover program C code verification VCC 13
14
Isabelle/HOL VCC 14
Isabelle/HOL VCC concrete assert(p(x)); property 14
Isabelle/HOL VCC abstract spec(bool P(X) returns(...);) property concrete assert(p(x)); property 14
Isabelle/HOL VCC abstract spec(bool P(X) returns(...);) property spec(void P_equivalence(x) ensures(p(x) ⇐ ⇒ P(abs(x)));) concrete assert(p(x)); property 14
Isabelle/HOL VCC abstract spec(bool P(X) returns(...);) property spec(void P_holds(X) ensures(P(X));) spec(void P_equivalence(x) ensures(p(x) ⇐ ⇒ P(abs(x)));) concrete assert(p(x)); property 14
Isabelle/HOL formal definition P where “P(X) = . . . ” theorem P_holds: “P(X)” � proof � proof VCC abstract spec(bool P(X) returns(...);) property spec(void P_holds(X) ensures(P(X));) spec(void P_equivalence(x) ensures(p(x) ⇐ ⇒ P(abs(x)));) concrete assert(p(x)); property 14
Maximum Cardinality Matching Checker VCC 15
Maximum Cardinality Matching Checker VCC struct abs_graph { abs_edge es[mathint]; mathint n_edges, n_nodes; }; 15
Maximum Cardinality Matching Checker VCC struct abs_graph { abs_edge es[mathint]; mathint n_edges, n_nodes; }; spec(abs_graph abs_g(graph * G) ensures(...);) 15
Maximum Cardinality Matching Checker VCC struct abs_graph { abs_edge es[mathint]; mathint n_edges, n_nodes; }; spec(abs_graph abs_g(graph * G) ensures(...);) spec(bool abs_is_osc(abs_graph G, abs_fun osc) ensures(...);) 15
Maximum Cardinality Matching Checker VCC struct abs_graph { abs_edge es[mathint]; mathint n_edges, n_nodes; }; spec(abs_graph abs_g(graph * G) ensures(...);) spec(bool abs_is_osc(abs_graph G, abs_fun osc) ensures(...);) void is_osc_equivalence(graph * G, unsigned * osc) ensures( spec_is_osc(G, osc) ⇐ ⇒ abs_is_osc(abs_g(G), abs_f(osc))); 15
Maximum Cardinality Matching Checker Isabelle/HOL 16
Maximum Cardinality Matching Checker Isabelle/HOL record abs_graph = es :: int ⇒ abs_edge n_edges, n_nodes :: int 16
Maximum Cardinality Matching Checker Isabelle/HOL record abs_graph = es :: int ⇒ abs_edge n_edges, n_nodes :: int definition abs_is_osc where “abs_is_osc G osc = (. . . ∧ ( ∀ e. 0 ≤ e ∧ e < n_edges G − → osc (s (es G e)) = 1 ∨ osc (t (es G e)) = 1 ∨ (osc (t (es G e)) = osc (s (es G e)) ∧ osc (t (es G e)) > 1)))” 16
Maximum Cardinality Matching Checker Isabelle/HOL record abs_graph = es :: int ⇒ abs_edge n_edges, n_nodes :: int definition abs_is_osc where “abs_is_osc G osc = (. . . ∧ ( ∀ e. 0 ≤ e ∧ e < n_edges G − → osc (s (es G e)) = 1 ∨ osc (t (es G e)) = 1 ∨ (osc (t (es G e)) = osc (s (es G e)) ∧ osc (t (es G e)) > 1)))” theorem “|M| = n 1 + � i ≥ 2 ⌊ n i / 2 ⌋ − → ( ∀ M’. is_matching(M’) ∧ is_subset(G,M’) − → |M’| ≤ |M|)” � proof � 16
Combination of VCC and Isabelle/HOL ◮ combines the best of both worlds ◮ low-level code verification with VCC ◮ high-level mathematical reasoning with Isabelle/HOL ◮ sound combination ◮ clean separation of concepts 17
Isabelle/HOL interactive theorem theorem prover program C code verification VCC 18
Isabelle/HOL interactive theorem theorem prover LEDA graph algorithms program C code verification VCC 18
Recommend
More recommend