Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Introduction

Fiducia is a language for building embedded applications on seL4 Microkit systems. A project describes a system of protection domains (PDs) connected by channels. Each PD’s behaviour is a CSP-style process, which calls imported C or Pancake code. From this one description the toolchain builds a bootable Microkit image, and a UPPAAL model to check the system against.

What fic implements today: the inputs, the passes, and the verification and image outputs

This manual covers installing, configuring, building, running and verifying projects. The syntax and semantics of the language are in the Fiducia Language Reference.

🚧 Fiducia is under active development; interfaces described here may change between releases.

The toolchain

ToolRole
ficThe compiler: checks a project and builds its Microkit image, or emits an intermediate form instead (see the fic reference).
fireThe project runner: reads fire.toml and drives fic. fire build writes the image and the UPPAAL model, fire run launches the image, fire verify checks the model, fire clean removes what was generated.
fic-lspThe language server the editor extension runs.

A Fiducia project

A project is a directory holding:

  • one .fis file, the system description: memory regions, protection domains, channels, and the system composition;
  • one .fi file per protection domain, its implementation: imports, memory mappings, events and processes. The file eth_outer.fi implements the PD named eth_outer;
  • the imported files: C (.c, .h) and Pancake (.pnk);
  • spec/*.q, the queries fire verify checks;
  • fire.toml, the manifest.

demo/ring/ in the repository is the smallest complete project (one buffered channel), demo/pingpong/ adds C contracts and verification, and demo/datadiode/ is a larger one, the subject of the tutorial.

Where to go next

  1. Install the tools.
  2. Follow the tutorial, a walk through the data diode.
  3. Write a fire.toml.
  4. Build and run on QEMU.
  5. Verify the model.
  6. Consult the fic reference for the compiler’s checks and emit formats.

Installation

Fiducia ships three binaries: fic (the compiler), fire (the project runner) and fic-lsp (the language server), and a VS Code extension. They are not yet published to crates.io — install the pre-built binaries from the website.

Pre-built binaries are published monthly (and on manual dispatch) to fiducia-lang.github.io/releases. Available platforms: linux-x86-64, macos-arm64.

# Download and extract (replace <version> and <platform> accordingly)
curl -fsSL -o fic.tar.gz \
  https://fiducia-lang.github.io/releases/v<version>/fic-<platform>-<version>.tar.gz
tar -xzf fic.tar.gz

# Move to a directory in your PATH (the tarball contains all three binaries)
sudo mv fic fire fic-lsp /usr/local/bin/
# Or for user-local installation
mv fic fire fic-lsp ~/.local/bin/

# Verify installation — fic and fire share one toolchain version
fic --version
fire --version

This manual and the language reference are published at fiducia-lang.github.io/docs/manual.

The Linux binaries need glibc 2.34 or newer (Ubuntu 22.04, Debian 12, Fedora 35 or later).

ℹ️ cargo install fic fire will become available once the project is published to crates.io after the language design stabilises.

libclang (for C imports)

fic reads an imported C header with libclang, which it loads when it runs, so a project that imports C needs libclang installed. Any version from 6.0 on works.

  • macOS: the Xcode Command Line Tools provide it (xcode-select --install).
  • Debian and Ubuntu: sudo apt install libclang-dev.
  • Fedora: sudo dnf install clang-devel.

If fic cannot find it, set LIBCLANG_PATH to the directory that holds libclang.so (libclang.dylib on macOS).

Editor support

The VS Code extension (also for Cursor) highlights .fis and .fi files, marks syntax errors and shows hover information. It runs fic-lsp, from the tarball above, as its language server.

curl -fsSL -o fiducia.vsix \
  https://fiducia-lang.github.io/releases/v<version>/fiducia-<version>.vsix
code --install-extension fiducia.vsix

If fic-lsp is not on your PATH, set its location in the editor’s settings:

{ "fiducia.serverPath": "/path/to/fic-lsp" }

Resolution and type errors are not shown in the editor yet; fic --check and fire build report them.

Building from source

Building needs Rust 1.92 or newer.

git clone https://github.com/fiducia-lang/fic
cd fic
rustup target add aarch64-unknown-none   # fic's build compiles its PD runtime for it
cargo install --path .       # fic
cargo install --path fire    # fire
cargo install --path fic-lsp # fic-lsp

The repository also provides a Nix flake (nix develop) that supplies the full toolchain — Rust, the Microkit SDK, and the cross-compiler — with no manual setup. See CONTRIBUTING.md.

Prerequisites for building images

Compiling a project to a bootable image (fire build, fire run, or bare fic — image generation is its default mode) needs the seL4 Microkit SDK and an AArch64 bare-metal cross-compiler.

Microkit SDK

# macOS (Apple Silicon):
curl -fsSL -o microkit-sdk.tar.gz \
  https://github.com/seL4/microkit/releases/download/2.3.0/microkit-sdk-2.3.0-macos-aarch64.tar.gz
# Linux (x86-64):
curl -fsSL -o microkit-sdk.tar.gz \
  https://github.com/seL4/microkit/releases/download/2.3.0/microkit-sdk-2.3.0-linux-x86-64.tar.gz

tar -xzf microkit-sdk.tar.gz

ARM GNU toolchain

# macOS (Apple Silicon):
curl -fsSL -o arm-gnu-toolchain.tar.xz \
  https://developer.arm.com/-/media/Files/downloads/gnu/15.2.rel1/binrel/arm-gnu-toolchain-15.2.rel1-darwin-arm64-aarch64-none-elf.tar.xz
# Linux (x86-64):
curl -fsSL -o arm-gnu-toolchain.tar.xz \
  https://developer.arm.com/-/media/Files/downloads/gnu/15.2.rel1/binrel/arm-gnu-toolchain-15.2.rel1-x86_64-aarch64-none-elf.tar.xz

tar -xJf arm-gnu-toolchain.tar.xz

QEMU (for fire run in QEMU mode)

Install qemu-system-aarch64 from your package manager (brew install qemu, apt install qemu-system-arm, …).

UPPAAL (for fire verify)

fire verify runs the UPPAAL command-line model checker verifyta. Download UPPAAL and either put verifyta on your PATH, set $VERIFYTA, or point to it from fire.toml. UPPAAL requires a (free academic) licence.

Frama-C and pancake2viper (for contracts)

A project whose imports carry contracts needs a tool to read and prove them. For C with ACSL annotations, that is Frama-C 33 with its WP plugin, and the fic-acsl plugin from the repository, which fic uses to read the contracts. For Pancake, fire verify runs pancake2viper, and building the image needs the CakeML compiler cake. The Nix flake provides all of them.

Environment variables

VariableNeeded byDescription
MICROKIT_SDKimage buildsPath to the extracted Microkit SDK. Fallback for [run.target] sdk.
GCCimage buildsAArch64 cross-compiler binary. Fallback for [run.target] gcc.
LDimage buildsAArch64 cross-linker binary. Fallback for [run.target] ld.
LIBCLANG_PATHfic, with C importsDirectory holding libclang, if it is not found on its own.
CAKE_MLimage builds with .pnk importsThe CakeML compiler binary.
FRAMACfic and fire verify, with ACSL importsThe frama-c binary (falls back to PATH).
FIC_ACSL_PLUGINfic and fire verify, with ACSL importsA fic-acsl plugin build that is not installed into Frama-C.
VERIFYTAfire verifyThe verifyta binary (falls back to PATH).
PANCAKE2VIPERfire verify, with .pnk importsThe pancake2viper binary (falls back to PATH).
PANCAKE2VIPER_CAKEfire verify, with .pnk importsThe CakeML compiler pancake2viper runs, passed to it as CAKE_ML, when it must differ from the one that builds images.
FIRE_FICfireThe fic binary fire runs (falls back to the fic beside fire, then PATH).
# Set once — add to your shell profile
export MICROKIT_SDK=<path-to-microkit-sdk>
export GCC=<path-to-arm-gnu-toolchain>/bin/aarch64-none-elf-gcc
export LD=<path-to-arm-gnu-toolchain>/bin/aarch64-none-elf-ld

A project can instead pin the first three in fire.toml’s [run.target] section.

Tutorial: a Data Diode

This tutorial walks through demo/datadiode/, a complete Fiducia project: a network data diode on seL4 Microkit. Ethernet frames enter on an untrusted (Low) network, cross one forwarding protection domain and leave on a trusted (High) network, and nothing travels back. You read the project file by file, in the order the concepts are needed, then build it, boot it in QEMU and drive it with real traffic.

host ──virtio──▶ eth_outer ──o2d──▶ dd ──d2i──▶ eth_inner ──virtio──▶ host
 (untrusted)      (Low NIC)      (diode)       (High NIC)      (trusted)

You need the tools from Installation, including its prerequisites for building images, QEMU and Python 3. The syntax of each construct is in the Fiducia Language Reference; this page links to it rather than repeat it.

1. The project

demo/datadiode/
├── fire.toml        the manifest
├── datadiode.fis    the system: regions, PDs, channels
├── eth_outer.fi     the Low NIC's PD
├── dd.fi            the diode PD
├── eth_inner.fi     the High NIC's PD
├── include/         the C headers: eth.h, which the .fi files import, and
│                    the util.h and virtio_net.h it builds on
├── src/             the C sources: eth.c, util.c, virtio_net.c
├── spec/            the queries fire verify checks
└── inject.py        the host side: sends frames, checks what comes out

Each protection domain (PD) declared in the .fis has a .fi of the same name: dd.fi implements the PD dd. A .fi imports the C headers it calls; each include/x.h is linked with its src/x.c. The project’s other C goes into one archive, from which each PD links what its C calls: eth.c calls util.c and virtio_net.c, which no .fi imports.

fire.toml names the project and says how to run it. Its [run] section is the QEMU command line: an AArch64 virt board and two virtio-net NICs on UDP sockets, which inject.py talks to. The outer NIC must be the first -device. See The Project Manifest for every field.

2. The system description

datadiode.fis describes the whole system: what each PD is, what memory exists, and how the PDs are connected. It holds no behaviour.

A struct for the frame

struct Frame {
    len: uint16;
    origin: uint8;
    data: uint8[2048];
}

const ORIGIN_OUTER: uint8 = 1;
const ORIGIN_INNER: uint8 = 2;

Frame is the value that crosses the diode. origin is the network the frame came in on, one of the two constants; the model tracks it, which is what Verify states secrecy over. A struct or constant declared in the .fis is shared by every PD and by the C code: the build writes it to include/gen/types.h, which include/eth.h includes, so C sees the same struct Frame. See Data Layer.

Memory regions

Low MemoryRegion eth_outer_output(0x200000, 0x200000);
High MemoryRegion eth_inner_input(0x200000, 0x200000);

MemoryRegion virtio_window(0x1000, 0x1000, 0xa003000);

Low MemoryRegion outer_dma(0x200000, 0x200000);
High MemoryRegion inner_dma(0x200000, 0x200000);

A region is a size, a page size and, for a device, a physical address. virtio_window is the page of QEMU’s virtio-mmio devices where both NICs sit, outer_dma and inner_dma hold each NIC’s virtio rings and buffers, and the first two back the channels below.

Each region carries a security label, Low or High. fic checks one rule over labels: a mapping of a region is labelled at least as high as the region, so High memory is never mapped into a Low context. See Information Flow. This check, like the well-formedness checks, is a placeholder: both are still under research.

Protection domains

ProtectionDomain eth_outer(99, 79);
ProtectionDomain dd(150);
ProtectionDomain eth_inner(199, 78);

A PD is a priority and, optionally, the IRQ it handles. Each NIC’s PD takes its device’s interrupt; dd touches no device.

Channels and the buffered queue

Chan o2d = eth_outer --> dd via eth_outer_output<Frame>;
Chan d2i = dd --> eth_inner via eth_inner_input<Frame>;

System = eth_outer ||| dd ||| eth_inner;

A channel connects two PDs. --> makes it one-way: eth_outer sends on o2d and dd receives, never the reverse, and no channel runs from eth_inner back towards eth_outer. That declared topology is what makes the diode one-way.

via eth_outer_output<Frame> makes o2d a buffered channel: it carries Frame values, queued in the region eth_outer_output, which is mapped into both of its PDs. A channel without via carries no value: it is a bare Microkit notification.

The queue is a ring, Lamport’s single-producer single-consumer FIFO:

  • Capacity from the region. A 16-byte header holds the two indices and a signal word, then the slots, packed. o2d’s 2 MiB region of 2052-byte Frames holds ⌊(0x200000 − 16) / 2052⌋ = 1021 frames.
  • First in, first out. The receiver takes frames in the order they were sent.
  • A send never waits. A send copies the value into the next slot and notifies the receiver if the receiver asked. If the ring is full, the value is lost and the sender goes on.
  • A receive waits while the ring is empty. When the receiver is notified, it receives until the ring is empty, so several sends behind one notification are all received. Finding the ring empty, it asks to be notified of the next send; until then, sends notify no one.

A diode wants exactly this. The Low side must never wait on the High side, and with a lossy ring it cannot: when eth_inner falls behind, d2i fills and dd drops frames, and eth_outer and dd carry on. The queue holds up to 1021 frames in flight on each hop, so a burst from the network does not drop frames as long as the PDs downstream keep up.

System lists the PDs, interleaved. The Channel Declarations reference has the precise rules.

3. The diode: dd.fi

dd is the whole diode, and the smallest PD:

@bind(microkit.init)
proc Init() {
    ready -> Skip;
}

@bind(microkit.notified)
proc Notified() {
    o2d?f -> forward -> d2i!f -> Notified();
}

evt ready: dbg("diode transport ready");

evt forward: dbg("pass o2d -> d2i");

A PD’s behaviour is a set of processes. Microkit calls two entry points on every PD, and @bind says which process each runs: microkit.init at boot, microkit.notified whenever the PD is notified.

Notified receives a frame from o2d into f (o2d?f), performs the event forward, sends f on d2i (d2i!f), and starts again. While o2d is empty, o2d?f waits: the PD returns to the kernel until eth_outer sends.

An evt is a named step of computation. Here both events only print with dbg, the lines you see on the serial console.

4. The Low NIC: eth_outer.fi

eth_outer drives a real NIC through C: imports, mappings, state, events, then processes.

import "include/eth.h" as eth;

Low Mapping vwin(virtio_window, 0x2_000_000, "rw", false);
Low Mapping dma(outer_dma, 0x2_400_000, "rw", false);

An import makes a header’s functions callable as eth.eth_poll(). A Mapping puts a region into this PD’s address space, here at fixed virtual addresses, read-write and uncached, as device memory must be. A mapping’s addresses are readable in the program: dma.paddr below is the physical address of outer_dma.

The PD’s state is a few variables, among them the frame to send:

rx: bool;
kind: int;
replied: bool;
reply_len: uint16;
frame: Frame;
nic: int;

Events call into C and update that state:

evt setup: nic = eth.eth_setup(1, dma.paddr);

evt handle_irq: eth.eth_clear_irq();

evt poll: {
    rx = eth.eth_poll();
    kind = eth.eth_pkt_kind();
}

evt stage_forward: {
    frame = eth.eth_frame(ORIGIN_OUTER);
    dbg("forward -> o2d");
}

evt send_frame.|len: uint16|: {
    eth.eth_send_frame(len);
    dbg("Packet sent to network len=", len);
}

eth_frame returns a struct Frame, the type the .fis declared, with its origin set to the argument: every frame eth_outer sends is tagged with the outer network. send_frame carries a value: send_frame.reply_len performs it with len bound to reply_len.

At boot, Init brings up the NIC and reports whether it came up, with a guarded choice: [g] P [] [h] Q runs the branch whose guard holds.

@bind(microkit.init)
proc Init() {
    setup -> ReportNic();
}

proc ReportNic() {
        [nic >= 0] nic_up -> Skip
     [] [nic < 0] nic_failed -> Skip;
}

On each interrupt, Notified handles it and starts again:

@bind(microkit.notified)
proc Notified() {
    irq?79 -> HandleRx();
    Notified();
}

proc HandleRx() {
    handle_irq -> Skip;
    Drain();
    irq!79 -> Skip;
}

proc Drain() {
    poll -> Skip;
        [rx && kind == 1] stage_forward -> o2d!frame -> Drain()
     [] [rx && (kind == 2 || kind == 3)] handle_ping -> Reply()
     [] [rx && kind == 0] Drain()
     default Skip;
}

proc Reply() {
        [replied] send_frame.reply_len -> Drain()
     [] [!replied] Drain();
}

irq?79 waits for the NIC’s interrupt and irq!79 acknowledges it; P; Q runs P, then Q. Drain reads frames until there are none: a frame for another host is copied into frame and sent on o2d, an ARP request or ping for this PD is answered on the outer network, anything else is dropped, and default ends the loop once no guard holds. Reply sends only if handle_ping built a reply: a request shorter than its headers state gets none. The send o2d!frame never waits, so a slow dd never stalls the outer NIC.

5. The High NIC: eth_inner.fi

eth_inner starts like eth_outer, with High mappings of inner_dma. Its Notified waits for either of two things:

@bind(microkit.notified)
proc Notified() {
        irq?78 -> DrainNic()
     [] d2i?f -> Deliver(f);
    Notified();
}

proc Deliver(f: Frame) {
    send_frame.f -> Skip;
}

[] without guards is an external choice: the branch whose first event happens runs. A frame on d2i is transmitted on the inner network; the NIC’s own interrupt is acknowledged, and what the inner network sends is dropped. No branch sends anything towards dd.

6. Build

$ fire build demo/datadiode/
fire: building datadiode for qemu_virt_aarch64 (debug)
  ✓ Wrote the data-layer headers to demo/datadiode/include/gen
  ✓ Parsed 1 system + 3 program files + 1 foreign module(s)
  ✓ Resolved names
  ...
  ✓ Type-checked information flow
  ✓ Checked channel dependency acyclicity (WF2)
  ✓ Built the graphs and checked them (notified: receive-headed, receives at the head only; notified and protected: guarded choices)
  ✓ Generated 3 C file(s) in demo/datadiode/build/gen
MICROKIT|CAPDL SPEC: number of root objects = 90, spec footprint = 13.32 KiB
MICROKIT|INITIAL TASK: memory size = 440 KiB
MICROKIT|LOADER: image file size = 2.69 MiB
  ✓ image: demo/datadiode/build/datadiode.img
  ...
  ✓ UPPAAL model written to demo/datadiode/build/datadiode.xta

fire build checks the project, generates C for each PD, compiles it with the imported C and builds the Microkit image; it also writes the UPPAAL model. It warns about events such as forward that only print: the model leaves dbg out, so there they do nothing. To check the project without building, run fic demo/datadiode/ --check (see the fic reference).

7. Run

Boot the image in one terminal:

$ fire run demo/datadiode/
  ✓ image up to date: demo/datadiode/build/datadiode.img
fire: launching qemu-system-aarch64
...
MON|INFO: Microkit Monitor started!
eth_inner: init
eth_inner: virtio-net up on slot 6
dd: init
dd: diode transport ready
eth_outer: init
eth_outer: virtio-net up on slot 7

and send traffic from another:

$ python3 demo/datadiode/inject.py
forward: injected 4 on outer, received 4 on inner, 4 payload-identical
ping: reply on outer
arp: reply on outer
diode: no leak (one-way upheld)
RESULT: PASS

inject.py sends four frames for a foreign host into the outer NIC and checks that they come out of the inner NIC unchanged, pings eth_outer and sends it an ARP request, and sends a frame into the inner NIC to check that it never reaches the outer one. The console shows each frame cross:

eth_outer: forward -> o2d
dd: pass o2d -> d2i
eth_inner: delivered
...
eth_outer: Packet sent to network len=58
eth_outer: Packet sent to network len=42

Exit QEMU with Ctrl-A x.

8. Verify

fire verify does two things: it proves the contracts on the project’s C with Frama-C, then checks the UPPAAL model fire build wrote against the queries in spec/.

The contracts

The model does not look inside C. What it knows of a call is the function’s ACSL contract, which for the diode is in include/eth.h:

/*@ ensures \result == 0 || \result == 1; */
bool eth_poll(void);

