moonproof-backend 0.2.2

ProverBackend trait with local and remote implementations for Moonproof
Documentation
pub mod local;
pub mod remote;

use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use std::fmt;

#[derive(Debug, thiserror::Error)]
pub enum BackendError {
    #[error("Proving failed: {0}")]
    ProvingFailed(String),

    #[error("Verification failed: {0}")]
    VerificationFailed(String),

    #[error("Network error: {0}")]
    Network(String),

    #[error("Invalid input: {0}")]
    InvalidInput(String),

    #[error("Backend unavailable: {0}")]
    Unavailable(String),
}

pub type Result<T> = std::result::Result<T, BackendError>;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProofOutput {
    pub proof_hex: String,
    pub duration_ms: u64,
    pub k: u32,
    pub proof_size: usize,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CircuitInfo {
    pub k: u32,
    pub num_constraints: usize,
    pub num_public_inputs: usize,
    pub num_private_inputs: usize,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BackendHealth {
    pub healthy: bool,
    pub name: String,
    pub message: String,
}

#[async_trait]
pub trait ProverBackend: Send + Sync {
    async fn prove(&self, zkir_json: &str, witness_json: &str) -> Result<ProofOutput>;
    async fn verify(&self, zkir_json: &str, witness_json: &str, proof_hex: &str) -> Result<bool>;
    async fn circuit_info(&self, zkir_json: &str) -> Result<CircuitInfo>;
    async fn health(&self) -> Result<BackendHealth>;
    fn name(&self) -> &'static str;
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum BackendMode {
    Local,
    Remote,
}

impl fmt::Display for BackendMode {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            BackendMode::Local => write!(f, "Local"),
            BackendMode::Remote => write!(f, "Remote"),
        }
    }
}