This directory contains the Mina SNARK worker library implementation. The SNARK worker is responsible for generating zero-knowledge proofs (SNARKs) required by the Mina protocol.
The SNARK worker operates as either:
- An integrated service within the Mina daemon
- A standalone process (see the
standalone/directory)
SNARK workers generate proofs for transactions and receive fees for their work, creating an economic incentive for proof generation in the Mina network.
The SNARK worker follows a simple polling loop:
-
Request work – The worker calls
Get_workRPC on the daemon to obtain aSpec.Partitioned.t. The daemon's work partitioner partitions pending scan-state jobs into individually-provable chunks before handing them out. -
Generate proof –
Prod.Impl.perform_partitioneddrives the actual proof generation. Depending on the configured proof level it either:- Runs the full SNARK prover (
Transaction_snark) for aSinglespec or aSub_zkapp_commandsegment/merge spec, or - Returns a dummy proof when the proof level is
CheckorNo_check.
- Runs the full SNARK prover (
-
Submit result – The worker calls
Submit_workRPC on the daemon with the completedResult.Partitioned.t. The daemon's work partitioner combines partial sub-zkapp results and, once a full work unit is assembled, adds it to the snark pool. -
Report failures – If proof generation fails, the worker calls
Failed_to_generate_snarkRPC so the daemon can reassign the work to another worker.
The worker retries all RPC calls with jitter-based back-off. When no work is available it naps for a randomised interval to avoid busy-polling.
Prod.Impl.Worker_state.t is created once at startup and holds:
- The proof-level variant (
Full,Check, orNo_check) together with the instantiatedTransaction_snarkmodule. - A proof-cache database (
Proof_cache_tag.cache_db) for storing intermediate ZK-app segment proofs to disk, avoiding out-of-memory issues for large ZK-app commands. - Logger and signature-kind configuration.
snark_worker.ml– Top-level module re-exporting RPCs, entry point, and the production implementation.intf.ml– Legacy interface signatures (Work_S/Rpcs_versioned_S) from the original RPC design. The current RPC protocol is defined in the individualrpc_*.mlmodules usingSpec.Partitioned/Result.Partitionedtypes.prod.ml– Production implementation:Worker_statecreation and theperform_partitioned/perform_singleproof-generation functions.entry.ml– Themainpolling loop and thecommand_from_rpcsCLI command used by the integrated worker.events.ml– Structured-log event definitions.rpc_get_work.ml– Versioned RPC definition for requesting work from the daemon.rpc_submit_work.ml– Versioned RPC definition for submitting completed proofs to the daemon.rpc_failed_to_generate_snark.ml– Versioned RPC definition for reporting proof-generation failures.
For information about the standalone SNARK worker executable, see the standalone README.
The library is primarily used:
- Internally by the Mina daemon (
entry.ml/command_from_rpcs) to run an integrated SNARK worker process. - By external SNARK workers that connect to a Mina daemon via the versioned RPC protocol to perform proof generation independently.
SNARK workers communicate with the Mina daemon via versioned RPCs:
| RPC | Direction | Purpose |
|---|---|---|
Get_work |
Worker → Daemon | Poll for a partitioned work spec |
Submit_work |
Worker → Daemon | Submit a completed proof |
Failed_to_generate_snark |
Worker → Daemon | Report a proof-generation error |
For a high-level description of how the SNARK worker interacts with the SNARK pool and the rest of the daemon, see docs/snark-worker-and-pool.md.