/*@ ensures 0 <= \result <= 3; */
int64_t eth_pkt_kind(void);

/*@ ensures \result.origin == origin; */
struct Frame eth_frame(uint8_t origin);

/*@ ensures \result == 0 || \result == 1; */
bool eth_make_reply(void);

The first two are the NIC’s input as the model sees it: on each poll a frame may or may not have arrived, of any of the four kinds, so the model explores every branch of Drain. The third says a frame carries the origin it was given, and the fourth that a request may or may not get a reply, so the model explores both branches of Reply. Frama-C’s WP proves all four on src/eth.c.

eth.c calls helpers in util.c, whose contracts in include/util.h say what each reads and writes; WP proves those on src/util.c, and that neither file’s proved functions have a runtime error. So a frame’s bytes stay inside its buffer, whatever length the device, the frame itself or the other side of the diode gives. That holds on the forward path (eth_poll, eth_frame and eth_send_frame_value) and in eth_make_reply, which answers ARP and ping. The loops need an SMT prover, Z3: fire.toml names it, and why3 must know where it is (why3 config detect; the Nix shell is set up).

One thing is assumed. fire.toml lists it under assume, and the report names it: the virtio_net.c driver, which reaches the device in ways WP does not model. eth.c’s proof uses the driver’s contracts in include/virtio_net.h as given.

