crates

terminal_contract

check proofs license minimum Rust version

The request and reply words of a terminal that serves its clients over a message-passing call. no_std, no dependencies, no unsafe. The terminal, its clients, its input driver and its supervisor share this one definition, so none of them can drift from the others.

The crate is the wire half only. It carries the operations, the reply flags, the badges that limit what a copy of the terminal's endpoint may ask, and the messages a supervisor uses to swap one terminal for another. The line editor that serves the words lives elsewhere, so a kernel or a client links the words without linking the editor.

The protocol

EXAMPLES

use terminal_contract::{
    admits, decode, req, BAD_REQUEST, OPERATION_QUIESCE, OPERATION_WRITE, SUPERVISOR_BADGE,
};

// A client asks the terminal to print five bytes from its output page.
let word = req(OPERATION_WRITE, 5);

// The server takes the word apart, refusing any reserved bit, and checks the badge.
assert_eq!(decode(word), Some((OPERATION_WRITE, 5)));
assert_eq!(decode(word | 1 << 40), None); // answered with BAD_REQUEST
assert!(admits(0, OPERATION_WRITE));

// Only the supervisor's copy may quiesce the terminal.
assert!(!admits(0, OPERATION_QUIESCE));
assert!(admits(SUPERVISOR_BADGE, OPERATION_QUIESCE));
assert_eq!(BAD_REQUEST, u64::MAX);

What is proven

Three Kani harnesses in src/verification.rs hold for every input, not a sample:

Each harness has a patch in falsifications/ that breaks the code it checks and turns that harness red. The unit tests also pin the wire values of the flags and the identity, and the doctests run the examples above.

Building and testing

cargo test
rustup target add x86_64-unknown-none aarch64-unknown-none-softfloat riscv64imac-unknown-none-elf
cargo build --lib --target x86_64-unknown-none   # also aarch64-unknown-none-softfloat, riscv64imac-unknown-none-elf

Run rustup target add once, before the first bare-metal build. The tests need no terminal: they check the words alone. A test that drives a real terminal over these words lives with the program that serves them.

Running the proofs

Install Kani 0.68.0, the version CI uses, with cargo install --locked kani-verifier --version 0.68.0, then cargo kani setup, which downloads a model checker and so needs network access. After that, cargo kani runs the three harnesses in a few seconds once the crate compiles. A passing run also prints checks marked UNREACHABLE and an internal error: entered unreachable code description, which are checks proved unreachable. Only the final line, Complete - 3 successfully verified harnesses, 0 failures, 3 total., matters. To run one harness, use cargo kani --harness verification::admits_follows_the_documented_badge_table --exact.

To replay one falsification patch:

git apply falsifications/verification.admits_follows_the_documented_badge_table.patch
cargo kani --harness verification::admits_follows_the_documented_badge_table --exact   # ends VERIFICATION:- FAILED
git checkout -- src

BUGS

Minimum Rust version

Rust 1.88. To check it:

rustup toolchain install 1.88 --profile minimal --target x86_64-unknown-none
cargo +1.88 test
cargo +1.88 build --lib --target x86_64-unknown-none

License

Licensed under either of MIT (LICENSE-MIT) or Apache-2.0 (LICENSE-APACHE), at your option.