Expand description
Precompile framework for deferred verification in the Miden VM.
This module provides the infrastructure for executing computationally expensive operations (precompiles) during VM execution while deferring their verification until proof generation.
§Overview
Precompiles enable the Miden VM to efficiently handle operations like cryptographic hashing (e.g., Keccak256) that would be prohibitively expensive to prove directly in the VM. Instead of proving every step of these computations, the VM uses a deferred verification approach.
§Workflow
The precompile system follows a four-stage lifecycle:
-
VM Execution: When a program calls a precompile (via an event handler), the VM:
- Computes the result non-deterministically using the host
- Creates a
PrecompileCommitmentbinding inputs and outputs together - Stores a
PrecompileRequestcontaining the raw input data for later verification - Records the commitment into a
PrecompileTranscript
-
Request Storage: All precompile requests are collected and included in the execution proof.
-
Proof Generation: The prover generates a STARK proof of the VM execution. The final
PrecompileTranscriptstate (sponge capacity) is a public input. The verifier enforces the initial (empty) and final state via variable‑length public inputs. -
Verification: The verifier:
- Recomputes each precompile commitment using the stored requests via
PrecompileVerifier - Reconstructs the
PrecompileTranscriptby recording all commitments in order - Verifies the STARK proof with the final transcript state as public input.
- Accepts the proof only if precompile verification succeeds and the STARK proof is valid
- Recomputes each precompile commitment using the stored requests via
§Key Types
PrecompileRequest: Stores the event ID and raw input bytes for a precompile callPrecompileCommitment: A cryptographic commitment to both inputs and outputs, consisting of a tag (with event ID and metadata) and a commitment to the request’s calldata.PrecompileVerifier: Trait for implementing verification logic for specific precompilesPrecompileVerifierRegistry: Registry mapping event IDs to their verifier implementationsPrecompileTranscript: A transcript (implemented via an RPO256 sponge) that creates a sequential commitment to all precompile requests.
§Example Implementation
See the Keccak256 precompile in miden_core_lib::handlers::keccak256 for a complete reference
implementation demonstrating both execution-time event handling and verification-time
commitment recomputation.
§Security Considerations
⚠️ Alpha Status: This framework is under active development and subject to change. The security model assumes a fixed set of precompiles supported by the network. User-defined precompiles cannot be verified in the current architecture.
Structs§
- Precompile
Commitment - A commitment to the evaluation of
PrecompileRequest, representing both the input and result of the request. - Precompile
Request - Represents a single precompile request consisting of an event ID and byte data.
- Precompile
Transcript - Precompile transcript implemented with an RPO256 sponge.
- Precompile
Verifier Registry - Registry of precompile verifiers.
Enums§
Traits§
- Precompile
Verifier - Trait for verifying precompile computations.
Type Aliases§
- Precompile
Error - Type alias for precompile errors.
- Precompile
Transcript Digest - Type alias representing the finalized transcript digest.
- Precompile
Transcript State - Type alias representing the precompile transcript state (sponge capacity word).