Precompiles
Precompiles let Miden programs make claims about expensive computations without executing them
directly in the VM trace, while still binding those claims into the VM proof. This page covers the
VM-side mechanics: wrappers register deferred nodes, bind their digests to circuit-visible data, and
log statement digests that evaluate to TRUE. VmProof authenticates the resulting root. Deferred
execution proofs transport portable singleton witnesses; the deferred-proof semantics
define batch proving, completion, and verification.
Concrete proof-bound implementations live in the miden-precompiles crate. Their MASM support
modules are internal implementation details used by core-library facades and tests.
Data model
EidosFrame— A 4-felt node constructor(domain_tag, param0, param1, param2). The registered domain defines the meaning of all three parameters. The framework defines frames for semanticANDand opaqueCHUNKS;TRUEis a zero-digest sentinel with no frame.Node— A content-addressed(frame, payload)term in the deferred DAG. Payloads are data chunks, join child digests, pair lists oflhs_digest || rhs_digestchunks, or the frameworkTRUEsentinel.Precompile— A host implementation that owns one registered domain and decodes the structural shape for its frames. It evaluates nodes to canonical form and optionally contributes constants throughinit().PrecompileRegistry— The host/framework dispatcher for trusted precompile implementations. The type remains inmiden-coreso the framework does not depend on concrete implementations.DeferredState— Execution state that tracks registered nodes, evaluates them under the registry, and maintains the rolling deferred root. Completion consumes and releases this state.PrecompileWitness— One portable canonical root opening carried by execution outputs and deferred proofs. Decoding checks bounded canonical transport syntax; preparation validates its child-first graph, charges configured per-witness work limits, and computes commitments before native evaluation or recording import.Prover::prove_precompilesimports an owned batch directly into one Session to validate and prove the assertions.- Deferred root — A single digest public value. Each logged statement appends
Node::AND(previous_root, statement_digest)and advances the root to that node digest. The unsafeclear_deferredoperation resets it toTRUE_DIGEST(the zero word).
Lifecycle overview
- Wrapper registers nodes – Internal MASM support code stages node payloads on the operand
stack or in memory and emits
adv.register_deferred/adv.register_deferred_data. Registration stores the node in host-sideDeferredState, checks structural child closure, and evaluates the node immediately under the installed registry. - Wrapper binds digests inside the VM – Registration arguments are visible in the VM
execution trace, but the event does not constrain the host-side
DeferredStateupdate. Memory-backed registration also performs direct host reads without adding AIR accesses. The wrapper computes each proof-relevant digest with VM instructions from the exact same initial chaining word and stack payload or ordered memory chunk sequence. - Wrapper evaluates only through explicit predicates – When a wrapper uses
adv.evaluate_deferred*to obtain host-computed canonical data, it must use VM instructions to relate that advice to values established independently of it, then log a statement digest that precompile proving checks against the committed operands. log_deferredfolds a statement – The opcode expectsSTMNTat the top of the stack.STMNTmust already be registered inDeferredStateand evaluate toTRUE. One constrained Eidos compression computesROOT_NEW = Eidos::compress(DEFERRED_AND_INIT_CV, ROOT_PREV || STMNT), and host-side deferred state records the correspondingANDnode.
Clearing the accumulator in a kernel epilogue
clear_deferred reads ROOT from the top word of the operand stack and resets the rolling
deferred root to [0, 0, 0, 0] (TRUE_DIGEST) in one cycle. Native execution requires ROOT to
equal the current accumulator. The instruction fails outside the root execution context
(ctx == 0). Its stack effect is [ROOT, ...] -> [ROOT, ...]: the entire operand stack is
preserved.
Unsafe: use this instruction only inside a trusted kernel's epilogue, after a recursive verifier
has proved the exact ROOT supplied on the stack. The epilogue must bind the verifier's
statement to the same ROOT word passed to clear_deferred and must not log unverified
statements between verification and clearing. Clearing removes the claims committed by its supplied
root from the final outstanding precompile obligation; host-side evaluation is not a substitute
for proving them. The instruction itself performs no proof verification.
What the VM proof guarantees
The AIR accounts for deferred-root transitions through a multiset lookup. Each log consumes its
previous root and produces the hash-constrained next root; each clear consumes the exact ROOT
on its stack and produces zero. Boundary contributions supply the initial zero root and consume
the public final root. The lookup does not track an addition count, index, or execution order.
The AIR does not enforce native execution's chronological check against the current accumulator.
Under the hash and lookup soundness assumptions, every logged obligation is covered by a root
consumed by a clear or remains committed by the public final root. Trusted code must recursively
prove every root it clears. Clearing may discharge all logged obligations or only a subset; a
malicious prover cannot omit the remaining obligations from both the cleared roots and the final
root. Any obligations remaining in the final root still require an external precompile proof to
complete the execution proof. To establish that all obligations were settled inside the execution,
the accepting verifier must require the authenticated final root to equal TRUE_DIGEST. Tracking
the number or index of additions is unnecessary for this guarantee. See the
lookup accounting for an ordering example.
Rules for safe clearing
The root-context restriction on clear_deferred admits both top-level program code and kernel
procedures entered by syscall. To ensure every clear follows successful settlement, the
application must enforce these rules:
- Authenticate the clearing code. The accepting verifier uses the application's expected
program and kernel (
ProgramInfo, or the correspondingExecutionClaim). This prevents a prover from substituting a program or kernel that clears without verification. - Prevent direct clearing by untrusted code. Run untrusted scripts through
callordyncallin non-root contexts (ctx != 0), whereclear_deferredis rejected. - Protect indirect routes to clearing. Kernel entry points and root-context dynamic dispatch
must not let an untrusted caller bypass settlement and reach
clear_deferredunchecked. Authenticate any dispatch tables used by these paths. The VM's kernel ROM constraints already restrict syscall targets to the committed kernel; that kernel must enforce the settlement checks. - Verify the exact root before each clear. Trusted settlement code must verify a proof for
the same
ROOTword passed toclear_deferred, whether returned bylog_deferredor supplied through advice. It must use the intended recursive PVM verifier and enforce the application's proof acceptance policy, including the required security level, before executing the instruction.
Host state after clearing
Only the accumulator is reset: registered nodes, evaluation caches, and consumed execution work
remain in host state. Later logging starts from TRUE_DIGEST.
Responsibilities
- VM — Executes deferred advice events,
log_deferred, andclear_deferred, maintains the rolling deferred root, and exposes the final root as a public value. - Host / advice provider — Maintains
DeferredState, runs trusted precompile implementations, and supplies evaluation advice when wrappers request it. - MASM wrapper — Registers concrete deferred nodes and computes node and statement digests
with VM instructions from exact stack payloads or memory reads. It logs only statements that
should evaluate to
TRUE, and hides helper outputs from callers when appropriate. Proving, verification, transport, and resource policy are specified in the deferred-proof semantics.
Conventions
- Frame layout:
FRAME = [domain_tag, param0, param1, param2]. Every value is a canonicalu32. The registered domain defines the parameters; none has a framework-wide meaning. - Payload shapes are declared by the selected precompile's
decode(params). Parameter and payload semantics are validated by the owning precompile:NodeType::Dataaccepts one or more opaque 8-felt chunks. For memory-backed registration, the stack-suppliedn_chunksdetermines how many chunks are read.NodeType::Joinreadslhs_digest || rhs_digest.NodeType::PairListaccepts one or morelhs_digest || rhs_digestchunks. A domain that encodes a pair count in its parameters must check that count invalidate_payload, before insertion.
log_deferredstack effect:[STMNT, ...] -> [ROOT_NEW, ...]. The precompile wrapper dropsROOT_NEWafter the root transition has been constrained.clear_deferredstack effect:[ROOT, ...] -> [ROOT, ...]; native execution requiresROOTto match the current accumulator.- Input and memory layouts are precompile-specific. Core-library wrappers define the native formats for hash facades and for arithmetic/curve support used by signature verification.
Examples
- Hash support wrappers register the input/result nodes needed for the hash claim and log a statement digest that verifies the claimed digest.
- Signature support wrappers register the public key, precompile-specific message input, signature, and verification predicate nodes, then log the predicate statement.
Related reading
- Deferred computation – deferred DAG, wire, and proof lifecycle.
- Precompile accumulator instructions –
log_deferred,clear_deferred, and the clearing safety contract. PrecompileWitnessimplementation (core/src/deferred/wire.rs) – portable canonical opening.