vex_core/zk.rs
1//! # VEX ZK Bridge
2//!
3//! Provides the trait-based interface for Zero-Knowledge proof verification.
4//! This allows vex-core to remain decoupled from heavy ZK libraries like Plonky3
5//! while still supporting "Shadow Intent" verification.
6
7use serde_json::Value;
8use thiserror::Error;
9
10#[derive(Error, Debug)]
11pub enum ZkError {
12 #[error("Verification failed: {0}")]
13 VerificationFailed(String),
14 #[error("Invalid proof format: {0}")]
15 InvalidFormat(String),
16 #[error("Missing public inputs: {0}")]
17 MissingMetadata(String),
18 #[error("Configuration error: {0}")]
19 ConfigError(String),
20}
21
22/// Interface for ZK-STARK verification.
23/// Implementations are provided by downstream crates (e.g., attest-rs).
24pub trait ZkVerifier: Send + Sync + std::fmt::Debug {
25 /// Verifies a STARK proof against a commitment and public inputs.
26 ///
27 /// # Arguments
28 /// * `commitment_hash` - The root hash the proof must bind to.
29 /// * `stark_proof_b64` - Base64 encoded STARK proof.
30 /// * `public_inputs` - JSON values representing the non-private data.
31 fn verify_stark(
32 &self,
33 commitment_hash: &str,
34 stark_proof_b64: &str,
35 public_inputs: &Value,
36 ) -> Result<bool, ZkError>;
37
38 /// Computes the JCS hash of the verifier's own parameters (Phase 3 Binding).
39 fn to_jcs_hash(&self) -> Result<crate::merkle::Hash, String> {
40 Ok(crate::merkle::Hash::digest(&[])) // Dummy default for mocks/Phase 1
41 }
42}