tor_hscrypto/pow/
err.rs

1//! Combined error types for any proof of work scheme
2
3use crate::pow::v1::{RuntimeErrorV1, SolutionErrorV1};
4
5/// Error type for the onion service proof of work subsystem
6#[derive(Clone, Debug, thiserror::Error)]
7#[non_exhaustive]
8pub enum Error {
9    /// Solution was incorrect
10    ///
11    /// In general the detailed reason for failure should be ignored,
12    /// and it certainly should not be shared with clients. It's useful
13    /// for unit testing and possibly debugging. A particular type of flaw
14    /// in a solution could be exposed at a variety of layers in the
15    /// verification process depending on luck and algorithm parameters.
16    #[error("Incorrect solution to a client puzzle")]
17    BadSolution(#[source] SolutionError),
18
19    /// Runtime error while solving a proof of work puzzle
20    ///
21    /// Something went wrong in the environment to prevent the
22    /// solver from completing.
23    #[error("Runtime error while solving a client puzzle: {0}")]
24    SolveRuntime(#[source] RuntimeError),
25
26    /// Runtime error while verifying a proof of work puzzle
27    ///
28    /// Something went wrong in the environment to prevent the
29    /// verifier from coming to any conclusion.
30    #[error("Runtime error while verifying a client puzzle: {0}")]
31    VerifyRuntime(#[source] RuntimeError),
32}
33
34/// Detailed errors for ways a solution can fail verification
35///
36/// These errors must not be exposed to clients, who might
37/// use them to gain an advantage in computing solutions.
38#[derive(Clone, Debug, thiserror::Error)]
39#[non_exhaustive]
40pub enum SolutionError {
41    /// Solution errors from the `v1` proof of work scheme
42    #[error("V1, {0}")]
43    V1(#[from] SolutionErrorV1),
44}
45
46/// Detailed runtime errors
47#[derive(Clone, Debug, thiserror::Error)]
48#[non_exhaustive]
49pub enum RuntimeError {
50    /// Runtime errors from the `v1` proof of work scheme
51    #[error("V1, {0}")]
52    V1(#[from] RuntimeErrorV1),
53}