Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Contracts

A foreign function may carry a contract: requires and ensures clauses written in the function’s own language. A contract does two jobs, and only one of them is fic’s.

  • The model assumes it. --emit=xta turns a contracted function that a protection domain calls into a UPPAAL function ffi_<name>: each requires is an assert at every call (never a guard), and the deterministic ensures is the value the call returns. An ensures that only bounds the return value to an interval, comparing it with constants under && and || (\result == 0 || \result == 1, 0 <= \result <= 3), makes the value a choice: in an event, the edge that fires it selects any value the clause allows. That is how a driver’s input enters the model. A call returning a struct takes the fields its ensures fix (\result.origin == origin), and keeps the rest.
  • A verifier proves it against the code: Frama-C with -wp for C, pancake2viper for Pancake. fire verify runs them; see the fire verify chapter of the manual for the tools and their setup.

So the model is only as sound as the contracts, and fic never derives a clause itself: it translates what the annotation states.

The subset fic reads

Both notations are lifted to one neutral form, so one subset applies: integer and boolean literals, parameters, .fis constants, the return value and a field of it (\result.f), the parameter’s value on entry, + - * / %, the comparisons, == and !=, ! && ||, and c ? a : b.

C (ACSL)Pancake
Notation/*@ ... */ before the functionannotation lines inside the function body
Preconditionsrequiresrequires
Postconditionsensuresensures
Return value\resultretval
Value on entry\old(x)old(x)
Purityassigns \nothing;derived from the body
/*@ requires 0 <= r && r < ROUNDS;
  @ ensures \result == r + 1;
  @ assigns \nothing;
  @*/
int64_t tally(int64_t r) { return r + 1; }

A constant declared in the .fis may be named in a clause (ROUNDS); the generated header gives each language its value.

Anything outside the subset is rejected by its name, so a contract never seems read when it was not:

error: cq/ping.fi: ACSL contract error in "pingpong.c": function `tally`:
`ensures \forall integer k; ...` uses the quantifier `\forall`, which is
outside fic's contract subset (arithmetic, comparisons, `! && ||`, `? :`,
`\old`, `\result`, parameters)

In ACSL, quantifiers, memory predicates (\valid, *p), implication, bit operators and C casts are outside it; in Pancake, so are permissions, quantifiers, the heap, implication, calls, bit operators and shifts. Clauses the subset does not cover at all are the verifier’s and are not an error: in ACSL named behaviours, assumes, terminates and exits, and in Pancake any annotation other than requires and ensures (a trusted, an invariant).

What the model needs of a call

For a Pancake function the model checks each call site, because it must produce a value the automaton can use:

  • A call whose value is used, rather than made as a bare statement, needs a deterministic ensures retval == E. Without one, --check reports that the function has “no deterministic ensures retval == … clause”.
  • A call in a guard must also be pure, because the generated C may evaluate a guard more than once. A Pancake function is impure if it calls a foreign function, stores to memory, reads shared memory, raises, or writes a global, directly or through a callee.

An ACSL contract is lifted and rendered the same way. assigns \nothing; marks a C function pure, and a missing assigns clause counts as impure, since ACSL’s default permits every effect; the guard check currently runs for Pancake contracts only.

What fire verify proves

fire verify runs the contract prover first (Frama-C WP for a C import, pancake2viper for Pancake), then verifyta on the model that assumes the contracts. Both must pass: a model check over an unproved contract proves nothing about the code behind it.