TestDL Tutorial: V-B1 Example
This one-hour tutorial is our first practical session with the two small languages used by ALVIE/Sancus. We learn them through the specification used to reproduce the V-B1 vulnerability from the Mind the Gap paper, using its corresponding Sancus implementation. We use a reduced fast profile while reading the languages, then reproduce the real attack from the complete V-B1 models tracked in the repository. V-B1 is used as the second case study because it is a published vulnerability whose checked-in models let a new user reproduce and inspect a genuine witness without waiting for full learning.
The complete syntax and semantics are in the TestDL Action Reference. We use that page when we need details. This tutorial focuses on where to start and what each part is doing.
For the quickest setup, we use the published Docker image described in Getting Started and mount a host directory for the witness we produce later:
mkdir -p "$PWD/alvie-output"docker pull matteobusi/alviedocker run --rm -it \ -v "$PWD/alvie-output:/output" \ matteobusi/alvieThe image already contains ALVIE/Sancus, its dependencies, and sancus-core-gap, and starts in the repository root so the paths below work unchanged.
Inside the container, files written to /output appear in ./alvie-output on the host.
The Docker Hub image is matteobusi/alvie, and its Dockerfile installs Graphviz for the rendering command below.
We use the native setup instructions in Getting Started only when we need a local development environment.
What We Will Build
Section titled “What We Will Build”An ALVIE/Sancus experiment combines two files:
- an attacker specification (
.atdl) describes allowed attacker actions, including interrupt behavior; - an enclave specification (
.etdl) describes the victim program.
The worked example uses:
spec-lib/fast/b1.atdlspec-lib/fast/enclave-complete.etdlThe fast profile is intentionally smaller than the complete profile. It is suitable for learning the language, but it is not a replacement for the full paper experiment.
A short security vocabulary
Section titled “A short security vocabulary”You do not need prior Sancus or side-channel experience for this tutorial.
Here, a secret is a value held by the enclave that the attacker should not be able to distinguish.
The attacker cannot read protected memory directly.
It can choose allowed actions, request timer interrupts, and observe public effects such as execution time, control-flow boundaries, and unprotected memory.
A side channel exists when those public observations differ for secret 0 and secret 1.
V-B1 is a timing/interrupt example.
The vulnerable Sancus implementation takes one extra CPU cycle for the first instruction after reti (return from interrupt).
Its security model expects that instruction to take the normal time.
ALVIE/Sancus learns models for both secret values and searches them for an attacker-visible consequence of that one-cycle mismatch.
This is the workflow described in the ALVIE paper.
1. Prepare the checkout
Section titled “1. Prepare the checkout”For a native checkout rather than the Docker image, we check that the required Sancus repository is present and build the OCaml project:
test -d sancus-core-gapcd alvie/codedune buildcd ../..test -d sancus-core-gap succeeds only when the simulator checkout is at the repository root.
dune build compiles the executables used later in this tutorial; the cd commands enter and leave the ALVIE/Sancus OCaml project directory.
See Getting Started for the full environment setup.
2. Read the enclave specification
Section titled “2. Read the enclave specification”Open spec-lib/fast/enclave-complete.etdl.
Its outer enclave section is the set of victim-program behaviours ALVIE/Sancus may instantiate.
Each expression describes a possible protected program fragment, not an instruction the attacker chooses directly.
Its outer form is:
enclave { ...};Actions separated by ; run in sequence.
The ? placeholder is replaced by the value passed to learn.exe --secret:
cmp ?, r4;jmp #enc_eThe large parenthesized expression in the file contains alternatives joined by |.
Parentheses group an expression, eps means an empty action, and a choice lets the learner explore different allowed victim behaviors.
One representative branch is:
ifz (mov #42, &unprot_mem; nop) (nop; mov #42, &unprot_mem)The full meaning of ifz, operands, memory labels, and instruction atoms is covered by the TestDL Action Reference.
3. Read the attacker specification
Section titled “3. Read the attacker specification”Open spec-lib/fast/b1.atdl.
Attacker files have three sections:
isr { ... };prepare { ... };cleanup { ... };The example attacker specification contains:
isr { timer_enable 1; reti};
prepare { timer_enable 3; create <enc_s, enc_e, data_s, data_e>; jin enc_s};
cleanup { nop };prepare is the attacker-controlled setup executed before the interaction we learn.
Here it configures a timer, enables the enclave with its memory boundaries, and transfers control to the enclave entry point.
isr describes the code that runs when the timer interrupts execution; in this example it schedules the next interrupt one tick later and returns with reti, making closely spaced interrupts part of the threat model.
cleanup is the attacker-controlled suffix after an interaction, where a specification can model teardown, reset, or follow-up actions.
This example uses nop, so cleanup has no extra effect.
These bodies use the same ; , |, eps, repetition, and grouping operators as enclave expressions.
The TestDL Specification Reference describes their grammar.
The TestDL Action Reference defines the actions.
4. Learn one small model directly
Section titled “4. Learn one small model directly”Before comparing V-B1, run ALVIE/Sancus directly on the repository’s small running example. This is a real simulator execution and produces one learned model in about half a minute on a typical development machine. It teaches the learner interface without presenting a short, bounded run as a V-B1 security verdict.
mkdir -p "$ALVIE_OUTPUT/example-learn"dune exec bin/learn.exe -- \ --att-spec ../../spec-lib/example/attacker.atdl \ --encl-spec ../../spec-lib/example/enclave.etdl \ --res "$ALVIE_OUTPUT/example-learn/secret-0.dot" \ --tmpdir "$ALVIE_OUTPUT/example-learn/tmp" \ --commit bf89c0b \ --sancus ../../sancus-core-gap \ --secret 0 \ --oracle randomwalk \ --step-limit 5000 \ --reset-probability 0.09 \ > "$ALVIE_OUTPUT/example-learn/learn.log" 2>&1The two --*-spec arguments select the attacker and victim languages.
--res chooses the learned-model file, and --tmpdir holds generated programs and simulator traces.
--sancus points to the Sancus checkout.
This command fixes the secret to 0 and uses final Sancus revision bf89c0b; it does not compare secrets and therefore cannot establish or rule out a vulnerability.
randomwalk is a bounded equivalence oracle.
--step-limit 5000 caps its exploration work, while --reset-probability 0.09 makes it randomly restart on some paths.
The output model is $ALVIE_OUTPUT/example-learn/secret-0.dot, and the complete learner output is in learn.log.
The current example produces a small 21-line DOT file.
The full command-line reference is in the Executables Reference.
5. Reproduce the checked-in V-B1 witness
Section titled “5. Reproduce the checked-in V-B1 witness”Learning V-B1 from scratch can take a long time, even with a bounded oracle.
For this first session, use the four complete V-B1 models already tracked in the repository.
They were learned for vulnerable Sancus revision ef753b6:
- one model for each secret value (
0and1); - one interrupt-enabled and one no-interrupt model for each secret.
Run the same four-model comparison that ALVIE/Sancus uses for an attack assessment:
cd alvie/code# Docker container:export ALVIE_OUTPUT=/output# Native host: export ALVIE_OUTPUT=/tmp/alvie-outputmkdir -p "$ALVIE_OUTPUT/vb1-fa"dune exec bin/fa.exe -- \ --m1-int ../../results/ef753b6-b1-enclave-complete-0-0.01-0.01-int.dot \ --m2-int ../../results/ef753b6-b1-enclave-complete-1-0-0.01-0.01-int.dot \ --m1-nint ../../results/ef753b6-b1-enclave-complete-0-0.01-0.01-nint.dot \ --m2-nint ../../results/ef753b6-b1-enclave-complete-1-0.01-0.01-nint.dot \ --tmpdir "$ALVIE_OUTPUT/vb1-fa" \ --witness-file-basename "$ALVIE_OUTPUT/vb1-fa/witness" \ --cex-limit 1The four model arguments are what make this a security comparison rather than a simple comparison between two runs:
--m1-intand--m2-intare the interrupt-enabled models for secret0and secret1.--m1-nintand--m2-nintare their no-interrupt counterparts. ALVIE/Sancus subtracts differences already present without interrupts, leaving behavior attributable to the interrupt-enabled threat model.ALVIE_OUTPUT=/outputselects the Docker bind mount. For native use, we can set it to/tmp/alvie-outputinstead.--tmpdiris a disposable work directory for mCRL2 intermediate files.--witness-file-basenamechooses the output prefix; ALVIE/Sancus writes$ALVIE_OUTPUT/vb1-fa/witness_int.dot.--cex-limit 1asks for one witness, which keeps this introductory result focused and fast.
For the complete comparison interface, see Executables Reference.
6. Render and inspect the witness
Section titled “6. Render and inspect the witness”Render the resulting Graphviz file:
dot -Tpdf "$ALVIE_OUTPUT/vb1-fa/witness_int.dot" \ -o "$ALVIE_OUTPUT/vb1-fa/witness_int.pdf"dot -Tpdf turns the witness graph into a PDF; -o gives that PDF its name.
Open it with a local PDF viewer.
In the Docker workflow, the PDF is now on the host under ./alvie-output/vb1-fa/.
For an older published image without Graphviz, we copy the checked-in rendering instead:
cp ../../counterexamples/b1/pdf/ef753b6-b1_int.pdf \ "$ALVIE_OUTPUT/vb1-fa/reference-witness.pdf"To locate the important labels directly in the generated graph, run:
grep -nE 'add #1, &data_s|timer_enable 1|timerA_counter = [01]' \ "$ALVIE_OUTPUT/vb1-fa/witness_int.dot"The graph starts with the common setup: timer_enable 3, create, and jin enc_s.
It then shows two executions side by side.
The black dashed path is the model for secret 0; the red dotted path is the model for secret 1.
The attacker is not choosing cmp #0, r4 or cmp #1, r4: those are the two secret-specific enclave programs being compared.
Follow the branch labelled ifz [ add #1, &data_s; nop], [ nop; add #1, &data_s;].
The attacker first uses timer_enable 3 so an interrupt arrives during the first instruction of that action.
In the handler, it executes timer_enable 1 and then reti, scheduling another interrupt for the first cycle after the handler returns.
Timer A counts from 0 to the requested value, so the decisive public value is either 0 or 1:
- With secret
0, the first cycle afterretiis Sancus padding intended to mitigate the Nemesis attack. The second interrupt therefore runs immediately after that padding, and the attacker observestimerA_counter = 0. - With secret
1, control first returns to the enclave to execute the remainingnop. Because of V-B1, thatnoptakes two cycles rather than one, so the originally balancedifzbranches are no longer balanced. When the attacker regains control, it observestimerA_counter = 1.
That single public timer value distinguishes the secret-dependent executions.
It is the V-B1 attack: a one-cycle implementation/model mismatch after reti becomes a secret-dependent timing observation.
The witness is evidence for this threat model and these learned models.
It is not a claim that every Sancus program leaks, nor does it automatically provide a code repair.
The Log and Output Reference explains fields such as k, gie, timerA_counter, PM, and UM.
7. Optional: learn the models yourself
Section titled “7. Optional: learn the models yourself”The comparison above is complete and immediately reproducible. We run learning ourselves only when we want to regenerate the models and have time to let the complete experiment finish. The repository wrapper then runs the full V-B1 experiment:
cd ../.../learn_one.sh e8cf011 b1 fast./check_one.sh b1 fastcd ../.. returns from alvie/code to the repository root.
In learn_one.sh e8cf011 b1 fast, e8cf011 is V-B1’s special fixing commit, b1 selects the attacker spec, and fast is both the specification directory and output namespace.
The wrapper learns secret 0/1 models with and without interrupts for the vulnerable, special-fix, and final commits.
check_one.sh b1 fast compares the secret pairs and subtracts no-interrupt witnesses.
Results, logs, and temporary files are placed under results/fast/, logs/fast/, and tmp/fast/.
It takes a few minutes on a machine with several cores, so it is not part of the one-hour tutorial.
See Reproducing the Simulation Experiments for wrapper behavior and Executables Reference for the underlying commands.
For the full paper profile, replace fast with a separate namespace and use the complete specifications.
Expect it to take longer: the slowest complete models take about 5 minutes each.
8. Make a small change
Section titled “8. Make a small change”Copy a specification before experimenting so generated output stays separate:
cp spec-lib/fast/b1.atdl /tmp/my-b1.atdlThis copies the original fast attacker specification to a disposable path.
Keep the original under spec-lib/ unchanged, then pass /tmp/my-b1.atdl as --att-spec and choose new --res and --tmpdir paths when rerunning the direct learner command.
We can now change one timer, choice, or action and rerun the direct command with a new --res and --tmpdir.
Parser errors usually come from a missing semicolon, unmatched parenthesis, unknown action, or invalid register.
For exact syntax, consult the action reference, and use Extending TestDL Actions when adding a new language construct.
Related files
Section titled “Related files”- Complete V-B1 attacker profile:
spec-lib/b1.atdl - Complete enclave profile:
spec-lib/enclave-complete.etdl - Full experiment workflow: Reproducing the Simulation Experiments