snark/lib.rs
1//! # SNARK Verification Orchestration
2//!
3//! The SNARK crate provides zero-knowledge proof verification capabilities for
4//! the Mina Rust node, orchestrating the verification of blocks, transactions,
5//! and SNARK work through a Redux-style state machine architecture.
6//!
7//! ## Overview
8//!
9//! This crate handles three main types of proof verification:
10//! - **Block Verification**: Validates blockchain blocks and their proofs
11//! - **Transaction Verification**: Verifies user commands and zkApp
12//! transactions
13//! - **Work Verification**: Validates SNARK work proofs from workers
14//!
15//! ## Architecture
16//!
17//! The crate follows the Mina node's Redux architecture pattern with:
18//! - **State**: [`SnarkState`] - Centralized verification state
19//! - **Actions**: [`SnarkAction`] - Events triggering verification operations
20//! - **Enabling Conditions**: [`redux::EnablingCondition`] - Guards preventing
21//! invalid state transitions
22//! - **Reducers**: Pure functions managing state transitions
23//! - **Effects**: Service interactions for actual proof verification
24//!
25//! You can find more information regarding the Redux pattern in the
26//! documentation at
27//! <https://o1-labs.github.io/mina-rust/docs/developers/architecture>.
28//!
29//! ## Core Components
30//!
31//! ### Verification State Machine
32//!
33//! Each verification type maintains its own state machine:
34//! - [`block_verify`] - Block proof verification state machine
35//! - [`user_command_verify`] - User command verification state machine
36//! - [`work_verify`] - SNARK work verification state machine
37//!
38//! ### Effectful Operations
39//!
40//! Operations run in separate service threads:
41//! - [`block_verify_effectful`] - Block verification services
42//! - [`user_command_verify_effectful`] - Transaction verification services
43//! - [`work_verify_effectful`] - Work verification services
44//!
45//! ## Configuration
46//!
47//! The [`SnarkConfig`] contains verifier indices and SRS parameters required
48//! for proof verification. These are network-specific and loaded during
49//! initialization.
50//!
51//! ## Integration
52//!
53//! The SNARK crate integrates with:
54//! - **Ledger**: Uses cryptographic primitives from the ledger crate
55//! - **Kimchi**: Leverages the Kimchi proving system for verification, used
56//! since Berkeley.
57//! - **Node**: Provides verification services to the main node
58//!
59//! ## Example Usage
60//!
61//! ```rust,no_run
62//! use snark::{SnarkConfig, SnarkState};
63//!
64//! // Initialize SNARK state with configuration
65//! let config = SnarkConfig { /* ... */ };
66//! let state = SnarkState::new(config);
67//!
68//! // The state machine handles verification requests through actions
69//! // dispatched by the main node's Redux store
70//! ```
71//!
72//! ## Performance Considerations
73//!
74//! - Verifier indices and SRS parameters are cached for reuse
75//! - Multiple verification operations can run concurrently
76//!
77//! For detailed API documentation, see the individual module documentation.
78
79use kimchi::mina_curves::pasta::Vesta;
80
81mod merkle_path;
82
83pub use ledger::proofs::{
84 caching::{srs_from_bytes, srs_to_bytes, verifier_index_from_bytes, verifier_index_to_bytes},
85 verifiers::{BlockVerifier, TransactionVerifier},
86};
87
88pub use merkle_path::calc_merkle_root_hash;
89
90pub mod block_verify;
91pub mod block_verify_effectful;
92pub mod user_command_verify;
93pub mod user_command_verify_effectful;
94pub mod work_verify;
95pub mod work_verify_effectful;
96
97mod snark_event;
98pub use snark_event::*;
99
100mod snark_actions;
101pub use snark_actions::*;
102
103mod snark_config;
104pub use snark_config::*;
105
106mod snark_state;
107pub use snark_state::*;
108
109mod snark_reducer;
110
111pub type VerifierIndex = ledger::proofs::VerifierIndex<mina_curves::pasta::Fq>;
112pub type VerifierSRS = poly_commitment::ipa::SRS<Vesta>;
113
114use redux::SubStore;
115pub trait SnarkStore<GlobalState>:
116 SubStore<GlobalState, SnarkState, SubAction = SnarkAction>
117{
118}
119impl<S, T: SubStore<S, SnarkState, SubAction = SnarkAction>> SnarkStore<S> for T {}
120
121pub fn get_srs() -> std::sync::Arc<poly_commitment::ipa::SRS<Vesta>> {
122 ledger::verifier::get_srs::<mina_curves::pasta::Fp>()
123}