Skip to main content

pallas_validate/utils/
validation.rs

1//! Types for validating transactions in each era.
2use thiserror::Error;
3
4#[derive(Debug, Clone, Error)]
5#[non_exhaustive]
6pub enum ValidationError {
7    #[error("transaction and protocol parameters differ")]
8    TxAndProtParamsDiffer,
9
10    #[error("byron doesn't need account state")]
11    PParamsByronDoesntNeedAccountState,
12
13    #[error("missing account state")]
14    EnvMissingAccountState,
15
16    #[error("unknown protocol parameters")]
17    UnknownProtParams,
18
19    #[error("{0}")]
20    Byron(ByronError),
21
22    #[error("{0}")]
23    ShelleyMA(ShelleyMAError),
24
25    #[error("{0}")]
26    Alonzo(AlonzoError),
27
28    #[error("{0}")]
29    PostAlonzo(PostAlonzoError),
30}
31
32#[derive(Debug, Clone, Error)]
33#[non_exhaustive]
34pub enum ByronError {
35    #[error("transaction has no inputs")]
36    TxInsEmpty,
37
38    #[error("transaction has no outputs")]
39    TxOutsEmpty,
40
41    #[error("some transaction input is not present in the UTxO set")]
42    InputNotInUTxO,
43
44    #[error("transaction output has no lovelace")]
45    OutputWithoutLovelace,
46
47    #[error("transaction size could not be determined")]
48    UnknownTxSize,
49
50    #[error("transaction fee cannot be computed")]
51    UnableToComputeFees,
52
53    #[error("transaction fee is below the minimum fee required")]
54    FeesBelowMin,
55
56    #[error("transaction size exceeds the maximum allowed")]
57    MaxTxSizeExceeded,
58
59    #[error("unable to process witnesses from the transaction")]
60    UnableToProcessWitness,
61
62    #[error("transaction witness is missing")]
63    MissingWitness,
64
65    #[error("transaction has the wrong signature")]
66    WrongSignature,
67}
68
69#[derive(Debug, Clone, Error)]
70#[non_exhaustive]
71pub enum ShelleyMAError {
72    #[error("transaction has no inputs")]
73    TxInsEmpty,
74
75    #[error("some transaction input is not present in the UTxO set")]
76    InputNotInUTxO,
77
78    #[error("transaction exceeds the TTL range")]
79    TTLExceeded,
80
81    #[error("transaction composition is not compatible with shelley")]
82    AlonzoCompNotShelley,
83
84    #[error("transaction size could not be determined")]
85    UnknownTxSize,
86
87    #[error("transaction size exceeds the maximum allowed")]
88    MaxTxSizeExceeded,
89
90    #[error("some value in the transaction is not shelley-compatible")]
91    ValueNotShelley,
92
93    #[error("minimum lovelace requirement was not met")]
94    MinLovelaceUnreached,
95
96    #[error("transaction values are not preserved correctly")]
97    PreservationOfValue,
98
99    #[error("transaction contains a negative value")]
100    NegativeValue,
101
102    #[error("transaction fee is below the minimum fee required")]
103    FeesBelowMin,
104
105    #[error("transaction output is from a different era")]
106    WrongEraOutput,
107
108    #[error("failed to decode the address")]
109    AddressDecoding,
110
111    #[error("transaction has the wrong network ID")]
112    WrongNetworkID,
113
114    #[error("metadata hash is invalid")]
115    MetadataHash,
116
117    #[error("vkey witness is missing")]
118    MissingVKWitness,
119
120    #[error("script witness is missing")]
121    MissingScriptWitness,
122
123    #[error("transaction has the wrong signature")]
124    WrongSignature,
125
126    #[error("minting lacks the required policy")]
127    MintingLacksPolicy,
128
129    #[error("key is already registered")]
130    KeyAlreadyRegistered,
131
132    #[error("key is not yet registered")]
133    KeyNotRegistered,
134
135    #[error("pointer is already in use")]
136    PointerInUse,
137
138    #[error("rewards are not null")]
139    RewardsNotNull,
140
141    #[error("pool is already registered")]
142    PoolAlreadyRegistered,
143
144    #[error("pool is not yet registered")]
145    PoolNotRegistered,
146
147    #[error("pool cost is below the minimum")]
148    PoolCostBelowMin,
149
150    #[error("transaction has duplicate genesis delegates")]
151    DuplicateGenesisDelegate,
152
153    #[error("transaction has duplicate genesis VRF")]
154    DuplicateGenesisVRF,
155
156    #[error("genesis key is not in the mapping")]
157    GenesisKeyNotInMapping,
158
159    #[error("insufficient funds for instantaneous rewards")]
160    InsufficientForInstantaneousRewards,
161
162    #[error("MIR certificate is too late in the epoch")]
163    MIRCertificateTooLateinEpoch,
164
165    #[error("script is denied")]
166    ScriptDenial,
167}
168
169#[derive(Debug, Clone, Error)]
170#[non_exhaustive]
171pub enum AlonzoError {
172    #[error("transaction size could not be determined")]
173    UnknownTxSize,
174
175    #[error("transaction has no inputs")]
176    TxInsEmpty,
177
178    #[error("some transaction input is not present in the UTxO set")]
179    InputNotInUTxO,
180
181    #[error("collateral is not present in the UTxO set")]
182    CollateralNotInUTxO,
183
184    #[error("block precedes the validity interval")]
185    BlockExceedsValInt,
186
187    #[error("block exceeds the validity interval")]
188    BlockPrecedesValInt,
189
190    #[error("upper bound of the validity interval is missing")]
191    ValIntUpperBoundMissing,
192
193    #[error("transaction fee is below the minimum fee required")]
194    FeeBelowMin,
195
196    #[error("collateral input is missing from the transaction")]
197    CollateralMissing,
198
199    #[error("transaction contains too many collateral inputs")]
200    TooManyCollaterals,
201
202    #[error("the collateral input is not VKey locked")]
203    CollateralNotVKeyLocked,
204
205    #[error("failed to decode the address")]
206    AddressDecoding,
207
208    #[error("collateral input does not meet the minimum lovelace required")]
209    CollateralMinLovelace,
210
211    #[error("collateral input contains non-lovelace assets")]
212    NonLovelaceCollateral,
213
214    #[error("transaction contains a negative value")]
215    NegativeValue,
216
217    #[error("transaction values are not preserved correctly")]
218    PreservationOfValue,
219
220    #[error("minimum lovelace requirement was not met")]
221    MinLovelaceUnreached,
222
223    #[error("the maximum value size has been exceeded")]
224    MaxValSizeExceeded,
225
226    #[error("transaction output has the wrong network ID")]
227    OutputWrongNetworkID,
228
229    #[error("transaction has the wrong network ID")]
230    TxWrongNetworkID,
231
232    #[error("required redeemer is missing")]
233    RedeemerMissing,
234
235    #[error("the transaction's execution units exceed the maximum allowed")]
236    TxExUnitsExceeded,
237
238    #[error("transaction size exceeds the maximum allowed")]
239    MaxTxSizeExceeded,
240
241    #[error("vkey witness is missing")]
242    VKWitnessMissing,
243
244    #[error("vkey witness has the wrong signature")]
245    VKWrongSignature,
246
247    #[error("required signer is missing")]
248    ReqSignerMissing,
249
250    #[error("required signer has the wrong signature")]
251    ReqSignerWrongSig,
252
253    #[error("script witness is missing")]
254    ScriptWitnessMissing,
255
256    #[error("minting lacks the required policy")]
257    MintingLacksPolicy,
258
259    #[error("failed to decode the input")]
260    InputDecoding,
261
262    #[error("an unnecessary native script is present")]
263    UnneededNativeScript,
264
265    #[error("an unnecessary Plutus V1 script is present")]
266    UnneededPlutusScript,
267
268    #[error("an unnecessary redeemer is present")]
269    UnneededRedeemer,
270
271    #[error("required datum is missing")]
272    DatumMissing,
273
274    #[error("an unnecessary datum is present")]
275    UnneededDatum,
276
277    #[error("metadata hash is invalid")]
278    MetadataHash,
279
280    #[error("invalid script integrity hash")]
281    ScriptIntegrityHash,
282}
283
284#[derive(Debug, Clone, Error)]
285#[non_exhaustive]
286pub enum PostAlonzoError {
287    #[error("transaction size could not be determined")]
288    UnknownTxSize,
289
290    #[error("transaction has no inputs")]
291    TxInsEmpty,
292
293    #[error("some transaction input is not present in the UTxO set")]
294    InputNotInUTxO,
295
296    #[error("collateral is not present in the UTxO set")]
297    CollateralNotInUTxO,
298
299    #[error("reference input is not present in the UTxO set")]
300    ReferenceInputNotInUTxO,
301
302    #[error("block precedes the validity interval")]
303    BlockPrecedesValInt,
304
305    #[error("block exceeds the validity interval")]
306    BlockExceedsValInt,
307
308    #[error("transaction fee is below the minimum fee required")]
309    FeeBelowMin,
310
311    #[error("collateral input is missing from the transaction")]
312    CollateralMissing,
313
314    #[error("transaction contains too many collateral inputs")]
315    TooManyCollaterals,
316
317    #[error("failed to decode the input")]
318    InputDecoding,
319
320    #[error("the collateral input is not VKey locked")]
321    CollateralNotVKeyLocked,
322
323    #[error("collateral input does not meet the minimum lovelace required")]
324    CollateralMinLovelace,
325
326    #[error("collateral input contains non-lovelace assets")]
327    NonLovelaceCollateral,
328
329    #[error("collateral input contains incorrect assets")]
330    CollateralWrongAssets,
331
332    #[error("transaction contains a negative value")]
333    NegativeValue,
334
335    #[error("paid collateral does not match the annotated collateral")]
336    CollateralAnnotation,
337
338    #[error("transaction values are not preserved correctly")]
339    PreservationOfValue,
340
341    #[error("minimum lovelace requirement was not met")]
342    MinLovelaceUnreached,
343
344    #[error("the maximum value size has been exceeded")]
345    MaxValSizeExceeded,
346
347    #[error("failed to decode the address")]
348    AddressDecoding,
349
350    #[error("transaction output has the wrong network ID")]
351    OutputWrongNetworkID,
352
353    #[error("transaction has the wrong network ID")]
354    TxWrongNetworkID,
355
356    #[error("the transaction's execution units exceed the maximum allowed")]
357    TxExUnitsExceeded,
358
359    #[error("required redeemer is missing")]
360    RedeemerMissing,
361
362    #[error("an unnecessary redeemer is present")]
363    UnneededRedeemer,
364
365    #[error("transaction size exceeds the maximum allowed")]
366    MaxTxSizeExceeded,
367
368    #[error("minting lacks the required policy: {0}")]
369    MintingLacksPolicy(pallas_crypto::hash::Hash<28>),
370
371    #[error("metadata hash is invalid")]
372    MetadataHash,
373
374    #[error("required datum is missing")]
375    DatumMissing,
376
377    #[error("an unnecessary datum is present")]
378    UnneededDatum,
379
380    #[error("script witness is missing")]
381    ScriptWitnessMissing,
382
383    #[error("an unnecessary native script is present")]
384    UnneededNativeScript,
385
386    #[error("an unnecessary Plutus V1 script is present")]
387    UnneededPlutusV1Script,
388
389    #[error("an unnecessary Plutus V2 script is present")]
390    UnneededPlutusV2Script,
391
392    #[error("an unnecessary Plutus V3 script is present")]
393    UnneededPlutusV3Script,
394
395    #[error("required signer is missing")]
396    ReqSignerMissing,
397
398    #[error("required signer has the wrong signature")]
399    ReqSignerWrongSig,
400
401    #[error("vkey witness is missing")]
402    VKWitnessMissing,
403
404    #[error("vkey witness has the wrong signature")]
405    VKWrongSignature,
406
407    #[error("transaction contains an unsupported plutus language")]
408    UnsupportedPlutusLanguage,
409
410    #[error("invalid script integrity hash")]
411    ScriptIntegrityHash,
412}
413
414pub type ValidationResult = Result<(), ValidationError>;