Skip to content

Commit 2e0c25b

Browse files
committed
SNARK library: document with top-level comments
1 parent 1352ed5 commit 2e0c25b

File tree

6 files changed

+149
-0
lines changed

6 files changed

+149
-0
lines changed

snark/src/block_verify/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
//! # Block Verification State Machine
2+
//!
3+
//! This module implements the state machine for verifying blockchain block proofs
4+
//! within the Mina protocol. It manages the lifecycle of block verification
5+
//! requests and maintains verification state.
6+
//!
7+
//! ## Overview
8+
//!
9+
//! Block verification ensures that:
10+
//! - Block proofs are cryptographically valid
11+
//! - Block headers contain correct consensus information
12+
//! - Blockchain state transitions are legitimate
13+
//!
14+
//! ## Usage
15+
//!
16+
//! Block verification is typically initiated by:
17+
//! - Consensus mechanisms validating incoming blocks
18+
//! - Fork resolution comparing competing chains
19+
//!
20+
//! The verification process runs asynchronously in service threads to avoid
21+
//! blocking the main state machine.
22+
123
mod snark_block_verify_state;
224
pub use snark_block_verify_state::*;
325

snark/src/block_verify_effectful/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
//! # Block Verification Service Layer
2+
//!
3+
//! This module provides the effectful (side-effect) operations for block
4+
//! verification, separating the computations from the main state machine logic.
5+
16
mod snark_block_verify_effectful_actions;
27
pub use snark_block_verify_effectful_actions::*;
38

snark/src/lib.rs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,81 @@
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+
179
use kimchi::mina_curves::pasta::Vesta;
280

381
mod merkle_path;

snark/src/merkle_path/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
//! # Merkle Path Verification Utilities
2+
//!
3+
//! This module provides utilities for computing and verifying Merkle tree paths,
4+
//! which are essential for account existence proofs in the Mina ledger.
5+
//!
6+
//! [`calc_merkle_root_hash`] computes the root hash from an account and its
7+
//! Merkle path, allowing verification that the account is part of a specific
8+
//! ledger state.
9+
//! This is commonly used in transaction verification (ensuring account exists).
10+
//! It uses the Poseidon hash function, as specified in the Mina protocol.
11+
112
use ark_ff::fields::arithmetic::InvalidBigInt;
213
use mina_p2p_messages::{bigint::BigInt, v2::MerkleTreeNode};
314
use poseidon::hash::params::get_merkle_param_for_height;

snark/src/user_command_verify/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
//! # User Command Verification State Machine
2+
//!
3+
//! This module handles the verification of user commands and zkApp transactions
4+
//! within the Mina protocol. It manages SNARK validation for transactions
5+
//! before they are included in blocks.
6+
//!
7+
//! ## Overview
8+
//!
9+
//! User command verification validates:
10+
//! - **Payment transactions**: Simple value transfers between accounts
11+
//! - **Delegation commands**: Stake delegation operations
12+
//! - **zkApp transactions**
13+
//!
14+
//! ## Verification Process
15+
//!
16+
//! The verification process includes:
17+
//! - Signature validation for transaction authorization
18+
//! - Proof verification for zkApp transactions
19+
//! - Account state consistency checks
20+
//! - Fee and nonce validation
21+
122
mod snark_user_command_verify_state;
223
pub use snark_user_command_verify_state::*;
324

snark/src/work_verify/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
//! # SNARK Work Verification State Machine
2+
//!
3+
//! This module manages the verification of SNARK work proofs submitted by
4+
//! external SNARK workers. It validates computational work that helps maintain
5+
//! the blockchain's security and scalability.
6+
//!
7+
//! ## Overview
8+
//!
9+
//! SNARK work verification handles:
10+
//! - **Transaction SNARK proofs**: Proofs for transaction validity
11+
//! - **Merge proofs**: Proofs combining multiple transaction proofs
12+
113
mod snark_work_verify_state;
214
pub use snark_work_verify_state::*;
315

0 commit comments

Comments
 (0)