Skip to content
You are reading the documentation of the development version (main branch): it may describe changes that are not released yet. Current documentation: 2026.10. Other versions: 2026.09 (extended documentation), 2026.09 (as released)

Tutorial: Find a Leak on Tiny

New

This tutorial runs a whole ALVIE experiment on Tiny, the reference platform of ALVIE/Core. Tiny is a small processor written in OCaml, so learning a model takes a fraction of a second, and you need no simulator and no Sancus checkout. It has two planted timing leaks: one that any attacker sees, and one that only an attacker with interrupts sees. The steps are those of an experiment on Sancus (see Getting Started), and How ALVIE Works explains the ideas behind them.

You need the OCaml build of ALVIE (dune build in alvie/code, for example in the Docker image), or nothing at all: the tutorial Tiny of ALVIE in your browser runs these steps in your browser, with the same commands. mCRL2 is needed only to check formulas. Run every command from alvie/code.

Tiny runs the attacker’s code or the code of one enclave. The attacker arms a timer with timer n and calls the enclave with call. Each instruction of the enclave takes one or two cycles, and the timer counts them. When the timer expires during an instruction, the instruction completes and then the interrupt is handled: the attacker sees the interrupt and its latency, the cycles the instruction still ran after the timer expired. The attacker’s ISR runs, and reti resumes the enclave. When the enclave returns (ret), the attacker sees how many cycles it ran since it was called or last resumed.

The enclave’s instructions:

InstructionCycles
nop, mov r, v, ret1
bz r (branch on zero)2 if r is 0, 1 otherwise
pad r (pads a branch on zero)1 if r is 0, 2 otherwise

The plugin files are in plugins/tiny/, and the backend is lib/core/tiny/tiny.ml.

A spec says which tests to run, one body per section, as for Sancus. plugins/tiny/fixtures/leak-time.spec:

// The enclave branches on the secret with bz: it takes two cycles if the secret is 0, one otherwise, so the time it
// takes tells the secret, with or without interrupts.
prepare { (timer 1 | timer 2 | timer 3 | eps); call };
enclave { mov r0, ?; bz r0; ret };
isr { reti };
cleanup { halt };

The attacker may arm the timer, then calls the enclave. The enclave puts the secret (?) in r0 and branches on it. The ISR resumes the enclave, and after the enclave has returned the attacker ends the test.

alvie tiny exec runs atoms one at a time and prints what each observes, with the section the test moves to. Write the atoms in a file, one per line:

timer 2
call
mov r0, 0
bz r0
reti
ret
halt
Terminal window
_build/default/bin/alvie.exe tiny exec --spec plugins/tiny/fixtures/leak-time.spec --secret 0 --inputs inputs.txt
prepare timer 2 Ok
prepare call Enter -> enclave
enclave mov r0, 0 Run
enclave bz r0 Irq(latency = 1) -> isr
isr reti Resume -> enclave
enclave ret Exit(time = 1) -> cleanup
cleanup halt Done (finished)

mov took one cycle; the timer expired after the first cycle of bz, which takes two on 0, so the latency is 1. An atom that the spec does not allow at that point is refused, with the atoms it allows.

Learn a model for each value of the secret:

Terminal window
_build/default/bin/alvie.exe tiny learn --spec plugins/tiny/fixtures/leak-time.spec --secret 0 --res /tmp/tiny/time-0.dot
_build/default/bin/alvie.exe tiny learn --spec plugins/tiny/fixtures/leak-time.spec --secret 1 --res /tmp/tiny/time-1.dot
Learned a model of 19 states and 21 transitions in 0.1s (1078 queries, 1640 steps): /tmp/tiny/time-0.dot
Learned a model of 17 states and 19 transitions in 0.1s (961 queries, 1541 steps): /tmp/tiny/time-1.dot

Learning is deterministic: the same spec and options give the same model (--seed changes the random choices). The options of the learner are those of Choosing Learner Settings: --oracle pac (the default) with --epsilon and --delta, or --oracle randomwalk.

alvie tiny compare looks for runs that the attacker tells apart: the same attacker inputs, the same enclave code up to the secret, and different outputs.

Terminal window
_build/default/bin/alvie.exe tiny compare --m1 /tmp/tiny/time-0.dot --m2 /tmp/tiny/time-1.dot --secrets 0,1 --witnesses /tmp/tiny/time-witnesses.dot
noninterference does not hold: 3 witnesses (see /tmp/tiny/time-witnesses.dot)

The exit status is 4 when there are witnesses, so scripts can test it. Render the witness graph with Graphviz (dot -Tsvg /tmp/tiny/time-witnesses.dot -o witnesses.svg) and read it as Reading and Checking a Witness explains: one witness is the run without a timer, where the enclave returns after Exit(time = 4) for secret 0 and Exit(time = 3) for secret 1.

Learn the same spec on the variant no-interrupts, whose timer never expires, and give it to compare as the baseline: witnesses that the baseline has too do not count.