eth.c copies a frame with fi_memcpy_u8, one of the memory routines fic links into every PD. fic generates their contracts in include/gen/mem.h and proves them itself, so the report lists them as EXTERNAL, not ASSUMED.

The queries

spec/datadiode.q holds seven:

A[] not deadlock

E<> dd.L2
E<> eth_inner.Deliver

A[] not (!dd.awake && q_o2d.length > 0 && !pend_o2d)
A[] not (!eth_inner.awake && q_d2i.length > 0 && !pend_d2i)

A[] not (eth_outer.frame.origin == ORIGIN_INNER || dd.f.origin == ORIGIN_INNER || (exists (i : int[0, 2]) q_o2d_val[i].origin == ORIGIN_INNER))

E<> dd.f.origin == ORIGIN_OUTER
  • No deadlock. The environment raises each NIC’s interrupt for ever, as inject.py keeps sending, so a deadlock would be a driver that never takes or never acknowledges its interrupt.
  • A frame crosses each hop. dd can reach the location after its receive on o2d, and eth_inner can reach Deliver.
  • No lost wake-up. A receiver that is waiting while its queue holds a value always has a notification pending. In the model a queue holds at most 3 values.
  • Secrecy. No Low PD, and no slot of o2d, ever holds a frame that came in on the inner network.
  • The origin travels. dd does receive a frame tagged with the outer network, so the secrecy query is not true for want of frames.
