jf_merkle_tree/
errors.rs

1// Copyright (c) 2022 Espresso Systems (espressosys.com)
2// This file is part of the Jellyfish library.
3
4// You should have received a copy of the MIT License
5// along with the Jellyfish library. If not, see <https://mit-license.org/>.
6//! Error types
7
8use ark_std::string::String;
9use displaydoc::Display;
10use jf_poseidon2::Poseidon2Error;
11use jf_rescue::RescueError;
12
13/// Error type for Merkle tree
14#[derive(Debug, Display, Eq, PartialEq)]
15pub enum MerkleTreeError {
16    /// Parameters error, {0}
17    ParametersError(String),
18    /// Queried leaf isn't in this Merkle tree
19    NotFound,
20    /// Queried leaf is already occupied.
21    ExistingLeaf,
22    /// Queried leaf is forgotten.
23    ForgottenLeaf,
24    /// Merkle tree is already full.
25    ExceedCapacity,
26    /// Digest error, {0}
27    DigestError(String),
28    /// Inconsistent Structure error, {0}
29    InconsistentStructureError(String),
30}
31
32impl ark_std::error::Error for MerkleTreeError {}
33
34impl From<RescueError> for MerkleTreeError {
35    fn from(err: RescueError) -> Self {
36        MerkleTreeError::DigestError(ark_std::format!("{}", err))
37    }
38}
39
40impl From<Poseidon2Error> for MerkleTreeError {
41    fn from(err: Poseidon2Error) -> Self {
42        MerkleTreeError::DigestError(ark_std::format!("{}", err))
43    }
44}