solana_zk_sdk/zk_elgamal_proof_program/
errors.rs1#[cfg(not(target_os = "solana"))]
2use crate::range_proof::errors::RangeProofGenerationError;
3use {
4 crate::{
5 errors::ElGamalError, range_proof::errors::RangeProofVerificationError,
6 sigma_proofs::errors::*,
7 },
8 thiserror::Error,
9};
10
11#[cfg(not(target_os = "solana"))]
12#[derive(Error, Clone, Debug, Eq, PartialEq)]
13pub enum ProofGenerationError {
14 #[error("illegal number of commitments")]
15 IllegalCommitmentLength,
16 #[error("illegal amount bit length")]
17 IllegalAmountBitLength,
18 #[error("invalid commitment")]
19 InvalidCommitment,
20 #[error("range proof generation failed")]
21 RangeProof(#[from] RangeProofGenerationError),
22 #[error("unexpected proof length")]
23 ProofLength,
24}
25
26#[derive(Error, Clone, Debug, Eq, PartialEq)]
27pub enum ProofVerificationError {
28 #[error("range proof verification failed")]
29 RangeProof(#[from] RangeProofVerificationError),
30 #[error("sigma proof verification failed")]
31 SigmaProof(SigmaProofType, SigmaProofVerificationError),
32 #[error("ElGamal ciphertext or public key error")]
33 ElGamal(#[from] ElGamalError),
34 #[error("Invalid proof context")]
35 ProofContext,
36 #[error("illegal commitment length")]
37 IllegalCommitmentLength,
38 #[error("illegal amount bit length")]
39 IllegalAmountBitLength,
40}
41
42#[derive(Clone, Debug, Eq, PartialEq)]
43pub enum SigmaProofType {
44 ZeroCiphertext,
45 Equality,
46 PubkeyValidity,
47 PercentageWithCap,
48 ValidityProof,
49}
50
51impl From<ZeroCiphertextProofVerificationError> for ProofVerificationError {
52 fn from(err: ZeroCiphertextProofVerificationError) -> Self {
53 Self::SigmaProof(SigmaProofType::ZeroCiphertext, err.0)
54 }
55}
56
57impl From<EqualityProofVerificationError> for ProofVerificationError {
58 fn from(err: EqualityProofVerificationError) -> Self {
59 Self::SigmaProof(SigmaProofType::Equality, err.0)
60 }
61}
62
63impl From<PubkeyValidityProofVerificationError> for ProofVerificationError {
64 fn from(err: PubkeyValidityProofVerificationError) -> Self {
65 Self::SigmaProof(SigmaProofType::PubkeyValidity, err.0)
66 }
67}
68
69impl From<PercentageWithCapProofVerificationError> for ProofVerificationError {
70 fn from(err: PercentageWithCapProofVerificationError) -> Self {
71 Self::SigmaProof(SigmaProofType::PercentageWithCap, err.0)
72 }
73}
74
75impl From<ValidityProofVerificationError> for ProofVerificationError {
76 fn from(err: ValidityProofVerificationError) -> Self {
77 Self::SigmaProof(SigmaProofType::ValidityProof, err.0)
78 }
79}