Documentation Index
Fetch the complete documentation index at: https://mintlify.com/risc0/risc0/llms.txt
Use this file to discover all available pages before exploring further.
risc0-binfmt
Therisc0-binfmt crate manages formatted binaries used by the RISC Zero zkVM, including ELF parsing, memory image construction, and image ID computation.
Installation
Overview
This crate provides low-level utilities for working with zkVM binaries:- ELF file parsing and loading
- Memory image construction
- Image ID computation (program identity)
- System state serialization
- Exit code handling
Most users don’t need this crate directly. Use
risc0-zkvm which handles binary formats automatically.Feature Flags
Enables standard library support (enabled by default).
Enables random number generation utilities.
Core Functions
compute_image_id
Compute the image ID of a combined user + kernel ELF binary.Parameters:
blob: Combined ELF binary (user program + kernel)
compute_kernel_id
Compute the kernel ID from a combined binary.Parameters:
blob: Combined ELF binary
Binary Types
Program
Represents a parsed ELF program.Fields:
entry: Program entry point addressimage: Memory image with loaded segments
ProgramBinary
Combined user program and kernel binary.
Create a combined binary from user and kernel ELFs.Example:
ProgramBinaryHeader
Header for combined binary format.Contains metadata about the binary including version and ABI information.
AbiKind
ABI version for the binary.
Memory Image
MemoryImage
Represents the zkVM memory layout.
Represents a memory page.
Start address for kernel code.
Address Types
ByteAddr
Byte-aligned address.
WordAddr
Word-aligned address (4-byte alignment).
Exit Codes
ExitCode
Program exit status.Variants:
Halted(code): Program terminated with exit codePaused(code): Program paused (for host interaction)SystemSplit: Segment boundary (internal)
Error when exit code is invalid.
System State
SystemState
Complete zkVM system state.Fields:
pc: Program countermerkle_root: Root of memory Merkle tree
Error during state decoding.
SHA Half Encoding
Write digest as 16-bit halves.
Read digest from 16-bit halves.
Hashing
Digestible
Trait for types that can be hashed.
Tagged Hashing
Create tagged hash of struct fields.
Create tagged hash of list items.
Cons operation for building tagged lists.
Create tagged hash from iterator.
Proof-of-Work
PovwNonce
Proof-of-work nonce.
Proof-of-work job identifier.
Proof-of-work log identifier.
Examples
Computing Image ID
Creating Combined Binary
Working with Memory Images
Handling Exit Codes
System State Serialization
Tagged Hashing
Address Conversion
Binary Format
The combined binary format:- Header: Version, ABI kind, sizes
- User Program: User ELF binary
- Kernel: Kernel ELF binary
- Metadata: Additional program info
Image ID Computation
The image ID is computed by:- Loading the user ELF into memory
- Computing Merkle tree of memory pages
- Hashing program metadata
- Combining into final digest
- Deterministic (same program = same ID)
- Unique (different programs = different IDs)
- 256-bit security