$ fire verify demo/datadiode/
fire: verifying datadiode
  ✓ Running frama-c: /usr/bin/frama-c

  ACSL: src/eth.c                                          PASS
  ACSL: src/util.c                                         PASS
  ACSL: src/virtio_net.c, 9 functions not proved           ASSUMED
      virtio_net_up, virtio_net_rx, virtio_net_tx, virtio_net_ack, ...
  ACSL: include/gen/mem.h, 6 functions proved by fic       EXTERNAL
      bcmp, fi_memcpy_u8, memcmp, memcpy, memmove, memset
  ✓ Running verifyta: /opt/uppaal/bin/verifyta
  ✓ Query file: demo/datadiode/spec/datadiode.q

  Q1  A[] not deadlock                                     PASS
  Q2  E<> dd.L2                                            PASS
  Q3  E<> eth_inner.Deliver                                PASS
  ...
  Q7  E<> dd.f.origin == ORIGIN_OUTER                      PASS

Verifying: fire verify has the options, and how a contract becomes the model’s view of a call.

Where to go next

The Project Manifest (fire.toml)

fire reads fire.toml from the project directory. It names the project, locates the sources, and says how fire build and fire run build and launch the image and how fire verify runs its verifiers.

Example

Based on demo/pingpong/fire.toml:

