Introduction to formal verification

Introduction to formal verification

Frédéric Herbreteau, Bordeaux INP/LaBRI (frederic.herbreteau@bordeaux-inp.fr)

Objective

  • Use model-checking to assess the correctness of a system
    • from a model $M$: a set of runs given as a transition system
    • and a specification $\varphi$ \(M \models \varphi\)
  • The specification $\varphi$ shall specify which runs are correct and which are not
  • A dedicated algorithm is then used to decide whether:
    • all runs of $M$ satisfy $\varphi$, in other words $M \models \varphi$
    • or at least one run of $M$ falsifies $\varphi$, i.e. $M \not\models \varphi$

What is a specification?

  • Property of the runs of a system: which runs are correct and which are not?
  • Must have a clear and well-defined semantics

Example: mutual exclusion

”$\textcolor{blue}{P_1}$ and $\textcolor{red}{P_2}$ do not access the critical section simultaneously”

Good run Bad run

Formalising specifications

  • $AP$ = set of atomic propositions on states (labels) $\to$ what we observe
  • $\Sigma = 2^{AP}$ is the set of all sets of atomic propositions
  • $\Sigma^*$ and $\Sigma^\omega$ are the sets finite and infinite sequences over $\Sigma$
  • A property $P$ is any subset of infinite traces from $\Sigma^\omega$

Example: mutual exclusion (cf. previous slide)

  • $AP$?
  • What is $\Sigma$?
  • Give some traces from $\Sigma^*$? From $\Sigma^\omega$?
  • Express “$\textcolor{blue}{P_1}$ and $\textcolor{red}{P_2}$ do not access the critical section simultaneously”

Invariance properties

Definition: an property $P$ is an invariance property if there exists a boolean formula $\varphi$ on $AP$ that holds in every state of the model \(P = \{ A_0 A_1 A_2 \cdots \, | \, A_i \models \varphi \text{ for every } i \ge 0 \}\)

  • Properties that involve only one state (not several states on a run)
  • Must hold in every state of the model

Example:

What is $\varphi$ in the two situations below?

  • mutual exclusion: no state with both $\textcolor{blue}{cs_1}$ and $\textcolor{red}{cs_2}$
  • domain: the value of $x$ is always non-negative

Preservation of invariance properties

Assume an invariance property $P$, and two sets of infinite traces such that:

\[T_1 \subseteq T_2\]
  • if $T_1 \models P$, what can we say of $T_2$?
  • if $T_1 \not\models P$, what can we of $T_2$?
  • if $T_2 \models P$, what can we say of $T_1$?
  • if $T_2 \not\models P$, what can we say of $T_1$?

Deadlocks

Definition: A deadlock state is a state with no outgoing transition

  • deadlock states are obviously bad on actual systems
  • they are also bad for formal verification
    • deadlocks may lead to finite runs which violate a property
    • whereas verification algorithms only consider infinite runs

Example:

  • Process 1: holds Lock A -> waits for Lock B
  • Process 2: holds Lock B -> waits for Lock A

Specification of invariance properties and deadlocks in TLA+

  • Invariant property specification and verification:
Mutex == ~(cs1 /\ cs2)    (* in .tla file *)

INVARIANT Mutex           \* in .cfg file
  • Deadlock detection:
CHECK_DEADLOCK TRUE       \* in .cfg file