1#[cfg(not(feature = "std"))]
2use alloc::string::String;
3
4#[cfg(feature = "std")]
5use thiserror::Error;
6
7#[cfg_attr(feature = "std", derive(Error))]
8#[derive(Debug)]
9pub enum ZkError {
10 #[cfg_attr(feature = "std", error("Invalid proof"))]
11 InvalidProof,
12
13 #[cfg_attr(feature = "std", error("Invalid parameters"))]
14 InvalidParameters,
15
16 #[cfg_attr(feature = "std", error("Computation error: {0}"))]
17 ComputationError(String),
18
19 #[cfg(feature = "std")]
20 #[cfg_attr(feature = "std", error("Serialization error: {0}"))]
21 SerializationError(String),
22
23 #[cfg(not(feature = "std"))]
24 SerializationError,
25
26 #[cfg_attr(feature = "std", error("IO error: {0}"))]
27 IoError(String),
28}
29
30#[cfg(not(feature = "std"))]
32impl core::fmt::Display for ZkError {
33 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
34 match self {
35 ZkError::InvalidProof => write!(f, "Invalid proof"),
36 ZkError::InvalidParameters => write!(f, "Invalid parameters"),
37 ZkError::ComputationError(msg) => write!(f, "Computation error: {}", msg),
38 ZkError::SerializationError => write!(f, "Serialization error"),
39 ZkError::IoError(msg) => write!(f, "IO error: {}", msg),
40 }
41 }
42}