[project]
name = "pingpong"      # output stem: build/pingpong.img, build/pingpong.xta
src  = "."             # the .fis/.fi files, relative to this file

[run]
mode = "qemu"
# {img}: the built image.
args = [
    "-machine", "virt,virtualization=on",
    "-cpu",     "cortex-a53",
    "-serial",  "mon:stdio",
    "-device",  "loader,file={img},addr=0x70000000,cpu-num=0",
    "-m",       "size=2G",
    "-nographic",
]

[run.target]
board   = "qemu_virt_aarch64"
profile = "debug"
# sdk, gcc, ld default to $MICROKIT_SDK, $GCC, $LD.
# ping<->pong is a 2-cycle; pingpong.q decides deadlock freedom instead.
allow_wf2_cycles = true

[verify.model_checker]
mode = "verifyta"  # path defaults to $VERIFYTA, then PATH

[[verify.code_verifier]]
language = "c"  # path defaults to $FRAMAC, then PATH
args = ["-wp-rte", "-wp-prover", "qed"]

[project] — identity and sources

FieldRequiredDescription
nameyesThe output filename stem: build/<name>.img and build/<name>.xta.
srcyesThe directory holding the .fis / .fi files, relative to fire.toml. Generated files go to <src>/build/ and <src>/include/gen/; queries live in <src>/spec/.
includenoDirectories searched for the headers the imported C includes, after the project’s own; each is passed to fic as -I. $NAME and ${NAME} read the environment (an unset one is an error); a relative path is relative to fire.toml. E.g. ["$VENDOR/include", "vendor/include"].

[run] — how to launch

[run] and [run.target] are required, also by fire verify.

FieldRequiredDescription
modeyesqemu or hardware. Hardware is not implemented yet.
argsnoArguments passed to qemu-system-aarch64. {img} is replaced by the image’s absolute path.

[run.target] — board and toolchain

FieldRequiredDescription
boardyesMicrokit board, e.g. qemu_virt_aarch64: a directory under the SDK’s board/.
profileyesMicrokit build profile: debug or release. Only a debug image prints (dbg, and fic’s own lines) and reports a notification that no receive took.
sdknoThe Microkit SDK. Falls back to $MICROKIT_SDK.
gccnoThe AArch64 cross-compiler. Falls back to $GCC.
ldnoThe AArch64 cross-linker. Falls back to $LD.
allow_wf2_cyclesnoPass --allow-wf2-cycles to fic. Default false.

sdk, gcc and ld, when set, override the environment for the fic that fire runs, which pins a toolchain per project.

[verify.model_checker] — the model checker

The [verify] tables are optional, but with any of them present [verify.model_checker] is required; without them fire verify finds verifyta through $VERIFYTA or PATH and has no code verifier.

FieldRequiredDescription
modeyesThe model checker. verifyta (UPPAAL) is the only one.
pathnoThe binary. Falls back to $VERIFYTA, then verifyta on PATH.
argsnoExtra flags, after the model and query arguments.

[[verify.code_verifier]] — code verifiers

One entry per foreign language whose imports carry contracts. The model assumes those contracts, so fire verify proves them first, and fails if a project has contracts in a language with no entry.

FieldRequiredDescription
languageyes"c": Frama-C’s WP plugin proves the ACSL. "pnk": pancake2viper proves the Pancake contracts.
pathnoThe binary. Falls back to $FRAMAC / $PANCAKE2VIPER, then frama-c / pancake2viper on PATH.
argsnoExtra flags, after the verifier’s own arguments.
assumenoC only (an error on a "pnk" entry): functions Frama-C does not prove. WP skips each (-wp-skip-fct) and its callers use its contract as given; fire verify lists them on an ASSUMED row. A name that no file sent to Frama-C defines is an error. E.g. ["virtio_net_rx", "virtio_net_tx"], a device driver’s entry points.

Building and Running: fire build / fire run

fire build compiles a project to a bootable Microkit image and its UPPAAL model; fire run builds the image and launches it, as configured in fire.toml. fire clean removes what they generated.

Usage

fire build [PROJECT_DIR] [-o <IMG>] [--target <img,xta>] [--pretty]
fire run   [PROJECT_DIR] [-o <IMG>]
fire clean [PROJECT_DIR]
Argument / flagDescription
PROJECT_DIRThe directory holding fire.toml. Defaults to the current directory.
-o, --output <IMG>The image path, instead of <src>/build/<name>.img.
--target <img,xta>What fire build builds: the image (img), the model (xta), or both, the default.
--prettyAlso write the model as the UPPAAL GUI’s XML, build/<name>.xml.

