ALVIE/VaultLink Reference
New
ALVIE/VaultLink learns a Mealy machine of a service that speaks a line-based text protocol, and compares two such machines.
It was a variant of ALVIE for training (the branch variant/vaultlink, with the programs vl_learn, vl_compare and vl_replay); it is
now part of ALVIE, as alvie vaultlink, and runs in a browser too (see ALVIE in the Browser).
It reaches a service over TCP (--target host:port), or a service in memory (--service, see below).
The workflow has three steps:
- Write a
.vtdlfile that says which inputs to send, what to observe in the responses, and which input sequences are worth exploring. - Run
alvie vaultlink learnagainst each service to learn a model, written as a DOT graph. - Run
alvie vaultlink compareon two models, then usealvie vaultlink replayto try the sequences it reports against the real service.
Specification files
Section titled “Specification files”A training exercise provides a starter .vtdl file with values and inputs filled in for its own service.
observe and session are left minimal on purpose: writing them is part of the exercise.
A minimal file still parses and runs, producing a model too small to be useful, as a starting point to extend.
A .vtdl file has four sections in this order.
values may be omitted.
Every section and every statement ends with ;.
Comments are written (* ... *) and may be nested.
values { user = "alice"; pw = "correct-horse";};
inputs { HELLO = "HELLO"; ID_ME = "ID {user}"; PASS_OK = "PASS {pw}"; READ = "READ";};
observe { "OK" -> OK; "ERR" -> ERR; "DATA vault={v} contents=*" -> DATA(v); _ -> OTHER;};
session { HELLO; (ID_ME | PASS_OK | READ)*};values
Section titled “values”Named string constants.
An input command can refer to a value as {name}, which is replaced by the constant.
Every {name} must refer to a declared value.
inputs
Section titled “inputs”The input alphabet of the learner. Each entry maps an input name to the command line sent to the service. Names are upper case, may contain digits and underscores, and must be unique. The names appear on the transitions of the learned model.
RESET, HELP, and QUIT are commands of the transport, not of the protocol.
They are rejected as inputs, because ALVIE sends RESET itself before every query to return the service to its initial state.
observe
Section titled “observe”Maps each response line to one output symbol.
Rules are tried in order and the first rule that matches the whole line wins.
In a pattern, * matches any text and discards it, and {x} matches one or more characters and captures them.
Two wildcards in a row must be separated by literal text.
The output of a rule is a name, optionally followed by captured variables: DATA(v) produces the symbol DATA(alice) when v captured alice.
Every variable used in the output must be captured by the pattern.
The last rule must be _, which matches every line.
Output names are upper case.
ILLEGAL and DISCONNECTED are reserved for ALVIE.
Choosing what to observe is part of the modelling work. An observable that discards too much can make two different behaviours look the same. An observable that keeps too much, such as a whole line that varies from run to run, makes the learner see unboundedly many outputs.
session
Section titled “session”A regular expression over input names that limits which input sequences the learner explores. It uses the combinators of TestDL:
| Syntax | Meaning |
|---|---|
a; b | a and then b |
a | b | a or b |
a* | zero or more repetitions of a |
eps | the empty sequence |
( ... ) | grouping |
A trailing ; before ) or at the end is accepted.
The learner only sends an input if the sequence so far can still be completed to a word of the expression.
An input that the expression forbids is never sent, and the model has no transition for it.
A tighter expression makes learning faster, but a sequence that the expression excludes can never be tried. A behaviour that needs such a sequence is invisible.
Commands
Section titled “Commands”alvie vaultlink learn
Section titled “alvie vaultlink learn”alvie vaultlink learn --spec my.vtdl --target localhost:9101 --res impl.dotalvie vaultlink learn --spec my.vtdl --service firmware --res impl.dotLearns a model of the service at --target, or of the service in memory --service, and writes it to --res.
States are numbered from 0 in breadth-first order.
Transitions are labelled INPUT / OUTPUT.
| Option | Meaning |
|---|---|
--oracle | wmethod (default), randomwalk, or pac. |
--extra-states k | wmethod: the service may have up to k more states than the learned model. Default 2. |
--max-tests n | wmethod: stop each equivalence check after n tests. This gives up the guarantee. |
--step-limit, --reset-probability | randomwalk: length of each random walk and the chance of restarting it. pac: the chance of ending a test where the session may end. |
--epsilon, --delta, --round-limit | pac: error bound, confidence, and an optional cap on rounds. |
--seed n | Seed of the random choices, for the randomwalk and pac oracles. |
--debug | Logs every step. |
A test of pac ends when the session allows no more input, or, where the session may end, with the probability of
--reset-probability: without this, a session such as (HELLO | READ)* never ends a test (vl_learn did not end).
The wmethod oracle tests every input sequence of a fixed shape and, if the service passes all of them, the model is exact for any service with at most k more states.
The other oracles sample behaviour at random, so a rare behaviour can be missed.
The last line of a run says which guarantee applies.
Learning one service from scratch takes seconds.
A larger --extra-states makes the equivalence check much slower, because the number of tests grows quickly with it.
alvie vaultlink compare
Section titled “alvie vaultlink compare”alvie vaultlink compare spec.dot impl.dotPrints the shortest input sequences on which the two models give different outputs, up to --limit of them (default 10).
Each step shows the input and the outputs of the two models, with <> marking the step where they first differ:
#1 HELLO OK | OK ID_ME OK | OK READ <> ERR | DATA(alice)The exit status is 0 if the models agree, 1 if they differ, and 2 if a file cannot be read.
An input that only one of the models has is skipped, because the other model’s session forbids it.
alvie vaultlink replay
Section titled “alvie vaultlink replay”alvie vaultlink replay --spec my.vtdl --target localhost:9101 HELLO ID_ME PASS_OK READSends the named inputs to the service in order and prints the raw conversation. Each line shows the input, the command that was sent, the response line, and the output symbol in brackets. Inputs can be given as separate arguments or as one quoted list separated by spaces or commas.
replay ignores the session expression, so any sequence of declared inputs can be sent.
It is the way to try a sequence from compare with a variation, for example with a different value in an input.
alvie vaultlink serve
Section titled “alvie vaultlink serve”alvie vaultlink serve --service reference --port 9101Serves a service in memory over TCP on 127.0.0.1, one connection at a time, to practise with --target.
The native ALVIE only.
The services in memory
Section titled “The services in memory”--service chooses a vault controller in the same program, so no network is needed (in a browser, this is the only
choice). They speak the protocol of VaultLink, one command per line:
| Command | Meaning |
|---|---|
HELLO | opens the session |
ID <id> | declares the identity of the operator |
PASS <pw> | authenticates the session |
AUDIT | notes the access in the register |
OPEN | opens the door of the vault of the identity |
READ | reads the contents |
CLOSE | seals the session, for good |
RESET (back to the start), HELP and QUIT are commands of the transport.
The answers are OK ..., ERR <reason> (an ERR ends the session: start again from HELLO) and
DATA vault=<id> contents=<...>.
The operators are alice (password correct-horse) and bob (password battery-staple).
referenceis the documented controller:HELLO,ID,PASS,AUDIT,OPEN, thenREADany number of times andCLOSE.firmwarebehaves asreferenceexcept for one behaviour that the documentation does not have: finding it is the exercise. It is not the service of the VaultLink challenge.
spec-lib/vaultlink/vault.vtdl is a specification for them:
alvie vaultlink learn --spec ../../spec-lib/vaultlink/vault.vtdl --service reference --res spec.dotalvie vaultlink learn --spec ../../spec-lib/vaultlink/vault.vtdl --service firmware --res impl.dotalvie vaultlink compare spec.dot impl.dotReading a model
Section titled “Reading a model”A learned model is plain text. To draw it, run:
dot -Tpng impl.dot -o impl.pngLook for transitions that the two models do not share and for states that exist in only one of them.
alvie vaultlink compare finds these automatically, but the structure of a model often shows more than one sequence does.
Errors
Section titled “Errors”| Status | Meaning |
|---|---|
| 0 | Success. |
| 1 | compare only: the models differ. |
| 2 | A problem with the specification, an option, or a file. The message gives a line and column for specification errors. |
| 3 | The service cannot be reached or does not behave like a VaultLink service. |