crates

program_argument_contract

check proofs license minimum Rust version

One read-only 4 KiB page that carries a program's argv as length-prefixed bytes. Whoever spawns the program writes it with PageBuilder, and the program's runtime reads it with ArgumentPage. no_std, no dependencies, so the writer and the reader share one definition and cannot drift on the layout.

The bytes carry no authority. The access a program holds decides what it may read or write, never what its arguments say, so nothing checks the page's bytes for meaning.

The contract

EXAMPLES

use program_argument_contract::{ArgumentPage, PAGE_BYTES, PageBuilder};

let mut page = [0u8; PAGE_BYTES];
let mut builder = PageBuilder::new(&mut page).unwrap();
for argument in [&b"rg"[..], b"ab\xffcd", b"src"] {
    builder.push(argument).unwrap();
}
assert_eq!(builder.finish(), 3);

let arguments: Vec<&[u8]> = ArgumentPage::parse(&page).iter().collect();
assert_eq!(arguments, [&b"rg"[..], b"ab\xffcd", b"src"]);

What is proven

Two Kani harnesses cover the parser, over a symbolic 48-byte page that carries the magic. parse_never_panics_and_iterates_len_items proves that parse never panics and that the iterator yields exactly len() arguments, with is_empty agreeing. a_parsed_page_holds_exactly_what_its_header_states proves that a page which parses holds exactly count arguments whose four-byte prefixes and bytes add up to total. Each has a falsification patch in falsifications/ that turns it red. the_builder_and_the_parser_round_trip_two_arguments proves that two arguments of three and two symbolic bytes, written over a 4,096-byte page of stale bytes, read back exactly as PageBuilder wrote them. Its falsification patch is in falsifications/ too. Each harness verifies in under a minute. No proof covers the caller's promise that the address names a mapped page, because Kani cannot see a mapping.

Building and testing

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

BUGS

Minimum Rust version

Rust 1.88.

License

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