What it does

  1. Reads fire.toml and resolves the source directory (project.src).
  2. Builds the image with fic <src> --board <board> --build-profile <profile>, with the toolchain from [run.target] or the environment, and the model with fic <src> --emit=xta. The image is skipped when it is newer than every source file and fire.toml, the model when it is newer than every source file (✓ image up to date: …, ✓ model up to date: …).
  3. fire run only: launches qemu-system-aarch64 with the [run] args, {img} replaced by the image’s path.

fire clean removes build/ (the image, the model, and anything the UPPAAL GUI saved beside it) and include/gen/, then include/ if that leaves it empty. It never touches the sources or spec/.

Walkthrough: ping-pong

$ fire build demo/pingpong/
fire: building pingpong for qemu_virt_aarch64 (debug)
  ✓ Wrote the data-layer headers to demo/pingpong/include/gen
  ✓ Parsed 1 system + 2 program files + 1 foreign module(s)
  ...
  ✓ Generated 2 C file(s) in demo/pingpong/build/gen
MICROKIT|CAPDL SPEC: number of root objects = 52, spec footprint = 7.55 KiB
MICROKIT|INITIAL TASK: memory size = 384 KiB
MICROKIT|LOADER: image file size = 2.64 MiB
  ✓ image: demo/pingpong/build/pingpong.img
  ...
  ✓ UPPAAL model written to demo/pingpong/build/pingpong.xta

fire run demo/pingpong/ then boots the image in QEMU; with -serial mon:stdio the PDs’ output appears in your terminal. Exit QEMU with Ctrl-A x.

The Microkit build report, build/report.txt, shows the memory layout and the values patched into each PD.

Troubleshooting

SymptomLikely cause / fix
no fire.toml in ...PROJECT_DIR has no manifest: pass the project directory, not the repository root.
Could not read MICROKIT_SDK environment variableSet $MICROKIT_SDK or [run.target] sdk. Likewise for GCC and LD.
board path '...' does not exist[run.target] board / profile is not a directory under <sdk>/board/.
failed to launch ficPut fic beside fire or on PATH, or set $FIRE_FIC.
warning: WF2 violation: channel dependency graph contains a cycleSee --allow-wf2-cycles.
C compile errorsThe C is compiled with -Wall -Werror: fix the warning in the imported file.
QEMU exits at onceCheck the [run] args loader address against the board: addr=0x70000000 for qemu_virt_aarch64.

Verifying: fire verify

fire verify checks the UPPAAL model fire build wrote against the project’s queries, with UPPAAL’s verifyta. The model assumes the contracts of the imported code, so it proves those first. It never writes the model: run fire build first, and again after a source changes.

Usage

fire verify [PROJECT_DIR] [-q <QUERY_FILE>] [-o <OUTPUT_FILE>]
Argument / flagDescription
PROJECT_DIRThe directory holding fire.toml. Defaults to the current directory.
-q, --query <QUERY_FILE>One query file, instead of every .q in <src>/spec/.
-o, --output <OUTPUT_FILE>Also save the report as plain text, even when the run fails.

What it does

  1. Reads fire.toml and resolves the source directory.

  2. Proves the imported code’s contracts with the code verifier for each language that has any: Frama-C for annotated C, pancake2viper for Pancake. Files without contracts have nothing to prove. A header’s contracts are proved on the project’s .c file of the same name, which includes it (include/eth.h on src/eth.c); an annotated header with no such source is an error. A C function named in the entry’s assume is not proved: its file gets an ASSUMED row naming it. Rows name a file by its path in the project.

    A contract can also be on a function that none of those files defines, such as a library routine. Frama-C uses such a contract at each call but cannot prove it. fire verify lists these functions in a row for the header that declares them:

    • EXTERNAL for include/gen/mem.h, the memory routines fic links into every PD. fic proves their contracts itself.
    • ASSUMED for any other header. Nobody proved these contracts.

    fic’s proof holds only for the gen/mem.h that fic generates. If the file has been changed, the run fails on a row naming it; fire build writes the file again.

  3. Reads build/<name>.xta. The --pretty XML is for the GUI only.

  4. Runs verifyta ([verify.model_checker] path, then $VERIFYTA, then PATH) on the model and each query file, asking for a trace.

  5. Prints one PASS / FAIL line per contract file and per query, and exits non-zero if any check fails, or if verifyta answered fewer queries than a file holds (a refused licence, a crash).

With -o, each part’s rows are followed by one line with the tools’ own figures. For C contracts:

verify contracts  demo: datadiode  result: PASS  files: 3  functions: 9  goals: 110/110  assumed: 9  external: 6
  • functions: the functions whose contract Frama-C proves on their body. A contract is the annotation on one function.
  • goals: the facts WP proved, of those it had to. One contract takes several goals, and -wp-rte adds one for each operation that could fail at run time.
  • assumed: the functions that are not proved, named in assume or declared by a header no proved file gives a body for.
  • external: the functions of include/gen/mem.h, which fic proves.

assumed and external are left out when they are zero, and functions when the fic-acsl plugin is not installed.

Writing queries

Which properties matter depends on the application, so fic emits only the model and you write the queries: a UPPAAL query file in <src>/spec/, part of the project’s sources.

Queries name the process instances of the model (the PD names) and their locations; a PD’s variables keep their names, and a struct’s field is pd.var.field. Read build/<name>.xta, or open the --pretty XML in the UPPAAL GUI, to find them.

Buffered channels in the model