Terminal window
_build/default/bin/alvie.exe tiny learn --spec plugins/tiny/fixtures/leak-time.spec --secret 0 --variant no-interrupts --res /tmp/tiny/time-0-nint.dot
_build/default/bin/alvie.exe tiny learn --spec plugins/tiny/fixtures/leak-time.spec --secret 1 --variant no-interrupts --res /tmp/tiny/time-1-nint.dot
_build/default/bin/alvie.exe tiny compare --m1 /tmp/tiny/time-0.dot --m2 /tmp/tiny/time-1.dot \
--m1-baseline /tmp/tiny/time-0-nint.dot --m2-baseline /tmp/tiny/time-1-nint.dot \
--secrets 0,1 --witnesses /tmp/tiny/time-witnesses-baseline.dot
noninterference holds: 0 witnesses (see /tmp/tiny/time-witnesses-baseline.dot)

Every witness is already there without interrupts: the leak of bz is the time the enclave takes, which any attacker sees.

plugins/tiny/fixtures/leak-interrupt.spec pads the branch:

enclave { mov r0, ?; bz r0; pad r0; ret };

bz r0; pad r0 takes three cycles whatever the secret, so without interrupts nothing leaks. Learn the four models and compare, first the baseline on its own, then with interrupts against it:

Terminal window
for s in 0 1; do
_build/default/bin/alvie.exe tiny learn --spec plugins/tiny/fixtures/leak-interrupt.spec --secret $s --res /tmp/tiny/irq-$s.dot
_build/default/bin/alvie.exe tiny learn --spec plugins/tiny/fixtures/leak-interrupt.spec --secret $s --variant no-interrupts --res /tmp/tiny/irq-$s-nint.dot
done
_build/default/bin/alvie.exe tiny compare --m1 /tmp/tiny/irq-0-nint.dot --m2 /tmp/tiny/irq-1-nint.dot --secrets 0,1 --witnesses /tmp/tiny/irq-nint.dot
_build/default/bin/alvie.exe tiny compare --m1 /tmp/tiny/irq-0.dot --m2 /tmp/tiny/irq-1.dot \
--m1-baseline /tmp/tiny/irq-0-nint.dot --m2-baseline /tmp/tiny/irq-1-nint.dot --secrets 0,1 --witnesses /tmp/tiny/irq.dot
noninterference holds: 0 witnesses (see /tmp/tiny/irq-nint.dot)
noninterference does not hold: 2 witnesses (see /tmp/tiny/irq.dot)

The witnesses arm the timer with timer 2 or timer 3. With timer 2, the timer expires in the first cycle of bz for secret 0, a latency of 1, and at the end of bz for secret 1, a latency of 0: the interrupt tells the secret, as the attack of Nemesis does on Sancus.

The parameter mitigation of the manifest is an option of every command. --mitigation constant-time makes bz and pad take two cycles whatever the register:

Terminal window
_build/default/bin/alvie.exe tiny learn --spec plugins/tiny/fixtures/leak-interrupt.spec --secret 0 --mitigation constant-time --res /tmp/tiny/ct-0.dot
_build/default/bin/alvie.exe tiny learn --spec plugins/tiny/fixtures/leak-interrupt.spec --secret 1 --mitigation constant-time --res /tmp/tiny/ct-1.dot
_build/default/bin/alvie.exe tiny compare --m1 /tmp/tiny/ct-0.dot --m2 /tmp/tiny/ct-1.dot --secrets 0,1 --witnesses /tmp/tiny/ct.dot
noninterference holds: 0 witnesses (see /tmp/tiny/ct.dot)

alvie tiny property checks the other properties of the catalogue: inclusion and equivalence of two models, with a trace that shows the difference, and mCRL2 formulas (see the Executables Reference). For example, the two models without interrupts of step 6 are not equivalent:

Terminal window
_build/default/bin/alvie.exe tiny property equivalence /tmp/tiny/time-0-nint.dot /tmp/tiny/time-1-nint.dot
does not hold: a trace of /tmp/tiny/time-0-nint.dot only:
call/Enter
mov r0; 0/τ
bz r0/τ
ret/Exit[time = 4]

Hidden outputs are τ.

Steps 4 to 8 are the fixtures of Tiny, in plugins/tiny/fixtures: each is a spec with the verdict it must give. alvie tiny fixtures learns and compares them all, and checks the verdicts:

Terminal window
_build/default/bin/alvie.exe tiny fixtures --out /tmp/tiny/fixtures
PASS leak-interrupt a leak (2 witnesses)
PASS leak-time-baseline no leak
PASS leak-time a leak (3 witnesses)
PASS safe-constant-time no leak
PASS safe-no-branch no leak
5 fixtures, 0 failed (models and witnesses in /tmp/tiny/fixtures)
  • Change the enclave of a spec and predict the verdict before you check it.
  • Plugin Author Guide: Tiny is also the smallest complete plugin; the guide shows how to make your own.
  • Getting Started: the same experiment on Sancus, with its simulator.