Skip to main content

nym_compact_ecash/
error.rs

1// Copyright 2024 - Nym Technologies SA <contact@nymtech.net>
2// SPDX-License-Identifier: Apache-2.0
3
4use thiserror::Error;
5
6pub type Result<T> = std::result::Result<T, CompactEcashError>;
7
8#[derive(Error, Debug)]
9pub enum CompactEcashError {
10    #[error("failed to verify expiration date signatures")]
11    ExpirationDateSignatureVerification,
12
13    #[error("failed to validate expiration date signatures")]
14    ExpirationDateSignatureValidity,
15
16    #[error("empty set for aggregation")]
17    AggregationEmptySet,
18
19    #[error("duplicate indices for aggregation")]
20    AggregationDuplicateIndices,
21
22    #[error("aggregation verification error")]
23    AggregationVerification,
24
25    #[error("the provided signature is at infinity")]
26    IdentitySignature,
27
28    #[error("different element size for aggregation")]
29    AggregationSizeMismatch,
30
31    #[error("the provided commitment hash is at infinity")]
32    IdentityCommitmentHash,
33
34    #[error("withdrawal request failed to verify")]
35    WithdrawalRequestVerification,
36
37    #[error("invalid key generation parameters")]
38    KeygenParameters,
39
40    #[error("signing authority's key is too short")]
41    KeyTooShort,
42
43    #[error("empty/incomplete set of coordinates for interpolation")]
44    InterpolationSetSize,
45
46    #[error("issuance verification failed")]
47    IssuanceVerification,
48
49    #[error("trying to spend more than what's available. Spending : {spending}, available : {remaining}")]
50    SpendExceedsAllowance { spending: u64, remaining: u64 },
51
52    #[error("signature failed validity check")]
53    SpendSignaturesValidity,
54
55    #[error("signature failed verification check")]
56    SpendSignaturesVerification,
57
58    #[error("duplicate serial number in the payment")]
59    SpendDuplicateSerialNumber,
60
61    #[error("given spend date is too late")]
62    SpendDateTooLate,
63
64    #[error("given spend date is too early")]
65    SpendDateTooEarly,
66
67    #[error("ZK proof failed to verify")]
68    SpendZKProofVerification,
69
70    #[error("could not decode base 58 string - {0}")]
71    MalformedString(#[from] bs58::decode::Error),
72
73    #[error("the provided construct is not compatible with the provided arguments")]
74    IncompatibleConstruction,
75
76    #[error("failed to verify coin indices signatures")]
77    CoinIndicesSignatureVerification,
78
79    #[error("failed to deserialize a {object}")]
80    DeserializationFailure { object: String },
81
82    #[error("failed to deserialise {type_name}: {source}")]
83    BinaryDeserialisationFailure {
84        type_name: String,
85        source: bincode::Error,
86    },
87
88    #[error(
89        "deserialization error, expected at least {} bytes, got {}",
90        min,
91        actual
92    )]
93    DeserializationMinLength { min: usize, actual: usize },
94
95    #[error("{type_name} deserialization error, expected {expected} bytes, got {actual}")]
96    DeserializationLengthMismatch {
97        type_name: String,
98        expected: usize,
99        actual: usize,
100    },
101
102    #[error("tried to deserialize {object} with bytes of invalid length. Expected {actual} < {target} or {modulus_target} % {modulus} == 0")]
103    DeserializationInvalidLength {
104        actual: usize,
105        target: usize,
106        modulus_target: usize,
107        modulus: usize,
108        object: String,
109    },
110
111    #[error("failed to deserialize scalar from the received bytes - it might not have been canonically encoded")]
112    ScalarDeserializationFailure,
113
114    #[error("failed to deserialize G1Projective point from the received bytes - it might not have been canonically encoded")]
115    G1ProjectiveDeserializationFailure,
116
117    #[error("failed to deserialize G2Projective point from the received bytes - it might not have been canonically encoded")]
118    G2ProjectiveDeserializationFailure,
119
120    #[error("verification key is invalid for this operation")]
121    VerificationKeyTooShort,
122
123    #[error("did not provide the sufficient number of coin index signatures")]
124    InsufficientNumberOfIndexSignatures,
125
126    #[error("did not provide the sufficient number of expiration date signatures")]
127    InsufficientNumberOfExpirationSignatures,
128
129    //context : This can happen only if the wallet secret `v` was picked such that `v + coin_index + 1 == 0`.
130    //The chance of this happening is of the order 2^-381 and not failing is waay too much work.
131    //TLDR: this event can happen, but with probability 0
132    #[error("you're one of the most unluck person on your planet and your wallet cannot complete this payment")]
133    UnluckiestError,
134}