A buffered channel c is a queue q_c holding its length (in place of the ring’s two indices), signalled (as filib’s signal word: false while the receiver asks to be notified) and capacity, plus pend_c, Microkit’s pending notification. Its values are q_c_val, oldest first. A PD that receives on one has a local awake:

  • a send that fits stores its value at q_c_val[q_c.length], adds one and, if the receiver asked, sets pend_c; on a full queue it is lost;
  • a receive needs awake && q_c.length > 0, takes q_c_val[0] and shifts the rest down;
  • at a resume point the PD parks (awake = false, asking on each buffered arm) when no arm is enabled, and wakes on a pending notification.

So A[] not (!rx.awake && q_c.length > 0 && !pend_c) states that no wake-up is lost.

An IRQ is raised by the Environment template for ever, as a test harness keeps feeding a device, and handled as seL4 handles it: a raise sets irq_N_pend, which the PD’s irq?N takes, and masks the IRQ (irq_N_masked) until the driver acks it with irq!N, so the device raises again only after the ack. What the device delivers comes from the driver’s contracts (see Contracts). The device always has a move unless a driver never takes or never acks its IRQ, so A[] not deadlock states that no driver is stuck on its IRQ. A receiver stuck on a buffered channel while others run is not a deadlock: the lost-wake-up query above catches it. Each queue holds at most 3 in the model (its capacity if smaller). A result that holds there holds of the real capacity once the small-capacity argument is proved (#601, obligation 6).

A struct in the model keeps its fields but its arrays: a .fi program never indexes one, so no guard reads it. A call whose contract fixes a field of its result (ensures \result.origin == origin) sets that field and leaves the others as they were.

That is enough for secrecy, a reachability query. demo/datadiode’s Frame carries origin, the network it came in on, which eth_frame’s contract fixes; A[] not (... dd.f.origin == ORIGIN_INNER ...) states that no frame from the inner network reaches a PD on the outer side, in any variable or queue slot.

Worked example: ping-pong

demo/pingpong/ has two PDs, ping and pong, which bounce a notification ROUNDS times over a cyclic channel (ping <-> pong) and then stop. WF2 would reject the cycle, so the manifest sets allow_wf2_cycles and spec/pingpong.q decides deadlock freedom instead:

$ fire verify demo/pingpong/
fire: verifying pingpong
  ✓ Running frama-c: /usr/local/bin/frama-c

  ACSL: pingpong.c                                         PASS
  ✓ Running verifyta: /opt/uppaal/bin/verifyta
  ✓ Query file: demo/pingpong/spec/pingpong.q

  Q1  A[] (deadlock imply ping.rounds == ROUNDS)           PASS
  Q2  E<> ping.rounds == ROUNDS                            PASS
  Q3  A[] ping.rounds <= ROUNDS                            PASS
  Q4  E<> pong.L2                                          PASS
  Q5  A<> ping.rounds == ROUNDS                            PASS

Q1 is deadlock freedom up to the intended end: the finished rally is a state where both PDs wait, so a plain A[] not deadlock would fail on it. Q5 says the rally finishes on every path.

Reading a failure

A failing query prints FAIL and, when verifyta produces one, the trace:

  Q1  A[] not deadlock                                     FAIL
    Trace (12 steps):
      ...
      ↯ stuck at: ping.L1, pong.L2

The ↯ stuck at line gives each automaton’s location in the deadlocked state, usually enough to spot the circular wait. A reachability query that fails with (property unreachable — no counterexample trace) names a state that can never be entered.

The fic Compiler

fic is the Fiducia compiler. fire drives it; run it directly to check a project, build an image with explicit flags, or inspect an intermediate form.

fic <PROJECT_DIR> --board <BOARD> --build-profile <PROFILE> [-o <IMG>]   # image (default)
fic <PROJECT_DIR> --check                                               # checks only
fic <PROJECT_DIR> --emit=<FORMAT> [-o <PATH>]                           # an intermediate form

PROJECT_DIR is a project directory.

By default fic compiles the project to a bootable Microkit image, <project>.img (default output paths are in the project directory and named after it): it runs the checks below, generates each PD’s C, compiles and links it with the imported code, and packs the loader, the seL4 kernel and the PD ELFs into the image. This needs --board, --build-profile and the toolchain.

With --check, fic runs the checks only. It writes nothing but the data-layer headers (include/gen/) that a project’s imported code reads:

$ fic demo/ring/ --check
  ✓ Parsed 1 system + 2 program files + 0 foreign module(s)
  ✓ Resolved names
  ✓ Resolved mapping vaddrs
  ✓ Built the resolved AST
  ✓ Built the typed AST
  ✓ Checked process bodies (tail references)
  ✓ Bound the kernel entry points of every protection domain
  ✓ Built the graphs and checked them (notified: receive-headed, receives at the head only; notified and protected: guarded choices)
  ✓ Type-checked information flow
  ✓ Checked channel dependency acyclicity (WF2)

--emit formats

--emit writes an intermediate form instead of the image:

FormatOutput (default)Description
rawaststdoutThe parsed syntax tree as JSON, before name resolution.
aststdoutThe syntax tree as JSON, after the front end’s checks.
raststdoutThe resolved tree as JSON: every name an id, vaddrs allocated.
taststdoutThe typed tree as JSON: every declaration typed, constants folded.
ccfgstdoutThe graphs as JSON: per program, one graph per entry point.
c<project>/build/gen/The generated C, one file per PD; -o names the directory.
dot<project>.dotThe topology as a Graphviz graph: dot -Tpng <project>.dot -o <project>.png.
xta<project>.xtaThe UPPAAL model, as the text verifyta reads. With --pretty, the same model as the XML the UPPAAL GUI opens, <project>.xml. Queries are yours to write: see fire verify.

Only --check and the image run WF2.

Well-formedness

The Lean model’s flattening theorem assumes the checks below. All but the tail references and the Sync receives are warnings: a finding is a program the theorem does not cover, not a rejected one. The receive checks read the graph of the process bound to microkit.notified, every process it reaches unfolded. The choice check reads the bodies of the processes bound to microkit.notified and microkit.protected, each choice on its own guards. Init is not checked.

The head is the steps an invocation starts with, through [], the left of ; and a called process. There every branch is a receive, and the message picks the branch, and a branch is a receive, not a call. Everywhere else the guards decide, each choice by its own: guards above a ; do not decide the choice after it.

default is sugar: ρ₁ [] … [] ρₙ default ρ is ρ₁ [] … [] ρₙ [] [¬(b₁ ∨ … ∨ bₙ)] ρ, the bᵢ the other branches’ guards (true when unguarded).

CheckFinding
Tail references (tailRec)Error. A process references one being lowered in non-tail position.
Receive-headed notified (recvHeaded)The head has a guard or a step that is not a receive, in a notified that receives.
Receives at the headA receive or IRQ await outside the head; two at the head on one channel or IRQ.
Sync receives in protectedError. The protected head is not unguarded Sync receives, one per channel; a receive or IRQ await after it; a Sync receive in init or notified.
Channel dependency (WF2)The channels form a cycle; --allow-wf2-cycles skips the check.
Guarded choicesOutside the head, per choice: an unguarded branch, two branches that can both be enabled, or a state where none is. At the head: a branch that is a call.

A program with a finding in either receive row is outside the deadlock freedom fic guarantees, and the warning says so.

Guards are decided over bool variables, foreign calls (opaque, equal calls equal) and comparisons with constants at the variables’ widths. A warning can be spurious; a clean result is a proof. Unlike the Lean model’s Wf3, every pair of branches is compared, and a branch need not start with an event: [g] e -> P [] [!g] Skip is decided.

Options

--check

Run the checks only. Conflicts with --emit.

-o, --output <PATH>

The output path, instead of the default for the image or the emit format.

-I, --include <DIR>

A directory searched for the headers that imported C files #include, after the project directory and its include/ (repeatable, in order). The C reader, Frama-C and the image build’s compiler all search it. fire passes each project.include entry this way.

--board <BOARD>, --build-profile <PROFILE>

Required for the image: the Microkit board (e.g. qemu_virt_aarch64) and build profile (debug or release), a directory under $MICROKIT_SDK/board/.

--pretty

With --emit=xta: write the model as the UPPAAL GUI’s XML.

--allow-wf2-cycles

Skip the WF2 check. WF2 rejects every cyclic channel dependency graph, including systems that are deadlock-free (e.g. the asymmetric dining philosophers, Hoare CSP §2.5.4, or demo/pingpong’s ping <-> pong). Without the flag, a cycle is a warning and the build goes on. Use it when deadlock freedom is established another way, typically by fire verify on the model.

Language server

The Language Server Protocol server is a separate binary, fic-lsp (analogous to rust-analyzer vs rustc), built from the fic-lsp workspace crate and used by the editor integrations under editors/. It ships in the release tarball beside fic and fire (see Installation); it speaks LSP on stdio.

Environment variables

See Installation.

Diagnostics

Errors and warnings are rendered as annotated source snippets, pointing at the .fis / .fi source: parse errors, duplicate names, undeclared references, vaddr misalignment and overlaps, information-flow violations, and the well-formedness findings.

Exit status

fic exits 0 on success, warnings included, and non-zero on any error, so it is safe to use in scripts and CI.

Glossary

Design vocabulary used across the fic issues, the papers and the compiler source. Use these terms in new issues, PRs and docs.

orchestration — the generated per-PD code that owns the event loop and all communication: the init()/notified()/protected() bodies, channel dispatch, and every microkit_*/seL4_* call, lowered from the .fi process algebra via the Ccfg. Matches the Orchestration IR type (src/ccfg/system.rs, one per PD) and src/ast/process.rs’s own framing (“a process is the orchestration layer of a Fiducia protection domain”). The orchestration communicates; foreign functions compute.

foreign implementation — one imported unit of non-Fiducia code (a .h/.c or .pnk file, one per import declaration in a .fi program; .rs has no reader yet). Never abbreviate to “FI” — it collides with the .fi file extension, which names the orchestration source, i.e. the opposite side of the boundary.

foreign function — an individual callable inside a foreign implementation, reached from a computation event (alias.fn(...)). Matches standard FFI (“foreign function interface”) usage. Use “foreign implementation” for the unit, “foreign function” for the call.

Ccfg — Communicating Control-Flow Graph: the compiler IR between the typed AST and all backends (src/ccfg/). One Ccfg per bound entry point; locations are bare control points; transitions carry a guard and an event, both the typed AST’s nodes. All semantic lowering happens once, into the Ccfg; backends are emitters over it.

emitter — any backend that walks the Ccfg and produces target text (XTA, C). The second half of the lower once / emit many split, matching src/c_backend/, src/xta_backend/ and the --emit= flags. The invariant with teeth: emitters make syntax decisions only — if a backend needs semantic information the Ccfg does not carry, fix the IR, not the backend.

extraction — reserved for the verified emitter path: producing executable code whose correspondence to the mechanised semantics is anchored by proof (an eventual Pancake emitter, once the unfold(Ccfg) ≈ llts correspondence exists). Do not use it for today’s unverified C emission — the word’s job is to distinguish the path that carries a proof from the ones that don’t.

transpiling — whole-language, source-to-source translation between surface languages (Fiducia→Pancake as a standalone translation; pancake2viper). Not the right word for Ccfg backends: emitting a verification model isn’t transpiling, and compiling direct to a binary is precisely not source-to-source.

llts — Local Labelled Transition System: a concept from the CoreFi paper, mechanised in fidus/CoreFi/{Llts,Glts}.lean, capturing CoreFi’s small-step semantics. The compiler has no llts of its own; its closest counterpart is the Ccfg.