solana_zk_token_sdk/
errors.rs

1//! Errors related to proving and verifying proofs.
2#[cfg(not(target_os = "solana"))]
3use crate::range_proof::errors::RangeProofGenerationError;
4use {
5    crate::{range_proof::errors::RangeProofVerificationError, sigma_proofs::errors::*},
6    thiserror::Error,
7};
8
9#[derive(Error, Clone, Debug, Eq, PartialEq)]
10pub enum ElGamalError {
11    #[error("key derivation method not supported")]
12    DerivationMethodNotSupported,
13    #[error("seed length too short for derivation")]
14    SeedLengthTooShort,
15    #[error("seed length too long for derivation")]
16    SeedLengthTooLong,
17    #[error("failed to deserialize ciphertext")]
18    CiphertextDeserialization,
19    #[error("failed to deserialize public key")]
20    PubkeyDeserialization,
21    #[error("failed to deserialize keypair")]
22    KeypairDeserialization,
23    #[error("failed to deserialize secret key")]
24    SecretKeyDeserialization,
25}
26
27#[derive(Error, Clone, Debug, Eq, PartialEq)]
28pub enum AuthenticatedEncryptionError {
29    #[error("key derivation method not supported")]
30    DerivationMethodNotSupported,
31    #[error("seed length too short for derivation")]
32    SeedLengthTooShort,
33    #[error("seed length too long for derivation")]
34    SeedLengthTooLong,
35    #[error("failed to deserialize")]
36    Deserialization,
37}
38
39#[cfg(not(target_os = "solana"))]
40#[derive(Error, Clone, Debug, Eq, PartialEq)]
41pub enum ProofGenerationError {
42    #[error("not enough funds in account")]
43    NotEnoughFunds,
44    #[error("transfer fee calculation error")]
45    FeeCalculation,
46    #[error("illegal number of commitments")]
47    IllegalCommitmentLength,
48    #[error("illegal amount bit length")]
49    IllegalAmountBitLength,
50    #[error("invalid commitment")]
51    InvalidCommitment,
52    #[error("range proof generation failed")]
53    RangeProof(#[from] RangeProofGenerationError),
54    #[error("unexpected proof length")]
55    ProofLength,
56}
57
58#[derive(Error, Clone, Debug, Eq, PartialEq)]
59pub enum ProofVerificationError {
60    #[error("range proof verification failed")]
61    RangeProof(#[from] RangeProofVerificationError),
62    #[error("sigma proof verification failed")]
63    SigmaProof(SigmaProofType, SigmaProofVerificationError),
64    #[error("ElGamal ciphertext or public key error")]
65    ElGamal(#[from] ElGamalError),
66    #[error("Invalid proof context")]
67    ProofContext,
68    #[error("illegal commitment length")]
69    IllegalCommitmentLength,
70    #[error("illegal amount bit length")]
71    IllegalAmountBitLength,
72}
73
74#[derive(Clone, Debug, Eq, PartialEq)]
75pub enum SigmaProofType {
76    EqualityProof,
77    ValidityProof,
78    ZeroBalanceProof,
79    FeeSigmaProof,
80    PubkeyValidityProof,
81}
82
83#[derive(Error, Clone, Debug, Eq, PartialEq)]
84pub enum TranscriptError {
85    #[error("point is the identity")]
86    ValidationError,
87}
88
89#[cfg(not(target_os = "solana"))]
90impl From<EqualityProofVerificationError> for ProofVerificationError {
91    fn from(err: EqualityProofVerificationError) -> Self {
92        Self::SigmaProof(SigmaProofType::EqualityProof, err.0)
93    }
94}
95
96#[cfg(not(target_os = "solana"))]
97impl From<FeeSigmaProofVerificationError> for ProofVerificationError {
98    fn from(err: FeeSigmaProofVerificationError) -> Self {
99        Self::SigmaProof(SigmaProofType::FeeSigmaProof, err.0)
100    }
101}
102
103#[cfg(not(target_os = "solana"))]
104impl From<ZeroBalanceProofVerificationError> for ProofVerificationError {
105    fn from(err: ZeroBalanceProofVerificationError) -> Self {
106        Self::SigmaProof(SigmaProofType::ZeroBalanceProof, err.0)
107    }
108}
109
110#[cfg(not(target_os = "solana"))]
111impl From<ValidityProofVerificationError> for ProofVerificationError {
112    fn from(err: ValidityProofVerificationError) -> Self {
113        Self::SigmaProof(SigmaProofType::ValidityProof, err.0)
114    }
115}
116
117#[cfg(not(target_os = "solana"))]
118impl From<PubkeyValidityProofVerificationError> for ProofVerificationError {
119    fn from(err: PubkeyValidityProofVerificationError) -> Self {
120        Self::SigmaProof(SigmaProofType::PubkeyValidityProof, err.0)
121    }
122}