1use casper_types::bytesrepr;
3
4use crate::{ChunkWithProof, Digest};
5
6#[derive(Debug, thiserror::Error)]
8#[non_exhaustive]
9pub enum Error {
10 #[error("Incorrect digest length {0}, expected length {}.", Digest::LENGTH)]
11 IncorrectDigestLength(usize),
13 #[error("Base16 decode error {0}.")]
15 Base16DecodeError(base16::DecodeError),
16}
17
18#[derive(thiserror::Error, Debug, PartialEq, Eq)]
20#[non_exhaustive]
21pub enum MerkleVerificationError {
22 #[error("Index out of bounds. Count: {count}, index: {index}")]
24 IndexOutOfBounds {
25 count: u64,
27 index: u64,
29 },
30
31 #[error(
33 "Unexpected proof length. Count: {count}, index: {index}, \
34 expected proof length: {expected_proof_length}, \
35 actual proof length: {actual_proof_length}"
36 )]
37 UnexpectedProofLength {
38 count: u64,
40 index: u64,
42 expected_proof_length: u8,
44 actual_proof_length: usize,
46 },
47}
48
49#[derive(thiserror::Error, Debug)]
51#[non_exhaustive]
52pub enum ChunkWithProofVerificationError {
53 #[error(transparent)]
55 MerkleVerificationError(#[from] MerkleVerificationError),
56
57 #[error("Chunk with proof has empty Merkle proof: {chunk_with_proof:?}")]
59 ChunkWithProofHasEmptyMerkleProof {
60 chunk_with_proof: ChunkWithProof,
62 },
63 #[error("Merkle proof has an unexpected root hash")]
65 UnexpectedRootHash,
66 #[error("Bytesrepr error computing chunkable hash: {0}")]
68 Bytesrepr(bytesrepr::Error),
69
70 #[error(
72 "First digest in Merkle proof did not match hash of chunk. \
73 First digest in indexed Merkle proof: {first_digest_in_indexed_merkle_proof:?}. \
74 Hash of chunk: {hash_of_chunk:?}."
75 )]
76 FirstDigestInMerkleProofDidNotMatchHashOfChunk {
77 first_digest_in_indexed_merkle_proof: Digest,
79 hash_of_chunk: Digest,
81 },
82}
83
84#[derive(thiserror::Error, Debug, Eq, PartialEq, Clone)]
86#[non_exhaustive]
87pub enum MerkleConstructionError {
88 #[error(
90 "Could not construct Merkle proof. Index out of bounds. Count: {count}, index: {index}"
91 )]
92 IndexOutOfBounds {
93 count: u64,
95 index: u64,
97 },
98 #[error(
100 "Could not construct Merkle proof. Too many leaves. Count: {count}, max: {} (u64::MAX)",
101 u64::MAX
102 )]
103 TooManyLeaves {
104 count: String,
106 },
107}