//! Zero-Knowledge Proof System for Synor L2 Rollups
//!
//! This crate provides the cryptographic foundation for ZK-rollups on Synor,
//! enabling massive L2 scaling with validity proofs rather than fraud proofs.
//!
//! # Architecture
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────────┐
//! │                        ZK-Rollup Layer                         │
//! ├─────────────────────────────────────────────────────────────────┤
//! │  ┌──────────────┐  ┌──────────────┐  ┌──────────────────────┐  │
//! │  │   Circuits   │  │ State Tree   │  │    Proof System      │  │
//! │  │  (R1CS/AIR)  │  │ (Sparse MT)  │  │  (Groth16/PLONK)     │  │
//! │  └──────────────┘  └──────────────┘  └──────────────────────┘  │
//! ├─────────────────────────────────────────────────────────────────┤
//! │  ┌──────────────────────────────────────────────────────────┐  │
//! │  │              Rollup State Manager                        │  │
//! │  │  - Batch processing                                      │  │
//! │  │  - State diff computation                                │  │
//! │  │  - Proof generation coordination                         │  │
//! │  └──────────────────────────────────────────────────────────┘  │
//! └─────────────────────────────────────────────────────────────────┘
//!                              │
//!                              ▼
//! ┌─────────────────────────────────────────────────────────────────┐
//! │                    L1 Bridge Contract                          │
//! │  - State root verification                                     │
//! │  - Proof validation                                            │
//! │  - Deposit/withdrawal handling                                 │
//! └─────────────────────────────────────────────────────────────────┘
//! ```
//!
//! # Key Features
//!
//! - **Validity Proofs**: Instant finality (no 7-day challenge period)
//! - **High Throughput**: 1,000-10,000 TPS depending on transaction complexity
//! - **Data Compression**: State diffs instead of full calldata
//! - **Trustless Bridge**: On-chain verification of all state transitions
//!
//! # Proof System Comparison
//!
//! | System | Trusted Setup | Proof Size | Verification | Prover Time |
//! |--------|---------------|------------|--------------|-------------|
//! | Groth16 | Yes (per circuit) | ~200 bytes | ~10ms | Slow |
//! | PLONK | Universal | ~500 bytes | ~15ms | Medium |
//! | STARK | No | ~50KB | ~30ms | Fast |
//!
//! We use Groth16 for production (smallest proofs, fastest verification)
//! with a universal setup ceremony for the trusted setup.
//!
//! # Quick Start
//!
//! ```rust,ignore
//! use synor_zk::{RollupManager, BatchTransaction, ProofSystem};
//!
//! // Initialize rollup manager
//! let mut rollup = RollupManager::new();
//!
//! // Add transactions to batch
//! rollup.add_transaction(BatchTransaction::transfer(from, to, amount))?;
//!
//! // Generate proof and new state root
//! let (proof, new_state_root) = rollup.finalize_batch()?;
//!
//! // Submit to L1 bridge
//! bridge.submit_batch(proof, new_state_root)?;
//! ```

#![allow(dead_code)]

pub mod circuit;
pub mod proof;
pub mod rollup;
pub mod state;

pub use circuit::{Circuit, CircuitConfig, ConstraintSystem};
pub use proof::{Proof, ProofSystem, VerificationKey};
pub use rollup::{BatchTransaction, RollupBatch, RollupManager, RollupConfig};
pub use state::{StateTree, StateRoot, Account, AccountState};

/// Re-export common types
pub use synor_types::Hash256;

/// ZK-Rollup configuration constants
pub mod constants {
    /// Maximum transactions per batch
    pub const MAX_BATCH_SIZE: usize = 1000;

    /// State tree depth (supports 2^32 accounts)
    pub const STATE_TREE_DEPTH: usize = 32;

    /// Minimum batch size before proof generation
    pub const MIN_BATCH_SIZE: usize = 10;

    /// Proof generation timeout in seconds
    pub const PROOF_TIMEOUT_SECS: u64 = 300;

    /// L1 bridge verification gas limit
    pub const VERIFICATION_GAS_LIMIT: u64 = 500_000;
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_constants() {
        assert!(constants::MAX_BATCH_SIZE > constants::MIN_BATCH_SIZE);
        assert!(constants::STATE_TREE_DEPTH >= 20); // At least 1M accounts
    }
}
