Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions snark/src/block_verify/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
//! # Block Verification State Machine
//!
//! This module implements the state machine for verifying blockchain block proofs
//! within the Mina protocol. It manages the lifecycle of block verification
//! requests and maintains verification state.
//!
//! ## Overview
//!
//! Block verification ensures that:
//! - Block proofs are cryptographically valid
//! - Block headers contain correct consensus information
//! - Blockchain state transitions are legitimate
//!
//! ## Usage
//!
//! Block verification is typically initiated by:
//! - Consensus mechanisms validating incoming blocks
//! - Fork resolution comparing competing chains
//!
//! The verification process runs asynchronously in service threads to avoid
//! blocking the main state machine.

mod snark_block_verify_state;
pub use snark_block_verify_state::*;

Expand Down
5 changes: 5 additions & 0 deletions snark/src/block_verify_effectful/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
//! # Block Verification Service Layer
//!
//! This module provides the effectful (side-effect) operations for block
//! verification, separating the computations from the main state machine logic.

mod snark_block_verify_effectful_actions;
pub use snark_block_verify_effectful_actions::*;

Expand Down
78 changes: 78 additions & 0 deletions snark/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,81 @@
//! # SNARK Verification Orchestration
//!
//! The SNARK crate provides zero-knowledge proof verification capabilities for
//! the Mina Rust node, orchestrating the verification of blocks, transactions,
//! and SNARK work through a Redux-style state machine architecture.
//!
//! ## Overview
//!
//! This crate handles three main types of proof verification:
//! - **Block Verification**: Validates blockchain blocks and their proofs
//! - **Transaction Verification**: Verifies user commands and zkApp
//! transactions
//! - **Work Verification**: Validates SNARK work proofs from workers
//!
//! ## Architecture
//!
//! The crate follows the Mina node's Redux architecture pattern with:
//! - **State**: [`SnarkState`] - Centralized verification state
//! - **Actions**: [`SnarkAction`] - Events triggering verification operations
//! - **Enabling Conditions**: [`redux::EnablingCondition`] - Guards preventing
//! invalid state transitions
//! - **Reducers**: Pure functions managing state transitions
//! - **Effects**: Service interactions for actual proof verification
//!
//! You can find more information regarding the Redux pattern in the
//! documentation at
//! <https://o1-labs.github.io/mina-rust/docs/developers/architecture>.
//!
//! ## Core Components
//!
//! ### Verification State Machine
//!
//! Each verification type maintains its own state machine:
//! - [`block_verify`] - Block proof verification state machine
//! - [`user_command_verify`] - User command verification state machine
//! - [`work_verify`] - SNARK work verification state machine
//!
//! ### Effectful Operations
//!
//! Operations run in separate service threads:
//! - [`block_verify_effectful`] - Block verification services
//! - [`user_command_verify_effectful`] - Transaction verification services
//! - [`work_verify_effectful`] - Work verification services
//!
//! ## Configuration
//!
//! The [`SnarkConfig`] contains verifier indices and SRS parameters required
//! for proof verification. These are network-specific and loaded during
//! initialization.
//!
//! ## Integration
//!
//! The SNARK crate integrates with:
//! - **Ledger**: Uses cryptographic primitives from the ledger crate
//! - **Kimchi**: Leverages the Kimchi proving system for verification, used
//! since Berkeley.
//! - **Node**: Provides verification services to the main node
//!
//! ## Example Usage
//!
//! ```rust,no_run
//! use snark::{SnarkConfig, SnarkState};
//!
//! // Initialize SNARK state with configuration
//! let config = SnarkConfig { /* ... */ };
//! let state = SnarkState::new(config);
//!
//! // The state machine handles verification requests through actions
//! // dispatched by the main node's Redux store
//! ```
//!
//! ## Performance Considerations
//!
//! - Verifier indices and SRS parameters are cached for reuse
//! - Multiple verification operations can run concurrently
//!
//! For detailed API documentation, see the individual module documentation.

use kimchi::mina_curves::pasta::Vesta;

mod merkle_path;
Expand Down
11 changes: 11 additions & 0 deletions snark/src/merkle_path/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
//! # Merkle Path Verification Utilities
//!
//! This module provides utilities for computing and verifying Merkle tree paths,
//! which are essential for account existence proofs in the Mina ledger.
//!
//! [`calc_merkle_root_hash`] computes the root hash from an account and its
//! Merkle path, allowing verification that the account is part of a specific
//! ledger state.
//! This is commonly used in transaction verification (ensuring account exists).
//! It uses the Poseidon hash function, as specified in the Mina protocol.

use ark_ff::fields::arithmetic::InvalidBigInt;
use mina_p2p_messages::{bigint::BigInt, v2::MerkleTreeNode};
use poseidon::hash::params::get_merkle_param_for_height;
Expand Down
21 changes: 21 additions & 0 deletions snark/src/user_command_verify/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
//! # User Command Verification State Machine
//!
//! This module handles the verification of user commands and zkApp transactions
//! within the Mina protocol. It manages SNARK validation for transactions
//! before they are included in blocks.
//!
//! ## Overview
//!
//! User command verification validates:
//! - **Payment transactions**: Simple value transfers between accounts
//! - **Delegation commands**: Stake delegation operations
//! - **zkApp transactions**
//!
//! ## Verification Process
//!
//! The verification process includes:
//! - Signature validation for transaction authorization
//! - Proof verification for zkApp transactions
//! - Account state consistency checks
//! - Fee and nonce validation

mod snark_user_command_verify_state;
pub use snark_user_command_verify_state::*;

Expand Down
12 changes: 12 additions & 0 deletions snark/src/work_verify/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
//! # SNARK Work Verification State Machine
//!
//! This module manages the verification of SNARK work proofs submitted by
//! external SNARK workers. It validates computational work that helps maintain
//! the blockchain's security and scalability.
//!
//! ## Overview
//!
//! SNARK work verification handles:
//! - **Transaction SNARK proofs**: Proofs for transaction validity
//! - **Merge proofs**: Proofs combining multiple transaction proofs

mod snark_work_verify_state;
pub use snark_work_verify_state::*;

Expand Down
Loading
Loading