Skip to content
You are reading the current documentation of ALVIE: 2026.10. Other versions: development version, 2026.09 (extended documentation), 2026.09 (as released)

Reading and Checking a Witness

New

This guide shows how to read the result of a comparison and how to check a witness. It uses the Getting Started example, so run that example first. The How ALVIE Works page explains the terms.

The commands run from the repository root, unless a step says otherwise. In the Docker image, the repository root is the start directory.

The comparison tool prints the number of distinguishing traces. It prints this number only in debug mode.

  • check_one.sh and check_all.sh use debug mode. They save the count in logs/<namespace>/compare-<commit>-<attack>.log.
  • check_example.sh does not use debug mode. Its log is empty.

For an attack run, read the count from the log:

For example, after ./check_one.sh b6 b6-sim, run:

Terminal window
grep "Results" logs/b6-sim/compare-*.log

The line looks like this:

=== Results: found 49 FA violations. See …/ef753b6-b6_int.dot for details.

For the example, run the comparison again with --debug.

Terminal window
alvie/code/_build/default/bin/fa.exe \
--m1-int results/example/bf89c0b-attacker-enclave-0-0.01-0.01.dot \
--m2-int results/example/bf89c0b-attacker-enclave-1-0.01-0.01.dot \
--witness-file-basename /tmp/example-witness \
--tmpdir /tmp/alvie-fa \
--debug

The example reports found 1 FA violations. Without --debug, the tool writes the witness file and prints nothing. You can also look at the witness file. A witness with at least one transition contains lines with ->:

Terminal window
grep -c -- '->' counterexamples/example/bf89c0b-attacker_int.dot
CountMeaning
0No difference found. The witness file contains one state and no transitions.
1 or moreThe tool found differences. Open the witness file.

The count is the number of traces, not the number of vulnerabilities. The option --cex-limit caps it.

Convert the witness to a PDF:

Terminal window
dot -Tpdf counterexamples/example/bf89c0b-attacker_int.dot -o example-witness.pdf

Open the PDF. If you cannot open it, read the file as text. Each transition is one line that starts with two state numbers.

A witness graph shows the paths of both models in one drawing.

StyleMeaning
Black, dashedA path of the secret 0 model. Paths that both models share are also black.
Red, dottedA path of the secret 1 model.

Start at the initial state. Follow the black path. The red path leaves the black path at the point where the two models first give different outputs.

Each transition has a label in this form:

input / output (k = …, gie = …, umem_val = …, reg_val = …, timerA_counter = …, mode = …)

Example:

ubr/Time (k = 7, gie = false, umem_val = 0, reg_val = 0, timerA_counter = 9, mode = PM)
PartMeaning
ubrThe input that ALVIE sent.
TimeThe kind of output. See the Log and Output Reference.
kThe number of clock cycles of this step.
gieThe global interrupt enable bit.
umem_valThe value of the observed unprotected memory cell.
reg_valThe value of register r4, reduced to 3 bits.
timerA_counterThe value of the hardware timer that the attacker can read.
modePM if the CPU runs protected code. UM if it runs unprotected code.

The secret appears in some inputs. For example, cmp #0, r4 is the enclave instruction cmp ?, r4 with secret 0.

Compare the black and red paths step by step. Stop at the first step where the output is different.

In the Getting Started example, the two paths separate at the secret comparison:

black: cmp #0, r4 / Time (k = 1, …, timerA_counter = 2, mode = PM)
red: cmp #1, r4 / Time (k = 1, …, timerA_counter = 2, mode = PM)

The outputs are equal here, so this step is not the difference. The inputs differ only because the secret is in the input.

The next steps show the difference:

black: ubr / Time (k = 7, …, timerA_counter = 9, mode = PM)
red: ubr / Time (k = 2, …, timerA_counter = 4, mode = UM)

For secret 0, the enclave runs 7 cycles. For secret 1, it runs 2 cycles. The attacker reads the timer and learns the secret.

The exact cycle numbers can change with the toolchain and the ALVIE version. The difference between the two paths is the important part.

6. Decide what kind of difference you have

Section titled “6. Decide what kind of difference you have”

Use this table to classify the first different output.

What differsLikely cause
k or timerA_counterA timing leak. The secret changes the execution time.
umem_valA value written to unprotected memory depends on the secret.
reg_valA register value that depends on the secret reaches the attacker.
The kind of output (for example Reset against Time)The secret changes the control flow or causes a reset.
gie or modeThe secret changes the interrupt state or the CPU mode.

