1use crate::poly::variant;
19use crate::{config, trace};
20use core::fmt;
21use hekate_crypto::{merkle, transcript};
22
23pub type Result<T> = core::result::Result<T, Error>;
24
25#[derive(Clone, Copy, Debug, Eq, PartialEq)]
26pub enum Error {
27 Config(config::Error),
28 Trace(trace::Error),
29 Merkle(merkle::Error),
30 Transcript(transcript::Error),
31 VirtualPoly(variant::Error),
32
33 Protocol {
36 protocol: &'static str,
37 message: &'static str,
38 },
39
40 InvariantViolation {
43 message: &'static str,
44 },
45}
46
47impl fmt::Display for Error {
48 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
49 match self {
50 Self::Config(e) => e.fmt(f),
51 Self::Trace(e) => e.fmt(f),
52 Self::Merkle(e) => e.fmt(f),
53 Self::Transcript(e) => e.fmt(f),
54 Self::VirtualPoly(e) => e.fmt(f),
55 Self::Protocol { protocol, message } => {
56 write!(f, "Protocol error ({protocol}): {message}")
57 }
58 Self::InvariantViolation { message } => {
59 write!(f, "Invariant violation: {message}")
60 }
61 }
62 }
63}
64
65impl From<config::Error> for Error {
66 fn from(value: config::Error) -> Self {
67 Self::Config(value)
68 }
69}
70
71impl From<trace::Error> for Error {
72 fn from(value: trace::Error) -> Self {
73 Self::Trace(value)
74 }
75}
76
77impl From<merkle::Error> for Error {
78 fn from(value: merkle::Error) -> Self {
79 Self::Merkle(value)
80 }
81}
82
83impl From<transcript::Error> for Error {
84 fn from(value: transcript::Error) -> Self {
85 Self::Transcript(value)
86 }
87}
88
89impl From<variant::Error> for Error {
90 fn from(value: variant::Error) -> Self {
91 Self::VirtualPoly(value)
92 }
93}