exo_proofs/error.rs
1// Copyright 2026 Exochain Foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at:
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// SPDX-License-Identifier: Apache-2.0
16
17//! Error types for the proof system.
18
19use thiserror::Error;
20
21/// Errors arising from proof operations.
22#[derive(Debug, Error)]
23pub enum ProofError {
24 #[error("constraint system error: {0}")]
25 ConstraintError(String),
26
27 #[error("proof generation failed: {0}")]
28 ProofGenerationFailed(String),
29
30 #[error("proof verification failed: {0}")]
31 VerificationFailed(String),
32
33 #[error("invalid proof format: {0}")]
34 InvalidProofFormat(String),
35
36 #[error("setup error: {0}")]
37 SetupError(String),
38
39 #[error("invalid witness: {0}")]
40 InvalidWitness(String),
41
42 #[error("deserialization error: {0}")]
43 DeserializationError(String),
44
45 /// The `exo-proofs` crate is a pedagogical/structural implementation —
46 /// not cryptographically hardened. It refuses to execute unless the
47 /// opt-in `unaudited-pedagogical-proofs` Cargo feature is enabled.
48 ///
49 /// Constitutional rule (per EXOCHAIN doctrine): never ship code that
50 /// claims a capability it does not have. Callers who want to use this
51 /// crate for classroom/structural work must explicitly opt in; callers
52 /// who accidentally depend on it will fail loudly at call time instead
53 /// of trusting a fake proof.
54 ///
55 /// When a real proof backend (production-hardened SNARK/STARK/ZKML)
56 /// lands, the opt-in flag MUST be removed and this variant deleted.
57 #[error(
58 "exo-proofs is unaudited (pedagogical implementation). \
59 Callers must opt in with the 'unaudited-pedagogical-proofs' \
60 Cargo feature before {api} will execute. \
61 Do NOT enable this flag in production."
62 )]
63 UnauditedImplementation {
64 /// The verifier/prover API that refused.
65 api: &'static str,
66 },
67}
68
69/// Convenience alias for results that may fail with a [`ProofError`].
70pub type Result<T> = std::result::Result<T, ProofError>;