Next, decide whether the leak is a program flaw or an architecture problem.

  • Four-model comparison. The tool has already removed the differences that exist without interrupts. What remains needs interrupts. It is more likely an architecture problem.
  • Two-model comparison. The Getting Started example uses only two models. A difference can be a program flaw. The enclave in that example is unbalanced on purpose (ubr), so its witness is a program flaw.

Then check whether the witness is expected. Some processor commits still have known problems. The Attack Catalogue lists them. For example, the last Sancus commit bf89c0b still reports violations because of the known issues V-B8 and V-B9.

Replay a witness to confirm it on the simulator. You need the exact inputs. The learned model files contain them in S-expression form.

  1. Open the learned model for secret 0, for example results/example/bf89c0b-attacker-enclave-0-0.01-0.01.dot. Find the transitions along the witness path. Each label starts with the input:

    0 -> 6 [label="((IAttacker(CStartCounting 256))(((OTime(…)))()5))", …
  2. Write the inputs into a file, one after the other, inside one pair of parentheses. The command below also makes a second file for secret 1. It changes S_IMM 0 to S_IMM 1:

    Terminal window
    cat > /tmp/trace0.sexp <<'EOF'
    ((IAttacker(CStartCounting 256))
    (IAttacker(CCreateEncl(enc_s enc_e data_s data_e)))
    (IAttacker(CJmpIn enc_s))
    (IEnclave(CInst(I_CMP(S_IMM 0)(D_R(R 4)))))
    (IEnclave CUbr))
    EOF
    sed 's/S_IMM 0/S_IMM 1/' /tmp/trace0.sexp > /tmp/trace1.sexp
  3. Run exec.exe from alvie/code, once for each secret:

    Terminal window
    cd alvie/code
    for secret in 0 1; do
    echo "secret $secret:"
    _build/default/bin/exec.exe \
    --sexp-input /tmp/trace$secret.sexp \
    --att-spec ../../spec-lib/example/attacker.atdl \
    --encl-spec ../../spec-lib/example/enclave.etdl \
    --secret $secret \
    --commit bf89c0b \
    --tmpdir /tmp/alvie-exec$secret \
    --sancus "$PWD/../../sancus-core-gap"
    echo
    done
    cd ../..

The input must match the secret. If the file has S_IMM 0 and you pass --secret 1, the specification does not allow the input. The tool shows a † output.

The tool prints one bracket group for each input. For this trace, the last group is different:

secret 0:
[SCt][Ct][Iti][=t][Uto]
secret 1:
[SCt][Ct][Iti][=t][Uo]

The two input files differ only in the secret, and the outputs of the last input differ. This confirms the witness. Add --debug to see the full payload of each step.

See the Log and Output Reference for the meaning of the symbols.

A known-answer check shows that your setup produces correct results. The repository contains learned models for the known attacks. The comparison of these models is fast, because it does not run the simulator.

Run fa.exe on the checked-in B6 models:

Terminal window
mkdir -p /tmp/alvie-kat
alvie/code/_build/default/bin/fa.exe \
--m1-int results/ef753b6-b6-enclave-complete-0-0.01-0.01-int.dot \
--m2-int results/ef753b6-b6-enclave-complete-1-0.01-0.01-int.dot \
--m1-nint results/ef753b6-b6-enclave-complete-0-0.01-0.01-nint.dot \
--m2-nint results/ef753b6-b6-enclave-complete-1-0.01-0.01-nint.dot \
--witness-file-basename /tmp/alvie-kat/b6 \
--tmpdir /tmp/alvie-kat/tmp \
--debug

The expected counts for the checked-in models are:

AttackOriginal commit ef753b6Last commit bf89c0b
B13306
B336196
B6496

If your counts are different, check the build and the mCRL2 installation first. See Troubleshooting.

A finding is more useful when another person can reproduce it. Keep these items:

  • The commit label and the specification files.
  • The learn.exe options, mainly the oracle and its limits.
  • The four learned models and the witness file.
  • The replay file and the output of both replays.

ALVIE shows that a difference exists. It does not say how to fix it. Use the witness and the replay to find the cause in the design.

If you think ALVIE gives a wrong result, open a bug report and attach these items.