Skip to main content

MmapProverIndex

Struct MmapProverIndex 

Source
pub struct MmapProverIndex<const FULL_ROUNDS: usize, G: KimchiCurve<FULL_ROUNDS>, Srs> {
    index: ManuallyDrop<ProverIndex<FULL_ROUNDS, G, Srs>>,
    _mmap: Arc<ReadOnlyMmap>,
}
Expand description

A ProverIndex whose large Vec<F> fields are backed by memory in a live mmap(2) region instead of owned heap allocations.

The wrapper [Deref]s to ProverIndex, so anywhere the existing prover takes &ProverIndex (e.g. ProverProof::create) it transparently accepts an MmapProverIndex as well. The file pages can be evicted by the kernel under memory pressure and re-faulted on demand.

§Lifetime and drop

The inner ProverIndex is stored in a [ManuallyDrop] because its Vec<F> fields (sid; every Evaluations.evals; lookup data when present) are constructed via Vec::from_raw_parts(mmap_ptr, len, len) and point into the mapping. Running Vec::drop on them would call dealloc on mmap memory, which is undefined behaviour.

Consequently, when MmapProverIndex is dropped, the inner ProverIndex’s owned sub-allocations (the owned gates vector, linearization, powers_of_alpha, and any LazyCache/Arc machinery) leak. This notably includes the Arc<Srs> strong count: it is never decremented, so the SRS is never freed for the life of the process even if the caller drops its own clone. The lazily-recomputed precomputations (the d4/d8 DomainConstantEvaluations, tens of MB) are likewise owned heap allocations that leak and are not reclaimed by munmap. This is acceptable for Mina’s usage pattern — proving keys are loaded once at daemon startup and held for the life of the process, so cumulative leakage is bounded and the OS reclaims everything on exit. The Arc<ReadOnlyMmap> held alongside is dropped normally, which calls munmap and releases the mmap-backed field arrays (the bulk of the on-disk key), but not the recomputed/owned allocations above.

A future refinement could replace the bulk leak with a manual per- field tear-down: pattern-destructure the ProverIndex, drop the owned fields explicitly, and mem::forget only the mmap-backed Vecs. That’s about 50 lines of unsafe and can be added without affecting the on-disk format or the public API.

Fields§

§index: ManuallyDrop<ProverIndex<FULL_ROUNDS, G, Srs>>§_mmap: Arc<ReadOnlyMmap>

Implementations§

Source§

impl<const FULL_ROUNDS: usize, G, Srs> MmapProverIndex<FULL_ROUNDS, G, Srs>
where G: KimchiCurve<FULL_ROUNDS>,

Source

pub fn madvise_dontneed(&self)

Advise the kernel that the mapped cache file’s pages are no longer needed (MADV_DONTNEED). Reads into the mapping after this call will trigger fresh page faults that re-populate from disk.

This simulates the real-world behaviour the zero-copy cache was designed for — pages evicted under memory pressure are silently re-faulted as the prover walks back through them. Used in tests (see cached_index_prove_after_madv_dontneed) to confirm that the construction doesn’t somehow keep the data pinned in RAM via a stray owned copy.

No-op on a zero-length mapping.

Methods from Deref<Target = ProverIndex<FULL_ROUNDS, G, Srs>>§

Source

pub fn verify( &self, witness: &[Vec<F>; 15], public: &[F], ) -> Result<(), GateError>

This function verifies the consistency of the wire assignments (witness) against the constraints

Source

pub fn perm_quot( &self, lagrange: &WitnessOverDomains<F>, beta: F, gamma: F, z: &DensePolynomial<F>, alphas: impl Iterator<Item = F>, ) -> Result<(Evaluations<F, D<F>>, DensePolynomial<F>), ProverError>

permutation quotient poly contribution computation

§Errors

Will give error if polynomial division fails.

§Panics

Will panic if power of alpha is missing.

Source

pub fn perm_lnrz( &self, e: &ProofEvaluations<PointEvaluations<F>>, zeta: F, beta: F, gamma: F, alphas: impl Iterator<Item = F>, ) -> Evaluations<F, D<F>>

permutation linearization poly contribution computation

Source

pub fn perm_aggreg( &self, witness: &[Vec<F>; 15], beta: &F, gamma: &F, rng: &mut (impl RngCore + CryptoRng), ) -> Result<DensePolynomial<F>, ProverError>

permutation aggregation polynomial computation

§Errors

Will give error if permutation result is not correct.

§Panics

Will panic if first element is not 1.

Source

pub fn verifier_index_digest<EFqSponge: Clone + FqSponge<G::BaseField, G, G::ScalarField, FULL_ROUNDS>>( &self, ) -> G::BaseField
where VerifierIndex<FULL_ROUNDS, G, Srs>: Clone,

Retrieve or compute the digest for the corresponding verifier index.

Source

pub fn verifier_index(&self) -> VerifierIndex<FULL_ROUNDS, G, Srs>
where VerifierIndex<FULL_ROUNDS, G, Srs>: Clone,

Produces the VerifierIndex from the prover’s ProverIndex.

§Panics

Will panic if srs cannot be in cell.

Trait Implementations§

Source§

impl<const FULL_ROUNDS: usize, G, Srs> Debug for MmapProverIndex<FULL_ROUNDS, G, Srs>
where G: KimchiCurve<FULL_ROUNDS>,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const FULL_ROUNDS: usize, G, Srs> Deref for MmapProverIndex<FULL_ROUNDS, G, Srs>
where G: KimchiCurve<FULL_ROUNDS>,

Source§

type Target = ProverIndex<FULL_ROUNDS, G, Srs>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<const FULL_ROUNDS: usize, G, Srs> Send for MmapProverIndex<FULL_ROUNDS, G, Srs>
where G: KimchiCurve<FULL_ROUNDS>, ProverIndex<FULL_ROUNDS, G, Srs>: Send,

Source§

impl<const FULL_ROUNDS: usize, G, Srs> Sync for MmapProverIndex<FULL_ROUNDS, G, Srs>
where G: KimchiCurve<FULL_ROUNDS>, ProverIndex<FULL_ROUNDS, G, Srs>: Sync,

Auto Trait Implementations§

§

impl<const FULL_ROUNDS: usize, G, Srs> !Freeze for MmapProverIndex<FULL_ROUNDS, G, Srs>

§

impl<const FULL_ROUNDS: usize, G, Srs> !RefUnwindSafe for MmapProverIndex<FULL_ROUNDS, G, Srs>

§

impl<const FULL_ROUNDS: usize, G, Srs> !UnwindSafe for MmapProverIndex<FULL_ROUNDS, G, Srs>

§

impl<const FULL_ROUNDS: usize, G, Srs> Unpin for MmapProverIndex<FULL_ROUNDS, G, Srs>
where <G as AffineRepr>::BaseField: Unpin, <G as AffineRepr>::ScalarField: Unpin, G: Unpin,

§

impl<const FULL_ROUNDS: usize, G, Srs> UnsafeUnpin for MmapProverIndex<FULL_ROUNDS, G, Srs>
where <G as AffineRepr>::BaseField: UnsafeUnpin, <G as AffineRepr>::ScalarField: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V