Process Calculus
Behavior expressions are the core of SPL. They describe what an agent does, as algebraic terms over actions (calls of transitions) and equation names. They appear on the right of the equations in an agent's process { } block and in pattern signatures.
For each construct, this page gives its meaning, how saple analyze treats it today, an example and the mistakes to avoid. How SAPLE explores a process ties them together.
Notation#
A model has a state: the values of its attributes. We write P —a→ P' for “in the current state, P can perform the action a and then behaves as P'”. An action is a call of a transition: it can happen only when the transition's guard: holds, and happening runs its effect:, which gives the next state. A process with no —a→ step has stopped; the terminals say how.
Terminals#
| Term | Meaning | What saple analyze does when a path reaches it |
|---|---|---|
done | Successful termination | Ends the path, then checks the patterns against the actions the walk executed |
0 | Deadlock: the process is stuck | Ends the path; nothing is reported |
Bottom, unexplored | Unknown continuation: the model does not say what follows | Ends the path; what would follow is not analysed |
Bottom(via=R) | Unknown continuation, reached by a jump through register R | Same as Bottom |
None of them has a next step. They differ in what the end of the path means.
done#
done is successful termination: the process has finished its work.
In SAPLE. The concrete walk (see below) ends the path at done and checks the model's patterns against the actions it executed on that path. This end-of-path check runs only at done and where a * loop may stop, not at the other terminals. In a pattern signature, done closes the signature.
0 (deadlock)#
0 is deadlock: the process is stuck and never acts again. Unlike done, it does not count as finishing. Use it for a branch that cannot go on.
In SAPLE. A path that reaches 0 ends silently. Properties are checked after every action, so the actions before 0 are checked as on any other path, but reaching 0 is not itself reported: SAPLE has no built-in deadlock check. A path also ends silently when its next action is disabled (the transition's guard is false). Before exploring, SAPLE rewrites 0 . P to 0 and drops 0 alternatives from a choice (P + 0 becomes P), unless --pure-substrate is given.
To make a stuck state visible, record it in the state just before 0 and state a property about it. Here a client takes a lock and, without releasing it, tries to take it again:
schema Lock {
attributes {
held : Bool = false ;
blocked : Bool = false ;
}
}
transition acquire() { guard: held == false ; effect: held := true ; }
transition release() { guard: held == true ; effect: held := false ; }
transition block() { guard: held == true ; effect: blocked := true ; }
agent Client() {
attributes { }
process {
First = acquire() . Second ;
Second = [held == false] acquire() . release() . done
+ [held == true] block() . 0 ;
}
}
system Demo {
schema: Lock ;
agents { Client() ; }
properties {
neverBlocked : blocked == false ;
}
}saple analyze lock.spl 1 finding(s):
1. [PROPERTY] HIGH — Property 'neverBlocked' violated
Property: neverBlocked
Trace: acquire → block
Witness: blocked=Bool(true), held=Bool(true)With [held == true] 0 in place of [held == true] block() . 0, the same path ends at 0 and the report is No vulnerabilities detected.
Bottom and unexplored#
Bottom (⊥ in the literature) marks a continuation the model knows nothing about. It is neither success nor deadlock: it is missing information. unexplored is another spelling of the same term. The AArch64 front end writes it for the arm of a conditional branch that the recorded run did not take (see branch).
In SAPLE. The path ends at Bottom, but it is not dropped: properties are checked after each of its actions, and pattern matching uses its actions like those of any other path. What would follow Bottom is not analysed, so a report without findings says nothing about it. The concrete walk does not run its end-of-path pattern check at Bottom.
Bottom. Bottom . P parses, but the two stages disagree on it: the concrete walk stops at Bottom, while pattern matching goes on into P. unexplored followed by ( is an action named unexplored, not the terminal.
Bottom(via=R)#
Bottom(via=R) is Bottom with a note attached: control continues at an address held in register R (an indirect jump) that the model does not resolve.
In SAPLE. The parser keeps the register name, but nothing uses it yet: every stage treats Bottom(via=R) exactly as Bottom. Neither documented front end emits it. The only accepted form is via= followed by a name: Bottom(via=) and Bottom(reg=X16) are parse errors.
Prefix: a . P#
Perform the action a, then behave as P.
Meaning. a . P —a→ P, when the guard of a's transition holds in the current state. The effect of a gives the next state. Prefix is right-associative: a . b . P is a . (b . P).
The term before a . is an action: a transition name with its arguments in parentheses. The arguments are expressions, evaluated in the current state and bound to the transition's parameters. The parentheses may be left out for a transition without parameters; writing () keeps actions and equation names visibly apart.
B0 = recv(x) . check(x) . B1 ;
B1 = reply(x) . done ;In SAPLE. At a prefix, the concrete walk binds the arguments and evaluates the transition's guard. If the guard is false, the path ends without a report. If it holds, the walk runs the effect, checks every system property in the new state (a violated property is a [PROPERTY] finding, with the path so far as its trace and the state as its witness) and continues with P. Pattern matching records the action and its argument values.
. is executed as an action- The last name of a chain is read as an equation reference. In
a() . b(), the concrete walk never runsbunless an equation is namedb, so its effect is never checked against the properties (pattern matching does treat a final transition name as an action). End every chain with. done,. 0or an equation name:a() . b() . done. - An equation name before a
.is not expanded. InLogin . serve() . done,Loginis taken as an action that has no transition: the walk records it, changes nothing and goes on. A misspelled action name behaves the same way, without an error. To run an equation and then continue, end that equation with the continuation (Login = authenticate() . Serve ;).
Choice: P + Q#
Behave as P or as Q.
Meaning. P + Q —a→ P' when P —a→ P', and P + Q —a→ Q' when Q —a→ Q'. The first action decides the branch, and the other branch is discarded. When both can act, either may happen: the choice is nondeterministic. P + Q + R is one choice among three.
In SAPLE. The concrete walk explores every branch in turn, each from the same state. A branch whose first action is disabled ends there without a report. Pattern matching enumerates one path per branch.
A turnstile that takes at most two coins. In Unlocked, a visitor may push or insert another coin:
type Gate = { LOCKED, UNLOCKED } ;
schema Turnstile {
attributes {
gate : Gate = LOCKED ;
coins : Int = 0 ;
passes : Int = 0 ;
}
}
transition coin() { guard: coins < 2 ; effect: coins += 1 ; gate := UNLOCKED ; }
transition push() { guard: gate == UNLOCKED ; effect: passes += 1 ; gate := LOCKED ; }
agent Controller() {
attributes { }
process {
Locked = [coins < 2] coin() . Unlocked
+ [coins == 2] done ;
Unlocked = push() . Locked
+ coin() . Unlocked ;
}
}
system Entrance {
schema: Turnstile ;
agents { Controller() ; }
properties {
noLostCoin : coins <= passes + 1 ;
}
}saple analyze turnstile.spl 1 finding(s):
1. [PROPERTY] HIGH — Property 'noLostCoin' violated
Property: noLostCoin
Trace: coin → coin
Witness: coins=Int(2), gate=Int(1), passes=Int(0)The walk tries both branches of Unlocked. The coin() branch inserts a second coin while the gate is already open, so a coin is swallowed (gate=Int(1) is the ordinal of UNLOCKED). The push() branch never violates the property.
Guard: [cond] P#
Behave as P, but only if cond holds now.
Meaning. [c] P —a→ P' when c holds in the current state and P —a→ P'. The guard is evaluated once, when the guarded process is about to start; it is not re-checked later. Guards with choice give a conditional, [c] P + [!(c)] Q. When no branch's guard holds, the choice is stuck, like 0.
A guard covers one prefix chain: [c] a . P + Q is ([c] a . P) + Q. Parenthesise to guard more: [c] (a . P + Q).
Idle = [state == INVALID] handleMiss() . Idle
+ [state != INVALID] handleHit() . Idle ;In SAPLE.
- The concrete walk evaluates
condin the current state. If it is false, the branch is dropped without a report. - Before exploring, SAPLE decides some guards from the action in front of them: it replaces
a . [c] Pby0whena's effect always makescfalse, and bya . Pwhen the effect always makesctrue.--verbosereports these rewrites aslaw-applied ecgaandlaw-applied eige. - In pattern matching, a guard travels with the action that follows it and is added to the pattern's constraint, together with the constant values that earlier actions on the path assign. An attribute that no earlier action sets is unknown there, not its initial value, so a guard rules out a match only when the path itself contradicts it.
- On a model from the x86-64 front end, the walk does not decide guards: it follows both branches and lets the solver decide along the path.
[ready] is false even when ready is true, and [!ready] is always true. The same holds for a transition guard such as guard: held ;. Write [ready == true] and [ready == false].
Parallel composition: P || Q#
P and Q run side by side.
Meaning. Interleaving: P || Q —a→ P' || Q when P —a→ P', and P || Q —a→ P || Q' when Q —a→ Q'. One action happens at a time, and the composition has finished when both sides have. The sides do not synchronise; they interact only through the shared state. P || Q || R composes three processes.
In SAPLE. Pattern matching enumerates the interleavings of the two sides' paths, at most 64 per composition. Interleavings that differ only in the order of independent actions are listed once. Two actions are independent when neither writes an attribute the other reads or writes and neither is named in a pattern signature. --pure-substrate lists every interleaving.
A connection whose writer sends twice while a closer closes it:
schema Channel {
attributes {
open : Bool = true ;
sent : Int = 0 ;
}
}
transition send() { guard: true ; effect: sent += 1 ; }
transition close() { guard: true ; effect: open := false ; }
agent Connection() {
attributes { }
process {
Run = Writer || Closer ;
Writer = send() . send() . done ;
Closer = close() . done ;
}
}
pattern sendAfterClose {
signature { close() . send() . done }
constraints { true }
severity: MEDIUM ;
}
system Link {
schema: Channel ;
agents { Connection() ; }
}saple analyze channel.spl 1 finding(s):
1. [STRUCTURAL] MEDIUM — Pattern 'sendAfterClose' structurally matches behavior (constraint satisfiable)
Pattern: sendAfterClose
Trace: close → sendsaple analyze --trace channel.spl lists the enumerated paths. The first and last come from Closer and Writer on their own (every equation is a starting point), and the three in between are the interleavings of Run:
Enumerated 5 parametric behavior paths
Path 1: close
Path 2: send → send → close
Path 3: send → close → send
Path 4: close → send → send
Path 5: send → send|| on its own, from a copy of the state. A property that fails only after both sides have acted, such as two increments of a shared counter that must stay at most 1, is not reported today. Patterns see the interleavings, as above.
Star: P *#
Repeat P zero or more times.
Meaning. P * may stop at once or behave as P, and each time P finishes it may start again. * is postfix and applies to the term just before it: a . b * is a . (b *); write (a . b . done) * to repeat a chain. A star cannot be followed by .; to continue after a loop, use recursion.
In SAPLE. Pattern matching unrolls zero to four repetitions (fewer near its depth bound), at most 64 paths. The concrete walk checks the patterns at the star, for the case of zero repetitions, and then walks the body once from the current state. It never runs two repetitions one after another.
schema File {
attributes {
reads : Int = 0 ;
}
}
transition open() { guard: true ; effect: skip ; }
transition read() { guard: true ; effect: reads += 1 ; }
agent Reader() {
attributes { }
process {
Session = open() . (read() . done) * ;
}
}
system Files {
schema: File ;
agents { Reader() ; }
properties {
singleRead : reads <= 1 ;
}
}saple analyze star.spl No vulnerabilities detected.Pattern matching sees up to four reads (saple analyze --trace star.spl):
Enumerated 5 parametric behavior paths
Path 1: open
Path 2: open → read
Path 3: open → read → read
Path 4: open → read → read → read
Path 5: open → read → read → read → readsingleRead is not reported, because the walk never chains repetitions. To check a property across repetitions, write the loop as a recursive equation, as below.
star_loop.spl is star.spl with Session replaced by these two equations:
Session = open() . Reading ;
Reading = [reads < 3] read() . Reading + done ;saple analyze star_loop.spl 2 finding(s):
1. [PROPERTY] HIGH — Property 'singleRead' violated
Property: singleRead
Trace: open → read → read
Witness: reads=Int(2)
2. [PROPERTY] HIGH — Property 'singleRead' violated
Property: singleRead
Trace: open → read → read → read
Witness: reads=Int(3)Recursion and equation references#
A name that is not followed by . refers to an equation: it behaves as that equation's right-hand side. An equation that refers to itself, directly or through others, is a loop.
Meaning. With X = P: X —a→ P' when P —a→ P'. An equation may refer to equations declared after it. The first equation of an agent is its initial behavior.
In SAPLE. The concrete walk unfolds a reference each time it reaches one. A loop runs until a guard stops it, an action is disabled, or the walk's depth bound of 100 is reached; a path cut at the bound ends without a report. Pattern matching unfolds references up to its own depth bound of 50 and keeps the paths it cuts there. A reference to a name that is no equation ends the concrete walk's path silently; pattern matching reads it as an action when it names a transition.
A client that retries a connection until it has made three attempts:
schema Client {
attributes {
tries : Int = 0 ;
}
}
transition attempt() { guard: true ; effect: tries += 1 ; }
transition giveUp() { guard: true ; effect: skip ; }
agent Connector() {
attributes { }
process {
Retry = [tries < 3] attempt() . Retry
+ [tries >= 3] giveUp() . done ;
}
}
system Dialler {
schema: Client ;
agents { Connector() ; }
properties {
atMostTwoAttempts : tries <= 2 ;
}
}saple analyze retry.spl 2 finding(s):
1. [PROPERTY] HIGH — Property 'atMostTwoAttempts' violated
Property: atMostTwoAttempts
Trace: attempt → attempt → attempt
Witness: tries=Int(3)
2. [PROPERTY] HIGH — Property 'atMostTwoAttempts' violated
Property: atMostTwoAttempts
Trace: attempt → attempt → attempt → giveUp
Witness: tries=Int(3)The walk follows the reference to Retry through three attempts, then takes the giveUp() branch. The property is checked after every action, so the violation is reported again after giveUp().
P = a() . P + b() . P, has about 2100 paths up to the depth bound, and the analysis does not finish in practical time. Bound such loops with guards over a counter (as in Retry) or make one branch leave the loop.
saple analyze puts the equations of all agents in one namespace. An equation with the same name as one in an earlier agent replaces it. Give each agent its own equation names.
Branch#
branch writes a two-way conditional jump of which one direction was observed. The AArch64 front end emits it for a conditional branch in a recorded run (AArch64 Model):
B0 = adds_w(X0, X2, 64) .
branch V == 1
taken: branch_taken(0x401030) . unexplored
observed fall: branch_fall(0x40101c) . B1 ;Meaning. branch c taken: P fall: Q is [c] P + [!(c)] Q, and it behaves exactly as that guarded choice. The observed marker is checked by the parser and then dropped.
- The
taken:arm comes first, thenfall:. Each arm is a prefix chain. - Exactly one arm carries
observed. The other must end inunexploredorBottom. branchis the statement only when an expression follows it. Before(,.,+,*,||,;,)or}, it is an ordinary name, sobranch (V == 1)is read as an action namedbranchand fails to parse. Writebranch V == 1.
Atomic region#
atomic { … } in process position marks a prefix chain that the other side of a || should not interrupt. The body may contain only prefixes, equation references and terminals; a choice, parallel composition, star or guard inside is a parse error.
Commit = atomic { lock() . write(v) . unlock() . Commit } ;||, SAPLE removes the region before exploring, which changes nothing. Put the continuation inside the region, as above: atomic { … } . Commit parses, but the concrete walk stops after the region.
Precedence#
From lowest to highest binding:
| Operator | Syntax | Notes |
|---|---|---|
| Parallel | P || Q | Lowest; P || Q || R is one composition |
| Choice | P + Q | P + Q + R is one choice |
| Prefix, guard, star | a . P, [c] P, P * | Prefix is right-associative; a guard covers one prefix chain; * applies to the term just before it |
| Atoms | actions, names, terminals, ( … ), atomic { … }, branch … | Highest |
a . b . P + c . Qis(a . (b . P)) + (c . Q).P + Q || Ris(P + Q) || R.[c] a . P + Qis([c] a . P) + Q, and[c] P || Qis([c] P) || Q.a . b *isa . (b *), and[c] a *is[c] (a *).
saple parse --ast file.spl prints the parsed tree, which shows how an expression was grouped.
A complete agent#
A server with a queue of at most two requests. It stops taking requests once three have been served, and it can shut down whenever the queue is empty:
schema Queue {
attributes {
pending : Int = 0 ;
served : Int = 0 ;
}
}
transition request() { guard: pending < 2 ; effect: pending += 1 ; }
transition serve() { guard: pending > 0 ; effect: pending -= 1 ; served += 1 ; }
transition shutdown() { guard: pending == 0 ; effect: skip ; }
agent Server() {
attributes { }
process {
Idle = [served < 3] request() . Busy
+ shutdown() . done ;
Busy = serve() . Idle
+ request() . Busy ;
}
}
system Service {
schema: Queue ;
agents { Server() ; }
properties {
queueBounded : pending <= 2 ;
serviceCapped : served <= 3 ;
}
}saple analyze server.spl No vulnerabilities detected.Idleis the initial behavior, because it is the first equation.[served < 3]bounds the loop, so the walk ends after a few dozen steps.- Paths that reach a disabled action (another request with two pending, or a shutdown with a request pending) end there. Neither property is violated on any path.
How SAPLE explores a process#
saple analyze model.spl runs three stages on a hand-written model. --verbose shows each of them:
- Simplification (
stl-normalize). The equations are rewritten with laws that preserve what they can do, for exampleP + 0toP,0 . Pto0, and guards that the preceding action decides (see Guard).--pure-substrateturns this stage off. - Pattern matching (
stage-2a-structural). Every equation is a starting point. From each one, SAPLE enumerates paths of actions, one per branch of a choice, with the interleavings of||and the unrollings of*and of references. It does not decide the[c]guards while enumerating (they are added to each pattern's constraint), it ignores the transitions' own guards, and it keeps paths cut at a bound. Each pattern's signature is then matched against these paths, and its constraint is checked with the solver (Patterns). - Concrete walk (
stage-2b-concrete). The walk starts at the first equation of the first agent in the file. Its state is the schema's attributes with their declared initial values;--input NAME=VALUE(an integer or a real, after the file name) overrides one. At each action, it checks the transition's guard, runs the effect and checks every property of the system. It explores every branch of every choice, depth first. A path ends at a terminal, at a disabled action, at the depth bound, or at a reference to an unknown name.
For the retry client above, saple analyze --verbose retry.spl shows both stages. Pattern matching does not evaluate [tries < 3], so it unfolds the loop up to its depth bound (12 attempts). The walk evaluates the guard, makes three attempts, then gives up; the number in brackets is the depth:
═══ stage-2a-structural ═══
enumerated 13 paths from 1 roots (max_depth=50, depth_caps=0)
path 0 (12 actions)
path 1 (12 actions)
…
path 12 (1 actions)
Structural findings: 0
═══ stage-2b-concrete ═══
[ 0] attempt
[ 1] attempt
[ 2] attempt
[ 3] [guard] condition not met, skipping branch
[ 3] giveUp
[ 2] [guard] condition not met, skipping branch
[ 1] [guard] condition not met, skipping branch
[ 0] [guard] condition not met, skipping branch
Concrete findings: 2| Bound | Pattern matching | Concrete walk |
|---|---|---|
| Depth | 50 levels per path (each action, choice, guard, reference, || and * uses one) | 100 levels per path (each action uses one, and so does a reference that no action precedes) |
| Paths | At most 4096 per starting point and per sub-term | No limit: every branch is followed |
P || Q | At most 64 interleavings | Each side alone, from a copy of the state |
P * | 0 to 4 repetitions, at most 64 paths | Zero repetitions, or the body once |
Two further rules hold today. The system's agents { } and init { } do not change the walk: it starts from the first agent declared in the file, in the schema's initial state. To analyse several agents together, compose them with || in one equation, keeping in mind the limitation of Parallel composition. Agent attributes are not part of the walked state: put the state that the transitions read and write in the schema. See also Agents and Transitions.
Common mistakes#
| You write | What happens | Write instead |
|---|---|---|
request() serve() . done | Parse error: expected Semicolon, found Ident | request() . serve() . done |
a() . b() | Parses, but the concrete walk never runs b | a() . b() . done |
Login . serve() . done, with Login an equation | Login is taken as an action with no transition; its equation is not run | Main = Login ; with Login = authenticate() . Serve ; |
(open() . done + cancel() . done) . read() . done | Parses; pattern matching continues with read, but the concrete walk ends after the choice. The same holds after atomic { … }. | open() . Read + cancel() . Read with Read = read() . done ; |
(a() . b() . done) . c() . done | Parses, but the concrete walk runs a, skips b and continues with c | a() . b() . c() . done |
[c] a() . P + Q, meaning to guard both | Only the first branch is guarded | [c] (a() . P + Q) |
[ready], [!ready] | Evaluated wrongly by the walk (see Guard) | [ready == true], [ready == false] |
a() . b() *, meaning to repeat both | Repeats only b | (a() . b() . done) * |
(read() . done) * . close() . done | Parse error: expected Semicolon, found Dot | Loop = read() . Loop + close() . done ; |
branch (V == 1) … | Parse error: expected Semicolon, found Ident, because branch ( starts an action named branch | branch V == 1 … |
atomic { lock() . write() . done + abort() . done } | Parse error: expected a prefix chain inside atomic { } | Make the choice outside the region |
Delta | Parse error: 'Delta' is no longer valid; use 'done' instead | done |
The rejected forms, as the parser sees them:
agent Server() {
attributes { }
process {
Idle = request() serve() . done ;
}
}agent Reader() {
attributes { }
process {
Session = (read() . done) * . close() . done ;
}
}agent Program() {
attributes { }
process {
B0 = branch (V == 1)
taken: jump() . unexplored
observed fall: next() . done ;
}
}agent Writer() {
attributes { }
process {
Commit = atomic { lock() . write() . done + abort() . done } ;
}
}agent Worker() {
attributes { }
process {
Main = work() . Delta ;
}
}Algebraic laws#
SAPLE's algebraic core implements these laws as rewrite rules. In them, P . Q runs Q after P has finished (done is written Δ in the literature):
| Law | Equation | Why it matters |
|---|---|---|
| Deadlock is the choice identity | P + 0 = P | A branch that can never start adds no behavior, so pruning an impossible branch leaves the rest unchanged. |
| Choice is idempotent | P + P = P | Offering the same alternative twice is offering it once; the rule fires on identical terms. |
Bottom absorbs choice | Bottom + P = Bottom | If one alternative is unknown, so is the whole choice: knowing P says nothing about the unknown branch. |
done is the sequence identity | done . P = P, P . done = P | A finished process passes control on unchanged, so sub-processes compose without extra steps. |
| Deadlock is a left zero of sequence | 0 . P = 0 | Nothing after a deadlock ever happens. |
Bottom propagates through sequence | Bottom . P = Bottom | Nothing after an unknown continuation can be assumed. |
| Right distributivity | (P1 + P2) . P3 = P1 . P3 + P2 . P3 | A common continuation can be moved into each branch; the right-hand form is the one to write for analysis (see Common mistakes). |
| Sequence is associative | (P1 . P2) . P3 = P1 . (P2 . P3) | The grouping of a sequence does not change its behavior. |
done is the parallel identity | P || done = P | A finished partner does not constrain the other side. |
| Deadlock propagates through parallel | P || 0 = 0 | In this algebra, a deadlocked component deadlocks the whole composition. |
| Parallel is associative | (P1 || P2) || P3 = P1 || (P2 || P3) | Three components compose the same way whatever the grouping. |
| Expansion | a.P1 || b.P2 = a.(P1 || b.P2) + b.(a.P1 || P2) | Parallel composition reduces to choice and prefix: the interleavings that pattern matching enumerates. |
saple analyze does not rewrite a model with this table. Before exploring, it applies P + 0 = P and 0 . P = 0 together with its own laws, which decide guards from the effect of the action before them (see How SAPLE explores a process). During exploration, Bottom only ends a path: P + Bottom keeps the paths of P.