Reproducing the Simulation Experiments
In this guide, we build ALVIE/Sancus, run its checked-in example, and then reproduce an attack experiment.
We assume that the repository root is the current directory and that sancus-core-gap is checked out there.
Set Up the Environment
Section titled “Set Up the Environment”The Dockerfile is the reference environment, so it is the shortest path to a reproducible setup. With Docker installed, we build and start it with:
docker build -t alvie .docker run --rm -it alvieThe Dockerfile installs mCRL2 from its Ubuntu PPA on amd64 and builds it from source on arm64, so the default build works natively on both architectures.
We specify --platform only when intentionally cross-building for another architecture.
For a native setup, we need OCaml 4.13 or later (the Docker image has 4.13.1, CI uses 5.4.1), Dune, the MSP430 toolchain, Verilator, and the Sancus simulator checkout; mCRL2 only for alvie property formula.
For either setup, we verify the OCaml build before running an experiment:
cd alvie/codedune buildcd ../..Running the example
Section titled “Running the example”We begin with the checked-in example, which learns models for secret 0 and secret 1 at the final Sancus commit, both with and without interrupt handling:
rm -rf results/example counterexamples/example logs/example tmp/example./learn_example.sh./check_example.shThe learned models are in results/example/, while the witness graph is in counterexamples/example/.
We can list the exact output filenames with:
find results/example counterexamples/example -name '*.dot' -printTo inspect the witness visually, render it with Graphviz:
dot -Tpdf counterexamples/example/bf89c0b-attacker_int.dot -o example.pdfThe example test suite also runs independently:
cd alvie/codedune exec tt_attack -- test --color=neverOne attack
Section titled “One attack”For an attack experiment, we use a distinct namespace so that its models, logs, and temporary files remain together.
The third argument selects that namespace; when it does not name a directory under spec-lib/, the wrapper reads the root specifications.
B6 is a practical first experiment:
./learn_one.sh d54f031 b6 b6-sim./check_one.sh b6 b6-simThe standard fixing commits are:
| Attack | Fixing commit |
|---|---|
| B1 | e8cf011 |
| B2 | 3170d5d |
| B3 | 6475709 |
| B4 | 3636536 |
| B6 | d54f031 |
| B7 | 264f135 |
| B8, B9 | no special fixing commit |
For B8 and B9:
./learn_one_nospecial.sh b8 b8-sim./check_one.sh b8 b8-simEach standard ALVIE/Sancus attack run learns four models per relevant commit: secret 0 and secret 1, with interrupts enabled and disabled.
The comparison uses all four models and writes a witness graph under counterexamples/<namespace>/<attack>/.
Learning time varies substantially with the machine and specification, so we keep the generated namespace when comparing runs.
All attacks
Section titled “All attacks”./learn_all.sh all-sim./check_all.sh all-simThe learning wrapper launches simulator jobs in parallel, at most as many at a time as the machine has cores.
We set ALVIE_JOBS to choose a different limit (0 removes it), for example ALVIE_JOBS=8 ./learn_all.sh all-sim.
Each processor version is compiled only once: compiled simulators are kept in simv-cache inside the temporary directory, and later runs reuse them.
We set ALVIE_SIM_CACHE to use a different cache directory, or ALVIE_SIM_CACHE=0 to always recompile.
We use a machine with enough memory and disk space for the temporary VCD and program files.
Fast specifications
Section titled “Fast specifications”spec-lib/fast/ contains faster attacker specifications.
They fix the timer to one value instead of four; the enclave specification is the same.
We pass fast as the namespace to select them:
./learn_one.sh d54f031 b6 fastFast specifications are useful for development and timing experiments, but they are not equivalent to the complete attacker profiles.
Direct commands
Section titled “Direct commands”When we need to learn a single model rather than use the wrappers, we run learn.exe directly from alvie/code:
dune exec bin/learn.exe -- \ --att-spec ../../spec-lib/b6.atdl \ --encl-spec ../../spec-lib/enclave-complete.etdl \ --res /tmp/alvie-b6-s0.dot \ --tmpdir /tmp/alvie-b6 \ --sancus ../../sancus-core-gap \ --commit ef753b6 \ --secret 0 \ --oracle pacWe compare four models with:
dune exec bin/fa.exe -- \ --m1-int /tmp/model-0-int.dot \ --m2-int /tmp/model-1-int.dot \ --m1-nint /tmp/model-0-nint.dot \ --m2-nint /tmp/model-1-nint.dot \ --tmpdir /tmp/alvie-fa \ --witness-file-basename /tmp/alvie-witnessThis writes /tmp/alvie-witness_int.dot.
A nonzero violation count means the comparison found distinguishing traces under the learned models and selected threat model.
Output layout
Section titled “Output layout”results/<namespace>/: learned.dotMealy machines.counterexamples/<namespace>/: comparison witness graphs.logs/<namespace>/: stdout/stderr captured by the wrappers.tmp/<namespace>/: generated assembly, binaries, simulator files, and VCDs.
The model filename contains the Sancus commit, attacker and enclave names, secret, PAC parameters, and either int or nint.