Expand description
mmap-backed proving-key cache.
The cache file is a self-describing binary layout:
- File magic + format version + ark-ff version + identifier.
- Fixed-size
ScalarHeaderholding all small POD metadata (public input count, zk_rows, domain sizes + generators, endo, shift, etc.). - A section table pointing at variable-length POD payload sections (sid, pruned gates, column evaluation arrays, lookup arrays).
The readable side MmapProverIndex holds an Arc<ReadOnlyMmap> plus
precomputed slice references into the mapping. Field-element accesses do
not allocate; the OS page cache handles eviction under pressure.
Only available with the mmap_cache feature.
Structsยง
- Feature
Flag Bits - Feature-flag bits packed into
ScalarHeader::feature_flags. - Lookup
Parts ๐ - Validated, not-yet-materialised lookup sections gathered during the
readerโs validation phase. The
&[u8]descriptors borrow the mmap; the owned runtime-table data is parsed eagerly (it is not mmap-backed). All of this is turned into aLookupConstraintSystemin the infallible materialisation phase so no mmap-backedVecis built before validation completes._descfields are(bytes, element_count). - Lookup
Selector Bits - Bits indicating which optional
LookupConstraintSystemsections are stored, packed intoScalarHeader::lookup_selectors_present. - Mmap
Prover Index - A
ProverIndexwhose largeVec<F>fields are backed by memory in a livemmap(2)region instead of owned heap allocations. - Optional
Selector Bits - Bits indicating which optional column-evaluation selectors are stored.
- Preamble
- Parsed preamble data, returned to the reader along with the tail slice.
- Pruned
Gate - A gate record stripped down to the fields the prover reads at prove
time: type tag and wire targets. Coefficients are deliberately omitted
because they are folded into
ColumnEvaluations::coefficients8at key generation time. - Pruned
Wire - On-disk form of
crate::circuits::wires::Wire: 4-byte row, 4-byte col. - Read
Only ๐Mmap - Minimal read-only
MAP_SHAREDmmap wrapper built on libc. Keeps the feature flag self-contained (no externalmemmap2crate required in the kimchi-stubs vendored registry) and matches the subset of behavior we need: open file, map read-only, munmap on drop. - Scalar
Header - Fixed-size header holding all scalar-valued metadata.
- Section
Entry - One entry in the section table.
- Write
Context ๐ - Context tracked during a cache-write to record sections in parallel with the growing payload buffer.
Enumsยง
- Cache
Error - Errors surfaced by the cache read/write paths.
- Section
Tag - Tags identifying the different payload sections in the section table. Tag values are stable across format versions within the same major version and must never be reused for a different meaning.
Constantsยง
- ARK_
FF_ VERSION - The ark-ff version string recorded in cache files produced by this binary. Read back at open time and compared to the readerโs version; mismatched readers reject the file rather than silently corrupting.
- ARK_
FF_ VERSION_ MAX_ LEN - Maximum length of the ark-ff version string recorded in the header.
- FIELD_
ELEMENT_ BYTES - Size of one field element on disk: four little-endian
u64limbs of Montgomery representation. - FILE_
MAGIC - Magic bytes at file offset 0. Distinct from any existing cache format in the Mina stack so a wrong file is rejected immediately.
- FORMAT_
VERSION - Current on-disk layout version. Bump on any incompatible change.
- IDENTIFIER_
MAX_ LEN - Maximum length (in bytes) of the caller-supplied identifier stored in the file header. Sized to comfortably accommodate sha512 hex (128 bytes) plus a caller prefix. Stored length-prefixed inside a fixed-size field so the header layout is constant regardless of identifier length.
- PREAMBLE_
SIZE - Byte offset (from file start) of the
num_sectionsu32 in the fixed preamble. Callers outside this module shouldnโt need this, but tests sometimes do. - PRUNED_
GATE_ SIZE - Byte size of one pruned gate record on disk. Must match
write_pruned_gateexactly. - SECTION_
ALIGNMENT - Alignment (in bytes) applied to every payload section.
BigInt<4>(fouru64limbs) only needs 8-byte alignment for zero-copy&[F]casts viafrom_raw_parts; 32 is a conservative choice that comfortably covers it and matches the field elementโs on-disk size. - SECTION_
TABLE_ OFFSET - Total file offset at which the section table begins (immediately after
the
ScalarHeader).
Functionsยง
- align_
up - Rounds
nup to the nearest multiple ofSECTION_ALIGNMENT. - alignment_
padding - Padding required after a byte-run of length
nto reach section alignment. - coefficient_
tag - Returns the section tag for the
i-th coefficient column (0..COLUMNS). - field_
to_ limbs - Returns the four LE u64 Montgomery-form limbs underlying
f. - fixed_
region_ ๐size - Computes the total bytes consumed by the fixed preamble +
ScalarHeader - gate_
type_ ๐from_ tag - gate_
type_ ๐to_ tag - limbs_
to_ field - Reconstructs a field element from its four LE u64 Montgomery-form
limbs. Inverse of
field_to_limbs; see that functionโs docstring for the layout assumptions. - mmap_
field_ ๐ โvec_ unchecked - Zero-copy: constructs a
Vec<F>whose backing storage is the mmap region itself, viaVec::from_raw_parts(mmap_ptr, len, len). - pack_
feature_ ๐flags - pad_
string ๐ - Encodes
sinto a fixed-size zero-padded field. Errors ifsis longer thanmax. - permutation_
coefficient_ tag - Returns the section tag for the
i-th permutation coefficient column (0..=6). - read_
cache - Reads a cache file produced by
write_cacheand returns anMmapProverIndex: aProverIndex-compatible wrapper whose bulkVec<F>fields are backed by the mmapโd file rather than heap copies. - read_
exact ๐ - read_
preamble ๐ - read_
pruned_ ๐gate - read_
u32_ ๐le - read_
u64_ ๐le - unpack_
feature_ ๐flags - unpad_
string ๐ - Reads a zero-terminated UTF-8 string from a fixed-size field.
- validate_
field_ ๐section - Validates that
bytesholds exactlycountfield elements, i.e. thatbytes.len() == count * FIELD_ELEMENT_BYTES. Purely a check โ constructs nothing โ so it is safe to call in the readerโs fallible validation phase before any mmap-backedVecexists.tagis only used for the error. - write_
cache - Writes a proving index to
pathin the mmap cache format. - write_
field_ ๐slice - Serializes a slice of field elements as contiguous little-endian u64
limbs. Output length is
elements.len() * FIELD_ELEMENT_BYTES. - write_
preamble ๐ - write_
pruned_ ๐gate - write_
u32_ ๐le - write_
u64_ ๐le