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